@codecademy/gamut 68.6.1-alpha.f6b2ce.0 → 68.6.1
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/dist/Modals/elements.d.ts +186 -1
- package/dist/Modals/elements.js +3 -3
- package/dist/{InternalFloatingCard/InternalFloatingCard.d.ts → PatternBackdrop/PatternBackdrop.d.ts} +8 -24
- package/dist/PatternBackdrop/PatternBackdrop.js +42 -0
- package/dist/Toast/Toast.js +4 -4
- package/package.json +8 -11
- package/agent-tools/.claude-plugin/marketplace.json +0 -16
- package/agent-tools/.claude-plugin/plugin.json +0 -7
- package/agent-tools/.cursor-plugin/plugin.json +0 -7
- package/agent-tools/DESIGN.Codecademy.md +0 -696
- package/agent-tools/DESIGN.LXStudio.md +0 -512
- package/agent-tools/DESIGN.Percipio.md +0 -513
- package/agent-tools/DESIGN.md +0 -1
- package/agent-tools/agents/.gitkeep +0 -0
- package/agent-tools/commands/gamut-review.md +0 -259
- package/agent-tools/guidelines/components/animations.md +0 -74
- package/agent-tools/guidelines/components/buttons.md +0 -95
- package/agent-tools/guidelines/components/card.md +0 -19
- package/agent-tools/guidelines/components/coachmark.md +0 -21
- package/agent-tools/guidelines/components/data-table.md +0 -79
- package/agent-tools/guidelines/components/forms.md +0 -106
- package/agent-tools/guidelines/components/loading-states.md +0 -17
- package/agent-tools/guidelines/components/menu.md +0 -58
- package/agent-tools/guidelines/components/overview.md +0 -124
- package/agent-tools/guidelines/components/radial-progress.md +0 -13
- package/agent-tools/guidelines/components/select.md +0 -23
- package/agent-tools/guidelines/components/tooltips.md +0 -22
- package/agent-tools/guidelines/components/video.md +0 -29
- package/agent-tools/guidelines/foundations/color.md +0 -168
- package/agent-tools/guidelines/foundations/modes.md +0 -69
- package/agent-tools/guidelines/foundations/spacing.md +0 -107
- package/agent-tools/guidelines/foundations/typography.md +0 -82
- package/agent-tools/guidelines/overview-icons.md +0 -19
- package/agent-tools/guidelines/overview-illustrations.md +0 -7
- package/agent-tools/guidelines/overview-patterns.md +0 -7
- package/agent-tools/guidelines/overview.md +0 -84
- package/agent-tools/guidelines/setup.md +0 -83
- package/agent-tools/rules/accessibility.mdc +0 -78
- package/agent-tools/skills/gamut-accessibility/SKILL.md +0 -224
- package/agent-tools/skills/gamut-color-mode/SKILL.md +0 -149
- package/agent-tools/skills/gamut-components/SKILL.md +0 -46
- package/agent-tools/skills/gamut-forms/SKILL.md +0 -101
- package/agent-tools/skills/gamut-style-utilities/SKILL.md +0 -111
- package/agent-tools/skills/gamut-system-props/SKILL.md +0 -225
- package/agent-tools/skills/gamut-testing/SKILL.md +0 -225
- package/agent-tools/skills/gamut-theming/SKILL.md +0 -63
- package/agent-tools/skills/gamut-typography/SKILL.md +0 -79
- package/bin/commands/plugin/install.mjs +0 -213
- package/bin/commands/plugin/list.mjs +0 -73
- package/bin/commands/plugin/remove.mjs +0 -108
- package/bin/commands/plugin/update.mjs +0 -59
- package/bin/gamut.mjs +0 -96
- package/bin/lib/claude.mjs +0 -52
- package/bin/lib/cursor.mjs +0 -40
- package/bin/lib/design.mjs +0 -71
- package/bin/lib/io.mjs +0 -14
- package/bin/lib/resolve-plugin-dir.mjs +0 -38
- package/bin/lib/run-command.mjs +0 -22
- package/dist/InternalFloatingCard/InternalFloatingCard.js +0 -98
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-accessibility
|
|
3
|
-
description: Gamut a11y matrix, overlays, FocusTrap, tips, live regions. When invoked, read guidelines/components/buttons.md, menu.md, tooltips.md as needed. Forms: gamut-forms. Cursor: accessibility.mdc.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Gamut Accessibility
|
|
7
|
-
|
|
8
|
-
## Read first
|
|
9
|
-
|
|
10
|
-
When this skill applies, read the linked component guides for widgets you are auditing (not all at once):
|
|
11
|
-
|
|
12
|
-
- [`guidelines/components/buttons.md`](../../guidelines/components/buttons.md)
|
|
13
|
-
- [`guidelines/components/menu.md`](../../guidelines/components/menu.md)
|
|
14
|
-
- [`guidelines/components/tooltips.md`](../../guidelines/components/tooltips.md)
|
|
15
|
-
|
|
16
|
-
Universal rules: [`accessibility.mdc`](../../rules/accessibility.mdc) (Cursor, always-on). Form wiring: `gamut-forms`.
|
|
17
|
-
|
|
18
|
-
Source: `@codecademy/gamut` — `react-aria-components` is used only in [`packages/gamut/src/Tabs/`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/Tabs/) (`Tabs.tsx`, `TabList.tsx`, `Tab.tsx`, `TabPanel.tsx`). `react-focus-on` powers `FocusTrap` ([`packages/gamut/src/FocusTrap/index.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/FocusTrap/index.tsx)), used by overlays such as `Overlay` ([`packages/gamut/src/Overlay/index.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/Overlay/index.tsx)) and `Popover`. Other widgets (e.g. `Menu`, `DatePicker`) implement keyboard and ARIA in Gamut code — verify behavior in Storybook and source, do not assume React Aria.
|
|
19
|
-
|
|
20
|
-
Product-oriented button variants and props: [`guidelines/components/buttons.md`](../../guidelines/components/buttons.md) · Menus: [`guidelines/components/menu.md`](../../guidelines/components/menu.md) · Tooltips: [`guidelines/components/tooltips.md`](../../guidelines/components/tooltips.md)
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Universal rules
|
|
25
|
-
|
|
26
|
-
Prefer native HTML, minimal ARIA, correct roles, visible names, focus visibility, semantic color / `ColorMode`, and Gamut primitives — see the always-loaded Gamut Accessibility Rules: [`accessibility.mdc`](../../rules/accessibility.mdc). This skill adds Gamut component behavior and audit detail below.
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## How Gamut handles accessibility
|
|
31
|
-
|
|
32
|
-
Tabs use `react-aria-components` (see `packages/gamut/src/Tabs/*.tsx`) for roving tabindex and keyboard navigation. Overlays (e.g. `Overlay`, `Popover`) use `FocusTrap` → `react-focus-on` for focus containment and Escape/outside close. Other interactive components (`Menu`, `DatePicker`, `Modal`, `Dialog`, etc.) rely on in-repo implementations — supply accessible names, wire labels to controls, and avoid duplicating what a component already sets (`aria-live`, `aria-describedby`, tabindex, etc.); confirm in source when auditing.
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## Component reference (index)
|
|
37
|
-
|
|
38
|
-
There is no exported `<Button>` — use `FillButton`, `TextButton`, `StrokeButton`, `CTAButton`, and `IconButton` (shared `ButtonProps` type). Prefer these over `<div onClick>` or `<span role="button">`.
|
|
39
|
-
|
|
40
|
-
Forms — `FormGroup`, `ConnectedForm` / `ConnectedFormGroup`, `GridForm`, field atoms (`Select`, `Checkbox`, `Radio`), validation, `aria-live` / `aria-describedby`: canonical reference is [`gamut-forms`](../gamut-forms/SKILL.md).
|
|
41
|
-
|
|
42
|
-
| Component(s) | Handled in library | App / author responsibilities |
|
|
43
|
-
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
44
|
-
| `FillButton`, `TextButton`, `StrokeButton`, `CTAButton` | Render `<button>` (or `<a>` when `href` is set); native click + keyboard activation | Visible text or `href` purpose; follow [`buttons.md`](../../guidelines/components/buttons.md) for variants and `disabled` vs `aria-disabled`. |
|
|
45
|
-
| `IconButton` | `tip` feeds the accessible name for icon-only controls | Always pass `tip` when the button has no visible text. |
|
|
46
|
-
| `Dialog` | `Overlay` (shroud, Escape, focus), `role="dialog"`, `aria-modal`, close control with configurable `closeButtonProps.tip` | Provide a clear `title` (and meaningful body copy). Confirm naming with [Molecules / Modals / Dialog](https://gamut.codecademy.com/?path=/docs-molecules-modals-dialog--docs). |
|
|
47
|
-
| `Modal` | Same overlay/focus stack; optional `aria-label`; multi-`views` support | `title` / view titles; pass `aria-label` when there is no visible title string. [Molecules / Modals / Modal](https://gamut.codecademy.com/?path=/docs-molecules-modals-modal--docs). |
|
|
48
|
-
| `Alert` | Default `aria-live="polite"`, `role="status"` | Use `aria-live="assertive"` only for urgent interruptions; do not nest inside another live region. |
|
|
49
|
-
| `Tabs`, `Tab`, `TabList`, `TabPanel` | `react-aria-components` in `packages/gamut/src/Tabs/` — roving tabindex, arrows, Home/End | Name each tab; Tab moves into the active panel per APG. |
|
|
50
|
-
| Forms | See Forms above | [`gamut-forms`](../gamut-forms/SKILL.md) |
|
|
51
|
-
| `DatePicker` + `DatePickerInput` | Segmented input + calendar behavior inside `FormGroup` | Provide `label` / `name` / `form` as for any input; keep `DatePickerInput` inside `DatePicker`. When embedded in `FormGroup` / `GridForm`, follow [`gamut-forms`](../gamut-forms/SKILL.md). [Organisms / DatePicker](https://gamut.codecademy.com/?path=/docs-organisms-datepicker--docs). |
|
|
52
|
-
| `Menu`, `MenuItem`, `MenuSeparator` | List + `MenuProvider` (keyboard / roles depend on variant) | Label `Menu` / menubar per pattern; follow Storybook [Molecules / Menu](https://gamut.codecademy.com/?path=/docs-molecules-menu--docs). |
|
|
53
|
-
| `Popover` | `FocusTrap` when open (unless `skipFocusTrap`), positioning | `onRequestClose`, meaningful `role` when needed; do not trap focus unnecessarily when `skipFocusTrap`. |
|
|
54
|
-
| `Flyout` | `Overlay`, `Drawer`, visible `title`, close `IconButton` with `tip={closeLabel}` | Pass `title` and `closeLabel`; name panel content. |
|
|
55
|
-
| `Drawer` | Focuses container when `expanded`, `tabIndex={-1}` on shell | Drawer is a surface, not a full dialog — supply headings/labels inside for screen readers. |
|
|
56
|
-
| `Disclosure` | `DisclosureButton` drives expand/collapse | Provide `heading` / structure so the control’s purpose is clear. |
|
|
57
|
-
| `Toggle` | `ToggleLabel` + `htmlFor` wired to control `id` | With no visible `label`, pass `ariaLabel` (or use `as="button"` pattern per props). |
|
|
58
|
-
| `ToolTip` | Floating mode renders a screen-reader `role="tooltip"` branch with `id` | Pass the same `id` to the trigger’s `aria-describedby` when you rely on the tooltip as supplementary description (see component `id` JSDoc). |
|
|
59
|
-
| `InfoTip` | — | `ariaLabel` or `ariaLabelledby` (camelCase) — no automatic fallback. |
|
|
60
|
-
| `PreviewTip` | `Anchor`-based preview, focus-driven content | `linkDescription` and visible anchor text; do not use the preview as the sole name for an unrelated control. |
|
|
61
|
-
| `SkipToContent` | Skip link behavior | Place early in the tab order; `href` target `id` must exist on main content. |
|
|
62
|
-
| `Toast` + `Toaster` | `Toaster` wraps the stack in `aria-live="polite"` | Keep messages concise; avoid stacking many simultaneous assertive announcements. |
|
|
63
|
-
| `Pagination` | Page / control buttons | Ensure current page and actions are perceivable (labels / `aria-current` patterns per Storybook). [Molecules / Pagination](https://gamut.codecademy.com/?path=/docs-molecules-pagination--docs). |
|
|
64
|
-
| `FocusTrap` | Escape, outside click, `allowPageInteraction` | Return focus to trigger on close for custom overlays. |
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
// correct
|
|
68
|
-
<IconButton icon={DeleteIcon} tip="Delete item" onClick={handleDelete} />
|
|
69
|
-
|
|
70
|
-
// wrong — no accessible name, no keyboard semantics
|
|
71
|
-
<div onClick={handleDelete}><DeleteIcon /></div>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Dialog / Modal (detail)
|
|
75
|
-
|
|
76
|
-
Both use `Overlay` and `FocusTrap` (`react-focus-on`) patterns: focus moves into the surface, Escape closes (when enabled), focus should return to the trigger on close.
|
|
77
|
-
|
|
78
|
-
Prefer a visible title so the dialog has a clear name; on `Modal`, pass `aria-label` when there is no suitable visible title string. Close control: `IconButton` with `closeButtonProps.tip` (defaults documented in source).
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
<Dialog
|
|
82
|
-
title="Confirm deletion"
|
|
83
|
-
confirmCta={{ children: 'Delete', onClick: handleDelete }}
|
|
84
|
-
onRequestClose={handleClose}
|
|
85
|
-
isOpen={open}
|
|
86
|
-
/>
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Alert (detail)
|
|
90
|
-
|
|
91
|
-
Renders with `aria-live="polite"` and `role="status"` by default. Override with `aria-live="assertive"` only for time-sensitive errors requiring immediate interruption. Do not nest `<Alert>` inside another live region.
|
|
92
|
-
|
|
93
|
-
### Tabs (detail)
|
|
94
|
-
|
|
95
|
-
Built on `react-aria-components`. Follows the [ARIA Tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/): arrow keys navigate tabs, Tab moves focus into the active panel, Home/End jump to first/last tab. The tablist is a composite — only the active tab is in the tab sequence (roving tabindex). No manual `aria-selected` or keyboard handling needed.
|
|
96
|
-
|
|
97
|
-
### InfoTip (example)
|
|
98
|
-
|
|
99
|
-
`<InfoTip>` needs `ariaLabel` or `ariaLabelledby` — see also the always-loaded rules.
|
|
100
|
-
|
|
101
|
-
```tsx
|
|
102
|
-
<InfoTip ariaLabel="More information about billing" />
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### ToolTip (detail)
|
|
106
|
-
|
|
107
|
-
When `placement="floating"`, the component renders a screen-reader-only branch with `role="tooltip"` and an optional `id`. Pass the same `id` to the described element’s `aria-describedby` so assistive tech associates the tooltip copy with the trigger. Inline placement uses the wrapper differently — see [Molecules / Tips / ToolTip](https://gamut.codecademy.com/?path=/docs-molecules-tips-tooltip--docs).
|
|
108
|
-
|
|
109
|
-
### SkipToContent (detail)
|
|
110
|
-
|
|
111
|
-
Include `<SkipToContent>` as the first focusable element in the page shell. The main content region must expose a matching `id` for the skip target.
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## Focus management
|
|
116
|
-
|
|
117
|
-
`<FocusTrap>` is for custom overlay patterns not covered by `Dialog` / `Modal`.
|
|
118
|
-
|
|
119
|
-
Key props:
|
|
120
|
-
|
|
121
|
-
- `active` — enable/disable the trap dynamically
|
|
122
|
-
- `onEscapeKey` — close handler
|
|
123
|
-
- `onClickOutside` — dismiss on outside click
|
|
124
|
-
- `allowPageInteraction` — permit scrolling outside the trap without closing
|
|
125
|
-
|
|
126
|
-
Always return focus to the trigger on close. `react-focus-on` (via `FocusTrap`) and overlay flows handle much of this for dialogs/popovers; `Tabs` inherit focus behavior from `react-aria-components`. Custom surfaces must store a ref to the trigger and call `.focus()` on close when the library does not.
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
## Composite widgets and managed focus
|
|
131
|
-
|
|
132
|
-
ARIA composite roles (`listbox`, `menu`, `tree`, `grid`, `tablist`) use managed focus: only one element in the composite is in the tab sequence at a time. Tab moves focus to the next element outside the composite; arrow keys move focus within it.
|
|
133
|
-
|
|
134
|
-
Implementation pattern — roving tabindex:
|
|
135
|
-
|
|
136
|
-
- Set `tabIndex={0}` on the currently active item
|
|
137
|
-
- Set `tabIndex={-1}` on all other items
|
|
138
|
-
- On arrow key, update which item holds `tabIndex={0}` and call `.focus()` on it
|
|
139
|
-
|
|
140
|
-
`Tabs` (`react-aria-components`) implement roving tabindex for the tablist pattern. `Menu` and other composites implement focus in Gamut — if you build a custom composite, implement roving tabindex yourself. A flat `tabIndex={0}` on every item is wrong — it puts every item in the sequential tab order.
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
## Device-independent events
|
|
145
|
-
|
|
146
|
-
Use `click` for activation, not `mousedown`. `click` follows pointer activation; native `<button>` (and similar controls) also fire `click` from keyboard (Space and Enter). A focused `<a href>` is usually activated with Enter, which fires `click` — Space often scrolls the page instead of activating the link. `mousedown` does not represent keyboard activation, so relying on it alone breaks keyboard-only use.
|
|
147
|
-
|
|
148
|
-
For custom elements with `role="button"`, do not assume the browser will synthesize `click` from the keyboard the way it does for native interactive elements (`<button>`, `<a href>`, and other built-ins). Handle `keydown` for Space and Enter explicitly:
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
152
|
-
if (e.key === ' ' || e.key === 'Enter') {
|
|
153
|
-
e.preventDefault();
|
|
154
|
-
handleActivation();
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Prefer Gamut `*Button` components (or `Anchor` with a real `href`) so you do not reimplement this.
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## Live regions
|
|
164
|
-
|
|
165
|
-
| Scenario | Pattern |
|
|
166
|
-
| ------------------------------------------ | ------------------------------------------- |
|
|
167
|
-
| Status updates, non-critical notifications | `aria-live="polite"` |
|
|
168
|
-
| Urgent global interruptions | `aria-live="assertive"` (use sparingly) |
|
|
169
|
-
| Frequently updating counts or progress | `aria-live="polite"` + `aria-atomic="true"` |
|
|
170
|
-
|
|
171
|
-
Form-bound `aria-live` and `FormError` patterns: see Forms above (do not assume assertive on every field error).
|
|
172
|
-
|
|
173
|
-
Inject live regions into the DOM before they need to announce. A region added simultaneously with its first announcement may be ignored by some assistive technologies.
|
|
174
|
-
|
|
175
|
-
Do not elevate unrelated inline errors to `assertive` — reserve assertive for urgent interruptions the user did not directly trigger.
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
## ARIA authoring rules
|
|
180
|
-
|
|
181
|
-
- No redundant roles: don't set `role="button"` on `<button>` or `role="heading"` on `<h2>`
|
|
182
|
-
- `aria-hidden` cascades: placing `aria-hidden="true"` on a parent removes the entire subtree from the accessibility tree, including focusable descendants — never put it on an ancestor of a focusable element
|
|
183
|
-
- `role="presentation"` and `aria-hidden` on focusable elements: both are prohibited on elements that can receive focus — they remove semantics while leaving the element keyboard-reachable, producing an operable but unnamed control
|
|
184
|
-
- Labelling vs describing: `aria-label` / `aria-labelledby` name the control. `aria-describedby` provides supplementary context. Both can coexist on the same element
|
|
185
|
-
- Required fields: use `aria-required="true"` or the HTML `required` attribute. Visual asterisks must have an explanatory text string visible on the page; the asterisk glyph itself should carry `aria-hidden="true"` — `<FormGroupLabel>` already handles this
|
|
186
|
-
- `display:none` vs `aria-hidden`: elements with `display:none` are already removed from the accessibility tree; adding `aria-hidden` is redundant. Use `aria-hidden="true"` only when an element is visually present but should be hidden from assistive technology
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
## Color and contrast (non-text)
|
|
191
|
-
|
|
192
|
-
Semantic tokens, `ColorMode`, and `<Background>` are covered in the always-loaded `accessibility.mdc` rule and the `gamut-color-mode` skill. Here: non-text contrast (focus rings, input borders, icon affordances) should meet ~3:1 vs adjacent colors where WCAG 1.4.11 applies — validate in your layout.
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
## Testing checklist
|
|
197
|
-
|
|
198
|
-
- [ ] Full keyboard navigation: every interactive element reachable and operable without a mouse
|
|
199
|
-
- [ ] Focus is always visible and never lost or unexpectedly trapped
|
|
200
|
-
- [ ] Dialogs trap focus correctly; Escape closes; focus returns to the trigger
|
|
201
|
-
- [ ] Composite widgets (tabs, menus, listboxes) use arrow keys internally, not Tab
|
|
202
|
-
- [ ] All form inputs have programmatically associated labels (not placeholder-only)
|
|
203
|
-
- [ ] Form errors surface through the library’s `FormError` / live-region patterns (Forms above)
|
|
204
|
-
- [ ] Icon-only controls have accessible names
|
|
205
|
-
- [ ] No content relies solely on color to convey meaning
|
|
206
|
-
- [ ] Screen reader matrix: VoiceOver + Safari (iOS), VoiceOver + Chrome (macOS), NVDA + Chrome (Windows)
|
|
207
|
-
- [ ] 200% zoom: layout intact, no content overflow or disappearance
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
## Common anti-patterns
|
|
212
|
-
|
|
213
|
-
| Anti-pattern | Fix |
|
|
214
|
-
| -------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
215
|
-
| `<div onClick={…}>` for actions | `FillButton`, `TextButton`, `StrokeButton`, `CTAButton`, or `IconButton` (with `tip`) |
|
|
216
|
-
| `placeholder` as the only label | `FormGroupLabel` with matching `htmlFor` / `id` |
|
|
217
|
-
| `aria-label` on a `<div>` with no role | Add a meaningful `role` or use a semantic element |
|
|
218
|
-
| `role="button"` without Space/Enter handlers | Use a Gamut `*Button`, `Anchor` with `href`, or add `keydown` |
|
|
219
|
-
| `tabIndex={0}` on every item in a composite | Roving tabindex: `0` on active item, `-1` on rest |
|
|
220
|
-
| Tooltip as the only accessible name for a control | Set `aria-label` (or visible text) on the control as well |
|
|
221
|
-
| `aria-hidden="true"` on a focusable element | Also remove from tab order (`tabIndex={-1}`) or restructure |
|
|
222
|
-
| `mousedown` for activation | Use `click` |
|
|
223
|
-
| `outline: none` without a replacement | Use Gamut’s built-in focus styles |
|
|
224
|
-
| Multiple `aria-live` regions for the same content stream | One region per logical stream; reuse it across updates |
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-color-mode
|
|
3
|
-
description: Light/dark behavior, semantic color aliases, Background, color-mode hooks, hardcoded hex fixes. When invoked, read guidelines/foundations/modes.md and color.md first.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Gamut ColorMode
|
|
7
|
-
|
|
8
|
-
## Read first
|
|
9
|
-
|
|
10
|
-
When this skill applies, read before writing code:
|
|
11
|
-
|
|
12
|
-
- [`guidelines/foundations/modes.md`](../../guidelines/foundations/modes.md)
|
|
13
|
-
- [`guidelines/foundations/color.md`](../../guidelines/foundations/color.md)
|
|
14
|
-
|
|
15
|
-
Confirm token mappings against root `DESIGN.md` and the active theme — do not assume Codecademy Core values.
|
|
16
|
-
|
|
17
|
-
Source: `@codecademy/gamut-styles` — [`ColorMode.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut-styles/src/ColorMode.tsx)
|
|
18
|
-
|
|
19
|
-
## Overview
|
|
20
|
-
|
|
21
|
-
Gamut's color system uses semantic aliases instead of raw color tokens. This means components automatically adapt across light and dark modes without configuration.
|
|
22
|
-
|
|
23
|
-
### Semantic color aliases
|
|
24
|
-
|
|
25
|
-
| Alias | Purpose |
|
|
26
|
-
| ------------ | ------------------------------------------ |
|
|
27
|
-
| `text` | Standard text color for all type |
|
|
28
|
-
| `background` | Base background color |
|
|
29
|
-
| `primary` | Interactive elements with primary action |
|
|
30
|
-
| `secondary` | Interactive elements with secondary action |
|
|
31
|
-
|
|
32
|
-
This set is not exhaustive (e.g. `text-accent`, `background-disabled`, `danger` — see the light/dark tables in Storybook).
|
|
33
|
-
|
|
34
|
-
Key principle: Always use these aliases in component styles — never hardcode specific color tokens like `navy-400` for anything that needs to change per mode.
|
|
35
|
-
|
|
36
|
-
Storybook: [Foundations / ColorMode](https://gamut.codecademy.com/?path=/docs-foundations-colormode--page) — interactive reference. [Meta / Best practices](https://gamut.codecademy.com/?path=/docs-meta-best-practices--page) — semantic tokens, `css` / `variant` / `states`, and system props with ColorMode.
|
|
37
|
-
|
|
38
|
-
Agent skill: [`gamut-style-utilities`](../gamut-style-utilities/SKILL.md) — `css` / `variant` / `states` with semantic colors alongside ColorMode.
|
|
39
|
-
|
|
40
|
-
## `<ColorMode />`
|
|
41
|
-
|
|
42
|
-
Wraps content in a color mode context. Place `<ColorMode />` as high in the app tree as practical. For a nested or static themed area on a page, use `<Background />` instead.
|
|
43
|
-
|
|
44
|
-
```tsx
|
|
45
|
-
import { ColorMode } from '@codecademy/gamut-styles';
|
|
46
|
-
|
|
47
|
-
// Explicit light or dark
|
|
48
|
-
<ColorMode mode="light">{children}</ColorMode>
|
|
49
|
-
|
|
50
|
-
// Follow OS light/dark preference (see mode="system" below)
|
|
51
|
-
<ColorMode mode="system">{children}</ColorMode>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Props: `mode="light" | "dark" | "system"`
|
|
55
|
-
|
|
56
|
-
### `mode="system"` (OS preference)
|
|
57
|
-
|
|
58
|
-
`system` is not a third color theme. It always resolves to `"light"` or `"dark"` based on the user's OS setting.
|
|
59
|
-
|
|
60
|
-
How it works
|
|
61
|
-
|
|
62
|
-
1. `ColorMode` calls `usePrefersDarkMode()`, which reads `window.matchMedia('(prefers-color-scheme: dark)')`.
|
|
63
|
-
2. If the query matches → active mode is `"dark"`; otherwise `"light"`.
|
|
64
|
-
3. Descendants receive that mode's semantic color variables (`text`, `background`, `primary`, etc.) — same as passing `mode="light"` or `mode="dark"` directly.
|
|
65
|
-
|
|
66
|
-
When the OS changes (e.g. user toggles system appearance), the media query fires a `change` event, `ColorMode` re-renders, and semantic colors update for everything inside the wrapper.
|
|
67
|
-
|
|
68
|
-
What it does not do
|
|
69
|
-
|
|
70
|
-
- Read in-app preferences (account settings, a theme toggle in localStorage). For those, pass `mode="light"` or `mode="dark"` yourself from your own state.
|
|
71
|
-
- Replace `<Background>`. A colored band still needs `<Background bg="hyper">` if you want contrast-based mode selection for that surface.
|
|
72
|
-
|
|
73
|
-
Prefer `mode="system"` over wiring the hook yourself
|
|
74
|
-
|
|
75
|
-
```tsx
|
|
76
|
-
// Prefer — ColorMode owns light/dark resolution
|
|
77
|
-
<ColorMode mode="system">{children}</ColorMode>;
|
|
78
|
-
|
|
79
|
-
// Avoid — duplicates what mode="system" already does
|
|
80
|
-
const prefersDark = usePrefersDarkMode();
|
|
81
|
-
<ColorMode mode={prefersDark ? 'dark' : 'light'}>{children}</ColorMode>;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Use `usePrefersDarkMode()` only when you need the OS preference for something other than setting `ColorMode`'s mode (e.g. picking a decorative palette `bg` in a demo).
|
|
85
|
-
|
|
86
|
-
Place `<ColorMode mode="system">` high in the tree (often inside `GamutProvider`) so the whole app follows system appearance unless a subtree overrides with `mode="light"`, `mode="dark"`, or `<Background>`.
|
|
87
|
-
|
|
88
|
-
## `<Background />`
|
|
89
|
-
|
|
90
|
-
Use `<Background>` instead of putting `bg` on a layout component when a section needs a fixed palette color (card, hero, landing band, etc.) — independent of the parent color mode. Pass a palette token to `bg` (e.g. `hyper`, `navy`, `paleGreen`), not a semantic alias (`text`, `background`, `primary`).
|
|
91
|
-
|
|
92
|
-
`<Background>` switches light/dark to whichever mode gives the highest contrast between that surface and body `text`. Nested Gamut components inherit readable colors without extra setup.
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
import { Background } from '@codecademy/gamut-styles';
|
|
96
|
-
|
|
97
|
-
// Single background — mode switches automatically if needed
|
|
98
|
-
const Card = ({ children }) => <Background bg="hyper">{children}</Background>;
|
|
99
|
-
|
|
100
|
-
// Nested backgrounds — each creates its own color context
|
|
101
|
-
const Page = () => (
|
|
102
|
-
<Background bg="black" p={24}>
|
|
103
|
-
<Background bg="paleGreen" p={24}>
|
|
104
|
-
{/* content inside inner Background uses its own mode */}
|
|
105
|
-
</Background>
|
|
106
|
-
</Background>
|
|
107
|
-
);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### `background-current` CSS variable
|
|
111
|
-
|
|
112
|
-
When `<Background>` is rendered, it sets a `background-current` CSS variable on the theme. Use this to reference an ancestor's background color (e.g. for simulating transparency or masking content).
|
|
113
|
-
|
|
114
|
-
## Color mode hooks
|
|
115
|
-
|
|
116
|
-
```tsx
|
|
117
|
-
import {
|
|
118
|
-
useColorModes,
|
|
119
|
-
useCurrentMode,
|
|
120
|
-
usePrefersDarkMode,
|
|
121
|
-
} from '@codecademy/gamut-styles';
|
|
122
|
-
|
|
123
|
-
// [activeModeKey, activeModeColors, allModes, getColorValue]
|
|
124
|
-
const [current, currentColors, modes, getColorValue] = useColorModes();
|
|
125
|
-
|
|
126
|
-
// Active mode key: "light" | "dark" (optional override argument)
|
|
127
|
-
const current = useCurrentMode();
|
|
128
|
-
const forced = useCurrentMode('light');
|
|
129
|
-
|
|
130
|
-
// Boolean from window.matchMedia('(prefers-color-scheme: dark)')
|
|
131
|
-
const prefersDark = usePrefersDarkMode();
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Decision guide
|
|
135
|
-
|
|
136
|
-
| Need | Use |
|
|
137
|
-
| ------------------------------------------------------------- | ---------------------------------- | ---- | --------- |
|
|
138
|
-
| Set a page or section to a specific mode | `<ColorMode mode="light | dark | system">` |
|
|
139
|
-
| Place content on a colored background with automatic contrast | `<Background bg="...">` |
|
|
140
|
-
| Read the current mode in JavaScript | `useCurrentMode()` |
|
|
141
|
-
| Access all modes, variables, and resolve raw colors | `useColorModes()` |
|
|
142
|
-
| Detect OS dark mode preference | `usePrefersDarkMode()` |
|
|
143
|
-
| Access full emotion theme | `useTheme()` from `@emotion/react` |
|
|
144
|
-
|
|
145
|
-
## Common mistakes to avoid
|
|
146
|
-
|
|
147
|
-
- Do not use raw color tokens (e.g. `color: 'navy-400'`) for text, backgrounds, or borders that need to be accessible across modes — use semantic aliases instead.
|
|
148
|
-
- Do not use a raw `bg` prop for colored section backgrounds that need static, ColorMode-agnostic, background colors — use `<Background>` so mode selection is handled for you.
|
|
149
|
-
- Do not manually set `ColorMode`'s `mode` from `usePrefersDarkMode()` when `mode="system"` is enough. The hook is still useful for non-mode concerns (e.g. choosing a decorative `bg` in Storybook demos).
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-components
|
|
3
|
-
description: Implements or reviews Gamut UI components in TSX — Menu, DataTable, DataList, Card, Select, Video, Coachmark, Shimmer, animations, tooltips. Use when no narrower gamut-* skill applies. When invoked, read only the relevant guidelines/components/*.md files.
|
|
4
|
-
paths: '**/*.tsx'
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Gamut components (guideline router)
|
|
8
|
-
|
|
9
|
-
Use when building or changing Gamut components in `.tsx` files and a narrower skill does not already cover the task (`gamut-forms`, `gamut-color-mode`, etc.).
|
|
10
|
-
|
|
11
|
-
## Read first
|
|
12
|
-
|
|
13
|
-
1. Read [`guidelines/overview.md`](../../guidelines/overview.md) Step 2 table only (component → guide mapping).
|
|
14
|
-
2. Read only the `guidelines/components/*.md` files for components you will touch in this task — not all guides.
|
|
15
|
-
|
|
16
|
-
Do not load every guideline file. Skip guides for components you are not using.
|
|
17
|
-
|
|
18
|
-
## Component → guideline
|
|
19
|
-
|
|
20
|
-
| Component(s) | Guideline |
|
|
21
|
-
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
22
|
-
| `FillButton`, `StrokeButton`, `TextButton`, `IconButton`, `CTAButton` | [`buttons.md`](../../guidelines/components/buttons.md) |
|
|
23
|
-
| `GridForm`, `ConnectedForm` | [`forms.md`](../../guidelines/components/forms.md) — prefer `gamut-forms` skill |
|
|
24
|
-
| `DataTable`, `DataList` | [`data-table.md`](../../guidelines/components/data-table.md) |
|
|
25
|
-
| `Menu`, `MenuItem`, `MenuSeparator` | [`menu.md`](../../guidelines/components/menu.md) |
|
|
26
|
-
| `Card` | [`card.md`](../../guidelines/components/card.md) |
|
|
27
|
-
| `Select`, `SelectDropdown` | [`select.md`](../../guidelines/components/select.md) |
|
|
28
|
-
| `RadialProgress` | [`radial-progress.md`](../../guidelines/components/radial-progress.md) |
|
|
29
|
-
| `Shimmer`, `Spinner`, `FeatureShimmer` | [`loading-states.md`](../../guidelines/components/loading-states.md) |
|
|
30
|
-
| `Coachmark` | [`coachmark.md`](../../guidelines/components/coachmark.md) |
|
|
31
|
-
| `ToolTip`, `InfoTip`, `PreviewTip` | [`tooltips.md`](../../guidelines/components/tooltips.md) |
|
|
32
|
-
| `Video` | [`video.md`](../../guidelines/components/video.md) |
|
|
33
|
-
| `Rotation`, `ExpandInCollapseOut`, `FadeInSlideOut` | [`animations.md`](../../guidelines/components/animations.md) |
|
|
34
|
-
| `ColorMode`, `Background` | [`modes.md`](../../guidelines/foundations/modes.md) — prefer `gamut-color-mode` skill |
|
|
35
|
-
|
|
36
|
-
Discovery and forms vs. atoms: [`components/overview.md`](../../guidelines/components/overview.md).
|
|
37
|
-
|
|
38
|
-
## Related skills
|
|
39
|
-
|
|
40
|
-
| Topic | Skill |
|
|
41
|
-
| ---------------------- | ---------------------------------- |
|
|
42
|
-
| Forms | `gamut-forms` |
|
|
43
|
-
| Color / modes | `gamut-color-mode` |
|
|
44
|
-
| Layout / spacing props | `gamut-system-props` |
|
|
45
|
-
| Accessibility | `gamut-accessibility` |
|
|
46
|
-
| Product theme | `gamut-theming` + root `DESIGN.md` |
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-forms
|
|
3
|
-
description: Implementing or auditing Gamut forms — GridForm, ConnectedForm, FormGroup, labels, validation. When invoked, read guidelines/components/forms.md first. Pair with gamut-accessibility for non-form widgets.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Gamut forms
|
|
7
|
-
|
|
8
|
-
## Read first
|
|
9
|
-
|
|
10
|
-
When this skill applies, read [`guidelines/components/forms.md`](../../guidelines/components/forms.md) before writing code.
|
|
11
|
-
|
|
12
|
-
Canonical wiring for `FormGroup`, `ConnectedForm`, `ConnectedFormGroup`, `GridForm`, and field renderers. Source: `packages/gamut/src/Form/`, `ConnectedForm/`, `GridForm/`.
|
|
13
|
-
|
|
14
|
-
Universal label and primitive guidance: [`accessibility.mdc`](../../rules/accessibility.mdc) · overlay and composite patterns: [`gamut-accessibility`](../gamut-accessibility/SKILL.md).
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Mandatory: use organisms for functional forms
|
|
19
|
-
|
|
20
|
-
Functional forms (submit/save, validation, dirty state) must use `GridForm` or `ConnectedForm`. Do not compose from bare `Input`, `Select`, `Checkbox`, etc.
|
|
21
|
-
|
|
22
|
-
| Organism | When |
|
|
23
|
-
| --------------- | -------------------------------------------------------- |
|
|
24
|
-
| `GridForm` | Declarative `fields` + `submit` — settings, CRUD dialogs |
|
|
25
|
-
| `ConnectedForm` | Custom layout with managed `react-hook-form` state |
|
|
26
|
-
|
|
27
|
-
Rules: Always set `defaultValues`. Use `validation="onChange"` when submit should stay disabled until valid. `hideLabel: true` on checkbox/radio fields with no `label`, and on toggle (`custom`) fields where `Toggle` renders its own label.
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Prefer connected layouts
|
|
32
|
-
|
|
33
|
-
For typical product forms, prefer `GridForm` (declarative `fields`, `LayoutGrid`, submit/cancel) or `ConnectedForm` with `ConnectedFormGroup` / `useConnectedForm`. Use raw `FormGroup` + atoms only when the layout is simple and you fully own `id`, `htmlFor`, invalid state, and any `aria-describedby` (see below).
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Labels and controls
|
|
38
|
-
|
|
39
|
-
`htmlFor` / `id` pairing — universal rule in [`accessibility.mdc`](../../rules/accessibility.mdc) (Form label association). Form-specific notes:
|
|
40
|
-
|
|
41
|
-
- `FormGroupLabel` → control `id` (or stable `name` when that is your field’s id convention).
|
|
42
|
-
- Checkbox, Radio, Select: same pairing; checkbox/radio use the visually hidden input pattern from `@codecademy/gamut-styles` where applicable.
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## `FormGroup` (baseline)
|
|
47
|
-
|
|
48
|
-
[`FormGroup.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/Form/elements/FormGroup.tsx)
|
|
49
|
-
|
|
50
|
-
- `description` → `FormGroupDescription` with `aria-live="assertive"`.
|
|
51
|
-
- `error` (string) → `FormError` with `aria-live="polite"` and `role="alert"`.
|
|
52
|
-
|
|
53
|
-
Raw `FormGroup` does not set `aria-describedby` or `aria-invalid` on `children`. If you compose fields outside `ConnectedFormGroup` / `GridForm`, wire those yourself or accept that only the live regions above communicate errors/descriptions.
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## `ConnectedFormGroup`
|
|
58
|
-
|
|
59
|
-
[`ConnectedFormGroup.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/ConnectedForm/ConnectedFormGroup.tsx)
|
|
60
|
-
|
|
61
|
-
- Passes `aria-describedby` (error region id when shown) and `aria-invalid` on the rendered field component.
|
|
62
|
-
- `FormError`: `aria-live="assertive"` and `role="alert"` only when `isFirstError`; otherwise `aria-live="off"` and `role="status"` so subsequent errors do not interrupt repeatedly.
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## `GridForm`
|
|
67
|
-
|
|
68
|
-
[`GridFormInputGroup/index.tsx`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/GridForm/GridFormInputGroup/index.tsx) · [`GridFormTextInput`](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/GridForm/GridFormInputGroup/GridFormTextInput/index.tsx)
|
|
69
|
-
|
|
70
|
-
- Composes `ConnectedForm`, `LayoutGrid`, `GridFormButtons`, and field metadata. `FormError` uses the same first-error assertive pattern as `ConnectedFormGroup` (`aria-live` assertive vs off, `role` alert vs status).
|
|
71
|
-
- Built-in text inputs set `aria-invalid` and register with react-hook-form via `register`. Custom / `custom` / `custom-group` renderers must still expose correct `id`, `label`, and error surfacing consistent with this pattern.
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## Live regions — do not double up
|
|
76
|
-
|
|
77
|
-
`FormGroup`, `ConnectedFormGroup`, and `GridForm` already render `FormError` (and base `FormGroup` renders `FormGroupDescription`) with live-region attributes. Do not add a second `aria-live` wrapper for the same message stream.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Storybook
|
|
82
|
-
|
|
83
|
-
- [Organisms / GridForm / About](https://gamut.codecademy.com/?path=/docs-organisms-gridform-about--docs) · [Usage](https://gamut.codecademy.com/?path=/docs-organisms-gridform-usage--docs) · [Validation](https://gamut.codecademy.com/?path=/docs-organisms-gridform-validation--docs) · [Fields](https://gamut.codecademy.com/?path=/docs-organisms-gridform-fields--docs)
|
|
84
|
-
- [Organisms / ConnectedForm / ConnectedForm](https://gamut.codecademy.com/?path=/docs-organisms-connectedform-connectedform--docs) · [ConnectedFormGroup](https://gamut.codecademy.com/?path=/docs-organisms-connectedform-connectedformgroup--docs)
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## Example — baseline `FormGroup`
|
|
89
|
-
|
|
90
|
-
```tsx
|
|
91
|
-
<FormGroup
|
|
92
|
-
htmlFor="email-input"
|
|
93
|
-
description="Used for login"
|
|
94
|
-
error={errors.email}
|
|
95
|
-
>
|
|
96
|
-
<FormGroupLabel htmlFor="email-input">Email</FormGroupLabel>
|
|
97
|
-
<Input id="email-input" type="email" />
|
|
98
|
-
</FormGroup>
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
When using `ConnectedFormGroup` or `GridForm`, prefer their docs and defaults over hand-rolling the above for every field.
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-style-utilities
|
|
3
|
-
description: css(), variant(), states(), StyleProps, useTheme from @codecademy/gamut-styles. When invoked, read guidelines/foundations/color.md for semantic tokens.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Gamut style utilities
|
|
7
|
-
|
|
8
|
-
## Read first
|
|
9
|
-
|
|
10
|
-
When this skill applies, read [`guidelines/foundations/color.md`](../../guidelines/foundations/color.md) before choosing color tokens in `css` / `variant` / `states`.
|
|
11
|
-
|
|
12
|
-
Source: `@codecademy/gamut-styles` — [`variance/props.ts`](https://github.com/Codecademy/gamut/blob/main/packages/gamut-styles/src/variance/props.ts) (`css`, `variant`, `states` built on `PROPERTIES.all`).
|
|
13
|
-
|
|
14
|
-
See also: [`gamut-theming`](../gamut-theming/SKILL.md) (which theme, `GamutProvider`, new themes). [`gamut-system-props`](../gamut-system-props/SKILL.md) (`system.*`, responsive props, `Box`). [`gamut-color-mode`](../gamut-color-mode/SKILL.md) (semantic color, `<ColorMode>`, `<Background>`). [Best practices](../../../../styleguide/src/lib/Meta/Best%20practices.mdx) and [system compose](https://gamut.codecademy.com/?path=/docs-foundations-system-compose--page).
|
|
15
|
-
|
|
16
|
-
## Overview
|
|
17
|
-
|
|
18
|
-
Use `css()`, `variant()`, and `states()` from `@codecademy/gamut-styles` for typed, token-scaled style objects (same scales as composed `system.*` props). Prefer semantic color keys so styles track ColorMode and theme.
|
|
19
|
-
|
|
20
|
-
For layout-heavy styled components, prefer composing `system.*` via `variance.compose()` (see `gamut-system-props`) instead of re-stating every longhand in `css()`.
|
|
21
|
-
|
|
22
|
-
## `css()` — static style objects
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
import { css } from '@codecademy/gamut-styles';
|
|
26
|
-
import styled from '@emotion/styled';
|
|
27
|
-
|
|
28
|
-
const Box = styled.div(css({ bg: 'navy-400', p: 4 }));
|
|
29
|
-
const Text = styled.div(css({ color: 'primary', p: 4 }));
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## `variant()` and `states()` — branching and toggles
|
|
33
|
-
|
|
34
|
-
- `variant()` — mutually exclusive modes: `base`, `defaultVariant`, and a `variants` map (semantic colors, spacing shorthands, nested selectors such as `'&:hover'`).
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
import { variant } from '@codecademy/gamut-styles';
|
|
38
|
-
import styled from '@emotion/styled';
|
|
39
|
-
|
|
40
|
-
const Anchor = styled.a(
|
|
41
|
-
variant({
|
|
42
|
-
base: { p: 4 },
|
|
43
|
-
defaultVariant: 'interface',
|
|
44
|
-
variants: {
|
|
45
|
-
interface: {
|
|
46
|
-
color: 'text',
|
|
47
|
-
'&:hover': { color: 'text-accent' },
|
|
48
|
-
},
|
|
49
|
-
inline: {
|
|
50
|
-
color: 'primary',
|
|
51
|
-
'&:hover': { color: 'secondary' },
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
- `states()` — independent boolean-style props (`base` + named keys).
|
|
59
|
-
|
|
60
|
-
```tsx
|
|
61
|
-
import { states } from '@codecademy/gamut-styles';
|
|
62
|
-
import styled from '@emotion/styled';
|
|
63
|
-
|
|
64
|
-
const UtilityBox = styled.div(
|
|
65
|
-
states({
|
|
66
|
-
base: { mx: 4, my: 8, p: 16 },
|
|
67
|
-
disabled: { bg: 'background-disabled', color: 'text-disabled' },
|
|
68
|
-
center: { alignItems: 'center', justifyContent: 'center' },
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### `StyleProps` on React components
|
|
74
|
-
|
|
75
|
-
```tsx
|
|
76
|
-
import { states } from '@codecademy/gamut-styles';
|
|
77
|
-
import { StyleProps } from '@codecademy/variance';
|
|
78
|
-
import styled from '@emotion/styled';
|
|
79
|
-
|
|
80
|
-
const panelShellStates = states({ base: { p: 4 }, dense: { p: 2 } });
|
|
81
|
-
const PanelShell = styled.div(panelShellStates);
|
|
82
|
-
|
|
83
|
-
export type PanelShellProps = StyleProps<typeof panelShellStates> & {
|
|
84
|
-
title: string;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const Panel: React.FC<PanelShellProps> = ({ title, ...rest }) => (
|
|
88
|
-
<PanelShell {...rest}>{title}</PanelShell>
|
|
89
|
-
);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Prefer `variant` / `states` over branching on raw `theme` fields inside styled template literals when the output is Emotion-managed CSS.
|
|
93
|
-
|
|
94
|
-
## `useTheme()` — escape hatch
|
|
95
|
-
|
|
96
|
-
Prefer `css()`, `system.*`, `variant()`, and `states()` for styling. Use `useTheme()` from `@emotion/react` when a token value must be read in plain JS (charts, canvas, third-party props), not as the default way to color DOM nodes.
|
|
97
|
-
|
|
98
|
-
```tsx
|
|
99
|
-
import { useTheme } from '@emotion/react';
|
|
100
|
-
|
|
101
|
-
const Sparkline = () => {
|
|
102
|
-
const theme = useTheme();
|
|
103
|
-
return <path strokeWidth={theme.spacing[4]} d="M0 0 L10 10" />;
|
|
104
|
-
};
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Key principles
|
|
108
|
-
|
|
109
|
-
- Prefer semantic color keys in `css` / `variant` / `states` so ColorMode and theme switches apply; see `gamut-color-mode`.
|
|
110
|
-
- Never hardcode hex in component styles — use tokens / semantic aliases.
|
|
111
|
-
- Prefer `variant` / `states` for modes and toggles instead of ad-hoc `theme` interpolation in template literals.
|