Skip to content

Commit

Permalink
fix: display semantic colors in table and allow to filter them (#258)
Browse files Browse the repository at this point in the history
* 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 <marti.malek@free-now.com>
  • Loading branch information
martimalek and martimalek committed Jul 11, 2022
1 parent 89f3937 commit 2e83e76
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/essentials/Colors/docs/SemanticColorsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ const ColorBlock = styled.div<{ color: string }>`
width: 4rem;
`;

const flatSemanticColors = flattenObj(SemanticColors);
const flatSemanticColorsKeys = [...flatSemanticColors.keys()] as string[];

export const SemanticColorsTable: FC = () => {
const [nameSearchInput, setNameSearchInput] = useState('');
const flatSemanticColors = flattenObj(SemanticColors);

const filteredColorKeys = Object.keys(flatSemanticColors).filter(it => {
if (nameSearchInput === '') {
return true;
}

return it.toLowerCase().includes(nameSearchInput.toLowerCase());
});
const filteredColorKeys = !nameSearchInput
? flatSemanticColorsKeys
: flatSemanticColorsKeys.filter(it => it.toLowerCase().includes(nameSearchInput.toLowerCase().trim()));

return (
<>
Expand All @@ -64,13 +62,13 @@ export const SemanticColorsTable: FC = () => {
{filteredColorKeys.map(key => (
<TableRow key={key}>
<TableCell>
<ColorBlock color={flatSemanticColors[key]} />
<ColorBlock color={flatSemanticColors.get(key)} />
</TableCell>
<TableCell>
<code>{key}</code>
</TableCell>
<TableCell>
<code>{flatSemanticColors[key]}</code>
<code>{flatSemanticColors.get(key)}</code>
</TableCell>
</TableRow>
))}
Expand Down

0 comments on commit 2e83e76

Please sign in to comment.