Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating documentation #593

Merged
merged 17 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ Follow these steps to below to get the library up and running locally.

### Setup

- Install [Node.js](https://nodejs.org) version 12
- Install [Node.js](https://nodejs.org) version 16
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 node version to 16 as stated in the package.json

"node": "^16.20.0"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense - nvmrc is also already at 16

- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v1](https://yarnpkg.com/en/docs/install)
- Run `yarn setup` to install dependencies and run any requried post-install scripts
- Run `yarn setup` to install dependencies and run any required post-install scripts
Copy link
Collaborator Author

@georgewrmarshall georgewrmarshall Jan 20, 2024

Choose a reason for hiding this comment

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

Fixing spelling mistake

- **Warning:** Do not use the `yarn` / `yarn install` command directly. Use `yarn setup` instead. The normal install command will skip required post-install scripts, leaving your development environment in an invalid state.

### Documentation
Expand All @@ -117,9 +117,9 @@ We use storybook for documentation. To get storybook up and running use:
yarn storybook
```

### Figma Tokens
### Tokens Studio for Figma (formerly known as Figma Tokens)

The primary data for the generation of tokens is based on the json generated from a figma plugin called [Figma Tokens](https://github.com/six7/figma-tokens). This keeps our code in sync with our figma libraries. Currently the token formats are manually generated we are hoping to automate this process in future.
The primary data for the generation of tokens is based on the json generated from a figma plugin called [Tokens Studio for Figma (formerly known as Figma Tokens)](https://github.com/six7/figma-tokens). This keeps our code in sync with our figma libraries. Currently the token formats are manually generated we are hoping to automate this process in future.

### Testing and Linting

Expand Down
71 changes: 61 additions & 10 deletions docs/BrandColors.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,68 @@
import { Meta, Canvas, Story } from '@storybook/addon-docs';
import LinkTo from '@storybook/addon-links/react';
import { Canvas } from '@storybook/blocks';
import * as BrandColorStories from './BrandColors.stories';

<Meta title="Design Tokens/Brand Colors" />
# Brand colors (first tier)

# Brand Colors (first tier)
Brand colors form the foundation of our color system. They use literal color names (like red, green, etc.) and a numeric scale (where 000 is light and 900 is dark) by default. These colors are essential to maintaining visual consistency across our products and are primarily used as a reference for the [theme colors](/docs/colors-theme-colors--docs).

Brand specific colors used in the first tier of design token abstraction. They **should not** be used in the code directly but referenced by [**Theme Colors**](/docs/colors-themecolors--light-theme-colors) used in second tier tokens. Most brand color progressions were generated using [0to255](https://0to255.com/037dd6)
While these colors are fundamental to our design system, they **should not** be used directly in most cases. Instead, they should be referenced via [theme colors](/docs/colors-theme-colors--docs), which form the second tier of our design tokens.

<Canvas>
<Story id="colors-brandcolors--default-story" />
</Canvas>
However, in rare cases where a color needs to remain constant across themes (e.g., white always being white, regardless of light or dark mode), the corresponding brand color can be used. Always ensure there isn't an existing theme token that could be used instead.

_The majority of our brand color progressions were generated using the [0to255](https://0to255.com/037dd6) tool, which helps ensure smooth and consistent color transitions._

- [**Brand colors**](#brand-colors)
- [**Best practices**](#best-practices)
- [**References**](#references)

## Brand colors

<Canvas of={BrandColorStories.DefaultStory} />

## Best Practices

### ✅ **DO**: Use brand colors when the color should remain the same across all themes

```jsx
fill: brandColors.white.white000;
fill: var(--brand-colors-white-white000);
```

### ❌ **DON'T**: Use brand colors without checking for an existing theme token first

```jsx
background-color: brandColors.blue.blue500; // Brand color instead of theme.color.primary.default
background-color: var(--brand-colors-blue-blue500); // Brand color instead of var(--color-primary-default)
```

### ✅ **DO**: Store non-token colors in a global file

If you need to use colors that are not included in the design tokens, store these colors in a global file in your project. This makes it easier to keep track of these colors and update them as needed. Always consider this as a last resort, and strive to use design tokens wherever possible.

```jsx
// colors.js
export const customColors = {
myCustomColor: '#abc123',
};

// colors.css
--custom-colors-my-custom-color: #abc123;

// component.js
import { customColors } from './colors.js';

background-color: customColors.myCustomColor;
background-color: var(--custom-colors-my-custom-color);
```

### ❌ **DON'T**: Use non-token colors directly in your components

```jsx
// Avoid
background-color: #abc123; // Custom color not in design tokens or global file
```

## References

- [Tool used to generate colors](http://www.0to255.com/037DD6)
- [Figma Brand Colors Library](https://www.figma.com/file/cBAUPFMnbv6tHR1J8KvBI2/Brand-Colors?node-id=0%3A1)(internal use only)
- [0to255](http://www.0to255.com/037DD6): The tool we used to generate our color progressions.
- [Figma Brand Colors Library](https://www.figma.com/file/cBAUPFMnbv6tHR1J8KvBI2/Brand-Colors?node-id=0%3A1): Our internal Figma library for brand colors. Please note that this is for internal use only.
25 changes: 11 additions & 14 deletions docs/BrandColors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { ComponentStory, ComponentMeta } from '@storybook/react';
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import tokens from '../src/figma/tokens.json';

import { ColorSwatchGroup } from './components';

import README from './BrandColors.mdx';

export default {
title: 'Colors/BrandColors',
const meta: Meta<typeof ColorSwatchGroup> = {
title: 'Colors/Brand Colors',
component: ColorSwatchGroup,
parameters: {
docs: {
page: README,
},
},
} as ComponentMeta<typeof ColorSwatchGroup>;
};

const Template: ComponentStory<typeof ColorSwatchGroup> = (args) => (
<ColorSwatchGroup {...args} />
);
export default meta;

export const DefaultStory = Template.bind({});
type Story = StoryObj<typeof ColorSwatchGroup>;

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

DefaultStory.storyName = 'Default';
30 changes: 13 additions & 17 deletions docs/IntroductionColor.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { lightTheme } from '../src/index.ts';

# Color

Color is used to express style and communicate meaning.

## Token Tiers

We follow a 3 tiered system for color design tokens.
Color is used to express style and communicate meaning. We follow a 3 tiered system for color design tokens.

<div
style={{
Expand All @@ -23,29 +19,29 @@ We follow a 3 tiered system for color design tokens.
<img width="80%" src={designTokenDiagramImage} />
</div>

<br />
<br />

### **Brand colors** (first tier)
## Brand colors (first tier)

These colors **SHOULD NOT** be used in your component styles directly. They are used as a reference for the [Theme Colors](/docs/colors-themecolors--light-theme-colors). Brand colors are used to keep track of all colors used in our app. See [Brand Colors](/docs/colors-brandcolors--default-story)
Brand colors are the foundation of our color system. They are primarily used as a reference for the [theme colors](/docs/colors-theme-colors--docs) and **should not** be used directly in most component styles.

### **Theme Colors** (second tier)
However, in rare cases where a color needs to remain constant across themes (e.g., white always being white, regardless of light or dark mode), the corresponding brand color can be used. Always ensure there isn't an existing theme token that could be used instead.

These colors are color agnostic, semantically neutral and theme compatible design tokens that you can use in your code and styles. Please refer to the description of each token for it's intended purpose. See [Theme Colors](/docs/colors-themecolors--light-theme-colors)
For more details, refer to the [brand colors](/docs/colors-brand-colors--docs) section.

### **Component colors** (third tier)
## Theme colors (second tier)

Another level of abstraction is component colors that you can use at a component specific level. We do not currently provide any component tier colors but that may change in future.
Theme colors are design tokens that are named based on their function rather than their actual color values. This makes them adaptable to different themes and ensures consistency and accessibility across your project. For most use cases, these function-based theme color tokens should be your first choice.

## Takeaways
For more details, refer to the [theme colors](/docs/colors-theme-colors--docs) section

- Do not use static HEX values in your code. Use the [Theme Colors](/docs/colors-themecolors--light-theme-colors). If one does not exist for your use case [create an issue](https://github.com/MetaMask/design-tokens/issues/new) and tag it with a `color` label.
- Make sure the design token you are using is for it's intended purpose. Please refer to the description of each token.
## Component colors (third tier)

### Next 👉 [Theme Colors](/docs/colors-themecolors--light-theme-colors)
Component colors provide another level of abstraction for component-specific colors. We currently do not provide any component tier colors, but this may change in the future

<br />
## Next steps

Learn more about our [brand colors](/docs/colors-brand-colors--docs) or [theme colors](/docs/colors-theme-colors--docs) section

## References

Expand Down
28 changes: 10 additions & 18 deletions docs/Shadows.mdx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { Meta, Canvas, Story } from '@storybook/addon-docs';
import LinkTo from '@storybook/addon-links/react';
import * as ShadowStories from './Shadows.stories';

<Meta title="Design Tokens/Shadows" />

# Shadows

Shadows convey elevation of elements on a surface
Shadows in design are used to create depth and hierarchy. They can be used to differentiate between different elements, and to highlight interactive elements.

<Canvas>
<Story id="shadows-shadows--shadow" />
</Canvas>
<Canvas of={ShadowStories.DefaultStory} />

## Size

There are 4 different sizes of shadow in MetaMask.
Shadows come in four different sizes: XS, SM, MD, and LG. The size of the shadow can be used to indicate the relative importance or prominence of an element.

<Canvas>
<Story id="shadows-shadows--size" />
</Canvas>
<Canvas of={ShadowStories.Size} />

| Size | JS | CSS |
| ------ | ----------------- | ----------------------- |
Expand All @@ -28,25 +24,21 @@ There are 4 different sizes of shadow in MetaMask.

## Color

As well as the neutral colors for shadow 2 other colors exist that are used for the primary and error/danger button hover states
Shadows can have three different colors: default (neutral), primary, and error/danger. The color of the shadow can be used to indicate the state or functionality of an element.

<Canvas>
<Story id="shadows-shadows--color" />
</Canvas>
<Canvas of={ShadowStories.Color} />

| Color | JS | CSS |
| ----------- | ----------------------- | ----------------------------- |
| **neutral** | `colors.shadow.default` | `var(--color-shadow-default)` |
| **primary** | `colors.primary.shadow` | `var(--color-primary-shadow)` |
| **danger** | `colors.error.shadow` | `var(--color-error-shadow)` |

## Example usage
## Usage

Using both size and color tokens, different shadows can be applied to components.
Shadows can be applied to various components to create depth and hierarchy. Here are some examples of how shadows can be used in different components:

<Canvas>
<Story id="shadows-shadows--example-usage" />
</Canvas>
<Canvas of={ShadowStories.ExampleUsage} />

| Component | JS | CSS |
| ------------------------ | ------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
Expand Down
82 changes: 45 additions & 37 deletions docs/Shadows.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import React from 'react';
import { lightTheme } from '../src/js';

import { Text } from './components';

import README from './Shadows.mdx';

export default {
title: 'Shadows/Shadows',
parameters: {
docs: {
page: README,
},
},
argTypes: {
size: {
control: 'select',
options: Object.keys(lightTheme.shadows.size),
},
color: {
control: 'select',
options: ['default', 'primary', 'error'],
},
},
args: {
color: 'default',
size: 'xs',
},
};

interface ShadowSwatchProps {
children: any;
style?: object;
Expand Down Expand Up @@ -61,8 +36,29 @@ const ShadowSwatch = ({
</div>
);

export const Shadow = (args) => {
return (
export default {
title: 'Shadows/Shadows',
component: ShadowSwatch,
parameters: {
docs: {
page: README,
},
},
argTypes: {
size: {
control: 'select',
options: Object.keys(lightTheme.shadows.size),
},
color: {
control: 'select',
options: ['default', 'primary', 'error'],
},
},
};

export const DefaultStory = {
name: 'Default',
render: (args) => (
<div
style={{
display: 'grid',
Expand All @@ -76,11 +72,15 @@ export const Shadow = (args) => {
</Text>
</ShadowSwatch>
</div>
);
),
args: {
color: 'default',
size: 'xs',
},
};

export const Size = (args) => {
return (
export const Size = {
render: (args) => (
<div
style={{
display: 'grid',
Expand Down Expand Up @@ -109,11 +109,15 @@ export const Size = (args) => {
</Text>
</ShadowSwatch>
</div>
);
),
args: {
color: 'default',
size: 'xs',
},
};

export const Color = (args) => {
return (
export const Color = {
render: (args) => (
<div
style={{
display: 'grid',
Expand Down Expand Up @@ -151,11 +155,15 @@ export const Color = (args) => {
</Text>
</ShadowSwatch>
</div>
);
),
args: {
color: 'default',
size: 'xs',
},
};

export const ExampleUsage = () => {
return (
export const ExampleUsage = {
render: () => (
<div>
<div
style={{
Expand Down Expand Up @@ -233,5 +241,5 @@ export const ExampleUsage = () => {
</ShadowSwatch>
</div>
</div>
);
),
};
Loading
Loading