@classic-homes/theme-react 0.6.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -0
- package/dist/index.d.mts +729 -33
- package/dist/index.d.ts +729 -33
- package/dist/index.js +3906 -1007
- package/dist/index.mjs +3939 -1086
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -28,3 +28,321 @@ import '@classic-homes/theme-react/styles.css';
|
|
|
28
28
|
|
|
29
29
|
Without this import the `DataPanel` resize handles (edges + corners) will not be
|
|
30
30
|
positioned or visible, so detached/pinned resizing won't work.
|
|
31
|
+
|
|
32
|
+
The class lists come from `@classic-homes/theme-tokens/recipes`, the same recipes
|
|
33
|
+
theme-svelte reads, so both frameworks render the same classes. They are bundled
|
|
34
|
+
into this package's `dist/`, so the usual Tailwind `content` glob for
|
|
35
|
+
`@classic-homes/theme-react/dist` keeps picking them up. No component uses a
|
|
36
|
+
`theme()` call in its classes, so they also work under Tailwind v4.
|
|
37
|
+
|
|
38
|
+
## Components
|
|
39
|
+
|
|
40
|
+
All components forward refs and accept `className` (merged with `cn()`, so your
|
|
41
|
+
classes win over the defaults).
|
|
42
|
+
|
|
43
|
+
Props follow the theme-svelte components. Where Svelte binds a value (`bind:value`), React
|
|
44
|
+
takes `value` + `onValueChange` (controlled) or `defaultValue` (uncontrolled).
|
|
45
|
+
|
|
46
|
+
| Group | Components |
|
|
47
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| Actions | `Button`, `DropdownMenu` |
|
|
49
|
+
| Forms | `Input`, `PasswordInput`, `Textarea`, `NumberInput`, `Select`, `Checkbox`, `RadioGroup`, `Switch`, `Slider`, `SegmentedControl`, `Label` |
|
|
50
|
+
| Layout & display | `Card`, `Section`, `Separator`, `Badge`, `Avatar`, `Kbd`, `Icon`, `EmptyState`, `PageHeader`, Table primitives |
|
|
51
|
+
| Navigation | `Tabs` + `TabPanel`, `SkipLink` |
|
|
52
|
+
| Overlays | `Dialog`, `Sheet`, `Popover`, `Tooltip`, `Collapsible`, `DataPanel`, `Studio` |
|
|
53
|
+
| Feedback | `Alert`, `Spinner`, `Skeleton`, `ProgressBar`, `LoadingOverlay`, `LoadingPage`, `LoadingSection`, `LiveRegion` |
|
|
54
|
+
|
|
55
|
+
### Button
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
<Button variant="secondary" size="sm">Cancel</Button>
|
|
59
|
+
<Button loading loadingText="Saving…">Save</Button>
|
|
60
|
+
<Button href="/docs">Read the docs</Button>
|
|
61
|
+
<Button asChild><Link to="/x">Router link</Link></Button>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- `variant`: `default` | `secondary` | `destructive` | `outline` | `ghost` | `link`
|
|
65
|
+
- `size`: `default` | `sm` | `md` | `lg` | `icon` (`icon` requires `aria-label`)
|
|
66
|
+
- `loading`: shows a spinner, disables the button, sets `aria-busy` and announces
|
|
67
|
+
"Loading"; `loadingText` replaces the children meanwhile
|
|
68
|
+
- `href`: renders an `<a>`; while `disabled` or `loading` it drops the href,
|
|
69
|
+
leaves the tab order and sets `aria-disabled`
|
|
70
|
+
- `asChild`: merge the button props onto the single child element (no spinner)
|
|
71
|
+
- Like a native `<button>`, it has no default `type`, so it submits inside a form
|
|
72
|
+
|
|
73
|
+
### Card
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<Card variant="highlight" interactive>
|
|
77
|
+
<CardHeader variant="bordered">
|
|
78
|
+
<CardTitle>Lot 42</CardTitle>
|
|
79
|
+
<CardDescription>Move-in ready</CardDescription>
|
|
80
|
+
</CardHeader>
|
|
81
|
+
<CardContent>…</CardContent>
|
|
82
|
+
<CardFooter>…</CardFooter>
|
|
83
|
+
</Card>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- Card: flat, `rounded-md`. `variant`: `default` | `featured` (2px border) |
|
|
87
|
+
`highlight` (teal border) | `warning` (red border); `borderColor`: `default` |
|
|
88
|
+
`primary` | `muted` (ignored by highlight/warning); `interactive` adds a hover
|
|
89
|
+
shadow; `as`: `div` | `article` | `section` | `aside`
|
|
90
|
+
- CardHeader `variant`: `default` | `compact` | `bordered` | `shaded`
|
|
91
|
+
- CardTitle `as`: `h1`–`h6` (default `h3`)
|
|
92
|
+
|
|
93
|
+
### Dialog
|
|
94
|
+
|
|
95
|
+
`SimpleDialog` takes the same props as theme-svelte's `Dialog`:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<SimpleDialog
|
|
99
|
+
trigger={<Button>Rename</Button>}
|
|
100
|
+
title="Rename plan"
|
|
101
|
+
description="Shown on the hotsheet"
|
|
102
|
+
footer={
|
|
103
|
+
<>
|
|
104
|
+
<Button variant="outline" onClick={close}>
|
|
105
|
+
Cancel
|
|
106
|
+
</Button>
|
|
107
|
+
<Button onClick={save}>Save</Button>
|
|
108
|
+
</>
|
|
109
|
+
}
|
|
110
|
+
>
|
|
111
|
+
<Input aria-label="Name" />
|
|
112
|
+
</SimpleDialog>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Props: `open` / `defaultOpen` / `onOpenChange`, `title`, `description`, `header`
|
|
116
|
+
(replaces title and description), `headerActions`, `footer`, `trigger`, `size`
|
|
117
|
+
(`sm` | `md` | `lg` | `xl` | `2xl` | `full`, default `md`), `showClose` (default
|
|
118
|
+
`true`), `dirty`, `onOpenAutoFocus`, `onCloseAutoFocus`, `className`.
|
|
119
|
+
|
|
120
|
+
For a custom layout, compose the Radix parts. `Dialog` (also exported as
|
|
121
|
+
`DialogRoot`) is the Radix root:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
125
|
+
<DialogTrigger asChild>
|
|
126
|
+
<Button>Open</Button>
|
|
127
|
+
</DialogTrigger>
|
|
128
|
+
<DialogContent size="lg">
|
|
129
|
+
<DialogHeader
|
|
130
|
+
actions={
|
|
131
|
+
<Button size="sm" variant="ghost">
|
|
132
|
+
Help
|
|
133
|
+
</Button>
|
|
134
|
+
}
|
|
135
|
+
>
|
|
136
|
+
<DialogTitle>Title</DialogTitle>
|
|
137
|
+
<DialogDescription>Description</DialogDescription>
|
|
138
|
+
</DialogHeader>
|
|
139
|
+
<DialogBody>Scrolls when the viewport clamps the dialog</DialogBody>
|
|
140
|
+
<DialogFooter>
|
|
141
|
+
<DialogClose asChild>
|
|
142
|
+
<Button variant="outline">Cancel</Button>
|
|
143
|
+
</DialogClose>
|
|
144
|
+
</DialogFooter>
|
|
145
|
+
</DialogContent>
|
|
146
|
+
</Dialog>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- DialogContent: `size`, `showClose` (default `true`; the close button sits in
|
|
150
|
+
DialogHeader's actions, or in the corner without a DialogHeader), `dirty`, and
|
|
151
|
+
the Radix content props. A `className` with an unprefixed `max-w-*` replaces
|
|
152
|
+
the size cap.
|
|
153
|
+
- DialogHeader (`border-b bg-muted/30`) and DialogFooter (`border-t bg-muted/30`)
|
|
154
|
+
stay pinned; DialogBody scrolls. Content put straight into DialogContent gets
|
|
155
|
+
no padding, so wrap it in DialogBody.
|
|
156
|
+
|
|
157
|
+
**Unsaved changes (`dirty`)**, on Dialog and Sheet: once something inside is
|
|
158
|
+
edited (typing, or a checkbox/switch/radio click; `type="search"` inputs and
|
|
159
|
+
anything under `[data-dirty-ignore]` don't count), Escape, an overlay click or
|
|
160
|
+
the close button ask "Discard unsaved changes?" in place of the footer instead of
|
|
161
|
+
closing. `dirty={true}` forces the prompt, `dirty={false}` turns it off. Closing
|
|
162
|
+
in code (`open={false}`, a Cancel button) is never blocked.
|
|
163
|
+
|
|
164
|
+
### Others
|
|
165
|
+
|
|
166
|
+
- **Avatar**: `size` `xs` | `sm` | `md` (default) | `lg` | `xl`; `name` sets the
|
|
167
|
+
accessible label. AvatarImage needs `alt`; AvatarFallback shows initials.
|
|
168
|
+
- **Badge**: `variant` (`default`, `secondary`, `destructive`, `outline`,
|
|
169
|
+
`success`, `warning`, `info`), `size` (`default`, `sm`, `dot`), `clickable`
|
|
170
|
+
(or `onClick`) renders a button, `live`, `label`.
|
|
171
|
+
- **Label**: `disabled` dims it; the colour reads `--label-foreground`.
|
|
172
|
+
- **Switch**: `checked` / `defaultChecked` / `onCheckedChange`, `size`
|
|
173
|
+
(`default` | `sm`, React only); needs `aria-label`, `aria-labelledby` or an
|
|
174
|
+
`id` paired with a Label.
|
|
175
|
+
- **ProgressBar**: `value` (omit for indeterminate), `max`, `size` (`sm`, `md`,
|
|
176
|
+
`lg`), `variant` (`default`, `success`, `warning`, `destructive`), `label`,
|
|
177
|
+
`showValue`.
|
|
178
|
+
- **Skeleton**: `variant` (`default`, `text`, `avatar`, `card`, `button`,
|
|
179
|
+
`title`), `animation` (`pulse`, `shimmer`, `none`).
|
|
180
|
+
- **Spinner**: `size` (`sm`, `md`, `lg`, `xl`), `label`.
|
|
181
|
+
- **Separator**: `orientation`, `decorative` (default `true`).
|
|
182
|
+
- **Sheet**: `side`, `size`, `title`, `hideTitle`, `description`,
|
|
183
|
+
`headerActions`, `footer`, `dirty`.
|
|
184
|
+
|
|
185
|
+
### Alert
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
<Alert variant="warning">
|
|
189
|
+
<AlertTitle>Unsaved changes</AlertTitle>
|
|
190
|
+
<AlertDescription>Save before you leave.</AlertDescription>
|
|
191
|
+
</Alert>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`role="alert"`. The `error`, `destructive` and `warning` variants are announced assertively.
|
|
195
|
+
|
|
196
|
+
### Tabs
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
const [tab, setTab] = useState('profile');
|
|
200
|
+
|
|
201
|
+
<Tabs
|
|
202
|
+
label="Account"
|
|
203
|
+
tabs={[
|
|
204
|
+
{ id: 'profile', label: 'Profile' },
|
|
205
|
+
{ id: 'inbox', label: 'Inbox', badge: 3 },
|
|
206
|
+
]}
|
|
207
|
+
value={tab}
|
|
208
|
+
onValueChange={setTab}
|
|
209
|
+
>
|
|
210
|
+
<TabPanel value="profile">…</TabPanel>
|
|
211
|
+
<TabPanel value="inbox">…</TabPanel>
|
|
212
|
+
</Tabs>;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Arrow keys, Home and End move between tabs. With `collapse="auto"` (the default) the
|
|
216
|
+
row turns into a Select when it does not fit; `collapse="never"` wraps it instead.
|
|
217
|
+
|
|
218
|
+
### Select
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
<Select
|
|
222
|
+
label="Community"
|
|
223
|
+
options={[
|
|
224
|
+
{ value: 'aspen', label: 'Aspen' },
|
|
225
|
+
{ label: 'North', options: [{ value: 'elm', label: 'Elm' }] },
|
|
226
|
+
]}
|
|
227
|
+
value={community}
|
|
228
|
+
onValueChange={setCommunity}
|
|
229
|
+
hint="Where the home is"
|
|
230
|
+
error={errors.community}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Checkbox, RadioGroup, Slider, NumberInput, Textarea
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
<Checkbox checked={agree} onCheckedChange={setAgree} required error={errors.agree}>
|
|
238
|
+
I accept the terms
|
|
239
|
+
</Checkbox>
|
|
240
|
+
|
|
241
|
+
<RadioGroup
|
|
242
|
+
label="Plan"
|
|
243
|
+
options={[{ value: 'basic', label: 'Basic', description: 'One user' }]}
|
|
244
|
+
value={plan}
|
|
245
|
+
onValueChange={setPlan}
|
|
246
|
+
/>
|
|
247
|
+
|
|
248
|
+
<Slider label="Price" defaultValue={[200, 600]} max={1000} step={10} showValue />
|
|
249
|
+
|
|
250
|
+
<NumberInput label="Bedrooms" min={1} max={6} value={beds} onValueChange={setBeds} />
|
|
251
|
+
|
|
252
|
+
<Textarea aria-label="Notes" autosize maxRows={10} revertTo={saved} onValueChange={setNotes} />
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
NumberInput steps with ArrowUp/ArrowDown and clamps to `min`/`max` on blur.
|
|
256
|
+
Textarea's `revertTo` shows a revert button while the text differs; the revert can be undone.
|
|
257
|
+
|
|
258
|
+
### SegmentedControl
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
<SegmentedControl
|
|
262
|
+
label="Group homes by"
|
|
263
|
+
options={[
|
|
264
|
+
{ value: 'community', label: 'Community' },
|
|
265
|
+
{ value: 'plan', label: 'Floor Plan', icon: 'home' },
|
|
266
|
+
]}
|
|
267
|
+
value={groupBy}
|
|
268
|
+
onValueChange={setGroupBy}
|
|
269
|
+
/>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
A radio group: one option is always selected, arrow keys move the selection, Tab leaves.
|
|
273
|
+
|
|
274
|
+
### Tooltip, Popover, DropdownMenu, Collapsible
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
<Tooltip content="Delete this home">
|
|
278
|
+
<Button variant="ghost" size="icon" aria-label="Delete">
|
|
279
|
+
<Icon name="trash" />
|
|
280
|
+
</Button>
|
|
281
|
+
</Tooltip>
|
|
282
|
+
|
|
283
|
+
<Popover trigger={<Button variant="outline">Filters</Button>} aria-label="Filters">
|
|
284
|
+
…
|
|
285
|
+
</Popover>
|
|
286
|
+
|
|
287
|
+
<DropdownMenu
|
|
288
|
+
trigger="Actions"
|
|
289
|
+
triggerVariant="ghost"
|
|
290
|
+
showChevron
|
|
291
|
+
items={[
|
|
292
|
+
{ label: 'Edit', icon: 'edit', onSelect: edit },
|
|
293
|
+
{ type: 'separator' },
|
|
294
|
+
{ label: 'Delete', destructive: true, onSelect: remove },
|
|
295
|
+
]}
|
|
296
|
+
/>
|
|
297
|
+
|
|
298
|
+
<Collapsible label="More details">…</Collapsible>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Tooltip and Popover take their trigger as one element (Radix `asChild`). Tooltip's
|
|
302
|
+
`touch="tap"` lets a tap toggle an info-only tooltip.
|
|
303
|
+
|
|
304
|
+
### EmptyState, Section, Kbd, Icon
|
|
305
|
+
|
|
306
|
+
```tsx
|
|
307
|
+
<EmptyState
|
|
308
|
+
icon="inbox"
|
|
309
|
+
title="No messages"
|
|
310
|
+
description="New messages show up here."
|
|
311
|
+
actions={<Button>Compose</Button>}
|
|
312
|
+
/>
|
|
313
|
+
|
|
314
|
+
<Section title="Overview" description="This month">…</Section>
|
|
315
|
+
|
|
316
|
+
<Kbd keys={['Mod', 'K']} />
|
|
317
|
+
|
|
318
|
+
<Icon name="check" size={16} label="Done" />
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
`Kbd` shows "Mod" as ⌘ on Apple devices and Ctrl elsewhere. `Icon` draws from
|
|
322
|
+
`@classic-homes/theme-tokens/icons` (the theme-svelte set); it is `aria-hidden`,
|
|
323
|
+
and `label` adds visually hidden text.
|
|
324
|
+
|
|
325
|
+
### Table
|
|
326
|
+
|
|
327
|
+
```tsx
|
|
328
|
+
<TableContainer label="Homes">
|
|
329
|
+
<Table>
|
|
330
|
+
<TableHeader>
|
|
331
|
+
<TableRow>
|
|
332
|
+
<TableHead>Name</TableHead>
|
|
333
|
+
<TableHead align="right">Price</TableHead>
|
|
334
|
+
</TableRow>
|
|
335
|
+
</TableHeader>
|
|
336
|
+
<TableBody>
|
|
337
|
+
<TableRow interactive onClick={open}>
|
|
338
|
+
<TableCell>Aspen</TableCell>
|
|
339
|
+
<TableCell align="right">$400k</TableCell>
|
|
340
|
+
</TableRow>
|
|
341
|
+
</TableBody>
|
|
342
|
+
</Table>
|
|
343
|
+
</TableContainer>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Styled `<table>` primitives with the DataTable look. `TableContainer` adds the
|
|
347
|
+
border and horizontal scrolling; with `label` it is a focusable, named region.
|
|
348
|
+
||||||| 7db79b73
|