@box-kite/react 2.3.0 → 2.4.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.
Files changed (57) hide show
  1. package/.claude/rules/box-kite-rules.md +58 -92
  2. package/.claude/skills/box-kite/SKILL.md +81 -114
  3. package/.claude/skills/box-kite/references/components.md +1 -1
  4. package/.claude/skills/box-kite/references/patterns.md +1 -1
  5. package/.claude/skills/box-kite/references/rules.md +115 -0
  6. package/.claude/skills/box-kite/references/styling.md +2 -2
  7. package/.cursor/rules/box-kite.mdc +61 -95
  8. package/AGENTS.md +62 -96
  9. package/BOX_AI_CONTEXT.md +82 -78
  10. package/BOX_KITE_AI_CONTEXT.md +82 -78
  11. package/README.md +201 -716
  12. package/catalog.cjs +1 -1
  13. package/catalog.mjs +3 -0
  14. package/client.cjs +1 -1
  15. package/client.mjs +81 -81
  16. package/components/combobox/comboboxListbox.d.ts +2 -1
  17. package/components/combobox.cjs +1 -1
  18. package/components/combobox.d.ts +1 -1
  19. package/components/combobox.mjs +199 -188
  20. package/components/dataGrid/components/dataGridFooter.d.ts +6 -2
  21. package/components/dataGrid/contracts/dataGridContract.d.ts +2 -1
  22. package/components/dataGrid/models/gridModel.d.ts +21 -2
  23. package/components/dataGrid/models/groupRowModel.d.ts +1 -1
  24. package/components/dataGrid/models/rowModel.d.ts +1 -1
  25. package/components/dataGrid/models/sourceGroupRowModel.d.ts +5 -1
  26. package/components/dataGrid/models/sourceRowModel.d.ts +5 -1
  27. package/components/dataGrid/useListLayout.d.ts +1 -1
  28. package/components/dataGrid.cjs +3 -3
  29. package/components/dataGrid.mjs +732 -682
  30. package/components/radioGroup.cjs +1 -1
  31. package/components/radioGroup.mjs +1 -0
  32. package/components/semantics.d.ts +29 -29
  33. package/components/skeleton.cjs +1 -1
  34. package/components/skeleton.d.ts +1 -1
  35. package/components/skeleton.mjs +2 -1
  36. package/components/sortableList.cjs +1 -1
  37. package/components/sortableList.mjs +1 -1
  38. package/components/svg.d.ts +2 -2
  39. package/components/swipeItem.cjs +1 -1
  40. package/components/swipeItem.mjs +1 -1
  41. package/components/textarea.d.ts +1 -1
  42. package/components/textbox.d.ts +1 -1
  43. package/components/timeZoneSelect.d.ts +1 -1
  44. package/components/toaster.cjs +1 -1
  45. package/components/toaster.mjs +13 -14
  46. package/dataGridList.cjs +1 -1
  47. package/dataGridList.mjs +3 -5
  48. package/docs/a11y.md +1 -2
  49. package/docs/index.md +1 -1
  50. package/docs/props.md +43 -19
  51. package/effects.cjs +1 -1
  52. package/effects.mjs +2 -2
  53. package/identity.cjs +1 -1
  54. package/identity.mjs +5 -7
  55. package/package.json +12 -12
  56. package/react/effects.d.ts +5 -6
  57. package/react/identity/useIdentifier.d.ts +0 -3
