@codecademy/styleguide 79.2.4-alpha.38d1e4.0 → 79.2.4-alpha.9ce37a.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 +4 -2
- package/.storybook/preview.ts +2 -22
- 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/Stories/Component story documentation.mdx → Stories.mdx} +85 -19
- 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 +463 -0
- package/src/lib/Organisms/BarChart/BarChart.stories.tsx +352 -0
- package/src/static/organisms/barchart.png +0 -0
- package/src/lib/Meta/Gamut writing guide/About.mdx +0 -43
- package/src/lib/Meta/Gamut writing guide/Documentation in code.mdx +0 -134
- package/src/lib/Meta/Gamut writing guide/Formatting.mdx +0 -69
- package/src/lib/Meta/Gamut writing guide/General principles.mdx +0 -46
- package/src/lib/Meta/Gamut writing guide/Language and grammar.mdx +0 -54
- package/src/lib/Meta/Gamut writing guide/Linking.mdx +0 -60
- package/src/lib/Meta/Gamut writing guide/Referencing code.mdx +0 -86
- package/src/lib/Meta/Gamut writing guide/Stories/About pages.mdx +0 -49
- package/src/lib/Meta/Gamut writing guide/Stories/About.mdx +0 -57
- package/src/lib/Meta/Gamut writing guide/Stories/Component code examples.mdx +0 -79
- /package/src/lib/Meta/{Deep Controls add-on.mdx → Deep Controls Add-On.mdx} +0 -0
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
2
|
-
|
|
3
|
-
import { AboutHeader, Callout } from '~styleguide/blocks';
|
|
4
|
-
|
|
5
|
-
export const parameters = {
|
|
6
|
-
id: 'Linking',
|
|
7
|
-
title: 'Linking',
|
|
8
|
-
subtitle: 'Best practices for linking within documentation',
|
|
9
|
-
status: 'static',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
<Meta title="Meta/Gamut writing guide/Linking" />
|
|
13
|
-
|
|
14
|
-
<AboutHeader {...parameters} />
|
|
15
|
-
|
|
16
|
-
Use links to help users navigate between related components and resources. This guide covers linking within Storybook, to external sites, and writing clear link text.
|
|
17
|
-
|
|
18
|
-
## Internal Links
|
|
19
|
-
|
|
20
|
-
Use the `LinkTo` component from `~styleguide/blocks` and set the id prop as the story's id value.
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
import { LinkTo } from '~styleguide/blocks';
|
|
24
|
-
<LinkTo id="Meta/Stories">Stories</LinkTo>
|
|
25
|
-
<LinkTo id="Atoms/Animations/About">Animation</LinkTo>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Guidelines:
|
|
29
|
-
|
|
30
|
-
- Link text describes the destination, not the action: "See the [Stories page](#)" not "[See the Stories page](#)"
|
|
31
|
-
- Use descriptive link text that makes sense out of context: "[Stories page](#)" not "[Click here](#)"
|
|
32
|
-
- Link component names to their documentation
|
|
33
|
-
- Verify that the link works correctly
|
|
34
|
-
- 2-3 words minimum for easy clicking
|
|
35
|
-
- Unique link text when multiple links on page
|
|
36
|
-
- Meaningful and descriptive: conveys destination
|
|
37
|
-
- Action-oriented when appropriate: "View the component"
|
|
38
|
-
|
|
39
|
-
## External Links
|
|
40
|
-
|
|
41
|
-
When linking to external resources like official documentation or tools, use the following guidelines.
|
|
42
|
-
|
|
43
|
-
### Markdown Links:
|
|
44
|
-
|
|
45
|
-
Use Markdown for external links. The examples below will open in a new tab:
|
|
46
|
-
|
|
47
|
-
```markdown
|
|
48
|
-
[GitHub Repository](https://github.com/Codecademy/gamut)
|
|
49
|
-
[React Documentation](https://react.dev)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Anchor Component:
|
|
53
|
-
|
|
54
|
-
For more control over the link, use the `Anchor` component. The example below will open in the current tab:
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
<Anchor href="https://github.com/Codecademy/gamut">Gamut Repository</Anchor>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
<Callout text='To open external links in new tabs, use `target="_blank" rel="noreferrer"` together for security. However, avoid forcing this behavior unless necessary — users can choose to open links in new tabs themselves.' />
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks';
|
|
2
|
-
|
|
3
|
-
import { AboutHeader } from '~styleguide/blocks';
|
|
4
|
-
|
|
5
|
-
export const parameters = {
|
|
6
|
-
id: 'Referencing code',
|
|
7
|
-
title: 'Referencing code',
|
|
8
|
-
subtitle: 'Guidelines for referencing code and UI Elements',
|
|
9
|
-
status: 'static',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
<Meta title="Meta/Gamut writing guide/Referencing code" />
|
|
13
|
-
|
|
14
|
-
<AboutHeader {...parameters} />
|
|
15
|
-
|
|
16
|
-
This guide covers how to reference code elements, UI components, file paths, and commands consistently throughout documentation. Following these conventions ensures clarity and maintains a professional, accessible tone across all Gamut documentation.
|
|
17
|
-
|
|
18
|
-
## Code in Text
|
|
19
|
-
|
|
20
|
-
- Use backticks for inline code: `onClick`, `flex-direction`, `Box`, `StrokeButton`, `variant`, `backgroundColor`, etc.
|
|
21
|
-
- File and package names: `Button.tsx`, `package.json`, `@codecademy/gamut`
|
|
22
|
-
- When linking to stories, use Storybook's `<LinkTo />` component
|
|
23
|
-
- Values assigned for props or variables: `true`, `16px`, `null`
|
|
24
|
-
- "The `Box` component" (first mention) → "the component" (subsequent mentions)
|
|
25
|
-
- When plural, the component should stay singular and the “component” is the pluralized, e.g
|
|
26
|
-
- ✅ “These `Box` components are…”
|
|
27
|
-
- ❌ “These `Boxes` are…”
|
|
28
|
-
|
|
29
|
-
## Code samples
|
|
30
|
-
|
|
31
|
-
Code samples help developers understand how to implement components and patterns. Use them to demonstrate real-world usage, not just syntax.
|
|
32
|
-
|
|
33
|
-
### Format:
|
|
34
|
-
|
|
35
|
-
```tsx
|
|
36
|
-
import { StrokeButton } from '@codecademy/gamut';
|
|
37
|
-
export const SimpleButtonExample: React.FC = () => (
|
|
38
|
-
<StrokeButton variant="primary">Click me</StrokeButton>
|
|
39
|
-
);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Guidelines:
|
|
43
|
-
|
|
44
|
-
- Include necessary imports
|
|
45
|
-
- Use realistic, working examples
|
|
46
|
-
- Add comments for complex logic
|
|
47
|
-
- Keep examples focused on one concept
|
|
48
|
-
- Use TypeScript types
|
|
49
|
-
|
|
50
|
-
## Command-Line syntax
|
|
51
|
-
|
|
52
|
-
When documenting commands, use consistent formatting to make them easy to copy and execute. Commands should be ready to run without modification.
|
|
53
|
-
|
|
54
|
-
### Format:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
yarn add @codecademy/gamut-kit
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Guidelines:
|
|
61
|
-
|
|
62
|
-
- Use shell (`sh`) syntax highlighting for commands
|
|
63
|
-
- Don't include command prompt symbols ($, #)
|
|
64
|
-
- Show one command per block unless related
|
|
65
|
-
|
|
66
|
-
## File Paths
|
|
67
|
-
|
|
68
|
-
- Use backticks for file paths: `packages/gamut/src/Button/index.tsx`
|
|
69
|
-
- Use relative paths when contextual (e.g., `./types.ts`)
|
|
70
|
-
- Use paths from workspace root when further clarity is needed (e.g., `packages/gamut/src/Button/index.tsx`)
|
|
71
|
-
- Use "in" for code locations: "in the `componentName.mdx` file"
|
|
72
|
-
|
|
73
|
-
## UI element references
|
|
74
|
-
|
|
75
|
-
When instructing users to interact with the interface, clearly identify what the UI elements are, where to find them, and how to interact with them.
|
|
76
|
-
|
|
77
|
-
### Format:
|
|
78
|
-
|
|
79
|
-
- Bold for UI labels: **Next**, **Back**, **Close**
|
|
80
|
-
- Describe location: "Click the **Theme Switcher** (paintbrush icon)"
|
|
81
|
-
- Use sentence case: "the **Show code** button"
|
|
82
|
-
- Prefer words that aren't specific to input devices
|
|
83
|
-
- Use "click" as a device agnostic verb
|
|
84
|
-
- Avoid directional language:
|
|
85
|
-
- ✅ "the following/adjacent form" or "in the previous section"
|
|
86
|
-
- ❌ "the form on the right" or "in the section above"
|
|
@@ -1,49 +0,0 @@
|
|
|
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/Icons/About">Icons</LinkTo> folder contains an `About.mdx` file with a table of contents that links to more specific information about the icons — in this case, <LinkTo id="Atoms/Icons/Mini">Mini icons</LinkTo> and <LinkTo id="Atoms/Icons/Regular">Regular icons</LinkTo>.
|
|
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
|
|
@@ -1,57 +0,0 @@
|
|
|
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`, etc...).
|
|
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
|
-
/>
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
```
|
|
File without changes
|