anvilui 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -12,7 +12,7 @@
12
12
  6. Callbacks get **values, not events**: `onValueChange(value)`, `onCheckedChange(checked)`, `onOpenChange(open)`, `onPressedChange(pressed)`. No `onChange` except on `Input`/`Textarea` (native).
13
13
  7. `Checkbox`, `Switch`, `Radio` have **no `label` prop**: wrap them in `<label>`. Most other controls take `label`.
14
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`).
15
+ 9. Icon-only controls require `aria-label` (`IconButton`, `FAB` without `label`, icon `Toggle`, `Slider`/`Progress` without `label`, `Search`, `Carousel`). Groups and navigation need one too: `ToggleGroup`, `RadioGroup` (or a `<fieldset>` with `<legend>`), `FloatingToolbar`, `AvatarGroup`, `NavigationBar`/`Rail`/`List`.
16
16
  10. `Button` defaults to `type="button"`. Use `type="submit"` in forms.
17
17
  11. Dates are `"YYYY-MM-DD"` strings, times `"HH:mm"` strings. Not `Date` objects.
18
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)`.
@@ -95,10 +95,10 @@ Props marked \* are required. All components also take `className`, `style`, `re
95
95
  | `Search` | `aria-label`\*, `value`/`onValueChange(text)`, `placeholder`, `color` (`surface`/`container`); suggestions: `items` + `children` = `(item) => <SearchItem/>`, `empty` | `<Search aria-label="Filter" value={q} onValueChange={setQ} />` |
96
96
  | `Checkbox` | `checked`/`defaultChecked`/`onCheckedChange(boolean)`, `indeterminate`, `name` | `<label><Checkbox checked={c} onCheckedChange={setC} /> Remember me</label>` |
97
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} />` |
98
+ | `RadioGroup` / `Radio` | group: `value`/`defaultValue`/`onValueChange(value)`, `name`; radio: `value`\* | `<RadioGroup aria-label="Plan" 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`, `getAriaLabel(index)` (names each handle of a range) | `<Slider label="Volume" defaultValue={50} />` |
100
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" />` |
101
+ | `TimePicker` | `value`/`defaultValue` `"HH:mm" \| null`, `onValueChange`, `type: 'dial'\|'input'`, `hourCycle: 12\|24`, `label` or `aria-label`\*, `name` (own, not inside `Field`) | `<TimePicker label="Start" defaultValue="09:00" />` |
102
102
  | `Calendar` | `value`/`defaultValue` `"YYYY-MM-DD" \| null`, `onValueChange` | `<Calendar value={d} onValueChange={setD} />` |
103
103
  | `PinInput` | `length`\*, `label` or `aria-label`\*, `value`/`onValueChange`, `onValueComplete`, `mask`, `validationType` | `<PinInput label="Code" length={6} />` |
104
104
  | `Field` | `name`, `validate`, `validationMode: 'onSubmit'\|'onBlur'\|'onChange'`, `invalid`, `disabled` | `<Field name="email"><Input label="Email" required /><FieldError /></Field>` |
@@ -141,12 +141,12 @@ Props marked \* are required. All components also take `className`, `style`, `re
141
141
 
142
142
  | Component | Key props | Usage |
143
143
  | --- | --- | --- |
144
- | `Avatar` | `name`, `src`, `icon`, `size` (32/40/56px), `color` | `<Avatar name="Ada Lovelace" src={url} />` |
144
+ | `Avatar` | `name` (or `aria-label`), `src`, `icon`, `size` (32/40/56px), `color` | `<Avatar name="Ada Lovelace" src={url} />` |
145
145
  | `AvatarGroup` | `max`, `size`, `fan`, `aria-label` | `<AvatarGroup max={3} aria-label="Team">{avatars}</AvatarGroup>` |
146
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
147
  | `Icon` | `name`\* | `<Icon name="star" />` |
148
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 }} />` |
149
+ | `Skeleton` | `type: 'text'\|'circular'\|'rectangular'` (not `variant`), `animation`; size via `style` | `<Skeleton style={{ width: 120 }} />` |
150
150
  | `Sticker` | `color`, `startIcon`, `tilt` | `<Sticker>NEW</Sticker>` |
