@k8ordo/ui 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -182
- package/dist/{integrations/_shared → catalog}/icon-map.d.mts +4 -2
- package/dist/catalog/icon-map.mjs +212 -0
- package/dist/catalog/icon-names.d.mts +1 -0
- package/dist/{integrations/_shared → catalog}/icon-names.mjs +3 -1
- package/dist/catalog/index.d.mts +1289 -0
- package/dist/catalog/index.mjs +419 -0
- package/dist/catalog/render.css +34 -0
- package/dist/catalog/render.d.mts +72 -0
- package/dist/catalog/render.mjs +631 -0
- package/dist/catalog/render.module.mjs +11 -0
- package/dist/{integrations/_shared → catalog}/schemas.d.mts +120 -132
- package/dist/{integrations/_shared → catalog}/schemas.mjs +189 -131
- package/dist/catalog/to-tree.d.mts +4 -0
- package/dist/catalog/to-tree.mjs +17 -0
- package/dist/components/_internal/checked-values.d.mts +1 -0
- package/dist/components/_internal/checked-values.mjs +5 -0
- package/dist/components/_internal/field-message.css +25 -0
- package/dist/components/_internal/field-message.d.mts +10 -0
- package/dist/components/_internal/field-message.mjs +22 -0
- package/dist/components/_internal/field-message.module.mjs +9 -0
- package/dist/components/_internal/focus-ring.css +1 -1
- package/dist/components/_internal/high-contrast.css +1 -0
- package/dist/components/{observers/in-view → _internal}/in-view.mjs +1 -1
- package/dist/components/{observers/resize → _internal}/resize.mjs +1 -1
- package/dist/components/ai/_internal/attachment-preview.mjs +1 -1
- package/dist/components/ai/_internal/collapsible.mjs +1 -1
- package/dist/components/ai/attachment/attachment.d.mts +1 -1
- package/dist/components/ai/attachment/index.d.mts +1 -1
- package/dist/components/ai/conversation/conversation.mjs +4 -4
- package/dist/components/ai/index.d.mts +2 -2
- package/dist/components/ai/message/index.d.mts +2 -2
- package/dist/components/ai/message/message.d.mts +2 -2
- package/dist/components/ai/message/message.mjs +9 -9
- package/dist/components/ai/prompt-input/prompt-input.mjs +4 -4
- package/dist/components/ai/source/index.d.mts +2 -2
- package/dist/components/ai/source/source.d.mts +2 -2
- package/dist/components/ai/source/source.mjs +1 -1
- package/dist/components/ai/tool-invocation/approval-bar.mjs +11 -22
- package/dist/components/ai/tool-invocation/tool-invocation.d.mts +2 -2
- package/dist/components/buttons/button/button.css +1 -1
- package/dist/components/buttons/button/button.d.mts +34 -37
- package/dist/components/buttons/button/button.mjs +37 -24
- package/dist/components/buttons/button/button.module.mjs +0 -1
- package/dist/components/buttons/button/index.d.mts +2 -2
- package/dist/components/buttons/copy-button/copy-button.mjs +4 -4
- package/dist/components/buttons/icon-button/icon-button.css +3 -3
- package/dist/components/buttons/icon-button/icon-button.d.mts +37 -43
- package/dist/components/buttons/icon-button/icon-button.mjs +73 -63
- package/dist/components/buttons/icon-button/icon-button.module.mjs +2 -2
- package/dist/components/buttons/icon-button/index.d.mts +2 -2
- package/dist/components/buttons/toolbar/toolbar.css +5 -1
- package/dist/components/buttons/toolbar/toolbar.mjs +1 -1
- package/dist/components/data-display/accordion/accordion-button.d.mts +4 -1
- package/dist/components/data-display/accordion/accordion-button.mjs +4 -4
- package/dist/components/data-display/accordion/index.d.mts +3 -3
- package/dist/components/data-display/card/card-action.d.mts +6 -0
- package/dist/components/data-display/card/card-action.mjs +21 -0
- package/dist/components/data-display/card/card.css +24 -0
- package/dist/components/data-display/card/card.d.mts +26 -3
- package/dist/components/data-display/card/card.mjs +46 -6
- package/dist/components/data-display/card/card.module.mjs +4 -1
- package/dist/components/data-display/card/index.d.mts +2 -2
- package/dist/components/data-display/carousel/carousel.mjs +2 -2
- package/dist/components/data-display/code/code.css +4 -0
- package/dist/components/data-display/code-block/code-block.mjs +1 -1
- package/dist/components/data-display/data-table/data-table.css +0 -3
- package/dist/components/data-display/data-table/data-table.mjs +25 -26
- package/dist/components/data-display/tree/tree.d.mts +1 -1
- package/dist/components/data-display/tree/tree.mjs +6 -5
- package/dist/components/feedback/alert/alert.d.mts +2 -7
- package/dist/components/feedback/alert/alert.mjs +11 -11
- package/dist/components/feedback/alert/index.d.mts +2 -2
- package/dist/components/feedback/callout/callout.mjs +2 -2
- package/dist/components/feedback/progress/progress.mjs +1 -1
- package/dist/components/feedback/toast/context.d.mts +4 -5
- package/dist/components/feedback/toast/index.d.mts +2 -2
- package/dist/components/feedback/toast/provider.d.mts +7 -2
- package/dist/components/feedback/toast/provider.mjs +7 -2
- package/dist/components/feedback/toast/toast.d.mts +2 -3
- package/dist/components/form/autocomplete/autocomplete.d.mts +2 -2
- package/dist/components/form/autocomplete/autocomplete.mjs +12 -9
- package/dist/components/form/calendar/calendar.mjs +3 -5
- package/dist/components/form/checkbox/checkbox.d.mts +3 -1
- package/dist/components/form/checkbox/checkbox.mjs +44 -45
- package/dist/components/form/checkbox-card/checkbox-card.d.mts +3 -2
- package/dist/components/form/checkbox-card/checkbox-card.mjs +13 -6
- package/dist/components/form/checkbox-group/checkbox-group.d.mts +15 -20
- package/dist/components/form/checkbox-group/checkbox-group.mjs +18 -26
- package/dist/components/form/checkbox-group/index.d.mts +2 -34
- package/dist/components/form/checkbox-group/index.mjs +1 -8
- package/dist/components/form/color-picker/color-picker.css +3 -5
- package/dist/components/form/color-picker/color-picker.d.mts +0 -1
- package/dist/components/form/color-picker/color-picker.mjs +4 -4
- package/dist/components/form/combobox/combobox.d.mts +0 -1
- package/dist/components/form/combobox/combobox.mjs +9 -8
- package/dist/components/form/date-picker/date-picker.css +0 -5
- package/dist/components/form/date-picker/date-picker.mjs +21 -22
- package/dist/components/form/file-field/file-field.d.mts +6 -3
- package/dist/components/form/file-field/file-field.mjs +41 -18
- package/dist/components/form/file-field/index.d.mts +4 -1
- package/dist/components/form/form/form.mjs +0 -1
- package/dist/components/form/form-control/form-control.css +0 -15
- package/dist/components/form/form-control/form-control.d.mts +3 -4
- package/dist/components/form/form-control/form-control.mjs +44 -46
- package/dist/components/form/form-control/form-control.module.mjs +0 -3
- package/dist/components/form/number-field/number-field.d.mts +2 -2
- package/dist/components/form/number-field/number-field.mjs +13 -52
- package/dist/components/form/password-input/password-input.mjs +1 -1
- package/dist/components/form/radio/radio.mjs +4 -2
- package/dist/components/form/radio-card/radio-card.mjs +9 -2
- package/dist/components/form/range-slider/range-slider.d.mts +4 -2
- package/dist/components/form/range-slider/range-slider.mjs +2 -4
- package/dist/components/form/select/select.css +6 -4
- package/dist/components/form/select/select.d.mts +5 -0
- package/dist/components/form/select/select.mjs +10 -7
- package/dist/components/form/slider/slider.d.mts +2 -2
- package/dist/components/form/slider/slider.mjs +3 -6
- package/dist/components/form/switch/switch.d.mts +3 -0
- package/dist/components/form/switch/switch.mjs +43 -31
- package/dist/components/form/text-field/index.d.mts +2 -2
- package/dist/components/form/text-field/text-field.css +4 -0
- package/dist/components/form/text-field/text-field.d.mts +1 -1
- package/dist/components/form/textarea/textarea.d.mts +0 -1
- package/dist/components/form/textarea/textarea.mjs +1 -1
- package/dist/components/icons/base.d.mts +0 -1
- package/dist/components/icons/base.mjs +1 -2
- package/dist/components/icons/clipboard-check.d.mts +3 -0
- package/dist/components/icons/clipboard-check.mjs +18 -0
- package/dist/components/icons/git-pull-request.d.mts +3 -0
- package/dist/components/icons/git-pull-request.mjs +20 -0
- package/dist/components/icons/index.d.mts +9 -7
- package/dist/components/icons/index.mjs +30 -28
- package/dist/components/index.d.mts +58 -66
- package/dist/components/index.mjs +13 -19
- package/dist/components/layout/resizable-panels/resizable-panels.mjs +3 -3
- package/dist/components/navigation/anchor/anchor.css +3 -3
- package/dist/components/navigation/anchor/anchor.mjs +20 -7
- package/dist/components/navigation/anchor/anchor.module.mjs +1 -1
- package/dist/components/navigation/breadcrumb/breadcrumb.d.mts +6 -4
- package/dist/components/navigation/breadcrumb/breadcrumb.mjs +3 -2
- package/dist/components/navigation/pagination/pagination.d.mts +2 -2
- package/dist/components/navigation/pagination/pagination.mjs +2 -2
- package/dist/components/navigation/side-nav/side-nav.mjs +1 -1
- package/dist/components/navigation/stepper/stepper.mjs +3 -3
- package/dist/components/navigation/tabs/index.d.mts +10 -5
- package/dist/components/navigation/tabs/tabs.d.mts +11 -6
- package/dist/components/navigation/tabs/tabs.mjs +24 -27
- package/dist/components/overlays/_internal/modal-header.css +38 -0
- package/dist/components/overlays/_internal/modal-header.d.mts +7 -0
- package/dist/components/overlays/_internal/modal-header.mjs +32 -0
- package/dist/components/overlays/_internal/modal-header.module.mjs +10 -0
- package/dist/components/overlays/command-palette/command-palette.d.mts +2 -2
- package/dist/components/overlays/command-palette/command-palette.mjs +9 -8
- package/dist/components/overlays/context-menu/context-menu.mjs +3 -3
- package/dist/components/overlays/context-menu/index.d.mts +27 -2
- package/dist/components/overlays/dialog/dialog.css +3 -21
- package/dist/components/overlays/dialog/dialog.d.mts +20 -9
- package/dist/components/overlays/dialog/dialog.mjs +35 -73
- package/dist/components/overlays/dialog/dialog.module.mjs +1 -3
- package/dist/components/overlays/dialog/index.d.mts +2 -15
- package/dist/components/overlays/dialog/index.mjs +1 -8
- package/dist/components/overlays/drawer/drawer.css +4 -26
- package/dist/components/overlays/drawer/drawer.d.mts +7 -2
- package/dist/components/overlays/drawer/drawer.mjs +24 -37
- package/dist/components/overlays/drawer/drawer.module.mjs +2 -6
- package/dist/components/overlays/dropdown-menu/dropdown-menu.d.mts +35 -5
- package/dist/components/overlays/dropdown-menu/dropdown-menu.mjs +29 -11
- package/dist/components/overlays/dropdown-menu/hooks.d.mts +1 -1
- package/dist/components/overlays/dropdown-menu/hooks.mjs +1 -1
- package/dist/components/overlays/dropdown-menu/index.d.mts +34 -4
- package/dist/components/overlays/dropdown-menu/shared.css +1 -0
- package/dist/components/overlays/dropdown-menu/sub-menu.mjs +4 -4
- package/dist/components/overlays/list-box/hooks.mjs +2 -2
- package/dist/components/overlays/list-box/index.d.mts +2 -25
- package/dist/components/overlays/list-box/index.mjs +1 -9
- package/dist/components/overlays/list-box/list-box.d.mts +11 -16
- package/dist/components/overlays/list-box/list-box.mjs +23 -16
- package/dist/components/overlays/modal/modal.d.mts +8 -7
- package/dist/components/overlays/modal/modal.mjs +23 -32
- package/dist/components/overlays/popover/anchor-positioning.d.mts +3 -16
- package/dist/components/overlays/popover/anchor-positioning.mjs +14 -6
- package/dist/components/overlays/popover/hooks.d.mts +0 -2
- package/dist/components/overlays/popover/hooks.mjs +0 -2
- package/dist/components/overlays/popover/index.d.mts +19 -2
- package/dist/components/overlays/popover/index.mjs +7 -2
- package/dist/components/overlays/popover/popover.css +6 -0
- package/dist/components/overlays/popover/popover.d.mts +15 -2
- package/dist/components/overlays/popover/popover.mjs +28 -13
- package/dist/components/overlays/popover/popover.module.mjs +2 -1
- package/dist/components/overlays/tooltip/bridge.css +1 -1
- package/dist/components/overlays/tooltip/tooltip.mjs +5 -5
- package/dist/helpers/index.mjs +1 -1
- package/dist/i18n/en.mjs +1 -2
- package/dist/i18n/index.d.mts +3 -4
- package/dist/i18n/index.mjs +1 -2
- package/dist/i18n/ja.mjs +1 -2
- package/dist/i18n/messages.d.mts +2 -4
- package/dist/i18n/usage.d.mts +2 -1
- package/dist/i18n/usage.mjs +3 -3
- package/dist/index.d.mts +30 -36
- package/dist/index.mjs +4 -10
- package/dist/internal/iso-date.mjs +1 -1
- package/dist/styles/index.css +79 -225
- package/dist/styles/tailwind.css +1 -1
- package/dist/styles/tokens.css +281 -0
- package/dist/styles/tokens.d.mts +1 -1
- package/dist/styles/tokens.mjs +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/variables.d.mts +4 -2
- package/docs/GUIDE.md +141 -66
- package/docs/llms.txt +38 -11
- package/docs/props.generated.json +752 -481
- package/docs/references/ai-chat.md +87 -39
- package/docs/references/color.md +15 -15
- package/docs/references/components.md +568 -499
- package/docs/references/generative-ui.md +373 -185
- package/docs/references/interaction-design.md +6 -5
- package/docs/references/spatial-design.md +8 -8
- package/docs/references/types.md +22 -25
- package/package.json +37 -70
- package/dist/components/form/date-field/date-field.css +0 -31
- package/dist/components/form/date-field/date-field.d.mts +0 -7
- package/dist/components/form/date-field/date-field.mjs +0 -19
- package/dist/components/form/date-field/date-field.module.mjs +0 -4
- package/dist/components/form/date-field/index.d.mts +0 -2
- package/dist/components/form/date-field/index.mjs +0 -1
- package/dist/components/observers/in-view/index.d.mts +0 -2
- package/dist/components/observers/in-view/index.mjs +0 -1
- package/dist/components/observers/resize/index.d.mts +0 -2
- package/dist/components/observers/resize/index.mjs +0 -1
- package/dist/components/overlays/_internal/modal-dialog-context.d.mts +0 -11
- package/dist/components/overlays/_internal/modal-dialog-context.mjs +0 -12
- package/dist/components/providers/index.d.mts +0 -3
- package/dist/components/providers/index.mjs +0 -3
- package/dist/components/providers/portal-root.d.mts +0 -8
- package/dist/components/providers/portal-root.mjs +0 -11
- package/dist/components/providers/ui-provider.d.mts +0 -2
- package/dist/components/providers/ui-provider.mjs +0 -6
- package/dist/integrations/_shared/icon-map.mjs +0 -208
- package/dist/integrations/_shared/icon-names.d.mts +0 -1
- package/dist/integrations/_shared/openui-defs.d.mts +0 -15
- package/dist/integrations/_shared/openui-defs.mjs +0 -230
- package/dist/integrations/_shared/renderers.css +0 -50
- package/dist/integrations/_shared/renderers.d.mts +0 -88
- package/dist/integrations/_shared/renderers.mjs +0 -880
- package/dist/integrations/_shared/renderers.module.mjs +0 -13
- package/dist/integrations/ai-sdk/index.d.mts +0 -3
- package/dist/integrations/ai-sdk/index.mjs +0 -1
- package/dist/integrations/ai-sdk/map-parts.d.mts +0 -44
- package/dist/integrations/ai-sdk/map-parts.mjs +0 -56
- package/dist/integrations/json-render/catalog.d.mts +0 -1359
- package/dist/integrations/json-render/catalog.mjs +0 -373
- package/dist/integrations/json-render/registry.d.mts +0 -26
- package/dist/integrations/json-render/registry.mjs +0 -192
- package/dist/integrations/openui/form-views.d.mts +0 -24
- package/dist/integrations/openui/form-views.mjs +0 -89
- package/dist/integrations/openui/library.d.mts +0 -202
- package/dist/integrations/openui/library.mjs +0 -83
- package/dist/integrations/openui/prompt.d.mts +0 -2
- package/dist/integrations/openui/prompt.mjs +0 -18
- /package/dist/components/{observers → _internal}/fragment-instance.d.mts +0 -0
- /package/dist/components/{observers/in-view → _internal}/in-view.d.mts +0 -0
- /package/dist/components/{observers/resize → _internal}/resize.d.mts +0 -0
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// The stylesheet (required). In a Tailwind CSS 4 project, a CSS file
|
|
7
7
|
// imports 'tailwindcss' and then '@k8ordo/ui/tailwind.css' instead
|
|
8
8
|
import '@k8ordo/ui/styles.css';
|
|
9
|
-
// The provider (once, at the app root)
|
|
10
|
-
import {
|
|
9
|
+
// The provider for toasts (once, at the app root, when you use useToast)
|
|
10
|
+
import { ToastProvider } from '@k8ordo/ui';
|
|
11
11
|
// Components (all from the root entry)
|
|
12
12
|
import { Button, Card, TextField } from '@k8ordo/ui';
|
|
13
13
|
// And CodeBlock, which highlights on the server and has its own entry
|
|
@@ -17,58 +17,64 @@ import { CheckIcon } from '@k8ordo/ui/icons';
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Every component can be rendered from a Server Component, compound ones
|
|
20
|
-
included: `
|
|
20
|
+
included: `Tabs.Root`, `Accordion.Item`, `Popover.Trigger`, and the rest are
|
|
21
21
|
composed outside the client modules, so the parts resolve on the server. Only
|
|
22
22
|
the interactive parts carry `'use client'`.
|
|
23
23
|
|
|
24
|
+
What a Server Component cannot do is pass a client part a function other
|
|
25
|
+
than a Server Action. A part whose required prop is a function — the
|
|
26
|
+
`renderItem` of `Popover.Trigger`, `Tooltip.Trigger`, `ContextMenu.Trigger`,
|
|
27
|
+
`Toolbar.Item`, and `FileField.Trigger`, `DataTable`'s `getRowId` and a
|
|
28
|
+
column's `cell` — is rendered from a Client Component, as is any part given
|
|
29
|
+
`onChange` or another handler. `FormControl` and `Form` are not client
|
|
30
|
+
modules: a Server Component renders them with `renderInput` and with a Server
|
|
31
|
+
Action as `action`, and only the fields inside are client parts.
|
|
32
|
+
|
|
24
33
|
## Render props
|
|
25
34
|
|
|
26
35
|
Two different contracts are spelled `render*`, and mixing them up is the usual
|
|
27
36
|
source of surprise.
|
|
28
37
|
|
|
29
|
-
**Replacing the element** — `
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
navigate. The examples below name them `_disabled` / `_type` so the discarded
|
|
45
|
-
bindings pass a `no-unused-vars` rule.
|
|
46
|
-
- `disabled` is only the `disabled` you passed. While an action is pending (see
|
|
47
|
-
[Button](#button)), the bag carries `aria-disabled` and `aria-busy` but
|
|
48
|
-
`disabled` stays `false`, so the pressed element keeps focus; the supplied
|
|
49
|
-
`onClick` is what ignores presses meanwhile.
|
|
50
|
-
- Spreading onto a real `<button>` is exact, but write `type` on the element
|
|
51
|
-
anyway: the `button-has-type` lint rule cannot see a `type` that arrives
|
|
52
|
-
through a spread.
|
|
53
|
-
|
|
54
|
-
The link components own less, so their bags are smaller:
|
|
55
|
-
|
|
56
|
-
- `Anchor` hands back `href`, `className`, `children` (with the new-tab icon on
|
|
57
|
-
an external link), `target` / `rel` on an external link, and every other
|
|
38
|
+
**Replacing the element** — `renderAnchor` on `Button` and `IconButton` (with
|
|
39
|
+
`href`), `Anchor`, `Breadcrumb.Link`, `SideNav.Link`, `DropdownMenu.Item` /
|
|
40
|
+
`ContextMenu.Item` (with `href`), and `Card` (with `href`). The component computes
|
|
41
|
+
everything and hands back the exact props it would have put on its own `<a>`,
|
|
42
|
+
so substituting a framework `<Link>` loses nothing. Spread the bag onto whatever
|
|
43
|
+
you render.
|
|
44
|
+
|
|
45
|
+
- `Button` and `IconButton` hand back `href`, `className`, the composed
|
|
46
|
+
`children` (icons included), `ref`, `onClick`, `aria-disabled`, and every
|
|
47
|
+
anchor attribute the caller passed. `IconButton` adds `aria-label` and the
|
|
48
|
+
tooltip's handlers, chained with any the caller passed. While `disabled`, the
|
|
49
|
+
supplied `onClick` calls `preventDefault()`, so the link does not navigate.
|
|
50
|
+
- `Anchor` hands back `href`, `className`, `children` (with the new-tab icon
|
|
51
|
+
and the visually hidden new-tab wording on an external link), `target` /
|
|
52
|
+
`rel` on an external link, and every other
|
|
58
53
|
anchor attribute the caller passed, plus `kind` (`'internal'` |
|
|
59
54
|
`'external'`). `kind` is not an attribute: destructure it away before
|
|
60
55
|
spreading, or use it to choose between a framework `<Link>` and a plain `<a>`.
|
|
61
56
|
There is no `ref` and no disabled state.
|
|
62
|
-
- `Breadcrumb.Link` hands back `href`, `className`,
|
|
63
|
-
|
|
64
|
-
`<span aria-current="page"
|
|
57
|
+
- `Breadcrumb.Link` hands back `href`, `className`, `children`, and every other
|
|
58
|
+
anchor attribute the caller passed. A `current` link renders
|
|
59
|
+
`<span aria-current="page">`, without those attributes, and does not call
|
|
60
|
+
`renderAnchor`.
|
|
65
61
|
- `SideNav.Link` hands back `href`, `className`, `children`, `aria-current`
|
|
66
62
|
(`'page'` on the current link), and every other anchor attribute the caller
|
|
67
63
|
passed. A current link is still a link.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`
|
|
71
|
-
|
|
64
|
+
- `DropdownMenu.Item` and `ContextMenu.Item` hand back `href`, `className`,
|
|
65
|
+
`children` (the `label`), `role` (`'menuitem'`), and the keyboard wiring
|
|
66
|
+
(`id`, `ref`, `tabIndex`, `onFocus`, `onClick`, `onKeyDown`). Spread all of
|
|
67
|
+
it: the wiring is what moves the arrow keys onto the item, closes the menu
|
|
68
|
+
when it is chosen, and lets Space choose it.
|
|
69
|
+
- `Card` hands back `href`, `className`, `aria-labelledby`, and `target` /
|
|
70
|
+
`rel` with `openInNewTab` (`CardRenderAnchorProps`). There are no
|
|
71
|
+
`children`: the link lies over the card's content and takes its name from
|
|
72
|
+
`aria-labelledby`, which with `openInNewTab` also points at the hidden
|
|
73
|
+
new-tab wording.
|
|
74
|
+
|
|
75
|
+
**Filling a slot** — `renderInput` on `FormControl`, and `renderItem` on
|
|
76
|
+
`Popover.Trigger`, `Tooltip.Trigger` and `FileField.Trigger`. Here the
|
|
77
|
+
component owns no element of its own. It computes wiring —
|
|
72
78
|
ids, ARIA relationships, open/close handlers — and you supply the element that
|
|
73
79
|
wiring belongs to. Those bags carry only the wiring, and they are required
|
|
74
80
|
rather than optional.
|
|
@@ -84,11 +90,12 @@ import { Button } from '@k8ordo/ui';
|
|
|
84
90
|
size="sm" | "md" | "lg"
|
|
85
91
|
color="primary" | "secondary" | "base"
|
|
86
92
|
variant="solid" | "outline" | "skeleton"
|
|
93
|
+
type="button" | "submit" | "reset"
|
|
87
94
|
fullWidth={false}
|
|
88
95
|
startIcon={<Icon />}
|
|
89
96
|
endIcon={<Icon />}
|
|
90
97
|
disabled={false}
|
|
91
|
-
|
|
98
|
+
action={async () => {}}
|
|
92
99
|
>
|
|
93
100
|
Button
|
|
94
101
|
</Button>
|
|
@@ -96,98 +103,103 @@ import { Button } from '@k8ordo/ui';
|
|
|
96
103
|
|
|
97
104
|
Props:
|
|
98
105
|
|
|
106
|
+
- `action`: `() => void | Promise<void>`
|
|
99
107
|
- `children`: `ReactNode`
|
|
100
108
|
- `color`: `'primary'` | `'secondary'` | `'base'` (default: `'primary'`)
|
|
109
|
+
- `disabled`: `boolean` (default: `false`)
|
|
101
110
|
- `endIcon`: `ReactNode`
|
|
102
111
|
- `fullWidth`: `boolean` (default: `false`)
|
|
103
|
-
- `
|
|
104
|
-
- `
|
|
105
|
-
- `renderItem`: `(props: ButtonRenderItemProps) => ReactNode`
|
|
112
|
+
- `href`: `T`
|
|
113
|
+
- `renderAnchor`: `(props: RenderAnchorProps<T>) => ReactNode`
|
|
106
114
|
- `size`: `'sm'` | `'md'` | `'lg'` (default: `'md'`)
|
|
107
115
|
- `startIcon`: `ReactNode`
|
|
108
|
-
- `type`: `'button'` | `'submit'` (default: `'button'`)
|
|
116
|
+
- `type`: `'button'` | `'submit'` | `'reset'` (default: `'button'`)
|
|
109
117
|
- `variant`: `'solid'` | `'outline'` | `'skeleton'` (default: `'solid'`)
|
|
110
|
-
- Other props are forwarded to `ComponentPropsWithRef<'button'>`, except `className` / `style`.
|
|
118
|
+
- Other props are forwarded to `ComponentPropsWithRef<'button'> | ComponentPropsWithRef<'a'>`, except `className` / `style` / `aria-disabled`.
|
|
111
119
|
|
|
112
|
-
`
|
|
120
|
+
`action` runs inside a transition. While the promise it returns is pending —
|
|
113
121
|
and, with `type="submit"`, while the form's action is pending — the button shows
|
|
114
122
|
a spinner, carries `aria-busy` and `aria-disabled`, and ignores presses,
|
|
115
123
|
including the implicit submission of pressing Enter in a field. It does not
|
|
116
124
|
become natively `disabled`: Chromium moves focus to `body` when the focused
|
|
117
125
|
element is disabled, so a keyboard user who pressed the button would lose their
|
|
118
126
|
place. The `disabled` you pass is native, and takes the button out of the tab
|
|
119
|
-
order.
|
|
120
|
-
|
|
121
|
-
`
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
order. A synchronous update a user may press again at once belongs in
|
|
128
|
+
`onClick`, since `action` ignores presses while its transition is pending. Only
|
|
129
|
+
`type="submit"` follows the form's pending state; `type="reset"` resets the
|
|
130
|
+
form it belongs to.
|
|
131
|
+
|
|
132
|
+
A skeleton `Button` shows its state in the text color. A toggle passes
|
|
133
|
+
`aria-pressed` and a link to the current page passes `aria-current`; the text
|
|
134
|
+
then takes the info color. The state lives in the ARIA attribute, so assistive
|
|
135
|
+
technology hears what the color shows. Inside a `Toolbar` the toolbar shows a
|
|
136
|
+
pressed item by its ground instead, and the text is `fg-base` (see
|
|
137
|
+
[Toolbar](#toolbar)). A solid or outline toggle has no pressed look of its own;
|
|
138
|
+
switch its `variant` or `color` with the state.
|
|
139
|
+
|
|
140
|
+
With `href`, `Button` renders an `<a>` with the same look. That form takes
|
|
141
|
+
anchor attributes (`target`, `rel`, `download`, `data-*`) and no `type` or
|
|
142
|
+
`action`. `disabled` sets `aria-disabled` and stops the click from navigating.
|
|
143
|
+
`renderAnchor` draws a link component of your own, such as Next.js's `<Link>`;
|
|
144
|
+
see [Render props](#render-props) for what it receives. The type of `href` is
|
|
145
|
+
kept in the bag, so a typed route stays typed.
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
<Button color="base" href="/settings" variant="outline">
|
|
149
|
+
Settings
|
|
150
|
+
</Button>
|
|
126
151
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
color="base"
|
|
130
|
-
variant="outline"
|
|
131
|
-
renderItem={({ children, disabled: _disabled, type: _type, ...props }) => (
|
|
132
|
-
<a href="/page" {...props}>
|
|
133
|
-
{children}
|
|
134
|
-
</a>
|
|
135
|
-
)}
|
|
136
|
-
>
|
|
137
|
-
Link
|
|
152
|
+
<Button href="/settings" renderAnchor={(props) => <Link {...props} />}>
|
|
153
|
+
Settings
|
|
138
154
|
</Button>
|
|
139
155
|
```
|
|
140
156
|
|
|
141
157
|
### IconButton
|
|
142
158
|
|
|
143
|
-
An icon-only button.
|
|
159
|
+
An icon-only button. `variant` picks the ground: `skeleton` (the default) has
|
|
160
|
+
none, and `solid` fills it with the `color` family, as `Button` does. `label`
|
|
161
|
+
is the accessible name and the tooltip; the tooltip is not added as a
|
|
162
|
+
description, since it would repeat the name.
|
|
144
163
|
|
|
145
164
|
```tsx
|
|
146
165
|
import { IconButton } from '@k8ordo/ui';
|
|
147
166
|
|
|
148
|
-
<IconButton label="Close"
|
|
167
|
+
<IconButton label="Close" size="md">
|
|
149
168
|
<XIcon />
|
|
150
169
|
</IconButton>;
|
|
170
|
+
<IconButton color="primary" label="Send" variant="solid">
|
|
171
|
+
<SendIcon />
|
|
172
|
+
</IconButton>;
|
|
151
173
|
```
|
|
152
174
|
|
|
153
175
|
Props:
|
|
154
176
|
|
|
155
177
|
- `label`: `string` (required)
|
|
178
|
+
- `action`: `() => void | Promise<void>`
|
|
156
179
|
- `children`: `ReactNode`
|
|
157
|
-
- `color`: `'
|
|
158
|
-
- `
|
|
159
|
-
- `
|
|
180
|
+
- `color`: `'primary'` | `'secondary'` | `'base'` (default: `'primary'`)
|
|
181
|
+
- `disabled`: `boolean` (default: `false`)
|
|
182
|
+
- `href`: `T`
|
|
183
|
+
- `renderAnchor`: `(props: RenderAnchorProps<T>) => ReactNode`
|
|
160
184
|
- `size`: `'sm'` | `'md'` | `'lg'` (default: `'md'`)
|
|
161
185
|
- `tooltipDisabled`: `boolean` (default: `false`)
|
|
162
186
|
- `tooltipPlacement`: `Placement` (default: `'top'`)
|
|
163
|
-
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
`
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
`
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
renderItem={({
|
|
180
|
-
children,
|
|
181
|
-
disabled: _disabled,
|
|
182
|
-
triggerProps,
|
|
183
|
-
type: _type,
|
|
184
|
-
...props
|
|
185
|
-
}) => (
|
|
186
|
-
<a href="/contact" {...props} {...triggerProps}>
|
|
187
|
-
{children}
|
|
188
|
-
</a>
|
|
189
|
-
)}
|
|
190
|
-
>
|
|
187
|
+
- `type`: `'button'` | `'submit'` | `'reset'` (default: `'button'`)
|
|
188
|
+
- `variant`: `'solid'` | `'skeleton'` (default: `'skeleton'`)
|
|
189
|
+
- Other props are forwarded to `ComponentPropsWithRef<'button'> | ComponentPropsWithRef<'a'>`, except `className` / `style` / `aria-disabled`.
|
|
190
|
+
|
|
191
|
+
`action` keeps the button busy the way `Button`'s does — `aria-busy`,
|
|
192
|
+
`aria-disabled`, presses ignored, focus kept — without the spinner. `type`
|
|
193
|
+
takes `'button'`, `'submit'`, or `'reset'`, and only a submit button follows
|
|
194
|
+
the form's pending state.
|
|
195
|
+
|
|
196
|
+
With `href`, `IconButton` renders an `<a>`, named by `label` and with the same
|
|
197
|
+
tooltip. `renderAnchor` replaces that `<a>` under the same contract as
|
|
198
|
+
`Button`'s; the bag also carries `aria-label` and the tooltip's handlers and
|
|
199
|
+
`ref`, so spreading it keeps the tooltip.
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
<IconButton href="/contact" label="Mail">
|
|
191
203
|
<MailIcon />
|
|
192
204
|
</IconButton>
|
|
193
205
|
```
|
|
@@ -198,7 +210,7 @@ A button that copies text to the clipboard and shows that it did: its icon
|
|
|
198
210
|
turns into a check for two seconds (an error icon if the write fails), and a
|
|
199
211
|
live region beside it announces `copied` / `copyFailed` from the dictionary. The
|
|
200
212
|
button's name stays the same throughout. By default it is an outline `Button`
|
|
201
|
-
with its `label` as text; `iconOnly` makes it a
|
|
213
|
+
with its `label` as text; `iconOnly` makes it a skeleton `IconButton` whose
|
|
202
214
|
`label` is the tooltip.
|
|
203
215
|
|
|
204
216
|
```tsx
|
|
@@ -239,8 +251,10 @@ skipped. Tab leaves the toolbar, and coming back lands on the item last focused.
|
|
|
239
251
|
|
|
240
252
|
Each item is a slot: `Toolbar.Item`'s `renderItem` receives `ref`, `tabIndex`,
|
|
241
253
|
and `onFocus` (`ToolbarItemProps`) to spread onto a `Button`, an `IconButton`,
|
|
242
|
-
or any other button. A toggle item sets `aria-pressed`; the toolbar
|
|
243
|
-
pressed item
|
|
254
|
+
or any other button. A toggle item sets `aria-pressed`; the toolbar shows a
|
|
255
|
+
pressed item on the `bg-emphasize` ground with `fg-base` text (a disabled item
|
|
256
|
+
keeps its disabled text). The root needs a name (`aria-label` or
|
|
257
|
+
`aria-labelledby`).
|
|
244
258
|
Items are meant to be buttons: a control that uses the arrow keys itself (a text
|
|
245
259
|
field, a slider) would fight the toolbar for them.
|
|
246
260
|
|
|
@@ -319,9 +333,11 @@ Props (Breadcrumb.Link):
|
|
|
319
333
|
- `children`: `ReactNode`
|
|
320
334
|
- `current`: `boolean` (default: `false`)
|
|
321
335
|
- `renderAnchor`: `(props: RenderBreadcrumbAnchorProps<T>) => ReactNode` (default: `defaultRenderBreadcrumbAnchor`)
|
|
336
|
+
- Other props are forwarded to `AnchorHTMLAttributes<HTMLAnchorElement>`, except `className` / `style`.
|
|
322
337
|
|
|
323
|
-
`Breadcrumb.Link`
|
|
324
|
-
|
|
338
|
+
`Breadcrumb.Link` passes any other anchor attribute (`hrefLang`, `data-*`) to
|
|
339
|
+
the `<a>`, and its `renderAnchor` receives them with `href`, `className`, and
|
|
340
|
+
`children`; see [Render props](#render-props).
|
|
325
341
|
|
|
326
342
|
Props (Breadcrumb.Item):
|
|
327
343
|
|
|
@@ -342,12 +358,12 @@ Props:
|
|
|
342
358
|
- `currentPage`: `number` (required)
|
|
343
359
|
- `onChange`: `(page: number) => void` (required)
|
|
344
360
|
- `totalPages`: `number` (required)
|
|
345
|
-
- `aria-label`: `string`
|
|
346
361
|
- `disabled`: `boolean` (default: `false`)
|
|
362
|
+
- `label`: `string`
|
|
347
363
|
- `nextLabel`: `string`
|
|
348
364
|
- `prevLabel`: `string`
|
|
349
365
|
- `ref`: `Ref<HTMLElement>`
|
|
350
|
-
- Other props are forwarded to `HTMLAttributes<HTMLElement>`, except `className` / `style` / `children`.
|
|
366
|
+
- Other props are forwarded to `HTMLAttributes<HTMLElement>`, except `className` / `style` / `children` / `aria-label`.
|
|
351
367
|
|
|
352
368
|
### Stepper
|
|
353
369
|
|
|
@@ -511,12 +527,16 @@ Props:
|
|
|
511
527
|
|
|
512
528
|
### Tabs
|
|
513
529
|
|
|
514
|
-
Tab switching, as a compound component.
|
|
530
|
+
Tab switching, as a compound component. The tab that starts selected is
|
|
531
|
+
`defaultSelectedId`, required when the selection is not controlled; a
|
|
532
|
+
controlled one takes `selectedId` and `onChange`. Each `Tabs.Tab` and its
|
|
533
|
+
`Tabs.Panel` share an `id`, so map both from one list when the tabs come from
|
|
534
|
+
data.
|
|
515
535
|
|
|
516
536
|
```tsx
|
|
517
537
|
import { Tabs } from '@k8ordo/ui';
|
|
518
538
|
|
|
519
|
-
<Tabs.Root
|
|
539
|
+
<Tabs.Root defaultSelectedId="tab1">
|
|
520
540
|
<Tabs.List label="Tabs">
|
|
521
541
|
<Tabs.Tab id="tab1">Tab 1</Tabs.Tab>
|
|
522
542
|
<Tabs.Tab id="tab2">Tab 2</Tabs.Tab>
|
|
@@ -526,21 +546,23 @@ import { Tabs } from '@k8ordo/ui';
|
|
|
526
546
|
</Tabs.Root>;
|
|
527
547
|
```
|
|
528
548
|
|
|
529
|
-
|
|
549
|
+
The tab is marked selected at once, and the panels follow a deferred copy of
|
|
550
|
+
the selection (`useDeferredValue`): they cross-fade through React's
|
|
530
551
|
`<ViewTransition>` (off under `prefers-reduced-motion`), and a panel that
|
|
531
|
-
suspends keeps the current one on screen until it is ready.
|
|
552
|
+
suspends keeps the current one on screen until it is ready. Both hold however
|
|
553
|
+
the selection is set, by `useState` or by a store such as `@k8ordo/state`
|
|
554
|
+
whose updates are synchronous.
|
|
532
555
|
|
|
533
556
|
The keys follow the WAI-ARIA tabs pattern, and focusing a tab selects it.
|
|
534
|
-
`ArrowLeft` / `ArrowRight` move to the previous / next tab
|
|
535
|
-
ends, and swap under `dir="rtl"`; in vertical
|
|
536
|
-
vertical and `ArrowUp` / `ArrowDown` do the same.
|
|
537
|
-
first / last tab.
|
|
557
|
+
`ArrowLeft` / `ArrowRight` move to the previous / next tab in the order the
|
|
558
|
+
tabs appear, wrapping at the ends, and swap under `dir="rtl"`; in vertical
|
|
559
|
+
writing mode the list is vertical and `ArrowUp` / `ArrowDown` do the same.
|
|
560
|
+
`Home` / `End` go to the first / last tab.
|
|
538
561
|
|
|
539
562
|
Props (Tabs.Root):
|
|
540
563
|
|
|
541
|
-
- `ids`: `[string, ...string[]]` (required)
|
|
542
564
|
- `children`: `ReactNode`
|
|
543
|
-
- `defaultSelectedId`: `string`
|
|
565
|
+
- `defaultSelectedId`: `string`
|
|
544
566
|
- `onChange`: `(id: string) => void`
|
|
545
567
|
- `selectedId`: `string`
|
|
546
568
|
|
|
@@ -561,7 +583,14 @@ Props (Tabs.Tab):
|
|
|
561
583
|
|
|
562
584
|
### Anchor
|
|
563
585
|
|
|
564
|
-
A text link.
|
|
586
|
+
A text link. A link is external when its URL is an absolute `http:` / `https:`
|
|
587
|
+
URL or starts with `//` (or `/\`, which browsers read the same); a relative
|
|
588
|
+
path, a `?…`-only URL, and other schemes such as `mailto:` stay internal. An
|
|
589
|
+
external link, or one with `openInNewTab`, opens in a new tab with
|
|
590
|
+
`rel="noopener noreferrer"`, shows the new-tab icon, and says so to assistive
|
|
591
|
+
technology with visually hidden wording (`opensInNewTab`: "opens in a new
|
|
592
|
+
tab" in `en`, 「新しいタブで開きます」 in `ja`). The link stays inline, so a
|
|
593
|
+
long one wraps with the text around it.
|
|
565
594
|
|
|
566
595
|
```tsx
|
|
567
596
|
import { Anchor } from '@k8ordo/ui';
|
|
@@ -586,7 +615,7 @@ Props:
|
|
|
586
615
|
|
|
587
616
|
Form components are used together with `FormControl`'s `renderInput` pattern. Every form component except `FileField` supports both controlled and uncontrolled use; `FileField.Root` takes only `defaultValue` and keeps the selected files itself.
|
|
588
617
|
|
|
589
|
-
`ref` reaches the real element (`input` / `textarea` / `select` / `fieldset`). `FileField` uses a ref internally but composes it with yours, so the `ref` you pass still reaches the element. `Radio` (a group that renders several inputs) puts its `ref` on the radiogroup `<div>`, and `FormControl` (a wrapper) on its wrapper
|
|
618
|
+
`ref` reaches the real element (`input` / `textarea` / `select` / `fieldset`). `FileField` uses a ref internally but composes it with yours, so the `ref` you pass still reaches the element. `Radio` (a group that renders several inputs) puts its `ref` on the radiogroup `<div>`, and `FormControl` (a wrapper) on its wrapper `<div>`.
|
|
590
619
|
|
|
591
620
|
An uncontrolled field keeps its value in the DOM, so a form reset — `form.reset()`, a reset button, or React resetting the form after an action — puts it back to its `defaultValue`, and a `defaultValue` that changes after mount (the values a failed submission echoes back) is where the next reset goes. A value a component changes in code (a stepper, a chosen option, a removed file) is announced with an `input` event, so a form library listening on the `<form>` hears it like typing.
|
|
592
621
|
|
|
@@ -670,15 +699,27 @@ Props:
|
|
|
670
699
|
- `disabled`: `boolean` (default: `false`)
|
|
671
700
|
- `errorText`: `string`
|
|
672
701
|
- `helpText`: `string`
|
|
673
|
-
- `
|
|
674
|
-
- `
|
|
675
|
-
- `ref`: `Ref<HTMLElement>`
|
|
702
|
+
- `labelAs`: `'label'` | `'group'` (default: `'label'`)
|
|
703
|
+
- `ref`: `Ref<HTMLDivElement>`
|
|
676
704
|
- `required`: `boolean` (default: `false`)
|
|
677
|
-
- Other props are forwarded to `HTMLAttributes<
|
|
705
|
+
- Other props are forwarded to `HTMLAttributes<HTMLDivElement>`, except `className` / `style` / `children`.
|
|
678
706
|
|
|
679
707
|
`renderInput` receives `{ id, 'aria-describedby', 'aria-labelledby', disabled, invalid, required }`.
|
|
680
708
|
|
|
681
|
-
The wrapper
|
|
709
|
+
The wrapper is a `<div>`, and `labelAs` picks the element that draws the label. `'label'` (the default) gives a `<label htmlFor>` pointing at the field. `'group'` gives a `<span id>` with the same look, the required mark included, for a component that is a group itself — `Radio`, `RadioCard`, `CheckboxGroup`, `CheckboxCard`, and `RangeSlider` — and names it through `aria-labelledby`. A `<label>` cannot label a group, and a `<fieldset>` around one would nest a second group with the same name, so `'group'` renders neither. `FileField` takes `'group'` too: what a person reaches is its trigger, a button named through `aria-labelledby`, and a button cannot be required. `ColorPicker`, `DatePicker`, `Combobox`, and `Autocomplete` put the `id` on a text input, so they keep `'label'`.
|
|
710
|
+
|
|
711
|
+
```tsx
|
|
712
|
+
<FormControl
|
|
713
|
+
label="Plan"
|
|
714
|
+
labelAs="group"
|
|
715
|
+
required
|
|
716
|
+
renderInput={(props) => <RadioCard {...props} options={plans} />}
|
|
717
|
+
/>
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
`required` draws the built-in `required` wording after the label and passes `required: true` to `renderInput`. With `'label'` the mark is `aria-hidden`: the field's own `required` already tells a screen reader, so the name stays the label alone. With `'group'` the mark is part of the name, since neither a `role="group"` nor `FileField`'s trigger button takes `aria-required`.
|
|
721
|
+
|
|
722
|
+
A non-empty `errorText` is what makes the field invalid: it is drawn under the field in place of `helpText`, describes the field instead, and `renderInput` receives `invalid: true`. There is no `invalid` prop to keep in step with it. To mark a field invalid without a message, pass `invalid` to the field itself inside `renderInput`.
|
|
682
723
|
|
|
683
724
|
### TextField
|
|
684
725
|
|
|
@@ -703,6 +744,25 @@ import { TextField } from '@k8ordo/ui';
|
|
|
703
744
|
`type` also accepts any string, so the `type` `@k8ordo/form` derives
|
|
704
745
|
(`email`, `url`, `date`, `time`, `datetime-local`, …) spreads as it is.
|
|
705
746
|
|
|
747
|
+
A date or time input (`date`, `time`, `datetime-local`, `month`, `week`) is the
|
|
748
|
+
browser's own `<input>`: the value is the native string (`YYYY-MM-DD` for a
|
|
749
|
+
date, `''` when empty), and the browser checks `min` / `max` / `required`
|
|
750
|
+
itself. Its digits are tabular, so they do not shift sideways as the value
|
|
751
|
+
changes. A field derived from `z.iso.date()` spreads with nothing taken out:
|
|
752
|
+
|
|
753
|
+
```tsx
|
|
754
|
+
import { FormControl, TextField } from '@k8ordo/ui';
|
|
755
|
+
|
|
756
|
+
const eventDate = form.field('eventDate'); // z.iso.date()
|
|
757
|
+
|
|
758
|
+
<FormControl
|
|
759
|
+
errorText={eventDate.error}
|
|
760
|
+
label="Date"
|
|
761
|
+
required={eventDate.required}
|
|
762
|
+
renderInput={(props) => <TextField {...props} {...eventDate.input} />}
|
|
763
|
+
/>;
|
|
764
|
+
```
|
|
765
|
+
|
|
706
766
|
Props:
|
|
707
767
|
|
|
708
768
|
- `children`: `ReactNode`
|
|
@@ -733,12 +793,10 @@ Props:
|
|
|
733
793
|
- `fullHeight`: `boolean` (default: `false`)
|
|
734
794
|
- `invalid`: `boolean` (default: `false`)
|
|
735
795
|
- `ref`: `Ref<HTMLTextAreaElement>`
|
|
736
|
-
- `type`: `string`
|
|
737
796
|
- Other props are forwarded to `TextareaHTMLAttributes<HTMLTextAreaElement>`, except `className` / `style`.
|
|
738
797
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
checked by the browser on a `<textarea>` either.
|
|
798
|
+
A `<textarea>` has no `type`, and the browser does not check a `pattern` on
|
|
799
|
+
one.
|
|
742
800
|
|
|
743
801
|
### NumberField
|
|
744
802
|
|
|
@@ -778,18 +836,23 @@ range. `required` reaches the input itself, so an empty required field fails
|
|
|
778
836
|
native validation.
|
|
779
837
|
|
|
780
838
|
The input is `type="text"` (so it can format to `precision` and step with the
|
|
781
|
-
arrow keys), which the browser does not range-check — so the field
|
|
782
|
-
value
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
839
|
+
arrow keys), which the browser does not range-check — so the field keeps the
|
|
840
|
+
value in range itself: leaving the field, or pressing Enter in it (not while an
|
|
841
|
+
IME is composing), clamps a value below `min` or above `max` into range, the
|
|
842
|
+
same commit either way. A form submitted with Enter therefore sends the clamped
|
|
843
|
+
value. The field sets no validity message of its own, so whatever reports an
|
|
844
|
+
out-of-range value — the server's schema, when JavaScript has not run — keeps
|
|
845
|
+
its own wording.
|
|
846
|
+
|
|
847
|
+
`min` and `max` are numbers. An uncontrolled `defaultValue` also takes a
|
|
848
|
+
string, and `step` takes `'any'`: `@k8ordo/form` derives numeric `min` /
|
|
849
|
+
`max`, a `step` of `'any'` unless the schema sets one, and echoes the
|
|
850
|
+
submitted text as a string `defaultValue`. `precision` defaults to the number
|
|
851
|
+
of decimals in `step`; with `step="any"` the value is not rounded.
|
|
790
852
|
|
|
791
853
|
A value the field writes itself — an arrow key, a stepper press, formatting on
|
|
792
|
-
blur — is announced with one `input` event, and `onChange` is still
|
|
854
|
+
blur or Enter — is announced with one `input` event, and `onChange` is still
|
|
855
|
+
called once.
|
|
793
856
|
|
|
794
857
|
A form reset — `form.reset()`, a reset button, or React resetting the form after
|
|
795
858
|
an action — puts an uncontrolled field back to `defaultValue` (or to empty) and
|
|
@@ -800,8 +863,8 @@ Props:
|
|
|
800
863
|
|
|
801
864
|
- `defaultValue`: `number` | `string`
|
|
802
865
|
- `invalid`: `boolean` (default: `false`)
|
|
803
|
-
- `max`: `number`
|
|
804
|
-
- `min`: `number`
|
|
866
|
+
- `max`: `number` (default: `Number.MAX_SAFE_INTEGER`)
|
|
867
|
+
- `min`: `number` (default: `Number.MIN_SAFE_INTEGER`)
|
|
805
868
|
- `onChange`: `(value: number | null) => void`
|
|
806
869
|
- `precision`: `number`
|
|
807
870
|
- `ref`: `Ref<HTMLInputElement>`
|
|
@@ -809,41 +872,12 @@ Props:
|
|
|
809
872
|
- `value`: `number` | `null`
|
|
810
873
|
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `role` / `className` / `style` / `children`.
|
|
811
874
|
|
|
812
|
-
### DateField
|
|
813
|
-
|
|
814
|
-
A native `<input type="date">` styled like `TextField`. The value is a
|
|
815
|
-
`YYYY-MM-DD` string (`''` when empty), and the browser checks `min` / `max` /
|
|
816
|
-
`required` itself. `onChange` is the native event, as with `TextField`.
|
|
817
|
-
|
|
818
|
-
It accepts what `@k8ordo/form` derives from `z.iso.date()` as is: spread the
|
|
819
|
-
field's `input` and nothing needs to be taken out. `type` is always `date`, so a
|
|
820
|
-
`type` in the spread does not replace it.
|
|
821
|
-
|
|
822
|
-
```tsx
|
|
823
|
-
import { DateField, FormControl } from '@k8ordo/ui';
|
|
824
|
-
|
|
825
|
-
const eventDate = form.field('eventDate'); // z.iso.date()
|
|
826
|
-
|
|
827
|
-
<FormControl
|
|
828
|
-
errorText={eventDate.error}
|
|
829
|
-
invalid={eventDate.invalid}
|
|
830
|
-
label="Date"
|
|
831
|
-
required={eventDate.required}
|
|
832
|
-
renderInput={(props) => <DateField {...props} {...eventDate.input} />}
|
|
833
|
-
/>;
|
|
834
|
-
```
|
|
835
|
-
|
|
836
|
-
Props:
|
|
837
|
-
|
|
838
|
-
- `invalid`: `boolean` (default: `false`)
|
|
839
|
-
- `ref`: `Ref<HTMLInputElement>`
|
|
840
|
-
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `className` / `style` / `type` / `children`.
|
|
841
|
-
|
|
842
875
|
### DatePicker
|
|
843
876
|
|
|
844
|
-
`
|
|
845
|
-
same native `<input type="date">`, so typing a date, `name`, `required`,
|
|
846
|
-
`min` / `max` all work as they do on `
|
|
877
|
+
A date `TextField` with a button that opens `Calendar` in a popover. The field
|
|
878
|
+
is the same native `<input type="date">`, so typing a date, `name`, `required`,
|
|
879
|
+
and `min` / `max` all work as they do on a `TextField` with `type="date"`, and
|
|
880
|
+
spreading a derived
|
|
847
881
|
`@k8ordo/form` field works the same way. `onChange` takes the value
|
|
848
882
|
(`YYYY-MM-DD`, `''` when cleared), not the event, because a date picked from the
|
|
849
883
|
calendar has no input event of its own.
|
|
@@ -889,8 +923,8 @@ Month and weekday names, and the first day of the week, follow the same locale
|
|
|
889
923
|
as the built-in wording (i18n, below). Today is marked with
|
|
890
924
|
`aria-current="date"` in the visitor's time zone, which only the browser knows,
|
|
891
925
|
so the calendar renders in the browser alone: the server writes an empty box of
|
|
892
|
-
the same size. It submits nothing; inside a form, use `DatePicker` or
|
|
893
|
-
`
|
|
926
|
+
the same size. It submits nothing; inside a form, use `DatePicker` or a
|
|
927
|
+
`TextField` with `type="date"`.
|
|
894
928
|
|
|
895
929
|
```tsx
|
|
896
930
|
import { Calendar } from '@k8ordo/ui';
|
|
@@ -961,13 +995,23 @@ Props:
|
|
|
961
995
|
- `options`: `readonly Option[]` (required)
|
|
962
996
|
- `children`: `ReactNode`
|
|
963
997
|
- `invalid`: `boolean` (default: `false`)
|
|
998
|
+
- `placeholder`: `string`
|
|
964
999
|
- `ref`: `Ref<HTMLSelectElement>`
|
|
965
1000
|
- Other props are forwarded to `SelectHTMLAttributes<HTMLSelectElement>`, except `className` / `style`.
|
|
966
1001
|
|
|
967
1002
|
React applies a `<select>`'s `defaultValue` only when it mounts; `Select` also
|
|
968
1003
|
applies a later one, so the next reset — React's after a form action included —
|
|
969
|
-
goes back to it.
|
|
970
|
-
|
|
1004
|
+
goes back to it.
|
|
1005
|
+
|
|
1006
|
+
`placeholder` puts an option whose `value` is `''` first, labelled with it. A
|
|
1007
|
+
`<select>` without such an option always has a choice selected, so `required`
|
|
1008
|
+
means something only with one: leaving the placeholder selected fails
|
|
1009
|
+
validation. It stays selectable, so an optional field can be set back to no
|
|
1010
|
+
choice; `@k8ordo/form`'s `parseForm` reads `''` as no choice either way.
|
|
1011
|
+
|
|
1012
|
+
```tsx
|
|
1013
|
+
<Select name="plan" options={plans} placeholder="Choose a plan" required />
|
|
1014
|
+
```
|
|
971
1015
|
|
|
972
1016
|
### Autocomplete
|
|
973
1017
|
|
|
@@ -1004,11 +1048,11 @@ Props:
|
|
|
1004
1048
|
|
|
1005
1049
|
- `id`: `string` (required)
|
|
1006
1050
|
- `options`: `readonly Option[]` (required)
|
|
1007
|
-
- `defaultValue`: `string[]`
|
|
1051
|
+
- `defaultValue`: `readonly string[]`
|
|
1008
1052
|
- `invalid`: `boolean` (default: `false`)
|
|
1009
1053
|
- `onChange`: `(value: string[]) => void`
|
|
1010
1054
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1011
|
-
- `value`: `string[]`
|
|
1055
|
+
- `value`: `readonly string[]`
|
|
1012
1056
|
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `role` / `className` / `style` / `children` / `autoComplete` / `aria-autocomplete` / `aria-controls` / `aria-expanded` / `aria-activedescendant`.
|
|
1013
1057
|
|
|
1014
1058
|
### ColorPicker
|
|
@@ -1056,9 +1100,8 @@ Props:
|
|
|
1056
1100
|
- `onChange`: `(value: string) => void`
|
|
1057
1101
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1058
1102
|
- `swatches`: `readonly ColorPickerSwatch[]`
|
|
1059
|
-
- `type`: `string`
|
|
1060
1103
|
- `value`: `string`
|
|
1061
|
-
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `className` / `style` / `children`.
|
|
1104
|
+
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `className` / `style` / `children`.
|
|
1062
1105
|
|
|
1063
1106
|
### Combobox
|
|
1064
1107
|
|
|
@@ -1074,7 +1117,8 @@ and move through it (`Alt+ArrowDown` opens it without entering it), `Escape`
|
|
|
1074
1117
|
closes it and, pressed again, drops what was typed. Keys pressed while an IME is
|
|
1075
1118
|
composing belong to the IME.
|
|
1076
1119
|
|
|
1077
|
-
Without `search`, typing filters `options` by label
|
|
1120
|
+
Without `search`, typing filters `options` by label, case-insensitively in the
|
|
1121
|
+
language of `@k8ordo/i18n`'s current locale. With `search`, typing
|
|
1078
1122
|
calls it for the options instead — each call gets a `signal` that aborts when
|
|
1079
1123
|
the text changes again, so pass it to `fetch` — and `options` becomes the list
|
|
1080
1124
|
shown before anything is typed and where the current value's label is looked
|
|
@@ -1111,15 +1155,14 @@ Props:
|
|
|
1111
1155
|
- `options`: `readonly Option[]`
|
|
1112
1156
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1113
1157
|
- `search`: `ComboboxSearch`
|
|
1114
|
-
- `type`: `string`
|
|
1115
1158
|
- `value`: `string`
|
|
1116
|
-
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `role` / `className` / `style` / `children` / `autoComplete` / `aria-autocomplete` / `aria-controls` / `aria-expanded` / `aria-activedescendant`.
|
|
1159
|
+
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `role` / `className` / `style` / `children` / `autoComplete` / `aria-autocomplete` / `aria-controls` / `aria-expanded` / `aria-activedescendant`.
|
|
1117
1160
|
|
|
1118
1161
|
### Checkbox
|
|
1119
1162
|
|
|
1120
1163
|
The label is passed as the `label` prop, not as children. `onChange` is `(checked, event)`.
|
|
1121
1164
|
|
|
1122
|
-
`
|
|
1165
|
+
`value` is the input's native `value`: the string a checked box submits under its `name`. Without it the box submits the browser's default, `on`. It never sets the checked state — that is `checked` / `defaultChecked`. `@k8ordo/form` puts it in the `input` of a `z.stringbool()` field (the schema's spelling of `true`), so spreading that `input` is enough.
|
|
1123
1166
|
|
|
1124
1167
|
```tsx
|
|
1125
1168
|
import { Checkbox } from '@k8ordo/ui';
|
|
@@ -1131,7 +1174,23 @@ import { Checkbox } from '@k8ordo/ui';
|
|
|
1131
1174
|
<Checkbox defaultChecked label="I agree" />
|
|
1132
1175
|
|
|
1133
1176
|
// Submits inStock=true when checked, instead of inStock=on
|
|
1134
|
-
<Checkbox
|
|
1177
|
+
<Checkbox label="In stock only" name="inStock" value="true" />
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
`Checkbox` carries its own label, so it is not wrapped in `FormControl`. It
|
|
1181
|
+
draws a field's message itself instead: `errorText` (or, when there is none,
|
|
1182
|
+
`helpText`) is drawn under the box the way `FormControl` draws it, and the
|
|
1183
|
+
input is described by it, after any `aria-describedby` you pass. A non-empty
|
|
1184
|
+
`errorText` also sets `aria-invalid` and the invalid look, as `invalid` does;
|
|
1185
|
+
`invalid` alone marks the box without a message. With `@k8ordo/form`, pass
|
|
1186
|
+
`errorText={field.error}`.
|
|
1187
|
+
|
|
1188
|
+
```tsx
|
|
1189
|
+
<Checkbox
|
|
1190
|
+
{...agree.input}
|
|
1191
|
+
errorText={agree.error}
|
|
1192
|
+
label="I agree to the terms"
|
|
1193
|
+
/>
|
|
1135
1194
|
```
|
|
1136
1195
|
|
|
1137
1196
|
`indeterminate` shows the mixed state — some of a set selected — and sets the
|
|
@@ -1144,71 +1203,71 @@ Props:
|
|
|
1144
1203
|
- `label`: `string` (required)
|
|
1145
1204
|
- `checked`: `boolean`
|
|
1146
1205
|
- `defaultChecked`: `boolean`
|
|
1206
|
+
- `errorText`: `string`
|
|
1207
|
+
- `helpText`: `string`
|
|
1147
1208
|
- `indeterminate`: `boolean` (default: `false`)
|
|
1148
1209
|
- `invalid`: `boolean` (default: `false`)
|
|
1149
|
-
- `itemValue`: `string`
|
|
1150
1210
|
- `labelHidden`: `boolean` (default: `false`)
|
|
1151
1211
|
- `onChange`: `(checked: boolean, event: ChangeEvent<HTMLInputElement>) => void`
|
|
1152
1212
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1153
|
-
-
|
|
1213
|
+
- `value`: `string`
|
|
1214
|
+
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `className` / `style` / `children`.
|
|
1154
1215
|
|
|
1155
1216
|
### CheckboxGroup
|
|
1156
1217
|
|
|
1157
|
-
A group of checkboxes
|
|
1218
|
+
A group of checkboxes, one per entry in `options`: the multiple-choice counterpart of `Radio`, with the same `options` shape.
|
|
1219
|
+
|
|
1220
|
+
The group's selection lives in `value` / `onChange`, or in `defaultValue` when uncontrolled: the values of the checked options. That is a different thing from a lone `Checkbox` holding a boolean in `checked` — do not conflate them. `value` and `defaultValue` take a readonly array, and `onChange` receives a new `string[]` of the checked values in option order, so a `useState<string[]>` setter can be passed as it is.
|
|
1158
1221
|
|
|
1159
|
-
|
|
1222
|
+
It renders a `fieldset[role="group"]`, so `aria-labelledby` is required: `<FormControl labelAs="group">` draws the element it points at. Convey that the group is required through that element — `FormControl`'s required mark is part of the group's name in `'group'` mode. `role="group"` does not allow `aria-required`, so do not put it on the group. `required` is accepted so that `FormControl`'s props spread onto the group as they are, and is written to no element: a `<fieldset>` takes no `required`, and on a checkbox it would mean that box must be checked. Check the count with a rule of your own, or with `@k8ordo/form`'s, which a schema's `.min()` derives.
|
|
1160
1223
|
|
|
1161
|
-
|
|
1224
|
+
`invalid` — which `FormControl`'s props carry while its `errorText` is not empty — goes to every box as `aria-invalid` and the invalid look, since `role="group"` does not take `aria-invalid` either.
|
|
1162
1225
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1226
|
+
`name` goes on every box. It is optional and nothing fills it in: without a `name` the boxes submit nothing, which is what a group that only drives the page (`DataTable`'s column menu) wants even inside a form.
|
|
1227
|
+
|
|
1228
|
+
Uncontrolled, the selection lives in the checkboxes themselves, so a form reset
|
|
1229
|
+
puts the boxes back to `defaultValue` without leaving a stale selection behind.
|
|
1166
1230
|
|
|
1167
1231
|
```tsx
|
|
1168
1232
|
import { CheckboxGroup } from '@k8ordo/ui';
|
|
1169
1233
|
|
|
1170
1234
|
<p id="interests-label">Areas of interest</p>
|
|
1171
|
-
<CheckboxGroup
|
|
1235
|
+
<CheckboxGroup
|
|
1172
1236
|
aria-labelledby="interests-label"
|
|
1173
1237
|
name="interests"
|
|
1174
|
-
value={values}
|
|
1175
1238
|
onChange={setValues}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1239
|
+
options={[
|
|
1240
|
+
{ value: 'music', label: 'Music' },
|
|
1241
|
+
{ value: 'movie', label: 'Film' },
|
|
1242
|
+
]}
|
|
1243
|
+
value={values}
|
|
1244
|
+
/>;
|
|
1180
1245
|
```
|
|
1181
1246
|
|
|
1182
|
-
Props
|
|
1183
|
-
|
|
1184
|
-
- `label`: `string` (required)
|
|
1185
|
-
- `checked`: `boolean`
|
|
1186
|
-
- `defaultChecked`: `boolean`
|
|
1187
|
-
- `indeterminate`: `boolean` (default: `false`)
|
|
1188
|
-
- `invalid`: `boolean` (default: `false`)
|
|
1189
|
-
- `itemValue`: `string`
|
|
1190
|
-
- `labelHidden`: `boolean` (default: `false`)
|
|
1191
|
-
- `onChange`: `(checked: boolean, event: ChangeEvent<HTMLInputElement>) => void`
|
|
1192
|
-
- `ref`: `Ref<HTMLInputElement>`
|
|
1193
|
-
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `className` / `style` / `value` / `children`.
|
|
1194
|
-
|
|
1195
|
-
Props (CheckboxGroup.Root):
|
|
1247
|
+
Props:
|
|
1196
1248
|
|
|
1197
1249
|
- `aria-labelledby`: `string` (required)
|
|
1198
|
-
- `
|
|
1199
|
-
- `
|
|
1200
|
-
- `
|
|
1250
|
+
- `options`: `readonly Option[]` (required)
|
|
1251
|
+
- `defaultValue`: `readonly string[]`
|
|
1252
|
+
- `disabled`: `boolean` (default: `false`)
|
|
1201
1253
|
- `invalid`: `boolean` (default: `false`)
|
|
1254
|
+
- `name`: `string`
|
|
1202
1255
|
- `onChange`: `(value: string[]) => void`
|
|
1203
1256
|
- `ref`: `Ref<HTMLFieldSetElement>`
|
|
1204
|
-
- `
|
|
1205
|
-
-
|
|
1257
|
+
- `required`: `boolean`
|
|
1258
|
+
- `value`: `readonly string[]`
|
|
1259
|
+
- Other props are forwarded to `FieldsetHTMLAttributes<HTMLFieldSetElement>`, except `className` / `style` / `children` / `role`.
|
|
1206
1260
|
|
|
1207
1261
|
### CheckboxCard
|
|
1208
1262
|
|
|
1209
1263
|
A card-styled checkbox. Uncontrolled, the selection and its look follow the
|
|
1210
1264
|
checkboxes themselves (`:checked`), so a form reset restores both; `onChange`
|
|
1211
|
-
receives the checked values in document order.
|
|
1265
|
+
receives the checked values in document order. Like `CheckboxGroup`, it takes
|
|
1266
|
+
`required` from `FormControl`'s props and writes it to no element; wrap it in
|
|
1267
|
+
`<FormControl labelAs="group" required>`, whose mark is part of the group's
|
|
1268
|
+
name. `invalid` sets `aria-invalid` on every box as well as the look —
|
|
1269
|
+
`role="group"` does not take `aria-invalid` — and while the form's action is
|
|
1270
|
+
pending the boxes take `aria-disabled` and ignore presses, as `Checkbox` does.
|
|
1212
1271
|
|
|
1213
1272
|
```tsx
|
|
1214
1273
|
import { CheckboxCard } from '@k8ordo/ui';
|
|
@@ -1235,15 +1294,25 @@ Props:
|
|
|
1235
1294
|
|
|
1236
1295
|
- `aria-labelledby`: `string` (required)
|
|
1237
1296
|
- `options`: `readonly CheckboxCardOption[]` (required)
|
|
1238
|
-
- `defaultValue`: `string[]`
|
|
1297
|
+
- `defaultValue`: `readonly string[]`
|
|
1239
1298
|
- `invalid`: `boolean` (default: `false`)
|
|
1240
1299
|
- `onChange`: `(value: string[]) => void`
|
|
1241
1300
|
- `ref`: `Ref<HTMLFieldSetElement>`
|
|
1242
|
-
- `
|
|
1301
|
+
- `required`: `boolean`
|
|
1302
|
+
- `value`: `readonly string[]`
|
|
1243
1303
|
- Other props are forwarded to `FieldsetHTMLAttributes<HTMLFieldSetElement>`, except `className` / `style` / `children` / `role`.
|
|
1244
1304
|
|
|
1245
1305
|
### Radio
|
|
1246
1306
|
|
|
1307
|
+
A `div[role="radiogroup"]` of real `input[type="radio"]` elements, named
|
|
1308
|
+
through the required `aria-labelledby`. `name` is optional. Without one, the
|
|
1309
|
+
radios share a name made with `useId`: the browser groups radios by name for
|
|
1310
|
+
single selection and arrow-key roving, so a radio group always has one, and two
|
|
1311
|
+
groups never take each other's selection. `RadioCard` does the same. The
|
|
1312
|
+
checkbox groups (`CheckboxGroup`, `CheckboxCard`) fill in no name, since a box
|
|
1313
|
+
needs none to work and one without a name submits nothing. Pass `name` to
|
|
1314
|
+
submit the choice.
|
|
1315
|
+
|
|
1247
1316
|
```tsx
|
|
1248
1317
|
import { Radio } from '@k8ordo/ui';
|
|
1249
1318
|
|
|
@@ -1275,7 +1344,7 @@ Props:
|
|
|
1275
1344
|
|
|
1276
1345
|
### RadioCard
|
|
1277
1346
|
|
|
1278
|
-
A card-styled radio button. Real `input[type="radio"]` elements sit inside a `fieldset[role="radiogroup"]`, so arrow-key roving and single selection are left to the browser. Reach them from tests with `getByRole('radio', { checked })`. `required` goes to every radio, and an uncontrolled selection's look follows `:checked`, so a form reset restores it.
|
|
1347
|
+
A card-styled radio button. Real `input[type="radio"]` elements sit inside a `fieldset[role="radiogroup"]`, so arrow-key roving and single selection are left to the browser. Reach them from tests with `getByRole('radio', { checked })`. `required` goes to every radio, and an uncontrolled selection's look follows `:checked`, so a form reset restores it. `invalid` sets `aria-invalid` on the group as well as the look, and while the form's action is pending the radios take `aria-disabled` and ignore presses and arrow keys, as `Radio` does.
|
|
1279
1348
|
|
|
1280
1349
|
```tsx
|
|
1281
1350
|
import { RadioCard } from '@k8ordo/ui';
|
|
@@ -1313,8 +1382,9 @@ Props:
|
|
|
1313
1382
|
### Slider
|
|
1314
1383
|
|
|
1315
1384
|
A range slider. Uncontrolled, the value lives in the input, so a form reset
|
|
1316
|
-
puts it back to `defaultValue` and the filled track follows. `min
|
|
1317
|
-
an uncontrolled `defaultValue` also
|
|
1385
|
+
puts it back to `defaultValue` and the filled track follows. `min` and `max`
|
|
1386
|
+
are numbers; an uncontrolled `defaultValue` also takes a string, and `step`
|
|
1387
|
+
takes `'any'`, as `@k8ordo/form` derives them.
|
|
1318
1388
|
|
|
1319
1389
|
```tsx
|
|
1320
1390
|
import { Slider } from '@k8ordo/ui';
|
|
@@ -1327,16 +1397,20 @@ import { Slider } from '@k8ordo/ui';
|
|
|
1327
1397
|
onChange={onChange}
|
|
1328
1398
|
invalid={false}
|
|
1329
1399
|
disabled={false}
|
|
1330
|
-
required={false}
|
|
1331
1400
|
/>;
|
|
1332
1401
|
```
|
|
1333
1402
|
|
|
1403
|
+
`required` is accepted, so `FormControl`'s props and `@k8ordo/form`'s `input`
|
|
1404
|
+
spread onto the slider as they are, and is written to no element: HTML does
|
|
1405
|
+
not allow it on a range, and a range always has a value, so there is nothing
|
|
1406
|
+
to require.
|
|
1407
|
+
|
|
1334
1408
|
Props:
|
|
1335
1409
|
|
|
1336
1410
|
- `defaultValue`: `number` | `string`
|
|
1337
1411
|
- `invalid`: `boolean` (default: `false`)
|
|
1338
|
-
- `max`: `number`
|
|
1339
|
-
- `min`: `number`
|
|
1412
|
+
- `max`: `number` (default: `100`)
|
|
1413
|
+
- `min`: `number` (default: `0`)
|
|
1340
1414
|
- `onChange`: `(value: number) => void`
|
|
1341
1415
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1342
1416
|
- `step`: `number` | `'any'` (default: `1`)
|
|
@@ -1356,8 +1430,13 @@ pair `[lower, upper]`.
|
|
|
1356
1430
|
the thumbs keep their values in the DOM, so a form's reset and its dirty check
|
|
1357
1431
|
(value against default value) work on them as on any input. The whole slider is
|
|
1358
1432
|
a `role="group"`: name it with `aria-label` or `aria-labelledby`
|
|
1359
|
-
(
|
|
1360
|
-
followed by the built-in `rangeSliderStart` / `rangeSliderEnd`
|
|
1433
|
+
(`<FormControl labelAs="group">`'s `renderInput` props), and each thumb is read
|
|
1434
|
+
as that name followed by the built-in `rangeSliderStart` / `rangeSliderEnd`
|
|
1435
|
+
wording.
|
|
1436
|
+
|
|
1437
|
+
As on `Slider`, `required` is accepted and written to no thumb. In
|
|
1438
|
+
`<FormControl labelAs="group" required>` the mark is part of the group's
|
|
1439
|
+
name, so each thumb's name carries it.
|
|
1361
1440
|
|
|
1362
1441
|
```tsx
|
|
1363
1442
|
import { RangeSlider } from '@k8ordo/ui';
|
|
@@ -1381,14 +1460,14 @@ Props:
|
|
|
1381
1460
|
- `name`: `readonly [string, string]`
|
|
1382
1461
|
- `onChange`: `(value: [number, number]) => void`
|
|
1383
1462
|
- `ref`: `Ref<HTMLDivElement>`
|
|
1384
|
-
- `required`: `boolean`
|
|
1463
|
+
- `required`: `boolean`
|
|
1385
1464
|
- `step`: `number` (default: `1`)
|
|
1386
1465
|
- `value`: `readonly [number, number]`
|
|
1387
1466
|
- Other props are forwarded to `HTMLAttributes<HTMLDivElement>`, except `className` / `style` / `children` / `role`.
|
|
1388
1467
|
|
|
1389
1468
|
### Switch
|
|
1390
1469
|
|
|
1391
|
-
A toggle switch.
|
|
1470
|
+
A toggle switch. It is a checkbox underneath (`role="switch"`), so `value` is, as on `Checkbox`, the string it submits under its `name` when on, and `checked` / `defaultChecked` hold the state. Like `Checkbox`, it carries its own label and draws `errorText` / `helpText` itself, describing the input with them; a non-empty `errorText` sets `aria-invalid`.
|
|
1392
1471
|
|
|
1393
1472
|
```tsx
|
|
1394
1473
|
import { Switch } from '@k8ordo/ui';
|
|
@@ -1408,35 +1487,52 @@ Props:
|
|
|
1408
1487
|
- `label`: `string` (required)
|
|
1409
1488
|
- `checked`: `boolean`
|
|
1410
1489
|
- `defaultChecked`: `boolean`
|
|
1490
|
+
- `errorText`: `string`
|
|
1491
|
+
- `helpText`: `string`
|
|
1411
1492
|
- `invalid`: `boolean` (default: `false`)
|
|
1412
1493
|
- `onChange`: `(checked: boolean, event: ChangeEvent<HTMLInputElement>) => void`
|
|
1413
1494
|
- `ref`: `Ref<HTMLInputElement>`
|
|
1414
|
-
-
|
|
1495
|
+
- `value`: `string`
|
|
1496
|
+
- Other props are forwarded to `InputHTMLAttributes<HTMLInputElement>`, except `type` / `role` / `className` / `style` / `children`.
|
|
1415
1497
|
|
|
1416
1498
|
### FileField
|
|
1417
1499
|
|
|
1418
|
-
File upload, as a composite pattern.
|
|
1419
|
-
|
|
1500
|
+
File upload, as a composite pattern. The `<input type="file">` that submits
|
|
1501
|
+
is visually hidden, `aria-hidden`, and out of the Tab order; what a person
|
|
1502
|
+
reaches is the trigger. `FileField.Trigger`'s `renderItem` receives the wiring
|
|
1503
|
+
for it — `id`, `aria-labelledby` (the field's label, then the trigger's own
|
|
1504
|
+
text), `aria-describedby` (the root's), `ref`, `onClick`, and `disabled` —
|
|
1505
|
+
and nothing else, so it spreads onto a `Button` as it is. When a form moves focus to the hidden input after a failed
|
|
1506
|
+
submission, it goes on to the trigger, which `FormControl`'s error text
|
|
1507
|
+
already describes.
|
|
1508
|
+
|
|
1509
|
+
Wrap it in `<FormControl labelAs="group">`. The only element that carries
|
|
1510
|
+
`required` is the hidden input, and a button cannot take it, so the trigger
|
|
1511
|
+
says the field is required through its name: in `'group'` mode the mark is
|
|
1512
|
+
part of the heading the trigger reads, giving "Photos Required Choose files".
|
|
1420
1513
|
|
|
1421
1514
|
```tsx
|
|
1422
|
-
import { FileField } from '@k8ordo/ui';
|
|
1515
|
+
import { FileField, FormControl } from '@k8ordo/ui';
|
|
1423
1516
|
|
|
1424
|
-
<
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1517
|
+
<FormControl
|
|
1518
|
+
label="Photos"
|
|
1519
|
+
labelAs="group"
|
|
1520
|
+
required
|
|
1521
|
+
renderInput={(props) => (
|
|
1522
|
+
<FileField.Root {...props} accept="image/*" multiple maxFiles={5}>
|
|
1523
|
+
<FileField.Trigger
|
|
1524
|
+
renderItem={(wiring) => <Button {...wiring}>Choose files</Button>}
|
|
1525
|
+
/>
|
|
1526
|
+
<FileField.ItemList />
|
|
1527
|
+
</FileField.Root>
|
|
1528
|
+
)}
|
|
1529
|
+
/>;
|
|
1434
1530
|
```
|
|
1435
1531
|
|
|
1436
1532
|
`FileField.Dropzone` is an area files can be dropped onto. Left empty, it holds
|
|
1437
|
-
the built-in `fileFieldDrop` wording and a "choose files" button
|
|
1438
|
-
stays usable by keyboard; pass children to lay it out
|
|
1439
|
-
`FileField.Trigger` inside). Dropped files are added exactly like picked ones:
|
|
1533
|
+
the built-in `fileFieldDrop` wording and a "choose files" button wired as a
|
|
1534
|
+
trigger, so the field stays usable by keyboard; pass children to lay it out
|
|
1535
|
+
yourself (put a `FileField.Trigger` inside). Dropped files are added exactly like picked ones:
|
|
1440
1536
|
they respect `multiple` and `maxFiles`, land in the input so they are
|
|
1441
1537
|
submitted, and are announced with an `input` event so a form sees the change.
|
|
1442
1538
|
A dropped folder is skipped (choose folders through the picker with
|
|
@@ -1453,8 +1549,8 @@ submitted:
|
|
|
1453
1549
|
alone would keep only the files just picked. A rewrite is announced with an
|
|
1454
1550
|
`input` event.
|
|
1455
1551
|
- Removing a file from `ItemList` removes it from the input.
|
|
1456
|
-
-
|
|
1457
|
-
puts both back to
|
|
1552
|
+
- The files in `defaultValue` are submitted as well as listed, and a form
|
|
1553
|
+
reset puts both back to them (to an empty list without one).
|
|
1458
1554
|
- `onChange` receives that whole list — not only the files just picked or
|
|
1459
1555
|
dropped — after every pick, drop, and removal. Only a pick passes the
|
|
1460
1556
|
`event`.
|
|
@@ -1469,7 +1565,7 @@ submitted:
|
|
|
1469
1565
|
Props (Root):
|
|
1470
1566
|
|
|
1471
1567
|
- `children`: `ReactNode`
|
|
1472
|
-
- `defaultValue`: `File[]`
|
|
1568
|
+
- `defaultValue`: `File[]`
|
|
1473
1569
|
- `invalid`: `boolean` (default: `false`)
|
|
1474
1570
|
- `maxFiles`: `number`
|
|
1475
1571
|
- `onChange`: `(files: FileList | null, event?: ChangeEvent<HTMLInputElement>) => void`
|
|
@@ -1488,7 +1584,7 @@ Props (FileField.ItemList):
|
|
|
1488
1584
|
|
|
1489
1585
|
Props (FileField.Trigger):
|
|
1490
1586
|
|
|
1491
|
-
- `renderItem`: `(props: {
|
|
1587
|
+
- `renderItem`: `(props: { id: string; 'aria-labelledby': string | undefined; 'aria-describedby': string | undefined; ref: (node: HTMLElement | null) => void; onClick: () => void; disabled: boolean; }) => ReactElement` (required)
|
|
1492
1588
|
|
|
1493
1589
|
## Data display
|
|
1494
1590
|
|
|
@@ -1577,7 +1673,12 @@ A block of code, highlighted on the server with shiki, with a copy button.
|
|
|
1577
1673
|
It is an async Server Component on its own subpath, `@k8ordo/ui/code-block`,
|
|
1578
1674
|
and imports `server-only`: the highlighter never reaches the browser, and
|
|
1579
1675
|
importing it from a Client Component fails the build. Only the copy button is a
|
|
1580
|
-
client module.
|
|
1676
|
+
client module. shiki is an optional peer, installed by the application that
|
|
1677
|
+
imports `@k8ordo/ui/code-block`:
|
|
1678
|
+
|
|
1679
|
+
```bash
|
|
1680
|
+
pnpm add shiki
|
|
1681
|
+
```
|
|
1581
1682
|
|
|
1582
1683
|
```tsx
|
|
1583
1684
|
import { CodeBlock } from '@k8ordo/ui/code-block';
|
|
@@ -1879,7 +1980,7 @@ import { Tree } from '@k8ordo/ui';
|
|
|
1879
1980
|
```
|
|
1880
1981
|
|
|
1881
1982
|
- Which parents are open is controllable (`expandedIds` / `defaultExpandedIds`
|
|
1882
|
-
/ `
|
|
1983
|
+
/ `onExpandedIdsChange`, called with a new array), and so is the selected node (`selectedId` /
|
|
1883
1984
|
`defaultSelectedId` / `onChange`, called with the node's `id`).
|
|
1884
1985
|
- Keyboard: Down / Up move between the visible nodes; Right opens a closed
|
|
1885
1986
|
parent, then moves to its first child; Left closes an open parent, or moves
|
|
@@ -1902,20 +2003,23 @@ Props:
|
|
|
1902
2003
|
- `defaultSelectedId`: `string` | `null` (default: `null`)
|
|
1903
2004
|
- `expandedIds`: `readonly string[]`
|
|
1904
2005
|
- `onChange`: `(id: string) => void`
|
|
1905
|
-
- `
|
|
2006
|
+
- `onExpandedIdsChange`: `(ids: string[]) => void`
|
|
1906
2007
|
- `selectedId`: `string` | `null`
|
|
1907
2008
|
- Other props are forwarded to `HTMLAttributes<HTMLUListElement>`, except `children` / `className` / `style` / `role` / `aria-label`.
|
|
1908
2009
|
|
|
1909
2010
|
### Accordion
|
|
1910
2011
|
|
|
1911
|
-
A collapsible section, as a compound component.
|
|
2012
|
+
A collapsible section, as a compound component. `Accordion.Button` takes the
|
|
2013
|
+
heading `level` it sits at (required, the same words as `Heading`) and draws
|
|
2014
|
+
the button inside that heading element, as the WAI-ARIA accordion pattern
|
|
2015
|
+
asks; do not wrap it in a heading of your own.
|
|
1912
2016
|
|
|
1913
2017
|
```tsx
|
|
1914
2018
|
import { Accordion } from '@k8ordo/ui';
|
|
1915
2019
|
|
|
1916
2020
|
<Accordion.Root>
|
|
1917
2021
|
<Accordion.Item>
|
|
1918
|
-
<Accordion.Button>Section 1</Accordion.Button>
|
|
2022
|
+
<Accordion.Button level="h3">Section 1</Accordion.Button>
|
|
1919
2023
|
<Accordion.Panel>Content</Accordion.Panel>
|
|
1920
2024
|
</Accordion.Item>
|
|
1921
2025
|
</Accordion.Root>;
|
|
@@ -1923,6 +2027,7 @@ import { Accordion } from '@k8ordo/ui';
|
|
|
1923
2027
|
|
|
1924
2028
|
Props (Accordion.Button):
|
|
1925
2029
|
|
|
2030
|
+
- `level`: `'h2'` | `'h3'` | `'h4'` | `'h5'` | `'h6'` (required)
|
|
1926
2031
|
- `children`: `ReactNode`
|
|
1927
2032
|
|
|
1928
2033
|
Props (Accordion.Item):
|
|
@@ -1952,16 +2057,42 @@ import { Card } from '@k8ordo/ui';
|
|
|
1952
2057
|
<div style={{ padding: 'calc(var(--spacing) * 6)' }}>Content</div>
|
|
1953
2058
|
</Card>
|
|
1954
2059
|
|
|
1955
|
-
//
|
|
1956
|
-
<Card
|
|
1957
|
-
<
|
|
2060
|
+
// The whole card is a link, or a button
|
|
2061
|
+
<Card href="/articles/1">
|
|
2062
|
+
<h3>Article title</h3>
|
|
2063
|
+
<a href="/tags/react">React</a>
|
|
2064
|
+
</Card>
|
|
2065
|
+
<Card action={choose}>
|
|
2066
|
+
<h3>Go with this plan</h3>
|
|
1958
2067
|
</Card>
|
|
1959
2068
|
```
|
|
1960
2069
|
|
|
2070
|
+
`href` makes the whole card one link and `action` one button (`href` wins
|
|
2071
|
+
when both are given). The card draws an `<a>` or a `<button>` over its
|
|
2072
|
+
content, named by the content's text, so a keyboard reaches it and a screen
|
|
2073
|
+
reader announces it. Links, buttons, and fields inside the card are raised
|
|
2074
|
+
above it and stay pressable on their own. `action` runs in a transition, as
|
|
2075
|
+
`Button`'s does: while a promise it returned is pending, the card is busy and
|
|
2076
|
+
ignores presses. With `openInNewTab` the link opens in a new tab and says so
|
|
2077
|
+
to assistive technology the way `Anchor` does: its name ends with the
|
|
2078
|
+
dictionary's `opensInNewTab` wording ("opens in a new tab" in `en`,
|
|
2079
|
+
「新しいタブで開きます」 in `ja`), which the card keeps in a `hidden` element
|
|
2080
|
+
that `aria-labelledby` also points to. Pass `renderAnchor` to draw the link
|
|
2081
|
+
with your router's component; it receives `href`, `className`,
|
|
2082
|
+
`aria-labelledby`, and `target` / `rel` with `openInNewTab`.
|
|
2083
|
+
|
|
2084
|
+
Either one gives the card the pressable look: it scales to 1.02 on hover and to
|
|
2085
|
+
0.98 while pressed. `interactive` gives that look alone, for a card whose
|
|
2086
|
+
content is a link of your own.
|
|
2087
|
+
|
|
1961
2088
|
Props:
|
|
1962
2089
|
|
|
2090
|
+
- `action`: `() => void | Promise<void>`
|
|
1963
2091
|
- `children`: `ReactNode`
|
|
2092
|
+
- `href`: `T`
|
|
1964
2093
|
- `interactive`: `boolean` (default: `false`)
|
|
2094
|
+
- `openInNewTab`: `boolean` (default: `false`)
|
|
2095
|
+
- `renderAnchor`: `(props: CardRenderAnchorProps<T>) => ReactNode` (default: `defaultRenderAnchor`)
|
|
1965
2096
|
- `variant`: `'shadow'` | `'outline'` (default: `'shadow'`)
|
|
1966
2097
|
- `width`: `'full'` | `'fit'` (default: `'full'`)
|
|
1967
2098
|
- Other props are forwarded to `HTMLAttributes<HTMLDivElement>`, except `className` / `style`.
|
|
@@ -1986,14 +2117,22 @@ Props:
|
|
|
1986
2117
|
|
|
1987
2118
|
- `message`: `string` | `string[]` (required)
|
|
1988
2119
|
- `tone`: `Status` (required)
|
|
1989
|
-
- `action`: `
|
|
2120
|
+
- `action`: `ReactNode`
|
|
1990
2121
|
- `closeLabel`: `string`
|
|
1991
2122
|
- `onClose`: `() => void`
|
|
1992
2123
|
- Other props are forwarded to `HTMLAttributes<HTMLDivElement>`, except `children` / `role` / `className` / `style`.
|
|
1993
2124
|
|
|
1994
|
-
`action` is
|
|
1995
|
-
|
|
1996
|
-
|
|
2125
|
+
`action` is the link or button you render — an `Anchor`, a `Button`, a
|
|
2126
|
+
framework's `<Link>` — and `Alert` only decides where it goes: after a
|
|
2127
|
+
one-line message, or below a list. A Server Component can pass it as well.
|
|
2128
|
+
|
|
2129
|
+
```tsx
|
|
2130
|
+
<Alert
|
|
2131
|
+
action={<Anchor href="/settings">Open settings</Anchor>}
|
|
2132
|
+
message="Your profile setup is incomplete."
|
|
2133
|
+
tone="warning"
|
|
2134
|
+
/>
|
|
2135
|
+
```
|
|
1997
2136
|
|
|
1998
2137
|
### Callout
|
|
1999
2138
|
|
|
@@ -2064,31 +2203,34 @@ const syncingId = open('info', 'Syncing…', {
|
|
|
2064
2203
|
close(syncingId);
|
|
2065
2204
|
```
|
|
2066
2205
|
|
|
2067
|
-
`
|
|
2206
|
+
`useToast` needs a `ToastProvider` above it, once at the app root. Inside a
|
|
2207
|
+
`Dialog` or a `Drawer`, `useToast` opens the toast in that `<dialog>`, since
|
|
2208
|
+
the top layer would cover one opened outside; it goes away when the dialog
|
|
2209
|
+
closes.
|
|
2068
2210
|
|
|
2069
2211
|
What `useToast()` returns:
|
|
2070
2212
|
|
|
2071
|
-
- `open`: `(tone: Status, message: string, options?: ToastOptions) => string` (returns the toast's id; `ToastOptions` is `{ duration?: number; action?:
|
|
2213
|
+
- `open`: `(tone: Status, message: string, options?: ToastOptions) => string` (returns the toast's id; `ToastOptions` is `{ duration?: number; action?: ReactNode }`. `duration` is in milliseconds and defaults to `5000`; `Number.POSITIVE_INFINITY` keeps the toast until it is closed. `action` is a `ReactNode` placed as `Alert`'s `action` is.)
|
|
2072
2214
|
- `close`: `(id: string) => void` (closes only the toast with the id `open` returned)
|
|
2073
2215
|
- `closeAll`: `() => void`
|
|
2074
2216
|
|
|
2075
2217
|
### ToastProvider
|
|
2076
2218
|
|
|
2077
|
-
|
|
2219
|
+
Holds the toasts `useToast` opens. Wrap the app root in it once; an
|
|
2220
|
+
application that opens no toasts needs no provider at all. The components'
|
|
2221
|
+
own wording needs none either: it follows `@k8ordo/i18n` (i18n, below).
|
|
2078
2222
|
|
|
2079
2223
|
```tsx
|
|
2080
2224
|
import { ToastProvider } from '@k8ordo/ui';
|
|
2081
2225
|
|
|
2082
|
-
<ToastProvider
|
|
2083
|
-
|
|
2226
|
+
<ToastProvider>
|
|
2227
|
+
<App />
|
|
2084
2228
|
</ToastProvider>;
|
|
2085
2229
|
```
|
|
2086
2230
|
|
|
2087
2231
|
Props:
|
|
2088
2232
|
|
|
2089
2233
|
- `children`: `ReactNode`
|
|
2090
|
-
- `portalRef`: `RefObject<HTMLElement | null>` (default: `null`)
|
|
2091
|
-
- `position`: `'fixed'` | `'absolute'` (default: `'fixed'`)
|
|
2092
2234
|
|
|
2093
2235
|
### Progress
|
|
2094
2236
|
|
|
@@ -2152,80 +2294,78 @@ Props:
|
|
|
2152
2294
|
|
|
2153
2295
|
## Overlays
|
|
2154
2296
|
|
|
2155
|
-
###
|
|
2297
|
+
### Dialog
|
|
2156
2298
|
|
|
2157
|
-
|
|
2299
|
+
A modal dialog, opened in a `<dialog>` in the browser's top layer from the
|
|
2300
|
+
center of the screen or, with `side="bottom"`, as a sheet from the bottom.
|
|
2301
|
+
`title` is drawn as an `h2` heading with a close button, and it names the
|
|
2302
|
+
dialog; a dialog that draws no heading is named by `label` instead (one or the
|
|
2303
|
+
other, never both). `description` is drawn above the children and is the only
|
|
2304
|
+
text the dialog is described by: the body — a form, the buttons — is never
|
|
2305
|
+
read out as its description. `role="alertdialog"` goes on the `<dialog>`
|
|
2306
|
+
itself, for a confirmation that interrupts.
|
|
2158
2307
|
|
|
2159
2308
|
```tsx
|
|
2160
|
-
import {
|
|
2309
|
+
import { Dialog } from '@k8ordo/ui';
|
|
2161
2310
|
|
|
2162
|
-
<
|
|
2311
|
+
<Dialog isOpen={open} onClose={() => setOpen(false)} title="Confirm">
|
|
2163
2312
|
Content
|
|
2164
|
-
</
|
|
2313
|
+
</Dialog>;
|
|
2314
|
+
|
|
2315
|
+
<Dialog
|
|
2316
|
+
description="A deleted file cannot be restored."
|
|
2317
|
+
isOpen={open}
|
|
2318
|
+
onClose={() => setOpen(false)}
|
|
2319
|
+
role="alertdialog"
|
|
2320
|
+
title="Delete the file?"
|
|
2321
|
+
>
|
|
2322
|
+
<Button onClick={remove}>Delete</Button>
|
|
2323
|
+
</Dialog>;
|
|
2324
|
+
|
|
2325
|
+
<Dialog isOpen={open} label="Image preview" onClose={() => setOpen(false)}>
|
|
2326
|
+
<img alt="" src={src} />
|
|
2327
|
+
</Dialog>;
|
|
2165
2328
|
```
|
|
2166
2329
|
|
|
2167
2330
|
Props:
|
|
2168
2331
|
|
|
2169
|
-
- `aria-describedby`: `string`
|
|
2170
|
-
- `aria-label`: `string`
|
|
2171
|
-
- `aria-labelledby`: `string`
|
|
2172
2332
|
- `children`: `ReactNode`
|
|
2173
2333
|
- `defaultOpen`: `boolean`
|
|
2334
|
+
- `description`: `ReactNode`
|
|
2174
2335
|
- `isOpen`: `boolean`
|
|
2336
|
+
- `label`: `string`
|
|
2175
2337
|
- `onClose`: `() => void`
|
|
2176
2338
|
- `ref`: `Ref<HTMLDialogElement>`
|
|
2177
|
-
- `side`: `ModalSide` (default: `'center'`)
|
|
2178
|
-
|
|
2179
|
-
Name resolution goes `aria-label` / `aria-labelledby` first, then the heading registered by a `Dialog.Root` inside. With neither, the dialog is unnamed — so pass `aria-label` when you place content directly without a `Dialog`.
|
|
2180
|
-
|
|
2181
|
-
```tsx
|
|
2182
|
-
<Modal aria-label="Image preview" isOpen={open} onClose={onClose}>
|
|
2183
|
-
<img alt="" src={src} />
|
|
2184
|
-
</Modal>
|
|
2185
|
-
```
|
|
2186
|
-
|
|
2187
|
-
### Dialog
|
|
2188
|
-
|
|
2189
|
-
A compound component, used together with Modal.
|
|
2190
|
-
|
|
2191
|
-
```tsx
|
|
2192
|
-
import { Modal, Dialog } from '@k8ordo/ui';
|
|
2193
|
-
|
|
2194
|
-
<Modal isOpen={open} onClose={onClose}>
|
|
2195
|
-
<Dialog.Root>
|
|
2196
|
-
<Dialog.Header title="Confirm" onClose={onClose} />
|
|
2197
|
-
<Dialog.Content>Content</Dialog.Content>
|
|
2198
|
-
</Dialog.Root>
|
|
2199
|
-
</Modal>;
|
|
2200
|
-
```
|
|
2201
|
-
|
|
2202
|
-
Props (Dialog.Content):
|
|
2203
|
-
|
|
2204
|
-
- `children`: `ReactNode`
|
|
2205
|
-
|
|
2206
|
-
Props (Dialog.Header):
|
|
2207
|
-
|
|
2208
|
-
- `onClose`: `() => void` (required)
|
|
2209
|
-
- `title`: `ReactNode` (required)
|
|
2210
|
-
|
|
2211
|
-
Props (Dialog.Root):
|
|
2212
|
-
|
|
2213
|
-
- `children`: `ReactNode`
|
|
2214
|
-
- `id`: `string`
|
|
2215
|
-
- `ref`: `Ref<HTMLElement>`
|
|
2216
2339
|
- `role`: `'dialog'` | `'alertdialog'`
|
|
2217
|
-
- `
|
|
2340
|
+
- `side`: `DialogSide` (default: `'center'`)
|
|
2341
|
+
- `title`: `ReactNode`
|
|
2342
|
+
|
|
2343
|
+
`onClose` is called when the dialog closes while it is meant to be open —
|
|
2344
|
+
Escape, a click on the backdrop, the close button, a `<form method="dialog">`,
|
|
2345
|
+
or `<Activity>` hiding it — and never when you set `isOpen` to `false`
|
|
2346
|
+
yourself, so a route-bound dialog that goes back in `onClose` does not go back
|
|
2347
|
+
twice. The children stay mounted while the dialog is closed, so an
|
|
2348
|
+
uncontrolled field keeps what was typed until the next opening; render them
|
|
2349
|
+
under `isOpen` when they should start over. `ref` is the `<dialog>` element.
|
|
2350
|
+
|
|
2351
|
+
A dialog opens in the browser's top layer, and the page behind it is inert, so
|
|
2352
|
+
anything portaled to `document.body` ends up behind it and cannot be pressed.
|
|
2353
|
+
Floating UI of your own opens in place with the `popover` attribute, which
|
|
2354
|
+
reaches the top layer from where it is. A library that portals takes the
|
|
2355
|
+
dialog's `<dialog>` from `ref` as its container; if a part deep inside needs
|
|
2356
|
+
it, put your own Context in the children.
|
|
2218
2357
|
|
|
2219
2358
|
### CommandPalette
|
|
2220
2359
|
|
|
2221
|
-
A command palette: a
|
|
2222
|
-
filters. Typing matches each item's `label` and `keywords`, case-insensitively
|
|
2360
|
+
A command palette: a modal dialog holding a search field and the list of commands it
|
|
2361
|
+
filters. Typing matches each item's `label` and `keywords`, case-insensitively
|
|
2362
|
+
in the language of `@k8ordo/i18n`'s current locale.
|
|
2223
2363
|
`ArrowDown` / `ArrowUp` move through the matches and wrap around, `Enter` or a
|
|
2224
|
-
click runs the item's `
|
|
2364
|
+
click runs the item's `onAction` after closing the palette, and `Escape` closes
|
|
2225
2365
|
it; focus stays in the search field throughout (the WAI-ARIA combobox, with the
|
|
2226
2366
|
list always shown). Items that share a `group` are gathered under that heading,
|
|
2227
2367
|
in the order the group first appears, and `shortcut` keys are drawn with `Kbd`.
|
|
2228
|
-
Each opening starts from an empty search. Open and close it like `
|
|
2368
|
+
Each opening starts from an empty search. Open and close it like `Dialog`
|
|
2229
2369
|
(`isOpen` / `defaultOpen` / `onClose`); a key such as ⌘K / Ctrl+K is the
|
|
2230
2370
|
application's to wire.
|
|
2231
2371
|
|
|
@@ -2241,13 +2381,13 @@ import { CommandPalette } from '@k8ordo/ui';
|
|
|
2241
2381
|
label: 'New file',
|
|
2242
2382
|
group: 'File',
|
|
2243
2383
|
shortcut: ['⌘', 'N'],
|
|
2244
|
-
|
|
2384
|
+
onAction: createFile,
|
|
2245
2385
|
},
|
|
2246
2386
|
{
|
|
2247
2387
|
id: 'theme',
|
|
2248
2388
|
label: 'Toggle theme',
|
|
2249
2389
|
keywords: ['dark', 'light'],
|
|
2250
|
-
|
|
2390
|
+
onAction: toggleTheme,
|
|
2251
2391
|
},
|
|
2252
2392
|
]}
|
|
2253
2393
|
/>;
|
|
@@ -2256,21 +2396,27 @@ import { CommandPalette } from '@k8ordo/ui';
|
|
|
2256
2396
|
Props:
|
|
2257
2397
|
|
|
2258
2398
|
- `items`: `readonly CommandPaletteItem[]` (required)
|
|
2259
|
-
- `aria-label`: `string`
|
|
2260
2399
|
- `defaultOpen`: `boolean`
|
|
2261
2400
|
- `isOpen`: `boolean`
|
|
2401
|
+
- `label`: `string`
|
|
2262
2402
|
- `onClose`: `() => void`
|
|
2263
2403
|
- `placeholder`: `string`
|
|
2264
2404
|
- `ref`: `Ref<HTMLDialogElement>`
|
|
2265
2405
|
|
|
2266
2406
|
### Drawer
|
|
2267
2407
|
|
|
2268
|
-
A
|
|
2408
|
+
A panel that slides in from the left or right edge of the screen, in a
|
|
2409
|
+
`<dialog>` like `Dialog`. `title` is drawn as an `h2` heading with a close
|
|
2410
|
+
button and names the drawer, and `description`, drawn above the children, is
|
|
2411
|
+
the only text it is described by. The body scrolls on its own below the
|
|
2412
|
+
heading. `onClose` and the children follow `Dialog`'s rules: it is called only
|
|
2413
|
+
when the drawer closes while it is meant to be open, and the children stay
|
|
2414
|
+
mounted while it is closed.
|
|
2269
2415
|
|
|
2270
2416
|
```tsx
|
|
2271
2417
|
import { Drawer } from '@k8ordo/ui';
|
|
2272
2418
|
|
|
2273
|
-
<Drawer
|
|
2419
|
+
<Drawer isOpen={open} onClose={() => setOpen(false)} side="left" title="Menu">
|
|
2274
2420
|
Content
|
|
2275
2421
|
</Drawer>;
|
|
2276
2422
|
```
|
|
@@ -2280,43 +2426,59 @@ Props:
|
|
|
2280
2426
|
- `title`: `ReactNode` (required)
|
|
2281
2427
|
- `children`: `ReactNode`
|
|
2282
2428
|
- `defaultOpen`: `boolean`
|
|
2429
|
+
- `description`: `ReactNode`
|
|
2283
2430
|
- `isOpen`: `boolean`
|
|
2284
2431
|
- `onClose`: `() => void`
|
|
2432
|
+
- `ref`: `Ref<HTMLDialogElement>`
|
|
2285
2433
|
- `side`: `DrawerSide` (default: `'right'`)
|
|
2286
2434
|
|
|
2287
2435
|
### Popover
|
|
2288
2436
|
|
|
2289
|
-
A
|
|
2437
|
+
A panel that opens next to its trigger, placed with CSS Anchor Positioning, as
|
|
2438
|
+
a compound component. It is always a dialog: `Popover.Content` renders
|
|
2439
|
+
`role="dialog"` named by `label`, opening moves focus into it, and a click
|
|
2440
|
+
outside, Escape, or tabbing out closes it. The content draws the surface — the
|
|
2441
|
+
raised ground, the corners, the shadow, and an outline under high contrast —
|
|
2442
|
+
and no padding, so the padding comes from what you put inside.
|
|
2290
2443
|
|
|
2291
2444
|
```tsx
|
|
2292
2445
|
import { Popover } from '@k8ordo/ui';
|
|
2293
2446
|
|
|
2294
2447
|
<Popover.Root placement="bottom">
|
|
2295
2448
|
<Popover.Trigger renderItem={(props) => <Button {...props}>Open</Button>} />
|
|
2296
|
-
<Popover.Content
|
|
2297
|
-
|
|
2298
|
-
|
|
2449
|
+
<Popover.Content label="Filters">
|
|
2450
|
+
<Stack gap="sm" padding="md">
|
|
2451
|
+
…
|
|
2452
|
+
</Stack>
|
|
2453
|
+
</Popover.Content>
|
|
2299
2454
|
</Popover.Root>;
|
|
2300
2455
|
```
|
|
2301
2456
|
|
|
2457
|
+
A menu, a listbox, and a tooltip are their own components (`DropdownMenu`,
|
|
2458
|
+
`ListBox`, `Tooltip`); they are built on the same positioning.
|
|
2459
|
+
|
|
2460
|
+
The trigger is the content's implicit anchor: the content opens with
|
|
2461
|
+
`showPopover({ source: trigger })` and positions itself with
|
|
2462
|
+
`position-anchor: auto`. Nothing is written to the trigger's `anchor-name`, so
|
|
2463
|
+
one element can be the trigger of a popover and of a tooltip at once (an
|
|
2464
|
+
`IconButton` as a `Popover.Trigger`), and a trigger keeps an `anchor-name` of
|
|
2465
|
+
its own.
|
|
2466
|
+
|
|
2302
2467
|
Props (Root):
|
|
2303
2468
|
|
|
2304
2469
|
- `children`: `ReactNode`
|
|
2305
|
-
- `closeOnClickAway`: `boolean` (default: `true`)
|
|
2306
2470
|
- `defaultOpen`: `boolean` (default: `false`)
|
|
2307
2471
|
- `flipDisabled`: `boolean` (default: `false`)
|
|
2308
2472
|
- `isOpen`: `boolean`
|
|
2309
2473
|
- `onChange`: `(isOpen: boolean) => void`
|
|
2310
2474
|
- `placement`: `Placement` (default: `'bottom-start'`)
|
|
2311
|
-
- `role`: `'dialog'` | `'menu'` | `'listbox'` (default: `'menu'`)
|
|
2312
|
-
- `trapFocus`: `boolean` (default: `true`)
|
|
2313
2475
|
|
|
2314
2476
|
Escape closes **only the innermost one** when they are nested.
|
|
2315
2477
|
|
|
2316
2478
|
Props (Popover.Content):
|
|
2317
2479
|
|
|
2318
|
-
- `
|
|
2319
|
-
- `
|
|
2480
|
+
- `children`: `ReactNode` (required)
|
|
2481
|
+
- `label`: `string` (required)
|
|
2320
2482
|
|
|
2321
2483
|
Props (Popover.Trigger):
|
|
2322
2484
|
|
|
@@ -2369,6 +2531,27 @@ import { DropdownMenu } from '@k8ordo/ui';
|
|
|
2369
2531
|
</DropdownMenu.Root>;
|
|
2370
2532
|
```
|
|
2371
2533
|
|
|
2534
|
+
An item is an action or a link. With `onAction` it renders a `<button
|
|
2535
|
+
role="menuitem">` and calls `onAction` when chosen. With `href` it renders an
|
|
2536
|
+
`<a role="menuitem">`: choosing it closes the menu and leaves the navigation to
|
|
2537
|
+
the browser, so the router's interception, a middle click, and opening in a new
|
|
2538
|
+
tab all work. Space chooses a link item as it does a button item, rather than
|
|
2539
|
+
scrolling the page. `renderAnchor` draws a link component of your own instead;
|
|
2540
|
+
its bag is `href`, `className`, `children`, `role`, and the keyboard wiring
|
|
2541
|
+
(`id`, `ref`, `tabIndex`, `onFocus`, `onClick`, `onKeyDown`), so spread all of
|
|
2542
|
+
it.
|
|
2543
|
+
|
|
2544
|
+
```tsx
|
|
2545
|
+
<DropdownMenu.Content>
|
|
2546
|
+
<DropdownMenu.Item href="/settings" label="Settings" />
|
|
2547
|
+
<DropdownMenu.Item
|
|
2548
|
+
href="/billing"
|
|
2549
|
+
label="Billing"
|
|
2550
|
+
renderAnchor={(props) => <Link {...props} />}
|
|
2551
|
+
/>
|
|
2552
|
+
</DropdownMenu.Content>
|
|
2553
|
+
```
|
|
2554
|
+
|
|
2372
2555
|
Props (Root):
|
|
2373
2556
|
|
|
2374
2557
|
- `children`: `ReactNode`
|
|
@@ -2379,8 +2562,8 @@ Props (Root):
|
|
|
2379
2562
|
|
|
2380
2563
|
Trigger variants:
|
|
2381
2564
|
|
|
2382
|
-
- `DropdownMenu.Trigger`: text-based (`label`, `size`, `variant`)
|
|
2383
|
-
- `DropdownMenu.IconTrigger`: icon-based (`icon`, `label`)
|
|
2565
|
+
- `DropdownMenu.Trigger`: text-based (`label`, and `Button`'s `size`, `variant`, `color`)
|
|
2566
|
+
- `DropdownMenu.IconTrigger`: icon-based (`icon`, `label`, and `IconButton`'s `size`, `variant`, `color`)
|
|
2384
2567
|
|
|
2385
2568
|
Props (DropdownMenu.Content):
|
|
2386
2569
|
|
|
@@ -2390,11 +2573,16 @@ Props (DropdownMenu.IconTrigger):
|
|
|
2390
2573
|
|
|
2391
2574
|
- `icon`: `ReactNode` (required)
|
|
2392
2575
|
- `label`: `string` (required)
|
|
2576
|
+
- `color`: `ComponentProps<typeof IconButton>['color']` (default: `'base'`)
|
|
2577
|
+
- `size`: `ComponentProps<typeof IconButton>['size']` (default: `'md'`)
|
|
2578
|
+
- `variant`: `ComponentProps<typeof IconButton>['variant']` (default: `'solid'`)
|
|
2393
2579
|
|
|
2394
2580
|
Props (DropdownMenu.Item):
|
|
2395
2581
|
|
|
2396
2582
|
- `label`: `string` (required)
|
|
2397
|
-
- `
|
|
2583
|
+
- `href`: `T`
|
|
2584
|
+
- `onAction`: `() => void`
|
|
2585
|
+
- `renderAnchor`: `(props: RenderItemAnchorProps<T>) => ReactNode` (default: `defaultRenderAnchor`)
|
|
2398
2586
|
|
|
2399
2587
|
`DropdownMenu.SubMenu` is a nested menu. Hovering the `label` row, or opening it from the keyboard, opens the child menu to the right.
|
|
2400
2588
|
|
|
@@ -2406,6 +2594,7 @@ Props (DropdownMenu.SubMenu):
|
|
|
2406
2594
|
Props (DropdownMenu.Trigger):
|
|
2407
2595
|
|
|
2408
2596
|
- `label`: `string` (required)
|
|
2597
|
+
- `color`: `ComponentProps<typeof Button>['color']` (default: `'base'`)
|
|
2409
2598
|
- `size`: `ComponentProps<typeof Button>['size']` (default: `'md'`)
|
|
2410
2599
|
- `variant`: `ComponentProps<typeof Button>['variant']` (default: `'solid'`)
|
|
2411
2600
|
|
|
@@ -2413,8 +2602,8 @@ Props (DropdownMenu.Trigger):
|
|
|
2413
2602
|
|
|
2414
2603
|
A menu opened by right-clicking (or by the keyboard's context-menu key or
|
|
2415
2604
|
Shift+F10) on an area, shown at the pointer. The inside is `DropdownMenu`'s —
|
|
2416
|
-
`ContextMenu.Content`, `ContextMenu.Item` (`label`
|
|
2417
|
-
`ContextMenu.SubMenu` behave exactly like theirs — and only how it opens and
|
|
2605
|
+
`ContextMenu.Content`, `ContextMenu.Item` (`label` with `onAction` or `href`),
|
|
2606
|
+
and `ContextMenu.SubMenu` behave exactly like theirs — and only how it opens and
|
|
2418
2607
|
where differ. When it closes from inside (an item, Escape), focus returns to
|
|
2419
2608
|
the element that had it before it opened; closing by clicking elsewhere leaves
|
|
2420
2609
|
focus where the click put it.
|
|
@@ -2458,7 +2647,9 @@ Props (ContextMenu.Content):
|
|
|
2458
2647
|
Props (ContextMenu.Item):
|
|
2459
2648
|
|
|
2460
2649
|
- `label`: `string` (required)
|
|
2461
|
-
- `
|
|
2650
|
+
- `href`: `T`
|
|
2651
|
+
- `onAction`: `() => void`
|
|
2652
|
+
- `renderAnchor`: `(props: RenderItemAnchorProps<T>) => ReactNode` (default: `defaultRenderAnchor`)
|
|
2462
2653
|
|
|
2463
2654
|
Props (ContextMenu.SubMenu):
|
|
2464
2655
|
|
|
@@ -2471,54 +2662,37 @@ Props (ContextMenu.Trigger):
|
|
|
2471
2662
|
|
|
2472
2663
|
### ListBox
|
|
2473
2664
|
|
|
2474
|
-
|
|
2665
|
+
Picks one option from a list that opens from a button. The choices use the same `Option` (`{ value, label }`) as `Select`. It is one component: the button shows the current value, or an icon when `icon` is given, and the list holds `options`.
|
|
2475
2666
|
|
|
2476
2667
|
```tsx
|
|
2477
2668
|
import { ListBox } from '@k8ordo/ui';
|
|
2478
2669
|
|
|
2479
|
-
<ListBox
|
|
2670
|
+
<ListBox
|
|
2671
|
+
label="Items per page"
|
|
2480
2672
|
onChange={onChange}
|
|
2481
2673
|
options={[
|
|
2482
2674
|
{ value: '1', label: 'Option 1' },
|
|
2483
2675
|
{ value: '2', label: 'Option 2' },
|
|
2484
2676
|
]}
|
|
2485
2677
|
value={value}
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
</ListBox.Root>;
|
|
2678
|
+
/>;
|
|
2679
|
+
|
|
2680
|
+
<ListBox icon={<ListIcon />} label="Sort" options={sortOptions} />;
|
|
2490
2681
|
```
|
|
2491
2682
|
|
|
2492
|
-
Props
|
|
2683
|
+
Props:
|
|
2493
2684
|
|
|
2494
2685
|
- `options`: `readonly Option[]` (required)
|
|
2495
|
-
- `children`: `ReactNode`
|
|
2496
2686
|
- `defaultValue`: `Option['value']`
|
|
2687
|
+
- `helpContent`: `ReactElement`
|
|
2688
|
+
- `icon`: `ReactElement`
|
|
2689
|
+
- `label`: `string`
|
|
2497
2690
|
- `onChange`: `(value: Option['value']) => void`
|
|
2498
2691
|
- `placement`: `Placement` (default: `'bottom'`)
|
|
2692
|
+
- `size`: `'sm'` | `'md'` | `'lg'` (default: `'md'`)
|
|
2499
2693
|
- `value`: `Option['value']`
|
|
2500
2694
|
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
- `ListBox.Trigger`: text-based (`size`, `label`)
|
|
2504
|
-
- `ListBox.IconTrigger`: icon-based (`size`, `icon`, `label`)
|
|
2505
|
-
|
|
2506
|
-
Passing `label` makes the trigger's accessible name "label + current value". Omit it and only the current value is used, so pass it when there is no heading nearby.
|
|
2507
|
-
|
|
2508
|
-
Props (Content):
|
|
2509
|
-
|
|
2510
|
-
- `helpContent`: `ReactElement`
|
|
2511
|
-
|
|
2512
|
-
Props (ListBox.IconTrigger):
|
|
2513
|
-
|
|
2514
|
-
- `icon`: `ReactElement` (required)
|
|
2515
|
-
- `label`: `string`
|
|
2516
|
-
- `size`: `ComponentProps<typeof Button>['size']` (default: `'md'`)
|
|
2517
|
-
|
|
2518
|
-
Props (ListBox.Trigger):
|
|
2519
|
-
|
|
2520
|
-
- `label`: `string`
|
|
2521
|
-
- `size`: `ComponentProps<typeof Button>['size']` (default: `'md'`)
|
|
2695
|
+
Passing `label` makes the button's accessible name "label + current value". Omit it and only the current value is used, so pass it when there is no heading nearby. `helpContent` sits above the list, outside `role="listbox"`, and describes the list.
|
|
2522
2696
|
|
|
2523
2697
|
## Layout
|
|
2524
2698
|
|
|
@@ -2652,80 +2826,10 @@ Props (ResizablePanels.Handle):
|
|
|
2652
2826
|
- _No props of its own._
|
|
2653
2827
|
- Other props are forwarded to `HTMLAttributes<HTMLDivElement>`, except `className` / `style` / `role` / `children` / `tabIndex` / `aria-orientation` / `aria-valuenow` / `aria-valuemin` / `aria-valuemax` / `aria-controls`.
|
|
2654
2828
|
|
|
2655
|
-
## Observers
|
|
2656
|
-
|
|
2657
|
-
Components that watch their children and report back without adding a wrapper
|
|
2658
|
-
element. They are built on React's Fragment refs, so whatever the children
|
|
2659
|
-
render is what gets observed — including host elements that mount later.
|
|
2660
|
-
|
|
2661
|
-
### InView
|
|
2662
|
-
|
|
2663
|
-
Reports whether its children are inside the viewport, or inside `root`.
|
|
2664
|
-
|
|
2665
|
-
```tsx
|
|
2666
|
-
import { InView } from '@k8ordo/ui';
|
|
2667
|
-
|
|
2668
|
-
const [isInView, setIsInView] = useState(false);
|
|
2669
|
-
|
|
2670
|
-
<InView onChange={setIsInView}>
|
|
2671
|
-
<section>…</section>
|
|
2672
|
-
</InView>;
|
|
2673
|
-
|
|
2674
|
-
// inside a scroll container, and only until it has been seen once
|
|
2675
|
-
const [container, setContainer] = useState<HTMLElement | null>(null);
|
|
2676
|
-
|
|
2677
|
-
<div ref={setContainer} style={{ overflowY: 'auto' }}>
|
|
2678
|
-
<InView once onChange={reveal} root={container} rootMargin="0px 0px 24px 0px">
|
|
2679
|
-
<img alt="" src="…" />
|
|
2680
|
-
</InView>
|
|
2681
|
-
</div>;
|
|
2682
|
-
```
|
|
2683
|
-
|
|
2684
|
-
- `onChange` reports the state as soon as a host element is observed, then again
|
|
2685
|
-
each time it flips. The same value is never reported twice in a row, even
|
|
2686
|
-
when `root` changes and the observer is re-created.
|
|
2687
|
-
- With several host elements, `isInView` is `true` while **any** of them
|
|
2688
|
-
intersects, and it follows children that mount or unmount later. While the
|
|
2689
|
-
children render no host element, `onChange` is not called at all — the first
|
|
2690
|
-
report comes once one mounts.
|
|
2691
|
-
- `once` stops observing after the first `true`.
|
|
2692
|
-
- Hold `root` in state, not a `RefObject`: the observer has to be re-created
|
|
2693
|
-
once the element exists.
|
|
2694
|
-
|
|
2695
|
-
Props:
|
|
2696
|
-
|
|
2697
|
-
- `children`: `ReactNode` (required)
|
|
2698
|
-
- `onChange`: `(isInView: boolean) => void` (required)
|
|
2699
|
-
- `once`: `boolean` (default: `false`)
|
|
2700
|
-
- `root`: `Element` | `null` (default: `null`)
|
|
2701
|
-
- `rootMargin`: `string` (default: `'0px'`)
|
|
2702
|
-
- `threshold`: `number` (default: `0`)
|
|
2703
|
-
|
|
2704
|
-
### Resize
|
|
2705
|
-
|
|
2706
|
-
Calls `onChange` when the size of its children changes.
|
|
2707
|
-
|
|
2708
|
-
```tsx
|
|
2709
|
-
import { Resize } from '@k8ordo/ui';
|
|
2710
|
-
|
|
2711
|
-
<Resize onChange={remeasure}>
|
|
2712
|
-
<div>…</div>
|
|
2713
|
-
</Resize>;
|
|
2714
|
-
```
|
|
2715
|
-
|
|
2716
|
-
- `onChange` is also called once when observation starts, as a native
|
|
2717
|
-
`ResizeObserver` is.
|
|
2718
|
-
- It takes no argument; read what you need from the DOM in the handler.
|
|
2719
|
-
|
|
2720
|
-
Props:
|
|
2721
|
-
|
|
2722
|
-
- `children`: `ReactNode` (required)
|
|
2723
|
-
- `onChange`: `() => void` (required)
|
|
2724
|
-
|
|
2725
2829
|
## Icons
|
|
2726
2830
|
|
|
2727
2831
|
Decorative icons, from `@k8ordo/ui/icons` (the root entry does not export
|
|
2728
|
-
them). Each renders an `<svg>` with `aria-hidden
|
|
2832
|
+
them). Each renders an `<svg>` with `aria-hidden`, so
|
|
2729
2833
|
the accessible name belongs to the control around it — an `IconButton`'s
|
|
2730
2834
|
`label`, for example. They are drawn as lines in `currentColor`, so an icon
|
|
2731
2835
|
takes the text color of where it sits.
|
|
@@ -2758,22 +2862,23 @@ The icons: `AlertIcon`, `ArrowDownIcon`, `ArrowLeftIcon`, `ArrowRightIcon`,
|
|
|
2758
2862
|
`BotIcon`, `BotMessageIcon`, `CalendarIcon`, `CheckIcon`, `ChevronDownIcon`,
|
|
2759
2863
|
`ChevronIcon`, `ChevronLeftIcon`, `ChevronRightIcon`, `ChevronsUpDownIcon`,
|
|
2760
2864
|
`ChevronUpIcon`, `CircleAlertIcon`, `CircleCheckIcon`, `CircleHelpIcon`,
|
|
2761
|
-
`CircleXIcon`, `ClockIcon`, `CodeIcon`, `ColorScaleIcon`,
|
|
2762
|
-
`CopyIcon`, `DownloadIcon`, `EllipsisIcon`,
|
|
2763
|
-
`ExternalLinkIcon`, `EyeClosedIcon`, `EyeIcon`,
|
|
2764
|
-
`
|
|
2765
|
-
`
|
|
2766
|
-
`
|
|
2767
|
-
`
|
|
2768
|
-
`
|
|
2769
|
-
`
|
|
2770
|
-
`
|
|
2771
|
-
`
|
|
2772
|
-
`
|
|
2773
|
-
`
|
|
2774
|
-
`
|
|
2775
|
-
`
|
|
2776
|
-
`
|
|
2865
|
+
`CircleXIcon`, `ClipboardCheckIcon`, `ClockIcon`, `CodeIcon`, `ColorScaleIcon`,
|
|
2866
|
+
`ContrastIcon`, `CopyIcon`, `DownloadIcon`, `EllipsisIcon`,
|
|
2867
|
+
`EllipsisVerticalIcon`, `ExternalLinkIcon`, `EyeClosedIcon`, `EyeIcon`,
|
|
2868
|
+
`FileIcon`, `FileTextIcon`, `FilterIcon`, `FlaskIcon`, `FolderIcon`,
|
|
2869
|
+
`FolderOpenIcon`, `GitForkIcon`, `GitPullRequestIcon`, `GlobeIcon`, `GridIcon`,
|
|
2870
|
+
`GripVerticalIcon`, `HeartIcon`, `HistoryIcon`, `HomeIcon`, `ImageIcon`,
|
|
2871
|
+
`InfoIcon`, `LightbulbIcon`, `LinkIcon`, `ListIcon`, `LockIcon`, `LockOpenIcon`,
|
|
2872
|
+
`LogInIcon`, `LogOutIcon`, `MailIcon`, `MapPinIcon`, `MaximizeIcon`, `MenuIcon`,
|
|
2873
|
+
`MessageCircleIcon`, `MinimizeIcon`, `MinusIcon`, `MonitorIcon`, `MoonIcon`,
|
|
2874
|
+
`PackageIcon`, `PaintBucketIcon`, `PaletteIcon`, `PanelLeftIcon`,
|
|
2875
|
+
`PaperclipIcon`, `PauseIcon`, `PencilIcon`, `PinIcon`, `PlayIcon`, `PlusIcon`,
|
|
2876
|
+
`PresentationIcon`, `RedoIcon`, `RefreshIcon`, `RocketIcon`, `RssIcon`,
|
|
2877
|
+
`SearchIcon`, `SendIcon`, `SettingsIcon`, `ShareIcon`, `ShieldCheckIcon`,
|
|
2878
|
+
`SmileIcon`, `SparklesIcon`, `SquareIcon`, `SquircleIcon`, `StarIcon`,
|
|
2879
|
+
`SunIcon`, `TableIcon`, `TagIcon`, `TextHorizontalIcon`, `TextVerticalIcon`,
|
|
2880
|
+
`ThumbsDownIcon`, `ThumbsUpIcon`, `TrashIcon`, `TriangleAlertIcon`, `UndoIcon`,
|
|
2881
|
+
`UploadIcon`, `UserIcon`, `UsersIcon`, `XIcon`.
|
|
2777
2882
|
|
|
2778
2883
|
<!-- /generated:icons -->
|
|
2779
2884
|
|
|
@@ -2798,46 +2903,9 @@ export const BrandIcon = ({ size = 'md' }: Partial<BaseIconProps>) => (
|
|
|
2798
2903
|
```
|
|
2799
2904
|
|
|
2800
2905
|
`renderItem` receives `IconRenderProps`
|
|
2801
|
-
(`{ className: string; 'aria-hidden': true
|
|
2906
|
+
(`{ className: string; 'aria-hidden': true }`); the types
|
|
2802
2907
|
`BaseIconProps` (`{ size }`) and `IconRenderProps` are exported as well.
|
|
2803
2908
|
|
|
2804
|
-
## Providers
|
|
2805
|
-
|
|
2806
|
-
### UIProvider
|
|
2807
|
-
|
|
2808
|
-
Wrap the app root once. It includes ToastProvider. The components' own wording needs no provider: it follows `@k8ordo/i18n` (i18n, below).
|
|
2809
|
-
|
|
2810
|
-
```tsx
|
|
2811
|
-
import { UIProvider } from '@k8ordo/ui';
|
|
2812
|
-
|
|
2813
|
-
<UIProvider>
|
|
2814
|
-
<App />
|
|
2815
|
-
</UIProvider>;
|
|
2816
|
-
```
|
|
2817
|
-
|
|
2818
|
-
Props:
|
|
2819
|
-
|
|
2820
|
-
- `children`: `ReactNode`
|
|
2821
|
-
|
|
2822
|
-
### PortalRootProvider
|
|
2823
|
-
|
|
2824
|
-
A context that shares a portal container with your own `createPortal` calls;
|
|
2825
|
-
read it with `usePortalRoot()`. The library's overlays do not read it — they
|
|
2826
|
-
open in the top layer (`<dialog>`, the Popover API), and toasts go where
|
|
2827
|
-
`ToastProvider`'s `portalRef` points. `Modal` passes its own `<dialog>` as the
|
|
2828
|
-
value, so a portal placed through `usePortalRoot()` inside a modal stays in it.
|
|
2829
|
-
|
|
2830
|
-
```tsx
|
|
2831
|
-
import { PortalRootProvider, usePortalRoot } from '@k8ordo/ui';
|
|
2832
|
-
|
|
2833
|
-
<PortalRootProvider value={containerRef}>{children}</PortalRootProvider>;
|
|
2834
|
-
```
|
|
2835
|
-
|
|
2836
|
-
Props:
|
|
2837
|
-
|
|
2838
|
-
- `value`: `RefObject<HTMLElement | null>` (required)
|
|
2839
|
-
- `children`: `ReactNode`
|
|
2840
|
-
|
|
2841
2909
|
## i18n (message dictionary)
|
|
2842
2910
|
|
|
2843
2911
|
The wording components own internally (close, required, loading, …) comes from a dictionary, picked by `@k8ordo/i18n`'s current locale. There is no provider and nothing to pass.
|
|
@@ -2864,7 +2932,7 @@ A regional tag without a dictionary of its own (`en-US`) reads its language's (`
|
|
|
2864
2932
|
|
|
2865
2933
|
**Component prop > registered dictionary > built-in dictionary**.
|
|
2866
2934
|
|
|
2867
|
-
A component with a wording prop of its own — `Spinner`'s `label`, `Alert`'s `closeLabel`, `PasswordInput`'s `showLabel` / `hideLabel`, `Pagination`'s `prevLabel` / `nextLabel` — takes that prop over the dictionary.
|
|
2935
|
+
A component with a wording prop of its own — `Spinner`'s `label`, `Alert`'s `closeLabel`, `PasswordInput`'s `showLabel` / `hideLabel`, `Pagination`'s `label` / `prevLabel` / `nextLabel`, `CommandPalette`'s `label` — takes that prop over the dictionary.
|
|
2868
2936
|
|
|
2869
2937
|
```tsx
|
|
2870
2938
|
// Whatever the locale, this one Spinner reads 「保存中」
|
|
@@ -2878,7 +2946,6 @@ import {
|
|
|
2878
2946
|
en,
|
|
2879
2947
|
getMessages,
|
|
2880
2948
|
ja,
|
|
2881
|
-
messageUsage,
|
|
2882
2949
|
registerMessages,
|
|
2883
2950
|
type Messages,
|
|
2884
2951
|
} from '@k8ordo/ui/i18n';
|
|
@@ -2904,7 +2971,8 @@ function DismissButton({ onDismiss }) {
|
|
|
2904
2971
|
### Key list
|
|
2905
2972
|
|
|
2906
2973
|
Every key in the `Messages` type, grouped by the components that draw it —
|
|
2907
|
-
the same mapping `
|
|
2974
|
+
the same mapping `@k8ordo/ui/props.json` carries under `messages`. All values
|
|
2975
|
+
are `string`.
|
|
2908
2976
|
|
|
2909
2977
|
<!-- generated:message-keys -->
|
|
2910
2978
|
|
|
@@ -2921,13 +2989,14 @@ the same mapping `messageUsage` exports. All values are `string`.
|
|
|
2921
2989
|
- Combobox: `comboboxToggle`, `comboboxEmpty`, `comboboxFailed`
|
|
2922
2990
|
- FileField: `fileFieldRemove`
|
|
2923
2991
|
- FileField.Dropzone / FileField (generative UI): `fileFieldTrigger`, `fileFieldDrop`
|
|
2924
|
-
- NumberField: `numberFieldIncrement`, `numberFieldDecrement
|
|
2992
|
+
- NumberField: `numberFieldIncrement`, `numberFieldDecrement`
|
|
2925
2993
|
- RangeSlider: `rangeSliderStart`, `rangeSliderEnd`
|
|
2926
2994
|
- Calendar / DatePicker: `calendarPreviousMonth`, `calendarNextMonth`
|
|
2927
2995
|
- DatePicker: `datePickerOpen`, `datePickerDialog`
|
|
2928
2996
|
- ColorPicker: `colorPickerHue`, `colorPickerSaturation`, `colorPickerLightness`, `colorPickerSwatches`, `colorPickerOpen`
|
|
2929
2997
|
- PasswordInput: `passwordShow`, `passwordHide`
|
|
2930
2998
|
- ListBox: `listBoxPlaceholder`
|
|
2999
|
+
- Anchor / Card: `opensInNewTab`
|
|
2931
3000
|
- Breadcrumb: `breadcrumb`
|
|
2932
3001
|
- Tabs (generative UI): `tabList`
|
|
2933
3002
|
- Pagination: `paginationLabel`, `paginationPrevious`, `paginationNext`
|