@codecademy/gamut 68.6.1-alpha.c211a2.0 → 68.6.1-alpha.d46fc5.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/agent-tools/.claude-plugin/marketplace.json +16 -0
- package/agent-tools/.claude-plugin/plugin.json +7 -0
- package/agent-tools/.cursor-plugin/plugin.json +7 -0
- package/agent-tools/DESIGN.Codecademy.md +643 -0
- package/agent-tools/DESIGN.LXStudio.md +444 -0
- package/agent-tools/DESIGN.Percipio.md +435 -0
- package/agent-tools/DESIGN.md +1 -0
- package/agent-tools/agents/.gitkeep +0 -0
- package/agent-tools/commands/gamut-review.md +246 -0
- package/agent-tools/guidelines/components/buttons.md +91 -0
- package/agent-tools/guidelines/components/overview.md +52 -0
- package/agent-tools/guidelines/foundations/color.md +172 -0
- package/agent-tools/guidelines/foundations/modes.md +47 -0
- package/agent-tools/guidelines/foundations/spacing.md +107 -0
- package/agent-tools/guidelines/foundations/typography.md +84 -0
- package/agent-tools/guidelines/overview.md +46 -0
- package/agent-tools/guidelines/setup.md +81 -0
- package/agent-tools/rules/accessibility.mdc +78 -0
- package/agent-tools/skills/gamut-accessibility/SKILL.md +214 -0
- package/agent-tools/skills/gamut-color-mode/SKILL.md +140 -0
- package/agent-tools/skills/gamut-forms/SKILL.md +84 -0
- package/agent-tools/skills/gamut-style-utilities/SKILL.md +107 -0
- package/agent-tools/skills/gamut-system-props/SKILL.md +203 -0
- package/agent-tools/skills/gamut-testing/SKILL.md +221 -0
- package/agent-tools/skills/gamut-theming/SKILL.md +48 -0
- package/agent-tools/skills/gamut-typography/SKILL.md +75 -0
- package/bin/commands/plugin/install.mjs +213 -0
- package/bin/commands/plugin/list.mjs +73 -0
- package/bin/commands/plugin/remove.mjs +108 -0
- package/bin/commands/plugin/update.mjs +59 -0
- package/bin/gamut.mjs +96 -0
- package/bin/lib/claude.mjs +52 -0
- package/bin/lib/cursor.mjs +40 -0
- package/bin/lib/design.mjs +71 -0
- package/bin/lib/io.mjs +14 -0
- package/bin/lib/resolve-plugin-dir.mjs +38 -0
- package/bin/lib/run-command.mjs +22 -0
- package/package.json +11 -8
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Spacing, Border Radius & Layout
|
|
2
|
+
|
|
3
|
+
Token values match [`packages/gamut-styles/src/variables`](https://github.com/Codecademy/gamut/tree/main/packages/gamut-styles/src/variables) (`spacing.ts`, `borderRadii.ts`, `responsive.ts`). Breakpoints and max-content widths align with Storybook [Foundations / Layout](https://gamut.codecademy.com/?path=/docs-foundations-layout--docs).
|
|
4
|
+
|
|
5
|
+
**In code — use system props for spacing:** Gamut layout primitives (`Box`, `FlexBox`, `GridBox`, …) expose margin, padding, and gap props backed by **`system.space`** from `@codecademy/gamut-styles`. Pass **spacing scale numbers** (`4`, `8`, `16`, …), not raw pixel strings. For custom `styled` components, compose `system.space` (see [`gamut-system-props` skill](../../skills/gamut-system-props/SKILL.md)). [Meta / Best practices](https://gamut.codecademy.com/?path=/docs-meta-best-practices--page) shows responsive `Box` examples.
|
|
6
|
+
|
|
7
|
+
**Responsive behavior:** All those props accept mobile-first **object** (`{ _: 8, md: 24 }`) or **array** syntax per [Responsive properties](https://gamut.codecademy.com/?path=/docs-foundations-system-responsive-properties--page). **Container queries** use keys `c_base`, `c_xs`, … `c_xl`; the parent must set a container (e.g. `containerType="inline-size"` on `FlexBox`). Prefer a media-query fallback when mixing `c_*` with viewport breakpoints.
|
|
8
|
+
|
|
9
|
+
**Two different “grids”:**
|
|
10
|
+
|
|
11
|
+
- **Design / page grid** (this doc’s “Grid” section, 12 columns, margins/gutters) — product layout guidelines; implement with [`LayoutGrid`](https://gamut.codecademy.com/?path=/docs-layouts-layoutgrid-layoutgrid--docs) and responsive `columnGap` / `rowGap` where appropriate.
|
|
12
|
+
- **CSS Grid system props** — `system.grid` on styled components or `GridBox` for **local** regions; not the same as full-page `LayoutGrid`. See [System props / Grid](https://gamut.codecademy.com/?path=/docs-foundations-system-props-grid--page). `LayoutGrid` is for flexible full-page sections; use `FlexBox` / `GridBox` / `Box` for smaller areas ([LayoutGrid usage](https://gamut.codecademy.com/?path=/docs-layouts-layoutgrid-layoutgrid--docs)).
|
|
13
|
+
|
|
14
|
+
**Designer vs code names:** Figma / Layout docs often label artboards **XL, LG, MD, SM, XS, Base**. In code, viewport breakpoints are **`xl`, `lg`, `md`, `sm`, `xs`** (min-widths below); **`_`** is the base (no min-width query). The “Max content width” column maps to those design sizes, not the `xs` token name alone.
|
|
15
|
+
|
|
16
|
+
## Spacing scale
|
|
17
|
+
|
|
18
|
+
All spacing is multiples of 4px on an 8px grid.
|
|
19
|
+
|
|
20
|
+
| Token | Value |
|
|
21
|
+
| ----- | ----- |
|
|
22
|
+
| `0` | 0 |
|
|
23
|
+
| `4` | 4px |
|
|
24
|
+
| `8` | 8px |
|
|
25
|
+
| `12` | 12px |
|
|
26
|
+
| `16` | 16px |
|
|
27
|
+
| `24` | 24px |
|
|
28
|
+
| `32` | 32px |
|
|
29
|
+
| `40` | 40px |
|
|
30
|
+
| `48` | 48px |
|
|
31
|
+
| `64` | 64px |
|
|
32
|
+
| `96` | 96px |
|
|
33
|
+
|
|
34
|
+
Use multiples of 8px for block-element spacing. Use 4px only for inline or typographic relationships.
|
|
35
|
+
|
|
36
|
+
## Border radius
|
|
37
|
+
|
|
38
|
+
| Token | Value | Use |
|
|
39
|
+
| ------ | ----- | ---------------------------------- |
|
|
40
|
+
| `none` | 0px | Square / non-interactive elements |
|
|
41
|
+
| `sm` | 2px | Subtle rounding, tags |
|
|
42
|
+
| `md` | 4px | Buttons, inputs, interactive cards |
|
|
43
|
+
| `lg` | 8px | Cards, panels |
|
|
44
|
+
| `xl` | 16px | Large cards, modals |
|
|
45
|
+
| `full` | 999px | Pills, avatars, circular elements |
|
|
46
|
+
|
|
47
|
+
## Breakpoints
|
|
48
|
+
|
|
49
|
+
Mobile-first. Styles apply from the named breakpoint and up.
|
|
50
|
+
|
|
51
|
+
| Token | Min-width | Max content width |
|
|
52
|
+
| -------- | --------- | ----------------- |
|
|
53
|
+
| _(base)_ | 0 | 288px |
|
|
54
|
+
| `xs` | 480px | 448px |
|
|
55
|
+
| `sm` | 768px | 704px |
|
|
56
|
+
| `md` | 1024px | 896px |
|
|
57
|
+
| `lg` | 1200px | 1072px |
|
|
58
|
+
| `xl` | 1440px | 1248px |
|
|
59
|
+
|
|
60
|
+
The grid table below collapses **xl+lg**, **md**, **sm+xs**, and **base** to four implementation tiers; max-content widths still follow the six design sizes in Layout.
|
|
61
|
+
|
|
62
|
+
## Container query breakpoints
|
|
63
|
+
|
|
64
|
+
Container keys (`c_*`) use the **same min-width numbers** as viewport breakpoints, but they apply to the **width of a CSS containment context** (usually a parent), not the browser viewport. Use them when a component must adapt inside sidebars, split layouts, or embeds. Full detail: [Responsive properties — Container Queries](https://gamut.codecademy.com/?path=/docs-foundations-system-responsive-properties--page).
|
|
65
|
+
|
|
66
|
+
| Key | Min container width | Typical use |
|
|
67
|
+
| -------- | ------------------- | ----------------------------------------------------------------------- |
|
|
68
|
+
| `c_base` | 1px | Always matches once a container exists; base style inside the container |
|
|
69
|
+
| `c_xs` | 480px | Matches viewport `xs` threshold, but on **container** width |
|
|
70
|
+
| `c_sm` | 768px | |
|
|
71
|
+
| `c_md` | 1024px | |
|
|
72
|
+
| `c_lg` | 1200px | |
|
|
73
|
+
| `c_xl` | 1440px | |
|
|
74
|
+
|
|
75
|
+
**Requirements**
|
|
76
|
+
|
|
77
|
+
- A **descendant** of an element that establishes a container — e.g. parent `<FlexBox containerType="inline-size">` (or other `container-type`). Without that, `c_*` rules never match.
|
|
78
|
+
- Prefer a **viewport fallback** alongside `c_*` (e.g. `display={{ _: 'block', sm: 'flex', c_md: 'grid' }}`) for browsers or trees without container support.
|
|
79
|
+
|
|
80
|
+
**Object vs array**
|
|
81
|
+
|
|
82
|
+
- **Object:** `p={{ _: 8, c_md: 24 }}` — readable for a few container-only overrides.
|
|
83
|
+
- **Array:** after the six viewport slots (`_` through `xl`), indices **6–11** are `c_base`, `c_xs`, `c_sm`, `c_md`, `c_lg`, `c_xl` respectively. Use when you need the full ordered chain.
|
|
84
|
+
|
|
85
|
+
**When to use which**
|
|
86
|
+
|
|
87
|
+
- **Viewport keys** (`_`, `xs`, … `xl`) — page-level layout, full-bleed sections, global nav.
|
|
88
|
+
- **Container keys** (`c_base`, … `c_xl`) — reusable widgets whose width is driven by layout, not the device alone.
|
|
89
|
+
|
|
90
|
+
## Page layout grid (12 columns)
|
|
91
|
+
|
|
92
|
+
12-column grid at all breakpoints. Tier columns group breakpoints with identical margin/gutter/row-gap numbers from [Layout](https://gamut.codecademy.com/?path=/docs-foundations-layout--docs).
|
|
93
|
+
|
|
94
|
+
| Property | xl/lg | md | sm/xs | base |
|
|
95
|
+
| ------------------ | ----- | ---- | ----- | ---- |
|
|
96
|
+
| Horizontal margins | 64px | 48px | 32px | 16px |
|
|
97
|
+
| Column gutters | 32px | 24px | 16px | 8px |
|
|
98
|
+
| Row gaps | 32px | 24px | 16px | 8px |
|
|
99
|
+
|
|
100
|
+
Minimum touch target on mobile: **44×44px** — see `gamut-accessibility` skill for hit-target guidance.
|
|
101
|
+
|
|
102
|
+
## Responsive rules
|
|
103
|
+
|
|
104
|
+
- Begin design work at 1440px (XL), then adapt down.
|
|
105
|
+
- Multi-column layouts collapse to fewer columns — do not stretch or squish.
|
|
106
|
+
- Catalog cards and non-lockup elements should align on one axis (usually left), not fill column widths.
|
|
107
|
+
- Avoid dense or small components at the base (mobile) breakpoint.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Typography
|
|
2
|
+
|
|
3
|
+
Use **theme typography tokens** (`fontFamily`, `fontSize`, `fontWeight`, `lineHeight`) — never hardcoded font-family strings or magic px for product UI. Prefer `<Text>` from `@codecademy/gamut`, or `system.typography` / `css()` from `@codecademy/gamut-styles` ([`gamut-system-props` skill](../../skills/gamut-system-props/SKILL.md)).
|
|
4
|
+
|
|
5
|
+
Source of truth for scales and stacks: [`packages/gamut-styles/src/variables/typography.ts`](https://github.com/Codecademy/gamut/blob/main/packages/gamut-styles/src/variables/typography.ts) and theme builders under [`packages/gamut-styles/src/themes`](https://github.com/Codecademy/gamut/tree/main/packages/gamut-styles/src/themes).
|
|
6
|
+
|
|
7
|
+
**Storybook:** [Typography / Text](https://gamut.codecademy.com/?path=/docs-typography-text--docs) · [Meta / Best practices](https://gamut.codecademy.com/?path=/docs-meta-best-practices--page) (system props) · Foundations / Theme: [Core](https://gamut.codecademy.com/?path=/docs-foundations-theme-core-theme--docs), [Percipio](https://gamut.codecademy.com/?path=/docs-foundations-theme-percipio-theme--docs), [LX Studio](https://gamut.codecademy.com/?path=/docs-foundations-theme-lx-studio-theme--docs)
|
|
8
|
+
|
|
9
|
+
**DESIGN.md drift:** [`DESIGN.Percipio.md`](../../DESIGN.Percipio.md) and [`DESIGN.LXStudio.md`](../../DESIGN.LXStudio.md) sometimes describe **Roboto** or **Hanken Grotesk** for those products. **Shipped `gamut-styles` themes** currently use the stacks below (Skillsoft Text / Sans). Treat DESIGN YAML as product narrative until it matches code — confirm with the design platform when they disagree.
|
|
10
|
+
|
|
11
|
+
## Themes × font families
|
|
12
|
+
|
|
13
|
+
Semantic keys (`base`, `accent`, `monospace`, `system`) are stable; resolved stacks depend on `GamutProvider` theme ([`setup.md`](../setup.md)).
|
|
14
|
+
|
|
15
|
+
| Theme | `fontFamily.base` | `fontFamily.accent` | `fontFamily.monospace` | `fontFamily.system` |
|
|
16
|
+
| --------------------------------- | ------------------------------------ | ------------------------------------- | -------------------------------------- | ------------------------------ |
|
|
17
|
+
| **Core**, **Admin**, **Platform** | Apercu stack (`fontBase`) | Suisse + Apercu stack (`fontAccent`) | Monaco / Menlo stack (`fontMonospace`) | System UI stack (`fontSystem`) |
|
|
18
|
+
| **Percipio** | Skillsoft Text (`fontPercipioBase`) | Skillsoft Sans (`fontPercipioAccent`) | Roboto Mono | Roboto (`system`) |
|
|
19
|
+
| **LX Studio** | Same as Percipio (`base` / `accent`) | Same | Same stack as Core (`fontMonospace`) | Same as Core (`fontSystem`) |
|
|
20
|
+
|
|
21
|
+
Admin and Platform extend Core for colors / modes only — typography matches Core.
|
|
22
|
+
|
|
23
|
+
**Licensing:** Apercu is licensed for Codecademy surfaces only; Skillsoft products use Percipio/LX stacks above.
|
|
24
|
+
|
|
25
|
+
## Font size scale
|
|
26
|
+
|
|
27
|
+
Values are `rem`-backed keys on `theme.fontSize` (aliases shown as px for readability).
|
|
28
|
+
|
|
29
|
+
| Token | Size | Common use |
|
|
30
|
+
| ----- | ---- | ---------------------------- |
|
|
31
|
+
| `64` | 64px | Hero / display |
|
|
32
|
+
| `44` | 44px | Page titles |
|
|
33
|
+
| `34` | 34px | Section titles |
|
|
34
|
+
| `26` | 26px | Sub-section titles |
|
|
35
|
+
| `22` | 22px | Card titles, large UI labels |
|
|
36
|
+
| `20` | 20px | Secondary titles |
|
|
37
|
+
| `18` | 18px | Large body, intro text |
|
|
38
|
+
| `16` | 16px | Default body text |
|
|
39
|
+
| `14` | 14px | Small body, captions, labels |
|
|
40
|
+
|
|
41
|
+
## Line height
|
|
42
|
+
|
|
43
|
+
| Token | Value | Use |
|
|
44
|
+
| ------------- | ----- | ---------------------------- |
|
|
45
|
+
| `base` | 1.5 | Body text |
|
|
46
|
+
| `spacedTitle` | 1.3 | Sub-headlines, medium titles |
|
|
47
|
+
| `title` | 1.2 | Large headlines |
|
|
48
|
+
|
|
49
|
+
## Font weight (semantic)
|
|
50
|
+
|
|
51
|
+
Use **semantic keys** on components — do not assume a numeric bold everywhere.
|
|
52
|
+
|
|
53
|
+
| Token | Core / Admin / Platform | Percipio / LX Studio |
|
|
54
|
+
| ------- | ----------------------- | --------------------------------- |
|
|
55
|
+
| `base` | 400 | 400 |
|
|
56
|
+
| `title` | **700** | **500** (`fontWeightMediumTitle`) |
|
|
57
|
+
|
|
58
|
+
Headlines, CTAs, and buttons should use **`fontWeight="title"`** so Percipio/LX get **500**, Core gets **700**. Literal `700` breaks Skillsoft branding on those themes.
|
|
59
|
+
|
|
60
|
+
Numeric **`400`** and **`700`** keys also exist on the theme for rare explicit needs.
|
|
61
|
+
|
|
62
|
+
## Codecademy (Core / Admin / Platform) — voice & layout
|
|
63
|
+
|
|
64
|
+
These UX rules target **Apercu + Suisse** products; do not blindly apply to Percipio/LX without brand guidance.
|
|
65
|
+
|
|
66
|
+
- **`fontFamily="base"` (Apercu):** default UI and marketing type. Emphasis inside body copy: **Italic**, not Bold for intra-paragraph stress.
|
|
67
|
+
- **`fontFamily="accent"` (Suisse stack):** technical accent — code snippets, captions, labels with engineering flavor, figures. Use sparingly; glyph box reads larger — step **down ~10–15%** vs equivalent `base` size; give comfortable line-height.
|
|
68
|
+
- **Alignment:** left-align by default; center only short marketing headlines; avoid right-align except tabs / numerics.
|
|
69
|
+
- **Letter-spacing:** do not tweak tracking unless design specifies.
|
|
70
|
+
- **Line length:** ~45–85 characters per line (~66 ideal for single-column body); constrain container width, not arbitrary CSS letter-spacing.
|
|
71
|
+
|
|
72
|
+
## Line length (all products)
|
|
73
|
+
|
|
74
|
+
| Context | Target |
|
|
75
|
+
| ------------------ | ------------------- |
|
|
76
|
+
| Single-column body | ~66 chars (max ~85) |
|
|
77
|
+
| Multi-column | ≤50 chars per line |
|
|
78
|
+
| Minimum | ~45 chars |
|
|
79
|
+
|
|
80
|
+
## Related skills
|
|
81
|
+
|
|
82
|
+
- [`gamut-typography`](../../skills/gamut-typography/SKILL.md) — deeper editorial patterns for agents.
|
|
83
|
+
- [`gamut-style-utilities`](../../skills/gamut-style-utilities/SKILL.md) — `css()` / `variant` / `states` and tokenized typography in styled components.
|
|
84
|
+
- [`gamut-theming`](../../skills/gamut-theming/SKILL.md) — which theme / `GamutProvider` / `theme.d.ts`.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Gamut Design System
|
|
2
|
+
|
|
3
|
+
Gamut is the Codecademy / Skillsoft design system — React component library (`@codecademy/gamut`), design tokens (`@codecademy/gamut-styles`), and Figma components with live code previews via Figma Code Connect.
|
|
4
|
+
|
|
5
|
+
**Design voice**: "Ruled by logic, but creative and a bit unexpected." Structured and trustworthy for a learning platform, with engaging personality. Medium density — information-rich layouts with strong typographic hierarchy. Never cramped or overly airy.
|
|
6
|
+
|
|
7
|
+
**Core principles**:
|
|
8
|
+
|
|
9
|
+
- Components are color mode–aware by default — never hardcode hex values for adaptive, accessible UI
|
|
10
|
+
- All components work across all themes without modification
|
|
11
|
+
- 12-column grid
|
|
12
|
+
- Use **semantic theme tokens** from `@codecademy/gamut-styles` for **color roles** (ColorMode-aware), **typography**, **spacing**, **border radii**, and shared **layout** values (`elements`, …) — not raw palette hex or magic numbers. Defaults support accessible pairings, but **no token set guarantees WCAG AA** for every composition; validate non-standard combinations.
|
|
13
|
+
|
|
14
|
+
**ColorMode in product UI:** Use `<ColorMode>` and `<Background>` from `@codecademy/gamut-styles` for scoped light/dark and contrast-safe surfaces — see [foundations/modes.md](foundations/modes.md) and the `gamut-color-mode` skill. Storybook: [ColorMode](https://gamut.codecademy.com/?path=/docs-foundations-colormode--page), [Best practices](https://gamut.codecademy.com/?path=/docs-meta-best-practices--page) (semantic tokens + `css` / `variant` / `states`).
|
|
15
|
+
|
|
16
|
+
**Agent skills (styling / themes):** `gamut-style-utilities` (`css`, `variant`, `states`, `StyleProps`), `gamut-theming` (which theme, `GamutProvider`, new themes), `gamut-system-props` (`system.*` / `Box`), `gamut-color-mode` (ColorMode / semantic color).
|
|
17
|
+
|
|
18
|
+
## Themes
|
|
19
|
+
|
|
20
|
+
Runtime stacks come from `@codecademy/gamut-styles` (see [foundations/typography.md](foundations/typography.md)). Product `DESIGN.*.md` may differ until reconciled.
|
|
21
|
+
|
|
22
|
+
| Theme | Product | Primary UI fonts (shipped theme) | Dark mode |
|
|
23
|
+
| ------------- | ------------------------------- | ------------------------------------------------------------------------------ | --------- |
|
|
24
|
+
| **Core** | Codecademy (default) | Apercu + Suisse (`accent`) | ✓ |
|
|
25
|
+
| **Admin** | Codecademy admin tools | Same as Core | ✓ |
|
|
26
|
+
| **Platform** | Codecademy learning environment | Same as Core | ✓ |
|
|
27
|
+
| **LX Studio** | LX Studio application | Skillsoft Text / Sans (`base` / `accent`); DESIGN docs may list Hanken Grotesk | — |
|
|
28
|
+
| **Percipio** | Skillsoft Percipio | Skillsoft Text / Sans; DESIGN docs may list Roboto | — |
|
|
29
|
+
|
|
30
|
+
Set the theme at the app root via `<GamutProvider theme={...}>`.
|
|
31
|
+
|
|
32
|
+
**`gamut plugin` and `DESIGN.md`:** See Storybook [Meta → AI Tooling → Gamut plugin → Install](https://gamut.codecademy.com/?path=/docs-meta-ai-tooling-gamut-plugin-install--page). For app repos: `gamut plugin install cursor --theme core` (or `percipio`, `lxstudio`, …) from the repo root, or copy the appropriate `DESIGN.*.md` to `DESIGN.md` manually. Figma Make: [Meta → AI Tooling → Figma](https://gamut.codecademy.com/?path=/docs-meta-ai-tooling-figma-about--page).
|
|
33
|
+
|
|
34
|
+
## Reading order
|
|
35
|
+
|
|
36
|
+
| File | What it covers |
|
|
37
|
+
| ------------------------------------------------------ | ------------------------------------------------------------------------------ |
|
|
38
|
+
| [setup.md](setup.md) | Packages, GamutProvider, theme selection |
|
|
39
|
+
| [foundations/color.md](foundations/color.md) | Semantic roles (all themes), where to verify hex, Core-only cheatsheets |
|
|
40
|
+
| [foundations/modes.md](foundations/modes.md) | Light/dark ColorMode, Background component |
|
|
41
|
+
| [foundations/typography.md](foundations/typography.md) | Theme fonts, scales, semantic `title` weight (700 vs 500), Core voice rules |
|
|
42
|
+
| [foundations/spacing.md](foundations/spacing.md) | Spacing scale, radii, Layout grid; system props + responsive/container queries |
|
|
43
|
+
| [components/overview.md](components/overview.md) | Full component catalog |
|
|
44
|
+
| [components/buttons.md](components/buttons.md) | Button variants, props, decision tree |
|
|
45
|
+
| `agent-tools/skills/gamut-style-utilities/SKILL.md` | `css` / `variant` / `states`, `StyleProps`, `useTheme` escape hatch |
|
|
46
|
+
| `agent-tools/skills/gamut-theming/SKILL.md` | Theme matrix, `GamutProvider`, CreatingThemes |
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Setup
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
yarn add @codecademy/gamut-kit @emotion/react @emotion/styled
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`gamut-kit` bundles `gamut`, `gamut-icons`, `gamut-illustrations`, `gamut-patterns`, `gamut-styles`, `variance`, and `gamut-tests`.
|
|
10
|
+
|
|
11
|
+
**Full guide:** [Meta / Installation](https://gamut.codecademy.com/?path=/docs-meta-installation--page) in Storybook (CSP `nonce` on `GamutProvider`, Jest, Next/Gatsby entry points). For Emotion + TypeScript, add `theme.d.ts` as in [TypeScript (`theme.d.ts`)](#typescript-themedts) below.
|
|
12
|
+
|
|
13
|
+
Optionally add a `peerDependencies` block in `package.json` listing `@codecademy/gamut`, `@codecademy/gamut-icons`, `@codecademy/gamut-illustrations`, `@codecademy/gamut-patterns`, `@codecademy/gamut-styles`, `@codecademy/gamut-tests`, and `@codecademy/variance` (e.g. `"*"`) so editors surface those packages — see Meta / Installation for the JSON snippet.
|
|
14
|
+
|
|
15
|
+
## Required wrapper
|
|
16
|
+
|
|
17
|
+
Wrap the app root in `<GamutProvider>` from `@codecademy/gamut-styles`. This wires up the theme, color mode, and logical properties for all child components.
|
|
18
|
+
|
|
19
|
+
At runtime, `GamutProvider` defaults to Core when `theme` is omitted (`theme = coreTheme` in the implementation). For non-Core products and for TypeScript (`theme` is required on `GamutProviderProps`), pass `theme` explicitly using the table below.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { GamutProvider, theme } from '@codecademy/gamut-styles';
|
|
23
|
+
|
|
24
|
+
const App = () => (
|
|
25
|
+
<GamutProvider theme={theme}>{/* app content */}</GamutProvider>
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Theme selection
|
|
30
|
+
|
|
31
|
+
| Product | Theme to import |
|
|
32
|
+
| ------------------- | ----------------------------- |
|
|
33
|
+
| Codecademy public | `coreTheme` (default `theme`) |
|
|
34
|
+
| Codecademy admin | `adminTheme` |
|
|
35
|
+
| Codecademy platform | `platformTheme` |
|
|
36
|
+
| LX Studio | `lxStudioTheme` |
|
|
37
|
+
| Percipio | `percipioTheme` |
|
|
38
|
+
|
|
39
|
+
All themes are exported from `@codecademy/gamut-styles`.
|
|
40
|
+
|
|
41
|
+
## TypeScript (`theme.d.ts`)
|
|
42
|
+
|
|
43
|
+
Augment `@emotion/react` so `props.theme` in `styled` / `css` matches the **same theme object** you pass to `<GamutProvider theme={...}>`. If the types disagree, system props and token autocomplete will not line up with runtime.
|
|
44
|
+
|
|
45
|
+
Add a root `theme.d.ts` (or merge into your existing global types):
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
// theme.d.ts
|
|
49
|
+
import '@emotion/react';
|
|
50
|
+
|
|
51
|
+
import type { CoreTheme } from '@codecademy/gamut-styles';
|
|
52
|
+
|
|
53
|
+
declare module '@emotion/react' {
|
|
54
|
+
export interface Theme extends CoreTheme {}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Use the **theme interface that matches your provider** — same row as the [theme selection](#theme-selection) table:
|
|
59
|
+
|
|
60
|
+
| `GamutProvider` `theme` prop | Import for `Theme extends …` |
|
|
61
|
+
| ---------------------------- | ---------------------------- |
|
|
62
|
+
| `theme` or `coreTheme` | `CoreTheme` |
|
|
63
|
+
| `adminTheme` | `AdminTheme` |
|
|
64
|
+
| `platformTheme` | `PlatformTheme` |
|
|
65
|
+
| `lxStudioTheme` | `LxStudioTheme` |
|
|
66
|
+
| `percipioTheme` | `PercipioTheme` |
|
|
67
|
+
|
|
68
|
+
Example when the app uses Percipio:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// theme.d.ts
|
|
72
|
+
import '@emotion/react';
|
|
73
|
+
|
|
74
|
+
import type { PercipioTheme } from '@codecademy/gamut-styles';
|
|
75
|
+
|
|
76
|
+
declare module '@emotion/react' {
|
|
77
|
+
export interface Theme extends PercipioTheme {}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
See Emotion’s [TypeScript / define a theme](https://emotion.sh/docs/typescript#define-a-theme) for details.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Apply these guardrails when editing Gamut UI in TS/JS/TSX/JSX. Universal rules (always loaded). Form wiring depth: **`gamut-forms`** skill; other component matrix and audit detail: **`gamut-accessibility`** — those skills do not repeat this rule set.
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
globs: ['*.tsx', '*.ts', '*.jsx', '*.js']
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Gamut Accessibility Rules
|
|
8
|
+
|
|
9
|
+
## Prefer HTML over ARIA
|
|
10
|
+
|
|
11
|
+
Unnecessary ARIA can cause harm. If a native HTML element or attribute with the semantics and behavior you need already exists, use it. Reach for ARIA only when native HTML is genuinely insufficient for the pattern.
|
|
12
|
+
|
|
13
|
+
## A Role is a Promise
|
|
14
|
+
|
|
15
|
+
ARIA roles modify the accessibility tree and _imply_ behavior. Always ensure that the implied keyboard behavior, focusability, and interactivity exists when a role is used.
|
|
16
|
+
|
|
17
|
+
## ARIA can both cloak and enhance
|
|
18
|
+
|
|
19
|
+
ARIA can augment native semantics (`aria-pressed` on a `<button>`) or override them entirely (`role="menuitem"` on an `<a>`). Both capabilities are powerful and dangerous. Override only when native HTML genuinely doesn't fit the pattern; when augmenting, don't contradict the native semantics.
|
|
20
|
+
|
|
21
|
+
## Align accessible names with visible copy
|
|
22
|
+
|
|
23
|
+
Prefer wiring names through visible text and native `<label>` / control text / `alt` over using `aria-label`. Point `aria-labelledby` at the visible heading or label that should define the name if it's not possible to name elements from their content. Use bare `aria-label` when there is no suitable visible label.
|
|
24
|
+
|
|
25
|
+
## Treat missing visible labels as a design smell
|
|
26
|
+
|
|
27
|
+
When there is no visible text for a nameable element, consider this a sign that the content design could be improved, but not a requirement that it is changed. This is not an accessibility violation.
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<!-- smell: this list has no conceptual name, so we have to create one using ARIA -->
|
|
31
|
+
<ul aria-label="List heading">
|
|
32
|
+
<li>...</li>
|
|
33
|
+
</ul>
|
|
34
|
+
|
|
35
|
+
<!-- better: the list's name is visible and can be used for its accessible name -->
|
|
36
|
+
<h2 id="list-name">List heading</h2>
|
|
37
|
+
<ul aria-labelledby="list-name">
|
|
38
|
+
<li>...</li>
|
|
39
|
+
</ul>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Use Gamut primitives — do not fake buttons or dialogs
|
|
43
|
+
|
|
44
|
+
- **Actions:** use Gamut button atoms (`FillButton`, `TextButton`, `StrokeButton`, `CTAButton`, `IconButton`) — not `<div onClick>`, not `<span role="button">`, not `<a>` without `href` for actions. Variant and `tip` guidance: [`guidelines/components/buttons.md`](../guidelines/components/buttons.md).
|
|
45
|
+
- **Tabs / overlays:** `Tabs`, `Dialog`, `Modal`, and related primitives implement keyboard and focus patterns in code — still supply labels, titles, and trigger semantics as documented in the skill.
|
|
46
|
+
|
|
47
|
+
## Every interactive control needs an accessible name
|
|
48
|
+
|
|
49
|
+
- **`IconButton`** — provide `tip` (accessible name for icon-only).
|
|
50
|
+
- **`InfoTip`** — provide `ariaLabel` or `ariaLabelledby`; there is no automatic fallback.
|
|
51
|
+
- Decorative icon SVGs next to visible text — `aria-hidden="true"` on the icon.
|
|
52
|
+
|
|
53
|
+
## Form label association
|
|
54
|
+
|
|
55
|
+
Match **`htmlFor`** on **`<FormGroupLabel>`** with the **`id`** on the control. Base **`<FormGroup>`** renders live regions for **`error`** and **`description`**; **`GridForm`** and **`ConnectedForm`** add field wiring (**`aria-describedby`**, **`aria-invalid`**, first-error **`aria-live`** behavior) — do not add redundant duplicate regions. Depth: **[`skills/gamut-forms/SKILL.md`](../skills/gamut-forms/SKILL.md)**.
|
|
56
|
+
|
|
57
|
+
## Screen-reader-only text
|
|
58
|
+
|
|
59
|
+
Use `<Text screenreader>` for visually hidden but announced content. `<HiddenText>` is deprecated.
|
|
60
|
+
|
|
61
|
+
## Color and contrast
|
|
62
|
+
|
|
63
|
+
Do not hardcode hex for adaptive UI. Prefer semantic tokens and **`ColorMode` / `<Background>`** so surfaces track theme and mode — see the **`gamut-color-mode`** skill and [`foundations/modes.md`](../guidelines/foundations/modes.md). Default pairings support accessible UI, but **tokens do not guarantee WCAG compliance** for every layout; validate non-standard combinations.
|
|
64
|
+
|
|
65
|
+
## Focus visibility
|
|
66
|
+
|
|
67
|
+
Never suppress focus indicators with `outline: none` or `outline: 0` without a visible replacement. Gamut’s focus styles are intentional (WCAG 2.4.7).
|
|
68
|
+
|
|
69
|
+
## Where to read more (minimal index)
|
|
70
|
+
|
|
71
|
+
| Topic | Primary doc |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| Forms (`GridForm`, `ConnectedForm`, `FormGroup`, validation, live regions) | [`skills/gamut-forms/SKILL.md`](../skills/gamut-forms/SKILL.md) |
|
|
74
|
+
| Component matrix (tips, overlays, composites, checklists; not form wiring) | [`skills/gamut-accessibility/SKILL.md`](../skills/gamut-accessibility/SKILL.md) |
|
|
75
|
+
| Button variants, `IconButton` `tip`, `disabled` vs `aria-disabled` | [`guidelines/components/buttons.md`](../guidelines/components/buttons.md) |
|
|
76
|
+
| ColorMode, `Background`, semantic color roles | **`gamut-color-mode`** skill · [`foundations/modes.md`](../guidelines/foundations/modes.md) · [`foundations/color.md`](../guidelines/foundations/color.md) |
|
|
77
|
+
| Tokens, `css` / `variant` / `states` | Storybook [Meta / Best practices](https://gamut.codecademy.com/?path=/docs-meta-best-practices--page) |
|
|
78
|
+
| Install, `GamutProvider`, CSP | Storybook [Meta / Installation](https://gamut.codecademy.com/?path=/docs-meta-installation--page) |
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gamut-accessibility
|
|
3
|
+
description: Deep Gamut accessibility reference (component matrix, overlays, tips, live regions, checklists). Form wiring and validation UX live in **`gamut-forms`**. Universal HTML/ARIA/focus/color rules: always-loaded **`accessibility.mdc`** — read that first; this skill does not duplicate them.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Gamut Accessibility
|
|
7
|
+
|
|
8
|
+
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.
|
|
9
|
+
|
|
10
|
+
**Product-oriented button variants and props:** [`guidelines/components/buttons.md`](../../guidelines/components/buttons.md)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Universal rules
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## How Gamut handles accessibility
|
|
21
|
+
|
|
22
|
+
**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.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Component reference (index)
|
|
27
|
+
|
|
28
|
+
There is **no** exported `<Button>` — use **`FillButton`**, **`TextButton`**, **`StrokeButton`**, **`CTAButton`**, and **`IconButton`** (shared **`ButtonProps`** type). Prefer these over `<div onClick>` or `<span role="button">`.
|
|
29
|
+
|
|
30
|
+
**Forms** — **`FormGroup`**, **`ConnectedForm`** / **`ConnectedFormGroup`**, **`GridForm`**, field atoms (**`Select`**, **`Checkbox`**, **`Radio`**), validation, **`aria-live`** / **`aria-describedby`**: canonical reference is **[`gamut-forms`](../gamut-forms/SKILL.md)**.
|
|
31
|
+
|
|
32
|
+
| Component(s) | Handled in library | App / author responsibilities |
|
|
33
|
+
| --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
34
|
+
| **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`. |
|
|
35
|
+
| **IconButton** | `tip` feeds the accessible name for icon-only controls | Always pass **`tip`** when the button has no visible text. |
|
|
36
|
+
| **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). |
|
|
37
|
+
| **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). |
|
|
38
|
+
| **Alert** | Default **`aria-live="polite"`**, **`role="status"`** | Use **`aria-live="assertive"`** only for urgent interruptions; do not nest inside another live region. |
|
|
39
|
+
| **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. |
|
|
40
|
+
| **Forms** | See **Forms** above | **[`gamut-forms`](../gamut-forms/SKILL.md)** |
|
|
41
|
+
| **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). |
|
|
42
|
+
| **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). |
|
|
43
|
+
| **Popover** | **`FocusTrap`** when open (unless **`skipFocusTrap`**), positioning | **`onRequestClose`**, meaningful **`role`** when needed; do not trap focus unnecessarily when **`skipFocusTrap`**. |
|
|
44
|
+
| **Flyout** | **`Overlay`**, **`Drawer`**, visible **`title`**, close **`IconButton`** with **`tip={closeLabel}`** | Pass **`title`** and **`closeLabel`**; name panel content. |
|
|
45
|
+
| **Drawer** | Focuses container when **`expanded`**, **`tabIndex={-1}`** on shell | Drawer is a surface, not a full dialog — supply headings/labels inside for screen readers. |
|
|
46
|
+
| **Disclosure** | **`DisclosureButton`** drives expand/collapse | Provide **`heading`** / structure so the control’s purpose is clear. |
|
|
47
|
+
| **Toggle** | **`ToggleLabel`** + **`htmlFor`** wired to control **`id`** | With no visible **`label`**, pass **`ariaLabel`** (or use `as="button"` pattern per props). |
|
|
48
|
+
| **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). |
|
|
49
|
+
| **InfoTip** | — | **`ariaLabel`** or **`ariaLabelledby`** (camelCase) — no automatic fallback. |
|
|
50
|
+
| **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. |
|
|
51
|
+
| **SkipToContent** | Skip link behavior | Place early in the tab order; **`href`** target **`id`** must exist on main content. |
|
|
52
|
+
| **Toast** + **Toaster** | **`Toaster`** wraps the stack in **`aria-live="polite"`** | Keep messages concise; avoid stacking many simultaneous assertive announcements. |
|
|
53
|
+
| **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). |
|
|
54
|
+
| **FocusTrap** | Escape, outside click, **`allowPageInteraction`** | Return focus to trigger on close for custom overlays. |
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// correct
|
|
58
|
+
<IconButton icon={DeleteIcon} tip="Delete item" onClick={handleDelete} />
|
|
59
|
+
|
|
60
|
+
// wrong — no accessible name, no keyboard semantics
|
|
61
|
+
<div onClick={handleDelete}><DeleteIcon /></div>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Dialog / Modal (detail)
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
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).
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<Dialog
|
|
72
|
+
title="Confirm deletion"
|
|
73
|
+
confirmCta={{ children: 'Delete', onClick: handleDelete }}
|
|
74
|
+
onRequestClose={handleClose}
|
|
75
|
+
isOpen={open}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Alert (detail)
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
### Tabs (detail)
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
### InfoTip (example)
|
|
88
|
+
|
|
89
|
+
**`<InfoTip>`** needs **`ariaLabel`** or **`ariaLabelledby`** — see also the always-loaded rules.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
<InfoTip ariaLabel="More information about billing" />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### ToolTip (detail)
|
|
96
|
+
|
|
97
|
+
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).
|
|
98
|
+
|
|
99
|
+
### SkipToContent (detail)
|
|
100
|
+
|
|
101
|
+
Include **`<SkipToContent>`** as the first focusable element in the page shell. The main content region must expose a matching **`id`** for the skip target.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Focus management
|
|
106
|
+
|
|
107
|
+
**`<FocusTrap>`** is for custom overlay patterns not covered by **`Dialog`** / **`Modal`**.
|
|
108
|
+
|
|
109
|
+
Key props:
|
|
110
|
+
|
|
111
|
+
- **`active`** — enable/disable the trap dynamically
|
|
112
|
+
- **`onEscapeKey`** — close handler
|
|
113
|
+
- **`onClickOutside`** — dismiss on outside click
|
|
114
|
+
- **`allowPageInteraction`** — permit scrolling outside the trap without closing
|
|
115
|
+
|
|
116
|
+
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.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Composite widgets and managed focus
|
|
121
|
+
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
Implementation pattern — roving tabindex:
|
|
125
|
+
|
|
126
|
+
- Set **`tabIndex={0}`** on the currently active item
|
|
127
|
+
- Set **`tabIndex={-1}`** on all other items
|
|
128
|
+
- On arrow key, update which item holds **`tabIndex={0}`** and call **`.focus()`** on it
|
|
129
|
+
|
|
130
|
+
**`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.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Device-independent events
|
|
135
|
+
|
|
136
|
+
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.
|
|
137
|
+
|
|
138
|
+
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:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
142
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
handleActivation();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Prefer Gamut **`*Button`** components (or **`Anchor`** with a real **`href`**) so you do not reimplement this.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Live regions
|
|
154
|
+
|
|
155
|
+
| Scenario | Pattern |
|
|
156
|
+
| ------------------------------------------ | --------------------------------------------------- |
|
|
157
|
+
| Status updates, non-critical notifications | **`aria-live="polite"`** |
|
|
158
|
+
| Urgent global interruptions | **`aria-live="assertive"`** (use sparingly) |
|
|
159
|
+
| Frequently updating counts or progress | **`aria-live="polite"`** + **`aria-atomic="true"`** |
|
|
160
|
+
|
|
161
|
+
Form-bound **`aria-live`** and **`FormError`** patterns: see **Forms** above (do not assume assertive on every field error).
|
|
162
|
+
|
|
163
|
+
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.
|
|
164
|
+
|
|
165
|
+
Do not elevate unrelated inline errors to **`assertive`** — reserve assertive for urgent interruptions the user did not directly trigger.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## ARIA authoring rules
|
|
170
|
+
|
|
171
|
+
- **No redundant roles**: don't set **`role="button"`** on **`<button>`** or **`role="heading"`** on **`<h2>`**
|
|
172
|
+
- **`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
|
|
173
|
+
- **`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
|
|
174
|
+
- **Labelling vs describing**: **`aria-label`** / **`aria-labelledby`** name the control. **`aria-describedby`** provides supplementary context. Both can coexist on the same element
|
|
175
|
+
- **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
|
|
176
|
+
- **`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
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Color and contrast (non-text)
|
|
181
|
+
|
|
182
|
+
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.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Testing checklist
|
|
187
|
+
|
|
188
|
+
- [ ] Full keyboard navigation: every interactive element reachable and operable without a mouse
|
|
189
|
+
- [ ] Focus is always visible and never lost or unexpectedly trapped
|
|
190
|
+
- [ ] Dialogs trap focus correctly; Escape closes; focus returns to the trigger
|
|
191
|
+
- [ ] Composite widgets (tabs, menus, listboxes) use arrow keys internally, not Tab
|
|
192
|
+
- [ ] All form inputs have programmatically associated labels (not placeholder-only)
|
|
193
|
+
- [ ] Form errors surface through the library’s **`FormError`** / live-region patterns (**Forms** above)
|
|
194
|
+
- [ ] Icon-only controls have accessible names
|
|
195
|
+
- [ ] No content relies solely on color to convey meaning
|
|
196
|
+
- [ ] Screen reader matrix: VoiceOver + Safari (iOS), VoiceOver + Chrome (macOS), NVDA + Chrome (Windows)
|
|
197
|
+
- [ ] 200% zoom: layout intact, no content overflow or disappearance
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Common anti-patterns
|
|
202
|
+
|
|
203
|
+
| Anti-pattern | Fix |
|
|
204
|
+
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
|
|
205
|
+
| **`<div onClick={…}>`** for actions | **`FillButton`**, **`TextButton`**, **`StrokeButton`**, **`CTAButton`**, or **`IconButton`** (with **`tip`**) |
|
|
206
|
+
| **`placeholder`** as the only label | **`FormGroupLabel`** with matching **`htmlFor`** / **`id`** |
|
|
207
|
+
| **`aria-label`** on a **`<div>`** with no role | Add a meaningful **`role`** or use a semantic element |
|
|
208
|
+
| **`role="button"`** without Space/Enter handlers | Use a Gamut **`*Button`**, **`Anchor`** with **`href`**, or add **`keydown`** |
|
|
209
|
+
| **`tabIndex={0}`** on every item in a composite | Roving tabindex: **`0`** on active item, **`-1`** on rest |
|
|
210
|
+
| Tooltip as the only accessible name for a control | Set **`aria-label`** (or visible text) on the control as well |
|
|
211
|
+
| **`aria-hidden="true"`** on a focusable element | Also remove from tab order (**`tabIndex={-1}`**) or restructure |
|
|
212
|
+
| **`mousedown`** for activation | Use **`click`** |
|
|
213
|
+
| **`outline: none`** without a replacement | Use Gamut’s built-in focus styles |
|
|
214
|
+
| Multiple **`aria-live`** regions for the same content stream | One region per logical stream; reuse it across updates |
|