Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
feat: adding css and js token stories, scripts and css data
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall committed Jan 23, 2024
1 parent 0e4c543 commit 02dbb29
Show file tree
Hide file tree
Showing 13 changed files with 990 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/BrandColors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _The majority of our brand color progressions were generated using the [0to255](

## Brand colors

<Canvas of={BrandColorStories.DefaultStory} />
<Canvas of={BrandColorStories.Figma} />

## Best Practices

Expand Down
28 changes: 25 additions & 3 deletions docs/BrandColors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import tokens from '../src/figma/tokens.json';
import { ColorSwatchGroup } from './components';
import brandColors from './data/brandColors.json';
import { ColorSwatchGroup, ColorSwatch, Text } from './components';

import README from './BrandColors.mdx';

const meta: Meta<typeof ColorSwatchGroup> = {
Expand All @@ -18,7 +21,26 @@ export default meta;

type Story = StoryObj<typeof ColorSwatchGroup>;

export const DefaultStory: Story = {
export const Figma: Story = {
render: () => <ColorSwatchGroup swatchData={tokens.global.brandColors} />,
name: 'Default',
};

export const CSS: Story = {
render: () => (
<div
style={{
display: 'grid',
gap: '16px',
gridTemplateColumns: 'repeat(auto-fill, 300px)',
}}
>
{Object.values(brandColors).map(({ color, name }) => (
<ColorSwatch key={name} color={color} name={name} />
))}
</div>
),
};

export const JS: Story = {
render: () => <h1>Coming soon</h1>,
};
4 changes: 2 additions & 2 deletions docs/ThemeColors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ For most use cases, these function-based color tokens should be your first choic

The light theme colors are designed to be used in the styles for MetaMask UI when the light theme is active

<Canvas of={ThemeColorStories.LightThemeColors} />
<Canvas of={ThemeColorStories.FigmaLightTheme} />

## Dark theme colors

The dark theme colors are designed for MetaMask UI when the dark theme is active. They have the same names as the light theme colors but different values. If you are using the light theme colors for their intended purpose, your UI will automatically be compatible with the dark theme.

<Canvas of={ThemeColorStories.DarkThemeColors} />
<Canvas of={ThemeColorStories.FigmaDarkTheme} />

## Best practices

Expand Down
137 changes: 131 additions & 6 deletions docs/ThemeColors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import React from 'react';
import tokens from '../src/figma/tokens.json';
import { ColorSwatchGroup } from './components';

import { ColorSwatchGroup, ColorSwatch } from './components';
import README from './ThemeColors.mdx';

// Figma
import tokens from '../src/figma/tokens.json';
// JS
import { lightTheme, darkTheme } from '../src';
// CSS
import lightThemeCss from './data/lightTheme.json';
import darkThemeCss from './data/darkTheme.json';

export default {
title: 'Colors/Theme Colors',
component: ColorSwatchGroup,
Expand All @@ -13,8 +21,8 @@ export default {
},
};

export const LightThemeColors = {
render: () => <ColorSwatchGroup {...LightThemeColors.args} />,
export const FigmaLightTheme = {
render: () => <ColorSwatchGroup {...FigmaLightTheme.args} />,
args: {
swatchData: tokens.light.colors,
borderColor: tokens.light.colors.border.muted.value,
Expand All @@ -23,7 +31,7 @@ export const LightThemeColors = {
},
};

export const DarkThemeColors = {
export const FigmaDarkTheme = {
render: () => (
<div
style={{
Expand All @@ -32,7 +40,7 @@ export const DarkThemeColors = {
padding: '1rem',
}}
>
<ColorSwatchGroup {...DarkThemeColors.args} />
<ColorSwatchGroup {...FigmaDarkTheme.args} />
</div>
),
args: {
Expand All @@ -50,3 +58,120 @@ export const DarkThemeColors = {
},
},
};

export const CSSLightTheme = {
render: () => (
<div
style={{
display: 'grid',
gap: '16px',
gridTemplateColumns: 'repeat(auto-fill, 300px)',
}}
>
{Object.entries(lightThemeCss).map(
([name, { color, name: colorName }]) => (
<ColorSwatch key={name} color={color} name={colorName} />
),
)}
</div>
),
};

export const CSSDarkTheme = {
render: () => (
<div
style={{
backgroundColor: darkTheme.colors.background.default,
margin: '-1rem',
padding: '1rem',
}}
data-theme="dark"
>
<div
style={{
display: 'grid',
gap: '16px',
gridTemplateColumns: 'repeat(auto-fill, 300px)',
}}
>
{Object.entries(darkThemeCss).map(
([name, { color, name: colorName }]) => (
<ColorSwatch
key={name}
color={color}
name={colorName}
borderColor="var(--color-border-muted)"
textBackgroundColor="var(--color-background-default)"
textColor="var(--color-text-default)"
/>
),
)}
</div>
</div>
),
backgrounds: {
default: 'dark',
values: [{ name: 'dark', value: darkTheme.colors.background.default }],
},
};

export const JSLightTheme = {
render: () => (
<div
style={{
display: 'grid',
gap: '16px',
gridTemplateColumns: 'repeat(auto-fill, 300px)',
}}
>
{Object.entries(lightTheme.colors).flatMap(([category, colorObj]) =>
Object.entries(colorObj).map(([name, color]) => (
<ColorSwatch
key={`${category}-${name}`}
color={color}
name={`color.${category}.${name}`}
/>
)),
)}
</div>
),
};

export const JSDarkTheme = {
render: () => (
<div
style={{
backgroundColor: darkTheme.colors.background.default,
margin: '-1rem',
padding: '1rem',
}}
>
<div
style={{
display: 'grid',
gap: '16px',
gridTemplateColumns: 'repeat(auto-fill, 300px)',
}}
>
{Object.entries(darkTheme.colors).flatMap(([category, colorObj]) =>
Object.entries(colorObj).map(([name, color]) => (
<ColorSwatch
key={`${category}-${name}`}
color={color}
name={`color.${category}.${name}`}
borderColor={darkTheme.colors.border.muted}
textBackgroundColor={darkTheme.colors.background.default}
textColor={darkTheme.colors.text.default}
/>
)),
)}
</div>
</div>
),
parameters: {
backgrounds: {
default: 'dark',
values: [{ name: 'dark', value: darkTheme.colors.background.default }],
},
},
};
23 changes: 23 additions & 0 deletions docs/components/ColorSwatch/ColorSwatch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from '@storybook/react';
import { ColorSwatch } from './ColorSwatch';

const meta: Meta<typeof ColorSwatch> = {
title: 'Documentation Components/ColorSwatch',
component: ColorSwatch,
};

export default meta;

type Story = StoryObj<typeof ColorSwatch>;

export const Default: Story = {
render: () => (
<ColorSwatch
color="#007bff"
borderColor="#ced4da"
textBackgroundColor="#f8f9fa"
textColor="#212529"
name="Primary Default"
/>
),
};
1 change: 1 addition & 0 deletions docs/components/ColorSwatch/ColorSwatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ColorSwatch: FunctionComponent<ColorSwatchProps> = ({
backgroundColor: textBackgroundColor,
padding: 8,
borderRadius: '0 0 8px 8px',
color: textColor,
}}
>
<strong style={{ display: 'block', marginBottom: '8px' }}>
Expand Down
36 changes: 36 additions & 0 deletions docs/components/ColorSwatchGroup/ColorSwatchGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/react';
import { ColorSwatchGroup } from './ColorSwatchGroup';

const meta: Meta<typeof ColorSwatchGroup> = {
title: 'Documentation Components/ColorSwatchGroup',
component: ColorSwatchGroup,
};

export default meta;

type Story = StoryObj<typeof ColorSwatchGroup>;

export const Default: Story = {
render: () => (
<ColorSwatchGroup
swatchData={{
white: {
white000: {
value: '#FFFFFF',
description: '(HEX: #FFFFFF)',
type: 'color',
},
white010: {
value: '#FCFCFC',
description: '(HEX: #FCFCFC)',
type: 'color',
},
},
}}
borderColor="#ced4da"
textBackgroundColor="#f8f9fa"
textColor="#212529"
name="Color Swatch Group"
/>
),
};
2 changes: 1 addition & 1 deletion docs/components/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
import { Text } from '.';

export default {
title: 'Doc components/Text',
title: 'Documentation Components/Text',
argTypes: {
children: {
control: 'text',
Expand Down
Loading

0 comments on commit 02dbb29

Please sign in to comment.