@codecademy/styleguide 79.2.4-alpha.b2bca8.0 → 79.2.4-alpha.be71e3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/components/ImageWrapper.tsx +2 -4
- package/.storybook/preview.ts +22 -2
- package/CHANGELOG.md +1 -1
- package/package.json +2 -2
- package/src/lib/Meta/About.mdx +5 -5
- package/src/lib/Meta/{Best Practices.mdx → Best practices.mdx } +3 -3
- package/src/lib/Meta/Gamut writing guide/About.mdx +43 -0
- package/src/lib/Meta/Gamut writing guide/Documentation in code.mdx +134 -0
- package/src/lib/Meta/Gamut writing guide/Formatting.mdx +69 -0
- package/src/lib/Meta/Gamut writing guide/General principles.mdx +46 -0
- package/src/lib/Meta/Gamut writing guide/Language and grammar.mdx +54 -0
- package/src/lib/Meta/Gamut writing guide/Linking.mdx +60 -0
- package/src/lib/Meta/Gamut writing guide/Referencing code.mdx +86 -0
- package/src/lib/Meta/Gamut writing guide/Stories/About pages.mdx +49 -0
- package/src/lib/Meta/Gamut writing guide/Stories/About.mdx +57 -0
- package/src/lib/Meta/Gamut writing guide/Stories/Component code examples.mdx +79 -0
- package/src/lib/Meta/{Stories.mdx → Gamut writing guide/Stories/Component story documentation.mdx } +19 -85
- package/src/lib/Meta/{Usage Guide.mdx → Usage guide.mdx } +3 -3
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx +1 -1
- package/src/lib/Organisms/BarChart/BarChart.mdx +0 -463
- package/src/lib/Organisms/BarChart/BarChart.stories.tsx +0 -352
- package/src/static/organisms/barchart.png +0 -0
- /package/src/lib/Meta/{Deep Controls Add-On.mdx → Deep Controls add-on.mdx} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import { AboutHeader, LinkTo } from '~styleguide/blocks';
|
|
4
|
+
|
|
5
|
+
export const parameters = {
|
|
6
|
+
id: 'About pages',
|
|
7
|
+
title: 'About pages',
|
|
8
|
+
subtitle: 'How to create table of contents pages for component folders',
|
|
9
|
+
status: 'static',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
<Meta title="Meta/Gamut writing guide/Stories/About pages" />
|
|
13
|
+
|
|
14
|
+
<AboutHeader {...parameters} />
|
|
15
|
+
|
|
16
|
+
An `About.mdx` file serves as a landing page for folders containing multiple related components or stories. Write a clear overview explaining what the folder contains and how components relate. Organize components logically by importance or usage frequency, use descriptive subtitles, and keep it concise—these are entry points, not detailed documentation.
|
|
17
|
+
|
|
18
|
+
## When to create an About page
|
|
19
|
+
|
|
20
|
+
Create an `About.mdx` file when multiple stories are presented in a folder. For example, the <LinkTo id="Atoms/Animations/About">Animation</LinkTo> folder contains an `About.mdx` file with a table of contents that links to specific components — in this case, the <LinkTo id="Atoms/Animations/ExpandInCollapseOut">ExpandInCollapseOut</LinkTo> component and the <LinkTo id="Atoms/Animations/Rotation">Rotation</LinkTo> component.
|
|
21
|
+
|
|
22
|
+
## Basic structure
|
|
23
|
+
|
|
24
|
+
Inside the `About.mdx` file, use the `toc-story` snippet to generate a template. Import the `parameters` object from the respective component's `<ComponentName>.mdx` file and pass it to the `<TableOfContents />` component.
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { parameters as componentNameParameters } from './ComponentName.mdx';
|
|
28
|
+
import { parameters as anotherComponentParameters } from './AnotherComponent.mdx';
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export const parameters = {
|
|
32
|
+
id: 'ParentDir/FolderName',
|
|
33
|
+
title: 'FolderName',
|
|
34
|
+
subtitle: 'Overview of the components in this folder.',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
...
|
|
38
|
+
|
|
39
|
+
<TableOfContents links={addParentPath(parameters.id, [componentNameParameters, anotherComponentParameters]))} />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## The addParentPath function
|
|
43
|
+
|
|
44
|
+
The `addParentPath()` function is used to ensure that the links in the table of contents have the correct IDs, which are derived from the parent path and the component's ID or title.
|
|
45
|
+
|
|
46
|
+
This function takes two arguments:
|
|
47
|
+
|
|
48
|
+
1. The parent path (`parameters.id`) - defines the folder hierarchy
|
|
49
|
+
2. An array of parameter objects from child components/pages
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AboutHeader,
|
|
5
|
+
addParentPath,
|
|
6
|
+
TableOfContents,
|
|
7
|
+
} from '~styleguide/blocks';
|
|
8
|
+
|
|
9
|
+
import { parameters as aboutPagesParameters } from './About pages.mdx';
|
|
10
|
+
import { parameters as componentCodeExamplesParameters } from './Component code examples.mdx';
|
|
11
|
+
import { parameters as componentStoryDocumentationParameters } from './Component story documentation.mdx';
|
|
12
|
+
|
|
13
|
+
export const parameters = {
|
|
14
|
+
id: 'Meta/Gamut writing guide/Stories',
|
|
15
|
+
title: 'Stories',
|
|
16
|
+
subtitle: 'Guidelines and tooling for writing Storybook stories and docs.',
|
|
17
|
+
status: 'static',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
<Meta title="Meta/Gamut writing guide/Stories/About" />
|
|
21
|
+
|
|
22
|
+
<AboutHeader {...parameters} />
|
|
23
|
+
|
|
24
|
+
This guide covers how to write and organize Storybook stories for Gamut components. Use it when creating new component documentation or updating existing stories.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
We've provided a few helpful vscode snippets to help get through boilerplate. To use these start to type these strings in the editor and pick the template and fill out the tab targets.
|
|
29
|
+
|
|
30
|
+
- `component-story`: The default TSX story template for code examples.
|
|
31
|
+
- `component-doc`: The default component documentation template for a component's MDX file.
|
|
32
|
+
- `toc-story`: A simple template for a Table of Contents category page.
|
|
33
|
+
|
|
34
|
+
## File structure and naming
|
|
35
|
+
|
|
36
|
+
When making a new story, there are a few things to keep in mind:
|
|
37
|
+
|
|
38
|
+
- The folder structure is indicative of our flavor of atomic design.
|
|
39
|
+
- The folder struture is identical to the storybook hierarchy generated.
|
|
40
|
+
- For non-component related file names with more than one word, use a space between the words and use sentence case.
|
|
41
|
+
- Example: `General principles.mdx`
|
|
42
|
+
- Component-related files should use kebab-case: `RadialProgress.mdx`
|
|
43
|
+
|
|
44
|
+
First find the right folder for the story in `packages/styleguide/stories` (e.g. `Atoms` | `Molecules` | `Organisms`).
|
|
45
|
+
After finding it, create a new folder with two new files `#{COMPONENT_NAME}.stories.tsx` and `#{COMPONENT_NAME}.mdx`. This folder can also contain examples or other associated utility files.
|
|
46
|
+
|
|
47
|
+
## Learn more
|
|
48
|
+
|
|
49
|
+
Explore the pages below for detailed guidelines on each part of the story structure:
|
|
50
|
+
|
|
51
|
+
<TableOfContents
|
|
52
|
+
links={addParentPath(parameters.id, [
|
|
53
|
+
aboutPagesParameters,
|
|
54
|
+
componentStoryDocumentationParameters,
|
|
55
|
+
componentCodeExamplesParameters,
|
|
56
|
+
])}
|
|
57
|
+
/>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import { AboutHeader } from '~styleguide/blocks';
|
|
4
|
+
|
|
5
|
+
export const parameters = {
|
|
6
|
+
id: 'Component code examples',
|
|
7
|
+
title: 'Component code examples',
|
|
8
|
+
subtitle: 'How to write .stories.tsx files for Gamut components',
|
|
9
|
+
status: 'static',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
<Meta title="Meta/Gamut writing guide/Stories/Component code examples" />
|
|
13
|
+
|
|
14
|
+
<AboutHeader {...parameters} />
|
|
15
|
+
|
|
16
|
+
The `.stories.tsx` file defines the interactive examples and variations of the component. These stories power the Storybook UI and provide developers with working code examples. Use concrete, realistic values in self-contained stories that are easy to copy and paste. Each story should demonstrate one clear variation or behavior.
|
|
17
|
+
|
|
18
|
+
Our guidelines stem from the Storybook, specifically the [Component Story Format (CSF)](https://storybook.js.org/docs/8/api/csf) and [Writing stories in TypeScript](https://storybook.js.org/docs/writing-stories/typescript) documentation. We recommend using these resources for more detailed information.
|
|
19
|
+
|
|
20
|
+
## Basic structure
|
|
21
|
+
|
|
22
|
+
Each component should have a `ComponentName.stories.tsx` file that can use the `component-story` snippet to generate a template that resembles the following:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
// For ComponentName.stories.tsx
|
|
26
|
+
|
|
27
|
+
import { ComponentName } from '@codecademy/gamut';
|
|
28
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
29
|
+
|
|
30
|
+
const meta: Meta<typeof ComponentName> = {
|
|
31
|
+
component: ComponentName,
|
|
32
|
+
args: {
|
|
33
|
+
variant: 'default',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default meta;
|
|
38
|
+
type Story = StoryObj<typeof ComponentName>;
|
|
39
|
+
|
|
40
|
+
export const Default: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
children: <img src="./cinna.jpg" alt="jpeg" />,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const Secondary: Story = {
|
|
47
|
+
args: {
|
|
48
|
+
children: 'Pro Content',
|
|
49
|
+
variant: 'secondary',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Rendered code examples
|
|
55
|
+
|
|
56
|
+
Examples rendered via `<Canvas of={componentName.example} />` are stored in the `componentName.stories.tsx` file.
|
|
57
|
+
|
|
58
|
+
When providing an example, use concretely applicable values. Avoid naming things like foo or bar, instead be opt for values that could be used in a practical setting, e.g. if deciding on the name of a boolean variable, don't use isBar — instead, consider the setting the example could be used, isModalOpen.
|
|
59
|
+
|
|
60
|
+
When a user clicks **Show Code**, Storybook tries to show the underlying code, but Storybook is not good with abstractions. Instead of opting to be DRY, each example should contain all the code to render and when a user clicks on **Show Code**, they should be able to copy the code provided and render in their own project.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
// ❌ Don't abstract the logic into an InfoTipExample
|
|
64
|
+
export const Default: Story = {
|
|
65
|
+
render: (args) => <InfoTipExample {...args} />,
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
// ✅ Provide the actual code
|
|
71
|
+
export const Default: Story = {
|
|
72
|
+
render: (args) => (
|
|
73
|
+
<FlexBox center m={24} py={64}>
|
|
74
|
+
<Text mr={4}>Some text that needs info</Text>
|
|
75
|
+
<InfoTip {...args} />
|
|
76
|
+
</FlexBox>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
```
|
package/src/lib/Meta/{Stories.mdx → Gamut writing guide/Stories/Component story documentation.mdx }
RENAMED
|
@@ -1,67 +1,32 @@
|
|
|
1
1
|
import { Meta } from '@storybook/blocks';
|
|
2
2
|
|
|
3
|
-
import { AboutHeader
|
|
3
|
+
import { AboutHeader } from '~styleguide/blocks';
|
|
4
4
|
|
|
5
5
|
export const parameters = {
|
|
6
|
-
id: '
|
|
7
|
-
title: '
|
|
8
|
-
subtitle: '
|
|
6
|
+
id: 'Component story documentation',
|
|
7
|
+
title: 'Component story documentation',
|
|
8
|
+
subtitle: 'How to write .mdx documentation files for Gamut components',
|
|
9
9
|
status: 'static',
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
<Meta title="Meta/Stories" />
|
|
12
|
+
<Meta title="Meta/Gamut writing guide/Stories/Component story documentation" />
|
|
13
13
|
|
|
14
14
|
<AboutHeader {...parameters} />
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
The `.mdx` file provides the documentation structure and context for the component. It combines the interactive stories from the `.stories.tsx` file with written documentation, usage guidelines, and metadata.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- `component-story`: The default TSX story template.
|
|
21
|
-
- `component-doc`: The default component documentation template - each component should have a `.tsx` and `.mdx` file.
|
|
22
|
-
- `toc-story`: A simple template for a Table of Contents category page.
|
|
23
|
-
|
|
24
|
-
## File structure and naming
|
|
25
|
-
|
|
26
|
-
When you make a new story theres a few things to keep in mind:
|
|
27
|
-
|
|
28
|
-
- The folder structure is indicative of our flavor of atomic design.
|
|
29
|
-
- The folder struture is identical to the storybook hierarchy generated.
|
|
30
|
-
|
|
31
|
-
First find the right folder for your story in `packages/styleguide/stories` (e.g. `Atoms` | `Molecules` | `Organisms`).
|
|
32
|
-
Once you've found it create a new folder with two new files `#{COMPONENT_NAME}.stories.tsx` and `#{COMPONENT_NAME}.mdx`. You can also store examples or other associated utility files in this folder.
|
|
33
|
-
|
|
34
|
-
In your new files you can use the above snippets to set up your component add:
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
// For ComponentName.stories.tsx
|
|
38
|
-
|
|
39
|
-
import { ComponentName } from '@codecademy/gamut';
|
|
40
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
18
|
+
## Story structure
|
|
41
19
|
|
|
42
|
-
|
|
43
|
-
component: ComponentName,
|
|
44
|
-
args: {
|
|
45
|
-
variant: 'default',
|
|
46
|
-
},
|
|
47
|
-
};
|
|
20
|
+
In our opinion, a good component story page consists of:
|
|
48
21
|
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
1. **General Information:** Each component should define some key information on the `<Meta />` component
|
|
23
|
+
2. **Flagship Story + Props:** A single default story showing the default state of the component with a connected props table right below it.
|
|
24
|
+
3. **Variation Stories:** Granular subsections that show the discrete varaitions of the component and describe their use cases
|
|
25
|
+
4. **Usage instructions and Guidelines:** A section that describes how to use the component should and shouldn't be used, and any guidelines that should be followed.
|
|
51
26
|
|
|
52
|
-
|
|
53
|
-
args: {
|
|
54
|
-
children: <img src="./cinna.jpg" alt="jpeg" />,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
27
|
+
## Basic structure
|
|
57
28
|
|
|
58
|
-
|
|
59
|
-
args: {
|
|
60
|
-
children: 'Pro Content',
|
|
61
|
-
variant: 'secondary',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
```
|
|
29
|
+
Each component should have a `ComponentName.mdx` file that can use the `component-doc` snippet to generate a template that resembles the following:
|
|
65
30
|
|
|
66
31
|
```tsx
|
|
67
32
|
// For ComponentName.mdx, more details in the component-doc code snippet
|
|
@@ -97,16 +62,9 @@ export const parameters = {
|
|
|
97
62
|
Etc...
|
|
98
63
|
```
|
|
99
64
|
|
|
100
|
-
##
|
|
65
|
+
## General information
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
1. **General Information:** Each component should define some key information on the `<Meta />` component
|
|
105
|
-
2. **Flagship Story + Props:** A single default story showing the default state of the component with a connected props table right below it.
|
|
106
|
-
3. **Variation Stories:** Granular subsections that show the discrete varaitions of the component and describe their use cases
|
|
107
|
-
4. **Usage instructions and Guidelines:** A section that describes how to use the component should and shouldn't be used, and any guidelines that should be followed.
|
|
108
|
-
|
|
109
|
-
### General information
|
|
67
|
+
Each component should define key metadata in the `parameters` object:
|
|
110
68
|
|
|
111
69
|
1. `title`: The name of the component, this helps with linking to the story.
|
|
112
70
|
2. `subtitle`: What the component does, and what the component would typically be used for.
|
|
@@ -141,9 +99,9 @@ export const parameters = {
|
|
|
141
99
|
|
|
142
100
|
```
|
|
143
101
|
|
|
144
|
-
|
|
102
|
+
## Flagship story
|
|
145
103
|
|
|
146
|
-
The Flagship story for a component should be intended to give the reader a broad overview of its high-level functionality. Its `Canvas` should automatically display the story's code by setting the prop sourceState="shown"
|
|
104
|
+
The Flagship story for a component should be intended to give the reader a broad overview of its high-level functionality. Its `Canvas` should automatically display the story's code by setting the prop `sourceState="shown"`.
|
|
147
105
|
|
|
148
106
|
Try to include the major behaviors for the component that most readers would need to understand its uses.
|
|
149
107
|
|
|
@@ -156,7 +114,7 @@ Try to include the major behaviors for the component that most readers would nee
|
|
|
156
114
|
<Controls />
|
|
157
115
|
```
|
|
158
116
|
|
|
159
|
-
|
|
117
|
+
## Granular stories
|
|
160
118
|
|
|
161
119
|
Each subsequent story should elaborate on an important behavioral feature of the component.
|
|
162
120
|
Try to show a single use of the behavior configurable with args.
|
|
@@ -169,27 +127,3 @@ A short description should go here, as well as any variant specific usage guidel
|
|
|
169
127
|
<Canvas of={AnchorStories.Variant} />
|
|
170
128
|
|
|
171
129
|
```
|
|
172
|
-
|
|
173
|
-
### About pages
|
|
174
|
-
|
|
175
|
-
An `About.mdx` file should be be included when multiple stories are presented in a folder. E.g. the <LinkTo id="Atoms/Animations/About">Animation</LinkTo> folder which contains an `About.mdx` file with a table of contents that link to specific components -- in this case, the <LinkTo id="Atoms/Animations/ExpandInCollapseOut">ExpandInCollapseOut</LinkTo> component and the <LinkTo id="Atoms/Animations/Rotation">Rotation</LinkTo> component.
|
|
176
|
-
|
|
177
|
-
Inside the `About.mdx` file, import the `parameters` object from the respective component's `<ComponentName>.mdx` file and pass it to the `<TableOfContents />` component.
|
|
178
|
-
|
|
179
|
-
```tsx
|
|
180
|
-
import { parameters as componentNameParameters } from './ComponentName.mdx';
|
|
181
|
-
import { parameters as anotherComponentParameters } from './AnotherComponent.mdx';
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
export const parameters = {
|
|
185
|
-
id: 'ParentDir/FolderName',
|
|
186
|
-
title: 'FolderName',
|
|
187
|
-
subtitle: 'Overview of the components in this folder.',
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
...
|
|
191
|
-
|
|
192
|
-
<TableOfContents links={addParentPath(parameters.id, [componentNameParameters, anotherComponentParameters]))} />
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
The `addParentPath` function is used to ensure that the links in the table of contents have the correct IDs, which are derived from the parent path and the component's ID or title.
|
|
@@ -3,14 +3,14 @@ import { Meta } from '@storybook/blocks';
|
|
|
3
3
|
import { AboutHeader, Callout, ImageWrapper, LinkTo } from '~styleguide/blocks';
|
|
4
4
|
|
|
5
5
|
export const parameters = {
|
|
6
|
-
id: 'Usage
|
|
7
|
-
title: 'Usage
|
|
6
|
+
id: 'Usage guide',
|
|
7
|
+
title: 'Usage guide',
|
|
8
8
|
subtitle:
|
|
9
9
|
'Tips and tricks to using the Gamut Storybook as a user and developer.',
|
|
10
10
|
status: 'static',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
<Meta title="Meta/Usage
|
|
13
|
+
<Meta title="Meta/Usage guide" />
|
|
14
14
|
|
|
15
15
|
<AboutHeader {...parameters} />
|
|
16
16
|
|
|
@@ -11,7 +11,7 @@ export const parameters = {
|
|
|
11
11
|
type: 'figma',
|
|
12
12
|
url: 'https://www.figma.com/file/ReGfRNillGABAj5SlITalN/branch/ayKNSg6QvZUjsgw0FFysW4/%F0%9F%93%90-Gamut?type=design&node-id=41538-55277&mode=design&t=fGkWf5GSl5cj5fQo-0',
|
|
13
13
|
},
|
|
14
|
-
status: '
|
|
14
|
+
status: 'updating',
|
|
15
15
|
source: {
|
|
16
16
|
repo: 'gamut',
|
|
17
17
|
githubLink:
|