Skip to content

Commit

Permalink
fix: sx prop merge immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed Jun 11, 2024
1 parent b8090f5 commit 25f177d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 23 additions & 0 deletions packages/core/src/hook/useSx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const baseTheme: ThemedDict = {
fontStyle: 'normal',
fontWeight: '400',
},
body: {
fontFamily: 'Noto Sans',
fontSize: 12,
fontStyle: 'normal',
fontWeight: '400',
},
},
};

Expand Down Expand Up @@ -241,6 +247,23 @@ describe('style parse priority', () => {
{ fallback: { width: 1, marginX: 5 }, expectation: { width: 2, marginHorizontal: 4 } },
);
});

it('sx typography > fallback', () => {
expectResult(
baseTheme,
{ t: 'title' },
{
fallback: { typography: 'body' },
expectation: {
fontFamily: 'Noto Sans',
fontSize: 14,
fontStyle: 'normal',
fontWeight: '400',
},
styleType: 'TextStyle',
},
);
});
});

describe('radii', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export function mutateShortcutPropToOriginalKeys(sx?: TextSxProps | null) {
return sx;
}

const ret = { ...sx };

for (const key of Object.keys(sx)) {
if (SHORTCUT_NAME_MAP[key]) {
if (!(SHORTCUT_NAME_MAP[key] in sx)) {
sx[SHORTCUT_NAME_MAP[key]] = sx[key];
if (!(SHORTCUT_NAME_MAP[key] in ret)) {
ret[SHORTCUT_NAME_MAP[key]] = sx[key];
}
}
}

return sx;
return ret;
}

0 comments on commit 25f177d

Please sign in to comment.