diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..dc0bb0f --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v22.12.0 diff --git a/src/tokens/colors/color.stories.tsx b/src/tokens/colors/color.stories.tsx new file mode 100644 index 0000000..60a9987 --- /dev/null +++ b/src/tokens/colors/color.stories.tsx @@ -0,0 +1,56 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import tokens from '../transformed.tokens.json'; +import ColorTokens from './color'; + +const meta = { + title: 'Tokens/Colors', + component: ColorTokens, +} satisfies Meta; + +export default meta; +type Story = StoryObj; +export const Colors: Story = { + args: { + colors: Object.keys(tokens.color).map((name) => { + const colorGroup = tokens.color[name]; + + // If it's a direct color token (no further nesting) + if (colorGroup.value) { + return { + name, + variants: [ + { + name: null, + value: colorGroup.value, + type: colorGroup.type, + description: colorGroup.description, + }, + ], + }; + } + + // Handle nested structures (recursively flatten) + const processVariants = (data: any, parentKey = ""): any[] => { + return Object.entries(data).flatMap(([key, value]) => { + const currentKey = parentKey ? `${parentKey}-${key}` : key; + + if ((value as any).value) { + return { + name: currentKey, + value: (value as any).value, + type: (value as any).type, + description: (value as any).description, + }; + } else { + return processVariants(value, currentKey); + } + }); + }; + + return { + name, + variants: processVariants(colorGroup), + }; + }), + }, +}; diff --git a/src/tokens/colors/color.tsx b/src/tokens/colors/color.tsx new file mode 100644 index 0000000..062bcb9 --- /dev/null +++ b/src/tokens/colors/color.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +// Utility classes for token display components. +import clBase from '../../foundation/utility/cl-base.module.scss'; + +type ColorToken = { + name?: string; + value: string; + type: string; + description?: string; +}; + +type ColorTokensProps = { + colors: { + name: string; + variants: ColorToken[]; + }[]; +}; +export default function ColorTokens({ + colors, +}: ColorTokensProps) { + return ( +
+

Colors

+ {colors.map((colorGroup) => ( +
+

{colorGroup.name}

+
    + {colorGroup.variants.map((variant) => ( +
  • + {variant.name ?? colorGroup.name } + {variant.value} + + + var(--color-{colorGroup.name + .toLowerCase() + .replace("emulsifyblue", "emulsify-blue")}{ + variant.name ? `-${variant.name}` : "" + }) + + + +
  • + ))} +
+
+ ))} +
+ ); +}