Skip to content

Commit bf7c97f

Browse files
chore: add generated AI component index for /next (#5079)
* chore: add generated AI component index for /next Generates documentation/AI-COMPONENT-INDEX.md listing every /next component with props, sub-components, and asChild support. Gives AI coding assistants a stable ground-truth reference instead of re-walking the source tree each session. Wired into `prebuild` so `pnpm run build` keeps it fresh; ad-hoc regeneration via `pnpm run generate:component-index`. Closes #4890 * Fix incomplete string escaping or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * chore: verify component index freshness in CI * chore: reference component index from scaffolding entry points --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent f1bfc56 commit bf7c97f

11 files changed

Lines changed: 477 additions & 5 deletions

File tree

.claude/commands/new-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This command focuses on the per-component scaffolding flow. The patterns and cod
1515
- `figma_get_screenshot` — visual reference
1616
- `figma_get_variable_defs` — tokens **per state** (Default, Hover, Focus, Disabled, and any other state in the design). Use the EXACT variable names returned.
1717

18-
2. **Check for existing components to reuse** in `packages/eds-core-react/src/components/next/index.ts`. Prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography` over reinventing.
18+
2. **Check the component index first** [`documentation/AI-COMPONENT-INDEX.md`](../../documentation/AI-COMPONENT-INDEX.md) lists every existing `/next` component with its props and sub-components (generated, CI-verified). Confirm `$ARGUMENTS` doesn't already exist, and prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography` over reinventing. The underlying source of truth is `packages/eds-core-react/src/components/next/index.ts`.
1919

2020
3. **If an old component exists** at `packages/eds-core-react/src/components/$ARGUMENTS/`, read it for behavioural awareness (keyboard nav, focus management) only — do not copy implementation. Use modern patterns: `:focus-visible`, CSS tokens, simple state.
2121

.claude/rules/eds-component.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ paths:
1111
1212
This file is intentionally short. It only highlights what's easy to forget when working in `/next`:
1313

14+
- **Check [`documentation/AI-COMPONENT-INDEX.md`](../../documentation/AI-COMPONENT-INDEX.md) before creating a component** — a generated, CI-verified list of every `/next` component with props and sub-components; it may already exist
1415
- **No default exports** (except `.stories.tsx`)
1516
- **WCAG 2.1 AA** is non-negotiable — `jest-axe` test in every component
1617
- **Use `--eds-*` design tokens** — never hardcode hex values

.github/prompts/new-component.prompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This prompt focuses on the per-component scaffolding flow. The patterns and code
1818
- `figma_get_screenshot` — visual reference
1919
- `figma_get_variable_defs` — tokens **per state** (Default, Hover, Focus, Disabled, and any other state in the design). Use the EXACT variable names returned.
2020

21-
2. **Check for existing components to reuse** in `packages/eds-core-react/src/components/next/index.ts`. Prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography` over reinventing.
21+
2. **Check the component index first** [`documentation/AI-COMPONENT-INDEX.md`](../../documentation/AI-COMPONENT-INDEX.md) lists every existing `/next` component with its props and sub-components (generated, CI-verified). Confirm `${input:componentName}` doesn't already exist, and prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography` over reinventing. The underlying source of truth is `packages/eds-core-react/src/components/next/index.ts`.
2222

2323
3. **If an old component exists** at `packages/eds-core-react/src/components/${input:componentName}/`, read it for behavioural awareness (keyboard nav, focus management) only — do not copy implementation. Use modern patterns: `:focus-visible`, CSS tokens, simple state.
2424

.github/workflows/checks.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
secrets: inherit
2323
with:
2424
cacheKey: ${{ github.sha }}
25-
checkout_paths: packages apps scripts .github
25+
checkout_paths: packages apps scripts .github documentation
2626
packages:
2727
name: Process packages
2828
runs-on: ubuntu-latest
@@ -48,6 +48,11 @@ jobs:
4848
- name: Fallback install (cache miss)
4949
if: steps.setup-cache.outputs.cache-hit != 'true'
5050
run: pnpm install
51+
# Must run BEFORE the build: `prebuild` regenerates the index in the
52+
# workspace, which would mask a stale committed file.
53+
- name: Check AI component index freshness
54+
id: check-component-index
55+
run: pnpm run generate:component-index --check
5156
- name: Build packages
5257
id: build-packages
5358
run: pnpm run build

.opencode/agent/eds-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ When invoked to create a new component, follow this flow:
1515

1616
1. **Ask for a Figma URL.** If provided, run `figma_get_design_context`, `figma_get_screenshot`, and `figma_get_variable_defs` **per state** (Default, Hover, Focus, Disabled, etc.). Use the EXACT variable names returned.
1717

18-
2. **Check for existing components to reuse** in `packages/eds-core-react/src/components/next/index.ts`prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography`.
18+
2. **Check the component index first** [`documentation/AI-COMPONENT-INDEX.md`](../../documentation/AI-COMPONENT-INDEX.md) lists every existing `/next` component with its props and sub-components (generated, CI-verified). Confirm the component doesn't already exist, and prefer composing `Field`, `Icon`, `Input`, `Button`, `Typography`. The underlying source of truth is `packages/eds-core-react/src/components/next/index.ts`.
1919

2020
3. **If an old component exists** at `packages/eds-core-react/src/components/<name>/`, read it for behavioural awareness only — do not copy implementation. Use modern patterns (`:focus-visible`, CSS tokens, simple state).
2121

AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Equinor Design System (EDS) is a pnpm monorepo containing React component librar
1313
- `@equinor/eds-tokens` — Design tokens, CSS variables, and theming
1414
- `@equinor/eds-icons` — Icon library
1515

16+
### Existing /next components
17+
18+
Before scaffolding a new component, check [`documentation/AI-COMPONENT-INDEX.md`](./documentation/AI-COMPONENT-INDEX.md) — a generated list of every `/next` component with its props and sub-components. It is regenerated on `pnpm run build` (or run `pnpm run generate:component-index` ad-hoc). Don't edit it by hand.
19+
1620
## Secrets & Credentials
1721

1822
Never read, search, copy, or print the contents of secret files. The rule applies to **every** harness (Claude Code, Copilot, OpenCode) regardless of whether the harness enforces it.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- AUTOGENERATED by scripts/generate-component-index.js — do not edit by hand. -->
2+
<!-- Re-run: pnpm run generate:component-index -->
3+
4+
# EDS 2.0 Component Index (`/next`)
5+
6+
This file is the canonical "what already exists" reference for AI coding assistants working in this repo. It is regenerated from the source on every `pnpm run build`.
7+
8+
**If you are an AI assistant about to scaffold a new component: check this file first.** The component you are about to build may already exist.
9+
10+
- Source path: `packages/eds-core-react/src/components/next/<Component>/`
11+
- Top-level barrel: `packages/eds-core-react/src/components/next/index.ts`
12+
- Components: 23 • Props documented: 96 • With JSDoc description: 1
13+
14+
## Components
15+
16+
| Component | Description | Props | Sub-components | asChild | Status |
17+
| --- | --- | --- | --- | --- | --- |
18+
| Accordion || exclusive | Accordion.Item, Accordion.Header, Accordion.Panel || active |
19+
| Autocomplete || allowCustomValue, clearLabel, defaultInputValue, description, helperMessage, id, inputValue, label, loading, loadingText, noOptionsText, onClear, onCustomValueConfirm, onInputChange, onValueChange, optionsFilter, value ||| active |
20+
| Badge || emphasis, tone, variant ||| active |
21+
| Banner || onDismiss, role, tone | Banner.Icon, Banner.Message, Banner.Actions || active |
22+
| Button || asChild, icon, multiline, round, size, tone, variant ||| active |
23+
| Checkbox || disabled, helperMessage, indeterminate, indicator, label ||| active |
24+
| Chip || dropdown, onDelete, selected, tone, variant ||| active |
25+
| Dialog || onOpenChange, open, scrim | Dialog.Header, Dialog.Title, Dialog.Content, Dialog.Actions || active |
26+
| Divider ||||| active |
27+
| Field || disabled, position | Field.Label, Field.Description, Field.HelperMessage || active |
28+
| Icon | Icon component for EDS 2.0 | color, data, size, title ||| active |
29+
| Input || as, containerClassName, endAdornment, endText, hideErrorIcon, invalid, startAdornment, startText ||| active |
30+
| Link || asChild, variant ||| active |
31+
| Menu ||||| active |
32+
| MenuItem || active ||| active |
33+
| Radio || label ||| active |
34+
| Search || clearLabel, description, helperMessage, id, label, onClear ||| active |
35+
| Select || description, helperMessage, id, indicator, invalid, label, options, placeholder, readOnly ||| active |
36+
| Slot ||||| active |
37+
| Switch || label ||| active |
38+
| TextArea || description, helperMessage, id, indicator, invalid, label, labelInfo, maxRows, showCharacterCount ||| active |
39+
| TextField || description, helperMessage, id, indicator, label, labelInfo ||| active |
40+
| Tooltip || disabled, placement, title ||| active |
41+
42+
## Field reference
43+
44+
- **Description** — first paragraph of the JSDoc above the component's `forwardRef` declaration (also tries `<Name>Component` / `<Name>Root` for compound components), with the `<Name>Props` type alias as fallback. `` means no JSDoc is present yet; consider adding one.
45+
- **Props** — EDS-defined props only, from the `<Name>Props` type literal. Intersected HTML attributes (`HTMLAttributes<...>`, `InputHTMLAttributes<...>`, etc.) and React-conventional props (`children`, `className`, `style`, `ref`, `key`) are NOT listed — assume the standard DOM props for the underlying element are available. Known limitation: only inline type literals and intersections are walked — props coming from a referenced local type alias (`type FooProps = SharedBase & {...}`) or a union type are not expanded.
46+
- **Sub-components** — compound sub-components attached via the `Compound<Name>` type pattern (e.g. `Field.Label`, `Banner.Icon`). Standalone components exported from the same directory (e.g. `MenuItem` from `./Menu`) appear as their own rows.
47+
- **asChild**`` if the component supports the `asChild` polymorphism pattern (see `Slot/README.md`).
48+
- **Status**`active` unless the props type carries an `@deprecated` JSDoc tag.
49+
50+
## Out of scope
51+
52+
- Components outside `/next` (legacy `packages/eds-core-react/src/components/`)
53+
- Other packages (`eds-data-grid-react`, `eds-lab-react`)
54+
- Per-prop type signatures (names only)
55+
- Storybook links

documentation/agent-instructions/BUILDING_EDS_2_COMPONENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This is the canonical reference for the patterns that go into an EDS 2.0 compone
44

55
For the project-wide conventions (file structure, code style, CSS layering, testing, accessibility, conventional commits), see [`AGENTS.md`](../../AGENTS.md). This guide adds the component-building specifics that are not covered there.
66

7+
**Before building anything, check [`documentation/AI-COMPONENT-INDEX.md`](../AI-COMPONENT-INDEX.md)** — a generated, CI-verified list of every existing `/next` component with its props and sub-components. The component you are about to build may already exist, or an existing one may compose into what you need. One file read replaces walking the whole `/next` tree.
8+
79
## Table of Contents
810

911
- [Foundation Data-Attribute Reference](#foundation-data-attribute-reference)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"lint:css": "stylelint ./packages/eds-core-react/src/components/next/**/*.css",
1313
"init": "pnpm install --force && pnpm run build",
1414
"extract-prerequisites": "node scripts/extract-prerequisites.js",
15-
"prebuild": "pnpm run extract-prerequisites",
15+
"generate:component-index": "node scripts/generate-component-index.js",
16+
"prebuild": "pnpm run extract-prerequisites && pnpm run generate:component-index",
1617
"build": "pnpm run build:token-sync && pnpm run build:tokens-build && pnpm run build:icons && pnpm run build:tokens && pnpm run build:utils && pnpm run build:core-react && pnpm run build:data-grid-react && pnpm run build:lab && pnpm run build:color-palette-generator:cli",
1718
"build:color-palette-generator:cli": "pnpm --filter @equinor/eds-color-palette-generator run build:cli",
1819
"build:core-react": "pnpm --filter @equinor/eds-core-react run build",
@@ -96,6 +97,7 @@
9697
"stylelint-config-standard": "^40.0.0",
9798
"stylelint-order": "^8.1.1",
9899
"prettier": "3.9.5",
100+
"ts-morph": "^27.0.2",
99101
"typescript": "^5.9.3"
100102
},
101103
"browserslist": "last 2 Chrome versions, last 2 firefox versions, last 2 safari versions, last 2 edge versions, not dead",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)