@becket-ui/mcp 0.0.0-stage → 0.5.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.
@@ -0,0 +1,285 @@
1
+ # Writing app code with Becket UI
2
+
3
+ How to write React screens with `@becket-ui/react`. It's written for people and for agents: Claude
4
+ Design while it builds a design, Claude Code when it turns a design into app code, and any coding
5
+ agent connected to the Becket MCP. If you follow this guide, the code reads top to bottom, uses
6
+ Becket for everything Becket can do, and keeps working in dark and light themes.
7
+
8
+ Each rule says **Must** (required) or **Prefer / Avoid** (the default; deviate with a reason in a
9
+ comment).
10
+
11
+ ## 1. Setup, once per app
12
+
13
+ - Install `@becket-ui/react` and `@becket-ui/tokens`. Import `@becket-ui/tokens/index.css` **once**,
14
+ at the app entry.
15
+ - The theme lives on `<html data-theme="dark|light">` (dark is the default). Set it at the app root,
16
+ never inside a screen. There is **no provider** and no theme wrapper.
17
+ - `index.css` already paints the page background, text color and font from the theme. Don't repeat
18
+ that on a wrapper `div`.
19
+
20
+ ## 2. Must use a Becket component when one exists
21
+
22
+ Raw elements with inline styles are the most common mistake. Use this table:
23
+
24
+ | Instead of | Use |
25
+ | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
26
+ | page wrapper `div` (max width, centering, gutters) | `Container as="main" size="md"` |
27
+ | plain block `div` with padding, background or radius | `Box padding="md" background="subtle" radius="md"` |
28
+ | `div` with `display: flex; flex-direction: column` | `VStack` / `Stack` |
29
+ | `div` with `display: flex` (row) | `HStack`, or `Flex` for wrap, grow and basis |
30
+ | `div` with `display: grid` | `SimpleGrid columns={{ base: 1, md: 2 }}` |
31
+ | `h1`–`h6` with font styles | `Heading as="h1" size="2xl"` |
32
+ | `p` / `span` with font size or color | `Text fontSize="sm" color="muted"` |
33
+ | bold `span` | `Text as="strong"` |
34
+ | `hr`, or a 1px `div` | `Separator` (`orientation="vertical"` inside a row) |
35
+ | `button` | `Button visual="primary\|secondary\|neutral\|outline"` |
36
+ | `input` + `label` | `Field` + `FieldLabel` + `FieldControl`, or `TextField label` |
37
+ | `select` / `textarea` | `Select` / `Textarea` (or `FieldSelect` / `FieldTextarea` inside `Field`) |
38
+ | checkbox / radio / toggle `input` | `Checkbox`, `RadioGroup` + `Radio`, `Switch` |
39
+ | `table`, `tr`, `td` | `Table`, `Thead`, `Tbody`, `Tr`, `Th`, `Td` |
40
+ | panel `div` with border and padding | `Card` + `CardHeader` / `CardBody` / `CardFooter` |
41
+ | pill `span` | `Tag` (label) or `Badge` (count or status) |
42
+ | inline `svg` icon | `Icon` around your SVG, or a built-in glyph (`SearchIcon`, `ChevronDownIcon`, …); add `label` only when it carries meaning |
43
+ | `a` | `Link` |
44
+ | `a` styled as a button (call to action) | `Button as="a" href="…"` (anchor props are typed) |
45
+ | HTML from Markdown or MDX (blog posts, docs) | `<Prose as="article">`; wrap embedded components in `data-not-prose` |
46
+ | `ul` / `ol` with `li` | `List` (`as="ol"` for steps, `marker="none"` for nav) + `ListItem` |
47
+ | inline `code`, `kbd`, `mark` | `Code`, `Kbd`, `Mark` |
48
+ | `blockquote` (+ attribution) | `Blockquote cite` + `BlockquoteCaption` |
49
+ | `img` | `Image alt` (required; lazy by default), inside `Figure caption` when captioned |
50
+ | profile photo or initials circle | `Avatar name src` |
51
+ | centered box | `Center` (`inline` for icons in text) |
52
+ | 12-column page layout | `Grid columns={{ base: 1, md: 12 }}` + `GridItem colSpan` |
53
+ | fixed-ratio media (video, map, cover image) | `AspectRatio ratio="8:5"` (`"16:9"` for video) |
54
+ | screen-reader-only text, skip link | `VisuallyHidden`, `SkipLink href="#main"` |
55
+ | custom modal, side panel, dropdown, tabs or tooltip | `Dialog`, `Drawer`, `Menu`, `Tabs`, `Tooltip` |
56
+
57
+ Raw elements are fine for semantics Becket doesn't cover (`form`, `main`, `nav`, `section`). Render
58
+ them through a layout component's `as` prop when they also lay things out:
59
+ `<VStack as="form" gap="md">`.
60
+
61
+ **Known gaps** (until these ship, an inline `style` with tokens is allowed, with a `TODO` naming the
62
+ ticket):
63
+
64
+ - Font weight on `Text`: no `weight` prop yet (MAV-106). Use `Text as="strong"` for bold.
65
+ - Status colors on `Badge` and `Tag`: no `success` / `warning` / `danger` visuals yet (MAV-107).
66
+ Don't use a brand visual (`primary`, `secondary`) to mean a status.
67
+
68
+ ## 3. Prefer props, then tokens. Never classes, never literals
69
+
70
+ Style with component props, written inline where the component is used. That's Becket's design
71
+ language: `gap`, `align`, `justify`, `visual`, `size`, `invalid`, `columns`.
72
+
73
+ - **Spacing:** semantic `gap="xs|sm|md|lg|xl"` (or the Fibonacci steps `1 2 3 5 8 13 21 34`). Never
74
+ pixel numbers, and never Panda's in-between keys (`4`, `6`, `10`, `12`): they exist but are off
75
+ the scale.
76
+ - **Sizes and ratios:** use the component's `size` prop rather than a width, since its steps are
77
+ already on the scale. For fixed media, use the Fibonacci ratios (`AspectRatio ratio="3:2|8:5|13:8"`,
78
+ or a portrait flip such as `"5:8"`), and `"16:9"` only for video. Don't bring in sizes or ratios
79
+ from another system (`4:3`, 40px avatars).
80
+ - **When you need your own CSS** (a known gap above, or a one-off like `minWidth: 0`), use token
81
+ variables: `var(--beckui--colors-muted)`, `var(--beckui--spacing-lg)`, `var(--beckui--sizes-4xl)`,
82
+ `var(--beckui--radii-md)`; inside running text, `var(--beckui--spacing-text-2)` (em-based). Never hex,
83
+ `rgb()`, or raw `px`/`rem`/`em` values for spacing and color, since they ignore the app's theme overrides.
84
+ - **Must not** write or copy `.beckui--*` class names. They're generated, not API.
85
+ - **Avoid** named styled wrappers, CSS files per screen, or style objects defined away from the
86
+ element. A reader shouldn't have to look anything up to see how an element looks.
87
+ - **Colors carry meaning:** `primary` (yellow), `secondary` (sage) and `tertiary` (amber) are brand
88
+ identity; `danger`, `warning` and `success` are status only.
89
+
90
+ ## 4. Avoid hasty abstraction: inline first, extract on the third copy
91
+
92
+ Write markup inline. Extract a local component only when the same markup appears **three times** in
93
+ the same feature. Then:
94
+
95
+ - Build it only from Becket components and tokens; a helper made of raw `div`s and `span`s is the
96
+ same mistake, just moved.
97
+ - Keep it in the same file, or next to it, until a second feature needs it.
98
+ - Name it for what it shows (`MemberName`), not how (`TitleCell`).
99
+
100
+ ## 5. Prefer inversion of control: compose, don't configure
101
+
102
+ Pass content in instead of adding flags: `children`, element props (`actions={<Button>…</Button>}`),
103
+ and Becket's compound parts (`CardHeader` / `CardBody` / `CardFooter`, `DialogHeader` /
104
+ `DialogFooter`, `TabList` / `Tab` / `TabPanel`). A screen component with `showX`, `isY` and
105
+ `variantZ` booleans is a sign to invert.
106
+
107
+ ## 6. Prefer native HTML and zero JavaScript
108
+
109
+ Becket is native-first. Prefer the components and props that work without client JavaScript.
110
+ Interactive ones (`Tabs`, `Menu`, `Tooltip`, controlled `Dialog` / `Drawer`) ship JS. Use them when
111
+ the interaction needs them, not for static content. Put `'use client'` only on the leaf component
112
+ that holds state or handlers, never on a whole page or barrel file.
113
+
114
+ ## 7. State and effects
115
+
116
+ - **Derive, don't sync:** compute values from props and state during render
117
+ (`const activeCount = members.filter((m) => m.isActive).length`). Don't mirror them into state
118
+ with an effect.
119
+ - **Effects** are only for syncing with something outside React (subscriptions, timers, storage).
120
+ Theme and analytics belong at the app root.
121
+ - **Must not mutate** state, props or shared constants. Create new values with spread, `map`,
122
+ `filter` or `toSorted()`.
123
+ - Keep each piece of state in one place, as low in the tree as it can live.
124
+
125
+ ## 8. Accessibility (WCAG 2.2 AA)
126
+
127
+ - Every control has a name: a visible label (`TextField label`, `FieldLabel`, `Switch label`) or
128
+ `aria-label` when the label is visual only, such as a `Switch` in a table row:
129
+ ``aria-label={`Access for ${member.name}`}``.
130
+ - One `h1` per page. Headings follow the document outline (`Heading as="h2"` for sections).
131
+ - Use `Button` for actions and `Link` for navigation, never a clickable `div`.
132
+ - Don't rely on color alone for status: keep the text ("Active", "Invited").
133
+
134
+ ## 9. TypeScript and naming
135
+
136
+ - Type props explicitly (`type MemberTableProps = { … }`). Let TypeScript infer locals. Must not use
137
+ `any`.
138
+ - Use string unions and `as const` data instead of `enum`:
139
+ `const ROLES = ['owner', 'admin', 'member'] as const`.
140
+ - Use stable keys from data (`key={member.id}`), never the array index for lists that change.
141
+ - Callback props are `onX`; handlers inside are `handleX`. Booleans start with `is`, `has`, `should`
142
+ or `can`.
143
+ - Functions say what they do (`selectActiveMembers`, `formatSeatCount`), not `getX`. Keep
144
+ initialisms in one case (`userID`, `inviteURL`).
145
+ - Sort imports: third-party (React, then `@becket-ui/react`), then absolute app modules, then
146
+ relative.
147
+ - Comment **why**, not what. A `TODO` names its ticket: `// TODO (MAV-106): use Text weight`.
148
+
149
+ ## 10. Example: a settings screen
150
+
151
+ ### Avoid
152
+
153
+ From a real Claude Design handoff. It uses Becket's Tabs, Table and Switch correctly, but builds
154
+ everything else from raw markup:
155
+
156
+ ```tsx
157
+ <div style={{ minHeight: '100vh', background: 'var(--beckui--colors-background)', padding: '48px 24px' }}>
158
+ <div style={{ maxWidth: 880, display: 'flex', flexDirection: 'column', gap: 28 }}>
159
+ <h1 style={{ margin: 0, fontSize: 'var(--beckui--font-sizes-2xl)', fontWeight: 600 }}>Workspace settings</h1>
160
+ <p style={{ margin: 0, color: 'var(--beckui--colors-muted)' }}>Manage how the workspace behaves.</p>
161
+ {PREFS.map((pref, i) => (
162
+ <div key={pref.k}>
163
+ <div style={{ display: 'flex', justifyContent: 'space-between', gap: 24, padding: '16px 0' }}>
164
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
165
+ <span style={{ fontWeight: 600 }}>{pref.title}</span>
166
+ <span style={{ color: 'var(--beckui--colors-muted)' }}>{pref.desc}</span>
167
+ </div>
168
+ <Switch checked={prefs[pref.k]} onCheckedChange={…} aria-label={pref.title} />
169
+ </div>
170
+ {i < PREFS.length - 1 && <div style={{ height: 1, background: 'var(--beckui--colors-border)' }} />}
171
+ </div>
172
+ ))}
173
+ </div>
174
+ </div>
175
+ ```
176
+
177
+ What's wrong:
178
+
179
+ - Flex `div`s instead of `VStack` / `HStack`.
180
+ - `h1` / `p` / `span` instead of `Heading` / `Text`.
181
+ - A 1px `div` instead of `Separator`.
182
+ - Pixel gaps.
183
+ - A background the CSS already paints.
184
+ - A cryptic data key (`k`).
185
+
186
+ ### Prefer
187
+
188
+ ```tsx
189
+ import { useState } from "react";
190
+ import {
191
+ Card,
192
+ CardBody,
193
+ Container,
194
+ Heading,
195
+ HStack,
196
+ Separator,
197
+ Switch,
198
+ Text,
199
+ VStack,
200
+ } from "@becket-ui/react";
201
+
202
+ const PREFERENCES = [
203
+ {
204
+ id: "public",
205
+ title: "Public workspace",
206
+ description: "Anyone with the link can request to join.",
207
+ },
208
+ {
209
+ id: "guests",
210
+ title: "Allow guests",
211
+ description: "Invite people outside your domain with limited access.",
212
+ },
213
+ {
214
+ id: "sso",
215
+ title: "Require SSO",
216
+ description: "Members sign in through your identity provider.",
217
+ },
218
+ ] as const;
219
+
220
+ type PreferenceID = (typeof PREFERENCES)[number]["id"];
221
+
222
+ export function WorkspaceSettings() {
223
+ const [enabled, setEnabled] = useState<Record<PreferenceID, boolean>>({
224
+ public: false,
225
+ guests: true,
226
+ sso: true,
227
+ });
228
+
229
+ return (
230
+ <Container as="main" size="md">
231
+ <VStack gap="xl">
232
+ <VStack gap="xs">
233
+ <Heading as="h1" size="2xl">
234
+ Workspace settings
235
+ </Heading>
236
+ <Text fontSize="sm" color="muted">
237
+ Manage how the workspace behaves for everyone in it.
238
+ </Text>
239
+ </VStack>
240
+
241
+ <Card visual="outline" fullWidth>
242
+ <CardBody>
243
+ <VStack gap="md">
244
+ {PREFERENCES.map((preference, index) => (
245
+ <VStack key={preference.id} gap="md">
246
+ {index > 0 && <Separator />}
247
+ <HStack justify="between" align="center" gap="lg">
248
+ <VStack gap="xs">
249
+ <Text as="strong" fontSize="sm">
250
+ {preference.title}
251
+ </Text>
252
+ <Text fontSize="sm" color="muted">
253
+ {preference.description}
254
+ </Text>
255
+ </VStack>
256
+ <Switch
257
+ aria-label={preference.title}
258
+ checked={enabled[preference.id]}
259
+ onCheckedChange={(isOn) =>
260
+ setEnabled((current) => ({ ...current, [preference.id]: isOn }))
261
+ }
262
+ />
263
+ </HStack>
264
+ </VStack>
265
+ ))}
266
+ </VStack>
267
+ </CardBody>
268
+ </Card>
269
+ </VStack>
270
+ </Container>
271
+ );
272
+ }
273
+ ```
274
+
275
+ No raw layout or text elements are left: `Container` renders the `main` landmark, and every visual
276
+ decision is a prop with a token value.
277
+
278
+ ## 11. Before you finish
279
+
280
+ - [ ] No flex or grid `div`s, no `h1`–`h6` / `p` / `span` with font styles, no 1px divider `div`s.
281
+ - [ ] No hex or `rgb()` colors, no pixel spacing, no `.beckui--*` classes.
282
+ - [ ] Every inline `style` uses tokens and has a `TODO (MAV-…)` naming the gap it covers.
283
+ - [ ] Local helpers exist only for markup used three or more times, and are built from Becket.
284
+ - [ ] Every control has an accessible name; status isn't shown by color alone.
285
+ - [ ] Theme is set at the app root; `index.css` is imported once.