151
151
  | `AnimatedNumber` | `value`\*, `format`, `locales` | `<AnimatedNumber value={n} />` |
152
152
  | `Kbd` | `children`, `listen`, `listenFor` | `<Kbd>⌘</Kbd><Kbd>K</Kbd>` |
@@ -455,6 +455,7 @@ Inside AnvilRoot: `var(--avl-color-background)`, `var(--avl-color-on-background)
455
455
  | `toast('Saved')`, `<Toaster />`, `<Snackbar open>` | `const snackbar = useSnackbar(); snackbar.show({ message: 'Saved' })` |
456
456
  | `snackbar.show({ message, severity: 'success' })` | no severity; put it in the message |
457
457
  | `<Typography variant="h4">` | `<Typography type="h4">` |
458
+ | `<Skeleton variant="circular">` | `<Skeleton type="circular">` |
458
459
  | `<AppBar title="Inbox">` / `<AppBar>Inbox</AppBar>` | `<AppBar label="Inbox" />` |
459
460
  | `<ListItem>Text</ListItem>` / `primary=` / `secondary=` | `<ListItem label="Text" description="More" />` |
460
461
  | `<ListItem onClick={…} />` expecting a button | `<ListItem label="…" render={<button type="button" onClick={…} />} />` |
@@ -474,7 +475,7 @@ Inside AnvilRoot: `var(--avl-color-background)`, `var(--avl-color-on-background)
474
475
 
475
476
  ## Errors you may see
476
477
 
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
+ 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/Skeleton, `label` on Checkbox/Switch/Radio, missing `aria-label` (also on groups and navigation), a range Slider without `getAriaLabel`, a TimePicker inside a Field, 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
 
479
480
  ## More
480
481
 
@@ -1,10 +1,10 @@
1
- import { ReactNode } from 'react';
1
+ import { ComponentProps, ReactNode } from 'react';
2
2
  import { ColorModeSetting } from './AnvilContext';
3
3
  import { Theme } from '../../themes/types';
4
4
  import { DesignTokens } from '../../tokens/types';
5
5
  import '../../colors/colors.css';
6
6
  import './global.css';
