@slashsuite/ui-react 0.12.1 → 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 +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- 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 +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- 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/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- 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 +3 -2
package/dist/ChatComposer.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useId, useRef, useState, } from "react";
|
|
|
3
3
|
import { Button } from "./Button.js";
|
|
4
4
|
import { Cluster, ClusterGrow } from "./Cluster.js";
|
|
5
5
|
import { Field } from "./Field.js";
|
|
6
|
-
import {
|
|
6
|
+
import { TextareaControl } from "./Textarea.js";
|
|
7
7
|
/**
|
|
8
8
|
* An IME is still composing. Safari ends the composition before the Enter's keydown, so there
|
|
9
9
|
* `isComposing` is already false and only the 229 keyCode tells the commit from a real Enter.
|
|
@@ -12,23 +12,45 @@ function isComposing({ nativeEvent }) {
|
|
|
12
12
|
return nativeEvent.isComposing || nativeEvent.keyCode === 229;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* The
|
|
16
|
-
* the trimmed text and clears the box
|
|
17
|
-
* not send. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
|
|
18
|
-
* carries on with the text kept for the next send.
|
|
15
|
+
* The composer's text, and whether the last send found it empty; `type` sets the text and clears that.
|
|
16
|
+
* `send` sends the trimmed text and clears the box, or marks it empty; it does nothing while `busy`.
|
|
19
17
|
*/
|
|
20
|
-
|
|
21
|
-
const id = useId();
|
|
22
|
-
const box = useRef(null);
|
|
18
|
+
function useComposerText(busy, onSend) {
|
|
23
19
|
const [text, setText] = useState("");
|
|
24
|
-
const
|
|
25
|
-
const
|
|
20
|
+
const [empty, setEmpty] = useState(false);
|
|
21
|
+
const type = (next) => {
|
|
22
|
+
setText(next);
|
|
23
|
+
setEmpty(false);
|
|
24
|
+
};
|
|
26
25
|
const send = () => {
|
|
27
|
-
if (busy
|
|
26
|
+
if (busy)
|
|
27
|
+
return;
|
|
28
|
+
const trimmed = text.trim();
|
|
29
|
+
if (trimmed === "") {
|
|
30
|
+
setEmpty(true);
|
|
28
31
|
return;
|
|
32
|
+
}
|
|
29
33
|
onSend(trimmed);
|
|
30
34
|
setText("");
|
|
31
35
|
};
|
|
36
|
+
return { text, type, empty, send };
|
|
37
|
+
}
|
|
38
|
+
/** The composer's one submit button: Send, or Stop while a reply can be stopped. */
|
|
39
|
+
function SendOrStop({ stop, disabled, sendLabel = "Send", stopLabel = "Stop", }) {
|
|
40
|
+
return (_jsx(Button, { type: "submit", variant: stop ? "outline" : "primary", disabled: disabled, children: stop ? stopLabel : sendLabel }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The box a message is typed into, with its button beside it. It keeps its own text, and the box
|
|
44
|
+
* grows with it from 2 rows to 8. Enter sends the trimmed text and clears the box; Shift+Enter is a
|
|
45
|
+
* newline. Send stays enabled on an empty box: sending empty or whitespace-only text sends nothing
|
|
46
|
+
* and shows `emptyReason` under the box until the next keystroke. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
|
|
47
|
+
* carries on with the text kept for the next send.
|
|
48
|
+
*/
|
|
49
|
+
export function ChatComposer({ label, placeholder, disabled = false, busy = false, onSend, onStop, sendLabel, stopLabel, emptyReason = "Write a message first.", ...rest }) {
|
|
50
|
+
const id = useId();
|
|
51
|
+
const box = useRef(null);
|
|
52
|
+
const { text, type, empty, send } = useComposerText(busy, onSend);
|
|
53
|
+
const stop = busy && onStop !== undefined;
|
|
32
54
|
const onKeyDown = (event) => {
|
|
33
55
|
if (event.key !== "Enter" || event.shiftKey || isComposing(event))
|
|
34
56
|
return;
|
|
@@ -36,7 +58,7 @@ export function ChatComposer({ label, placeholder, disabled = false, busy = fals
|
|
|
36
58
|
send();
|
|
37
59
|
};
|
|
38
60
|
// One submit button that is Send or Stop, so it is the same element across the swap and keeps its
|
|
39
|
-
// focus. Send goes back to the box
|
|
61
|
+
// focus. Send goes back to the box, to type the next message or the missing one.
|
|
40
62
|
const onSubmit = (event) => {
|
|
41
63
|
event.preventDefault();
|
|
42
64
|
if (busy) {
|
|
@@ -46,5 +68,5 @@ export function ChatComposer({ label, placeholder, disabled = false, busy = fals
|
|
|
46
68
|
send();
|
|
47
69
|
box.current?.focus();
|
|
48
70
|
};
|
|
49
|
-
return (_jsx("form", { ...rest, onSubmit: onSubmit, children: _jsxs(Cluster, { align: "end", gap: "sm", children: [_jsx(ClusterGrow, { children: _jsx(Field, { label: label, htmlFor: id, labelHidden: true, children: _jsx(
|
|
71
|
+
return (_jsx("form", { ...rest, onSubmit: onSubmit, children: _jsxs(Cluster, { align: "end", gap: "sm", children: [_jsx(ClusterGrow, { children: _jsx(Field, { label: label, htmlFor: id, labelHidden: true, error: empty ? emptyReason : undefined, children: _jsx(TextareaControl, { ref: box, id: id, size: "md", width: "full", mono: false, grow: true, value: text, placeholder: placeholder, disabled: disabled, onChange: (event) => type(event.target.value), onKeyDown: onKeyDown }) }) }), _jsx(SendOrStop, { stop: stop, disabled: disabled || (busy && !stop), sendLabel: sendLabel, stopLabel: stopLabel })] }) }));
|
|
50
72
|
}
|
package/dist/Checkbox.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import type { ComponentPropsWithoutRef, ReactElement, ReactNode, Ref } from "rea
|
|
|
2
2
|
import type { Unstyled } from "./props.js";
|
|
3
3
|
import type { Size } from "./size.js";
|
|
4
4
|
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
import { type ChoiceVariant } from "./optionCard.js";
|
|
5
6
|
/** The props of a `Checkbox`. */
|
|
6
7
|
type CheckboxProps = {
|
|
7
8
|
/** The text beside the box. Leave it out for a bare box (a table cell) and name it with `aria-label`. */
|
|
8
9
|
label?: ReactNode;
|
|
9
10
|
/** A muted line under the label that says more. It is the box's `aria-describedby`. */
|
|
10
11
|
hint?: ReactNode;
|
|
11
|
-
/**
|
|
12
|
+
/** A red line under the hint, with an alert icon, announced politely; makes the box `aria-invalid`. */
|
|
12
13
|
error?: ReactNode;
|
|
13
14
|
/**
|
|
14
15
|
* The label's text size and the box with it.
|
|
@@ -23,6 +24,20 @@ type CheckboxProps = {
|
|
|
23
24
|
* keyboard focus and a tap, read out as its description.
|
|
24
25
|
*/
|
|
25
26
|
disabledReason?: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Mixed: some of what the box stands for is chosen and some is not, as a select-all box over a
|
|
29
|
+
* partly chosen list. It draws a dash and is read as "mixed"; a click checks it. The caller owns
|
|
30
|
+
* it: work it out from the list on every render.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
indeterminate?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* `plain` is the box and its words. `card` puts them in a bordered box the width of its parent,
|
|
36
|
+
* the label a title and the `hint` its description: for a few options that each need a line of
|
|
37
|
+
* explaining. The whole card is the click target, and a ticked one takes an accent edge.
|
|
38
|
+
* @default plain
|
|
39
|
+
*/
|
|
40
|
+
variant?: ChoiceVariant | undefined;
|
|
26
41
|
/** The `<input>`, for focus control. */
|
|
27
42
|
ref?: Ref<HTMLInputElement> | undefined;
|
|
28
43
|
} & Unstyled<Omit<ComponentPropsWithoutRef<"input">, "type" | "size" | "width" | "onChange">>;
|
|
@@ -33,9 +48,12 @@ type CheckboxProps = {
|
|
|
33
48
|
* `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
|
|
34
49
|
* larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
|
|
35
50
|
* box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
|
|
36
|
-
* line under the label that says more, like a `Field`'s; `error`
|
|
37
|
-
*
|
|
51
|
+
* line under the label that says more, like a `Field`'s; `error` adds a red line under it, with an alert
|
|
52
|
+
* icon, and makes the box `aria-invalid` and red-edged. The note is the box's `aria-describedby`.
|
|
38
53
|
* `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
|
|
54
|
+
* `indeterminate` draws a dash for a select-all box over a partly chosen list. `variant="card"`
|
|
55
|
+
* draws it as an option card: a bordered box with the label as its title and the hint under it. Under a finger the
|
|
56
|
+
* hit area grows to 44px.
|
|
39
57
|
* While `loading` the label is drawn and the box is a bone of its size.
|
|
40
58
|
*/
|
|
41
59
|
export declare function Checkbox({ loading, loadingLabel, ...props }: CheckboxProps & LoadingProps): ReactElement;
|
package/dist/Checkbox.js
CHANGED
|
@@ -1,24 +1,62 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { INVALID_EDGE, INVALID_EDGE_WITHIN } from "./control.js";
|
|
2
3
|
import { cx, focusRing } from "./cx.js";
|
|
4
|
+
import { controlText, useTypeStep } from "./density.js";
|
|
3
5
|
import { useNote, Words } from "./labelWords.js";
|
|
6
|
+
import { TOUCH_TARGET } from "./target.js";
|
|
4
7
|
import { WaitingChoice } from "./fieldWait.js";
|
|
5
8
|
import { useLoading } from "./skeleton.js";
|
|
6
9
|
import { useBlocked } from "./blocked.js";
|
|
7
|
-
|
|
10
|
+
import { OPTION_CARD, OPTION_CARD_CHOSEN, OPTION_CARD_HOVER, OPTION_CARD_TITLE, } from "./optionCard.js";
|
|
11
|
+
/**
|
|
12
|
+
* The label's gap, the box, and the box's drop onto the label's first line, by `size`. The label's
|
|
13
|
+
* type is a control's of that size (`controlText`), whose line height the drop is set for.
|
|
14
|
+
*/
|
|
8
15
|
const SIZE = {
|
|
9
|
-
sm: {
|
|
10
|
-
md: {
|
|
11
|
-
lg: {
|
|
16
|
+
sm: { gap: "gap-1.5", box: "h-3.5 w-3.5", start: "mt-px" },
|
|
17
|
+
md: { gap: "gap-2", box: "h-4 w-4", start: "mt-0.5" },
|
|
18
|
+
lg: { gap: "gap-2.5", box: "h-5 w-5", start: "mt-0.5" },
|
|
19
|
+
};
|
|
20
|
+
/** The mark over a checked box: a tick, or a dash for a mixed one. */
|
|
21
|
+
const MARK = {
|
|
22
|
+
tick: {
|
|
23
|
+
path: "M4 8.5l2.5 2.5L12 5.5",
|
|
24
|
+
shown: "group-has-[input:checked:not(:indeterminate)]/checkbox:visible",
|
|
25
|
+
},
|
|
26
|
+
dash: { path: "M4.5 8h7", shown: "group-has-[input:indeterminate]/checkbox:visible" },
|
|
12
27
|
};
|
|
13
|
-
/**
|
|
14
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The mark over the box: the tick when it is checked, the dash when it is mixed (`indeterminate`).
|
|
30
|
+
* Both read the input's own state, so an uncontrolled Checkbox changes with no re-render.
|
|
31
|
+
*/
|
|
32
|
+
function Tick({ size, onFirstLine, mark, }) {
|
|
15
33
|
/* The checked box: a filled accent square at the input's own place (an absolutely
|
|
16
34
|
positioned flex child sits where the first flex item would, so it needs no insets), shown
|
|
17
35
|
by the label's `:has(:checked)` so an uncontrolled Checkbox changes with no re-render.
|
|
18
36
|
Inside a Card or table row the input is lifted to `z-10` by `liftInteractive` (cx.ts), and
|
|
19
37
|
it comes later in the DOM, so the tick ranks `z-20` there to paint over it. Scoped to the
|
|
20
38
|
`isolate` ancestor like the Input icon (InputShell.tsx), so it never outranks a sticky bar. */
|
|
21
|
-
return (_jsx("span", { "aria-hidden": "true", className: cx(SIZE[size].box, onFirstLine && SIZE[size].start, "pointer-events-none invisible absolute in-[.isolate]:z-20 block rounded border border-violet-600 bg-violet-600 text-violet-50
|
|
39
|
+
return (_jsx("span", { "aria-hidden": "true", className: cx(SIZE[size].box, onFirstLine && SIZE[size].start, "pointer-events-none invisible absolute in-[.isolate]:z-20 block rounded border border-violet-600 bg-violet-600 text-violet-50", MARK[mark].shown), children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", className: "h-full w-full", children: _jsx("path", { d: MARK[mark].path, stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The label round the box: faded and not-allowed unless the box is enabled. Written as
|
|
43
|
+
* `has-enabled` so the label carries no `disabled` class text: the disabled state belongs on the
|
|
44
|
+
* input. A blocked box is enabled (it keeps its focus) and fades as a disabled one does. A card
|
|
45
|
+
* draws its box and takes the focus ring from the input.
|
|
46
|
+
*/
|
|
47
|
+
function labelLook(blocked, card) {
|
|
48
|
+
return cx("group/checkbox inline-flex items-start text-slate-700", TOUCH_TARGET, blocked
|
|
49
|
+
? "cursor-not-allowed opacity-50"
|
|
50
|
+
: "cursor-not-allowed opacity-50 has-enabled:cursor-pointer has-enabled:opacity-100", card &&
|
|
51
|
+
cx(OPTION_CARD, OPTION_CARD_HOVER, INVALID_EDGE_WITHIN, "has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600"));
|
|
52
|
+
}
|
|
53
|
+
/** A ticked card's accent edge, shown by the input's own state so an uncontrolled card needs no re-render. */
|
|
54
|
+
function CardEdge() {
|
|
55
|
+
return (_jsx("span", { "aria-hidden": "true", className: cx(OPTION_CARD_CHOSEN, "invisible group-has-[input:checked]/checkbox:visible") }));
|
|
56
|
+
}
|
|
57
|
+
/** A card's label, in the card title's weight. */
|
|
58
|
+
function CardTitle({ label }) {
|
|
59
|
+
return label == null ? label : _jsx("span", { className: OPTION_CARD_TITLE, children: label });
|
|
22
60
|
}
|
|
23
61
|
/**
|
|
24
62
|
* A checkbox with its label. It is a real `<input type="checkbox">`, drawn by the library (an
|
|
@@ -27,37 +65,45 @@ function Tick({ size, onFirstLine }) {
|
|
|
27
65
|
* `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
|
|
28
66
|
* larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
|
|
29
67
|
* box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
|
|
30
|
-
* line under the label that says more, like a `Field`'s; `error`
|
|
31
|
-
*
|
|
68
|
+
* line under the label that says more, like a `Field`'s; `error` adds a red line under it, with an alert
|
|
69
|
+
* icon, and makes the box `aria-invalid` and red-edged. The note is the box's `aria-describedby`.
|
|
32
70
|
* `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
|
|
71
|
+
* `indeterminate` draws a dash for a select-all box over a partly chosen list. `variant="card"`
|
|
72
|
+
* draws it as an option card: a bordered box with the label as its title and the hint under it. Under a finger the
|
|
73
|
+
* hit area grows to 44px.
|
|
33
74
|
* While `loading` the label is drawn and the box is a bone of its size.
|
|
34
75
|
*/
|
|
35
76
|
export function Checkbox({ loading, loadingLabel, ...props }) {
|
|
77
|
+
const step = useTypeStep();
|
|
36
78
|
if (useLoading(loading).loading) {
|
|
37
79
|
const size = props.size ?? "md";
|
|
38
|
-
return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: SIZE[size].
|
|
80
|
+
return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx(SIZE[size].gap, controlText(size, step, false), props.variant === "card" && OPTION_CARD), shape: cx(SIZE[size].box, props.label != null && SIZE[size].start, "rounded"), attrs: props }));
|
|
39
81
|
}
|
|
40
82
|
return _jsx(ShownCheckbox, { ...props });
|
|
41
83
|
}
|
|
42
84
|
/** A checkbox with its box drawn. */
|
|
43
|
-
function ShownCheckbox({ label, hint, error, size = "md", onChange, disabledReason, "aria-describedby": describedBy, ...rest }) {
|
|
44
|
-
const {
|
|
85
|
+
function ShownCheckbox({ label, hint, error, size = "md", onChange, disabledReason, indeterminate = false, variant, ref, "aria-describedby": describedBy, ...rest }) {
|
|
86
|
+
const { ids: noteIds, describedIds, invalid } = useNote(hint, error, describedBy);
|
|
87
|
+
const step = useTypeStep();
|
|
45
88
|
const { props: guard, tooltip, blocked, } = useBlocked(disabledReason, {
|
|
46
89
|
...rest,
|
|
47
90
|
"aria-describedby": describedIds || undefined,
|
|
48
91
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
92
|
+
const card = variant === "card";
|
|
93
|
+
return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cx(labelLook(blocked, card), SIZE[size].gap, controlText(size, step, false)), children: [card ? _jsx(CardEdge, {}) : null, _jsx(Tick, { size: size, onFirstLine: label != null, mark: "tick" }), indeterminate ? _jsx(Tick, { size: size, onFirstLine: label != null, mark: "dash" }) : null, _jsx("input", { type: "checkbox", className: cx(SIZE[size].box, "shrink-0", label != null && SIZE[size].start, "appearance-none rounded border border-slate-300 bg-white hover:border-violet-400", INVALID_EDGE, !card && focusRing), "aria-invalid": invalid, ...rest, ref: (node) => {
|
|
94
|
+
if (node)
|
|
95
|
+
node.indeterminate = indeterminate;
|
|
96
|
+
if (typeof ref === "function")
|
|
97
|
+
return ref(node);
|
|
98
|
+
if (ref)
|
|
99
|
+
ref.current = node;
|
|
100
|
+
return undefined;
|
|
101
|
+
}, ...guard, ...(onChange
|
|
56
102
|
? {
|
|
57
103
|
onChange: (event) => {
|
|
58
104
|
if (!blocked)
|
|
59
105
|
onChange(event.target.checked);
|
|
60
106
|
},
|
|
61
107
|
}
|
|
62
|
-
: {}) }), _jsx(Words, { label: label, hint: hint, error: error,
|
|
108
|
+
: {}) }), _jsx(Words, { label: card ? _jsx(CardTitle, { label: label }) : label, hint: hint, error: error, ids: noteIds })] }), tooltip] }));
|
|
63
109
|
}
|
package/dist/Chevron.js
CHANGED
|
@@ -2,5 +2,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { cx } from "./cx.js";
|
|
3
3
|
/** The right-pointing chevron of a collapsible header; it turns down when `open`. */
|
|
4
4
|
export function Chevron({ open }) {
|
|
5
|
-
return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", fill: "currentColor", className: cx("h-4 w-4 shrink-0 text-slate-400", open && "rotate-90"), children: _jsx("path", { fillRule: "evenodd", d: "M7.2 4.8a.75.75 0 0 1 1.06 0l4.7 4.67a.75.75 0 0 1 0 1.06l-4.7 4.67a.75.75 0 1 1-1.06-1.06L11.37 10 7.2 5.86a.75.75 0 0 1 0-1.06Z", clipRule: "evenodd" }) }));
|
|
5
|
+
return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", fill: "currentColor", className: cx("h-4 w-4 shrink-0 text-slate-400 motion-safe:transition-transform", open && "rotate-90"), children: _jsx("path", { fillRule: "evenodd", d: "M7.2 4.8a.75.75 0 0 1 1.06 0l4.7 4.67a.75.75 0 0 1 0 1.06l-4.7 4.67a.75.75 0 1 1-1.06-1.06L11.37 10 7.2 5.86a.75.75 0 0 1 0-1.06Z", clipRule: "evenodd" }) }));
|
|
6
6
|
}
|
package/dist/Cluster.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import type { Passthrough } from "./props.js";
|
|
3
3
|
import { type StackGap } from "./Stack.js";
|
|
4
4
|
/** The first three steps of `Stack`'s scale: `xs` between items in a line, `sm` inside a group, `md` between blocks. */
|
|
5
5
|
export type ClusterGap = Extract<StackGap, "xs" | "sm" | "md">;
|
|
6
6
|
/** Where a `Cluster`'s items sit across the row: `center`, `baseline` for mixed text sizes, `start` or `end`. */
|
|
7
7
|
export type ClusterAlign = "center" | "baseline" | "start" | "end";
|
|
8
|
-
/** Where a `Cluster`'s items sit along the row: `start`, `end`, or `between` to spread them to both ends. */
|
|
9
|
-
export type ClusterJustify = "start" | "between" | "end";
|
|
8
|
+
/** Where a `Cluster`'s items sit along the row: `start`, `center`, `end`, or `between` to spread them to both ends. */
|
|
9
|
+
export type ClusterJustify = "start" | "center" | "between" | "end";
|
|
10
10
|
/**
|
|
11
11
|
* A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
|
|
12
12
|
* cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
|
|
@@ -19,18 +19,12 @@ export type ClusterJustify = "start" | "between" | "end";
|
|
|
19
19
|
* `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
|
|
20
20
|
* inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
|
|
21
21
|
* content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
|
|
22
|
-
* (tags, chips)
|
|
23
|
-
*
|
|
22
|
+
* (tags, chips), as in `CardGrid`: the Cluster wraps each child in its own `<li>`, so the caller
|
|
23
|
+
* writes the items (`Pill`s) and never an `<li>`. `as="nav"` is a row of links (a footer's or a
|
|
24
|
+
* section's): a `<nav>` named by its required `aria-label`, holding a list with each link in its
|
|
25
|
+
* own `<li>`.
|
|
24
26
|
*/
|
|
25
|
-
export declare function Cluster({ as
|
|
26
|
-
/**
|
|
27
|
-
* The element: `div`, `span` for a row inside a `<p>` or other phrasing content, or `ul` or `ol`
|
|
28
|
-
* for a list (no markers; each child is an `<li>`).
|
|
29
|
-
*
|
|
30
|
-
* In a `span` the items must be phrasing content, so no `ClusterGrow`.
|
|
31
|
-
* @default div
|
|
32
|
-
*/
|
|
33
|
-
as?: "div" | "span" | "ul" | "ol" | undefined;
|
|
27
|
+
export declare function Cluster({ as, gap, align, justify, wrap, children, ...rest }: ClusterElement & {
|
|
34
28
|
/**
|
|
35
29
|
* The space between items: the first steps of the gap scale. Its default is one of those the
|
|
36
30
|
* `Size` type lists as not `md`.
|
|
@@ -43,7 +37,7 @@ export declare function Cluster({ as: Tag, gap, align, justify, wrap, children,
|
|
|
43
37
|
*/
|
|
44
38
|
align?: ClusterAlign | undefined;
|
|
45
39
|
/**
|
|
46
|
-
* The main axis: `start`, `between` (the first and last items at the two ends) or `end`.
|
|
40
|
+
* The main axis: `start`, `center`, `between` (the first and last items at the two ends) or `end`.
|
|
47
41
|
* @default start
|
|
48
42
|
*/
|
|
49
43
|
justify?: ClusterJustify | undefined;
|
|
@@ -54,6 +48,24 @@ export declare function Cluster({ as: Tag, gap, align, justify, wrap, children,
|
|
|
54
48
|
wrap?: boolean | undefined;
|
|
55
49
|
children?: ReactNode;
|
|
56
50
|
} & Passthrough): ReactElement;
|
|
51
|
+
/** A `Cluster`'s element, and the name a `nav` needs. */
|
|
52
|
+
type ClusterElement = {
|
|
53
|
+
/**
|
|
54
|
+
* The element: `div`, `span` for a row inside a `<p>` or other phrasing content, `ul` or `ol`
|
|
55
|
+
* for a list (no markers; the Cluster wraps each child in an `<li>`), or `nav` for a row of
|
|
56
|
+
* links (a `<nav>` named by `aria-label`, around such a list).
|
|
57
|
+
*
|
|
58
|
+
* In a `span` the items must be phrasing content, so no `ClusterGrow`.
|
|
59
|
+
* @default div
|
|
60
|
+
*/
|
|
61
|
+
as?: "div" | "span" | "ul" | "ol" | undefined;
|
|
62
|
+
/** The accessible name; required with `as="nav"`, where it names the landmark, such as "Footer". */
|
|
63
|
+
"aria-label"?: string | undefined;
|
|
64
|
+
} | {
|
|
65
|
+
as: "nav";
|
|
66
|
+
/** The accessible name; required with `as="nav"`, where it names the landmark, such as "Footer". */
|
|
67
|
+
"aria-label": string;
|
|
68
|
+
};
|
|
57
69
|
/** The narrowest a `ClusterGrow` gets before the row wraps: `sm` or `md`. */
|
|
58
70
|
export type ClusterGrowMinWidth = "sm" | "md";
|
|
59
71
|
/**
|
|
@@ -68,3 +80,4 @@ export declare function ClusterGrow({ minWidth, children, ...rest }: {
|
|
|
68
80
|
minWidth?: ClusterGrowMinWidth | undefined;
|
|
69
81
|
children?: ReactNode;
|
|
70
82
|
} & Passthrough): ReactElement;
|
|
83
|
+
export {};
|
package/dist/Cluster.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement } from "react";
|
|
2
3
|
import { cx } from "./cx.js";
|
|
3
4
|
import { STACK_GAP } from "./Stack.js";
|
|
4
5
|
const ALIGN = {
|
|
@@ -9,9 +10,17 @@ const ALIGN = {
|
|
|
9
10
|
};
|
|
10
11
|
const JUSTIFY = {
|
|
11
12
|
start: "justify-start",
|
|
13
|
+
center: "justify-center",
|
|
12
14
|
between: "justify-between",
|
|
13
15
|
end: "justify-end",
|
|
14
16
|
};
|
|
17
|
+
/** A Cluster that is a `ul`, `ol` or `nav` is a list: its role, and each child in its own `<li>`. */
|
|
18
|
+
function listOf(tag, children) {
|
|
19
|
+
if (tag !== "ul" && tag !== "ol" && tag !== "nav")
|
|
20
|
+
return { items: children };
|
|
21
|
+
const items = Children.toArray(children).map((child, index) => (_jsx("li", { className: "flex", children: child }, isValidElement(child) ? child.key : index)));
|
|
22
|
+
return { role: "list", items };
|
|
23
|
+
}
|
|
15
24
|
/**
|
|
16
25
|
* A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
|
|
17
26
|
* cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
|
|
@@ -24,11 +33,19 @@ const JUSTIFY = {
|
|
|
24
33
|
* `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
|
|
25
34
|
* inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
|
|
26
35
|
* content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
|
|
27
|
-
* (tags, chips)
|
|
28
|
-
*
|
|
36
|
+
* (tags, chips), as in `CardGrid`: the Cluster wraps each child in its own `<li>`, so the caller
|
|
37
|
+
* writes the items (`Pill`s) and never an `<li>`. `as="nav"` is a row of links (a footer's or a
|
|
38
|
+
* section's): a `<nav>` named by its required `aria-label`, holding a list with each link in its
|
|
39
|
+
* own `<li>`.
|
|
29
40
|
*/
|
|
30
|
-
export function Cluster({ as
|
|
31
|
-
|
|
41
|
+
export function Cluster({ as = "div", gap = "sm", align = "center", justify = "start", wrap = true, children, ...rest }) {
|
|
42
|
+
const { role, items } = listOf(as, children);
|
|
43
|
+
const className = cx("flex", role && "list-none", STACK_GAP[gap], ALIGN[align], JUSTIFY[justify], wrap && "flex-wrap");
|
|
44
|
+
if (as === "nav") {
|
|
45
|
+
return (_jsx("nav", { ...rest, children: _jsx("ul", { role: "list", className: className, children: items }) }));
|
|
46
|
+
}
|
|
47
|
+
const Tag = as;
|
|
48
|
+
return (_jsx(Tag, { role: role, ...rest, className: className, children: items }));
|
|
32
49
|
}
|
|
33
50
|
/** The narrowest a `ClusterGrow` gets before it wraps under, the same two steps as `CardGrid`'s `minWidth`. */
|
|
34
51
|
const GROW_MIN_WIDTH = {
|
package/dist/Code.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import type { Passthrough } from "./props.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a
|
|
5
|
+
* touch smaller, for the mono face). `lines={1}` keeps a long value (a hash, a path) on one line,
|
|
6
|
+
* cut with an ellipsis, and shows its whole text in a tooltip while it is cut; `breakWords` instead breaks a long unbroken
|
|
7
|
+
* value at the edge of its box, as `Text` does.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Code({ lines, breakWords, children, ...rest }: {
|
|
5
10
|
children: ReactNode;
|
|
11
|
+
/** `1` keeps it on one line, cut with an ellipsis; while it is cut, its whole text shows in a tooltip. */
|
|
12
|
+
lines?: 1 | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Breaks a long unbroken value (a URL, a hash) at the edge of its box.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
breakWords?: boolean | undefined;
|
|
6
18
|
} & Passthrough): ReactElement;
|
package/dist/Code.js
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { Children } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { layoutClass } from "./textBox.js";
|
|
5
|
+
import { Truncated } from "./truncated.js";
|
|
6
|
+
/**
|
|
7
|
+
* Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a
|
|
8
|
+
* touch smaller, for the mono face). `lines={1}` keeps a long value (a hash, a path) on one line,
|
|
9
|
+
* cut with an ellipsis, and shows its whole text in a tooltip while it is cut; `breakWords` instead breaks a long unbroken
|
|
10
|
+
* value at the edge of its box, as `Text` does.
|
|
11
|
+
*/
|
|
12
|
+
export function Code({ lines, breakWords = false, children, ...rest }) {
|
|
13
|
+
const look = cx("rounded bg-slate-100 px-1 py-0.5 font-mono text-[0.9em]", layoutClass(undefined, lines), breakWords && "break-words");
|
|
14
|
+
if (lines === 1) {
|
|
15
|
+
return (_jsx(Truncated, { as: "code", attrs: rest, text: plainText(children), className: look, children: children }));
|
|
16
|
+
}
|
|
17
|
+
return (_jsx("code", { ...rest, className: look, children: children }));
|
|
18
|
+
}
|
|
19
|
+
/** The whole text of children made only of strings and numbers (`sha256:{hash}`), else undefined. */
|
|
20
|
+
function plainText(children) {
|
|
21
|
+
const parts = Children.toArray(children);
|
|
22
|
+
return parts.every((part) => typeof part === "string" || typeof part === "number")
|
|
23
|
+
? parts.join("")
|
|
24
|
+
: undefined;
|
|
5
25
|
}
|
package/dist/CodeBlock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
2
|
import type { CodeLanguage } from "./highlight.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
4
|
/** Exactly one of `children` (a string, newlines kept) or `lines` (one array entry per line). */
|
|
5
5
|
type CodeBlockSource = {
|
|
6
6
|
children: string;
|
|
@@ -20,7 +20,7 @@ type CodeBlockSource = {
|
|
|
20
20
|
* `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
|
|
21
21
|
* default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
|
|
22
22
|
* nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
|
|
23
|
-
* and scrolls them sideways under a
|
|
23
|
+
* and scrolls them sideways under a themed scrollbar, for code whose layout matters. With
|
|
24
24
|
* `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
|
|
25
25
|
* other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
|
|
26
26
|
* smaller box.
|
|
@@ -42,5 +42,5 @@ export declare function CodeBlock({ label, language, overflow, copy, children, l
|
|
|
42
42
|
* @default false
|
|
43
43
|
*/
|
|
44
44
|
copy?: boolean;
|
|
45
|
-
} & CodeBlockSource &
|
|
45
|
+
} & CodeBlockSource & Passthrough): ReactElement;
|
|
46
46
|
export {};
|
package/dist/CodeBlock.js
CHANGED
|
@@ -10,12 +10,12 @@ import { CodeBody } from "./CodeBody.js";
|
|
|
10
10
|
* `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
|
|
11
11
|
* default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
|
|
12
12
|
* nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
|
|
13
|
-
* and scrolls them sideways under a
|
|
13
|
+
* and scrolls them sideways under a themed scrollbar, for code whose layout matters. With
|
|
14
14
|
* `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
|
|
15
15
|
* other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
|
|
16
16
|
* smaller box.
|
|
17
17
|
*/
|
|
18
18
|
export function CodeBlock({ label, language = "text", overflow = "wrap", copy = false, children, lines, ...rest }) {
|
|
19
19
|
const captionId = useId();
|
|
20
|
-
return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-slate-50 font-mono text-[
|
|
20
|
+
return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-slate-50 font-mono text-[0.78125rem] leading-normal text-slate-900", children: [label && (_jsx("figcaption", { id: captionId, className: "border-b border-slate-200 px-3 py-1.5 text-xs text-slate-500", children: label })), _jsx(CodeBody, { code: lines ? lines.join("\n") : children, language: language, wrap: overflow === "wrap", copy: copy, labelledBy: label ? captionId : undefined })] }));
|
|
21
21
|
}
|
package/dist/CodeBody.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type CodeLanguage } from "./highlight.js";
|
|
|
5
5
|
* it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
|
|
6
6
|
* `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
|
|
7
7
|
* long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
|
|
8
|
-
* breaks inside itself); without it they scroll sideways under a themed
|
|
8
|
+
* breaks inside itself); without it they scroll sideways under a themed scrollbar. The button's column has
|
|
9
9
|
* a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
|
|
10
10
|
* client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
|
|
11
11
|
* or the button is dead.
|
package/dist/CodeBody.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CodeText } from "./CodeText.js";
|
|
3
3
|
import { CopyButton } from "./CopyButton.js";
|
|
4
|
-
import { cx, themedScrollbar } from "./cx.js";
|
|
4
|
+
import { cx, insetFocusRing, themedScrollbar } from "./cx.js";
|
|
5
5
|
import { consoleCommands } from "./highlight.js";
|
|
6
6
|
import { scrollStopProps, useScrollStop } from "./scrollStop.js";
|
|
7
|
-
/**
|
|
8
|
-
* The strip's focus ring, drawn inside it: the frame around the code clips anything outside the
|
|
9
|
-
* strip. `focusRing` with `-outline-offset-2` added would not do, since `outline-offset-2` comes
|
|
10
|
-
* later in the CSS and wins.
|
|
11
|
-
*/
|
|
12
|
-
const INSET_RING = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
|
|
13
7
|
/** Whether a strip that scrolls sideways takes its tab stop: always, until it has been measured. */
|
|
14
8
|
function takesStop(measured, stop) {
|
|
15
9
|
return measured ? stop : true;
|
|
@@ -19,7 +13,7 @@ function takesStop(measured, stop) {
|
|
|
19
13
|
* it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
|
|
20
14
|
* `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
|
|
21
15
|
* long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
|
|
22
|
-
* breaks inside itself); without it they scroll sideways under a themed
|
|
16
|
+
* breaks inside itself); without it they scroll sideways under a themed scrollbar. The button's column has
|
|
23
17
|
* a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
|
|
24
18
|
* client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
|
|
25
19
|
* or the button is dead.
|
|
@@ -31,8 +25,8 @@ export function CodeBody({ code, language, wrap, copy, labelledBy, }) {
|
|
|
31
25
|
// hydrated is never measured and still needs the stop. Once measured, a strip that fits drops it.
|
|
32
26
|
const { attach, stop, measured } = useScrollStop("x");
|
|
33
27
|
const tabStop = !wrap && takesStop(measured, stop);
|
|
34
|
-
// The ring
|
|
28
|
+
// The ring is insetFocusRing: scrollStopProps' own ring is drawn outside the box, which the strip's
|
|
35
29
|
// overflow-hidden frame would clip.
|
|
36
30
|
const { props: stopProps } = scrollStopProps(tabStop, labelledBy !== undefined ? { labelledBy } : { label: "Code" });
|
|
37
|
-
return (_jsxs("div", { className: cx("flex items-start", copy && "gap-1 pr-1.5"), children: [_jsx("div", { ref: wrap ? undefined : attach, ...stopProps, className: cx("min-w-0 flex-1", !wrap && `overflow-x-auto ${themedScrollbar}`, tabStop &&
|
|
31
|
+
return (_jsxs("div", { className: cx("flex items-start", copy && "gap-1 pr-1.5"), children: [_jsx("div", { ref: wrap ? undefined : attach, ...stopProps, className: cx("min-w-0 flex-1", !wrap && `overflow-x-auto ${themedScrollbar}`, tabStop && insetFocusRing), children: _jsx("pre", { className: cx("px-3 py-2.5 font-mono text-[0.78125rem] leading-normal text-slate-900", wrap ? "break-words whitespace-pre-wrap" : "w-max min-w-full whitespace-pre"), children: _jsx(CodeText, { code: code, language: language, breakAtSpaces: wrap }) }) }), copy && (_jsx("div", { className: "flex w-14 shrink-0 justify-end pt-2", children: _jsx(CopyButton, { text: language === "console" ? consoleCommands(code) : code }) }))] }));
|
|
38
32
|
}
|
package/dist/CodeExample.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Passthrough } from "./props.js";
|
|
|
6
6
|
* button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
|
|
7
7
|
* it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
|
|
8
8
|
* a shared minimum so two frames side by side start alike. A wide preview or a long line of code
|
|
9
|
-
* scrolls inside the frame, under a
|
|
9
|
+
* scrolls inside the frame, under a themed scrollbar, instead of widening the page or
|
|
10
10
|
* wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
|
|
11
11
|
* does anywhere else; the caption is outside it.
|
|
12
12
|
*/
|
package/dist/CodeExample.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CodeBody } from "./CodeBody.js";
|
|
3
3
|
import { themedScrollbar } from "./cx.js";
|
|
4
|
+
import { ScrollBody } from "./scrollBody.js";
|
|
4
5
|
import { AppScale } from "./typography.js";
|
|
5
6
|
/**
|
|
6
7
|
* One framed example: the rendered `children` on top and the `code` that makes them attached
|
|
@@ -8,10 +9,10 @@ import { AppScale } from "./typography.js";
|
|
|
8
9
|
* button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
|
|
9
10
|
* it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
|
|
10
11
|
* a shared minimum so two frames side by side start alike. A wide preview or a long line of code
|
|
11
|
-
* scrolls inside the frame, under a
|
|
12
|
+
* scrolls inside the frame, under a themed scrollbar, instead of widening the page or
|
|
12
13
|
* wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
|
|
13
14
|
* does anywhere else; the caption is outside it.
|
|
14
15
|
*/
|
|
15
16
|
export function CodeExample({ code, caption, copy = false, children, ...rest }) {
|
|
16
|
-
return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-white", children: [_jsx("
|
|
17
|
+
return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-white", children: [_jsx(ScrollBody, { axis: "x", label: "Preview", className: `min-h-24 overflow-x-auto p-5 ${themedScrollbar}`, children: _jsx("div", { className: "text-slate-900", children: _jsx(AppScale, { children: children }) }) }), _jsx("div", { className: "border-t border-slate-200 bg-slate-50", children: _jsx(CodeBody, { code: code, language: "tsx", wrap: false, copy: copy }) }), caption && (_jsx("figcaption", { className: "border-t border-slate-200 px-3 py-2.5 text-sm/5 text-slate-500", children: caption }))] }));
|
|
17
18
|
}
|