package/README.md CHANGED
@@ -1,785 +1,270 @@
1
- # Box Kite
1
+ <div align="center">
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@box-kite/react)](https://www.npmjs.com/package/@box-kite/react)
4
- [![bundle size](https://img.shields.io/bundlephobia/minzip/@box-kite/react)](https://bundlephobia.com/package/@box-kite/react)
5
- [![Tests](https://github.com/box-kite/box-kite/actions/workflows/test.yml/badge.svg)](https://github.com/box-kite/box-kite/actions/workflows/test.yml)
6
- [![license](https://img.shields.io/npm/l/@box-kite/react)](LICENSE)
3
+ <a href="https://www.box-kite.dev">
4
+ <img src="https://raw.githubusercontent.com/box-kite/box-kite/main/.github/assets/banner.png" alt="Box Kite — every CSS property is a typed prop. The React styling library your AI already knows." width="100%" />
5
+ </a>
7
6
 
8
- `Box` is a single React component with 235 typed CSS props. It generates the CSS for the values you
9
- pass at runtime and caches every rule by its content, so the same value anywhere in the app reuses
10
- one class — a project styles itself in TypeScript, with no CSS files to write and no class-name
11
- convention to remember.
7
+ <h3>The AI-first, fully typed styling library for React</h3>
12
8
 
13
- [Docs and live demos](https://www.box-kite.dev) · [Blog](https://www.box-kite.dev/blog/) · [Contributing](CONTRIBUTING.md) ·
14
- [Support](SUPPORT.md) · [Security](SECURITY.md) ·
15
- [Releases](https://github.com/box-kite/box-kite/releases)
9
+ <p>
10
+ <a href="https://www.npmjs.com/package/@box-kite/react"><img src="https://img.shields.io/npm/v/@box-kite/react?color=7c3aed&label=npm" alt="npm version" /></a>
11
+ <a href="https://github.com/box-kite/box-kite/actions/workflows/test.yml"><img src="https://github.com/box-kite/box-kite/actions/workflows/test.yml/badge.svg" alt="Tests" /></a>
12
+ <img src="https://img.shields.io/badge/TypeScript-every%20value-3178c6?logo=typescript&logoColor=white" alt="TypeScript: every value is typed" />
13
+ <a href="#-packages"><img src="https://img.shields.io/badge/dependencies-no%20third--party-10b981" alt="No third-party dependencies" /></a>
14
+ <a href="#-built-for-ai-agents"><img src="https://img.shields.io/badge/AGENTS.md-in%20the%20package-8b5cf6" alt="AGENTS.md ships in the package" /></a>
15
+ <a href="https://www.npmjs.com/package/@box-kite/mcp"><img src="https://img.shields.io/badge/MCP-server-a855f7" alt="MCP server" /></a>
16
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/@box-kite/react?color=64748b" alt="MIT license" /></a>
17
+ </p>
16
18
 
17
- **Built to be written by an AI.** The rules, every prop with the CSS it emits and a docs folder are
18
- inside the package, generated from the prop registry itself — so what your agent reads is never a
19
- version behind what it is writing against: [Built for AI](https://www.box-kite.dev/ai-context/) ·
20
- [`npx @box-kite/mcp`](https://www.npmjs.com/package/@box-kite/mcp) ·
21
- [generative UI](https://www.box-kite.dev/generative-ui/)
19
+ <p>
20
+ <a href="https://www.box-kite.dev"><b>Docs</b></a> ·
21
+ <a href="https://www.box-kite.dev/start-with-ai/"><b>Start with AI</b></a> ·
22
+ <a href="https://www.box-kite.dev/playground/">Playground</a> ·
23
+ <a href="https://www.box-kite.dev/showcase/">Showcase</a> ·
24
+ <a href="https://www.box-kite.dev/blog/">Blog</a> ·
25
+ <a href="https://github.com/box-kite/box-kite/releases">Releases</a>
26
+ </p>
22
27
 
23
- ## Getting Started
28
+ </div>
24
29
 
25
- 1. Installation
30
+ ---
26
31
 
27
- ```bash
28
- npm install @box-kite/react
29
- ```
30
-
31
- React 16.14 or newer, including 18 and 19 (both are covered by CI). TypeScript is optional but the
32
- props are typed for it.
33
-
34
- Two packages ship, and a React project installs one of them:
35
-
36
- | Package | What it is |
37
- | ------------------------------------------------- | ----------------------------------------------------------------- |
38
- | **`@box-kite/react`** | `Box`, every component, the hooks. Depends on the one below. |
39
- | [`@box-kite/core`](#using-the-core-without-react) | The engine and the types, no framework. For an app with no React. |
40
-
41
- `@box-kite/core/types` is where a project declares its own props and components — the augmentation
42
- target lives with the prop registry it extends, not with a binding.
43
-
44
- 2. Use it
32
+ **Box Kite** styles React in TypeScript. Every CSS property is a prop on `Box`, every value it takes is a type, and the CSS is
33
+ written for you at runtime — one shared class per value, no stylesheet to import, no class names to invent, no build plugin.
45
34
 
46
- Spacing counts in quarters of a rem: `p={3}` is `0.75rem`, `m={2}` is `0.5rem`. The example below is
47
- a box with `margin: 0.5rem` and `padding: 1.75rem`.
35
+ It is built to be **written by an AI**: the rules and a reference measured from the engine ship inside the package, an MCP
36
+ server checks a prop bag against the real engine, and the compiler refuses a value the library would not render.
48
37
 
49
- ```JS
50
- import Box from "@box-kite/react";
38
+ <!-- prettier-ignore -->
39
+ ```tsx
40
+ import Button from '@box-kite/react/components/button';
41
+ import Flex from '@box-kite/react/components/flex';
42
+ import { H2, P } from '@box-kite/react/components/semantics';
51
43
 
52
- export default function Component(props: Props) {
44
+ export function PlanCard() {
53
45
  return (
54
- <Box className="custom-class" m={2} p={7}>
55
- basic example
56
- </Box>
46
+ <Flex d="column" gap={3} p={6} md={{ p: 8 }} borderRadius={3} shadow="md"
47
+ bgColor="white" theme={{ dark: { bgColor: 'slate-900' } }}>
48
+ <H2 fontSize={20} fontWeight={600}>Pro plan</H2>
49
+ <P color="slate-600">Every value on this card is checked by the compiler.</P>
50
+ <Button hover={{ bgColor: 'indigo-600' }}>Upgrade</Button>
51
+ </Flex>
57
52
  );
58
53
  }
59
54
  ```
60
55
 
61
- **NOTE**: the root `font-size` is `16px`, so a quarter of a rem is 4px. Not every prop divides by
62
- four — `fontSize` divides by 16 (`fontSize={14}` is `0.875rem`), and border widths and `lineHeight`
63
- are plain pixels (`b={1}` is 1px).
56
+ Each prop becomes one shared class: `p={6}` is `padding: 1.5rem`, `md` wraps it in a media query, `theme` scopes it to the dark
57
+ subtree, and the same value anywhere else in the app reuses the same rule.
64
58
 
65
- There is nothing to memorise, though: every prop's hover documentation carries a worked example of
66
- the CSS it writes — `p={4} → padding: 1rem`, `fontSize={14} → font-size: 0.875rem` — and those lines
67
- are generated by running the engine, so the editor cannot tell you a scale the library stopped using.
68
-
69
- ## Colours
70
-
71
- The palette is Tailwind's, in OKLCH: twenty-six families of eleven steps — `slate-50` through
72
- `rose-950`, the four Tailwind 4.3 added (`mauve`, `mist`, `olive`, `taupe`) included — declared as CSS
73
- variables the first time a page asks for one. Any colour value takes an opacity modifier:
74
-
75
- ```JS
76
- <Box bgColor="blue-500/40" borderColor="black/10" hover={{ bgColor: 'blue-500/60' }} />
77
- ```
59
+ ## ⚡ Quick start
78
60
 
79
- That compiles to `color-mix(in oklab, var(--blue-500) 40%, transparent)`: the mix wraps the
80
- **variable**, so a themed token is still themed and everything asking for the same value still shares
81
- one class. It is not `opacity`, which fades the element, its text and its children — this fades one
82
- declaration. Every colour prop takes it (`color`, `bgColor`, `borderColor`, `outlineColor`, `fill`,
83
- `stroke`), as does a `vars` entry and a variable of your own from `Box.extend()`.
61
+ Start a new Vite + React app with a design, a sample page and the agent setup already in it:
84
62
 
85
- ## Gradients, shadows and filters
86
-
87
- A gradient is a value, not a string you assemble: the key names the kind and carries its geometry, and
88
- the stops are palette colours, so the whole thing is themed, takes the opacity modifier and shares one
89
- class with every other element asking for it.
90
-
91
- ```JS
92
- <Box bgGradient={{ linear: 'r', colors: ['blue-500', 'pink-500'] }} />
93
- <Box bgGradient={{ radial: 'circle', at: 'top left', colors: [['sky-500', '20%'], 'indigo-900'] }} />
94
- <Box bgGradient={{ conic: 45, colors: ['red-500', 'yellow-500', 'red-500'], interpolate: 'oklch' }} />
63
+ ```bash
64
+ npm create @box-kite@latest
95
65
  ```
96
66
 
97
- `interpolate` is worth knowing: sRGB drags a two-stop gradient through a grey middle, and `oklch` does
98
- not. `oklch-longer` takes the long way round the hue circle, which is what turns two stops into a
99
- spectrum. A gradient is judged whole — one unknown stop or one misspelt key and it emits no rule at
100
- all, rather than quietly painting something else.
101
-
102
- `box-shadow` is one CSS property, which normally means one shadow wins. Here it is **four layers** that
103
- compose, so an elevation, a ring and an inner hairline coexist:
67
+ Or add it to the app you have:
104
68
 
105
- ```JS
106
- <Box shadow="md" ring={2} ringColor="indigo-500" borderRadius={2} />
107
- <Box insetShadow="sm" insetRing={1} shadow="lg" shadowColor="blue-500/40" />
108
- ```
109
-
110
- `shadow` is Tailwind's elevation scale (`xxs` through `xxl`, and the older `small`/`medium`/`large`
111
- presets still work), `insetShadow` draws inside the border box, and `ring`/`insetRing` are a width in
112
- px. A ring follows `borderRadius` and costs no layout, which is what makes it different from
113
- `outline`. Each layer has its own colour prop — `shadowColor`, `ringColor`, and so on — which shows
114
- nothing until the layer it belongs to is painted, exactly as `borderColor` needs a border width.
115
- `textShadow` and `textShadowColor` are the text-side pair.
116
-
117
- Filters stack the same way, and for the same reason: `filter` is one property whose value is a list, so
118
- each of the nine functions sets a layer of its own and all nine write one composed declaration.
119
-
120
- ```JS
121
- <Box blur="sm" grayscale={100} />
122
- <Box brightness={110} saturate={150} hueRotate={90} />
123
- <Box dropShadow="lg" dropShadowColor="indigo-500/40" />
124
- <Box backdropBlur="sm" backdropSaturate={180} bgColor="white/20" />
69
+ ```bash
70
+ npm install @box-kite/react
125
71
  ```
126
72
 
127
- A number is the function's own unit — a percentage for `brightness`, `contrast`, `grayscale`,
128
- `invert`, `saturate` and `sepia`, degrees for `hueRotate`, pixels for `blur`, which takes Tailwind's
129
- `xs`–`xxxl` scale too. `dropShadow` is cast by the _shape_ rather than the box, which is what a
130
- transparent PNG or an SVG path wants. The nine `backdrop*` props are the same functions applied to
131
- what is behind the element — the glassmorphism half.
132
-
133
- `maskImage` takes the gradient record over again and reads its alpha channel, so a fade to
134
- `transparent` is an edge fade; and `bgClip="text"` with `color="transparent"` is how a gradient
135
- becomes lettering.
136
-
137
- ```JS
138
- <Box maskImage={{ linear: 'b', colors: ['black', ['black', '55%'], 'transparent'] }} />
139
- <H1 color="transparent" bgClip="text" bgGradient={{ linear: 'r', colors: ['violet-500', 'cyan-400'] }}>
140
- Painted by the background
141
- </H1>
73
+ React 18 or newer, and **no third-party dependencies**: the install is Box Kite and its own engine, nothing else. TypeScript is
74
+ optional, but it is where the library shines.
75
+
76
+ ## ✨ Why Box Kite
77
+
78
+ <table>
79
+ <tr>
80
+ <td width="50%" valign="top">
81
+ <h4>🤖 AI-first</h4>
82
+ <p>The package carries its own <code>AGENTS.md</code>, a <code>docs/</code> folder and a skill, all generated from the prop
83
+ registry so they can never be a version behind. An MCP server answers mid-task.</p>
84
+ </td>
85
+ <td width="50%" valign="top">
86
+ <h4>🔒 Typed down to the value</h4>
87
+ <p>Every prop accepts a closed set: palette tokens, scale steps, keywords. A typo is a compile error with a
88
+ <i>“Did you mean”</i>, not a silently missing style.</p>
89
+ </td>
90
+ </tr>
91
+ <tr>
92
+ <td valign="top">
93
+ <h4>🧩 Zero config, zero dependencies</h4>
94
+ <p>No CSS files, no PostCSS, no bundler plugin, no provider — and no third-party packages in your lockfile. Styles are
95
+ generated on demand and deduplicated by content.</p>
96
+ </td>
97
+ <td valign="top">
98
+ <h4>🖥️ Server Components</h4>
99
+ <p>Renders in a React Server Component with no <code>'use client'</code>: each rule travels with the markup as a
100
+ <code>&lt;style&gt;</code> React 19 hoists and dedupes.</p>
101
+ </td>
102
+ </tr>
103
+ <tr>
104
+ <td valign="top">
105
+ <h4>♿ Accessible components</h4>
106
+ <p>Dialog, Menu, Tabs, Combobox, DatePicker, DataGrid and more — each with the ARIA and keyboard of its APG pattern, swept
107
+ by axe in CI.</p>
108
+ </td>
109
+ <td valign="top">
110
+ <h4>🎨 Modern CSS, as props</h4>
111
+ <p>OKLCH palette, themes, container queries, <code>@starting-style</code>, anchor positioning, view transitions, scroll
112
+ timelines — and the top layer instead of <code>z-index</code>.</p>
113
+ </td>
114
+ </tr>
115
+ </table>
116
+
117
+ ## 🤖 Built for AI agents
118
+
119
+ A model's memory of a CSS-in-JS API is usually a memory of a _different_ API — the prop names here collide with Tailwind's
120
+ and Chakra's while the numbers mean something else. So Box Kite does not rely on what a model remembers:
121
+
122
+ | What | How you get it |
123
+ | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
124
+ | **`AGENTS.md` + `docs/`** inside the npm package | Automatic — `node_modules/@box-kite/react/AGENTS.md`, with every prop and the CSS it writes |
125
+ | **Project wiring** (`AGENTS.md`, `CLAUDE.md`, MCP) | `npm create @box-kite@latest -- --agents-only` — merges into an existing repo, and updates on a rerun |
126
+ | **Skill** for Claude Code, Cursor, Codex, Copilot… | `npx skills add box-kite/box-kite` |
127
+ | **MCP server** — no key, no network | `claude mcp add box-kite -- npx -y @box-kite/mcp` (or the stdio config your editor takes) |
128
+ | **llms.txt** and markdown docs | [box-kite.dev/llms.txt](https://www.box-kite.dev/llms.txt) — append `.md` to any docs URL |
129
+
130
+ **`check_styles` runs your props through the real engine.** A value the library does not accept writes no rule and no class
131
+ name — by design, so a typo never emits a broken declaration. The MCP tool makes that visible before anything renders:
132
+
133
+ ```text
134
+ ✅ p → .p-4{padding:1rem}
135
+ ❌ bgColor does not accept "blue-550" — no rule and no class name were written.
136
+ ✅ fontSize → .fontSize-14{font-size:0.875rem}
137
+ ⚠️ href an HTML attribute, not a style prop. Written at the top level it typechecks
138
+ and is then dropped — it goes in props={{ "href": … }}.
142
139
  ```
143
140
 
144
- ## Components
141
+ **The dev console is written as a prompt.** Each warning says what rendered and the line to write instead, so an agent reading
142
+ a test run fixes itself:
145
143
 
146
- Every component here is a `Box` underneath — the same style props, the same theming, the same
147
- `component`/`variant` defaults — with the right HTML tag, the ARIA its pattern owes and, where the
148
- pattern has one, its keyboard. Each is a separate entry point, so a `Textbox` does not pull the
149
- `DataGrid` into your bundle. Module paths below are relative to the package name, i.e.
150
- `@box-kite/react/components/flex`.
151
-
152
- ```JS
153
- import Box from "@box-kite/react";
144
+ ```text
145
+ [box-kite] bgColor="bleu-500" wrote no CSS: bgColor does not take that value, so the prop
146
+ was dropped along with its class. Did you mean "blue-500"?
147
+ [box-kite] fontSize={4} is 4px text: fontSize's divider is 16, not the spacing scale's 4,
148
+ so the number is the pixel size. For 16px write fontSize={16}.
154
149
  ```
155
150
 
156
- ### Layout and content
157
-
158
- | Component | Module | What it is |
159
- | ---------------------------------------------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------- |
160
- | `Flex` | `components/flex` | `Box` with `display: flex` |
161
- | `Grid` | `components/grid` | `Box` with `display: grid` |
162
- | `H1`–`H6`, `P`, `Span`, `Link`, `Img`, `Nav`, `Header`, `Main`, `Section`, … | `components/semantics` | one `Box` per semantic tag — 25 of them |
163
- | `Svg`, `Path`, `Circle`, `Rect`, `SvgText`, … | `components/svg` | one component per SVG element — 20 of them, so a drawing never writes `tag` |
164
- | `Icon` | `components/icon` | Box props on an icon somebody else drew — lucide, Tabler, react-icons, a raw `<svg>` |
165
- | `Sparkline`, `ProgressRing`, `Gauge`, `MiniDonut` | `components/chart` | chart micro-primitives over those elements — a chart that takes Box props and no chart library |
166
- | `ChartContainer` | `components/chart` | the theming bridge: the variables a Recharts (or any) chart reads, declared in both themes |
167
- | `BaseSvg` | `components/baseSvg` | deprecated: `Svg` with the 24×24 icon preset |
168
- | `VisuallyHidden` | `components/visuallyHidden` | text for a screen reader only — clipped away rather than hidden, so it stays in the a11y tree |
169
-
170
- ### Form controls
171
-
172
- | Component | Module | What it is |
173
- | ------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
174
- | `Button` | `components/button` | `<button>`, with `type` and `onClick` lifted out of `props` |
175
- | `Textbox` | `components/textbox` | `<input>` |
176
- | `Textarea` | `components/textarea` | `<textarea>` |
177
- | `Checkbox` | `components/checkbox` | a real `<input type="checkbox">`; `label` renders the wrapping `<label>` for you, and `indeterminate` reports `aria-checked="mixed"` |
178
- | `Switch` | `components/switch` | the same input as `role="switch"` — Enter toggles it as well as Space |
179
- | `RadioGroup`, `RadioGroup.Item` | `components/radioGroup` | the APG radio group: one shared `name`, one tab stop, arrow keys between the options |
180
- | `RadioButton` | `components/radioButton` | a single labelled `<input type="radio">`, for a group you assemble yourself |
181
- | `Select` | `components/select` | a `Dropdown` over a list of rows: `data={rows} def={{ valueKey, displayKey }}` |
182
- | `Form` | `components/form` | a `<form>` that reads its own fields on submit and hands them to you as one object |
183
-
184
- ### Overlays and data
185
-
186
- | Component | Module | What it is |
187
- | ----------------------------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
188
- | `Overlay` | `components/overlay` | the positioning primitive: a portal rendered where it is declared, so its children escape `overflow: hidden`. No ARIA, no open state, no dismissal |
189
- | `Tooltip` | `components/tooltip` | the APG tooltip on top of `Overlay` — hover _and_ focus, `aria-describedby`, Escape, hoverable (WCAG 1.4.13) |
190
- | `Dropdown`, `Dropdown.Item`, `Dropdown.Display` | `components/dropdown` | the APG combobox: select-only, or the editable one with `isSearchable` |
191
- | `DataGrid` | `components/dataGrid` | the APG grid — sorting, filtering, grouping, row selection, row details, virtualized rows and columns, and a keyboard that covers all of it |
192
-
193
- Two whose shape is not obvious from a table:
151
+ **And a UI a model writes at runtime is a first-class citizen.** `catalog()` turns every component and every value its props
152
+ take into JSON Schema — the shape structured output, json-render and A2UI want — and `<SpecRenderer>` renders what comes back,
153
+ checking each node against an allow-list you control. `toolPart()` and `a2uiToSpec()` read AI SDK, assistant-ui, CopilotKit,
154
+ AG-UI and A2UI, and `<ToolCallCard>`, `<ApprovalCard>`, `<Reasoning>` and `<StreamingText>` draw an agent's turn.
155
+ → [Generative UI](https://www.box-kite.dev/generative-ui/) · [Agent components](https://www.box-kite.dev/agent/) ·
156
+ [Interop](https://www.box-kite.dev/interop/)
194
157
 
195
- ```tsx
196
- // The tooltip's trigger is a render prop, so `aria-describedby` lands on the control itself
197
- // rather than on a wrapper around it.
198
- import Tooltip from '@box-kite/react/components/tooltip';
158
+ ## 🔒 Typed down to the value
199
159
 
200
- <Tooltip content="Deletes the row for good">{(trigger) => <Button {...trigger}>Delete</Button>}</Tooltip>;
201
- ```
160
+ Props are not `string`. Colours are palette tokens (with an optional `/opacity`), spacing is a scale, keywords are unions — so
161
+ the editor autocompletes them and the compiler catches the rest:
202
162
 
163
+ <!-- prettier-ignore -->
203
164
  ```tsx
204
- // `Form` reads the named fields under it when it submits, and hands them over as one object.
205
- import Button from '@box-kite/react/components/button';
206
- import Form from '@box-kite/react/components/form';
207
- import Textbox from '@box-kite/react/components/textbox';
208
-
209
- interface Credentials {
210
- email: string;
211
- password: string;
212
- }
213
-
214
- <Form<Credentials> p={4} onSubmit={(values) => signIn(values)}>
215
- <Textbox name="email" type="email" />
216
- <Textbox name="password" type="password" />
217
- <Button type="submit">Sign in</Button>
218
- </Form>;
219
- ```
220
-
221
- `onSubmit(values, event)` runs after the event's `preventDefault()`. A field is in `values` if it
222
- has a `name`: a lone checkbox or radio contributes its `checked` boolean, a name used more than
223
- once collects the checked or entered values into an array, and a dotted name (`address.city`,
224
- `lines[0].qty`) nests. Everything else arrives as the string the DOM holds — the type argument
225
- describes the object you expect, it is not checked against the fields.
226
-
227
- ## SVG
228
-
229
- Twenty-three SVG properties are Box props, so a shape is themed, hovered and made responsive the
230
- same way a `<div>` is — and there is a component for every SVG element, so a drawing never writes
231
- `tag` either.
232
-
233
- ```JSX
234
- import { Path, Svg } from '@box-kite/react/components/svg';
235
-
236
- <Svg
237
- viewBox="0 0 200 48"
238
- width="200px"
239
- fill="none"
240
- strokeWidth={3}
241
- strokeLinecap="round"
242
- strokeDasharray={320}
243
- strokeDashoffset={320}
244
- hover={{ strokeDashoffset: 0 }}
245
- theme={{ dark: { stroke: 'violet-400' }, light: { stroke: 'violet-600' } }}
246
- >
247
- <Path d="M8 40 L56 12 L104 34 L152 8 L192 24" />
248
- </Svg>;
249
- ```
250
-
251
- That draws the line on hover, and nothing in it declares a transition: every `<svg>` and the shapes
252
- inside it already transition on `--svgTransitionTime`, which `prefers-reduced-motion: reduce` sets
253
- to `0s`.
254
-
255
- | Prop | Notes |
256
- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
257
- | `fill`, `stroke` | any colour variable, or `'none'` |
258
- | `fillOpacity`, `strokeOpacity` | `0`–`1` in tenths, the same scale as `opacity` |
259
- | `fillRule` | `'nonzero'`, `'evenodd'` |
260
- | `strokeWidth`, `strokeDasharray`, `strokeDashoffset`, `strokeMiterlimit` | numbers in **SVG user units — no divider**. A dash pattern with its own gap is a string, `'12 4'` |
261
- | `strokeLinecap`, `strokeLinejoin` | `'butt'`/`'round'`/`'square'`, `'miter'`/`'round'`/`'bevel'` |
262
- | `paintOrder` | `'normal'`, `'fill'`, `'stroke'`, `'markers'` — `'stroke'` is how outlined text stays legible |
263
- | `vectorEffect` | `'none'`, `'non-scaling-stroke'` |
264
- | `shapeRendering` | `'auto'`, `'optimizeSpeed'`, `'crispEdges'`, `'geometricPrecision'` |
265
- | `textAnchor` | `'start'`, `'middle'`, `'end'` — which part of a label sits on its `x` |
266
- | `dominantBaseline` | `'alphabetic'`, `'central'`, `'hanging'`, … — which part sits on its `y` |
267
- | `cx`, `cy`, `r`, `rx`, `ry`, `x`, `y` | the SVG 2 geometry, in **user units**, or a percentage. `rx`/`ry` also take `'auto'` |
268
-
269
- Every paint and stroke property here is an inherited one, so setting it on the `<svg>` reaches the
270
- shapes inside — with two exceptions. `vector-effect` and `dominant-baseline` are not inherited, so
271
- those two props write a rule that names the element _and_ its descendants: `vectorEffect="non-scaling-stroke"`
272
- on the `<svg>` keeps a hairline one pixel wide however far the `viewBox` is scaled, and
273
- `dominantBaseline="central"` on the `<svg>` reaches every label in it.
274
-
275
- The geometry props are different again. They belong to one shape, so they go on the shape — but they
276
- are real CSS, which means they transition, and an animated gauge or a growing bar needs no JavaScript:
277
-
278
- ```JSX
279
- <Circle cx={48} cy={48} r={38} strokeDasharray={239} strokeDashoffset={239} hover={{ strokeDashoffset: 60, r: 40 }} />;
280
- ```
281
-
282
- Where a prop name and an SVG attribute collide, the element decides which one wins. On `Rect`,
283
- `width={40}` is forty user units rather than the layout scale's `10rem`; on `Path`, `d` is path data
284
- rather than `flex-direction`; on `SvgText`, `x` and `y` are the attributes, because the CSS geometry
285
- properties do not apply to `<text>`. On `Circle` those same names stay the CSS props that transition.
286
-
287
- ### Icons
288
-
289
- An icon set is somebody else's component, so there is no `tag` that renders one and Box cannot wrap
290
- it. `Icon` styles it through the one channel it does offer — the `className` it spreads onto its own
291
- `<svg>`:
292
-
293
- ```JSX
294
- import Icon from '@box-kite/react/components/icon';
295
- import { Sun } from 'lucide-react';
296
-
297
- <Icon size={5} color="amber-500" hover={{ color: 'amber-300' }} label="Sunny">
298
- <Sun />
299
- </Icon>;
300
- ```
301
-
302
- It works with lucide, Tabler, react-icons or an `<svg>` you paste in, and it knows none of their
303
- APIs: `size` is a number on the ÷4 scale (`size={6}` is 24px, the default) that lands in the class,
304
- where a CSS declaration outranks the `width`/`height` attributes the icon writes for itself. Without
305
- a `label` an icon is `aria-hidden`; with one it is `role="img"` and that name. For SVG you draw
306
- yourself, reach for `Svg` instead — it takes these props directly.
307
-
308
- Behind it is `useClassNames`, which is public for the same reason: a `motion.div`, a router's
309
- `NavLink` or a third-party chart takes a `className` and nothing else.
310
-
311
- ```JSX
312
- import { useClassNames } from '@box-kite/react';
313
-
314
- const { className, styles } = useClassNames({ color: 'sky-500', hover: { color: 'sky-300' } });
315
-
316
- <>
317
- {styles}
318
- <NavLink to="/" className={className} />
319
- </>;
320
- ```
321
-
322
- `styles` is defined in element mode only, where the CSS travels as hoistable `<style>` elements
323
- rather than going to a stylesheet; elsewhere it is undefined and rendering it costs nothing.
324
-
325
- ### Charts
326
-
327
- Four micro-primitives, built from the SVG components — the small drawings a dashboard needs rather
328
- than a chart library:
329
-
330
- ```JSX
331
- import { Gauge, MiniDonut, ProgressRing, Sparkline } from '@box-kite/react/components/chart';
332
-
333
- <Sparkline data={[4, 9, 6, 12, 10, 15]} variant="area" color="sky-500" width="7rem" />;
334
- <ProgressRing value={0.62} color="emerald-500" label="62% complete" />;
335
- <Gauge value={0.4} sweep={180} color="rose-500" />;
336
- <MiniDonut data={[5, 3, 2]} />;
337
- ```
338
-
339
- There are no axes, no legends and no data transformations: what they give you instead is that a
340
- chart is a Box, so its colour, its size, its dark mode and its hover state are the props you already
341
- know. A sparkline stretches to whatever box it is in (and keeps its line one width thick, through
342
- `vectorEffect="non-scaling-stroke"`), a ring's arc eases between values with no animation code, and
343
- naming follows `Svg`: no `label` means `aria-hidden`, a `label` means `role="img"`.
344
-
345
- They are cheap enough for one in every row of a virtualized grid, because the part that differs per
346
- row — the shape — is the `d` attribute, which the styling engine never sees. What _is_ a style prop
347
- is the paint, which the rows share. `fill` and `stroke` also take `url(#gradient)` and
348
- `var(--chart-1)` now, so a gradient fill is a value with a theme and a `hover`, not an attribute.
349
-
350
- ### Theming a chart library
351
-
352
- The other half of charts is the chart library you already use. A `<ChartContainer>` declares the
353
- variables a chart reads, so the chart itself names no colour at all:
354
-
355
- ```JSX
356
- import { ChartContainer } from '@box-kite/react/components/chart';
357
- import { Area, AreaChart, ResponsiveContainer, XAxis } from 'recharts';
358
-
359
- <ChartContainer series={['revenue', 'cost']} height={60}>
360
- <ResponsiveContainer width="100%" height="100%">
361
- <AreaChart data={months}>
362
- <XAxis dataKey="month" />
363
- <Area dataKey="revenue" stroke="var(--color-revenue)" fill="var(--color-revenue)" fillOpacity={0.15} />
364
- <Area dataKey="cost" stroke="var(--color-cost)" fill="var(--color-cost)" fillOpacity={0.15} />
365
- </AreaChart>
366
- </ResponsiveContainer>
367
- </ChartContainer>;
368
- ```
369
-
370
- It declares `--chart-1` … `--chart-6` in both themes and one `--color-<series>` per series you name,
371
- so the chart flips light to dark with nothing in its own code changing — and the names are the ones
372
- the ecosystem already uses, so a chart lifted out of shadcn's charts works unchanged.
373
-
374
- What makes that cheap is the prop behind it. `vars` is the one prop whose declaration _names_ come
375
- from its value:
376
-
377
- ```JSX
378
- <Flex vars={{ 'color-revenue': 'sky-500', 'chart-gap': '4px' }} theme={{ dark: { vars: { 'color-revenue': 'sky-400' } } }}>
379
- ```
380
-
381
- declares `--color-revenue: var(--sky-500)` and `--chart-gap: 4px` on the element, inherited by
382
- everything inside it — including markup this library never rendered. A colour token resolves to the
383
- variable behind it, anything else is written out as it stands. Being an ordinary prop, it nests in a
384
- theme, a breakpoint and a pseudo-class, and it lands in a **class**: two subtrees declaring the same
385
- palette share one rule, and nothing needs a `<style>` tag or an `id` to scope it to one chart.
386
-
387
- ## Extend props
388
-
389
- It is possible to add your own props to define your custom styles.
390
- You need to do a few steps.
391
-
392
- 1. In a project root file you need to define your extends
393
-
394
- ```JS
395
- import Box from "@box-kite/react";
396
-
397
- export const { extendedProps, extendedPropTypes } = Box.extend(
398
- // css variables
399
- {
400
- dark: '#123123',
401
- light: '#ededed',
402
- cssVarName: 'cssVarValue',
403
- myShadow: '10px 5px 5px red',
404
- myGradient1: 'linear-gradient(#e66465, #9198e5)',
405
- myGradient2: 'linear-gradient(black, white)',
406
- },
407
- // new custom props
408
- {
409
- background: [
410
- {
411
- values: ['myGradient1', 'myGradient2'] as const,
412
- valueFormat: (value: string) => `var(--background${value})`,
413
- },
414
- ],
415
- },
416
- // extend values for existing props
417
- {
418
- color: [
419
- {
420
- values: ['dark', 'light'],
421
- valueFormat: (value, getVariableValue) => getVariableValue(value),
422
- },
423
- ],
424
- }
425
- );
426
- ```
427
-
428
- 2. Now you have to add typings to the Box in order to have intellisense for you new props and value.
429
- You need to create a `box.d.ts`
430
-
431
- ```JS
432
- import '@box-kite/react';
433
- import { ExtractBoxStyles, ExtractComponentsAndVariants } from '@box-kite/core/types';
434
- import { extendedProps, extendedPropTypes, components } from './path-to-your-b0x-extends-declaration';
435
-
436
- declare module '@box-kite/core/types' {
437
- namespace Augmented {
438
- interface BoxProps extends ExtractBoxStyles<typeof extendedProps> {}
439
- interface BoxPropTypes extends ExtractBoxStyles<typeof extendedPropTypes> {}
440
- interface ComponentsTypes extends ExtractComponentsAndVariants<typeof components> {}
441
- }
442
- }
443
- ```
165
+ <Box bgColor="bleu-500" />
166
+ // ~~~~~~~ ts(2820): Type '"bleu-500"' is not assignable… Did you mean '"blue-500"'?
444
167
 
445
- ### The escape hatch
168
+ <Box display="flexx" />
169
+ // ~~~~~~~ ts(2820): … Did you mean '"flex"'?
446
170
 
447
- For a one-off property nobody will type twice, `css` takes a style object and compiles it the way
448
- every other prop is compiled — into a shared class, never a `style` attribute — so it nests wherever
449
- a prop does and renders on a server:
171
+ <Box opacity={50} />
172
+ // ~~~~~~~ ts(2322): Type '50' is not assignable to type '0 | 1 | 0.1 | 0.2 | …'
450
173
 
451
- ```JSX
452
- <Box css={{ mixBlendMode: 'multiply', WebkitLineClamp: 2 }} hover={{ css: { isolation: 'isolate' } }} />
453
- ```
174
+ <Button variant="primaryy">Save</Button>
175
+ // ~~~~~~~ ts(2322): a component's variants are typed too
454
176
 
455
- Names are camelCase and typed, values are CSS written as they stand (a colour token resolves to its
456
- variable, a length wants its unit), and it sorts last so it wins over a typed prop naming the same
457
- property. Prefer a prop, then `Box.extend()` for anything used twice.
458
-
459
- ## Theme for components
460
-
461
- In the project root file (main.tsx) use `Theme.setup`
462
-
463
- ```JS
464
- import Box from '@box-kite/react';
465
-
466
- Box.components({
467
- button: {
468
- styles: {
469
- px: 4
470
- },
471
- variants: {
472
- mytheme: {
473
- px: 8
474
- }
475
- }
476
- },
477
- ...
478
- })
177
+ <Box css={{ mixBlendMod: 'multiply' }} />
178
+ // ~~~~~~~~~~~ ts(2561): … Did you mean to write 'mixBlendMode'?
479
179
  ```
480
180
 
481
- All styles will be applied to Button component
181
+ - **Hover a prop, see its CSS.** Every prop's JSDoc carries an example such as `p={4} → padding: 1rem` — generated by running
182
+ the engine, so the editor can never teach a scale the library stopped using.
183
+ - **Your own tokens join the types.** `Box.extend()` adds variables, props and values; one `declare module` makes them
184
+ autocomplete like the built-ins. `Box.components()` variants are typed the same way.
185
+ - **The escape hatch is typed too.** `css={{ … }}` is checked against `csstype` and still compiles to a shared class — never a
186
+ `style` attribute.
482
187
 
483
- ```JS
484
- import Button from '@box-kite/react/components/button';
188
+ ## 📐 The scales
485
189
 
486
- function MyComponent() {
487
- return <Button>Click me</Button>
488
- }
489
- ```
190
+ The one thing worth learning by heart — the divider is per prop:
490
191
 
491
- or is possible to use Button with specific variant
192
+ | Prop | Scale | Example |
193
+ | ---------------------------------------- | ------------------- | ---------------------------------------- |
194
+ | `p`, `m`, `gap`, `width`, `borderRadius` | ÷4 (quarter rem) | `p={4}` → `1rem` (16px) |
195
+ | `fontSize` | ÷16 | `fontSize={14}` → `0.875rem` (14px) |
196
+ | `b` (border width), `lineHeight` | px | `b={1}` → `1px` |
197
+ | `animationDuration`, `transitionDelay`… | ms | `transitionDuration={150}` → `150ms` |
198
+ | colours | tokens + `/opacity` | `bgColor="blue-500/40"` → `color-mix(…)` |
492
199
 
493
- ```JS
494
- import Button from '@box-kite/react/components/button';
200
+ Three conventions follow from "every visual value is a prop": the element comes from the component (`<Flex>`, `<Button>`,
201
+ `<H1>`, `<Path>`), HTML attributes go in `props` (`<Link props={{ href: '/about' }}>`), and there is no `style={{ }}`.
495
202
 
496
- function MyComponent() {
497
- return <Button variant="mytheme">Click me</Button>
498
- }
499
- ```
203
+ ## 🧱 Components
500
204
 
501
- ## Theme variables
205
+ Every component is a `Box` underneath — same props, same theming, same `variant`s — and each is its own entry point, so a
206
+ `Textbox` never pulls the `DataGrid` into your bundle.
502
207
 
503
- In CSS file is possible to override default values for:
208
+ | Area | Components |
209
+ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
210
+ | **Layout & content** | [`Flex`](https://www.box-kite.dev/flex/), [`Grid`](https://www.box-kite.dev/grid/), `H1`–`H6`, `P`, `Link`, `Nav`…, [`List`](https://www.box-kite.dev/list/), [`Svg` + every SVG element](https://www.box-kite.dev/svg/), [`Icon`](https://www.box-kite.dev/icon/), `Skeleton` |
211
+ | **Forms** | [`Button`](https://www.box-kite.dev/button/), [`Textbox`](https://www.box-kite.dev/textbox/), [`Checkbox`](https://www.box-kite.dev/checkbox/), [`Switch`](https://www.box-kite.dev/switch/), [`RadioGroup`](https://www.box-kite.dev/radiobutton/), [`Combobox`](https://www.box-kite.dev/combobox/), [`Slider`](https://www.box-kite.dev/slider/), `Form` |
212
+ | **Dates** | [`DateField`](https://www.box-kite.dev/date-field/), [`Calendar`](https://www.box-kite.dev/calendar/), [`DatePicker`](https://www.box-kite.dev/date-picker/), `TimeZoneSelect` — over a zone-safe [date module](https://www.box-kite.dev/dates/) |
213
+ | **Overlays** | [`Dialog`](https://www.box-kite.dev/dialog/), [`Popover`](https://www.box-kite.dev/popover/), [`Menu`](https://www.box-kite.dev/menu/), [`Tooltip`](https://www.box-kite.dev/tooltip/), [`Toaster`](https://www.box-kite.dev/toaster/) — in the top layer, no portal, no `z-index` |
214
+ | **Disclosure** | [`Tabs`](https://www.box-kite.dev/tabs/), [`Accordion`](https://www.box-kite.dev/accordion/), [`Progress`](https://www.box-kite.dev/progress/) |
215
+ | **Data & dashboards** | [`DataGrid`](https://www.box-kite.dev/datagrid/) (sort, filter, group, edit, paste, virtualized), [`DashboardGrid`](https://www.box-kite.dev/dashboard/), [`Sparkline`, `Gauge`, `ChartContainer`](https://www.box-kite.dev/charts/) |
216
+ | **AI** | [`ToolCallCard`, `ApprovalCard`, `Reasoning`, `StreamingText`](https://www.box-kite.dev/agent/), `markdownComponents`, [`SpecRenderer`](https://www.box-kite.dev/generative-ui/) |
504
217
 
505
- ```CSS
506
- --borderColor: black;
507
- --outlineColor: black;
508
- --lineHeight: 1.2;
509
- --fontSize: 14px;
510
- --transitionTime: 0.25s;
511
- ```
218
+ The behaviour behind them ships on its own as `@box-kite/react/a11y` — focus return, roving focus, dismissal and controllable
219
+ state — for the widgets you build yourself.
512
220
 
513
- ## React Server Components (React 19)
514
-
515
- Box renders inside a Server Component with no `'use client'` — the styles travel with the markup
516
- instead of being injected by an effect. A server component just imports the package as usual:
221
+ ## 🖥️ Server Components
517
222
 
518
223
  ```tsx
519
224
  // app/page.tsx — a Server Component. No 'use client', no provider, no CSS import.
520
225
  import Flex from '@box-kite/react/components/flex';
521
- import { H1, P } from '@box-kite/react/components/semantics';
226
+ import { H1 } from '@box-kite/react/components/semantics';
522
227
 
523
228
  export default function Page() {
524
229
  return (
525
- <Flex d="column" gap={2} p={6} bgColor="slate-50" borderRadius={2}>
230
+ <Flex d="column" gap={2} p={6}>
526
231
  <H1 fontSize={24}>Rendered on the server</H1>
527
- <P color="slate-600" sm={{ fontSize: 16 }}>
528
- Its CSS was hoisted into &lt;head&gt; by React, not inserted by a client runtime.
529
- </P>
530
232
  </Flex>
531
233
  );
532
234
  }
533
235
  ```
534
236
 
535
- The `react-server` export condition resolves to a build of Box that calls no hook, schedules no
536
- effect and never touches the DOM: each generated rule comes back as a `<style href precedence>`
537
- element rendered next to the markup, which React 19 hoists into `<head>` and dedupes by `href`.
538
- That is also what makes it stream-safe — nothing has to wait for a commit that Suspense may split.
539
-
540
- **Client components** (anything with `'use client'`) can use the same emission path, and should in an
541
- RSC app, so their CSS is in the HTML too. One line, in a module the root layout imports:
542
-
543
- ```tsx
544
- 'use client';
545
- import Box from '@box-kite/react';
237
+ The `react-server` export condition resolves to a hook-free build of Box; each rule comes back as a `<style href precedence>`
238
+ element that React 19 hoists into `<head>` and dedupes, so it is stream-safe and the cascade is held by `@layer`, not by element
239
+ order. → [How it works](https://www.box-kite.dev/server-components/) ·
240
+ [measured against CSS modules](https://www.box-kite.dev/blog/styling-server-components/) ·
241
+ [a whole Next.js app](examples/next-app)
546
242
 
547
- Box.configure({ sink: 'element' }); // React 19 only — see below
548
- ```
243
+ ## 📦 Packages
549
244
 
550
- Notes and limits:
551
-
552
- - **The cascade comes from `@layer`, not from element order.** React hoists elements in render
553
- order, so a responsive rule could otherwise land ahead of the base rule it has to override. In
554
- this mode every rule is wrapped in a cascade layer (one per breakpoint × prop) and the base
555
- element declares the layer order once, up front — the order the elements end up in cannot change
556
- the result. The consequence worth knowing: **unlayered CSS of your own always wins** over Box
557
- props here, which matches where the library puts its `<style>` element in the other modes.
558
- - **Declare `Box.extend()` props before the first render.** CSS appends a layer it meets for the
559
- first time after every layer already named, so a prop registered mid-render sorts after the
560
- built-ins.
561
- - **Class names are content-hashed** in this mode instead of counted, so a class resolved on the
562
- server matches the one the client bundle resolves for the same props.
563
- - **Still client-only:** hover-callback children (`{({ isHover }) => …}`) and `Box.Theme`, which
564
- needs state, storage and a media-query listener. Theme _styles_ are unaffected: a `theme` prop
565
- generates rules scoped to the theme's own subtree, so setting the theme class and `data-theme` on
566
- `<html>` in a server component is enough.
567
- - **Most pre-built components render on the server too.** `Flex`, `Grid`, `Button`, `Textbox`,
568
- `Textarea`, `RadioButton`, `Icon`, the SVG elements, `VisuallyHidden` and the semantic tags (`H1`, `P`, `Link`, `Nav` …) are
569
- hook-free wrappers around Box, and their published chunks import the package by name — so the
570
- `react-server` condition reaches them and they resolve the same hook-free Box. Import them
571
- straight into a Server Component.
572
- - **The stateful ones become client boundaries.** `Dropdown`, `Tooltip`, `Overlay`, `DataGrid`,
573
- `Checkbox`, `Switch`, `RadioGroup`, `Select` and `Form` hold state or measure the DOM, so their chunks ship a
574
- `'use client'` banner.
575
- A Server Component may still import one — the bundler opens the boundary for you — but it is
576
- hydrated like any client component, and its CSS is in the server-rendered HTML only if a client
577
- module of yours has already called `Box.configure({ sink: 'element' })`.
578
- - **React 19 only.** On React 18 the elements cannot be hoisted and render inline; keep the default
579
- sink there (a documented App Router fallback for React 18 is still to come).
580
- - **Cost:** one base element per page (the reset, `:root`, and the layer order — ~1.8 KB gzipped)
581
- plus one `<style>` element per distinct rule, deduped across every Box that uses it.
582
-
583
- A whole Next.js App Router app built this way — streamed Suspense boundary, client island, theme
584
- toggle, and a page of pre-built components rendered on the server — is in
585
- [`examples/next-app`](examples/next-app): `npm run build:next-app` and `npm run smoke:next-app`,
586
- which starts the production server and asserts on the HTML it serves.
587
-
588
- ## Behaviour primitives for your own components
589
-
590
- Every accessible widget needs the same mechanics, and none of them are visible in the markup:
591
- return focus to whatever opened a layer, move through a list with the arrow keys, close on Escape
592
- or a press outside, hold a value the consumer may or may not own, generate ids that wire one
593
- element to another. They are what this library's components are built from, and they ship on their
594
- own for the patterns it does not cover:
245
+ | Package | What it is |
246
+ | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
247
+ | [`@box-kite/react`](https://www.npmjs.com/package/@box-kite/react) | `Box`, every component and hook; depends on `@box-kite/core` and nothing else |
248
+ | [`@box-kite/core`](https://www.npmjs.com/package/@box-kite/core) | the styling engine with no framework and no dependencies — `createStyleEngine().classNames(props)` ([example](examples/vanilla)) |
249
+ | [`@box-kite/mcp`](https://www.npmjs.com/package/@box-kite/mcp) | the MCP server: docs search, props, components, rules and `check_styles` |
250
+ | [`@box-kite/create`](https://www.npmjs.com/package/@box-kite/create) | `npm create @box-kite` — a Vite + React app with a design and the agent setup |
595
251
 
596
- ```tsx
597
- import { useControllableState, useDismiss, useFocusReturn, useIdentifier, useRovingFocus } from '@box-kite/react/a11y';
598
- import VisuallyHidden from '@box-kite/react/components/visuallyHidden';
252
+ ## 📚 Learn more
599
253
 
600
- function Menu({ open, onOpenChange, items }) {
601
- const trigger = useRef(null);
602
- const popup = useRef(null);
254
+ - **[Documentation](https://www.box-kite.dev)** — every prop and component, with live demos
255
+ - **[Start with AI](https://www.box-kite.dev/start-with-ai/)** — build an app in three prompts with Claude Code, Cursor, Codex or Copilot
256
+ - **[Built for AI](https://www.box-kite.dev/ai-context/)** — what ships for agents, and why
257
+ - **[Theming](https://www.box-kite.dev/theme-setup/)**, **[Extending](https://www.box-kite.dev/box-functions/)**,
258
+ **[Escape hatch](https://www.box-kite.dev/escape-hatch/)**
259
+ - **[`BOX_KITE_AI_CONTEXT.md`](src/BOX_KITE_AI_CONTEXT.md)** — the whole surface on one page
603
260
 
604
- const roving = useRovingFocus({ count: items.length, textOf: (index) => items[index].label });
261
+ ## 🤝 Contributing
605
262
 
606
- useDismiss({ enabled: open, inside: [trigger, popup], onDismiss: (reason, event) => onOpenChange(false, { reason, event }) });
607
- useFocusReturn({ enabled: open, returnTo: trigger });
608
- }
609
- ```
263
+ Issues and pull requests are welcome — start with [CONTRIBUTING.md](CONTRIBUTING.md), which covers the architecture and the
264
+ framework-free core boundary. Questions go to [SUPPORT.md](SUPPORT.md), vulnerabilities to [SECURITY.md](SECURITY.md).
610
265
 
611
- 2.2 KB gzipped for all five hooks, and they pull in no styling engine — you can use them next to
612
- any CSS you like. Changes are **event-sourced**: `onChange(value, { reason, event })` tells you
613
- _why_ something closed (`'escape'`, `'outside-pointer'`, a reason of your own), which is what makes
614
- a controlled component controllable in practice. Roles and ARIA are deliberately left to you: a
615
- listbox and a menu navigate identically and are named completely differently.
616
-
617
- Full reference: [docs/a11y-primitives.md](docs/a11y-primitives.md).
618
-
619
- ## Using the core without React
620
-
621
- The engine that turns props into CSS has no framework in it, and it is published on its own:
622
-
623
- ```js
624
- import { createStyleEngine } from '@box-kite/core';
625
-
626
- const engine = createStyleEngine();
627
-
628
- document.querySelector('#card').className = engine.classNames({
629
- p: 4,
630
- bgColor: 'blue-500',
631
- borderRadius: 2,
632
- hover: { bgColor: 'blue-600' },
633
- md: { p: 8 },
634
- });
635
- ```
266
+ If Box Kite saves you time, a ⭐ on [GitHub](https://github.com/box-kite/box-kite) helps other people find it.
636
267
 
637
- That is the whole runtime. The props are the ones `<Box>` takes — pseudo-classes, breakpoints,
638
- themes, `component`/`variant` — and the CSS behind them is written to a `<style>` element the
639
- engine creates, on its own microtask. Nothing has to be flushed, mounted or provided.
640
-
641
- ```js
642
- const engine = createStyleEngine();
643
-
644
- // Custom variables and props, the vanilla form of Box.extend()
645
- engine.extend(
646
- { brand: '#6d28d9' },
647
- {},
648
- { bgColor: [{ styleName: 'background-color', values: ['brand'], valueFormat: (v, get) => get(v) }] },
649
- );
650
-
651
- // Component defaults with variants, the vanilla form of Box.components()
652
- engine.components({ panel: { styles: { p: 6, borderRadius: 3 }, variants: { accent: { b: 2, borderColor: 'brand' } } } });
653
-
654
- engine.classNames({ component: 'panel', variant: 'accent' });
655
- engine.flushSync(); // only when computed styles are read in the same tick
656
- engine.getStyles(); // the stylesheet as text, for static output
657
- ```
658
-
659
- Theming is the same state machine `<Box.Theme>` runs, as a plain object:
660
-
661
- ```js
662
- import { createThemeController } from '@box-kite/core';
663
-
664
- // Reads prefers-color-scheme, restores a stored choice, writes the theme class and data-theme onto
665
- // <html>, and follows the system preference until something overrides it. A theme rule is scoped to
666
- // the subtree that theme owns (`@scope (.dark) to ([data-theme])`), so one class restyles everything
667
- // inside it and a nested theme takes over from there.
668
- const theme = createThemeController({ storageKey: 'theme' });
669
-
670
- theme.subscribe((name) => console.log('theme is now', name));
671
- theme.set('dark'); // theme.set(null) hands control back to the system
672
- ```
673
-
674
- Notes:
675
-
676
- - **The engine is explicit here.** The React entries share one lazily-created default instance so
677
- `Box` and `Box.extend()` agree with no configuration; a vanilla app has no such ambient thing to
678
- agree with, and separate instances are what keeps a widget independent of its host page.
679
- - **No React reaches this entry**, in the sources or in the bundle — both are checked in CI. It is
680
- 14 KB gzipped, all engine.
681
- - `sink: 'string'` collects CSS in memory with no DOM (`getStyles()` reads it back), which is how
682
- server rendering works; `sink: 'element'` is the React 19 mode above and has no meaning here, so
683
- `classNames()` refuses to run in it.
684
-
685
- A complete page — props, pseudo-classes, breakpoints, themes, `extend`, `components`, no framework
686
- — is in [`examples/vanilla`](examples/vanilla): `npm run dev:vanilla`.
687
-
688
- ## Architecture
689
-
690
- The styling engine is framework-free. Everything that generates CSS — the 235 prop definitions,
691
- the value formatters, class-name generation, rule ordering, the style sinks (CSSOM, `textContent`,
692
- string for SSR, style elements for React 19), the flush scheduler, CSS variables and the theme
693
- runtime — lives in `src/core/` and imports no React at all. CI fails the build if it ever does
694
- (`npm run check:boundaries`), and it ships on its own as
695
- [`@box-kite/core`](#using-the-core-without-react).
696
-
697
- React is a thin adapter on top of it:
698
-
699
- | | Files | Lines | Share |
700
- | ---------------------------------------------------------- | ----- | ----- | -------- |
701
- | Core engine (`src/core/`, `core.ts`) | 23 | 5,702 | 90.9% |
702
- | React binding (`src/react/`, `box.ts`, `rsc.ts`, `ssg.ts`) | 14 | 573 | **9.1%** |
703
-
704
- The binding is the whole React-specific surface: resolve class names during render, flush the
705
- pending rules from `useInsertionEffect`, render the style elements of the Server-Component path,
706
- and hold the theme state. React feature code the components share sits alongside it and is counted
707
- separately — three helper hooks (`useVisibility`, `usePortalContainer`, `useVirtualization`), the
708
- modules behind [`@box-kite/react/a11y`](#behaviour-primitives-for-your-own-components), the
709
- markup the form controls share, and the ARIA the SVG and chart components share, 911 lines together. A Vue adapter would need its own arrow-key navigation for the same reason it
710
- would need its own components, which says nothing about how much of the styling engine is
711
- React-specific.
712
-
713
- That ratio is not theoretical: the same engine is driven straight from the DOM in
714
- [`examples/vanilla`](examples/vanilla) with no framework loaded, and from a server with no
715
- `document` in `ssg.ts`. Numbers are printed by `npm run check:boundaries` and refreshed with the
716
- code.
717
-
718
- See [CONTRIBUTING.md](CONTRIBUTING.md#the-core-boundary) for the boundary rules and where new code
719
- belongs.
720
-
721
- ## AI editors and agents
722
-
723
- The package ships its own instructions, because an agent has priors about a library this new and they
724
- are wrong. `AGENTS.md` at the package root is the file agents look for — the rules, the dividers, one
725
- worked example — and `docs/` sits beside it: every prop with the CSS it writes (`docs/props.md`),
726
- every component with its import and whether it renders on a server (`docs/components.md`), and the
727
- behaviour hooks (`docs/a11y.md`). All of it is generated during the build from the prop registry, the
728
- rules file and the built chunks' own exports, so none of it can drift from the library it describes.
729
-
730
- ```shell
731
- npm create @box-kite@latest -- --agents-only
732
- ```
733
-
734
- That adds a root `AGENTS.md` (merged into yours, if you have one) with the four facts a model gets wrong
735
- and a pointer to the package's own, so an upgrade brings the rules with it; a `CLAUDE.md` importing it;
736
- and the MCP server below, in `.mcp.json` and in the config of each editor whose folder is there. Run again,
737
- it updates rather than repeats. `npm create @box-kite` writes all of it into a new app already
738
- (`--no-agents` leaves it out).
739
-
740
- Codex, Cursor, Copilot, VS Code, Windsurf, Cline and Zed read a root `AGENTS.md` natively; Claude
741
- Code reads `CLAUDE.md`, which is why the one line `@AGENTS.md` is there. The long-form
742
- [BOX_KITE_AI_CONTEXT.md](src/BOX_KITE_AI_CONTEXT.md) ships in the tarball too.
743
-
744
- The same rules are also a skill, which roughly forty-five coding agents install with one command:
745
-
746
- ```shell
747
- npx skills add box-kite/box-kite # Claude Code, Cursor, Codex, Copilot, Gemini CLI, Zed…
748
- ```
749
-
750
- In Claude Code this repository is also a plugin marketplace — `/plugin marketplace add box-kite/box-kite`
751
- then `/plugin install box-kite@box-kite` — and Cursor takes the rules as a rule file of its own:
752
-
753
- ```shell
754
- mkdir -p .cursor/rules && cp node_modules/@box-kite/react/.cursor/rules/box-kite.mdc .cursor/rules/
755
- ```
756
-
757
- Both are generated from the same rules file as `AGENTS.md`, and both are served by the docs site
758
- ([skill.md](https://www.box-kite.dev/skill.md), [box-kite.mdc](https://www.box-kite.dev/box-kite.mdc))
759
- for an agent that can fetch a URL but not run a command.
760
-
761
- ### The MCP server
762
-
763
- A file is read once, at the start; an MCP server is asked mid-task, which is when the question comes
764
- up. `@box-kite/mcp` is six tools at capability level — `search_docs`, `get_props`, `get_component`,
765
- `check_styles`, `get_rules`, `get_blocks` — with no key, no network and no state, because the
766
- references and the engine are built into it.
767
-
768
- ```shell
769
- claude mcp add box-kite -- npx -y @box-kite/mcp # or the stdio config your editor takes
770
- ```
771
-
772
- `check_styles` is the one a file cannot replace. Every prop here accepts a closed set of values, and
773
- a value it does not accept writes **no rule and no class name** — silently, by design, so that a typo
774
- never emits a broken declaration. It is the right behaviour and it is invisible, so the tool hands
775
- your props to the real engine and reports what each one wrote:
776
-
777
- ```shell
778
- ✅ p → .p-4{padding:1rem}
779
- ❌ bgColor does not accept "blue-550" — no rule and no class name were written.
780
- ✅ fontSize → .fontSize-14{font-size:0.875rem}
781
- ⚠️ href an HTML attribute, not a style prop. It goes in props={{ "href": … }}.
782
- ```
268
+ ## License
783
269
 
784
- For the same reason `get_props` measures a numeric prop's scale rather than describing its divider:
785
- it runs 1, 2, 4 and 8 through the engine and shows what came out. See [mcp/README.md](mcp/README.md).
270
+ [MIT](LICENSE) © Maxim Procopenco