7
- export type AnvilRootProps = {
7
+ export type AnvilRootProps = Omit<ComponentProps<'div'>, 'children'> & {
8
8
  /** Your app. Every AnvilUI component must be somewhere inside. */
9
9
  children: ReactNode;
10
10
  /** Extra classes for the root element, e.g. to make it fill the viewport. */
@@ -36,4 +36,4 @@ export type DateInputProps = Omit<BaseInput.Props, 'value' | 'defaultValue' | 'o
36
36
  * const [date, setDate] = useState<string | null>(null)
37
37
  * <DateInput label="Start date" value={date} onValueChange={setDate} />
38
38
  */
39
- export declare function DateInput({ value: valueProp, defaultValue, onValueChange, label, size, disabled, id, onBlur, className, style, ref, ...props }: DateInputProps): import("react").JSX.Element;
39
+ export declare function DateInput({ value: valueProp, defaultValue, onValueChange, label, size, disabled, id, onChange, onBlur, className, style, ref, ...props }: DateInputProps): import("react").JSX.Element;
@@ -1,3 +1,4 @@
1
+ import { type Ref } from 'react';
1
2
  import { Menu as BaseMenu } from '@base-ui/react/menu';
2
3
  import type { MaterialSymbol } from 'material-symbols';
3
4
  import { type ComponentColor, type ComponentFillType } from '../../colors/colors';
@@ -25,6 +26,8 @@ export type FABMenuProps = Omit<BaseMenu.Root.Props, 'children' | 'orientation'>
25
26
  sticky?: boolean;
26
27
  /** Extra classes for the FAB itself. */
27
28
  className?: string;
29
+ /** The FAB's `<button>`. */
30
+ ref?: Ref<HTMLButtonElement>;
28
31
  /** `FABMenuItem`s, listed top to bottom. */
29
32
  children: React.ReactNode;
30
33
  };
@@ -39,7 +42,7 @@ export type FABMenuProps = Omit<BaseMenu.Root.Props, 'children' | 'orientation'>
39
42
  * <FABMenuItem icon="folder" onClick={newFolder}>Folder</FABMenuItem>
40
43
  * </FABMenu>
41
44
  */
42
- export declare function FABMenu({ icon, closeIcon, 'aria-label': ariaLabel, color, fillType, side, align, sticky, className, children, ...props }: FABMenuProps): import("react").JSX.Element;
45
+ export declare function FABMenu({ icon, closeIcon, 'aria-label': ariaLabel, color, fillType, side, align, sticky, className, ref, children, ...props }: FABMenuProps): import("react").JSX.Element;
43
46
  export type FABMenuItemProps = Omit<BaseMenu.Item.Props, 'children'> & {
44
47
  /** Material Symbol before the label. */
45
48
  icon: MaterialSymbol;
@@ -18,7 +18,7 @@ export type NavigationBarProps = ComponentProps<'nav'>;
18
18
  * </NavigationBar>
19
19
  */
20
20
  export declare function NavigationBar({ className, ...props }: NavigationBarProps): import("react").JSX.Element;
21
- export type NavigationBarItemProps = useRender.ComponentProps<'a'> & {
21
+ export type NavigationBarItemProps = Omit<useRender.ComponentProps<'a'>, 'children'> & {
22
22
  /** Material Symbol to show. */
23
23
  icon: MaterialSymbol;
24
24
  /** Visible text, also the link's accessible name. */
@@ -17,7 +17,7 @@ export type NavigationListProps = ComponentProps<'nav'>;
17
17
  * </NavigationList>
18
18
  */
19
19
  export declare function NavigationList({ className, ...props }: NavigationListProps): import("react").JSX.Element;
20
- export type NavigationListItemProps = useRender.ComponentProps<'a'> & {
20
+ export type NavigationListItemProps = Omit<useRender.ComponentProps<'a'>, 'children'> & {
21
21
  /** Visible text, also the link's accessible name. */
22
22
  label: string;
23
23
  /** The current page. Sets aria-current="page". */
@@ -31,7 +31,7 @@ export declare function NavigationRail({ expanded: expandedProp, defaultExpanded
31
31
  export type NavigationRailToggleProps = Omit<IconButtonProps, 'icon'>;
32
32
  /** The menu button at the top that expands and collapses the rail. Needs an `aria-label`. */
33
33
  export declare function NavigationRailToggle({ className, onClick, ...props }: NavigationRailToggleProps): import("react").JSX.Element;
34
- export type NavigationRailItemProps = useRender.ComponentProps<'a'> & {
34
+ export type NavigationRailItemProps = Omit<useRender.ComponentProps<'a'>, 'children'> & {
35
35
  /** Material Symbol to show. */
36
36
  icon: MaterialSymbol;
37
37
  /** Visible text, also the link's accessible name. */
@@ -13,7 +13,7 @@ export type RadioGroupProps<Value = unknown> = BaseRadioGroup.Props<Value>;
13
13
  * <label><Radio value="pro" /> Pro</label>
14
14
  * </RadioGroup>
15
15
  */
16
- export declare function RadioGroup<Value>({ className, ...props }: RadioGroupProps<Value>): import("react").JSX.Element;
16
+ export declare function RadioGroup<Value>({ className, ref, ...props }: RadioGroupProps<Value>): import("react").JSX.Element;
17
17
  export type RadioProps<Value = unknown> = BaseRadio.Root.Props<Value>;
18
18
  /** One option in a `RadioGroup`. Needs a `value`. Wrap it in a `<label>` with its text. */
19
19
  export declare function Radio<Value>({ className, ...props }: RadioProps<Value>): import("react").JSX.Element;
@@ -5,7 +5,7 @@ export type SkeletonProps = React.ComponentProps<'span'> & {
5
5
  * a rounded box (images, cards). Set the size with `style`.
6
6
  * @default 'text'
7
7
  */
8
- variant?: 'text' | 'circular' | 'rectangular';
8
+ type?: 'text' | 'circular' | 'rectangular';
9
9
  /** Fades in and out while loading. @default 'pulse' */
10
10
  animation?: 'pulse' | 'none';
11
11
  };
@@ -14,7 +14,7 @@ export type SkeletonProps = React.ComponentProps<'span'> & {
14
14
  * put `aria-busy` on the region that's loading.
15
15
  *
16
16
  * @example
17
- * <Skeleton variant="circular" style={{ width: 40, height: 40 }} />
17
+ * <Skeleton type="circular" style={{ width: 40, height: 40 }} />
18
18
  * <Skeleton style={{ width: '60%' }} />
19
19
  */
20
- export declare function Skeleton({ variant, animation, className, ...props }: SkeletonProps): import("react").JSX.Element;
20
+ export declare function Skeleton({ type, animation, className, ...props }: SkeletonProps): import("react").JSX.Element;
@@ -11,6 +11,12 @@ export type SliderProps<Value extends number | readonly number[] = number | read
11
11
  * wave and the plain track, e.g. `squiggly={playing}`. @default false
12
12
  */
13
13
  squiggly?: boolean;
14
+ /**
15
+ * Names each handle of a range, e.g.
16
+ * `(i) => (i === 0 ? 'Minimum price' : 'Maximum price')`. Without it,
17
+ * every handle gets the same name.
18
+ */
19
+ getAriaLabel?: (index: number) => string;
14
20
  } & ({
15
21
  /** Visible label above the slider. */
16
22
  label: ReactNode;
@@ -29,4 +35,4 @@ export type SliderProps<Value extends number | readonly number[] = number | read
29
35
  * <Slider label="Volume" defaultValue={50} />
30
36
  * <Slider aria-label="Price" value={range} onValueChange={setRange} min={0} max={500} />
31
37
  */
32
- export declare function Slider<Value extends number | readonly number[]>({ label, 'aria-label': ariaLabel, showValue, squiggly, className, ...props }: SliderProps<Value>): import("react").JSX.Element;
38
+ export declare function Slider<Value extends number | readonly number[]>({ label, 'aria-label': ariaLabel, showValue, squiggly, getAriaLabel, className, ...props }: SliderProps<Value>): import("react").JSX.Element;
package/dist/dev.d.ts CHANGED
@@ -8,8 +8,13 @@ export declare const POPUP_OUTSIDE_ROOT = "Its popup portals to <body>, outside
8
8
  export declare const OUTSIDE_ROOT = "The theme variables only exist inside AnvilRoot, so it shows without colors, spacing or fonts.";
9
9
  /** Components need AnvilRoot for the theme and as the portal target. */
10
10
  export declare function checkRoot(found: boolean, component: string, reason?: string): void;
11
- /** For controls with no visible text: their name must come from aria-label. */
11
+ export declare const NO_TEXT = "It shows no text, so screen readers need an `aria-label`.";
12
+ export declare const UNNAMED_GROUP = "Screen readers announce the group without saying what it's for: give it an `aria-label`.";
13
+ export declare const UNNAMED_NAV = "Screen readers list it as just \"navigation\": give it an `aria-label` to tell it apart from other navigation.";
14
+ /** A `<fieldset>` with a `<legend>` already names the group of controls inside it. */
15
+ export declare function inNamedFieldset(el: Element | null): boolean;
16
+ /** For controls and groups with no visible name: it must come from aria-label. */
12
17
  export declare function checkName(props: {
13
18
  'aria-label'?: unknown;
14
19
  'aria-labelledby'?: unknown;
15
- }, component: string, example: string, doc: string): void;
20
+ }, component: string, example: string, doc: string, reason?: string): void;