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

Adding CSS and JS token display in storybook #594

Merged
merged 8 commits into from
Jan 24, 2024

Conversation

georgewrmarshall
Copy link
Collaborator

@georgewrmarshall georgewrmarshall commented Jan 23, 2024

Description

Previously, we didn't have a way to visualize the changes in CSS, and JavaScript color tokens. The current storybook renders the Figma token json. So we had to manually ensure that the hex values were the same across all these platforms. This process was prone to errors and inconsistencies.

This PR introduces a rudimentary visualization of the CSS and JS color tokens along with the Figma token json. Now, we can visually check that any token updates are correctly reflected across all token formats. This will help us maintain consistency and catch any discrepancies early.

How it works

  • JS token stories use the available lightTheme and darkTheme objects. Brand colors will be added in the near future
  • CSS token stories are generated from the CSS variables taken from the stylesheet rendered in storybook

Fixes: #595

Screenshots/Screencasts

Before

before720.mov

After

after720.mov

Manual Testing

To manually test the changes, check the Storybook build in this PR. You can also pull the branch and run the following command to run the script and generate the JSON data:

node scripts/extractCssColors.js

This will create a JSON file in the docs/data directory. You can then use this data in your Storybook stories to visualize the color tokens.

This PR helps us maintain consistency across our color tokens and makes it easier to update and verify these tokens.

@georgewrmarshall georgewrmarshall self-assigned this Jan 23, 2024
@georgewrmarshall georgewrmarshall added documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation labels Jan 23, 2024
@@ -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} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating reference to brand color story in MDX docs so it still renders

@@ -18,7 +21,26 @@ export default meta;

type Story = StoryObj<typeof ColorSwatchGroup>;

export const DefaultStory: Story = {
export const Figma: Story = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming stories to align with their format Figma, CSS, JS

@@ -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} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating story name references in MDX so they still render as intended

// CSS
import lightThemeCss from './data/lightTheme.json';
import darkThemeCss from './data/darkTheme.json';

Copy link
Collaborator Author

@georgewrmarshall georgewrmarshall Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports all the different token data for each format

name="Primary Default"
/>
),
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding missing ColorSwatch story for doc components

Screenshot 2024-01-22 at 5 26 18 PM

@@ -49,6 +49,7 @@ export const ColorSwatch: FunctionComponent<ColorSwatchProps> = ({
backgroundColor: textBackgroundColor,
padding: 8,
borderRadius: '0 0 8px 8px',
color: textColor,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

including text color so we can adjust the display of swatches for dark mode

name="Color Swatch Group"
/>
),
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including missing ColorSwatchGroup story for doc components
Screenshot 2024-01-22 at 5 27 28 PM

@georgewrmarshall georgewrmarshall force-pushed the fix/css-js-token-docs-display branch from 02dbb29 to 6798d5b Compare January 23, 2024 03:20
@metamaskbot
Copy link
Collaborator

Builds ready [6798d5b]

Storybook: Storybook

@georgewrmarshall georgewrmarshall force-pushed the fix/css-js-token-docs-display branch from 6798d5b to 76df8db Compare January 23, 2024 03:26
@metamaskbot
Copy link
Collaborator

Builds ready [76df8db]

Storybook: Storybook

@metamaskbot
Copy link
Collaborator

Builds ready [ee701ca]

Storybook: Storybook

@georgewrmarshall georgewrmarshall marked this pull request as ready for review January 23, 2024 17:03
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner January 23, 2024 17:03
@metamaskbot
Copy link
Collaborator

Builds ready [68504fb]

Storybook: Storybook

@@ -3,7 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
import { Text } from '.';

export default {
title: 'Doc components/Text',
title: 'Documentation Components/Text',
Copy link
Collaborator Author

@georgewrmarshall georgewrmarshall Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updating "Doc" to "Documentation" as it's bumped to 2 lines anyway

@@ -5,7 +5,7 @@ interface Props<C extends React.ElementType> {
/**
* The children or content of the Text component
*/
children?: React.ReactChild;
children?: React.ReactNode;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating deprecated ReactChild

Screenshot 2024-01-23 at 9 30 36 AM

/**
* The color prop of the Text component
*/
color?: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding color prop and setting the default to text/default to fix bug with shadows with this inclusion of CSS variable stories

Before

before.text.mov

After

after.text.mov

@metamaskbot
Copy link
Collaborator

Builds ready [5abc7de]

Storybook: Storybook

@metamaskbot
Copy link
Collaborator

Builds ready [a6a6567]

Storybook: Storybook

@metamaskbot
Copy link
Collaborator

Builds ready [ab1c530]

Storybook: Storybook

garrettbear
garrettbear previously approved these changes Jan 24, 2024
Copy link
Contributor

@garrettbear garrettbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just need to fix that merge conflict

@metamaskbot
Copy link
Collaborator

Builds ready [86cde74]

Storybook: Storybook

@metamaskbot
Copy link
Collaborator

Builds ready [7fea178]

Storybook: Storybook

@@ -37,7 +37,7 @@ export const brandColor: BrandColor = {
orange300: '#faa66c',
orange400: '#f8883b',
orange500: '#f66a0a',
orange600: '#c65507',
orange600: '#bf5208',
Copy link
Collaborator Author

@georgewrmarshall georgewrmarshall Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank goodness for tests. This fixes some wrong color values after #586 got merged and fixes failing test on main https://github.com/MetaMask/design-tokens/actions/runs/7644751686/job/20829744608

@garrettbear garrettbear merged commit 34bb957 into main Jan 24, 2024
7 checks passed
@garrettbear garrettbear deleted the fix/css-js-token-docs-display branch January 24, 2024 20:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visualize CSS and JS Color Tokens in Storybook
4 participants