anvilui 0.1.0 → 0.3.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 +60 -40
- 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 +48 -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 +39 -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 +14 -1
- package/dist/components/Input/Input.d.ts +14 -3
- 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 +33 -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 +12 -2
- package/dist/components/RadioGroup/RadioGroup.d.ts +14 -2
- package/dist/components/Search/Search.d.ts +55 -0
- package/dist/components/Select/Select.d.ts +21 -4
- package/dist/components/Skeleton/Skeleton.d.ts +20 -0
- package/dist/components/Slider/Slider.d.ts +7 -1
- package/dist/components/Snackbar/Snackbar.d.ts +7 -2
- package/dist/components/SplitButton/SplitButton.d.ts +13 -0
- package/dist/components/SquigglyWave/SquigglyWave.d.ts +26 -4
- 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 +14 -3
- package/dist/components/TimePicker/TimePicker.d.ts +47 -0
- package/dist/components/Toggle/Toggle.d.ts +42 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +16 -4
- 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 +3365 -654
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1443 -367
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +50 -4
- package/dist/index.js +3362 -667
- 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 +13 -8
- package/dist/tokens/baseTokens.d.ts +4 -0
- package/dist/tokens/types.d.ts +34 -0
- package/dist/utils.d.ts +4 -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 +73 -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 +42 -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 +55 -0
- package/docs/icons.md +38 -0
- package/docs/input.md +51 -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 +54 -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 +64 -0
- package/docs/search.md +77 -0
- package/docs/select.md +65 -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 +183 -0
- package/docs/time-picker.md +39 -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/docs/checkbox.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
A checkbox. **No `label` prop**: wrap it in a `<label>`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Checkbox } from 'anvilui'
|
|
7
|
+
import type { CheckboxProps } from 'anvilui' // = Base UI Checkbox.Root props
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Props (Base UI Checkbox.Root)
|
|
11
|
+
|
|
12
|
+
| Prop | Type | Default | Description |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `checked` / `defaultChecked` | `boolean` | `false` | |
|
|
15
|
+
| `onCheckedChange` | `(checked: boolean, details) => void` | | Not `onChange`. |
|
|
16
|
+
| `indeterminate` | `boolean` | `false` | Shows a dash. |
|
|
17
|
+
| `name`, `value` | `string` | | For forms. |
|
|
18
|
+
| `required`, `disabled`, `readOnly` | `boolean` | `false` | |
|
|
19
|
+
|
|
20
|
+
Base UI docs: `node_modules/@base-ui/react/docs/react/components/checkbox.md`.
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { useState } from 'react'
|
|
24
|
+
import { Checkbox } from 'anvilui'
|
|
25
|
+
|
|
26
|
+
export function Example() {
|
|
27
|
+
const [agreed, setAgreed] = useState(false)
|
|
28
|
+
return (
|
|
29
|
+
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
|
30
|
+
<Checkbox checked={agreed} onCheckedChange={setAgreed} />I agree to
|
|
31
|
+
the terms
|
|
32
|
+
</label>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
In a list row, put it in `ListItem`'s `start` with `render={<label />}` so the whole row toggles it ([list.md](list.md)).
|
package/docs/chip.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Chip, FilterChip, InputChip
|
|
2
|
+
|
|
3
|
+
Compact elements for actions, filters and entered values.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Chip, FilterChip, InputChip } from 'anvilui'
|
|
7
|
+
import type { ChipProps, FilterChipProps, InputChipProps } from 'anvilui'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
| Component | Is | Own props |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| `Chip` | a button (suggestion / quick action) | `startIcon?: MaterialSymbol`; Base UI Button props |
|
|
13
|
+
| `FilterChip` | an on/off toggle with a checkmark | `pressed` / `defaultPressed` / `onPressedChange(pressed, details)`; Base UI Toggle props |
|
|
14
|
+
| `InputChip` | a removable value (`<span>`) | `onRemove: () => void` (required), `removeLabel?: string` (default `'Remove'`), `startIcon?`, `disabled?` |
|
|
15
|
+
|
|
16
|
+
Chips have no `color`, `fillType` or `size` props.
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { useState } from 'react'
|
|
20
|
+
import { Chip, FilterChip, InputChip } from 'anvilui'
|
|
21
|
+
|
|
22
|
+
export function Example() {
|
|
23
|
+
const [vegan, setVegan] = useState(false)
|
|
24
|
+
const [tags, setTags] = useState(['react', 'design'])
|
|
25
|
+
return (
|
|
26
|
+
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
|
27
|
+
<Chip startIcon="event" onClick={() => console.log('added')}>
|
|
28
|
+
Add to calendar
|
|
29
|
+
</Chip>
|
|
30
|
+
<FilterChip pressed={vegan} onPressedChange={setVegan}>
|
|
31
|
+
Vegan
|
|
32
|
+
</FilterChip>
|
|
33
|
+
{tags.map((tag) => (
|
|
34
|
+
<InputChip
|
|
35
|
+
key={tag}
|
|
36
|
+
removeLabel={`Remove ${tag}`}
|
|
37
|
+
onRemove={() => setTags(tags.filter((t) => t !== tag))}
|
|
38
|
+
>
|
|
39
|
+
{tag}
|
|
40
|
+
</InputChip>
|
|
41
|
+
))}
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `InputChip` animates out, then calls `onRemove`. Remove the item from your state there; if you keep it, the chip reappears.
|
|
48
|
+
- Lay chips out in a flex row with `gap`.
|
package/docs/combobox.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Combobox, ComboboxItem
|
|
2
|
+
|
|
3
|
+
A text field that filters a list as you type and picks one item. **Children are a render function**, and `items` is the list to filter.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Combobox, ComboboxItem } from 'anvilui'
|
|
7
|
+
import type { ComboboxProps, ComboboxItemProps } from 'anvilui'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Combobox props
|
|
11
|
+
|
|
12
|
+
| Prop | Type | Default | Description |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `items` | `readonly Item[]` | | The options. |
|
|
15
|
+
| `children` | `(item: Item, index: number) => ReactNode` | required | Renders one `ComboboxItem`. |
|
|
16
|
+
| `value` / `defaultValue` | `Item \| null` | | The picked item. |
|
|
17
|
+
| `onValueChange` | `(item: Item \| null, details) => void` | | |
|
|
18
|
+
| `inputValue` / `onInputValueChange` | `string` / `(text, details) => void` | | The typed text. |
|
|
19
|
+
| `itemToStringLabel` | `(item) => string` | | Required for object items. |
|
|
20
|
+
| `label` | `ReactNode` | | Floating label. |
|
|
21
|
+
| `placeholder` | `string` | | |
|
|
22
|
+
| `empty` | `ReactNode` | | Shown when nothing matches; without it the popup hides. |
|
|
23
|
+
| `size` | `'small' \| 'normal'` | `'normal'` | |
|
|
24
|
+
| `className`, `style` | | | On the field wrapper. |
|
|
25
|
+
| `ref`, `id`, `aria-*`, `data-*` | | | On the text `<input>`. |
|
|
26
|
+
| `name`, `disabled`, `required`, `filter`, `limit` | | | Base UI Combobox.Root props. |
|
|
27
|
+
|
|
28
|
+
## ComboboxItem props
|
|
29
|
+
|
|
30
|
+
`value: Item` (required), `children` (label), `disabled`.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { useState } from 'react'
|
|
34
|
+
import { Combobox, ComboboxItem } from 'anvilui'
|
|
35
|
+
|
|
36
|
+
type User = { id: number; name: string }
|
|
37
|
+
const users: User[] = [
|
|
38
|
+
{ id: 1, name: 'Ada Lovelace' },
|
|
39
|
+
{ id: 2, name: 'Alan Turing' },
|
|
40
|
+
]
|
|
41
|
+
const fruits = ['Apple', 'Banana', 'Cherry']
|
|
42
|
+
|
|
43
|
+
export function Example() {
|
|
44
|
+
const [user, setUser] = useState<User | null>(null)
|
|
45
|
+
return (
|
|
46
|
+
<div style={{ display: 'grid', gap: 16, width: 320 }}>
|
|
47
|
+
<Combobox label="Fruit" items={fruits} empty="No fruit found">
|
|
48
|
+
{(fruit: string) => (
|
|
49
|
+
<ComboboxItem key={fruit} value={fruit}>
|
|
50
|
+
{fruit}
|
|
51
|
+
</ComboboxItem>
|
|
52
|
+
)}
|
|
53
|
+
</Combobox>
|
|
54
|
+
|
|
55
|
+
<Combobox
|
|
56
|
+
label="Assignee"
|
|
57
|
+
items={users}
|
|
58
|
+
value={user}
|
|
59
|
+
onValueChange={setUser}
|
|
60
|
+
itemToStringLabel={(u: User) => u.name}
|
|
61
|
+
>
|
|
62
|
+
{(u: User) => (
|
|
63
|
+
<ComboboxItem key={u.id} value={u}>
|
|
64
|
+
{u.name}
|
|
65
|
+
</ComboboxItem>
|
|
66
|
+
)}
|
|
67
|
+
</Combobox>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Base UI docs: `node_modules/@base-ui/react/docs/react/components/combobox.md`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Composition: `render`, refs, className
|
|
2
|
+
|
|
3
|
+
AnvilUI is built on [Base UI](https://base-ui.com). Base UI patterns apply everywhere.
|
|
4
|
+
|
|
5
|
+
## `render` instead of `asChild`
|
|
6
|
+
|
|
7
|
+
There is **no `asChild`** prop. To render a part as another element or component, pass `render`:
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import {
|
|
11
|
+
Button,
|
|
12
|
+
Dialog,
|
|
13
|
+
DialogPopup,
|
|
14
|
+
DialogTitle,
|
|
15
|
+
DialogTrigger,
|
|
16
|
+
IconButton,
|
|
17
|
+
Menu,
|
|
18
|
+
MenuItem,
|
|
19
|
+
MenuPopup,
|
|
20
|
+
MenuTrigger,
|
|
21
|
+
} from 'anvilui'
|
|
22
|
+
|
|
23
|
+
export function Example() {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<Dialog>
|
|
27
|
+
<DialogTrigger render={<Button />}>Open</DialogTrigger>
|
|
28
|
+
<DialogPopup>
|
|
29
|
+
<DialogTitle>Hi</DialogTitle>
|
|
30
|
+
</DialogPopup>
|
|
31
|
+
</Dialog>
|
|
32
|
+
|
|
33
|
+
<Menu>
|
|
34
|
+
<MenuTrigger
|
|
35
|
+
render={<IconButton icon="more_vert" aria-label="More" />}
|
|
36
|
+
/>
|
|
37
|
+
<MenuPopup>
|
|
38
|
+
<MenuItem>Rename</MenuItem>
|
|
39
|
+
</MenuPopup>
|
|
40
|
+
</Menu>
|
|
41
|
+
|
|
42
|
+
{/* A button that's a link: not a <button>, so nativeButton={false} */}
|
|
43
|
+
<Button render={<a href="/settings" />} nativeButton={false}>
|
|
44
|
+
Settings
|
|
45
|
+
</Button>
|
|
46
|
+
</>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- `render` merges props, `className` and `ref` into the element you pass.
|
|
52
|
+
- All Trigger and Close parts (`DialogTrigger`, `DialogClose`, `PopoverTrigger`, `PopoverClose`, `MenuTrigger`, `BottomSheetTrigger`, `BottomSheetClose`, `NavigationDrawerTrigger`) render a **bare, unstyled `<button>`** unless you pass `render`.
|
|
53
|
+
- When `render` swaps a button for a non-button element (`<a>`, `<div>`), add `nativeButton={false}`.
|
|
54
|
+
- Router links: `render={<Link to="/x" />}` (React Router) or `render={<Link href="/x" />}` (Next.js) on nav items, `ListItem`, `PreviewCardTrigger`, `Button` (+ `nativeButton={false}`).
|
|
55
|
+
|
|
56
|
+
## Refs and props
|
|
57
|
+
|
|
58
|
+
- Every component takes `ref` (React 19 `ref` prop) and passes unknown props to its main element.
|
|
59
|
+
- `className` is merged with the library's classes, never replaced. On Base UI-based parts it can also be a function of state: `className={(state) => state.open ? 'open' : ''}`.
|
|
60
|
+
- **Field-like components split their props** (`Input`, `Textarea`, `DateInput`, `Select`, `Combobox`, `Search`, `TimePicker`, `PinInput`): `className` and `style` go on the outer wrapper, so width and margins work; `ref`, `id`, `aria-*` and `data-*` go on the control. The control is the `<input>` / `<textarea>`, or the button for `Select` and `TimePicker`. `PinInput`'s `ref` is its group of boxes.
|
|
61
|
+
- `Tooltip` puts `className` on the bubble. `FABMenu` puts it on the FAB.
|
|
62
|
+
|
|
63
|
+
## State props
|
|
64
|
+
|
|
65
|
+
Stateful components work controlled or uncontrolled, with Base UI's names:
|
|
66
|
+
|
|
67
|
+
| State | Props | Callback signature |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| value | `value` / `defaultValue` / `onValueChange` | `(value, eventDetails) => void`. The **value**, not an event. |
|
|
70
|
+
| checked | `checked` / `defaultChecked` / `onCheckedChange` | `(checked: boolean, eventDetails) => void` (Checkbox, Switch) |
|
|
71
|
+
| pressed | `pressed` / `defaultPressed` / `onPressedChange` | `(pressed: boolean, eventDetails) => void` (Toggle, FilterChip) |
|
|
72
|
+
| open | `open` / `defaultOpen` / `onOpenChange` | `(open: boolean, eventDetails) => void` (Dialog, Popover, Menu, Select, …) |
|
|
73
|
+
|
|
74
|
+
Because the value comes first, a `useState` setter can be passed directly: `onValueChange={setTab}`, `onCheckedChange={setEnabled}`.
|
|
75
|
+
|
|
76
|
+
There is no `onChange` on Checkbox, Switch, Select, Slider, Tabs, RadioGroup or ToggleGroup. `Input` and `Textarea` take both native `onChange` (an event) and `onValueChange` (a string).
|
|
77
|
+
|
|
78
|
+
## Base UI docs for inherited props
|
|
79
|
+
|
|
80
|
+
Each page lists AnvilUI's own props. Parts also take every prop of the Base UI part they wrap. Those are documented in the installed Base UI package: `node_modules/@base-ui/react/docs/react/components/<name>.md`.
|
package/docs/confetti.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# useConfetti
|
|
2
|
+
|
|
3
|
+
A hook that returns a function firing a burst of confetti in the theme's colors. Does nothing with reduced motion on.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { useConfetti } from 'anvilui'
|
|
7
|
+
import type { ConfettiOptions, ConfettiOrigin } from 'anvilui'
|
|
8
|
+
|
|
9
|
+
const fire = useConfetti()
|
|
10
|
+
fire(origin?: Element | { x: number; y: number }, options?: ConfettiOptions): void
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
| Option | Type | Default |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `count` | `number` | `80` |
|
|
16
|
+
| `angle` | `number` (degrees, 0 = up) | `0` |
|
|
17
|
+
| `spread` | `number` (degrees) | `70` |
|
|
18
|
+
| `power` | `number` | `1` |
|
|
19
|
+
| `colors` | `ComponentColor[]` | `['primary', 'tonal', 'success', 'warning', 'error']` |
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Button, useConfetti } from 'anvilui'
|
|
23
|
+
|
|
24
|
+
export function Celebrate() {
|
|
25
|
+
const fire = useConfetti()
|
|
26
|
+
return <Button onClick={(e) => fire(e.currentTarget)}>Celebrate</Button>
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Without an origin it bursts from the bottom middle of the screen. Must be inside `AnvilRoot`.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ContextMenu
|
|
2
|
+
|
|
3
|
+
A menu that opens at the pointer on right-click (long-press on touch). Content uses `Menu`'s parts.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { ContextMenu, ContextMenuTrigger, MenuPopup, MenuItem } from 'anvilui'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
| Part | Renders | Notes |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `ContextMenu` | nothing (state) | `open` / `defaultOpen` / `onOpenChange` |
|
|
12
|
+
| `ContextMenuTrigger` | `<div>` | The area that responds to right-click; `render` to change the element. |
|
|
13
|
+
| `MenuPopup`, `MenuItem`, `MenuGroup`, `MenuSubmenu` | | Same as [Menu](menu.md). |
|
|
14
|
+
|
|
15
|
+
Right-click and long-press only: it can't be opened from the keyboard. Give keyboard users the same actions another way, e.g. a ⋮ [Menu](menu.md) button on each item.
|
|
16
|
+
|
|
17
|
+
Any content works inside the trigger, including `CardTitle` / `CardContent` when it renders a `Card`.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import {
|
|
21
|
+
Card,
|
|
22
|
+
CardContent,
|
|
23
|
+
ContextMenu,
|
|
24
|
+
ContextMenuTrigger,
|
|
25
|
+
MenuItem,
|
|
26
|
+
MenuPopup,
|
|
27
|
+
} from 'anvilui'
|
|
28
|
+
|
|
29
|
+
export function Example() {
|
|
30
|
+
return (
|
|
31
|
+
<ContextMenu>
|
|
32
|
+
<ContextMenuTrigger render={<Card />}>
|
|
33
|
+
<CardContent>Right-click this card</CardContent>
|
|
34
|
+
</ContextMenuTrigger>
|
|
35
|
+
<MenuPopup>
|
|
36
|
+
<MenuItem startIcon="content_copy">Copy</MenuItem>
|
|
37
|
+
<MenuItem startIcon="delete">Delete</MenuItem>
|
|
38
|
+
</MenuPopup>
|
|
39
|
+
</ContextMenu>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# DateInput
|
|
2
|
+
|
|
3
|
+
A text field for a date, typed in the user's locale format or picked from a calendar popup. **The value is a `"YYYY-MM-DD"` string, not a `Date`.**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { DateInput } from 'anvilui'
|
|
7
|
+
import type { DateInputProps } from 'anvilui'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
| Prop | Type | Default | Description |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| `value` / `defaultValue` | `string \| null` | `null` | `"YYYY-MM-DD"`. |
|
|
13
|
+
| `onValueChange` | `(value: string \| null) => void` | | `null` when cleared. |
|
|
14
|
+
| `label` | `ReactNode` | | Either this or `aria-label`. |
|
|
15
|
+
| `size` | `'small' \| 'normal'` | `'normal'` | |
|
|
16
|
+
| `name` | `string` | | Submits `"YYYY-MM-DD"` with the form (also when the name comes from a `Field`). |
|
|
17
|
+
| `className`, `style` | | | On the wrapper; `ref` and other props go on the `<input>`. |
|
|
18
|
+
| `disabled`, `required`, `id`, `onBlur` | | | On the `<input>`. |
|
|
19
|
+
|
|
20
|
+
No `min` / `max` / disabled dates.
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { useState } from 'react'
|
|
24
|
+
import { DateInput } from 'anvilui'
|
|
25
|
+
|
|
26
|
+
export function Example() {
|
|
27
|
+
const [start, setStart] = useState<string | null>('2026-11-06')
|
|
28
|
+
return (
|
|
29
|
+
<form>
|
|
30
|
+
<DateInput
|
|
31
|
+
label="Start date"
|
|
32
|
+
value={start}
|
|
33
|
+
onValueChange={setStart}
|
|
34
|
+
name="start"
|
|
35
|
+
/>
|
|
36
|
+
{/* Submits start=2026-11-06, not the text shown in the field */}
|
|
37
|
+
</form>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Convert: `new Date(value + 'T00:00')` for a local `Date`; back with `date.toISOString().slice(0, 10)` (UTC) or format it yourself.
|
package/docs/dialog.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Dialog
|
|
2
|
+
|
|
3
|
+
A modal dialog.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {
|
|
7
|
+
Dialog,
|
|
8
|
+
DialogTrigger,
|
|
9
|
+
DialogPopup,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
DialogDescription,
|
|
12
|
+
DialogActions,
|
|
13
|
+
DialogClose,
|
|
14
|
+
} from 'anvilui'
|
|
15
|
+
import type {
|
|
16
|
+
DialogProps,
|
|
17
|
+
DialogTriggerProps,
|
|
18
|
+
DialogPopupProps,
|
|
19
|
+
DialogTitleProps,
|
|
20
|
+
DialogDescriptionProps,
|
|
21
|
+
DialogActionsProps,
|
|
22
|
+
DialogCloseProps,
|
|
23
|
+
} from 'anvilui'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Parts
|
|
27
|
+
|
|
28
|
+
| Part | Renders | Notes |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `Dialog` | nothing (state) | `open` / `defaultOpen` / `onOpenChange(open, details)`, `modal` (default `true`), `disablePointerDismissal`, `morph` |
|
|
31
|
+
| `DialogTrigger` | bare `<button>` | `render={<Button />}` to style it. Optional when controlled. |
|
|
32
|
+
| `DialogPopup` | portal + backdrop + the dialog box | Put everything else inside. |
|
|
33
|
+
| `DialogTitle` | `<h2>` | Required for accessibility. |
|
|
34
|
+
| `DialogDescription` | `<p>` | |
|
|
35
|
+
| `DialogActions` | `<div>` | The button row at the bottom (the "footer"). |
|
|
36
|
+
| `DialogClose` | bare `<button>` | `render={<Button fillType="text" />}`. |
|
|
37
|
+
|
|
38
|
+
There is **no** `DialogContent`, `DialogOverlay`, `DialogPortal`, `DialogHeader` or `DialogFooter`.
|
|
39
|
+
|
|
40
|
+
`morph` (boolean, default `false`): the dialog grows out of its trigger, best when the trigger is a surface like a clickable `Card`.
|
|
41
|
+
|
|
42
|
+
## Example
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useState } from 'react'
|
|
46
|
+
import {
|
|
47
|
+
Button,
|
|
48
|
+
Dialog,
|
|
49
|
+
DialogActions,
|
|
50
|
+
DialogClose,
|
|
51
|
+
DialogDescription,
|
|
52
|
+
DialogPopup,
|
|
53
|
+
DialogTitle,
|
|
54
|
+
DialogTrigger,
|
|
55
|
+
Input,
|
|
56
|
+
} from 'anvilui'
|
|
57
|
+
|
|
58
|
+
export function DeleteDialog({ onDelete }: { onDelete: () => void }) {
|
|
59
|
+
return (
|
|
60
|
+
<Dialog>
|
|
61
|
+
<DialogTrigger render={<Button color="error" startIcon="delete" />}>
|
|
62
|
+
Delete
|
|
63
|
+
</DialogTrigger>
|
|
64
|
+
<DialogPopup>
|
|
65
|
+
<DialogTitle>Delete project?</DialogTitle>
|
|
66
|
+
<DialogDescription>This can't be undone.</DialogDescription>
|
|
67
|
+
<DialogActions>
|
|
68
|
+
<DialogClose render={<Button fillType="text" />}>
|
|
69
|
+
Cancel
|
|
70
|
+
</DialogClose>
|
|
71
|
+
<DialogClose
|
|
72
|
+
render={<Button color="error" />}
|
|
73
|
+
onClick={onDelete}
|
|
74
|
+
>
|
|
75
|
+
Delete
|
|
76
|
+
</DialogClose>
|
|
77
|
+
</DialogActions>
|
|
78
|
+
</DialogPopup>
|
|
79
|
+
</Dialog>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Controlled: open it from anywhere, close it after an async action
|
|
84
|
+
export function RenameDialog() {
|
|
85
|
+
const [open, setOpen] = useState(false)
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<Button onClick={() => setOpen(true)}>Rename</Button>
|
|
89
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
90
|
+
<DialogPopup>
|
|
91
|
+
<DialogTitle>Rename</DialogTitle>
|
|
92
|
+
<Input label="Name" autoFocus />
|
|
93
|
+
<DialogActions>
|
|
94
|
+
<DialogClose render={<Button fillType="text" />}>
|
|
95
|
+
Cancel
|
|
96
|
+
</DialogClose>
|
|
97
|
+
<Button onClick={() => setOpen(false)}>Save</Button>
|
|
98
|
+
</DialogActions>
|
|
99
|
+
</DialogPopup>
|
|
100
|
+
</Dialog>
|
|
101
|
+
</>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Opening from a `MenuItem`: control the dialog (`open` state) and set it in the item's `onClick`; don't nest the Dialog inside the menu popup. Base UI docs: `node_modules/@base-ui/react/docs/react/components/dialog.md`.
|
package/docs/divider.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Divider
|
|
2
|
+
|
|
3
|
+
A thin line between groups of content. Renders a separator `<div>`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Divider } from 'anvilui'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
| Prop | Type | Default | Description |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Vertical stretches to its flex row's height. |
|
|
12
|
+
| `label` | `ReactNode` | | Text in the middle ("or"). |
|
|
13
|
+
| `squiggly` | `boolean` | `false` | Wavy line. |
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Divider } from 'anvilui'
|
|
17
|
+
|
|
18
|
+
export function Example() {
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<Divider />
|
|
22
|
+
<Divider label="or" />
|
|
23
|
+
<div style={{ display: 'flex', gap: 8, height: 24 }}>
|
|
24
|
+
<span>Left</span>
|
|
25
|
+
<Divider orientation="vertical" />
|
|
26
|
+
<span>Right</span>
|
|
27
|
+
</div>
|
|
28
|
+
</>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
package/docs/fab-menu.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# FABMenu
|
|
2
|
+
|
|
3
|
+
A FAB that opens a stack of labeled actions. You position it.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { FABMenu, FABMenuItem } from 'anvilui'
|
|
7
|
+
import type { FABMenuProps, FABMenuItemProps } from 'anvilui'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## FABMenu props
|
|
11
|
+
|
|
12
|
+
| Prop | Type | Default | Description |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `icon` | `MaterialSymbol` | required | Icon while closed. |
|
|
15
|
+
| `aria-label` | `string` | required | |
|
|
16
|
+
| `children` | `FABMenuItem`s | required | |
|
|
17
|
+
| `closeIcon` | `MaterialSymbol` | `'close'` | Icon while open. |
|
|
18
|
+
| `color` | `ComponentColor` | `'primary'` | Items use the role's container shade. |
|
|
19
|
+
| `fillType` | `'filled' \| 'outlined' \| 'text'` | `'filled'` | |
|
|
20
|
+
| `side` | `'top' \| 'bottom' \| 'left' \| 'right' \| 'inline-start' \| 'inline-end'` | `'top'` | |
|
|
21
|
+
| `align` | `'start' \| 'center' \| 'end'` | `'end'` | |
|
|
22
|
+
| `sticky` | `boolean` | `true` | |
|
|
23
|
+
| `className` | `string` | | Goes on the FAB. |
|
|
24
|
+
| `open` / `defaultOpen` / `onOpenChange` | | | Base UI Menu.Root state. |
|
|
25
|
+
|
|
26
|
+
## FABMenuItem props
|
|
27
|
+
|
|
28
|
+
`icon: MaterialSymbol` (required), `children` (label, required), `color?: ComponentColor`, `onClick`, `disabled`, plus Base UI Menu.Item props.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { FABMenu, FABMenuItem } from 'anvilui'
|
|
32
|
+
|
|
33
|
+
export function Example() {
|
|
34
|
+
return (
|
|
35
|
+
<div style={{ position: 'fixed', insetInlineEnd: 16, bottom: 16 }}>
|
|
36
|
+
<FABMenu icon="add" aria-label="Create">
|
|
37
|
+
<FABMenuItem
|
|
38
|
+
icon="description"
|
|
39
|
+
onClick={() => console.log('doc')}
|
|
40
|
+
>
|
|
41
|
+
Document
|
|
42
|
+
</FABMenuItem>
|
|
43
|
+
<FABMenuItem
|
|
44
|
+
icon="folder"
|
|
45
|
+
onClick={() => console.log('folder')}
|
|
46
|
+
>
|
|
47
|
+
Folder
|
|
48
|
+
</FABMenuItem>
|
|
49
|
+
</FABMenu>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Needs `AnvilRoot` (the items portal into it).
|
package/docs/fab.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# FAB
|
|
2
|
+
|
|
3
|
+
The floating action button: the screen's main action. You position it (usually `position: fixed`, bottom-end).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { FAB } from 'anvilui'
|
|
7
|
+
import type { FABProps } from 'anvilui'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Props
|
|
11
|
+
|
|
12
|
+
| Prop | Type | Default | Description |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `icon` | `MaterialSymbol` | required | |
|
|
15
|
+
| `label` | `string` | | Visible text: makes it an extended FAB. |
|
|
16
|
+
| `aria-label` | `string` | required without `label` | |
|
|
17
|
+
| `size` | `'small' \| 'normal' \| 'big'` | `'normal'` | 40, 56 or 96px. |
|
|
18
|
+
| `color` | `ComponentColor` | `'primary'` | |
|
|
19
|
+
| `fillType` | `'filled' \| 'outlined' \| 'text'` | `'filled'` | |
|
|
20
|
+
| `sticky` | `boolean` | `true` | Drifts toward a nearby mouse cursor. |
|
|
21
|
+
|
|
22
|
+
Takes no children. Also Base UI Button props.
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { FAB } from 'anvilui'
|
|
26
|
+
|
|
27
|
+
export function Example() {
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<FAB
|
|
31
|
+
icon="edit"
|
|
32
|
+
aria-label="Compose"
|
|
33
|
+
style={{ position: 'fixed', insetInlineEnd: 16, bottom: 16 }}
|
|
34
|
+
/>
|
|
35
|
+
<FAB icon="add" label="New task" color="tonal" />
|
|
36
|
+
</>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`sticky` only adds a small `translate` toward the cursor, so it works with any `position` you set.
|
|
42
|
+
|
|
43
|
+
For a FAB that opens several actions, use [FABMenu](fab-menu.md).
|
package/docs/field.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Field, FieldDescription, FieldError
|
|
2
|
+
|
|
3
|
+
Wraps one control to add helper text, an error message and validation. The control keeps its own `label`. **There is no `FieldLabel`.**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Field, FieldDescription, FieldError } from 'anvilui'
|
|
7
|
+
import type {
|
|
8
|
+
FieldProps,
|
|
9
|
+
FieldDescriptionProps,
|
|
10
|
+
FieldErrorProps,
|
|
11
|
+
} from 'anvilui'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Field props (Base UI Field.Root)
|
|
15
|
+
|
|
16
|
+
| Prop | Type | Default | Description |
|
|
17
|
+
| --- | --- | --- | --- |
|
|
18
|
+
| `name` | `string` | | Form field name (overrides the control's). |
|
|
19
|
+
| `validate` | `(value, formValues) => string \| string[] \| null \| Promise<…>` | | Return an error message, or `null` when valid. |
|
|
20
|
+
| `validationMode` | `'onSubmit' \| 'onBlur' \| 'onChange'` | `'onSubmit'` | When to validate. Outside a `<form>`, use `onBlur` or `onChange`. |
|
|
21
|
+
| `invalid` | `boolean` | | Force the invalid state (e.g. a server error). |
|
|
22
|
+
| `disabled` | `boolean` | | Disables the control. |
|
|
23
|
+
|
|
24
|
+
## FieldError props
|
|
25
|
+
|
|
26
|
+
| Prop | Type | Description |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `match` | `boolean \| keyof ValidityState` | Show only for one problem (`'valueMissing'`, `'typeMismatch'`, …), or `true` to show whenever invalid. |
|
|
29
|
+
| `children` | `ReactNode` | Message. Without it, shows the browser's or `validate`'s message. |
|
|
30
|
+
|
|
31
|
+
`FieldDescription` is helper text; hidden while an error shows.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { Button, Field, FieldDescription, FieldError, Input } from 'anvilui'
|
|
35
|
+
|
|
36
|
+
export function Example() {
|
|
37
|
+
return (
|
|
38
|
+
<form
|
|
39
|
+
onSubmit={(e) => e.preventDefault()}
|
|
40
|
+
style={{ display: 'grid', gap: 16, width: 320 }}
|
|
41
|
+
>
|
|
42
|
+
<Field
|
|
43
|
+
name="username"
|
|
44
|
+
validate={(value) =>
|
|
45
|
+
String(value).length < 3 ? 'At least 3 characters' : null
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
<Input label="Username" required />
|
|
49
|
+
<FieldDescription>Shown on your profile.</FieldDescription>
|
|
50
|
+
<FieldError match="valueMissing">Choose a username.</FieldError>
|
|
51
|
+
<FieldError match="customError" />
|
|
52
|
+
</Field>
|
|
53
|
+
<Button type="submit">Save</Button>
|
|
54
|
+
</form>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Works with `Input`, `Textarea`, `DateInput`, `Select`, `Combobox`, `Checkbox`, `Switch`, `RadioGroup`, `Slider`. A required checkbox: `<Field name="terms"><label><Checkbox required /> I accept</label><FieldError match="valueMissing">Please accept the terms.</FieldError></Field>`. On a plain `<form>`, a custom `validate` only blocks submit after it has run: use `validationMode="onBlur"` or `"onChange"` (see [forms.md](forms.md)). Base UI docs: `node_modules/@base-ui/react/docs/react/components/field.md`.
|