@jonmilner/ui 0.22.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/Alert/Alert.css +2 -0
- package/dist/Alert/Alert.css.mjs +9 -0
- package/dist/Alert/index.d.mts +13 -0
- package/dist/Alert/index.mjs +45 -0
- package/dist/AlertDialog/client.mjs +4 -4
- package/dist/AlertDialog/index.d.mts +3 -2
- package/dist/AlertDialog/index.mjs +10 -9
- package/dist/Avatar/Avatar.css +1 -1
- package/dist/Badge/Badge.css +1 -1
- package/dist/Body/index.d.mts +9 -0
- package/dist/Body/index.mjs +12 -0
- package/dist/Box/Box.css +1 -1
- package/dist/Button/Button.css +1 -1
- package/dist/Caption/index.d.mts +6 -0
- package/dist/Caption/index.mjs +14 -0
- package/dist/Checkbox/Checkbox.css +1 -1
- package/dist/Chip/Chip.css +1 -1
- package/dist/Clickable/Clickable.css +1 -1
- package/dist/Code/Code.css +2 -0
- package/dist/Code/Code.css.mjs +7 -0
- package/dist/Code/index.d.mts +10 -0
- package/dist/Code/index.mjs +40 -0
- package/dist/ColorField/ColorField.css +2 -2
- package/dist/ColorField/client.mjs +2 -1
- package/dist/Combobox/Combobox.css +2 -2
- package/dist/Combobox/client.mjs +5 -1
- package/dist/Dialog/Dialog.css +2 -2
- package/dist/Dialog/client.d.mts +1 -1
- package/dist/Dialog/client.mjs +14 -12
- package/dist/Dialog/index.d.mts +1 -1
- package/dist/Field/Field.css +1 -1
- package/dist/Flex/index.d.mts +5 -0
- package/dist/Flex/index.mjs +14 -0
- package/dist/Heading/Heading.css +1 -1
- package/dist/Heading/index.d.mts +1 -1
- package/dist/Icon/Icon.css +1 -1
- package/dist/IconButton/IconButton.css +1 -1
- package/dist/Inline/Inline.css +1 -1
- package/dist/Inline/index.mjs +1 -1
- package/dist/Label/index.d.mts +9 -0
- package/dist/Label/index.mjs +19 -0
- package/dist/Menu/Menu.css +2 -2
- package/dist/Menu/Menu.css.mjs +2 -2
- package/dist/Menu/client.mjs +56 -77
- package/dist/Menu/item-row.mjs +2 -2
- package/dist/MultiSelect/MultiSelect.css +2 -2
- package/dist/NavList/NavList.css +2 -2
- package/dist/NavList/index.mjs +11 -2
- package/dist/NumberField/NumberField.css +2 -2
- package/dist/Popover/Popover.css +2 -0
- package/dist/Popover/Popover.css.mjs +7 -0
- package/dist/Popover/client.d.mts +11 -0
- package/dist/Popover/client.mjs +54 -0
- package/dist/Popover/index.d.mts +20 -0
- package/dist/Popover/index.mjs +39 -0
- package/dist/RadioGroup/RadioGroup.css +2 -2
- package/dist/RadioGroup/index.mjs +1 -0
- package/dist/SearchField/SearchField.css +2 -2
- package/dist/Select/Select.css +2 -2
- package/dist/Sidebar/Sidebar.css +2 -2
- package/dist/Sidebar/index.mjs +10 -3
- package/dist/SidebarLayout/SidebarLayout.css +1 -1
- package/dist/Stack/Stack.css +1 -1
- package/dist/Stack/index.mjs +1 -1
- package/dist/Switch/Switch.css +2 -2
- package/dist/Switch/index.mjs +7 -1
- package/dist/Table/Table.css +2 -2
- package/dist/Table/Table.css.mjs +4 -2
- package/dist/Table/index.d.mts +3 -9
- package/dist/Table/index.mjs +60 -74
- package/dist/Tabs/Tabs.css +1 -1
- package/dist/Tag/Tag.css +1 -1
- package/dist/Text/Text.css +1 -1
- package/dist/TextField/TextField.css +2 -2
- package/dist/Textarea/Textarea.css +2 -2
- package/dist/Toast/Toast.css +2 -2
- package/dist/Toast/Toast.css.mjs +10 -7
- package/dist/Toast/client.d.mts +3 -18
- package/dist/Toast/client.mjs +95 -134
- package/dist/Tooltip/Tooltip.css +1 -1
- package/dist/VisuallyHidden/VisuallyHidden.css +1 -1
- package/dist/base.css +2 -2
- package/dist/brands/default.mjs +2 -1
- package/dist/brands/forced-colors.mjs +2 -1
- package/dist/brands/neutral.mjs +8 -7
- package/dist/contrast/contrast.mjs +43 -35
- package/dist/contrast/mixes.mjs +15 -8
- package/dist/docs/Alert.md +106 -0
- package/dist/docs/AlertDialog.md +25 -11
- package/dist/docs/Body.md +74 -0
- package/dist/docs/Box.md +4 -3
- package/dist/docs/Caption.md +77 -0
- package/dist/docs/Code.md +84 -0
- package/dist/docs/ColorField.md +1 -1
- package/dist/docs/Combobox.md +2 -1
- package/dist/docs/Dialog.md +28 -4
- package/dist/docs/Flex.md +76 -0
- package/dist/docs/Heading.md +3 -3
- package/dist/docs/Icon.md +1 -0
- package/dist/docs/Inline.md +3 -2
- package/dist/docs/Label.md +77 -0
- package/dist/docs/Menu.md +3 -3
- package/dist/docs/MultiSelect.md +1 -0
- package/dist/docs/NumberField.md +1 -1
- package/dist/docs/Popover.md +135 -0
- package/dist/docs/SearchField.md +1 -1
- package/dist/docs/Select.md +1 -0
- package/dist/docs/Stack.md +12 -10
- package/dist/docs/Table.md +5 -5
- package/dist/docs/Text.md +30 -23
- package/dist/docs/TextField.md +1 -1
- package/dist/docs/Textarea.md +1 -1
- package/dist/docs/Toast.md +7 -7
- package/dist/docs/Tooltip.md +2 -2
- package/dist/docs/lint.md +18 -0
- package/dist/docs/llms.txt +19 -10
- package/dist/docs/manifest.json +559 -8
- package/dist/docs/migrations/0.23.0.md +84 -0
- package/dist/docs/theming.md +3 -3
- package/dist/icons/TriangleAlertIcon.d.mts +2 -0
- package/dist/icons/TriangleAlertIcon.mjs +10 -0
- package/dist/icons/index.d.mts +3 -2
- package/dist/icons/index.mjs +4 -3
- package/dist/index.d.mts +11 -3
- package/dist/index.mjs +47 -40
- package/dist/lint/index.d.mts +20 -1
- package/dist/lint/index.mjs +18 -3
- package/dist/popup/client.mjs +20 -19
- package/dist/popup/direction.d.mts +2 -1
- package/dist/popup/listbox-base.mjs +3 -2
- package/dist/popup/positioner.mjs +27 -0
- package/dist/scroll-region/scroll-region.d.mts +12 -0
- package/dist/scroll-region/scroll-region.mjs +29 -0
- package/dist/status-message/status-message.d.mts +5 -0
- package/dist/status-message/status-message.mjs +74 -0
- package/dist/status-message/tones.d.mts +7 -0
- package/dist/status-message/tones.mjs +8 -0
- package/dist/styles/atom-values.mjs +131 -0
- package/dist/styles/atoms.css +1 -1
- package/dist/styles/layers.css +1 -1
- package/dist/styles/responsive.css +1 -1
- package/dist/styles/scroll-region.css +2 -0
- package/dist/styles/scroll-region.css.mjs +7 -0
- package/dist/styles/status-message.css +2 -0
- package/dist/styles/status-message.css.mjs +7 -0
- package/dist/tokens/contract.d.mts +1 -1
- package/dist/tokens/roles.d.mts +1 -1
- package/dist/tokens/roles.mjs +1 -1
- package/package.json +30 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Alert
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Tells the user about a condition on the page that lasts until its cause changes: offline, a trial ending, a sync that failed. A tinted card in the page's flow with the variant's icon, a title, an optional description, optional actions and an optional close button. It is a static surface: only what you put in it is interactive.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- A state of the page or account that stays true until something changes: "You're offline", "Your trial ends in 3 days", "Sync failed".
|
|
10
|
+
- A form-level error, in a slot that reserves its height, once the fields' own errors don't cover it.
|
|
11
|
+
|
|
12
|
+
## When not to use
|
|
13
|
+
|
|
14
|
+
- The brief result of something the user just did ("Saved"): use `Toast`, which floats and leaves on its own.
|
|
15
|
+
- The error of one input: use the field's own error (`TextField`'s `error`, or `Field`).
|
|
16
|
+
- A decision that must be made before going on: use `AlertDialog`, which interrupts.
|
|
17
|
+
- A status label beside a name: use `Badge`.
|
|
18
|
+
- A bar fixed to the top of the viewport: Alert sits in the page's flow; the library has no such bar.
|
|
19
|
+
|
|
20
|
+
## Rules
|
|
21
|
+
|
|
22
|
+
- `variant`: `info` (default), `success`, `warning` or `danger`. Each brings its icon and tinted fill, so the icon, not only the color, tells them apart (WCAG 1.4.1).
|
|
23
|
+
- `title` states the condition in a few words; `description` says what it means or what to do. Keep the description to a sentence or two.
|
|
24
|
+
- `actions` holds the buttons or links that fix the condition, usually a `Button` with `variant="secondary"` and the default size, or `size="sm"`. They sit at the end when the space inside the alert's padding is 32rem wide or more, centered against the text, and below the text when it is narrower. The width is the alert's own, not the viewport's, so it holds in a sidebar. Only actions go here: a link inside a sentence belongs in `description`.
|
|
25
|
+
- `onDismiss` shows the close button and runs when it is pressed. The caller removes the alert; without `onDismiss` it stays until its cause changes. `dismissLabel` is the button's accessible name, "Dismiss" by default; pass a translated string.
|
|
26
|
+
- Dismissing moves nothing for free: the page below an alert closes up. Give an alert that comes and goes a slot that reserves its height, or put it where nothing below can be mid-use.
|
|
27
|
+
- The icon stays centered on the title's first line however far the text wraps. Below 16rem the content takes its own line under the icon.
|
|
28
|
+
- It fills its container's inline size and sits in normal flow. It measures itself, so it adds no width to a parent that shrinks to its content, such as `inline-flex` or a popup: give that parent a width. It sets no margin: the parent's `gap` spaces it. Fill, text color, radius, padding and `inlineSize` are default style props on the root; a consumer's win. `className`, `style`, `ref` and other attributes go to the root, `className` last.
|
|
29
|
+
- The module has no hooks, so a server component can render it, as long as it passes no `onDismiss` from there.
|
|
30
|
+
|
|
31
|
+
## Do
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
<Alert
|
|
35
|
+
variant="warning"
|
|
36
|
+
title="Your trial ends in 3 days"
|
|
37
|
+
description="Add a card to keep your projects."
|
|
38
|
+
actions={<Button variant="secondary">Add a card</Button>}
|
|
39
|
+
/>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
// Dismissible: the caller decides when it leaves, and remembers it.
|
|
44
|
+
{
|
|
45
|
+
showNotice && (
|
|
46
|
+
<Alert title="New export format" onDismiss={hideNotice} dismissLabel="Dismiss the notice" />
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// It appears because of what the user just did, so it announces itself. The region is on the page
|
|
53
|
+
// first, and the alert renders inside it.
|
|
54
|
+
<Box aria-atomic="true" aria-live="assertive">
|
|
55
|
+
{syncFailed && (
|
|
56
|
+
<Alert
|
|
57
|
+
variant="danger"
|
|
58
|
+
title="Sync failed"
|
|
59
|
+
actions={<Button variant="secondary">Retry</Button>}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
</Box>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Don't
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
// The brief result of an action: it would stay on the page with nothing left to say. Use Toast.
|
|
69
|
+
<Alert variant="success" title="Saved" />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// One input's error, away from the input. Use the field's `error`.
|
|
74
|
+
<Alert variant="danger" title="Email is required" />
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
// A decision: Alert does not stop the user. Use AlertDialog.
|
|
79
|
+
<Alert variant="danger" title="Delete this project?" actions={<Button>Delete</Button>} />
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- An alert announces nothing by default, since one present when the page loads should be read in order like the rest of it (ADR 0097). When one appears because of something the user just did, render it inside an element with `role="status"`, or `aria-live="assertive" aria-atomic="true"` for an urgent error, that is already on the page: a live region added with its text may go unread. An urgent region takes no `role="alert"`, since it sits empty until the error appears (ADR 0097), and an empty region still takes its parent's `gap`. Pass `role` to the alert itself only when it stays mounted and its text changes.
|
|
85
|
+
- Showing an alert never moves focus. When the close button removes the alert, move focus somewhere deliberate, such as the next control or the section's heading: the button is gone, so focus would otherwise fall to the page.
|
|
86
|
+
- The icon is decorative; the title states the condition.
|
|
87
|
+
- The close button is a native button with the shared focus ring and a 24px target.
|
|
88
|
+
- Resize text (WCAG 1.4.4): the 32rem width and the narrower 16rem one, where the content takes its own line below the icon and close button, are measured inside the padding and in rem, so at 200% text the layout wraps sooner and nothing overflows.
|
|
89
|
+
- Under forced colors the fill drops and the border keeps the card's edge.
|
|
90
|
+
|
|
91
|
+
## Props
|
|
92
|
+
|
|
93
|
+
Generated from the TypeScript types.
|
|
94
|
+
|
|
95
|
+
### Alert
|
|
96
|
+
|
|
97
|
+
| Prop | Type | Required | Description |
|
|
98
|
+
| --- | --- | --- | --- |
|
|
99
|
+
| `actions` | `ReactNode` | no | |
|
|
100
|
+
| `description` | `ReactNode` | no | |
|
|
101
|
+
| `dismissLabel` | `string` | no | |
|
|
102
|
+
| `onDismiss` | `(() => void)` | no | |
|
|
103
|
+
| `title` | `ReactNode` | yes | |
|
|
104
|
+
| `variant` | `"danger" \| "info" \| "success" \| "warning"` | no | |
|
|
105
|
+
|
|
106
|
+
Also accepts the style props (see `manifest.json` `styleProps`).
|
package/dist/docs/AlertDialog.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Purpose
|
|
4
4
|
|
|
5
|
-
Asks the user to confirm a consequential action before it runs: delete a project, discard unsaved changes, sign out every device. Built on Base UI's AlertDialog, which owns the behavior: `role="alertdialog"`, focus moves into the dialog and stays there, the page behind is
|
|
5
|
+
Asks the user to confirm a consequential action before it runs: delete a project, discard unsaved changes, sign out every device. Built on Base UI's AlertDialog, which owns the behavior: `role="alertdialog"`, focus moves into the dialog and stays there, the page behind is hidden from assistive tech, Esc closes it, and a click outside does not. It wears Dialog's panel at the `sm` width with a title, a description, Cancel and one confirm button, and Cancel takes focus on open.
|
|
6
6
|
|
|
7
7
|
## When to use
|
|
8
8
|
|
|
@@ -24,6 +24,7 @@ Asks the user to confirm a consequential action before it runs: delete a project
|
|
|
24
24
|
- `onConfirm` runs once on the confirm button, then the dialog closes; a second click while it fades out does nothing. If it throws, the dialog stays open; a returned promise is not awaited. For an action that can fail, control it with `open` and `onOpenChange` and report the failure where the action started.
|
|
25
25
|
- Cancel comes first and takes focus, so Enter on open cancels. On a touch screen Base UI focuses the panel instead, so no button is pressed by accident.
|
|
26
26
|
- Without `AlertDialog.Trigger`, control it with `open` and `onOpenChange`; it then portals to `<body>`, as Dialog does.
|
|
27
|
+
- `finalFocus` says where focus goes when it closes, as on `Dialog.Popup`. Opened from a menu item, the item is gone once the menu closes and there is no trigger, so pass a ref to the control to return to, usually the menu's trigger. The ref points at the focusable control itself. It gets focus at once on Esc, Cancel or confirm, with a visible focus ring after a key (ADR 0192); an empty ref falls back to the trigger, or the element focused before it opened.
|
|
27
28
|
- It is always modal and takes no `className`, `style` or style props: the panel is fixed so every confirm looks the same.
|
|
28
29
|
- The module has no hooks and no `"use client"`, but `onConfirm` is a function, so the component that renders it is a client component.
|
|
29
30
|
|
|
@@ -42,16 +43,28 @@ Asks the user to confirm a consequential action before it runs: delete a project
|
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
```tsx
|
|
45
|
-
// Opened from a menu item: no trigger, so control it.
|
|
46
|
+
// Opened from a menu item: no trigger, so control it, and return focus to the menu's trigger.
|
|
46
47
|
const [open, setOpen] = useState(false);
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const account = useRef<HTMLButtonElement>(null);
|
|
49
|
+
<>
|
|
50
|
+
<Menu>
|
|
51
|
+
<Menu.Trigger ref={account} variant="secondary">
|
|
52
|
+
Account
|
|
53
|
+
</Menu.Trigger>
|
|
54
|
+
<Menu.Popup>
|
|
55
|
+
<Menu.Item onClick={() => setOpen(true)}>Sign out everywhere…</Menu.Item>
|
|
56
|
+
</Menu.Popup>
|
|
57
|
+
</Menu>
|
|
58
|
+
<AlertDialog
|
|
59
|
+
open={open}
|
|
60
|
+
onOpenChange={setOpen}
|
|
61
|
+
finalFocus={account}
|
|
62
|
+
title="Sign out of every device?"
|
|
63
|
+
description="You stay signed in here."
|
|
64
|
+
confirmLabel="Sign out"
|
|
65
|
+
onConfirm={signOutEverywhere}
|
|
66
|
+
/>
|
|
67
|
+
</>;
|
|
55
68
|
```
|
|
56
69
|
|
|
57
70
|
## Don't
|
|
@@ -74,7 +87,7 @@ const [open, setOpen] = useState(false);
|
|
|
74
87
|
## Accessibility
|
|
75
88
|
|
|
76
89
|
- The trigger has `aria-haspopup="dialog"` and `aria-expanded`. The popup is `role="alertdialog"` with `aria-modal`, labelled by the title and described by the description.
|
|
77
|
-
- Opening moves focus to Cancel; Tab and Shift+Tab cycle between the two buttons, and the page behind is
|
|
90
|
+
- Opening moves focus to Cancel; Tab and Shift+Tab cycle between the two buttons, and the page behind is `aria-hidden`. Esc or Cancel closes it, and focus returns to the trigger, or to `finalFocus`. A click outside does nothing.
|
|
78
91
|
- A closed alert dialog stays on the page while it fades out, but is `inert` and `aria-hidden` from the moment it closes, and focus is back on the trigger at once, so a dialog opened during the fade is the only one a screen reader or a role query finds, and nothing in the fading one takes focus or a click (ADR 0113).
|
|
79
92
|
- The danger confirm button is told apart by its label as well as its color.
|
|
80
93
|
- Under reduced motion the panel only fades.
|
|
@@ -92,6 +105,7 @@ Generated from the TypeScript types.
|
|
|
92
105
|
| `confirmLabel` | `string` | yes | |
|
|
93
106
|
| `defaultOpen` | `boolean` | no | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. |
|
|
94
107
|
| `description` | `string \| number \| bigint \| Iterable<ReactNode> \| Promise<AwaitedReactNode> \| ReactElement<unknown, string \| JSXElementConstructor<any>> \| ReactPortal` | yes | |
|
|
108
|
+
| `finalFocus` | `boolean \| RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => void \| boolean \| HTMLElement \| null)` | no | |
|
|
95
109
|
| `onConfirm` | `() => void` | yes | |
|
|
96
110
|
| `onOpenChange` | `((open: boolean, eventDetails: AlertDialogRootChangeEventDetails) => void)` | no | Event handler called when the alert dialog is opened or closed. |
|
|
97
111
|
| `onOpenChangeComplete` | `((open: boolean) => void)` | no | Event handler called after any animations complete when the dialog is opened or closed. |
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Body
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Running text: paragraphs, descriptions, empty-state copy, the sentences in a card or dialog. A `Text` with body defaults: the `body` font role at `med`, rendered as a `p`. At `sm` it takes the paired `body` leading, 14/20, for dense UI.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- A paragraph or sentence a user reads.
|
|
10
|
+
- Dense UI copy (a table's empty state, a sidebar's help text): `size="sm"`.
|
|
11
|
+
|
|
12
|
+
## When not to use
|
|
13
|
+
|
|
14
|
+
- A heading: use `Heading`.
|
|
15
|
+
- Short UI text that names something (a value's name, a status, a column's label outside a table): use `Label`.
|
|
16
|
+
- A note under or beside other text (a timestamp, a count, a file size): use `Caption`.
|
|
17
|
+
- A form control's label: use `Field.Label`.
|
|
18
|
+
|
|
19
|
+
## Rules
|
|
20
|
+
|
|
21
|
+
- `size` is `sm`, `med` (default) or `lg`. Larger type is a `Heading`, or `Text` with `font="display"`.
|
|
22
|
+
- `as` defaults to `p`. Set another block element (`div`) when the text is not a paragraph.
|
|
23
|
+
- Body always sets its size, so it is not a run: a bold or emphasised word inside a Body is `<Text as="strong">`, which inherits the outer size. A `p` inside a `p` is invalid HTML.
|
|
24
|
+
- Body takes every other Text prop (`color`, `weight`, `leading`, `font`, `truncate`, `wrap`, style props) and overrides its defaults with them.
|
|
25
|
+
- Space paragraphs with the gap of a `Stack` around them, not margins: the box is trimmed to the text.
|
|
26
|
+
|
|
27
|
+
## Do
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<Stack gap="12">
|
|
31
|
+
<Body>Invites go to everyone on the list.</Body>
|
|
32
|
+
<Body color="fgMuted" size="sm">
|
|
33
|
+
Each link works once and expires after seven days.
|
|
34
|
+
</Body>
|
|
35
|
+
</Stack>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Don't
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
// Body stops at lg; a heading is a Heading.
|
|
42
|
+
<Body size="2xl">Settings</Body>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
// A Body inside a Body is a p inside a p, and resets the size; a run is a Text.
|
|
47
|
+
<Body size="sm">
|
|
48
|
+
Saved <Body>today</Body>
|
|
49
|
+
</Body>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Accessibility
|
|
53
|
+
|
|
54
|
+
- A `p` is a paragraph to screen readers; set `as` to another element only when the text is not one.
|
|
55
|
+
- Keep muted body text on the color roles meant for it (`fgMuted`), which meet contrast on every surface.
|
|
56
|
+
|
|
57
|
+
## Props
|
|
58
|
+
|
|
59
|
+
Generated from the TypeScript types.
|
|
60
|
+
|
|
61
|
+
### Body
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Required | Description |
|
|
64
|
+
| --- | --- | --- | --- |
|
|
65
|
+
| `as` | `ElementType` | no | |
|
|
66
|
+
| `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
|
|
67
|
+
| `leading` | `"body" \| "lg" \| "med" \| "meta" \| "sm"` | no | |
|
|
68
|
+
| `size` | `"lg" \| "med" \| "sm"` | no | |
|
|
69
|
+
| `tabularNums` | `boolean` | no | |
|
|
70
|
+
| `truncate` | `"box" \| boolean` | no | |
|
|
71
|
+
| `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
|
|
72
|
+
| `wrap` | `"nowrap" \| "pre" \| "pre-wrap"` | no | |
|
|
73
|
+
|
|
74
|
+
Also accepts every `<p>` attribute (change the element with `as`) and the style props (see `manifest.json` `styleProps`).
|
package/dist/docs/Box.md
CHANGED
|
@@ -7,13 +7,13 @@ The base element every component builds on: one element, chosen with `as`, style
|
|
|
7
7
|
## When to use
|
|
8
8
|
|
|
9
9
|
- Surfaces that need tokens but no behavior: a padded panel, a sticky bar, a grid.
|
|
10
|
-
- A semantic element (`as="section"`, `as="nav"`, `as="ul"`) that needs style props.
|
|
10
|
+
- A semantic element (`as="section"`, `as="nav"`, `as="ul"`) that needs style props. A raw element with a `className` (`<ul className={css.list}>`) is a code smell: a `Box` with `as` and style props is the minimum.
|
|
11
11
|
- Building a new component: render a `Box` and pass its tunable values as default style props.
|
|
12
12
|
|
|
13
13
|
## When not to use
|
|
14
14
|
|
|
15
|
-
- Text: use `
|
|
16
|
-
- Stacks and rows of children with a gap: use `Stack` or `Inline`. A Box with `display="flex"`, `flexDirection="column"` and `gap` is a `Stack` rebuilt by hand.
|
|
15
|
+
- Text: use `Heading`, `Body`, `Label`, `Caption` or `Code`; all visible text goes through them, or through `Text` for what none covers (see its docs).
|
|
16
|
+
- Stacks and rows of children with a gap: use `Stack` or `Inline`, not `Box` or `Flex`. A Box with `display="flex"`, `flexDirection="column"` and `gap` is a `Stack` rebuilt by hand.
|
|
17
17
|
- Records in rows that share named columns: use `Table`, not a grid of boxes, so the columns have headers.
|
|
18
18
|
- Anything interactive: use `Button` or a link component, which bring focus and states.
|
|
19
19
|
|
|
@@ -26,6 +26,7 @@ The base element every component builds on: one element, chosen with `as`, style
|
|
|
26
26
|
- The style-prop CSS ships in two files (decision 0111). Every component brings the base rules. The `sm`, `med`, `lg` and `xl` rules are `@jonmilner/ui/responsive.css`, which only Box, Stack and Inline import, so a Button alone ships none of them, whether imported from `@jonmilner/ui/Button` or from `@jonmilner/ui`.
|
|
27
27
|
- A responsive value on any other component (`<Button marginBlock={{ base: "8", med: "16" }}>`) keeps only its `base` value unless `responsive.css` is on the page. A Box, Stack or Inline on the page brings it, but one on another route only does if that route loaded first. So an app that sets one imports it once, as a JS import, in its root module beside `base.css`.
|
|
28
28
|
- In development a console warning names the missing import, but only where the rules are really absent: in development the root `@jonmilner/ui` import loads every component, Box included, so there the value works and the warning stays silent, and only the production build drops it.
|
|
29
|
+
- A `*.css.ts` file is the exception: never write a property/value pair there that a style prop covers (`display: "flex"`, `gap: vars.space["16"]`), unless the style prop cannot work in that case. `styleProps` from `@jonmilner/ui/lint` lists each prop's values (see `lint.md`).
|
|
29
30
|
- There are no hover, focus or active props; states belong in component CSS.
|
|
30
31
|
- `null` and `false` leave a prop unset, so `paddingInline={dense && "8"}` works.
|
|
31
32
|
- The consumer's `className` comes last and `style` is passed through, so consumer values win.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Caption
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
A note that sits under or beside other text: a timestamp, a count, a file size, a hint under a value. A `Text` with caption defaults: `xs`, `medium` weight, the paired `meta` leading (12/16), `fgMuted`, rendered as a `span`. One size, so it has no `size` or `leading` prop.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- Secondary detail about the thing next to it: "Updated 3 minutes ago", "12 files", "2.4 MB".
|
|
10
|
+
- A count or timestamp in a dense row.
|
|
11
|
+
- A figure's caption: `as="figcaption"` inside the `figure`.
|
|
12
|
+
|
|
13
|
+
## When not to use
|
|
14
|
+
|
|
15
|
+
- A form field's help text: use the field's `description` (or `Field.Description`), which the control is described by.
|
|
16
|
+
- A form field's error: use the field's `error` (or `Field.Error`).
|
|
17
|
+
- A sentence a user must read to act: use `Body`, at `sm` if it must be small.
|
|
18
|
+
- A name or tag: use `Label`.
|
|
19
|
+
|
|
20
|
+
## Rules
|
|
21
|
+
|
|
22
|
+
- No `size` or `leading`: a caption is 12/16. Larger secondary text is `Body size="sm" color="fgMuted"`.
|
|
23
|
+
- `color` defaults to `fgMuted`; set another role (`fg`, `danger`, …) to override it.
|
|
24
|
+
- `as` defaults to `span`. On its own it is still a trimmed block (Text's default `display`); directly inside another Text it is an inline run, still at `xs`.
|
|
25
|
+
- Caption takes every other Text prop (`weight`, `font`, `tabularNums`, `truncate`, style props) and overrides its defaults with them.
|
|
26
|
+
- Use `tabularNums` on a count or duration that ticks or sits in a column.
|
|
27
|
+
|
|
28
|
+
## Do
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
<Stack gap="8">
|
|
32
|
+
<Body size="sm">Quarterly report.pdf</Body>
|
|
33
|
+
<Caption>Updated 3 minutes ago</Caption>
|
|
34
|
+
</Stack>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
<Caption as="time" dateTime="2026-11-10">
|
|
39
|
+
Nov 10
|
|
40
|
+
</Caption>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Don't
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
// A caption has one size; small body text is Body.
|
|
47
|
+
<Caption size="sm">Each link works once.</Caption>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
// Help text under a field is its description, which the control is described by.
|
|
52
|
+
<TextField label="Email" />
|
|
53
|
+
<Caption>We never share it.</Caption>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Accessibility
|
|
57
|
+
|
|
58
|
+
- `fgMuted` meets text contrast on every surface; do not lighten a caption further with opacity.
|
|
59
|
+
- A caption is not tied to anything for assistive technology. When it describes a control, use `Field.Description` or `aria-describedby`.
|
|
60
|
+
- Never put information only in a caption that a user needs to complete a task.
|
|
61
|
+
|
|
62
|
+
## Props
|
|
63
|
+
|
|
64
|
+
Generated from the TypeScript types.
|
|
65
|
+
|
|
66
|
+
### Caption
|
|
67
|
+
|
|
68
|
+
| Prop | Type | Required | Description |
|
|
69
|
+
| --- | --- | --- | --- |
|
|
70
|
+
| `as` | `ElementType` | no | |
|
|
71
|
+
| `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
|
|
72
|
+
| `tabularNums` | `boolean` | no | |
|
|
73
|
+
| `truncate` | `"box" \| boolean` | no | |
|
|
74
|
+
| `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
|
|
75
|
+
| `wrap` | `"nowrap" \| "pre" \| "pre-wrap"` | no | |
|
|
76
|
+
|
|
77
|
+
Also accepts every `<span>` attribute (change the element with `as`) and the style props (see `manifest.json` `styleProps`).
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Code
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Code in the mono font: a run inside a line of text, or with `block` a multi-line sample on a muted surface. A `Text` preset, so it takes Text's props and the style props. No syntax highlighting, copy button, line numbers or wrapping.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- A file name, command, identifier or value inside a sentence: `<Code>`.
|
|
10
|
+
- A multi-line sample (a command, a config, a log excerpt) that keeps its line breaks: `<Code block>`.
|
|
11
|
+
|
|
12
|
+
## When not to use
|
|
13
|
+
|
|
14
|
+
- Prose in the mono font that is not code: use `Text` with `font="mono"`.
|
|
15
|
+
- A long log that should wrap: use `Text as="pre"` with `wrap="pre-wrap"`; a block never wraps.
|
|
16
|
+
- Highlighted code, a copy button or line numbers: not supported.
|
|
17
|
+
|
|
18
|
+
## Rules
|
|
19
|
+
|
|
20
|
+
- Inline renders `<code>` in the `mono` font. It sets no size or color and has no background, so it inherits the line's; it inherits them only directly inside a `Text`, where it is a `Text` run (see `Text`). Outside one (a `Button` label, a bare `li`, a `Box`) it is a top-level `Text` at the default size and color, so put it in a `Text`.
|
|
21
|
+
- Inline takes Text's props (`size`, `weight`, `color`, `font`) and overrides its defaults with them.
|
|
22
|
+
- `block` renders `<pre><code>` at `sm` on `bgMuted` with the `med` radius and `12` by `16` padding. Line breaks and runs of spaces stay, lines never wrap, and a long line scrolls sideways inside the block, never the page.
|
|
23
|
+
- A block's type requires a name, `aria-label` or `aria-labelledby` (never both), as `Table.ScrollArea`'s does: the scroll region is a `section`, so the name makes it a region landmark. It is in the tab order only while the code overflows, and the arrow keys then scroll it.
|
|
24
|
+
- A block takes the style props (on the surface), `className` and `style` (on the surface), and the `section`'s other props, `ref` included. It takes no block size.
|
|
25
|
+
- A block is `dir="ltr"`, scrollbar included, so a right-to-left page neither reorders the code nor opens it scrolled to the far edge.
|
|
26
|
+
- Children are text: put the code in a string or template literal, not markup.
|
|
27
|
+
- Both forms are hook-free.
|
|
28
|
+
|
|
29
|
+
## Do
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
<Text>
|
|
33
|
+
Run <Code>pnpm check</Code> before you push.
|
|
34
|
+
</Text>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
<Code block aria-label="Install command">
|
|
39
|
+
{`pnpm add @jonmilner/ui
|
|
40
|
+
pnpm exec local-ci run`}
|
|
41
|
+
</Code>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Don't
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
// A block with no name does not type-check; the scroll region needs one.
|
|
48
|
+
<Code block>{sample}</Code>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// Markup for color is highlighting, which Code does not do.
|
|
53
|
+
<Code block aria-label="Sample">
|
|
54
|
+
<span style={{ color: "red" }}>error</span>
|
|
55
|
+
</Code>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Accessibility
|
|
59
|
+
|
|
60
|
+
- A block that overflows is focusable, so a keyboard reaches it and scrolls it with the arrow keys; it shows the shared focus ring, inset so a dialog body does not clip it.
|
|
61
|
+
- Under forced colors the block gets a 1px `CanvasText` outline, inset, because its fill and radius vanish.
|
|
62
|
+
- The name says what the sample is (`Install command`), not that it is code.
|
|
63
|
+
- Under forced colors the scroll thumb keeps its fill.
|
|
64
|
+
|
|
65
|
+
## Props
|
|
66
|
+
|
|
67
|
+
Generated from the TypeScript types.
|
|
68
|
+
|
|
69
|
+
### Code
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Required | Description |
|
|
72
|
+
| --- | --- | --- | --- |
|
|
73
|
+
| `aria-label` | `string` | no | The region's name. Required unless `aria-labelledby` names it. |
|
|
74
|
+
| `aria-labelledby` | `string` | no | The id of the element that names the region. Required unless `aria-label` names it. |
|
|
75
|
+
| `block` | `false \| true` | no | |
|
|
76
|
+
| `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
|
|
77
|
+
| `leading` | `"body" \| "lg" \| "med" \| "meta" \| "sm"` | no | |
|
|
78
|
+
| `size` | `"2xl" \| "3xl" \| "4xl" \| "lg" \| "med" \| "sm" \| "xl" \| "xs"` | no | |
|
|
79
|
+
| `tabularNums` | `boolean` | no | |
|
|
80
|
+
| `truncate` | `"box" \| boolean` | no | |
|
|
81
|
+
| `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
|
|
82
|
+
| `wrap` | `"nowrap" \| "pre" \| "pre-wrap"` | no | |
|
|
83
|
+
|
|
84
|
+
Also accepts the style props (see `manifest.json` `styleProps`).
|
package/dist/docs/ColorField.md
CHANGED
|
@@ -67,7 +67,7 @@ A form field for one colour as a `#rrggbb` string: a swatch, the browser's own c
|
|
|
67
67
|
|
|
68
68
|
- The hex input is a `textbox` named by the label, visible or not; the swatch is the browser's colour input, named by `swatchLabel`. The swatch comes first in the tab order and opens the platform picker with Enter or Space.
|
|
69
69
|
- The colour shows as a filled square with a border, so a pale or dark colour stays visible on any background; the hex beside it says the colour in text.
|
|
70
|
-
- Invalid adds a danger border and the error message with its icon, never colour alone; disabled adds dashed borders. Under forced colors the swatch keeps its colour, since the colour is the content, and its border uses a system colour. On a coarse pointer (a touch screen) the hex text is 16px at every size, so iOS Safari does not zoom the page when the field takes focus.
|
|
70
|
+
- Invalid adds a 2px danger border, a 2px `CanvasText` border under forced colors, and the error message with its icon, never colour alone; disabled adds dashed borders. Under forced colors the swatch keeps its colour, since the colour is the content, and its border uses a system colour. On a coarse pointer (a touch screen) the hex text is 16px at every size, so iOS Safari does not zoom the page when the field takes focus.
|
|
71
71
|
|
|
72
72
|
## Props
|
|
73
73
|
|
package/dist/docs/Combobox.md
CHANGED
|
@@ -91,6 +91,7 @@ A form field for picking one value, or any number with `multiple`, from a list l
|
|
|
91
91
|
- A closed popup stays on the page while it fades out, but is `inert` and `aria-hidden` from the moment it closes, so a popup opened during the fade is the only one a screen reader or a role query finds (ADR 0113).
|
|
92
92
|
- Selection is a check mark on the option as well as the trigger's text, so it is not color alone. The check sits at the end of the row; its space is always kept, so labels never shift.
|
|
93
93
|
- The trigger summary is text: the label, the joined labels, or the count. When the count replaces the labels, the labels are hidden from assistive technology so the count is read once.
|
|
94
|
+
- Invalid adds a 2px danger border on the trigger, a 2px `CanvasText` border under forced colors, and the error message with its icon, never colour alone. While the focus ring shows, it replaces the border's second pixel.
|
|
94
95
|
- The highlighted option takes the shared highlight fill. Under forced colors it is `Highlight` with `HighlightText`, the input's ring is `Highlight`, and the popup keeps its border.
|
|
95
96
|
|
|
96
97
|
## Props
|
|
@@ -111,7 +112,7 @@ Generated from the TypeScript types.
|
|
|
111
112
|
| `filterLabel` | `string` | no | |
|
|
112
113
|
| `hideLabel` | `boolean` | no | |
|
|
113
114
|
| `label` | `ReactNode` | yes | |
|
|
114
|
-
| `multiple` | `
|
|
115
|
+
| `multiple` | `false \| true` | no | |
|
|
115
116
|
| `name` | `string` | no | |
|
|
116
117
|
| `onValueChange` | `((value: string \| null) => void) \| ((value: string[]) => void)` | no | |
|
|
117
118
|
| `options` | `readonly ListboxOption[]` | yes | |
|
package/dist/docs/Dialog.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Purpose
|
|
4
4
|
|
|
5
|
-
A modal panel over the page for one short task: edit a name, fill a small form, read details that need a decision. Built on Base UI's Dialog, which owns the behavior: focus moves into the dialog and stays there, the page behind is
|
|
5
|
+
A modal panel over the page for one short task: edit a name, fill a small form, read details that need a decision. Built on Base UI's Dialog, which owns the behavior: focus moves into the dialog and stays there, the page behind is hidden from assistive tech and does not scroll, Esc and a click on the backdrop close it, and focus returns to the trigger. The parts add the look: a dimmed backdrop, a raised panel with a title, and a zoom-and-fade that is a plain fade under reduced motion.
|
|
6
6
|
|
|
7
7
|
## When to use
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ A modal panel over the page for one short task: edit a name, fill a small form,
|
|
|
13
13
|
|
|
14
14
|
- Confirming something destructive or irreversible: use `AlertDialog`, which focuses Cancel and ignores outside clicks.
|
|
15
15
|
- A list of actions: use `Menu`.
|
|
16
|
-
- Content the user wants beside the page, or a hint: use
|
|
16
|
+
- Content the user wants beside the page, or a hint: use `Popover` or inline text; a modal blocks the page.
|
|
17
17
|
- A long flow or a lot of content: give it a page.
|
|
18
18
|
- A status message or the result of an action: use `Toast`, which leaves focus where it is; a dialog takes it.
|
|
19
19
|
|
|
@@ -29,6 +29,7 @@ A modal panel over the page for one short task: edit a name, fill a small form,
|
|
|
29
29
|
- Control it with `open` and `onOpenChange` to close it after a save or keep it open on an error. `onOpenChangeComplete` runs once the exit transition ends.
|
|
30
30
|
- The popup portals into the trigger's nearest `ThemeProvider`, so it keeps the brand and mode. That provider must not clip or stack its content: wrap the app root, and keep a nested provider off elements with `overflow: hidden`, a `transform` or their own `z-index`. It sits on `zIndex` `modal`. A dialog opened only through `open`, with no `Dialog.Trigger`, has no provider to find and portals to `<body>`.
|
|
31
31
|
- It is always modal. Never add key handlers, `tabIndex` or your own focus trap to the parts.
|
|
32
|
+
- `finalFocus` on `Dialog.Popup` sends focus elsewhere on close. A ref, to the focusable control itself, gets focus at once, with a visible focus ring after a key, and an empty one falls back to the trigger; a function's target gets focus when the fade ends; `false` returns no focus (ADR 0192).
|
|
32
33
|
- The module has no hooks, so a server component can render the parts; `onOpenChange` and other functions must come from a client component.
|
|
33
34
|
|
|
34
35
|
## Do
|
|
@@ -98,10 +99,33 @@ const [open, setOpen] = useState(false);
|
|
|
98
99
|
## Accessibility
|
|
99
100
|
|
|
100
101
|
- The trigger has `aria-haspopup="dialog"` and `aria-expanded`. The popup is `role="dialog"` with `aria-modal`, labelled by the title and described by the description.
|
|
101
|
-
- Opening moves focus into the popup; Tab and Shift+Tab cycle inside it, and the page behind is
|
|
102
|
+
- Opening moves focus into the popup; Tab and Shift+Tab cycle inside it, and the page behind is `aria-hidden`. Esc or a backdrop click closes it, and focus returns to the trigger.
|
|
102
103
|
- A closed dialog stays on the page while it fades out, but is `inert` and `aria-hidden` from the moment it closes, and focus is back on the trigger at once, so a dialog opened during the fade is the only one a screen reader or a role query finds, and nothing in the fading one takes focus or a click (ADR 0113).
|
|
103
104
|
- The panel takes the shared focus ring when focused from the keyboard. Under forced colors it keeps its border, so it stays apart from the page.
|
|
104
|
-
- The backdrop is
|
|
105
|
+
- The backdrop is the `backdrop` color role over the page; it only dims, and carries no text. In the presets that is 40% near-black in light mode and 70% black in dark. Under forced colors it has no fill.
|
|
106
|
+
|
|
107
|
+
## Theming
|
|
108
|
+
|
|
109
|
+
To change how far the backdrop dims, set the `backdrop` color role in the brand you pass to `defineTheme`, or override `--color-backdrop` on `[data-brand]` from `@layer app` under a preset. A rule on `:root` has no effect, since the brand's own block is closer. No selector on the portal's DOM is needed.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
const theme = defineTheme({
|
|
113
|
+
...defaultBrand,
|
|
114
|
+
name: "inbox",
|
|
115
|
+
color: {
|
|
116
|
+
...defaultBrand.color,
|
|
117
|
+
backdrop: "light-dark(oklch(0.145 0 0 / 0.5), oklch(0 0 0 / 0.8))",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```css
|
|
123
|
+
@layer app {
|
|
124
|
+
[data-brand] {
|
|
125
|
+
--color-backdrop: light-dark(oklch(0.145 0 0 / 0.5), oklch(0 0 0 / 0.8));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
105
129
|
|
|
106
130
|
## Props
|
|
107
131
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Flex
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
The flex primitive `Stack` and `Inline` are built from: a `Box` with `display="flex"` as a default style prop. It takes every `Box` prop, adds none, and has no class of its own, so `<Flex>` renders exactly `<Box display="flex">`.
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- Building a layout component that is a flex container, as `Stack` and `Inline` are.
|
|
10
|
+
- Almost never in an app: `Flex` there, like `display: flex` in a stylesheet, is a code smell, since a flex layout is a `Stack` or an `Inline`.
|
|
11
|
+
|
|
12
|
+
## When not to use
|
|
13
|
+
|
|
14
|
+
- A column of children with a gap: use `Stack`.
|
|
15
|
+
- A row of children with a gap, wrapping or not: use `Inline` (`flexWrap="nowrap"` keeps it on one line).
|
|
16
|
+
- A row whose ends sit apart, such as a title and its actions: use `Inline` with `flexWrap="nowrap"` and `justifyContent="space-between"`.
|
|
17
|
+
- A two-dimensional layout: use `Box` with `display="grid"`.
|
|
18
|
+
- A page with a sidebar: use `SidebarLayout`.
|
|
19
|
+
- A surface with padding or a background and no flex layout: use `Box`.
|
|
20
|
+
|
|
21
|
+
## Rules
|
|
22
|
+
|
|
23
|
+
- `display` defaults to `flex`; set it to override, such as `display={{ base: "none", med: "flex" }}`. `null` or `false` drops it, as on `Box`.
|
|
24
|
+
- There are no shorthand props such as `direction` or `align`: use the style props `flexDirection`, `alignItems`, `justifyContent`, `flexWrap` and `gap`.
|
|
25
|
+
- Polymorphic with `as`; the consumer's `className` and `style` pass through, and `ref` is a plain prop typed for the `as` element.
|
|
26
|
+
|
|
27
|
+
## Do
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<Inline flexWrap="nowrap" gap="8" justifyContent="space-between">
|
|
31
|
+
<Heading>Invoices</Heading>
|
|
32
|
+
<Button>New invoice</Button>
|
|
33
|
+
</Inline>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
// Building a layout component: Flex with its layout as default style props, as Stack is.
|
|
38
|
+
function Cluster<T extends ElementType = "div">({ flexWrap = "wrap", ...props }: FlexProps<T>) {
|
|
39
|
+
return <Flex<ElementType> flexWrap={flexWrap} {...props} />;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Don't
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
// Flex rebuilding Stack: use `<Stack gap="16">`.
|
|
47
|
+
<Flex flexDirection="column" gap="16">
|
|
48
|
+
<Label>Name</Label>
|
|
49
|
+
<Label>Email</Label>
|
|
50
|
+
</Flex>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
// Flex rebuilding Inline: use `<Inline gap="8">`.
|
|
55
|
+
<Flex alignItems="center" flexWrap="wrap" gap="8">
|
|
56
|
+
<Tag>design</Tag>
|
|
57
|
+
<Tag>tokens</Tag>
|
|
58
|
+
</Flex>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Accessibility
|
|
62
|
+
|
|
63
|
+
- Flex adds no role or ARIA. Pick the element with `as`.
|
|
64
|
+
- Visual order is source order; do not reverse it with `flexDirection` to reorder meaningful content, since reading and focus order follow the source.
|
|
65
|
+
|
|
66
|
+
## Props
|
|
67
|
+
|
|
68
|
+
Generated from the TypeScript types.
|
|
69
|
+
|
|
70
|
+
### Flex
|
|
71
|
+
|
|
72
|
+
| Prop | Type | Required | Description |
|
|
73
|
+
| --- | --- | --- | --- |
|
|
74
|
+
| `as` | `ElementType` | no | |
|
|
75
|
+
|
|
76
|
+
Also accepts every `<div>` attribute (change the element with `as`) and the style props (see `manifest.json` `styleProps`).
|
package/dist/docs/Heading.md
CHANGED
|
@@ -16,7 +16,7 @@ Section and page headings. A `Text` with heading defaults: the `heading` font ro
|
|
|
16
16
|
## Rules
|
|
17
17
|
|
|
18
18
|
- `as` is the level, `h1` to `h6`; the default is `h2`. Pick it from the outline, not the look.
|
|
19
|
-
- `size` is the look: `sm`, `med`, `lg`, `xl` or `
|
|
19
|
+
- `size` is the look: `sm`, `med`, `lg`, `xl`, `2xl` or `3xl`. Unset, it follows the level: `h1` `2xl` (set `3xl` for a larger page title), `h2` `xl`, `h3` `lg`, `h4` `med`, `h5` and `h6` `sm`.
|
|
20
20
|
- Heading takes every other Text prop (`font`, `weight`, `leading`, `color`, `truncate`, style props) and overrides its defaults with them.
|
|
21
21
|
- One `h1` per page; do not skip levels going down.
|
|
22
22
|
|
|
@@ -41,7 +41,7 @@ Section and page headings. A `Text` with heading defaults: the `heading` font ro
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
|
-
// Headings stop at
|
|
44
|
+
// Headings stop at 3xl; for display type use Text.
|
|
45
45
|
<Heading size="4xl" />
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -62,7 +62,7 @@ Generated from the TypeScript types.
|
|
|
62
62
|
| `as` | `"h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6"` | no | |
|
|
63
63
|
| `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
|
|
64
64
|
| `leading` | `"body" \| "lg" \| "med" \| "meta" \| "sm"` | no | |
|
|
65
|
-
| `size` | `"2xl" \| "lg" \| "med" \| "sm" \| "xl"` | no | |
|
|
65
|
+
| `size` | `"2xl" \| "3xl" \| "lg" \| "med" \| "sm" \| "xl"` | no | |
|
|
66
66
|
| `tabularNums` | `boolean` | no | |
|
|
67
67
|
| `truncate` | `"box" \| boolean` | no | |
|
|
68
68
|
| `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
|
package/dist/docs/Icon.md
CHANGED
|
@@ -103,6 +103,7 @@ Generated from `src/icons/svg/` and exported from `@jonmilner/ui/icons`; each ta
|
|
|
103
103
|
- `SearchIcon` (`search.svg`)
|
|
104
104
|
- `SettingsIcon` (`settings.svg`)
|
|
105
105
|
- `Trash2Icon` (`trash-2.svg`)
|
|
106
|
+
- `TriangleAlertIcon` (`triangle-alert.svg`)
|
|
106
107
|
- `XIcon` (`x.svg`)
|
|
107
108
|
|
|
108
109
|
<!-- icons:end -->
|