Skip to content

Commit e7b528d

Browse files
authored
docs: Add Gamut writing guide
Adds a style guide for documentation purposes
1 parent 501092e commit e7b528d

16 files changed

Lines changed: 729 additions & 98 deletions

packages/styleguide/.storybook/preview.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,35 @@ const preview: Preview = {
4545
'Meta',
4646
[
4747
'About',
48-
'Best Practices',
48+
'Brand',
49+
'Best practices',
4950
'Contributing',
51+
'Deep Controls add-on',
5052
'ESLint rules',
5153
'FAQs',
5254
'Logical and physical CSS properties',
5355
'Stories',
5456
'Brand',
5557
'Installation',
56-
'Usage Guide',
58+
'Stories',
59+
'Usage guide',
60+
'Gamut writing guide',
61+
[
62+
'About',
63+
'General principles',
64+
'Documentation in code',
65+
'Formatting',
66+
'Language and grammar',
67+
'Linking',
68+
'Referencing code',
69+
'Stories',
70+
[
71+
'About',
72+
'About pages',
73+
'Component story documentation',
74+
'Component code examples',
75+
],
76+
],
5777
'MCP',
5878
],
5979
'Foundations',

packages/styleguide/src/lib/Meta/About.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import {
66
TableOfContents,
77
} from '~styleguide/blocks';
88

9-
import { parameters as bestPracticesParameters } from './Best Practices.mdx';
9+
import { parameters as bestPracticesParameters } from './Best practices.mdx';
1010
import { parameters as brandParameters } from './Brand.mdx';
1111
import { parameters as contributingParameters } from './Contributing.mdx';
12-
import { parameters as deepControlsParameters } from './Deep Controls Add-On.mdx';
12+
import { parameters as deepControlsParameters } from './Deep Controls add-on.mdx';
1313
import { parameters as eslintRulesParameters } from './ESLint rules.mdx';
1414
import { parameters as faqsParameters } from './FAQs.mdx';
15+
import { parameters as gamutWritingGuideParameters } from './Gamut writing guide/About.mdx';
1516
import { parameters as installationParameters } from './Installation.mdx';
1617
import { parameters as logicalPhysicalParameters } from './Logical and physical CSS properties.mdx';
1718
import { parameters as mcpAboutParameters } from './MCP/About.mdx';
18-
import { parameters as storiesParameters } from './Stories.mdx';
19-
import { parameters as usageGuideParameters } from './Usage Guide.mdx';
19+
import { parameters as usageGuideParameters } from './Usage guide.mdx';
2020

2121
export const parameters = {
2222
id: 'Meta',
@@ -36,9 +36,9 @@ export const parameters = {
3636
deepControlsParameters,
3737
eslintRulesParameters,
3838
faqsParameters,
39+
gamutWritingGuideParameters,
3940
installationParameters,
4041
logicalPhysicalParameters,
41-
storiesParameters,
4242
brandParameters,
4343
usageGuideParameters,
4444
mcpAboutParameters,

packages/styleguide/src/lib/Meta/Best Practices.mdx renamed to packages/styleguide/src/lib/Meta/Best practices.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Meta } from '@storybook/blocks';
33
import { AboutHeader, Callout } from '~styleguide/blocks';
44

55
export const parameters = {
6-
id: 'Best Practices',
7-
title: 'Best Practices',
6+
id: 'Best practices',
7+
title: 'Best practices',
88
subtitle: 'Current best practices for using the Gamut Design System',
99
status: 'current',
1010
};
1111

12-
<Meta title="Meta/Best Practices" />
12+
<Meta title="Meta/Best practices" />
1313

1414
<AboutHeader {...parameters} />
1515

packages/styleguide/src/lib/Meta/Deep Controls Add-On.mdx renamed to packages/styleguide/src/lib/Meta/Deep Controls add-on.mdx

File renamed without changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
import {
4+
AboutHeader,
5+
addParentPath,
6+
LinkTo,
7+
TableOfContents,
8+
} from '~styleguide/blocks';
9+
10+
import { parameters as documentationInCodeParameters } from './Documentation in code.mdx';
11+
import { parameters as formattingParameters } from './Formatting.mdx';
12+
import { parameters as generalPrinciplesParameters } from './General principles.mdx';
13+
import { parameters as languageAndGrammarParameters } from './Language and grammar.mdx';
14+
import { parameters as linkingParameters } from './Linking.mdx';
15+
import { parameters as referencingCodeParameters } from './Referencing code.mdx';
16+
import { parameters as storiesParameters } from './Stories/About.mdx';
17+
18+
export const parameters = {
19+
id: 'Meta/Gamut writing guide',
20+
title: 'Gamut writing guide',
21+
subtitle:
22+
'Guidelines and standards for creating consistent, clear, and effective documentation.',
23+
};
24+
25+
<Meta title="Meta/Gamut writing guide/About" />
26+
27+
<AboutHeader {...parameters} />
28+
29+
Welcome to the Gamut writing guide! Thanks for taking the time to learn about our documentation standards. This guide helps keep our documentation clear, consistent, and useful across the Gamut design system.
30+
31+
The <LinkTo id="Meta/Gamut writing guide/General principles">General principles</LinkTo> is a great place to get an overview of our documentation philosophy and best practices. For specific topics like formatting, code documentation, or writing Storybook stories, check out the other pages below.
32+
33+
<TableOfContents
34+
links={addParentPath(parameters.id, [
35+
generalPrinciplesParameters,
36+
documentationInCodeParameters,
37+
formattingParameters,
38+
languageAndGrammarParameters,
39+
linkingParameters,
40+
referencingCodeParameters,
41+
storiesParameters,
42+
])}
43+
/>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
import { AboutHeader } from '~styleguide/blocks';
4+
5+
export const parameters = {
6+
title: 'Documentation in code',
7+
subtitle: `Guidelines for documenting code in Gamut component files`,
8+
status: 'static',
9+
};
10+
11+
<Meta title="Meta/Gamut writing guide/Documentation in code" />
12+
13+
<AboutHeader {...parameters} />
14+
15+
Good documentation starts in the code itself. By documenting components, props, and functions directly in source files, we create a single source of truth that stays synchronized with the implementation and surfaces automatically in developer tools and Storybook.
16+
17+
## Naming conventions
18+
19+
Clear, descriptive names reduce the need for comments and make code self-documenting. Choose names that reveal intent and follow established patterns.
20+
21+
### Variables and constants
22+
23+
- Use `camelCase` for variables: `userName`, `isLoading`, `itemCount`
24+
- Use descriptive names that reveal purpose: `filteredResults` not `arr`
25+
- Boolean variables should use `is`, `has`, `should`, or `can` prefixes: `isVisible`, `hasError`, `shouldRender`
26+
- Use `SCREAMING_SNAKE_CASE` for true constants: `MAX_RETRY_COUNT`, `DEFAULT_TIMEOUT`
27+
- Avoid single-letter names except for short loops or mathematical operations
28+
- Use plural names for arrays and collections: `users`, `menuItems`
29+
30+
### Functions and methods
31+
32+
- Use `camelCase` for function names: `getUserData`, `calculateTotal`, `handleClick`
33+
- Start with verbs that describe the action: `get`, `set`, `fetch`, `handle`, `render`, `calculate`
34+
- Event handlers should use `handle` prefix: `handleSubmit`, `handleClickOutside`
35+
- Boolean-returning functions should ask a question: `isValidEmail`, `canAccessResource`, `hasPermission`
36+
- Keep names concise but descriptive: `fetchUserProfile` not `getUserProfileDataFromAPI`
37+
38+
### Components
39+
40+
- Use `PascalCase` for component names: `Button`, `UserProfile`, `NavigationMenu`
41+
- Name folders to match the component: `Button`, `UserProfile`
42+
- Subsequently, name files within the folder to match the component: `Button.tsx`, `UserProfile.tsx`
43+
- Use descriptive names that indicate purpose: `SkipToContent`, `RadialProgress`, `Toggle`
44+
- Avoid generic names like `Component`, `Container`, `Wrapper` without context
45+
46+
## Code comments
47+
48+
Comments should explain _why_ code exists, not _what_ it does. Well-named variables and functions handle the "what." Reserve comments for non-obvious decisions, complex logic, and important context.
49+
50+
### When to comment
51+
52+
- **Complex logic**: Explain algorithms or non-obvious implementations
53+
54+
```tsx
55+
// Use binary search for O(log n) performance on sorted arrays
56+
const index = binarySearch(sortedArray, target);
57+
```
58+
59+
- **Business logic**: Document requirements or constraints
60+
61+
```tsx
62+
// Per WCAG 2.2, focus must return to trigger element on close
63+
previousFocusRef.current?.focus();
64+
```
65+
66+
- **Workarounds**: Explain temporary fixes or browser-specific code
67+
68+
```tsx
69+
// Safari doesn't support :focus-visible, fallback to :focus
70+
// TODO: Remove when Safari 15+ is minimum supported version
71+
```
72+
73+
- **Non-obvious decisions**: Clarify choices that might seem strange
74+
```tsx
75+
// Delay state update to avoid race condition with async validation
76+
setTimeout(() => setIsValid(true), 0);
77+
```
78+
79+
### When NOT to comment
80+
81+
- **Self-explanatory code**: Good names eliminate the need
82+
83+
```tsx
84+
// ❌ Bad: Comment restates the code
85+
// Set loading to true
86+
setIsLoading(true);
87+
88+
// ✅ Good: Code is self-documenting
89+
setIsLoading(true);
90+
```
91+
92+
- **Commented-out code**: Delete it; Git tracks history
93+
```tsx
94+
// ❌ Bad: Dead code clutters the file
95+
// const oldImplementation = () => { ... };
96+
```
97+
98+
### Comment style
99+
100+
- Use `//` for single-line comments, add a space after the `//` before commenting
101+
- Use `/** */` for JSDoc comments on exports (functions, types, components)
102+
- Write complete sentences with proper punctuation
103+
- Keep comments up-to-date when code changes
104+
105+
## API reference
106+
107+
Well-documented APIs make components easier to use and understand. Clear prop descriptions and type information help developers implement components correctly without needing to read the source code.
108+
109+
### Props documentation:
110+
111+
Add [JSDoc](https://jsdoc.app/) comments to the props to provide additional clarity for what these props do — these comments is used by TypeScript when hovering over a prop, additional it also shows up in the props table of a component's story in Storybook.
112+
113+
```tsx
114+
export type ButtonProps = {
115+
/**
116+
* The visual style variant of the button.
117+
*/
118+
variant: 'primary' | 'secondary';
119+
120+
/**
121+
* Whether the button is disabled.
122+
*/
123+
disabled?: boolean;
124+
};
125+
```
126+
127+
### Guidelines:
128+
129+
- Use full sentence descriptions
130+
- Start boolean descriptions with "Whether"
131+
- Document required vs. optional props
132+
- Include type information
133+
- Use discretion for whether a comment is needed or not
134+
- If unsure, include a comment
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
import { AboutHeader } from '~styleguide/blocks';
4+
5+
export const parameters = {
6+
id: 'Formatting',
7+
title: 'Formatting',
8+
subtitle: 'Standards for formatting text and content in documentation',
9+
status: 'static',
10+
};
11+
12+
<Meta title="Meta/Gamut writing guide/Formatting" />
13+
14+
<AboutHeader {...parameters} />
15+
16+
Consistent formatting makes documentation easier to scan, understand, and implement. These standards ensure our content is predictable and professional across all Gamut components.
17+
18+
## Numbers
19+
20+
- Use numerals for all numbers
21+
- Use commas for thousands: 1,000
22+
23+
## Units of Measurement
24+
25+
- Use standard units: px, rem, em, %
26+
- Include space between number and unit in prose: "16 pixels"
27+
- No space in code: `16px`, `2rem`
28+
29+
## Lists
30+
31+
Lists help break down complex information into digestible pieces. Use them to organize features, steps, or related concepts.
32+
33+
### Bulleted lists:
34+
35+
- Use for unordered items
36+
- Use parallel structure
37+
- End with periods if items are complete sentences
38+
- No periods if items are fragments
39+
40+
### Numbered lists:
41+
42+
- Use for sequential steps or prioritized items
43+
- Start each item with a capital letter
44+
45+
## Code Blocks
46+
47+
- Use triple backticks (` ``` `) with language identifier (e.g., `tsx`, `javascript`, `css`)
48+
- Include comments for complex examples
49+
- Keep examples concise and focused
50+
51+
Example:
52+
53+
````
54+
```tsx
55+
<TextButton onClick={handleClick}> Click me </TextButton>
56+
```
57+
````
58+
59+
## Headings Hierarchy
60+
61+
- Start with second-level headings (`<h2>` in HTML, `##` in Markdown). The first level heading is automatically set by the title parameter.
62+
- Don't skip heading levels. This ensures a logical reading order.
63+
64+
## Whitespace
65+
66+
- Use blank lines to separate sections
67+
- Don't use multiple consecutive blank lines
68+
- Indent code consistently (2 spaces for TypeScript/TSX)
69+
- When using tabs, set them to 2 spaces
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
import { AboutHeader } from '~styleguide/blocks';
4+
5+
export const parameters = {
6+
id: 'General principles',
7+
title: 'General principles',
8+
subtitle: 'Core principles for writing effective documentation',
9+
status: 'static',
10+
};
11+
12+
<Meta title="Meta/Gamut writing guide/General principles" />
13+
14+
<AboutHeader {...parameters} />
15+
16+
Good documentation does more than describe—it helps people succeed. These principles guide how we write about Gamut components, with a focus on clarity, accessibility, and helpfulness. Whether documenting a new component or updating existing content, prioritize being clear about what something does and honest about its limitations, accessible to the users who will interact with it, and helpful in showing how to use it effectively. We want to remove barriers and make it easier for designers and developers to do great work. Like our design system itself, this guide is a living document—it will continue to evolve as we add new features and learn from our users.
17+
18+
## Voice and tone
19+
20+
- Friendly and conversational: Write as if explaining to a colleague
21+
- Prefer "we" when a pronoun is needed
22+
- "You" is acceptable when necessary, e.g., "Use your best judgement"
23+
- Encouraging without overpromising: Be supportive but realistic
24+
- Global audience awareness: Avoid idioms, slang, and culturally-specific references
25+
26+
## Inclusivity
27+
28+
- Use inclusive language that makes all contributors feel welcome
29+
- Define terms when first introduced
30+
- Consider contributors of varying experience levels and roles (designers and developers)
31+
32+
## Transparency
33+
34+
- Clearly indicate component status:
35+
- `current`: Stable, recommended for use
36+
- `updating`: In progress, API may change
37+
- `deprecated`: Still supported but slated for deletion — do not use for new work
38+
- `static`: Reference material, no active development
39+
- Link to source code and design files (GitHub, Figma)
40+
41+
## Consistency
42+
43+
- Use a single term for the same concept, including how it's referred to between the heading, body copy, and code examples.
44+
- Do not use the same term for 2 different concepts.
45+
- Maintain consistent component naming across packages
46+
- Follow established patterns from existing components

0 commit comments

Comments
 (0)