Skip to content

Commit

Permalink
Merge branch 'bug/fix-crash-on-invalid-color'
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Nov 29, 2023
2 parents 31d9686 + a219c8a commit a825b4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ColorPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ interface ColorPreviewProps {
color: string;
}

const UNPARSABLE_COLOR_VALUES = ['inherit', 'initial', 'unset'];

// heuristic based on token name/scope and maybe even the format of the value
export const isColor = (value: string): boolean => {
// taken from https://stackoverflow.com/a/56266358/973537
const s = new Option().style;
s.color = value;
return s.color !== '';
return s.color !== '' && !UNPARSABLE_COLOR_VALUES.includes(s.color);
};

const ColorPreview = ({color}: ColorPreviewProps): JSX.Element | null => {
Expand Down
22 changes: 22 additions & 0 deletions src/TokenRow.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ support this yet!_
</Story>
</Canvas>

**CSS color properties**

<Canvas>
<Story
name="CSS color: inherit"
args={{
designToken: {
name: 'ofColorFg',
value: 'inherit',
original: {
value: 'inherit',
},
path: ['of', 'color', 'fg'],
attributes: {},
},
contained: false,
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable of={TokenRow} />

0 comments on commit a825b4a

Please sign in to comment.