anvilui 0.1.0 → 0.2.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/AGENTS.md +483 -0
- package/README.md +70 -3
- package/bin/anvilui.mjs +83 -0
- package/dist/colors/colors.d.ts +10 -2
- package/dist/components/Accordion/Accordion.d.ts +36 -0
- package/dist/components/AnimatedNumber/AnimatedNumber.d.ts +17 -0
- package/dist/components/AnvilRoot/AnvilContext.d.ts +22 -2
- package/dist/components/AnvilRoot/AnvilRoot.d.ts +44 -6
- package/dist/components/AppBar/AppBar.d.ts +13 -2
- package/dist/components/Avatar/Avatar.d.ts +6 -2
- package/dist/components/Avatar/AvatarGroupContext.d.ts +1 -0
- package/dist/components/AvatarGroup/AvatarGroup.d.ts +25 -0
- package/dist/components/Badge/Badge.d.ts +4 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts +22 -0
- package/dist/components/Button/Button.d.ts +17 -0
- package/dist/components/Calendar/Calendar.d.ts +19 -0
- package/dist/components/Card/Card.d.ts +36 -0
- package/dist/components/Carousel/Carousel.d.ts +21 -0
- package/dist/components/Checkbox/Checkbox.d.ts +10 -0
- package/dist/components/Chip/Chip.d.ts +25 -2
- package/dist/components/Combobox/Combobox.d.ts +42 -0
- package/dist/components/Confetti/Confetti.d.ts +31 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +24 -0
- package/dist/components/DateInput/DateInput.d.ts +37 -0
- package/dist/components/Dialog/Dialog.d.ts +32 -0
- package/dist/components/Divider/Divider.d.ts +8 -0
- package/dist/components/FAB/FAB.d.ts +4 -0
- package/dist/components/FAB/magnet.d.ts +2 -0
- package/dist/components/FABMenu/FABMenu.d.ts +55 -0
- package/dist/components/Field/Field.d.ts +20 -0
- package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +15 -0
- package/dist/components/HoldButton/HoldButton.d.ts +4 -1
- package/dist/components/Icon/Icon.d.ts +14 -0
- package/dist/components/IconButton/IconButton.d.ts +11 -0
- package/dist/components/Input/Input.d.ts +9 -0
- package/dist/components/Kbd/Kbd.d.ts +21 -0
- package/dist/components/List/List.d.ts +10 -1
- package/dist/components/Menu/Menu.d.ts +32 -0
- package/dist/components/Menubar/Menubar.d.ts +17 -0
- package/dist/components/NavigationBar/NavigationBar.d.ts +10 -0
- package/dist/components/NavigationDrawer/NavigationDrawer.d.ts +22 -0
- package/dist/components/NavigationList/NavigationList.d.ts +27 -0
- package/dist/components/NavigationRail/NavigationRail.d.ts +25 -9
- package/dist/components/PinInput/PinInput.d.ts +31 -0
- package/dist/components/Popover/Popover.d.ts +30 -2
- package/dist/components/PreviewCard/PreviewCard.d.ts +31 -0
- package/dist/components/Progress/Progress.d.ts +8 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +12 -0
- package/dist/components/Search/Search.d.ts +39 -0
- package/dist/components/Select/Select.d.ts +15 -2
- package/dist/components/Skeleton/Skeleton.d.ts +20 -0
- package/dist/components/Slider/Slider.d.ts +5 -0
- package/dist/components/Snackbar/Snackbar.d.ts +7 -2
- package/dist/components/SplitButton/SplitButton.d.ts +13 -0
- package/dist/components/Sticker/Sticker.d.ts +21 -0
- package/dist/components/Switch/Switch.d.ts +11 -0
- package/dist/components/Table/Table.d.ts +36 -0
- package/dist/components/Tabs/Tabs.d.ts +17 -0
- package/dist/components/Textarea/Textarea.d.ts +8 -0
- package/dist/components/TimePicker/TimePicker.d.ts +45 -0
- package/dist/components/Toggle/Toggle.d.ts +41 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +14 -2
- package/dist/components/Tooltip/Tooltip.d.ts +10 -1
- package/dist/components/Typography/Typography.d.ts +13 -1
- package/dist/datetime.d.ts +12 -0
- package/dist/dev.d.ts +15 -0
- package/dist/index.cjs +3105 -634
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1417 -364
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +50 -4
- package/dist/index.js +3038 -591
- package/dist/index.js.map +1 -1
- package/dist/themes/baseTheme.d.ts +2 -0
- package/dist/themes/createTheme.d.ts +22 -0
- package/dist/themes/monochromeTheme.d.ts +2 -0
- package/dist/themes/types.d.ts +15 -6
- package/dist/tokens/baseTokens.d.ts +4 -0
- package/dist/tokens/types.d.ts +34 -0
- package/docs/accordion.md +47 -0
- package/docs/animated-number.md +31 -0
- package/docs/app-bar.md +53 -0
- package/docs/avatar-group.md +35 -0
- package/docs/avatar.md +34 -0
- package/docs/badge.md +41 -0
- package/docs/bottom-sheet.md +65 -0
- package/docs/button.md +63 -0
- package/docs/calendar.md +26 -0
- package/docs/card.md +71 -0
- package/docs/carousel.md +43 -0
- package/docs/checkbox.md +37 -0
- package/docs/chip.md +48 -0
- package/docs/combobox.md +72 -0
- package/docs/composition.md +80 -0
- package/docs/confetti.md +30 -0
- package/docs/context-menu.md +42 -0
- package/docs/date-input.md +41 -0
- package/docs/dialog.md +106 -0
- package/docs/divider.md +31 -0
- package/docs/fab-menu.md +55 -0
- package/docs/fab.md +43 -0
- package/docs/field.md +59 -0
- package/docs/floating-toolbar.md +48 -0
- package/docs/forms.md +81 -0
- package/docs/hold-button.md +32 -0
- package/docs/icon-button.md +54 -0
- package/docs/icons.md +38 -0
- package/docs/input.md +50 -0
- package/docs/kbd.md +25 -0
- package/docs/list.md +65 -0
- package/docs/llms-index.md +82 -0
- package/docs/menu.md +88 -0
- package/docs/menubar.md +34 -0
- package/docs/morph.md +51 -0
- package/docs/navigation-bar.md +48 -0
- package/docs/navigation-drawer.md +72 -0
- package/docs/navigation-list.md +40 -0
- package/docs/navigation-rail.md +53 -0
- package/docs/pin-input.md +38 -0
- package/docs/popover.md +78 -0
- package/docs/preview-card.md +40 -0
- package/docs/progress.md +37 -0
- package/docs/radio-group.md +47 -0
- package/docs/search.md +77 -0
- package/docs/select.md +64 -0
- package/docs/setup.md +106 -0
- package/docs/skeleton.md +33 -0
- package/docs/slider.md +49 -0
- package/docs/snackbar.md +50 -0
- package/docs/split-button.md +44 -0
- package/docs/sticker.md +27 -0
- package/docs/switch.md +44 -0
- package/docs/table.md +66 -0
- package/docs/tabs.md +51 -0
- package/docs/textarea.md +23 -0
- package/docs/theming.md +182 -0
- package/docs/time-picker.md +38 -0
- package/docs/toggle-group.md +70 -0
- package/docs/toggle.md +49 -0
- package/docs/tooltip.md +42 -0
- package/docs/typography.md +41 -0
- package/package.json +25 -5
package/AGENTS.md
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
# AnvilUI: reference for AI coding agents
|
|
2
|
+
|
|
3
|
+
`anvilui` is a React 19 component library with Material 3 styling, built on [Base UI](https://base-ui.com) (`@base-ui/react`). It has ~50 accessible components (buttons, inputs, selects, dialogs, menus, navigation, …), a theme system driven by CSS variables, and Material Symbols icons referenced by name. It is **not** shadcn/ui, Radix or MUI: names and props differ. This file matches the installed version. Read it before writing code; per-component pages are in [`docs/`](docs/llms-index.md) (`node_modules/anvilui/docs/<name>.md`).
|
|
4
|
+
|
|
5
|
+
## Rules that prevent most errors
|
|
6
|
+
|
|
7
|
+
1. `import 'anvilui/styles.css'` once, and wrap the whole app in `<AnvilRoot>`. Nothing is themed outside it.
|
|
8
|
+
2. Everything imports from `'anvilui'`. No subpaths (`anvilui/button` doesn't exist) except `'anvilui/styles.css'`.
|
|
9
|
+
3. **No `asChild`.** Use `render`: `<DialogTrigger render={<Button />}>Open</DialogTrigger>`. Trigger and Close parts render bare, unstyled buttons without it.
|
|
10
|
+
4. **No `variant`.** Style is `fillType: 'filled' | 'outlined' | 'text'`; color is `color: 'primary' | 'tonal' | 'success' | 'warning' | 'error' | 'container' | 'surface'`. No `secondary` / `destructive` / `ghost`.
|
|
11
|
+
5. **Icons are strings** (Material Symbols names): `startIcon="add"`, `<IconButton icon="delete" aria-label="Delete" />`, `<Icon name="home" />`. Don't pass icon components.
|
|
12
|
+
6. Callbacks get **values, not events**: `onValueChange(value)`, `onCheckedChange(checked)`, `onOpenChange(open)`, `onPressedChange(pressed)`. No `onChange` except on `Input`/`Textarea` (native).
|
|
13
|
+
7. `Checkbox`, `Switch`, `Radio` have **no `label` prop**: wrap them in `<label>`. Most other controls take `label`.
|
|
14
|
+
8. Titles and text often go in **`label`, not children**: `AppBar`, `ListItem`, `Tooltip`, nav items, `Input`, `Select`, `Slider`, `Progress`.
|
|
15
|
+
9. Icon-only controls require `aria-label` (`IconButton`, `FAB` without `label`, icon `Toggle`, `Slider`/`Progress` without `label`, `Search`, `Carousel`).
|
|
16
|
+
10. `Button` defaults to `type="button"`. Use `type="submit"` in forms.
|
|
17
|
+
11. Dates are `"YYYY-MM-DD"` strings, times `"HH:mm"` strings. Not `Date` objects.
|
|
18
|
+
12. No layout components (`Box`, `Stack`, `Grid`, `Container`, `Flex`) and no `sx`. Use plain elements with `style` / CSS and theme variables like `var(--avl-spacing-x4)`.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
Requires `react` and `react-dom` 19+, and a bundler that handles CSS from `node_modules` (Vite, Next.js, webpack).
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
// main.tsx
|
|
26
|
+
import { createRoot } from 'react-dom/client'
|
|
27
|
+
import { AnvilRoot } from 'anvilui'
|
|
28
|
+
import 'anvilui/styles.css'
|
|
29
|
+
import { App } from './App'
|
|
30
|
+
|
|
31
|
+
createRoot(document.getElementById('root')!).render(
|
|
32
|
+
<AnvilRoot
|
|
33
|
+
defaultColorMode="system"
|
|
34
|
+
storageKey="color-mode"
|
|
35
|
+
className="app-root"
|
|
36
|
+
>
|
|
37
|
+
<App />
|
|
38
|
+
</AnvilRoot>
|
|
39
|
+
)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `AnvilRoot` is the only provider (theme, color mode, tooltips, snackbars, portal container). Don't add `ThemeProvider`, `Toaster` or `TooltipProvider`.
|
|
43
|
+
- Give it a class with `min-height: 100vh` so the background covers the page.
|
|
44
|
+
- Hooks `useAnvil()` and `useSnackbar()` work only in components **inside** it.
|
|
45
|
+
- Next.js App Router: render `AnvilRoot` in a `'use client'` component and use AnvilUI from client components. Details: [docs/setup.md](docs/setup.md).
|
|
46
|
+
- Fonts: Google Sans is not loaded for you (falls back to the system font). See setup.md.
|
|
47
|
+
|
|
48
|
+
## Exports
|
|
49
|
+
|
|
50
|
+
| Area | Exports | Doc |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| Root & theme | `AnvilRoot`, `useAnvil`, `AnvilContext`, `createTheme`, `createThemeFromImage`, `baseLightTheme`, `baseDarkTheme`, `monochromeLightTheme`, `monochromeDarkTheme`, `baseDesignTokens` | [theming.md](docs/theming.md) |
|
|
53
|
+
| Buttons | `Button`, `IconButton`, `SplitButton`, `HoldButton`, `Toggle`, `ToggleGroup`, `ToggleGroupItem`, `FAB`, `FABMenu`, `FABMenuItem` | [button](docs/button.md), [icon-button](docs/icon-button.md), [split-button](docs/split-button.md), [hold-button](docs/hold-button.md), [toggle](docs/toggle.md), [toggle-group](docs/toggle-group.md), [fab](docs/fab.md), [fab-menu](docs/fab-menu.md) |
|
|
54
|
+
| Chips | `Chip`, `FilterChip`, `InputChip` | [chip.md](docs/chip.md) |
|
|
55
|
+
| Form controls | `Input`, `Textarea`, `Select`, `SelectItem`, `Combobox`, `ComboboxItem`, `Search`, `SearchItem`, `Checkbox`, `Switch`, `RadioGroup`, `Radio`, `Slider`, `DateInput`, `TimePicker`, `Calendar`, `PinInput`, `Field`, `FieldDescription`, `FieldError` | [forms.md](docs/forms.md) + one page each |
|
|
56
|
+
| Overlays | `Dialog`(+`Trigger`, `Popup`, `Title`, `Description`, `Actions`, `Close`), `BottomSheet`(+`Trigger`, `Popup`, `Title`, `Description`, `Close`), `Popover`(+`Trigger`, `Popup`, `Title`, `Description`, `Close`), `PreviewCard`(+`Trigger`, `Popup`), `Tooltip` | [dialog](docs/dialog.md), [bottom-sheet](docs/bottom-sheet.md), [popover](docs/popover.md), [preview-card](docs/preview-card.md), [tooltip](docs/tooltip.md) |
|
|
57
|
+
| Menus | `Menu`, `MenuTrigger`, `MenuPopup`, `MenuItem`, `MenuGroup`, `MenuSubmenu`, `MenuSubmenuTrigger`, `ContextMenu`, `ContextMenuTrigger`, `Menubar` | [menu](docs/menu.md), [context-menu](docs/context-menu.md), [menubar](docs/menubar.md) |
|
|
58
|
+
| Navigation | `AppBar`, `NavigationBar`(+`Item`), `NavigationRail`(+`Toggle`, `Item`), `NavigationList`(+`Item`), `NavigationDrawer`(+`Trigger`, `Popup`, `Title`, `Item`), `Tabs`, `TabsList`, `TabsTab`, `TabsPanel`, `FloatingToolbar`(+`Button`, `Separator`) | [app-bar](docs/app-bar.md), [navigation-bar](docs/navigation-bar.md), [navigation-rail](docs/navigation-rail.md), [navigation-list](docs/navigation-list.md), [navigation-drawer](docs/navigation-drawer.md), [tabs](docs/tabs.md), [floating-toolbar](docs/floating-toolbar.md) |
|
|
59
|
+
| Content | `Card`, `CardTitle`, `CardContent`, `CardActions`, `List`, `ListItem`, `Table`, `TableCaption`, `TableHead`, `TableBody`, `TableRow`, `TableHeaderCell`, `TableCell`, `Accordion`, `AccordionItem`, `AccordionTrigger`, `AccordionPanel`, `Carousel`, `CarouselItem`, `Divider`, `Typography` | [card](docs/card.md), [list](docs/list.md), [table](docs/table.md), [accordion](docs/accordion.md), [carousel](docs/carousel.md), [divider](docs/divider.md), [typography](docs/typography.md) |
|
|
60
|
+
| Display | `Avatar`, `AvatarGroup`, `Badge`, `Icon`, `Progress`, `Skeleton`, `Sticker`, `AnimatedNumber`, `Kbd` | [avatar](docs/avatar.md), [avatar-group](docs/avatar-group.md), [badge](docs/badge.md), [icons](docs/icons.md), [progress](docs/progress.md), [skeleton](docs/skeleton.md), [sticker](docs/sticker.md), [animated-number](docs/animated-number.md), [kbd](docs/kbd.md) |
|
|
61
|
+
| Hooks | `useSnackbar` (toasts), `useConfetti`, `useAnvil` | [snackbar](docs/snackbar.md), [confetti](docs/confetti.md), [theming](docs/theming.md) |
|
|
62
|
+
| Motion | `morph`, `morphBetween` | [morph.md](docs/morph.md) |
|
|
63
|
+
| Types | `<Name>Props` for every component; `MaterialSymbol` (icon names), `ComponentColor`, `ComponentFillType`, `ColorProps`, `Theme`, `ThemePair`, `CreateThemeOptions`, `DesignTokens`, `Font`, `FontSize`, `Ease`, `EaseLength`, `ColorType`, `ColorModeSetting`, `TypographyType`, `TypographyTag`, `SnackbarOptions`, `ConfettiOptions`, `ConfettiOrigin`, `MorphOptions` | |
|
|
64
|
+
|
|
65
|
+
Nothing else is exported. Not in the library: `Box`, `Stack`, `Grid`, `Container`, `Label`, `FieldLabel`, `Form`, `Spinner`, `Toast`/`Toaster`, `Alert`, `Banner`, `Breadcrumbs`, `Pagination`, `Stepper`, `DataGrid`, `DatePicker` (use `DateInput`), `Drawer` (use `NavigationDrawer` / `BottomSheet`), `DropdownMenu` (use `Menu`), `Separator` (use `Divider`), `Sheet` (use `BottomSheet`).
|
|
66
|
+
|
|
67
|
+
## Component reference
|
|
68
|
+
|
|
69
|
+
Props marked * are required. All components also take `className`, `style`, `ref` and the props of their underlying element / Base UI part. Full tables: `docs/<name>.md`.
|
|
70
|
+
|
|
71
|
+
### Buttons
|
|
72
|
+
|
|
73
|
+
| Component | Key props | Usage |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| `Button` | `fillType`, `color`, `size: 'small'\|'normal'\|'big'`, `startIcon`, `endIcon`, `loading`, `disabled`, `type`, `render` | `<Button startIcon="add" onClick={create}>New</Button>` |
|
|
76
|
+
| `IconButton` | `icon`_, `aria-label`_, `fillType`, `color`. No size, no children | `<IconButton icon="close" aria-label="Close" fillType="text" color="container" />` |
|
|
77
|
+
| `SplitButton` | `<div>` props | `<SplitButton><Button>Save</Button><IconButton icon="arrow_drop_down" aria-label="More" /></SplitButton>` |
|
|
78
|
+
| `HoldButton` | `onConfirm`*, `holdDuration` (1500), Button props | `<HoldButton color="error" onConfirm={del}>Hold to delete</HoldButton>` |
|
|
79
|
+
| `Toggle` | `pressed`/`defaultPressed`/`onPressedChange`, `color`, `fillType`; text: `children`, `startIcon`, `size`; icon: `icon` + `aria-label` | `<Toggle icon="favorite" aria-label="Favorite" />` |
|
|
80
|
+
| `ToggleGroup` | `value`/`defaultValue`/`onValueChange` (single value; array with `multiple`), `multiple`, `color`, `fillType`, `size` | `<ToggleGroup aria-label="View" defaultValue="list">…</ToggleGroup>` |
|
|
81
|
+
| `ToggleGroupItem` | `value`*, `startIcon`, `endIcon`, `children` | `<ToggleGroupItem value="list">List</ToggleGroupItem>` |
|
|
82
|
+
| `FAB` | `icon`_, `label` or `aria-label`_, `size`, `color`, `fillType`, `sticky` | `<FAB icon="add" aria-label="New" style={{ position: 'fixed', right: 16, bottom: 16 }} />` |
|
|
83
|
+
| `FABMenu` | `icon`_, `aria-label`_, `children`* (`FABMenuItem`s), `side`, `align`, `color` | `<FABMenu icon="add" aria-label="Create"><FABMenuItem icon="folder">Folder</FABMenuItem></FABMenu>` |
|
|
84
|
+
| `Chip` / `FilterChip` / `InputChip` | `startIcon`; FilterChip `pressed`/`onPressedChange`; InputChip `onRemove`*, `removeLabel` | `<FilterChip pressed={on} onPressedChange={setOn}>Vegan</FilterChip>` |
|
|
85
|
+
|
|
86
|
+
### Form controls
|
|
87
|
+
|
|
88
|
+
| Component | Key props | Usage |
|
|
89
|
+
| --- | --- | --- |
|
|
90
|
+
| `Input` | `label`, `size: 'small'\|'normal'`, `value`/`defaultValue`, `onValueChange(string)` or `onChange(event)`, input attrs | `<Input label="Email" type="email" value={v} onValueChange={setV} />` |
|
|
91
|
+
| `Textarea` | same as Input + `rows` | `<Textarea label="Bio" rows={4} />` |
|
|
92
|
+
| `Select` | `items` (map or `{value,label}[]`), `value`/`defaultValue`/`onValueChange(value)`, `label`, `placeholder`, `multiple`, `name` | `<Select label="Fruit" items={fruits} defaultValue="apple">{…SelectItem}</Select>` |
|
|
93
|
+
| `SelectItem` | `value`*, children = label | `<SelectItem value="apple">Apple</SelectItem>` |
|
|
94
|
+
| `Combobox` | `items`, `children`* = `(item) => <ComboboxItem/>`, `value`/`onValueChange(item)`, `itemToStringLabel`, `label`, `empty` | `<Combobox label="Fruit" items={list}>{(f: string) => <ComboboxItem key={f} value={f}>{f}</ComboboxItem>}</Combobox>` |
|
|
95
|
+
| `Search` | `aria-label`_, `items`, `children`_ = `(item) => <SearchItem/>`, `value`/`onValueChange(text)`, `placeholder`, `empty` | `<Search aria-label="Search" items={[]} onValueChange={setQ}>{(i: string) => <SearchItem key={i} value={i}>{i}</SearchItem>}</Search>` |
|
|
96
|
+
| `Checkbox` | `checked`/`defaultChecked`/`onCheckedChange(boolean)`, `indeterminate`, `name` | `<label><Checkbox checked={c} onCheckedChange={setC} /> Remember me</label>` |
|
|
97
|
+
| `Switch` | `checked`/`defaultChecked`/`onCheckedChange(boolean)`, `name` | `<label><Switch defaultChecked /> Wi-Fi</label>` |
|
|
98
|
+
| `RadioGroup` / `Radio` | group: `value`/`defaultValue`/`onValueChange(value)`, `name`; radio: `value`* | `<RadioGroup defaultValue="a"><label><Radio value="a" /> A</label></RadioGroup>` |
|
|
99
|
+
| `Slider` | `label` or `aria-label`*, `value`/`defaultValue` (number or number[]), `onValueChange(number)`, `min`, `max`, `step`, `showValue`, `format` | `<Slider label="Volume" defaultValue={50} />` |
|
|
100
|
+
| `DateInput` | `value`/`defaultValue` `"YYYY-MM-DD" \| null`, `onValueChange`, `label` or `aria-label`* | `<DateInput label="Due" value={d} onValueChange={setD} />` |
|
|
101
|
+
| `TimePicker` | `value`/`defaultValue` `"HH:mm" \| null`, `onValueChange`, `type: 'dial'\|'input'`, `hourCycle: 12\|24`, `label` or `aria-label`*, `name` | `<TimePicker label="Start" defaultValue="09:00" />` |
|
|
102
|
+
| `Calendar` | `value`/`defaultValue` `"YYYY-MM-DD" \| null`, `onValueChange` | `<Calendar value={d} onValueChange={setD} />` |
|
|
103
|
+
| `PinInput` | `length`_, `label` or `aria-label`_, `value`/`onValueChange`, `onValueComplete`, `mask`, `validationType` | `<PinInput label="Code" length={6} />` |
|
|
104
|
+
| `Field` | `name`, `validate`, `validationMode: 'onSubmit'\|'onBlur'\|'onChange'`, `invalid`, `disabled` | `<Field name="email"><Input label="Email" required /><FieldError /></Field>` |
|
|
105
|
+
| `FieldDescription` / `FieldError` | FieldError `match` | `<FieldError match="valueMissing">Required</FieldError>` |
|
|
106
|
+
|
|
107
|
+
### Overlays and menus
|
|
108
|
+
|
|
109
|
+
| Component | Parts and key props | Usage |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `Dialog` | `open`/`defaultOpen`/`onOpenChange`; `DialogTrigger`, `DialogPopup` (includes portal + backdrop), `DialogTitle`, `DialogDescription`, `DialogActions`, `DialogClose` | see Patterns |
|
|
112
|
+
| `BottomSheet` | same shape: `BottomSheetTrigger`, `BottomSheetPopup`, `BottomSheetTitle`, `BottomSheetDescription`, `BottomSheetClose`; `snapPoints` | |
|
|
113
|
+
| `Popover` | `PopoverTrigger`, `PopoverPopup` (`side`, `align`, `sideOffset`), `PopoverTitle`, `PopoverDescription`, `PopoverClose` | |
|
|
114
|
+
| `PreviewCard` | `PreviewCardTrigger` (an `<a href>`), `PreviewCardPopup` | |
|
|
115
|
+
| `Tooltip` | `label`_, one element child_, `side`, `align`, `delay` | `<Tooltip label="Delete"><IconButton icon="delete" aria-label="Delete" /></Tooltip>` |
|
|
116
|
+
| `Menu` | `MenuTrigger`, `MenuPopup` (`side`, `align`), `MenuItem` (`onClick`, `startIcon`, `endIcon`, `disabled`), `MenuGroup`, `MenuSubmenu` + `MenuSubmenuTrigger` | see Patterns |
|
|
117
|
+
| `ContextMenu` | `ContextMenuTrigger` (area) + `MenuPopup` / `MenuItem` | |
|
|
118
|
+
| `Menubar` | contains `Menu`s | |
|
|
119
|
+
| `useSnackbar()` | `.show({ message*, action?: { label, onClick }, closeButton, timeout (5000), priority })`, `.close(id?)` | `snackbar.show({ message: 'Saved' })` |
|
|
120
|
+
|
|
121
|
+
### Navigation and layout
|
|
122
|
+
|
|
123
|
+
| Component | Key props | Usage |
|
|
124
|
+
| --- | --- | --- |
|
|
125
|
+
| `AppBar` | `label`*, `labelAs`, `start`, `end`, `size: 'normal'\|'big'`, `centered`, `color` ('container') | `<AppBar label="Inbox" start={…} end={…} />` |
|
|
126
|
+
| `NavigationBar` / `NavigationBarItem` | item: `icon`_, `label`_, `active`, `href` or `render={<Link/>}` | `<NavigationBarItem icon="home" label="Home" href="/" active />` |
|
|
127
|
+
| `NavigationRail` / `NavigationRailToggle` / `NavigationRailItem` | rail: `expanded`/`defaultExpanded`/`onExpandedChange`; toggle: `aria-label`_; item: `icon`_, `label`*, `active`, `end`, `href` | |
|
|
128
|
+
| `NavigationList` / `NavigationListItem` | item: `label`*, `active`, `href`, `render` | |
|
|
129
|
+
| `NavigationDrawer` | `NavigationDrawerTrigger`, `NavigationDrawerPopup`, `NavigationDrawerTitle`, `NavigationDrawerItem` (`icon`_, `label`_, `active`, `href`) | |
|
|
130
|
+
| `Tabs` | `value`/`defaultValue`/`onValueChange`; `TabsList`, `TabsTab` (`value`_, `icon`), `TabsPanel` (`value`_). Always set `defaultValue` | see Patterns |
|
|
131
|
+
| `FloatingToolbar` | `inverseColor`; `FloatingToolbarButton` (IconButton props), `FloatingToolbarSeparator` | |
|
|
132
|
+
| `Card` | `color` ('container'), `fillType`, `clickable`; `CardTitle` (`as`), `CardContent`, `CardActions` | |
|
|
133
|
+
| `List` / `ListItem` | list: `divided`; item: `label`*, `description`, `start`, `end`, `render`. No children | `<ListItem label="Wi-Fi" end={<Switch />} render={<label />} />` |
|
|
134
|
+
| `Table` | `TableCaption`, `TableHead`, `TableBody`, `TableRow`, `TableHeaderCell`, `TableCell` (native elements) | |
|
|
135
|
+
| `Accordion` | `value`/`defaultValue` (array), `multiple`; `AccordionItem` (`value`), `AccordionTrigger` (`as`), `AccordionPanel` | |
|
|
136
|
+
| `Carousel` / `CarouselItem` | `aria-label`* | |
|
|
137
|
+
| `Divider` | `orientation`, `label`, `squiggly` | `<Divider label="or" />` |
|
|
138
|
+
| `Typography` | `type: 'body'\|'caption'\|'h1'…'h6'` (not `variant`), `as` | `<Typography type="h5" as="h1">Settings</Typography>` |
|
|
139
|
+
|
|
140
|
+
### Display
|
|
141
|
+
|
|
142
|
+
| Component | Key props | Usage |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| `Avatar` | `name`, `src`, `icon`, `size` (32/40/56px), `color` | `<Avatar name="Ada Lovelace" src={url} />` |
|
|
145
|
+
| `AvatarGroup` | `max`, `size`, `fan`, `aria-label` | `<AvatarGroup max={3} aria-label="Team">{avatars}</AvatarGroup>` |
|
|
146
|
+
| `Badge` | `count` (omit for dot, 0 hides), `max`, `color` ('error'), wraps children | `<Badge count={3}><IconButton icon="mail" aria-label="Mail, 3 new" /></Badge>` |
|
|
147
|
+
| `Icon` | `name`* | `<Icon name="star" />` |
|
|
148
|
+
| `Progress` | `value`* (`number \| null`), `type: 'linear'\|'circular'\|'inline'`, `label` or `aria-label`*, `squiggly` | `<Progress type="circular" value={null} aria-label="Loading" />` |
|
|
149
|
+
| `Skeleton` | `variant: 'text'\|'circular'\|'rectangular'`, `animation`; size via `style` | `<Skeleton style={{ width: 120 }} />` |
|
|
150
|
+
| `Sticker` | `color`, `startIcon`, `tilt` | `<Sticker>NEW</Sticker>` |
|
|
151
|
+
| `AnimatedNumber` | `value`*, `format`, `locales` | `<AnimatedNumber value={n} />` |
|
|
152
|
+
| `Kbd` | `children`, `listen`, `listenFor` | `<Kbd>⌘</Kbd><Kbd>K</Kbd>` |
|
|
153
|
+
|
|
154
|
+
## Patterns
|
|
155
|
+
|
|
156
|
+
### App shell: app bar, side navigation, content
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
import {
|
|
160
|
+
AppBar,
|
|
161
|
+
Avatar,
|
|
162
|
+
IconButton,
|
|
163
|
+
NavigationRail,
|
|
164
|
+
NavigationRailItem,
|
|
165
|
+
NavigationRailToggle,
|
|
166
|
+
} from 'anvilui'
|
|
167
|
+
|
|
168
|
+
export function Shell({ children }: { children: React.ReactNode }) {
|
|
169
|
+
return (
|
|
170
|
+
<div style={{ display: 'flex', height: '100vh' }}>
|
|
171
|
+
<NavigationRail aria-label="Main">
|
|
172
|
+
<NavigationRailToggle aria-label="Toggle navigation" />
|
|
173
|
+
<NavigationRailItem
|
|
174
|
+
icon="dashboard"
|
|
175
|
+
label="Dashboard"
|
|
176
|
+
href="/"
|
|
177
|
+
active
|
|
178
|
+
/>
|
|
179
|
+
<NavigationRailItem
|
|
180
|
+
icon="settings"
|
|
181
|
+
label="Settings"
|
|
182
|
+
href="/settings"
|
|
183
|
+
/>
|
|
184
|
+
</NavigationRail>
|
|
185
|
+
<div
|
|
186
|
+
style={{
|
|
187
|
+
flex: 1,
|
|
188
|
+
display: 'flex',
|
|
189
|
+
flexDirection: 'column',
|
|
190
|
+
minWidth: 0,
|
|
191
|
+
}}
|
|
192
|
+
>
|
|
193
|
+
<AppBar
|
|
194
|
+
label="Dashboard"
|
|
195
|
+
labelAs="h1"
|
|
196
|
+
end={
|
|
197
|
+
<>
|
|
198
|
+
<IconButton
|
|
199
|
+
icon="notifications"
|
|
200
|
+
aria-label="Notifications"
|
|
201
|
+
fillType="text"
|
|
202
|
+
color="container"
|
|
203
|
+
/>
|
|
204
|
+
<Avatar name="Ada Lovelace" size="small" />
|
|
205
|
+
</>
|
|
206
|
+
}
|
|
207
|
+
/>
|
|
208
|
+
<main
|
|
209
|
+
style={{
|
|
210
|
+
flex: 1,
|
|
211
|
+
overflow: 'auto',
|
|
212
|
+
padding: 'var(--avl-spacing-x6)',
|
|
213
|
+
}}
|
|
214
|
+
>
|
|
215
|
+
{children}
|
|
216
|
+
</main>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Settings page: tabs, form fields, switches
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
import { useState } from 'react'
|
|
227
|
+
import {
|
|
228
|
+
Button,
|
|
229
|
+
Field,
|
|
230
|
+
FieldError,
|
|
231
|
+
Input,
|
|
232
|
+
List,
|
|
233
|
+
ListItem,
|
|
234
|
+
Select,
|
|
235
|
+
SelectItem,
|
|
236
|
+
Switch,
|
|
237
|
+
Tabs,
|
|
238
|
+
TabsList,
|
|
239
|
+
TabsPanel,
|
|
240
|
+
TabsTab,
|
|
241
|
+
useSnackbar,
|
|
242
|
+
} from 'anvilui'
|
|
243
|
+
|
|
244
|
+
const languages = { en: 'English', fr: 'Français', ja: '日本語' }
|
|
245
|
+
|
|
246
|
+
export function Settings() {
|
|
247
|
+
const snackbar = useSnackbar()
|
|
248
|
+
const [name, setName] = useState('Ada')
|
|
249
|
+
const [language, setLanguage] = useState<string | null>('en')
|
|
250
|
+
return (
|
|
251
|
+
<Tabs defaultValue="profile">
|
|
252
|
+
<TabsList>
|
|
253
|
+
<TabsTab value="profile" icon="person">
|
|
254
|
+
Profile
|
|
255
|
+
</TabsTab>
|
|
256
|
+
<TabsTab value="notifications" icon="notifications">
|
|
257
|
+
Notifications
|
|
258
|
+
</TabsTab>
|
|
259
|
+
</TabsList>
|
|
260
|
+
<TabsPanel value="profile">
|
|
261
|
+
<form
|
|
262
|
+
style={{
|
|
263
|
+
display: 'grid',
|
|
264
|
+
gap: 16,
|
|
265
|
+
maxWidth: 400,
|
|
266
|
+
paddingBlock: 16,
|
|
267
|
+
}}
|
|
268
|
+
onSubmit={(e) => {
|
|
269
|
+
e.preventDefault()
|
|
270
|
+
snackbar.show({ message: 'Profile saved' })
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
273
|
+
<Field name="name">
|
|
274
|
+
<Input
|
|
275
|
+
label="Display name"
|
|
276
|
+
required
|
|
277
|
+
value={name}
|
|
278
|
+
onValueChange={setName}
|
|
279
|
+
/>
|
|
280
|
+
<FieldError />
|
|
281
|
+
</Field>
|
|
282
|
+
<Select
|
|
283
|
+
label="Language"
|
|
284
|
+
items={languages}
|
|
285
|
+
value={language}
|
|
286
|
+
onValueChange={setLanguage}
|
|
287
|
+
>
|
|
288
|
+
{Object.entries(languages).map(([value, label]) => (
|
|
289
|
+
<SelectItem key={value} value={value}>
|
|
290
|
+
{label}
|
|
291
|
+
</SelectItem>
|
|
292
|
+
))}
|
|
293
|
+
</Select>
|
|
294
|
+
<Button type="submit" style={{ justifySelf: 'start' }}>
|
|
295
|
+
Save
|
|
296
|
+
</Button>
|
|
297
|
+
</form>
|
|
298
|
+
</TabsPanel>
|
|
299
|
+
<TabsPanel value="notifications">
|
|
300
|
+
<List divided>
|
|
301
|
+
<ListItem
|
|
302
|
+
label="Email"
|
|
303
|
+
description="Weekly summary"
|
|
304
|
+
end={<Switch defaultChecked />}
|
|
305
|
+
render={<label />}
|
|
306
|
+
/>
|
|
307
|
+
<ListItem
|
|
308
|
+
label="Push"
|
|
309
|
+
end={<Switch />}
|
|
310
|
+
render={<label />}
|
|
311
|
+
/>
|
|
312
|
+
</List>
|
|
313
|
+
</TabsPanel>
|
|
314
|
+
</Tabs>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Confirm dialog opened from a row menu
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
import { useState } from 'react'
|
|
323
|
+
import {
|
|
324
|
+
Button,
|
|
325
|
+
Dialog,
|
|
326
|
+
DialogActions,
|
|
327
|
+
DialogClose,
|
|
328
|
+
DialogDescription,
|
|
329
|
+
DialogPopup,
|
|
330
|
+
DialogTitle,
|
|
331
|
+
IconButton,
|
|
332
|
+
List,
|
|
333
|
+
ListItem,
|
|
334
|
+
Menu,
|
|
335
|
+
MenuItem,
|
|
336
|
+
MenuPopup,
|
|
337
|
+
MenuTrigger,
|
|
338
|
+
} from 'anvilui'
|
|
339
|
+
|
|
340
|
+
export function Files() {
|
|
341
|
+
const [files, setFiles] = useState(['report.pdf', 'notes.txt'])
|
|
342
|
+
// Separate from `open`, so the title still reads right while it animates closed
|
|
343
|
+
const [toDelete, setToDelete] = useState('')
|
|
344
|
+
const [open, setOpen] = useState(false)
|
|
345
|
+
return (
|
|
346
|
+
<>
|
|
347
|
+
<List divided>
|
|
348
|
+
{files.map((file) => (
|
|
349
|
+
<ListItem
|
|
350
|
+
key={file}
|
|
351
|
+
label={file}
|
|
352
|
+
end={
|
|
353
|
+
<Menu>
|
|
354
|
+
<MenuTrigger
|
|
355
|
+
render={
|
|
356
|
+
<IconButton
|
|
357
|
+
icon="more_vert"
|
|
358
|
+
aria-label={`Actions for ${file}`}
|
|
359
|
+
fillType="text"
|
|
360
|
+
color="container"
|
|
361
|
+
/>
|
|
362
|
+
}
|
|
363
|
+
/>
|
|
364
|
+
<MenuPopup align="end">
|
|
365
|
+
<MenuItem
|
|
366
|
+
startIcon="delete"
|
|
367
|
+
onClick={() => {
|
|
368
|
+
setToDelete(file)
|
|
369
|
+
setOpen(true)
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
Delete
|
|
373
|
+
</MenuItem>
|
|
374
|
+
</MenuPopup>
|
|
375
|
+
</Menu>
|
|
376
|
+
}
|
|
377
|
+
/>
|
|
378
|
+
))}
|
|
379
|
+
</List>
|
|
380
|
+
{/* Controlled, outside the menu, so closing the menu doesn't unmount it */}
|
|
381
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
382
|
+
<DialogPopup>
|
|
383
|
+
<DialogTitle>Delete {toDelete}?</DialogTitle>
|
|
384
|
+
<DialogDescription>This can't be undone.</DialogDescription>
|
|
385
|
+
<DialogActions>
|
|
386
|
+
<DialogClose render={<Button fillType="text" />}>
|
|
387
|
+
Cancel
|
|
388
|
+
</DialogClose>
|
|
389
|
+
<Button
|
|
390
|
+
color="error"
|
|
391
|
+
onClick={() => {
|
|
392
|
+
setFiles(files.filter((f) => f !== toDelete))
|
|
393
|
+
setOpen(false)
|
|
394
|
+
}}
|
|
395
|
+
>
|
|
396
|
+
Delete
|
|
397
|
+
</Button>
|
|
398
|
+
</DialogActions>
|
|
399
|
+
</DialogPopup>
|
|
400
|
+
</Dialog>
|
|
401
|
+
</>
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Router links
|
|
407
|
+
|
|
408
|
+
Nav items, `ListItem`, `MenuItem`, `PreviewCardTrigger` and `Card clickable` take `render`: `<NavigationRailItem icon="home" label="Home" render={<Link to="/" />} active={pathname === '/'} />`. On `Button` also pass `nativeButton={false}`: `<Button render={<Link to="/new" />} nativeButton={false}>New</Button>`.
|
|
409
|
+
|
|
410
|
+
### Switching views without URLs
|
|
411
|
+
|
|
412
|
+
Nav items render `<a>` by default. For in-page state, pass a plain button: `<NavigationRailItem icon="home" label="Home" active={view === 'home'} render={<button type="button" onClick={() => setView('home')} />} />` (no `nativeButton` needed). Same for `NavigationBarItem`, `NavigationListItem`, `NavigationDrawerItem` (still closes the drawer) and `ListItem`.
|
|
413
|
+
|
|
414
|
+
### Inline success / error messages
|
|
415
|
+
|
|
416
|
+
There is no `Alert` or `Banner`. For a message after an action, use a snackbar (`useSnackbar().show(...)`). For a message that stays on the page, use a colored card: `<Card color="success" role="status"><CardContent>Account created</CardContent></Card>` (`color="error"` with `role="alert"` for errors). For a field's error, use `Field` + `FieldError`.
|
|
417
|
+
|
|
418
|
+
### Typing state for value callbacks
|
|
419
|
+
|
|
420
|
+
`Value` is inferred from your `value` / `defaultValue`, so union-typed state works directly: `const [plan, setPlan] = useState<'free' | 'pro'>('free')` then `<ToggleGroup value={plan} onValueChange={setPlan}>` (also `RadioGroup`, `Tabs`, `Select`). `Slider` too: a number `value` gives a `(value: number)` callback, an array a `number[]` one, so `onValueChange={setVolume}` works. To type an icon field yourself: `import type { MaterialSymbol } from 'anvilui'`.
|
|
421
|
+
|
|
422
|
+
### Theme colors in your own CSS
|
|
423
|
+
|
|
424
|
+
Inside AnvilRoot: `var(--avl-color-background)`, `var(--avl-color-on-background)`, `var(--avl-color-on-background-muted)`, `var(--avl-color-primary)`, `var(--avl-color-surface)`, `var(--avl-color-divider)`, spacing `var(--avl-spacing-x1…x20)` (4px steps), radius `var(--avl-radius-medium)`. Custom brand: `createTheme('#0B6E4F')` → `<AnvilRoot lightTheme={t.light} darkTheme={t.dark}>` ([theming.md](docs/theming.md)).
|
|
425
|
+
|
|
426
|
+
## Common mistakes
|
|
427
|
+
|
|
428
|
+
| Wrong (other libraries) | Right (AnvilUI) |
|
|
429
|
+
| --- | --- |
|
|
430
|
+
| `<Button variant="outline">` | `<Button fillType="outlined">` |
|
|
431
|
+
| `<Button variant="ghost">` / `variant="link"` | `<Button fillType="text">` |
|
|
432
|
+
| `<Button variant="destructive">` / `color="danger"` | `<Button color="error">` |
|
|
433
|
+
| `<Button variant="secondary">` / `color="secondary"` | `<Button color="container">` or `color="tonal"` |
|
|
434
|
+
| `<Button size="lg">` / `size="sm"` | `size="big"` / `size="small"` |
|
|
435
|
+
| `<Button><Plus /> Add</Button>` | `<Button startIcon="add">Add</Button>` |
|
|
436
|
+
| `<IconButton><DeleteIcon /></IconButton>` | `<IconButton icon="delete" aria-label="Delete" />` |
|
|
437
|
+
| `<IconButton icon="x" size="small" />` | IconButton has no `size`; it's always 40px |
|
|
438
|
+
| `<DialogTrigger asChild><Button>Open</Button></DialogTrigger>` | `<DialogTrigger render={<Button />}>Open</DialogTrigger>` |
|
|
439
|
+
| `<DialogTrigger>Open</DialogTrigger>` expecting a styled button | It's a bare `<button>`; add `render={<Button />}` |
|
|
440
|
+
| `<DialogContent>`, `<DialogHeader>`, `<DialogFooter>` | `<DialogPopup>`, (nothing), `<DialogActions>` |
|
|
441
|
+
| `<Dialog><DialogPortal><DialogOverlay/>…` | `DialogPopup` already includes portal and backdrop |
|
|
442
|
+
| `<Tooltip content="Hi">` / `<TooltipTrigger>` | `<Tooltip label="Hi"><IconButton … /></Tooltip>` |
|
|
443
|
+
| `<Tooltip label="Hi">text</Tooltip>` | One element child: `<Tooltip label="Hi"><span tabIndex={0}>text</span></Tooltip>` |
|
|
444
|
+
| `<Checkbox label="Accept" />` | `<label><Checkbox /> Accept</label>` |
|
|
445
|
+
| `<Switch onChange={(e) => set(e.target.checked)} />` | `<Switch onCheckedChange={set} />` |
|
|
446
|
+
| `<Select onChange={(e) => set(e.target.value)}>` | `<Select onValueChange={set}>` |
|
|
447
|
+
| `<Select><SelectTrigger/><SelectContent>…` | `<Select label="…" items={items}><SelectItem value="a">A</SelectItem></Select>` |
|
|
448
|
+
| `<Select>` without `items` showing `"us"` instead of "United States" | pass `items={{ us: 'United States' }}` (or `[{ value, label }]`) |
|
|
449
|
+
| `<Combobox><ComboboxItem/>…</Combobox>` | `<Combobox items={list}>{(item) => <ComboboxItem key={item} value={item}>{item}</ComboboxItem>}</Combobox>` |
|
|
450
|
+
| `<Tabs><TabsTrigger/><TabsContent/>` | `<Tabs defaultValue="a"><TabsList><TabsTab value="a">A</TabsTab></TabsList><TabsPanel value="a">…</TabsPanel></Tabs>` |
|
|
451
|
+
| `<Tabs>` with string values and no `defaultValue` (nothing selected) | always pass `defaultValue` / `value` |
|
|
452
|
+
| `<Accordion type="single" collapsible defaultValue="a">` | `<Accordion defaultValue={['a']}>` (array; `multiple` for several) |
|
|
453
|
+
| `<DropdownMenu>`, `<DropdownMenuItem onSelect>` | `<Menu>`, `<MenuItem onClick>` |
|
|
454
|
+
| `<MenuSeparator />` | split items into `<MenuGroup>`s |
|
|
455
|
+
| `toast('Saved')`, `<Toaster />`, `<Snackbar open>` | `const snackbar = useSnackbar(); snackbar.show({ message: 'Saved' })` |
|
|
456
|
+
| `snackbar.show({ message, severity: 'success' })` | no severity; put it in the message |
|
|
457
|
+
| `<Typography variant="h4">` | `<Typography type="h4">` |
|
|
458
|
+
| `<AppBar title="Inbox">` / `<AppBar>Inbox</AppBar>` | `<AppBar label="Inbox" />` |
|
|
459
|
+
| `<ListItem>Text</ListItem>` / `primary=` / `secondary=` | `<ListItem label="Text" description="More" />` |
|
|
460
|
+
| `<ListItem onClick={…} />` expecting a button | `<ListItem label="…" render={<button type="button" onClick={…} />} />` |
|
|
461
|
+
| `<CardHeader>`, `<CardFooter>`, `<CardDescription>` | `<CardTitle>`, `<CardActions>`, `<CardContent>` |
|
|
462
|
+
| `<Badge badgeContent={3}>` | `<Badge count={3}>` |
|
|
463
|
+
| `<Progress value={undefined} />` for loading / `<Spinner />` | `<Progress value={null} aria-label="Loading" />` (`type="circular"` for a ring) |
|
|
464
|
+
| `<DateInput value={new Date()} />` | `value="2026-11-06"` (`"YYYY-MM-DD"` string) |
|
|
465
|
+
| `<TimePicker value="7:30 PM" />` | `value="19:30"` |
|
|
466
|
+
| `<Slider onValueChange={(e) => …e.target.value} />` | `onValueChange={(value) => …}` gets the number |
|
|
467
|
+
| `<Input error helperText="…" />` | `<Field><Input … /><FieldDescription>…</FieldDescription><FieldError /></Field>` |
|
|
468
|
+
| `<Button>` inside `<form>` not submitting | `<Button type="submit">` (default is `type="button"`) |
|
|
469
|
+
| `<ThemeProvider theme={…}>` | `<AnvilRoot lightTheme={…} darkTheme={…}>` |
|
|
470
|
+
| `useSnackbar()` / `useAnvil()` in the component that renders `<AnvilRoot>` | call them in a child component |
|
|
471
|
+
| `import { Button } from 'anvilui/button'` | `import { Button } from 'anvilui'` |
|
|
472
|
+
| Forgetting `import 'anvilui/styles.css'` | import it once in the entry file |
|
|
473
|
+
| `<Stack gap={2}>`, `<Box sx={…}>` | `<div style={{ display: 'flex', gap: 'var(--avl-spacing-x2)' }}>` |
|
|
474
|
+
|
|
475
|
+
## Errors you may see
|
|
476
|
+
|
|
477
|
+
In development, AnvilUI logs `[anvilui] …` errors with a fix and a doc path for: a missing stylesheet, components outside `AnvilRoot`, `asChild`, `variant` on Button/IconButton/Typography, `label` on Checkbox/Switch/Radio, missing `aria-label`, non-function Combobox/Search children, a Tooltip without one element child, and parts outside their parent. Base UI's own errors look like `Base UI: MenuRootContext is missing. Menu parts must be placed within <Menu.Root>`. `<Menu.Root>` there means AnvilUI's `<Menu>` (likewise `<Tabs.Root>` → `<Tabs>`, `<Dialog.Root>` → `<Dialog>`).
|
|
478
|
+
|
|
479
|
+
## More
|
|
480
|
+
|
|
481
|
+
- Routing index of all pages: [docs/llms-index.md](docs/llms-index.md)
|
|
482
|
+
- Inherited Base UI props for any part: `node_modules/@base-ui/react/docs/react/components/<name>.md`
|
|
483
|
+
- Types with JSDoc on every prop: `node_modules/anvilui/dist/index.d.ts`
|
package/README.md
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
# anvilui
|
|
2
2
|
|
|
3
|
-
React components built on [Base UI](https://base-ui.com).
|
|
3
|
+
React components built on [Base UI](https://base-ui.com). Requires React 19.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install anvilui
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Using with AI coding agents
|
|
10
|
+
|
|
11
|
+
AnvilUI is new, so AI models don't know its API and will guess it from other libraries. The package ships accurate, version-matched docs for agents: [`AGENTS.md`](AGENTS.md) plus one page per component in [`docs/`](docs/llms-index.md).
|
|
12
|
+
|
|
13
|
+
Tell your agent to read them. Paste this into your project's `AGENTS.md`, `CLAUDE.md`, `.cursorrules` or `.github/copilot-instructions.md`:
|
|
14
|
+
|
|
15
|
+
```md
|
|
16
|
+
## AnvilUI
|
|
17
|
+
|
|
18
|
+
This project uses the `anvilui` React component library. Its API differs from shadcn/ui, Radix and MUI, so don't guess it. Before writing or changing UI code that uses it, read `node_modules/anvilui/AGENTS.md`, then the page for each component you use in `node_modules/anvilui/docs/` (index: `node_modules/anvilui/docs/llms-index.md`). These docs match the installed version; prefer them over memory.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or run this once in your project, which appends that note to whichever of those files exist (or creates `AGENTS.md`):
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx anvilui setup-agents
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
In development, mistakes like a missing stylesheet, `asChild`, `variant` or a missing `aria-label` log an `[anvilui]` error that shows the fix and names the doc page, so pasting the console output back to your agent is enough. These checks are removed from production builds.
|
|
4
28
|
|
|
5
29
|
## Setup
|
|
6
30
|
|
|
31
|
+
### 1. Load the fonts
|
|
32
|
+
|
|
33
|
+
AnvilUI does not load any fonts by itself. The default theme uses Google Sans and Google Sans Code - if you intend to use them, add this to your HTML `<head>`:
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
37
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
38
|
+
<link
|
|
39
|
+
rel="stylesheet"
|
|
40
|
+
href="https://fonts.googleapis.com/css2?family=Google+Sans+Code:ital,wght,MONO@0,300..800,1;1,300..800,1&family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&display=swap"
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To use different fonts, pass `tokens.font` to `AnvilRoot` and load the font yourself instead of Google Sans.
|
|
45
|
+
|
|
46
|
+
### 2. Wrap your app in `AnvilRoot`
|
|
47
|
+
|
|
7
48
|
```tsx
|
|
8
49
|
import { AnvilRoot, Button } from 'anvilui'
|
|
9
50
|
import 'anvilui/styles.css'
|
|
@@ -17,9 +58,35 @@ export function App() {
|
|
|
17
58
|
}
|
|
18
59
|
```
|
|
19
60
|
|
|
20
|
-
- **Fonts:** the base tokens use Google Sans and Google Sans Code, which the library doesn't load. Add them yourself (e.g. a Google Fonts `<link>`), or pass your own `tokens.font` to `AnvilRoot`.
|
|
21
61
|
- **Icons:** components import `material-symbols/rounded.css`, so your bundler needs to handle CSS and font files from `node_modules` (Vite, Next and webpack setups do by default).
|
|
22
|
-
- Styles only apply inside `AnvilRoot`; nothing outside it is touched.
|
|
62
|
+
- Styles only apply inside `AnvilRoot`; nothing outside it is touched. To theme the whole page, give it a `className` that fills the viewport (`min-height: 100vh`).
|
|
63
|
+
|
|
64
|
+
## Color mode and themes
|
|
65
|
+
|
|
66
|
+
The color mode is `'light'`, `'dark'` or `'system'` (the default, which follows the OS setting live). Pass `storageKey="my-app-color-mode"` to remember the user's choice; with server rendering the saved mode is applied before the first paint, so there's no flash. Read or change the mode anywhere inside with `useAnvil()`:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
// colorMode is what's shown ('light' | 'dark'); colorModeSetting may be 'system'
|
|
70
|
+
const { colorMode, colorModeSetting, setColorMode } = useAnvil()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
To switch themes at runtime, keep them in state and pass them as `lightTheme` / `darkTheme`.
|
|
74
|
+
|
|
75
|
+
## Making a theme
|
|
76
|
+
|
|
77
|
+
Generate a light and a dark theme from one color, or from the main colors of an image:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { createTheme, createThemeFromImage } from 'anvilui'
|
|
81
|
+
|
|
82
|
+
const theme = createTheme('#0B6E4F') // optional: { tonal: '#…' }
|
|
83
|
+
// or, in the browser: from an <img>, a File/Blob, or a CORS-enabled URL
|
|
84
|
+
const theme = await createThemeFromImage(file)
|
|
85
|
+
|
|
86
|
+
<AnvilRoot lightTheme={theme.light} darkTheme={theme.dark}>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Each color keeps the lightness of the base theme, so text stays readable; only the hue and colorfulness change. Error, warning and success colors stay the same. Tweak any role by spreading: `{ ...theme.light, primary: '#…' }`.
|
|
23
90
|
|
|
24
91
|
## Morphing between views
|
|
25
92
|
|