@codecademy/styleguide 79.2.4-alpha.be71e3.0 → 79.2.4-alpha.ee1acd.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/Elements/DocsContainer.tsx +2 -2
- package/.storybook/components/Elements/StorySource.tsx +2 -2
- package/.storybook/components/Headers/ComponentHeader.tsx +1 -1
- package/.storybook/main.ts +20 -3
- package/.storybook/manager.ts +1 -1
- package/.storybook/preview.ts +11 -33
- package/.storybook/theming/GamutTheme.ts +1 -1
- package/CHANGELOG.md +5 -2
- package/package.json +2 -2
- package/project.json +9 -0
- package/src/lib/About.mdx +1 -1
- package/src/lib/Atoms/About.mdx +1 -1
- package/src/lib/Atoms/Animations/About.mdx +1 -1
- package/src/lib/Atoms/Animations/ExpandInCollapseOut/ExpandInCollapseOut.mdx +1 -1
- package/src/lib/Atoms/Animations/FadeInSlideOut/FadeInSlideOut.mdx +1 -1
- package/src/lib/Atoms/Animations/Rotation/Rotation.mdx +1 -1
- package/src/lib/Atoms/Badge/Badge.mdx +1 -1
- package/src/lib/Atoms/Buttons/About.mdx +1 -1
- package/src/lib/Atoms/Buttons/Button/Button.mdx +1 -1
- package/src/lib/Atoms/Buttons/CTAButton/CTAButton.mdx +1 -1
- package/src/lib/Atoms/Buttons/FillButton/FillButton.mdx +1 -1
- package/src/lib/Atoms/Buttons/IconButton/IconButton.mdx +1 -1
- package/src/lib/Atoms/Buttons/StrokeButton/StrokeButton.mdx +1 -1
- package/src/lib/Atoms/Buttons/TextButton/TextButton.mdx +1 -1
- package/src/lib/Atoms/Card/Card.mdx +1 -1
- package/src/lib/Atoms/Drawer/Drawer.mdx +1 -1
- package/src/lib/Atoms/FeatureShimmer/FeatureShimmer.mdx +1 -1
- package/src/lib/Atoms/FormElements/About.mdx +1 -1
- package/src/lib/Atoms/FormElements/Form/Form.mdx +1 -1
- package/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx +1 -1
- package/src/lib/Atoms/FormElements/FormGroupDescription/FormGroupDescription.mdx +1 -1
- package/src/lib/Atoms/FormElements/FormGroupLabel/FormGroupLabel.mdx +1 -1
- package/src/lib/Atoms/FormElements/FormRequiredText/FormRequiredText.mdx +1 -1
- package/src/lib/Atoms/FormInputs/About.mdx +1 -1
- package/src/lib/Atoms/FormInputs/Checkbox/Checkbox.mdx +1 -1
- package/src/lib/Atoms/FormInputs/Input/Input.mdx +1 -1
- package/src/lib/Atoms/FormInputs/Radio/Radio.mdx +1 -1
- package/src/lib/Atoms/FormInputs/Select/Select.mdx +1 -1
- package/src/lib/Atoms/FormInputs/SelectDropdown/SelectDropdown.mdx +1 -1
- package/src/lib/Atoms/FormInputs/TextArea/TextArea.mdx +1 -1
- package/src/lib/Atoms/Icons/About.mdx +1 -1
- package/src/lib/Atoms/Icons/Mini/Mini.mdx +1 -1
- package/src/lib/Atoms/Icons/Regular/Regular.mdx +1 -1
- package/src/lib/Atoms/Illustrations/Illustrations.mdx +1 -1
- package/src/lib/Atoms/InternalFloatingCard/InternalFloatingCard.mdx +1 -1
- package/src/lib/Atoms/Loaders/About.mdx +1 -1
- package/src/lib/Atoms/Loaders/Shimmer/Shimmer.mdx +1 -1
- package/src/lib/Atoms/Loaders/Spinner/Spinner.mdx +1 -1
- package/src/lib/Atoms/Patterns/Patterns.mdx +1 -1
- package/src/lib/Atoms/PopoverContainer/PopoverContainer.mdx +1 -1
- package/src/lib/Atoms/ProgressBar/ProgressBar.mdx +1 -1
- package/src/lib/Atoms/RadialProgress/RadialProgress.mdx +1 -1
- package/src/lib/Atoms/SkipToContent/SkipToContent.mdx +1 -1
- package/src/lib/Atoms/Tag/Tag.mdx +1 -1
- package/src/lib/Atoms/Toggle/Toggle.mdx +1 -1
- package/src/lib/Atoms/UtilityComponents/About.mdx +1 -1
- package/src/lib/Atoms/UtilityComponents/DelayedRenderWrapper/DelayedRenderWrapper.mdx +1 -1
- package/src/lib/Atoms/UtilityComponents/FocusTrap/FocusTrap.mdx +1 -1
- package/src/lib/Foundations/About.mdx +1 -1
- package/src/lib/Foundations/ColorMode/ColorMode.mdx +1 -1
- package/src/lib/Foundations/Layout.mdx +1 -1
- package/src/lib/Foundations/System/About.mdx +1 -1
- package/src/lib/Foundations/System/Compose.mdx +1 -1
- package/src/lib/Foundations/System/Props/About.mdx +1 -1
- package/src/lib/Foundations/System/Props/Background.mdx +1 -1
- package/src/lib/Foundations/System/Props/Border.mdx +1 -1
- package/src/lib/Foundations/System/Props/Color.mdx +1 -1
- package/src/lib/Foundations/System/Props/Flex.mdx +1 -1
- package/src/lib/Foundations/System/Props/Grid.mdx +1 -1
- package/src/lib/Foundations/System/Props/Layout.mdx +1 -1
- package/src/lib/Foundations/System/Props/List.mdx +1 -1
- package/src/lib/Foundations/System/Props/Positioning.mdx +1 -1
- package/src/lib/Foundations/System/Props/Shadow.mdx +1 -1
- package/src/lib/Foundations/System/Props/Space.mdx +1 -1
- package/src/lib/Foundations/System/Props/Typography.mdx +1 -1
- package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.mdx +1 -1
- package/src/lib/Foundations/System/Variants.mdx +1 -1
- package/src/lib/Foundations/Theme/About.mdx +1 -1
- package/src/lib/Foundations/Theme/AdminTheme.mdx +1 -1
- package/src/lib/Foundations/Theme/CoreTheme.mdx +1 -1
- package/src/lib/Foundations/Theme/CreatingThemes.mdx +1 -1
- package/src/lib/Foundations/Theme/LXStudioTheme.mdx +1 -1
- package/src/lib/Foundations/Theme/PercipioTheme.mdx +1 -1
- package/src/lib/Foundations/Theme/PlatformTheme.mdx +1 -1
- package/src/lib/Foundations/Typography.mdx +1 -1
- package/src/lib/Foundations/Utilities/Utilities.mdx +1 -1
- package/src/lib/Layouts/About.mdx +1 -1
- package/src/lib/Layouts/Boxes/About.mdx +1 -1
- package/src/lib/Layouts/Boxes/Box/Box.mdx +1 -1
- package/src/lib/Layouts/Boxes/FlexBox/FlexBox.mdx +1 -1
- package/src/lib/Layouts/Boxes/GridBox/GridBox.mdx +1 -1
- package/src/lib/Layouts/ContentContainer/ContentContainer.mdx +1 -1
- package/src/lib/Layouts/LayoutGrid/LayoutGrid.mdx +1 -1
- package/src/lib/Meta/About.mdx +6 -6
- package/src/lib/Meta/{Best practices.mdx → Best Practices.mdx } +4 -4
- package/src/lib/Meta/Brand.mdx +1 -1
- package/src/lib/Meta/Contributing.mdx +1 -1
- package/src/lib/Meta/{Deep Controls add-on.mdx → Deep Controls Add-On.mdx } +1 -1
- package/src/lib/Meta/ESLint rules.mdx +1 -1
- package/src/lib/Meta/FAQs.mdx +1 -1
- package/src/lib/Meta/Installation.mdx +1 -1
- package/src/lib/Meta/Logical and physical CSS properties.mdx +1 -1
- package/src/lib/Meta/MCP/About.mdx +1 -1
- package/src/lib/Meta/MCP/Code Connect.mdx +1 -1
- package/src/lib/Meta/MCP/Figma MCP.mdx +1 -1
- package/src/lib/Meta/{Gamut writing guide/Stories/Component story documentation.mdx → Stories.mdx} +88 -22
- package/src/lib/Meta/{Usage guide.mdx → Usage Guide.mdx } +4 -4
- package/src/lib/Molecules/About.mdx +1 -1
- package/src/lib/Molecules/AccordionButtonDeprecated/AccordionButtonDeprecated.mdx +1 -1
- package/src/lib/Molecules/AccordionDeprecated/AccordionDeprecated.mdx +1 -1
- package/src/lib/Molecules/Alert/Alert.mdx +1 -1
- package/src/lib/Molecules/Breadcrumbs/Breadcrumbs.mdx +1 -1
- package/src/lib/Molecules/Coachmark/Coachmark.mdx +1 -1
- package/src/lib/Molecules/Disclosure/Disclosure.mdx +1 -1
- package/src/lib/Molecules/Flyout/Flyout.mdx +1 -1
- package/src/lib/Molecules/Menu/Menu.mdx +1 -1
- package/src/lib/Molecules/Modals/About.mdx +1 -1
- package/src/lib/Molecules/Modals/Dialog/Dialog.mdx +1 -1
- package/src/lib/Molecules/Modals/Modal/Modal.mdx +1 -1
- package/src/lib/Molecules/Modals/Overlay/Overlay.mdx +1 -1
- package/src/lib/Molecules/Pagination/Pagination.mdx +1 -1
- package/src/lib/Molecules/Popover/Popover.mdx +1 -1
- package/src/lib/Molecules/Tabs/Tabs.mdx +1 -1
- package/src/lib/Molecules/Tips/About.mdx +1 -1
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx +1 -1
- package/src/lib/Molecules/Tips/PreviewTip/PreviewTip.mdx +1 -1
- package/src/lib/Molecules/Tips/ToolTip/ToolTip.mdx +1 -1
- package/src/lib/Molecules/Toasts/About.mdx +1 -1
- package/src/lib/Molecules/Toasts/Toast/Toast.mdx +1 -1
- package/src/lib/Molecules/Toasts/Toaster/Toaster.mdx +1 -1
- package/src/lib/Molecules/Video/Video.mdx +1 -1
- package/src/lib/Organisms/About.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/About.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/ConnectedForm/ConnectedForm.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/ConnectedForm/ConnectedForm.stories.tsx +1 -1
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx +1 -1
- package/src/lib/Organisms/ConnectedForm/ConnectedFormInputs/ConnectedFormInputs.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/SubmitButton/SubmitButton.mdx +1 -1
- package/src/lib/Organisms/ConnectedForm/SubmitButton/SubmitButton.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/About.mdx +1 -1
- package/src/lib/Organisms/GridForm/Buttons.mdx +1 -1
- package/src/lib/Organisms/GridForm/Buttons.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/Fields.mdx +1 -1
- package/src/lib/Organisms/GridForm/Fields.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/Layout.mdx +1 -1
- package/src/lib/Organisms/GridForm/Layout.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/States.mdx +1 -1
- package/src/lib/Organisms/GridForm/States.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/Usage.mdx +1 -1
- package/src/lib/Organisms/GridForm/Usage.stories.tsx +1 -1
- package/src/lib/Organisms/GridForm/Validation.mdx +1 -1
- package/src/lib/Organisms/Lists & Tables/About.mdx +1 -1
- package/src/lib/Organisms/Lists & Tables/DataList/DataList.mdx +1 -1
- package/src/lib/Organisms/Lists & Tables/DataTable/DataTable.mdx +1 -1
- package/src/lib/Organisms/Lists & Tables/List/List.mdx +1 -1
- package/src/lib/Organisms/Markdown/Markdown.mdx +1 -1
- package/src/lib/Typography/About.mdx +1 -1
- package/src/lib/Typography/Anchor/Anchor.mdx +1 -1
- package/src/lib/Typography/HiddenText/HiddenText.mdx +1 -1
- package/src/lib/Typography/Text/Text.mdx +1 -1
- package/src/lib/UX Writing/About.mdx +1 -1
- package/src/lib/UX Writing/Accessibility guidelines.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/About.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Alerts.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Alternative text.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Buttons.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Confirmation dialogs.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Error messages.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Notifications.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Toasts.mdx +1 -1
- package/src/lib/UX Writing/Component guidelines/Tooltips.mdx +1 -1
- package/src/lib/UX Writing/DIY UX writing in 8 steps.mdx +1 -1
- 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
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
useConnectedForm,
|
|
13
13
|
} from '@codecademy/gamut';
|
|
14
14
|
import { MiniArrowRightIcon, TerminalIcon } from '@codecademy/gamut-icons';
|
|
15
|
-
import { action } from '@storybook/addon-actions';
|
|
16
15
|
import type { Meta } from '@storybook/react';
|
|
17
16
|
import { useState } from 'react';
|
|
17
|
+
import { action } from 'storybook/actions';
|
|
18
18
|
|
|
19
19
|
const meta: Meta<typeof ConnectedForm> = {
|
|
20
20
|
component: ConnectedForm,
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
Text,
|
|
8
8
|
useConnectedForm,
|
|
9
9
|
} from '@codecademy/gamut';
|
|
10
|
-
import { action } from '@storybook/addon-actions';
|
|
11
10
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
11
|
+
import { action } from 'storybook/actions';
|
|
12
12
|
import type { TypeWithDeepControls } from 'storybook-addon-deep-controls';
|
|
13
13
|
|
|
14
14
|
import { infotipNestedArgTypes } from '~styleguide/argTypes';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConnectedForm, FlexBox, SubmitButton, Text } from '@codecademy/gamut';
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { action } from 'storybook/actions';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof SubmitButton> = {
|
|
6
6
|
component: SubmitButton,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormGroup, GridForm, Input, Text } from '@codecademy/gamut';
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { action } from 'storybook/actions';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof GridForm> = {
|
|
6
6
|
component: GridForm,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GridForm, Markdown } from '@codecademy/gamut';
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { action } from 'storybook/actions';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof GridForm> = {
|
|
6
6
|
component: GridForm,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GridForm } from '@codecademy/gamut';
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
3
|
import { useState } from 'react';
|
|
4
|
+
import { action } from 'storybook/actions';
|
|
5
5
|
|
|
6
6
|
const meta: Meta<typeof GridForm> = {
|
|
7
7
|
component: GridForm,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GridForm } from '@codecademy/gamut';
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { action } from 'storybook/actions';
|
|
4
4
|
import type { TypeWithDeepControls } from 'storybook-addon-deep-controls';
|
|
5
5
|
|
|
6
6
|
const meta: TypeWithDeepControls<Meta<typeof GridForm>> = {
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
/>
|
|
@@ -1,134 +0,0 @@
|
|
|
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
|
-
- 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
|