Skip to content

Commit 2e83e76

Browse files
martimalekMartí Malek
and
Martí Malek
authored
fix: display semantic colors in table and allow to filter them (#258)
* fix: display semantic colors in table and allow to filter them * refactor: improve performance of SemanticColorsTable * fix: trim table filter input Co-authored-by: Martí Malek <[email protected]>
1 parent 89f3937 commit 2e83e76

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/essentials/Colors/docs/SemanticColorsTable.tsx

+8-10
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ const ColorBlock = styled.div<{ color: string }>`
2828
width: 4rem;
2929
`;
3030

31+
const flatSemanticColors = flattenObj(SemanticColors);
32+
const flatSemanticColorsKeys = [...flatSemanticColors.keys()] as string[];
33+
3134
export const SemanticColorsTable: FC = () => {
3235
const [nameSearchInput, setNameSearchInput] = useState('');
33-
const flatSemanticColors = flattenObj(SemanticColors);
34-
35-
const filteredColorKeys = Object.keys(flatSemanticColors).filter(it => {
36-
if (nameSearchInput === '') {
37-
return true;
38-
}
3936

40-
return it.toLowerCase().includes(nameSearchInput.toLowerCase());
41-
});
37+
const filteredColorKeys = !nameSearchInput
38+
? flatSemanticColorsKeys
39+
: flatSemanticColorsKeys.filter(it => it.toLowerCase().includes(nameSearchInput.toLowerCase().trim()));
4240

4341
return (
4442
<>
@@ -64,13 +62,13 @@ export const SemanticColorsTable: FC = () => {
6462
{filteredColorKeys.map(key => (
6563
<TableRow key={key}>
6664
<TableCell>
67-
<ColorBlock color={flatSemanticColors[key]} />
65+
<ColorBlock color={flatSemanticColors.get(key)} />
6866
</TableCell>
6967
<TableCell>
7068
<code>{key}</code>
7169
</TableCell>
7270
<TableCell>
73-
<code>{flatSemanticColors[key]}</code>
71+
<code>{flatSemanticColors.get(key)}</code>
7472
</TableCell>
7573
</TableRow>
7674
))}

0 commit comments

Comments
 (0)