|
| 1 | +# AGENTS |
| 2 | + |
| 3 | +This file defines the working conventions for `design-system`. |
| 4 | +Follow these instructions for every pull request. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Environment & Tooling |
| 9 | +- **Node/NPM:** Node ≥20.15.0 and npm ≥10.7.0. |
| 10 | +- **Dependency manager:** Use `npm` with the committed `package-lock.json`. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Design Tokens (MANDATORY) |
| 15 | +Design tokens are the source of truth for colors, spacing, radius, elevation, etc. |
| 16 | + |
| 17 | +- **Token sources:** |
| 18 | + - Raw tokens: `css/src/tokens/index.css` |
| 19 | + - Token mappings & variables: `css/src/variables/index.css` |
| 20 | +- **Usage:** |
| 21 | + - Reference tokens through CSS variables (e.g., `var(--primary)`, `var(--border-radius-10)`, `var(--shadow-m)`) & only use tokens defined in `css/src/variables/index.css` files as css variables. |
| 22 | + - Do not hard-code hex values, pixel sizes, or box-shadow rules outside the token files. |
| 23 | + - Add or modify tokens only within the token files. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Design System Components (MANDATORY) |
| 28 | +Always use existing design system components before creating new ones or using native HTML elements. |
| 29 | + |
| 30 | +- **Component library:** `core/components/` |
| 31 | +- **Available atoms:** Avatar, AvatarGroup, Badge, Breadcrumbs, Button, Caption, Card, Checkbox, Chip, ChipGroup, Divider, Dropdown, Flex, Heading, HelpText, Icon, Input, Label, Legend, Link, LinkButton, Message, Meter, Paragraph, Pills, ProgressBar, ProgressRing, Radio, Row, Column, SegmentedControl, Slider, Spinner, StatusHint, Subheading, SwitchInput, Text, Textarea, Toast, and more. |
| 32 | +- **Available molecules:** Chat, ChatMessage, ChipInput, Dialog, Dropzone, EditableChipInput, EditableDropdown, EditableInput, EmptyState, FileList, FileUploader, FullscreenModal, InputMask, KeyValuePair, Modal, Pagination, Placeholder, Popover, Sidesheet, Stepper, Tabs, Tooltip, VerificationCodeInput, and more. |
| 33 | +- **Available organisms:** Calendar, ChoiceList, Combobox, DatePicker, DateRangePicker, Grid, HorizontalNav, InlineMessage, List, Listbox, Menu, Navigation, PageHeader, Select, Table, TextField, TimePicker, VerticalNav, and more. |
| 34 | +- **Rules:** |
| 35 | + - Import from the component's `index.tsx` (e.g., `import { Button } from '@/core/components/atoms/button'`). |
| 36 | + - Extend existing components via props rather than wrapping with custom HTML. |
| 37 | + - Do not replicate functionality already covered by an existing component. |
| 38 | + - When a component doesn't exist yet, follow the component layout structure below and build it from atomic components upward. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Code Style & Structure |
| 43 | +- **Languages:** TypeScript & React only. |
| 44 | +- **File naming:** PascalCase for component files; use `.tsx` for components. |
| 45 | +- **Component layout:** |
| 46 | + ```` |
| 47 | +
|
| 48 | + core/ |
| 49 | + ├── index.tsx # Export Components |
| 50 | + ├── index.type.tsx # Export Components Props/Types |
| 51 | + ├── components/{atoms|molecules|organisms}/ComponentName/ |
| 52 | + ├── index.tsx # Component Main entry file |
| 53 | + ├── {ComponentName}.tsx # Component Implementation |
| 54 | + ├── __tests__/ # Component Unit Tests |
| 55 | + ├── __stories__/ # Storybook stories |
| 56 | +
|
| 57 | + ```` |
| 58 | +- **Types:** Props interfaces named `[ComponentName]Props` extending `BaseProps`. Capitalize type aliases (e.g., `Appearance`, `Size`). |
| 59 | +- **Exports:** Named export of components from `index.tsx`; export props from `index.type.tsx`. |
| 60 | +- **Testing:** Jest & React Testing Library is used for unit testing and coverage. |
| 61 | +- Snapshots and unit tests are written in [COMPONENT_NAME].test.tsx file inside the __tests__ folder. |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## Styling |
| 66 | +- CSS Module has been used to define the class names. |
| 67 | +- Create a CSS file inside **css** directory with the file extension `module.css` (e.g avatar.module.css) |
| 68 | +- Use **ClassNames**, a utility for conditionally joining CSS classNames together. |
| 69 | +- Follow the **BEM Convention** & use CSS Modules for naming CSS classes. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Quality Checks (run before committing) |
| 74 | +1. `npm run lint:check` – ESLint for TS/JS. |
| 75 | +2. `npm run prettier:check` – Prettier for CSS. |
| 76 | +3. `npm run lint:types` – TypeScript type check. |
| 77 | +4. `npm test` – Jest unit tests (update tests alongside source changes). |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Commit & Branch Conventions |
| 82 | +- **Conventional Commits:** `type(component): message` |
| 83 | + - Valid types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore` |
| 84 | +- Keep commits focused; prefer a single commit per PR. |
| 85 | +- Branch names should reflect the work (e.g., `feat-button`, `fix-modal-height`). |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Documentation & Stories |
| 90 | +- Update or add Storybook stories for any visual or API change. |
| 91 | +- Update Markdown docs in `docs/` when behavior or usage changes. |
| 92 | +- Add/modify Figma files in `figma/` and connect via `figma-code-connect` for new components. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Accessibility (WCAG 2.2 AA — MANDATORY) |
| 97 | +All components must meet WCAG 2.2 AA. Treat WCAG as a hard requirement, not a guideline. |
| 98 | + |
| 99 | +### A11y References |
| 100 | +- Audit process: `.cursor/rules/wcag-a11y-audit-report.mdc` |
| 101 | +- Audit patterns: `.cursor/rules/wcag-audit-patterns.md` |
| 102 | +- Guidelines: `.cursor/rules/vercel-a11y-guidelines.mdc`, `.cursor/rules/web-interface-a11y-guidelines.mdc` |
| 103 | +- WCAG source data: `a11y-context/wcag-as-json.json` |
| 104 | + |
| 105 | +### Semantic HTML & ARIA |
| 106 | +- MUST: Use native semantics (`<button>`, `<a>`, `<label>`, `<table>`) before ARIA. |
| 107 | +- MUST: `<button>` for actions; `<a>`/`<Link>` for navigation — never `<div onClick>`. |
| 108 | +- MUST: Icon-only buttons must have a descriptive `aria-label`. |
| 109 | +- MUST: Decorative icons/images must have `aria-hidden="true"` / `alt=""`. |
| 110 | +- MUST: All images need `alt` text (empty string if purely decorative). |
| 111 | +- MUST: Custom widgets must have correct ARIA roles, states, and properties (`aria-expanded`, `aria-checked`, `aria-selected`, etc.). |
| 112 | +- MUST: Form inputs need `<label>` (via `htmlFor`) or `aria-label`/`aria-labelledby`. |
| 113 | +- MUST: Status/error messages use `role="alert"` or `aria-live="polite"` as appropriate. |
| 114 | +- MUST: No duplicate `id` attributes in the DOM. |
| 115 | + |
| 116 | +### Keyboard Navigation |
| 117 | +- MUST: All interactive elements are fully keyboard accessible. |
| 118 | +- MUST: Keyboard interactions follow [WAI-ARIA APG patterns](https://www.w3.org/WAI/ARIA/apg/patterns/). |
| 119 | +- MUST: No keyboard traps (unless intentional modal trapping per APG). |
| 120 | +- MUST: Focus is managed correctly — trap in modals, return focus on close. |
| 121 | +- MUST: Tab order is logical and matches visual order. |
| 122 | + |
| 123 | +### Focus Visibility |
| 124 | +- MUST: Visible focus ring on all interactive elements using `:focus-visible`. |
| 125 | +- NEVER: `outline: none` / `outline-none` without a visible focus replacement. |
| 126 | +- MUST: Focus indicators meet 3:1 contrast ratio against adjacent colors. |
| 127 | +- MUST: Focused elements are not obscured by sticky headers or overlays (WCAG 2.4.11). |
| 128 | + |
| 129 | +### Color & Contrast |
| 130 | +- MUST: Text contrast ≥ 4.5:1 (normal); ≥ 3:1 (large text ≥18pt or 14pt bold). |
| 131 | +- MUST: UI component boundaries and icons ≥ 3:1 contrast ratio. |
| 132 | +- MUST: Color is never the only means of conveying information (use icons, text, or patterns as redundant cues). |
| 133 | +- MUST: Error states use more than color alone. |
| 134 | + |
| 135 | +### Touch & Target Size |
| 136 | +- MUST: Interactive hit targets ≥ 24×24 px (mobile ≥ 44×44 px); expand hit area with padding if visual size is smaller. |
| 137 | +- MUST: `touch-action: manipulation` to prevent double-tap zoom delay. |
| 138 | +- MUST: No dead zones on checkboxes/radios — label and control share one hit target. |
| 139 | + |
| 140 | +### Motion & Animation |
| 141 | +- MUST: Honor `prefers-reduced-motion` — provide reduced variant or disable animation entirely. |
| 142 | +- MUST: Animate only compositor-friendly properties (`transform`, `opacity`). |
| 143 | +- NEVER: `transition: all` — list properties explicitly. |
| 144 | +- MUST: Animations are interruptible and respond to user input. |
| 145 | + |
| 146 | +### Content Handling |
| 147 | +- MUST: Text containers handle long content (`truncate`, `line-clamp`, `break-words`). |
| 148 | +- MUST: Flex children need `min-w-0` to allow text truncation. |
| 149 | +- MUST: Handle empty states — no broken UI for empty strings or arrays. |
| 150 | +- MUST: Locale-aware dates/times/numbers (`Intl.DateTimeFormat`, `Intl.NumberFormat`). |
| 151 | + |
| 152 | +### Per-Component Audit (when building or modifying components) |
| 153 | +For each component, validate: |
| 154 | +1. HTML structure and heading hierarchy. |
| 155 | +2. ARIA roles, states, and properties. |
| 156 | +3. Keyboard interactions and event handlers. |
| 157 | +4. Color contrast of all visual states (default, hover, focus, active, disabled, error). |
| 158 | +5. Touch target sizes. |
| 159 | +6. Focus handling (visibility, order, trap/return). |
| 160 | +7. Screen reader announcements for dynamic content. |
| 161 | +8. `prefers-reduced-motion` support for any animations. |
| 162 | + |
| 163 | +### Anti-patterns (always flag and fix) |
| 164 | +- `user-scalable=no` or `maximum-scale=1` disabling zoom. |
| 165 | +- `onPaste` with `preventDefault` blocking paste. |
| 166 | +- `outline: none` without focus-visible replacement. |
| 167 | +- `<div>` or `<span>` with click handlers instead of `<button>`. |
| 168 | +- Icon buttons without `aria-label`. |
| 169 | +- Images without `alt` attribute. |
| 170 | +- Form inputs without associated labels. |
| 171 | +- Hardcoded color values outside token files (contrast cannot be verified programmatically). |
| 172 | + |
| 173 | +### Resolving Lint Warnings |
| 174 | +- Resolve all `jsx-a11y` ESLint warnings before committing. |
| 175 | +- Run `npm run lint:check` and fix every a11y violation reported. |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +## Review & Misc |
| 180 | +- Avoid committing generated artifacts (`dist/`, `.lib/`) or build output. |
| 181 | +- Add yourself to contributors via `all-contributors` when appropriate. |
| 182 | +- PRs should include a clear description, pass all CI checks, and request review when ready. |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +Adhering to these guidelines keeps the design system consistent, accessible, and maintainable. |
0 commit comments