-
Notifications
You must be signed in to change notification settings - Fork 31
docs: Add Gamut writing guide #3197
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
Open
LinKCoding
wants to merge
30
commits into
main
Choose a base branch
from
kl-gmt-157
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+730
−98
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a2ef92b
started foundation for style guide
LinKCoding be93a53
round out docs
LinKCoding 6acf546
QA'd
LinKCoding 41ac0da
formatted
LinKCoding 5637dea
Update packages/styleguide/src/lib/Meta/Style Guide/Component Pages.mdx
LinKCoding 60f0a66
Update packages/styleguide/src/lib/Meta/Style Guide/Component Pages.mdx
LinKCoding d094255
Update packages/styleguide/src/lib/Meta/Style Guide/Computer Interfac…
LinKCoding 5a55840
Merge branch 'main' into kl-gmt-157
LinKCoding 70901b8
apply Amy's and Cass's feedback
LinKCoding bc10713
renaming files
LinKCoding 369bdca
Merge branch 'main' into kl-gmt-157
LinKCoding 94530ee
applied some feedback
LinKCoding 459414b
more feedback
LinKCoding fe22d3d
more feedback
LinKCoding 2d59049
more feedback and re-org some pages
LinKCoding e657bb2
re-orged Stories.mdx
LinKCoding 13c5f17
more feedback
LinKCoding b6ce364
formatted
LinKCoding 14d8a28
more feedback
LinKCoding fa9464d
more touch ups
LinKCoding b2b51d2
more clean up
LinKCoding 818c26d
one more sentence casing
LinKCoding 06aa6b0
merged main
LinKCoding 9e5ab02
Merge branch 'main' into kl-gmt-157
LinKCoding 277ac2e
address Cass's feedback
LinKCoding caa65a9
updated writing guide docs according to feedback and edited sentences…
LinKCoding 78cb3ac
Merge branch 'main' into kl-gmt-157
LinKCoding ddf2113
Merge branch 'main' into kl-gmt-157
LinKCoding 91f4726
fix import
LinKCoding dbb5e09
Merge branch 'main' into kl-gmt-157
LinKCoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
packages/styleguide/src/lib/Meta/Gamut writing guide/About.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { Meta } from '@storybook/blocks'; | ||
|
|
||
| import { | ||
| AboutHeader, | ||
| addParentPath, | ||
| LinkTo, | ||
| TableOfContents, | ||
| } from '~styleguide/blocks'; | ||
|
|
||
| import { parameters as documentationInCodeParameters } from './Documentation in code.mdx'; | ||
| import { parameters as formattingParameters } from './Formatting.mdx'; | ||
| import { parameters as generalPrinciplesParameters } from './General principles.mdx'; | ||
| import { parameters as languageAndGrammarParameters } from './Language and grammar.mdx'; | ||
| import { parameters as linkingParameters } from './Linking.mdx'; | ||
| import { parameters as referencingCodeParameters } from './Referencing code.mdx'; | ||
| import { parameters as storiesParameters } from './Stories/About.mdx'; | ||
|
|
||
| export const parameters = { | ||
| id: 'Meta/Gamut writing guide', | ||
| title: 'Gamut writing guide', | ||
| subtitle: | ||
| 'Guidelines and standards for creating consistent, clear, and effective documentation.', | ||
| }; | ||
|
|
||
| <Meta title="Meta/Gamut writing guide/About" /> | ||
|
|
||
| <AboutHeader {...parameters} /> | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| <TableOfContents | ||
| links={addParentPath(parameters.id, [ | ||
| generalPrinciplesParameters, | ||
| documentationInCodeParameters, | ||
| formattingParameters, | ||
| languageAndGrammarParameters, | ||
| linkingParameters, | ||
| referencingCodeParameters, | ||
| storiesParameters, | ||
| ])} | ||
| /> |
134 changes: 134 additions & 0 deletions
134
packages/styleguide/src/lib/Meta/Gamut writing guide/Documentation in code.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { Meta } from '@storybook/blocks'; | ||
|
|
||
| import { ComponentHeader } from '~styleguide/blocks'; | ||
|
|
||
| export const parameters = { | ||
| title: 'Documentation in code', | ||
| subtitle: `Guidelines for documenting code in Gamut component files`, | ||
| status: 'current', | ||
| }; | ||
|
|
||
| <Meta title="Meta/Gamut writing guide/Documentation in code" /> | ||
|
|
||
| <ComponentHeader {...parameters} /> | ||
|
|
||
| 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. | ||
|
|
||
| ## Naming conventions | ||
|
|
||
| Clear, descriptive names reduce the need for comments and make code self-documenting. Choose names that reveal intent and follow established patterns. | ||
|
|
||
| ### Variables and constants | ||
|
|
||
| - Use `camelCase` for variables: `userName`, `isLoading`, `itemCount` | ||
| - Use descriptive names that reveal purpose: `filteredResults` not `arr` | ||
| - Boolean variables should use `is`, `has`, `should`, or `can` prefixes: `isVisible`, `hasError`, `shouldRender` | ||
| - Use `SCREAMING_SNAKE_CASE` for true constants: `MAX_RETRY_COUNT`, `DEFAULT_TIMEOUT` | ||
| - Avoid single-letter names except for short loops or mathematical operations | ||
| - Use plural names for arrays and collections: `users`, `menuItems` | ||
|
|
||
| ### Functions and methods | ||
|
|
||
| - Use `camelCase` for function names: `getUserData`, `calculateTotal`, `handleClick` | ||
| - Start with verbs that describe the action: `get`, `set`, `fetch`, `handle`, `render`, `calculate` | ||
| - Event handlers should use `handle` prefix: `handleSubmit`, `handleClickOutside` | ||
| - Boolean-returning functions should ask a question: `isValidEmail`, `canAccessResource`, `hasPermission` | ||
| - Keep names concise but descriptive: `fetchUserProfile` not `getUserProfileDataFromAPI` | ||
|
|
||
| ### Components | ||
|
|
||
| - Use `PascalCase` for component names: `Button`, `UserProfile`, `NavigationMenu` | ||
| - Name folders to match the component: `Button`, `UserProfile` | ||
| - Subsequently, name files within the folder to match the component: `Button.tsx`, `UserProfile.tsx` | ||
| - Use descriptive names that indicate purpose: `SkipToContent`, `RadialProgress`, `Toggle` | ||
| - Avoid generic names like `Component`, `Container`, `Wrapper` without context | ||
|
|
||
| ## Code comments | ||
|
|
||
| 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. | ||
|
|
||
| ### When to comment | ||
|
|
||
| - **Complex logic**: Explain algorithms or non-obvious implementations | ||
|
|
||
| ```tsx | ||
| // Use binary search for O(log n) performance on sorted arrays | ||
| const index = binarySearch(sortedArray, target); | ||
| ``` | ||
|
|
||
| - **Business logic**: Document requirements or constraints | ||
|
|
||
| ```tsx | ||
| // Per WCAG 2.2, focus must return to trigger element on close | ||
| previousFocusRef.current?.focus(); | ||
| ``` | ||
|
|
||
| - **Workarounds**: Explain temporary fixes or browser-specific code | ||
|
|
||
| ```tsx | ||
| // Safari doesn't support :focus-visible, fallback to :focus | ||
| // TODO: Remove when Safari 15+ is minimum supported version | ||
| ``` | ||
|
|
||
| - **Non-obvious decisions**: Clarify choices that might seem strange | ||
| ```tsx | ||
| // Delay state update to avoid race condition with async validation | ||
| setTimeout(() => setIsValid(true), 0); | ||
| ``` | ||
|
|
||
| ### When NOT to comment | ||
|
|
||
| - **Self-explanatory code**: Good names eliminate the need | ||
|
|
||
| ```tsx | ||
| // ❌ Bad: Comment restates the code | ||
| // Set loading to true | ||
| setIsLoading(true); | ||
|
|
||
| // ✅ Good: Code is self-documenting | ||
| setIsLoading(true); | ||
| ``` | ||
|
|
||
| - **Commented-out code**: Delete it; Git tracks history | ||
| ```tsx | ||
| // ❌ Bad: Dead code clutters the file | ||
| // const oldImplementation = () => { ... }; | ||
| ``` | ||
|
|
||
| ### Comment style | ||
|
|
||
| - Use `//` for single-line comments, add a space after the `//` before commenting | ||
| - Use `/** */` for JSDoc comments on exports (functions, types, components) | ||
| - Write complete sentences with proper punctuation | ||
| - Keep comments up-to-date when code changes | ||
|
|
||
| ## API reference | ||
|
|
||
| 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. | ||
|
|
||
| ### Props documentation: | ||
|
|
||
| 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. | ||
|
|
||
| ```tsx | ||
| export type ButtonProps = { | ||
| /** | ||
| * The visual style variant of the button. | ||
| */ | ||
| variant: 'primary' | 'secondary'; | ||
|
|
||
| /** | ||
| * Whether the button is disabled. | ||
| */ | ||
| disabled?: boolean; | ||
| }; | ||
| ``` | ||
|
|
||
| ### Guidelines: | ||
|
|
||
| - Full sentence descriptions | ||
| - Start boolean descriptions with "Whether" | ||
| - Document required vs. optional props | ||
| - Include type information | ||
| - Use discretion for whether a comment is needed or not | ||
| - If unsure, include a comment |
69 changes: 69 additions & 0 deletions
69
packages/styleguide/src/lib/Meta/Gamut writing guide/Formatting.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { Meta } from '@storybook/blocks'; | ||
|
|
||
| import { AboutHeader } from '~styleguide/blocks'; | ||
|
|
||
| export const parameters = { | ||
| id: 'Formatting', | ||
| title: 'Formatting', | ||
| subtitle: 'Standards for formatting text and content in documentation', | ||
| status: 'static', | ||
| }; | ||
|
|
||
| <Meta title="Meta/Gamut writing guide/Formatting" /> | ||
|
|
||
| <AboutHeader {...parameters} /> | ||
|
|
||
| Consistent formatting makes documentation easier to scan, understand, and implement. These standards ensure our content is predictable and professional across all Gamut components. | ||
|
|
||
| ## Numbers | ||
|
|
||
| - Use numerals for all numbers | ||
| - Use commas for thousands: 1,000 | ||
|
|
||
| ## Units of Measurement | ||
|
|
||
| - Use standard units: px, rem, em, % | ||
| - Include space between number and unit in prose: "16 pixels" | ||
| - No space in code: `16px`, `2rem` | ||
|
|
||
| ## Lists | ||
|
|
||
| Lists help break down complex information into digestible pieces. Use them to organize features, steps, or related concepts. | ||
|
|
||
| ### Bulleted lists: | ||
|
|
||
| - Use for unordered items | ||
| - Use parallel structure | ||
| - End with periods if items are complete sentences | ||
| - No periods if items are fragments | ||
|
|
||
| ### Numbered lists: | ||
|
|
||
| - Use for sequential steps or prioritized items | ||
| - Start each item with a capital letter | ||
|
|
||
| ## Code Blocks | ||
|
|
||
| - Use triple backticks (` ``` `) with language identifier (e.g., `tsx`, `javascript`, `css`) | ||
| - Include comments for complex examples | ||
| - Keep examples concise and focused | ||
|
|
||
| Example: | ||
|
|
||
| ```` | ||
| ```tsx | ||
| <TextButton onClick={handleClick}> Click me </TextButton> | ||
| ``` | ||
| ```` | ||
|
|
||
| ## Headings Hierarchy | ||
LinKCoding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - Start with second-level headings (`<h2>` in HTML, `##` in Markdown). The first level heading is automatically set by the title parameter. | ||
| - Don't skip heading levels. This ensures a logical reading order. | ||
|
|
||
| ## Whitespace | ||
|
|
||
| - Use blank lines to separate sections | ||
| - Don't use multiple consecutive blank lines | ||
| - Indent code consistently (2 spaces for TypeScript/TSX) | ||
LinKCoding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - When using tabs, set them to 2 spaces | ||
46 changes: 46 additions & 0 deletions
46
packages/styleguide/src/lib/Meta/Gamut writing guide/General principles.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Meta } from '@storybook/blocks'; | ||
|
|
||
| import { AboutHeader } from '~styleguide/blocks'; | ||
|
|
||
| export const parameters = { | ||
| id: 'General principles', | ||
| title: 'General principles', | ||
| subtitle: 'Core principles for writing effective documentation', | ||
| status: 'static', | ||
| }; | ||
|
|
||
| <Meta title="Meta/Gamut writing guide/General principles" /> | ||
|
|
||
| <AboutHeader {...parameters} /> | ||
|
|
||
LinKCoding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 usefulness. Whether documenting a new component or updating existing content, prioritize being clear about what something does, honest about its limitations, 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. | ||
|
|
||
| ## Voice and tone | ||
|
|
||
| - Friendly and conversational: Write as if explaining to a colleague | ||
| - Prefer "we" when a pronoun is needed | ||
| - "You" is acceptable when necessary, e.g., "Use your best judgement" | ||
| - Encouraging without overpromising: Be supportive but realistic | ||
| - Global audience awareness: Avoid idioms, slang, and culturally-specific references | ||
|
|
||
| ## Inclusivity | ||
|
|
||
| - Use inclusive language that makes all contributors feel welcome | ||
| - Define terms when first introduced | ||
| - Consider contributors of varying experience levels and roles (designers and developers) | ||
|
|
||
| ## Transparency | ||
|
|
||
| - Clearly indicate component status: | ||
| - `current`: Stable, recommended for use | ||
| - `updating`: In progress, API may change | ||
| - `deprecated`: Still supported but slated for deletion — do not use for new work | ||
| - `static`: Reference material, no active development | ||
| - Link to source code and design files (GitHub, Figma) | ||
|
|
||
| ## Consistency | ||
|
|
||
| - Use a single term for the same concept, including how it's referred to between the heading, body copy, and code examples. | ||
| - Do not use the same term for 2 different concepts. | ||
| - Maintain consistent component naming across packages | ||
| - Follow established patterns from existing components | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.