@slashsuite/ui-react 0.12.0 → 0.13.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/MIGRATING.md +386 -8
- package/README.md +101 -44
- package/agent-docs/components/app-shell.md +139 -0
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/avatar-stack.md +64 -0
- package/agent-docs/components/avatar.md +76 -0
- package/agent-docs/components/badge.md +62 -0
- package/agent-docs/components/body-text.md +169 -0
- package/agent-docs/components/bottom-sheet.md +105 -0
- package/agent-docs/components/breadcrumbs.md +66 -0
- package/agent-docs/components/bullet-list.md +54 -0
- package/agent-docs/components/button.md +135 -0
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +87 -0
- package/agent-docs/components/card-grid.md +116 -0
- package/agent-docs/components/card.md +128 -0
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/centered-layout.md +90 -0
- package/agent-docs/components/chat-composer.md +49 -0
- package/agent-docs/components/chat-message.md +61 -0
- package/agent-docs/components/chat-thread.md +49 -0
- package/agent-docs/components/checkbox.md +81 -0
- package/agent-docs/components/cluster.md +108 -0
- package/agent-docs/components/code-example.md +48 -0
- package/agent-docs/components/code.md +72 -0
- package/agent-docs/components/colour-scheme-toggle.md +98 -0
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +51 -0
- package/agent-docs/components/copy-button.md +63 -0
- package/agent-docs/components/copy-line.md +55 -0
- package/agent-docs/components/date-field.md +106 -0
- package/agent-docs/components/date-range-picker.md +108 -0
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/detail-layout.md +147 -0
- package/agent-docs/components/dialog.md +132 -0
- package/agent-docs/components/disclosure.md +70 -0
- package/agent-docs/components/divider.md +62 -0
- package/agent-docs/components/docs-layout.md +164 -0
- package/agent-docs/components/drawer.md +137 -0
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +70 -0
- package/agent-docs/components/field-dialog.md +98 -0
- package/agent-docs/components/field.md +71 -0
- package/agent-docs/components/fieldset.md +82 -0
- package/agent-docs/components/file-drop.md +52 -0
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +144 -0
- package/agent-docs/components/form-row.md +93 -0
- package/agent-docs/components/full-bleed-layout.md +114 -0
- package/agent-docs/components/headings.md +107 -0
- package/agent-docs/components/hero.md +68 -0
- package/agent-docs/components/icon-button.md +90 -0
- package/agent-docs/components/icon.md +59 -0
- package/agent-docs/components/image.md +74 -0
- package/agent-docs/components/input.md +84 -0
- package/agent-docs/components/kbd.md +38 -0
- package/agent-docs/components/key-value-list.md +84 -0
- package/agent-docs/components/lightbox.md +97 -0
- package/agent-docs/components/list-layout.md +152 -0
- package/agent-docs/components/list-row.md +119 -0
- package/agent-docs/components/loading.md +69 -0
- package/agent-docs/components/markdown.md +51 -0
- package/agent-docs/components/media-tile.md +101 -0
- package/agent-docs/components/menu.md +110 -0
- package/agent-docs/components/meta-list.md +69 -0
- package/agent-docs/components/morph.md +134 -0
- package/agent-docs/components/navigation-progress.md +56 -0
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +74 -0
- package/agent-docs/components/page-fade.md +117 -0
- package/agent-docs/components/page-header.md +93 -0
- package/agent-docs/components/pagination.md +64 -0
- package/agent-docs/components/pill.md +105 -0
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/progress-bar.md +66 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +87 -0
- package/agent-docs/components/prose.md +41 -0
- package/agent-docs/components/radio-group.md +77 -0
- package/agent-docs/components/scroll-strip.md +48 -0
- package/agent-docs/components/segmented-control.md +135 -0
- package/agent-docs/components/select.md +70 -0
- package/agent-docs/components/show.md +120 -0
- package/agent-docs/components/side-column.md +74 -0
- package/agent-docs/components/sidebar-layout.md +134 -0
- package/agent-docs/components/site-footer.md +63 -0
- package/agent-docs/components/site-search.md +79 -0
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +112 -0
- package/agent-docs/components/split-bar.md +54 -0
- package/agent-docs/components/stack.md +197 -0
- package/agent-docs/components/stacked-bar.md +91 -0
- package/agent-docs/components/stat-tile.md +69 -0
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +112 -0
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/steps.md +74 -0
- package/agent-docs/components/sticky-bar.md +51 -0
- package/agent-docs/components/switch.md +79 -0
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +384 -0
- package/agent-docs/components/tabs.md +178 -0
- package/agent-docs/components/text-link.md +110 -0
- package/agent-docs/components/textarea.md +53 -0
- package/agent-docs/components/timeline.md +79 -0
- package/agent-docs/components/toast.md +91 -0
- package/agent-docs/components/trend-chart.md +61 -0
- package/agent-docs/components/video.md +49 -0
- package/agent-docs/llms.txt +174 -0
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +1 -0
- package/dist/Button.js +4 -3
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +113 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/cx.d.ts +22 -3
- package/dist/cx.js +22 -3
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +15 -1
- package/dist/density.js +27 -8
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +45 -0
- package/dist/stateMachineDots.js +162 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +27 -0
- package/dist/useFlowLayout.js +119 -0
- package/package.json +7 -3
- package/skills/uislash/SKILL.md +20 -0
package/dist/Field.js
CHANGED
|
@@ -3,49 +3,85 @@ import { useId } from "react";
|
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { FieldContext } from "./fieldControl.js";
|
|
5
5
|
import { ControlBone } from "./fieldWait.js";
|
|
6
|
+
import { useErrorAnnouncement } from "./fieldAnnounce.js";
|
|
7
|
+
import { useFieldType } from "./density.js";
|
|
8
|
+
import { Icon } from "./Icon.js";
|
|
6
9
|
import { BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
7
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The error line: an alert icon (so the error is not told by colour alone) and the text in red. It
|
|
12
|
+
* carries no `role="alert"`: the text is announced once through the page's (or its dialog's) one polite live region.
|
|
13
|
+
*/
|
|
14
|
+
export function ErrorLine({ id, error, }) {
|
|
15
|
+
const { anchor, announcement } = useErrorAnnouncement(error);
|
|
16
|
+
const type = useFieldType();
|
|
17
|
+
return (_jsxs("span", { ref: anchor, id: id, className: cx("flex items-start gap-1 text-red-700", type.note), children: [_jsx("span", { className: cx("flex shrink-0 items-center", type.line), children: _jsx(Icon, { name: "alert", size: "sm" }) }), _jsx("span", { className: "min-w-0", children: error }), announcement] }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The lines under a control or a row: the muted hint, and under it the error when there is one.
|
|
21
|
+
* The hint stays while an error shows, so the rule is still in view while the value is fixed.
|
|
22
|
+
* Neither draws nothing.
|
|
23
|
+
*/
|
|
8
24
|
export function fieldNote(hint, error, ids) {
|
|
9
|
-
if (error)
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
/** The
|
|
18
|
-
function
|
|
25
|
+
if (!hint && !error)
|
|
26
|
+
return null;
|
|
27
|
+
return _jsx(NoteLines, { hint: hint, error: error, ids: ids });
|
|
28
|
+
}
|
|
29
|
+
/** `fieldNote`'s lines, a component so the hint can read the type step. */
|
|
30
|
+
function NoteLines({ hint, error, ids, }) {
|
|
31
|
+
return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [hint ? _jsx(Hint, { id: ids?.hint, children: hint }) : null, error ? _jsx(ErrorLine, { id: ids?.error, error: error }) : null] }));
|
|
32
|
+
}
|
|
33
|
+
/** The muted hint under a control, one type step below its label. */
|
|
34
|
+
export function Hint({ id, children, }) {
|
|
35
|
+
return (_jsx("span", { id: id, className: cx("block text-slate-500", useFieldType().note), children: children }));
|
|
36
|
+
}
|
|
37
|
+
/** The ids a control's `aria-describedby` names for its note: the hint's, then the error's. */
|
|
38
|
+
export function noteDescribedBy(hint, error, ids) {
|
|
39
|
+
const named = [hint ? ids.hint : undefined, error ? ids.error : undefined].filter(Boolean);
|
|
40
|
+
return named.length > 0 ? named.join(" ") : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** The control's id, the note's ids and the note itself: the hint, the error under it, or nothing. */
|
|
43
|
+
function useFieldNote(htmlFor, hint, error, required) {
|
|
19
44
|
const generatedId = useId();
|
|
20
45
|
const ids = { hint: useId(), error: useId() };
|
|
21
|
-
const note = fieldNote(hint, error, ids);
|
|
22
|
-
let describedBy;
|
|
23
|
-
if (error)
|
|
24
|
-
describedBy = ids.error;
|
|
25
|
-
else if (hint)
|
|
26
|
-
describedBy = ids.hint;
|
|
27
46
|
return {
|
|
28
|
-
control: {
|
|
29
|
-
|
|
47
|
+
control: {
|
|
48
|
+
id: htmlFor ?? generatedId,
|
|
49
|
+
describedBy: noteDescribedBy(hint, error, ids),
|
|
50
|
+
invalid: Boolean(error),
|
|
51
|
+
required,
|
|
52
|
+
},
|
|
53
|
+
note: fieldNote(hint, error, ids),
|
|
30
54
|
};
|
|
31
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The marker after a required field's label: a red asterisk, hidden from assistive tech, since the
|
|
58
|
+
* control itself carries `required` and is read as required.
|
|
59
|
+
*/
|
|
60
|
+
export function RequiredMark({ required }) {
|
|
61
|
+
if (!required)
|
|
62
|
+
return null;
|
|
63
|
+
return (_jsx("span", { "aria-hidden": "true", className: "text-red-700", children: " *" }));
|
|
64
|
+
}
|
|
32
65
|
/** A field's label: hidden, or drawn, and free to wrap anywhere beside a control in a row. */
|
|
33
|
-
function labelLook(hidden, row) {
|
|
66
|
+
function labelLook(hidden, row, type) {
|
|
34
67
|
return hidden
|
|
35
68
|
? "sr-only"
|
|
36
|
-
: cx("
|
|
69
|
+
: cx(type, "font-medium text-slate-700", row && "min-w-0 wrap-anywhere");
|
|
37
70
|
}
|
|
38
71
|
/**
|
|
39
|
-
* A label above a control, with a hint
|
|
72
|
+
* A label above a control, with a hint line under it and, when set, an error line under the hint
|
|
73
|
+
* (an alert icon and red text, announced politely). The hint stays while the error shows.
|
|
74
|
+
* `required` marks the label with a red asterisk and makes the control inside `required`.
|
|
40
75
|
* Inside a `FormGrid`, `span="full"` runs the field across both columns. The `Input`, `Select`,
|
|
41
76
|
* `Textarea` or `FileDrop` inside takes the label, the note (`aria-describedby`) and, with an error,
|
|
42
77
|
* `aria-invalid` and a red edge by itself: give it no `id` and the Field no `htmlFor`. While
|
|
43
78
|
* `loading` the label is drawn and the control is a bone of its height, read from the density
|
|
44
79
|
* around it (`sm` in a `sm` card or table).
|
|
45
80
|
*/
|
|
46
|
-
export function Field({ label, htmlFor, hint, error, span, layout = "column", labelHidden = false, loading, loadingLabel, children, ...rest }) {
|
|
81
|
+
export function Field({ label, htmlFor, hint, error, required = false, span, layout = "column", labelHidden = false, loading, loadingLabel, children, ...rest }) {
|
|
47
82
|
const row = layout === "row" && !labelHidden;
|
|
48
|
-
const { control, note } = useFieldNote(htmlFor, hint, error);
|
|
83
|
+
const { control, note } = useFieldNote(htmlFor, hint, error, required);
|
|
49
84
|
const { loading: waiting, owner } = useLoading(loading);
|
|
50
|
-
|
|
85
|
+
const labelType = useFieldType().label;
|
|
86
|
+
return (_jsxs("div", { ...rest, ...busy(owner, waiting), className: cx(row ? "grid grid-cols-[8rem_1fr] items-center gap-x-3 gap-y-1.5" : "flex flex-col gap-1.5", span === "full" && "col-span-full"), children: [_jsxs("label", { htmlFor: control.id, className: labelLook(labelHidden, row, labelType), children: [label, _jsx(RequiredMark, { required: required })] }), _jsx(FieldContext.Provider, { value: control, children: waiting ? _jsx(ControlBone, {}) : children }), note && row ? _jsx("div", { className: "col-start-2", children: note }) : note, _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
51
87
|
}
|
package/dist/FieldDialog.d.ts
CHANGED
|
@@ -9,18 +9,23 @@ export type FieldDialogProps = {
|
|
|
9
9
|
label: string;
|
|
10
10
|
/** The field's placeholder. */
|
|
11
11
|
placeholder: string;
|
|
12
|
-
/** A muted line under the field
|
|
12
|
+
/** A muted line under the field. */
|
|
13
13
|
hint: string;
|
|
14
|
-
/**
|
|
14
|
+
/** The field's error when it is submitted empty: the submit button stays enabled, so this says what is missing. */
|
|
15
15
|
emptyReason: string;
|
|
16
16
|
/** The submit button's text. */
|
|
17
17
|
submit: string;
|
|
18
18
|
/** What the submit button says while `onSubmit` runs. */
|
|
19
19
|
busyLabel: string;
|
|
20
|
+
/**
|
|
21
|
+
* The button that closes the dialog without submitting, for an app in another language.
|
|
22
|
+
* @default Cancel
|
|
23
|
+
*/
|
|
24
|
+
cancelLabel?: string | undefined;
|
|
20
25
|
/** Gets the trimmed value. Resolving closes the dialog; a rejection shows its message in it. */
|
|
21
26
|
onSubmit: (value: string) => Promise<unknown>;
|
|
22
27
|
/** Called when the dialog closes: Cancel, Esc, the backdrop, or a resolved `onSubmit`. */
|
|
23
28
|
onClose: () => void;
|
|
24
29
|
} & Passthrough;
|
|
25
30
|
/** A `Dialog` with one text field and Cancel / submit buttons. Render it only while open. */
|
|
26
|
-
export declare function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, onSubmit, onClose, ...rest }: FieldDialogProps): ReactElement;
|
|
31
|
+
export declare function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, cancelLabel, onSubmit, onClose, ...rest }: FieldDialogProps): ReactElement;
|
package/dist/FieldDialog.js
CHANGED
|
@@ -4,15 +4,25 @@ import { Button } from "./Button.js";
|
|
|
4
4
|
import { Dialog } from "./Dialog.js";
|
|
5
5
|
import { Field } from "./Field.js";
|
|
6
6
|
import { Input } from "./Input.js";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The field's value and its in-flight state; `send` is the form's submit handler. An empty submit
|
|
9
|
+
* reports `emptyReason` as the field's error (the dialog then focuses the field); typing clears it.
|
|
10
|
+
*/
|
|
11
|
+
function useFieldSubmit(onSubmit, emptyReason) {
|
|
12
|
+
const [value, setTyped] = useState("");
|
|
10
13
|
const [busy, setBusy] = useState(false);
|
|
11
14
|
const [error, setError] = useState(null);
|
|
12
|
-
const
|
|
15
|
+
const setValue = (next) => {
|
|
16
|
+
setTyped(next);
|
|
17
|
+
setError(null);
|
|
18
|
+
};
|
|
13
19
|
const send = (event) => {
|
|
14
|
-
if (
|
|
20
|
+
if (busy)
|
|
21
|
+
return;
|
|
22
|
+
if (value.trim().length === 0) {
|
|
23
|
+
setError(emptyReason);
|
|
15
24
|
return;
|
|
25
|
+
}
|
|
16
26
|
// Close the <dialog> itself, so it animates out before `onClose` unmounts it.
|
|
17
27
|
const dialog = event.currentTarget.closest("dialog");
|
|
18
28
|
setError(null);
|
|
@@ -22,10 +32,10 @@ function useFieldSubmit(onSubmit) {
|
|
|
22
32
|
setError(e instanceof Error ? e.message : String(e));
|
|
23
33
|
});
|
|
24
34
|
};
|
|
25
|
-
return { value, setValue, busy, error,
|
|
35
|
+
return { value, setValue, busy, error, send };
|
|
26
36
|
}
|
|
27
37
|
/** A `Dialog` with one text field and Cancel / submit buttons. Render it only while open. */
|
|
28
|
-
export function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, onSubmit, onClose, ...rest }) {
|
|
29
|
-
const { value, setValue, busy, error,
|
|
30
|
-
return (_jsx(Dialog, { ...rest, title: title, description: description, onClose: onClose, onSubmit: send, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: (event) => event.currentTarget.closest("dialog")?.close(), children:
|
|
38
|
+
export function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, cancelLabel = "Cancel", onSubmit, onClose, ...rest }) {
|
|
39
|
+
const { value, setValue, busy, error, send } = useFieldSubmit(onSubmit, emptyReason);
|
|
40
|
+
return (_jsx(Dialog, { ...rest, title: title, description: description, onClose: onClose, onSubmit: send, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: (event) => event.currentTarget.closest("dialog")?.close(), children: cancelLabel }), _jsx(Button, { type: "submit", busy: busy && (busyLabel || true), children: submit })] }), children: _jsx(Field, { label: label, hint: hint, error: error ?? undefined, required: true, children: _jsx(Input, { autoFocus: true, placeholder: placeholder, value: value, onChange: (e) => setValue(e.target.value), autoComplete: "off" }) }) }));
|
|
31
41
|
}
|
package/dist/Fieldset.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { Unstyled } from "./props.js";
|
|
|
5
5
|
* belong together, or the filter chips of one facet (a `ButtonGroup` of `outline` `sm` pressed
|
|
6
6
|
* `Button`s). It is a `<fieldset>` named by its `label`, drawn as its `<legend>` in the `Field`
|
|
7
7
|
* label's look, over the children in one column; a `ButtonGroup` or a `FormGrid` inside lays out a
|
|
8
|
-
* row. `hint` is a muted line under the group and its `aria-describedby`; `error`
|
|
9
|
-
* with
|
|
8
|
+
* row. `hint` is a muted line under the group and its `aria-describedby`; `error` adds a red line
|
|
9
|
+
* under it with an alert icon, announced politely. `disabled` disables every control inside. One choice of several is a
|
|
10
10
|
* `RadioGroup`, never inside a `Fieldset`. Other props go on the `<fieldset>`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function Fieldset({ label, hint, error, children, "aria-describedby": ownDescribedBy, ...rest }: {
|
|
@@ -14,7 +14,7 @@ export declare function Fieldset({ label, hint, error, children, "aria-described
|
|
|
14
14
|
label: ReactNode;
|
|
15
15
|
/** A muted line under the group. */
|
|
16
16
|
hint?: ReactNode;
|
|
17
|
-
/** A red line under the
|
|
17
|
+
/** A red line under the hint, with an alert icon, announced politely. */
|
|
18
18
|
error?: ReactNode;
|
|
19
19
|
/** `Checkbox`es, `Field`s (in a `FormGrid` for a row), or a `ButtonGroup` of chips. */
|
|
20
20
|
children: ReactNode;
|
package/dist/Fieldset.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { useFieldType } from "./density.js";
|
|
5
|
+
import { fieldNote, noteDescribedBy } from "./Field.js";
|
|
4
6
|
/**
|
|
5
7
|
* A labelled group of controls: several `Checkbox`es answering one question, a set of `Field`s that
|
|
6
8
|
* belong together, or the filter chips of one facet (a `ButtonGroup` of `outline` `sm` pressed
|
|
7
9
|
* `Button`s). It is a `<fieldset>` named by its `label`, drawn as its `<legend>` in the `Field`
|
|
8
10
|
* label's look, over the children in one column; a `ButtonGroup` or a `FormGrid` inside lays out a
|
|
9
|
-
* row. `hint` is a muted line under the group and its `aria-describedby`; `error`
|
|
10
|
-
* with
|
|
11
|
+
* row. `hint` is a muted line under the group and its `aria-describedby`; `error` adds a red line
|
|
12
|
+
* under it with an alert icon, announced politely. `disabled` disables every control inside. One choice of several is a
|
|
11
13
|
* `RadioGroup`, never inside a `Fieldset`. Other props go on the `<fieldset>`.
|
|
12
14
|
*/
|
|
13
15
|
export function Fieldset({ label, hint, error, children, "aria-describedby": ownDescribedBy, ...rest }) {
|
|
14
16
|
const ids = { hint: useId(), error: useId() };
|
|
15
|
-
|
|
16
|
-
if (error)
|
|
17
|
-
note = ids.error;
|
|
18
|
-
else if (hint)
|
|
19
|
-
note = ids.hint;
|
|
17
|
+
const note = noteDescribedBy(hint, error, ids);
|
|
20
18
|
const describedBy = [ownDescribedBy, note].filter(Boolean).join(" ");
|
|
21
|
-
return (_jsxs("fieldset", { ...rest, "aria-describedby": describedBy === "" ? undefined : describedBy, className: "min-w-0", children: [_jsx("legend", { className: "
|
|
19
|
+
return (_jsxs("fieldset", { ...rest, "aria-describedby": describedBy === "" ? undefined : describedBy, className: "min-w-0", children: [_jsx("legend", { className: cx(useFieldType().label, "font-medium text-slate-700"), children: label }), _jsx("div", { className: "mt-2 flex flex-col gap-2.5", children: children }), (error || hint) && _jsx("div", { className: "mt-1.5", children: fieldNote(hint, error, ids) })] }));
|
|
22
20
|
}
|
package/dist/FileDrop.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { INVALID_EDGE_WITHIN } from "./control.js";
|
|
2
3
|
import { cx } from "./cx.js";
|
|
3
4
|
import { useFieldControl } from "./fieldControl.js";
|
|
4
5
|
const PAD = { sm: "px-3 py-2", md: "px-4 py-6", lg: "px-5 py-8" };
|
|
@@ -10,5 +11,5 @@ const PAD = { sm: "px-3 py-2", md: "px-4 py-6", lg: "px-5 py-8" };
|
|
|
10
11
|
*/
|
|
11
12
|
export function FileDrop({ size = "md", children, ...rest }) {
|
|
12
13
|
const field = useFieldControl(rest);
|
|
13
|
-
return (_jsxs("label", { className: cx("relative flex items-center justify-center rounded-lg border border-dashed border-slate-300 text-center text-sm text-slate-500 transition hover:border-violet-400 has-
|
|
14
|
+
return (_jsxs("label", { className: cx("relative flex items-center justify-center rounded-lg border border-dashed border-slate-300 text-center text-sm text-slate-500 transition hover:border-violet-400 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600", PAD[size], INVALID_EDGE_WITHIN, rest.disabled && "opacity-50"), children: [_jsx("input", { type: "file", className: "absolute inset-0 h-full w-full cursor-pointer rounded-lg opacity-0 disabled:cursor-not-allowed", ...rest, ...field }), children] }));
|
|
14
15
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { FlowDirection, FlowLayout } from "./flowLayout.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
import type { Tone } from "./tone.js";
|
|
6
|
+
import { useFlowLayout } from "./useFlowLayout.js";
|
|
7
|
+
/**
|
|
8
|
+
* One box of a `FlowDiagram`: its `id` (what an arrow's `from` and `to` name), its `label`, a
|
|
9
|
+
* `tone` that says what it means, the `group` it is framed in, and `content` drawn under the
|
|
10
|
+
* label (a few `Pill`s, a short list).
|
|
11
|
+
*/
|
|
12
|
+
export type FlowNode = {
|
|
13
|
+
/** Unique in the diagram; an arrow's `from` and `to` name it. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** The box's title. The box is as wide as it, up to 18rem; a longer one wraps. */
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* What the box means: `neutral` (default) is a plain box, the others take the `Callout`'s fill
|
|
19
|
+
* and ink. Say it in the label or the content too: colour alone tells a screen reader nothing.
|
|
20
|
+
*/
|
|
21
|
+
tone?: Tone | undefined;
|
|
22
|
+
/** Boxes with the same `group` are laid out together in a dashed frame named by it. */
|
|
23
|
+
group?: string | undefined;
|
|
24
|
+
/** Drawn under the label, inside the box, which grows to hold it: a few `Pill`s, a short list. Display only: no links or buttons. */
|
|
25
|
+
content?: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
/** One arrow of a `FlowDiagram`, from one node's `id` to another's, with an optional short `label` on it. */
|
|
28
|
+
export type FlowEdge = {
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
/** A word or two on the arrow: the event or the action that moves along it. */
|
|
32
|
+
label?: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Boxes joined by arrows, laid out for you: a flow, a pipeline, a state machine. Give it the
|
|
36
|
+
* `nodes` and the `edges` between them and it places every box in ranks `direction` (`down` or
|
|
37
|
+
* `right`) and routes every arrow round them, loops and arrows back up included (dagre's layered
|
|
38
|
+
* layout). Each box is as wide as its label and its `content`, so no text spills; boxes with a
|
|
39
|
+
* `group` share a dashed frame; `active` rings one box in the accent.
|
|
40
|
+
*
|
|
41
|
+
* The diagram is drawn at its own size and scrolls inside its own box when it is wider or taller
|
|
42
|
+
* than the room it has, so it never makes the page scroll sideways. It is an image named by
|
|
43
|
+
* `label`; every box and every arrow is also a visually hidden list after it.
|
|
44
|
+
*
|
|
45
|
+
* `overlay` draws on top of the diagram in its own coordinates: it is handed the laid-out
|
|
46
|
+
* `FlowLayout` (each box's place and each arrow's SVG path), for a marker that follows an arrow.
|
|
47
|
+
* It is not hit by the pointer, and it is hidden from a screen reader.
|
|
48
|
+
*
|
|
49
|
+
* While `loading` with no nodes it draws one bone the height of a small diagram.
|
|
50
|
+
*/
|
|
51
|
+
export declare function FlowDiagram({ label, nodes, edges, direction, active, overlay, loading, loadingLabel, ...rest }: {
|
|
52
|
+
/** What the diagram shows: its accessible name, and the name of its hidden list. */
|
|
53
|
+
label: string;
|
|
54
|
+
/** The boxes, each with a unique `id`. Their order is only a hint: the layout ranks them by the arrows. */
|
|
55
|
+
nodes: readonly FlowNode[];
|
|
56
|
+
/** The arrows. One whose `from` or `to` is not a node's `id` is not drawn. */
|
|
57
|
+
edges: readonly FlowEdge[];
|
|
58
|
+
/**
|
|
59
|
+
* Where the arrows run: `down` (top to bottom) or `right` (start to end).
|
|
60
|
+
* @default down
|
|
61
|
+
*/
|
|
62
|
+
direction?: FlowDirection;
|
|
63
|
+
/** The `id` of the one box to ring in the accent: the current step, the state a thing is in now. */
|
|
64
|
+
active?: string | undefined;
|
|
65
|
+
/** Draws on top of the diagram, in its coordinates, from the laid-out boxes and arrow paths. */
|
|
66
|
+
overlay?: ((layout: FlowLayout) => ReactNode) | undefined;
|
|
67
|
+
} & LoadingProps & Passthrough): ReactElement;
|
|
68
|
+
/** A box's tone in the internal view: the public tones, and `muted` for a box that is over. */
|
|
69
|
+
export type ViewTone = Tone | "muted";
|
|
70
|
+
/** A box of the internal view: a `FlowNode` that may also be `muted`. */
|
|
71
|
+
export type ViewNode = Omit<FlowNode, "tone"> & {
|
|
72
|
+
tone?: ViewTone | undefined;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The laid-out diagram, drawn: `FlowDiagram` without its loading bone, and with `layer`, which
|
|
76
|
+
* `StateMachine` draws its dots in. The caller lays it out (`useFlowLayout`) and hands over the
|
|
77
|
+
* `canvas` ref and the layout `drawn`. Unlike `overlay`, the layer is read by a screen reader and its
|
|
78
|
+
* children may take the pointer (`pointer-events-auto`), so they can be links. With a layer, the
|
|
79
|
+
* image is the drawing alone and the scrolling box round it is a group named by `label`. With `fit`,
|
|
80
|
+
* a drawing wider than its room is shrunk to the room's width instead of scrolling. Internal.
|
|
81
|
+
*/
|
|
82
|
+
export declare function FlowView({ label, nodes, edges, active, overlay, layer, canvas, drawn, fit, ...rest }: {
|
|
83
|
+
label: string;
|
|
84
|
+
nodes: readonly ViewNode[];
|
|
85
|
+
edges: readonly FlowEdge[];
|
|
86
|
+
active: string | undefined;
|
|
87
|
+
overlay?: ((layout: FlowLayout) => ReactNode) | undefined;
|
|
88
|
+
layer?: ((layout: FlowLayout) => ReactNode) | undefined;
|
|
89
|
+
canvas: ReturnType<typeof useFlowLayout>["canvas"];
|
|
90
|
+
drawn: FlowLayout;
|
|
91
|
+
fit?: boolean | undefined;
|
|
92
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { TONE_SURFACE, TONE_TEXT } from "./Callout.js";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
6
|
+
import { edgeKey, nodeKey, useFit, useFlowLayout } from "./useFlowLayout.js";
|
|
7
|
+
/** A box's frame by tone: the Callout's soft surfaces, a white box for `neutral`, a grey one for `muted`. */
|
|
8
|
+
const NODE_TONE = {
|
|
9
|
+
...TONE_SURFACE,
|
|
10
|
+
neutral: "border-slate-300 bg-white",
|
|
11
|
+
muted: "border-slate-200 bg-slate-50",
|
|
12
|
+
};
|
|
13
|
+
/** A box's ink by tone; `neutral` is the primary ink, `muted` the quiet one. */
|
|
14
|
+
const NODE_INK = {
|
|
15
|
+
...TONE_TEXT,
|
|
16
|
+
neutral: "text-slate-900",
|
|
17
|
+
muted: "text-slate-500",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Boxes joined by arrows, laid out for you: a flow, a pipeline, a state machine. Give it the
|
|
21
|
+
* `nodes` and the `edges` between them and it places every box in ranks `direction` (`down` or
|
|
22
|
+
* `right`) and routes every arrow round them, loops and arrows back up included (dagre's layered
|
|
23
|
+
* layout). Each box is as wide as its label and its `content`, so no text spills; boxes with a
|
|
24
|
+
* `group` share a dashed frame; `active` rings one box in the accent.
|
|
25
|
+
*
|
|
26
|
+
* The diagram is drawn at its own size and scrolls inside its own box when it is wider or taller
|
|
27
|
+
* than the room it has, so it never makes the page scroll sideways. It is an image named by
|
|
28
|
+
* `label`; every box and every arrow is also a visually hidden list after it.
|
|
29
|
+
*
|
|
30
|
+
* `overlay` draws on top of the diagram in its own coordinates: it is handed the laid-out
|
|
31
|
+
* `FlowLayout` (each box's place and each arrow's SVG path), for a marker that follows an arrow.
|
|
32
|
+
* It is not hit by the pointer, and it is hidden from a screen reader.
|
|
33
|
+
*
|
|
34
|
+
* While `loading` with no nodes it draws one bone the height of a small diagram.
|
|
35
|
+
*/
|
|
36
|
+
export function FlowDiagram({ label, nodes, edges, direction = "down", active, overlay, loading, loadingLabel, ...rest }) {
|
|
37
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
38
|
+
const { canvas, drawn } = useFlowLayout(nodes, edges, direction);
|
|
39
|
+
if (waiting && nodes.length === 0) {
|
|
40
|
+
return (_jsxs("figure", { ...rest, ...busy(owner, waiting), "aria-label": label, className: "flex flex-col", children: [_jsx(Bone, { shape: "block h-48 rounded-lg" }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
41
|
+
}
|
|
42
|
+
return (_jsx(FlowView, { ...rest, label: label, nodes: nodes, edges: edges, active: active, overlay: overlay, canvas: canvas, drawn: drawn }));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The laid-out diagram, drawn: `FlowDiagram` without its loading bone, and with `layer`, which
|
|
46
|
+
* `StateMachine` draws its dots in. The caller lays it out (`useFlowLayout`) and hands over the
|
|
47
|
+
* `canvas` ref and the layout `drawn`. Unlike `overlay`, the layer is read by a screen reader and its
|
|
48
|
+
* children may take the pointer (`pointer-events-auto`), so they can be links. With a layer, the
|
|
49
|
+
* image is the drawing alone and the scrolling box round it is a group named by `label`. With `fit`,
|
|
50
|
+
* a drawing wider than its room is shrunk to the room's width instead of scrolling. Internal.
|
|
51
|
+
*/
|
|
52
|
+
export function FlowView({ label, nodes, edges, active, overlay, layer, canvas, drawn, fit = false, ...rest }) {
|
|
53
|
+
const { frame, scale } = useFit(fit ? drawn.width : 0);
|
|
54
|
+
const known = new Set(nodes.map((n) => n.id));
|
|
55
|
+
const shown = edges.flatMap((edge, index) => known.has(edge.from) && known.has(edge.to) ? [{ edge, index }] : []);
|
|
56
|
+
const image = {
|
|
57
|
+
role: "img",
|
|
58
|
+
"aria-label": `${label}: ${count(known.size, "box", "boxes")} and ${count(shown.length, "arrow", "arrows")}`,
|
|
59
|
+
};
|
|
60
|
+
const drawing = _jsx(FlowCanvas, { drawn: drawn, nodes: nodes, edges: shown, active: active });
|
|
61
|
+
return (_jsxs("div", { ...rest, className: "flex min-w-0 flex-col", children: [_jsx("div", { ...(layer ? { role: "group", "aria-label": label } : image),
|
|
62
|
+
// A diagram wider than its room scrolls, so it takes the focus for the arrow keys.
|
|
63
|
+
tabIndex: 0, ref: frame, className: "max-w-full overflow-auto rounded-lg outline-offset-2 focus-visible:outline-2 focus-visible:outline-violet-600", children: _jsx("div", { className: "mx-auto", style: { width: drawn.width * scale, height: drawn.height * scale }, children: _jsxs("div", { ref: canvas, className: "relative origin-top-left", style: {
|
|
64
|
+
width: drawn.width,
|
|
65
|
+
height: drawn.height,
|
|
66
|
+
...(scale < 1 ? { transform: `scale(${scale})` } : {}),
|
|
67
|
+
}, children: [layer ? (_jsx("div", { ...image, className: "absolute inset-0", children: drawing })) : (drawing), overlay && (_jsx("div", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0", children: overlay(drawn) })), layer && _jsx("div", { className: "pointer-events-none absolute inset-0", children: layer(drawn) })] }) }) }), _jsx(FlowList, { label: label, nodes: nodes, edges: shown, active: active })] }));
|
|
68
|
+
}
|
|
69
|
+
/** `1 box`, `3 boxes`. */
|
|
70
|
+
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
71
|
+
/** The drawing itself: the group frames, the arrows, their labels and the boxes. */
|
|
72
|
+
function FlowCanvas({ drawn, nodes, edges, active, }) {
|
|
73
|
+
const marker = `flow-arrow-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
74
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
75
|
+
const paths = new Map(drawn.edges.map((e) => [e.index, e]));
|
|
76
|
+
return (_jsxs(_Fragment, { children: [drawn.groups.map((g) => (_jsx("div", { className: "absolute rounded-xl border border-dashed border-slate-300", style: { left: g.x, top: g.y, width: g.width, height: g.height }, children: _jsx("span", { className: "absolute left-3 top-1 text-xs font-medium text-slate-500", children: g.name }) }, g.name))), _jsx(FlowArrows, { drawn: drawn, marker: marker }), edges.map(({ edge, index }) => {
|
|
77
|
+
const at = paths.get(index)?.labelAt;
|
|
78
|
+
return edge.label && at ? (_jsx("span", { "data-measure": edgeKey(index), className: "absolute -translate-x-1/2 -translate-y-1/2 whitespace-nowrap rounded bg-white px-1 text-xs text-slate-600", style: { left: at.x, top: at.y }, children: edge.label }, index)) : null;
|
|
79
|
+
}), drawn.nodes.map((b) => {
|
|
80
|
+
const node = byId.get(b.id);
|
|
81
|
+
return node ? (_jsx(FlowBoxView, { box: b, node: node, active: active === b.id }, b.id)) : null;
|
|
82
|
+
})] }));
|
|
83
|
+
}
|
|
84
|
+
/** Every arrow as an SVG path, with its arrowhead. */
|
|
85
|
+
function FlowArrows({ drawn, marker }) {
|
|
86
|
+
return (_jsxs("svg", { width: drawn.width, height: drawn.height, className: "absolute inset-0 overflow-visible text-slate-400", children: [_jsx("defs", { children: _jsx("marker", { id: marker, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", markerUnits: "userSpaceOnUse", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0L10,5L0,10z", fill: "currentColor" }) }) }), drawn.edges.map((e) => (_jsx("path", { d: e.path, fill: "none", stroke: "currentColor", strokeWidth: 1.5, markerEnd: `url(#${marker})` }, e.index)))] }));
|
|
87
|
+
}
|
|
88
|
+
/** One box, placed: its label and content, sized by them, centred in the slot the layout gave it. */
|
|
89
|
+
function FlowBoxView({ box, node, active, }) {
|
|
90
|
+
const tone = node.tone ?? "neutral";
|
|
91
|
+
return (_jsx("div", { className: "absolute flex items-center justify-center", style: { left: box.x, top: box.y, width: box.width, height: box.height }, children: _jsxs("div", { "data-measure": nodeKey(box.id), className: cx("w-max max-w-72 shrink-0 rounded-lg border px-3 py-2 text-sm", NODE_TONE[tone], NODE_INK[tone], active && "outline-2 outline-offset-2 outline-violet-600"), children: [_jsx("div", { className: "font-medium", children: node.label }), node.content != null && _jsx("div", { className: "mt-2", children: node.content })] }) }));
|
|
92
|
+
}
|
|
93
|
+
/** The diagram as text for a screen reader: each box, its content, and the arrows out of it. */
|
|
94
|
+
function FlowList({ label, nodes, edges, active, }) {
|
|
95
|
+
const names = new Map(nodes.map((n) => [n.id, n.label]));
|
|
96
|
+
return (_jsx("ul", { "aria-label": label, className: "sr-only", children: nodes.map((n) => {
|
|
97
|
+
const out = edges.filter(({ edge }) => edge.from === n.id);
|
|
98
|
+
return (_jsxs("li", { children: [n.label, active === n.id && ", current", n.group && `, in ${n.group}`, n.content != null && _jsx("div", { children: n.content }), out.length > 0 && (_jsx("ul", { children: out.map(({ edge, index }) => (_jsxs("li", { children: [`to ${names.get(edge.to) ?? edge.to}`, edge.label && `, on ${edge.label}`] }, index))) }))] }, n.id));
|
|
99
|
+
}) }));
|
|
100
|
+
}
|
package/dist/FormRow.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { type LoadingProps } from "./skeleton.js";
|
|
|
4
4
|
/** Relative widths in a `FormRow`: a field of `span` 2 is twice as wide as one of `span` 1. */
|
|
5
5
|
export type FormRowSpan = 1 | 2 | 3 | 4;
|
|
6
6
|
/**
|
|
7
|
-
* Two columns of `Field`s
|
|
8
|
-
*
|
|
7
|
+
* Two columns of `Field`s once the grid is 36rem wide, one below that. It folds by its own width,
|
|
8
|
+
* not the viewport's, so it stays one column in a `Dialog` or a side column. A `Field` takes one
|
|
9
|
+
* column; `span="full"` runs it across both, and a `FormRow` is always full width.
|
|
9
10
|
*/
|
|
10
11
|
export declare function FormGrid({ children, ...rest }: {
|
|
11
12
|
children: ReactNode;
|
|
@@ -14,7 +15,8 @@ export declare function FormGrid({ children, ...rest }: {
|
|
|
14
15
|
* An inline-edit row: several controls side by side with proportional widths (`FormRowField`
|
|
15
16
|
* `span` 1 to 4), optional `actions` after them (a save button), and one `hint` or `error` line
|
|
16
17
|
* under the whole row. Every control sits on the bottom edge, so the actions line up with them
|
|
17
|
-
* whatever the labels do.
|
|
18
|
+
* whatever the labels do. Narrower than 36rem (the row's own width, not the viewport's) the fields
|
|
19
|
+
* and the actions stack.
|
|
18
20
|
*
|
|
19
21
|
* The row owns the note, so the fields beside each other keep their height: a `FormRowField` has
|
|
20
22
|
* no `hint` or `error` of its own.
|
|
@@ -24,7 +26,7 @@ export declare function FormRow({ actions, hint, error, children, ...rest }: {
|
|
|
24
26
|
actions?: ReactNode;
|
|
25
27
|
/** One muted line under the whole row. */
|
|
26
28
|
hint?: ReactNode;
|
|
27
|
-
/**
|
|
29
|
+
/** A red line under the hint, announced politely, as `Field`'s is. */
|
|
28
30
|
error?: ReactNode;
|
|
29
31
|
children: ReactNode;
|
|
30
32
|
} & Passthrough): ReactElement;
|
package/dist/FormRow.js
CHANGED
|
@@ -4,30 +4,32 @@ import { fieldNote } from "./Field.js";
|
|
|
4
4
|
import { ControlBone } from "./fieldWait.js";
|
|
5
5
|
import { BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
6
6
|
const SPAN = {
|
|
7
|
-
1: "
|
|
8
|
-
2: "
|
|
9
|
-
3: "
|
|
10
|
-
4: "
|
|
7
|
+
1: "@xl:flex-1",
|
|
8
|
+
2: "@xl:flex-2",
|
|
9
|
+
3: "@xl:flex-3",
|
|
10
|
+
4: "@xl:flex-4",
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* Two columns of `Field`s
|
|
14
|
-
*
|
|
13
|
+
* Two columns of `Field`s once the grid is 36rem wide, one below that. It folds by its own width,
|
|
14
|
+
* not the viewport's, so it stays one column in a `Dialog` or a side column. A `Field` takes one
|
|
15
|
+
* column; `span="full"` runs it across both, and a `FormRow` is always full width.
|
|
15
16
|
*/
|
|
16
17
|
export function FormGrid({ children, ...rest }) {
|
|
17
|
-
return (_jsx("div", { ...rest, className: "grid grid-cols-1 gap-4
|
|
18
|
+
return (_jsx("div", { ...rest, className: "@container w-full", children: _jsx("div", { className: "grid grid-cols-1 gap-4 @xl:grid-cols-2", children: children }) }));
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* An inline-edit row: several controls side by side with proportional widths (`FormRowField`
|
|
21
22
|
* `span` 1 to 4), optional `actions` after them (a save button), and one `hint` or `error` line
|
|
22
23
|
* under the whole row. Every control sits on the bottom edge, so the actions line up with them
|
|
23
|
-
* whatever the labels do.
|
|
24
|
+
* whatever the labels do. Narrower than 36rem (the row's own width, not the viewport's) the fields
|
|
25
|
+
* and the actions stack.
|
|
24
26
|
*
|
|
25
27
|
* The row owns the note, so the fields beside each other keep their height: a `FormRowField` has
|
|
26
28
|
* no `hint` or `error` of its own.
|
|
27
29
|
*/
|
|
28
30
|
export function FormRow({ actions, hint, error, children, ...rest }) {
|
|
29
31
|
const note = fieldNote(hint, error);
|
|
30
|
-
return (_jsxs("div", { ...rest, className: "col-span-full flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex flex-col gap-3
|
|
32
|
+
return (_jsxs("div", { ...rest, className: "@container col-span-full flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex flex-col gap-3 @xl:flex-row @xl:items-end", children: [children, actions && _jsx("div", { className: "flex items-center gap-2 @xl:shrink-0", children: actions })] }), note] }));
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* A compact label over one control, for a `FormRow`. `span` is its share of the row (1 default).
|
package/dist/Hero.d.ts
CHANGED
|
@@ -9,15 +9,38 @@ export type HeroProps = {
|
|
|
9
9
|
title: ReactNode;
|
|
10
10
|
/** What follows the title: a `Lead`, and the page's first actions if it has any. */
|
|
11
11
|
children?: ReactNode;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The name of the control that holds the glow still, for an app in another language.
|
|
14
|
+
* @default Pause the background motion
|
|
15
|
+
*/
|
|
16
|
+
pauseLabel?: string | undefined;
|
|
17
|
+
} & ({
|
|
18
|
+
/**
|
|
19
|
+
* A picture beside the words from `md` up, and under them on a phone: an `Image` of the
|
|
20
|
+
* product, at `width="full"`. The words keep the glow; the picture sits clear of it.
|
|
21
|
+
*/
|
|
22
|
+
media: ReactNode;
|
|
23
|
+
align?: "start" | undefined;
|
|
24
|
+
} | {
|
|
25
|
+
media?: undefined;
|
|
26
|
+
/**
|
|
27
|
+
* `center` sets the words in the middle of the page, under a centred glow: a landing page
|
|
28
|
+
* with no picture whose actions are one or two buttons. Pass the actions' `Cluster`
|
|
29
|
+
* `justify="center"` too.
|
|
30
|
+
* @default start
|
|
31
|
+
*/
|
|
32
|
+
align?: "start" | "center" | undefined;
|
|
33
|
+
});
|
|
13
34
|
/**
|
|
14
35
|
* A landing page's top block: an overline, the display title (the page's `h1`) and the lede under
|
|
15
36
|
* it, over a soft glow of three tilted ribbons that drift slowly behind the text. The glow is always
|
|
16
37
|
* there and its colours and strength are the theme's (the palette's `glow` role), so a paper theme
|
|
17
|
-
* keeps it faint. It is anchored to the text's own column (`max-w-3xl`, at the parent's start edge
|
|
18
|
-
* never the viewport, and clipped to it, so nothing scrolls
|
|
19
|
-
* `aria-hidden`, and the text sits above it.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
38
|
+
* keeps it faint. It is anchored to the text's own column (`max-w-3xl`, at the parent's start edge,
|
|
39
|
+
* or in its middle with `align="center"`), never the viewport, and clipped to it, so nothing scrolls
|
|
40
|
+
* sideways on a phone. It is `aria-hidden`, and the text sits above it. `media` puts a picture
|
|
41
|
+
* beside the words from `md` up. A small checkbox in the top corner holds the drift still, since it
|
|
42
|
+
* never ends on its own; under `prefers-reduced-motion: reduce` the glow stands still and the
|
|
43
|
+
* checkbox is not drawn. Pure markup and one inline stylesheet: it works rendered on the server with
|
|
44
|
+
* no script. One per page, on a landing page; every other page opens with a `PageHeader`.
|
|
22
45
|
*/
|
|
23
|
-
export declare function Hero({ overline, title, children, ...rest }: HeroProps & Passthrough): ReactElement;
|
|
46
|
+
export declare function Hero({ overline, title, children, media, align, pauseLabel, ...rest }: HeroProps & Passthrough): ReactElement;
|