@slashsuite/ui-react 0.0.0-stage → 0.12.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/LICENSE +21 -0
- package/MIGRATING.md +540 -0
- package/README.md +549 -2
- package/dist/AppShell.d.ts +127 -0
- package/dist/AppShell.js +119 -0
- package/dist/AppShellMenu.d.ts +26 -0
- package/dist/AppShellMenu.js +66 -0
- package/dist/Avatar.d.ts +75 -0
- package/dist/Avatar.js +95 -0
- package/dist/AvatarStack.d.ts +31 -0
- package/dist/AvatarStack.js +34 -0
- package/dist/Badge.d.ts +15 -0
- package/dist/Badge.js +15 -0
- package/dist/BottomSheet.d.ts +36 -0
- package/dist/BottomSheet.js +142 -0
- package/dist/Breadcrumbs.d.ts +27 -0
- package/dist/Breadcrumbs.js +29 -0
- package/dist/BulletList.d.ts +18 -0
- package/dist/BulletList.js +18 -0
- package/dist/Button.d.ts +121 -0
- package/dist/Button.js +182 -0
- package/dist/ButtonGroup.d.ts +15 -0
- package/dist/ButtonGroup.js +10 -0
- package/dist/Callout.d.ts +43 -0
- package/dist/Callout.js +45 -0
- package/dist/Card.d.ts +148 -0
- package/dist/Card.js +171 -0
- package/dist/CardBadge.d.ts +7 -0
- package/dist/CardBadge.js +12 -0
- package/dist/CardBody.d.ts +28 -0
- package/dist/CardBody.js +30 -0
- package/dist/CardGrid.d.ts +53 -0
- package/dist/CardGrid.js +52 -0
- package/dist/CardParts.d.ts +40 -0
- package/dist/CardParts.js +41 -0
- package/dist/ChatComposer.d.ts +35 -0
- package/dist/ChatComposer.js +50 -0
- package/dist/ChatMessage.d.ts +26 -0
- package/dist/ChatMessage.js +21 -0
- package/dist/ChatThread.d.ts +25 -0
- package/dist/ChatThread.js +60 -0
- package/dist/Checkbox.d.ts +42 -0
- package/dist/Checkbox.js +63 -0
- package/dist/Chevron.d.ts +5 -0
- package/dist/Chevron.js +6 -0
- package/dist/Cluster.d.ts +70 -0
- package/dist/Cluster.js +47 -0
- package/dist/Code.d.ts +6 -0
- package/dist/Code.js +5 -0
- package/dist/CodeBlock.d.ts +46 -0
- package/dist/CodeBlock.js +21 -0
- package/dist/CodeBody.d.ts +20 -0
- package/dist/CodeBody.js +38 -0
- package/dist/CodeExample.d.ts +25 -0
- package/dist/CodeExample.js +17 -0
- package/dist/CodeText.d.ts +11 -0
- package/dist/CodeText.js +64 -0
- package/dist/ColourSchemeToggle.d.ts +36 -0
- package/dist/ColourSchemeToggle.js +64 -0
- package/dist/Container.d.ts +22 -0
- package/dist/Container.js +26 -0
- package/dist/CopyButton.d.ts +17 -0
- package/dist/CopyButton.js +39 -0
- package/dist/CopyLine.d.ts +9 -0
- package/dist/CopyLine.js +7 -0
- package/dist/DateCalendar.d.ts +23 -0
- package/dist/DateCalendar.js +89 -0
- package/dist/DateField.d.ts +124 -0
- package/dist/DateField.js +111 -0
- package/dist/DateFieldCalendar.d.ts +24 -0
- package/dist/DateFieldCalendar.js +50 -0
- package/dist/DateRangePicker.d.ts +47 -0
- package/dist/DateRangePicker.js +44 -0
- package/dist/Dialog.d.ts +56 -0
- package/dist/Dialog.js +94 -0
- package/dist/Disclosure.d.ts +29 -0
- package/dist/Disclosure.js +23 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +5 -0
- package/dist/DocsLayout.d.ts +69 -0
- package/dist/DocsLayout.js +64 -0
- package/dist/Drawer.d.ts +30 -0
- package/dist/Drawer.js +24 -0
- package/dist/EmptyState.d.ts +47 -0
- package/dist/EmptyState.js +34 -0
- package/dist/Field.d.ts +44 -0
- package/dist/Field.js +51 -0
- package/dist/FieldDialog.d.ts +26 -0
- package/dist/FieldDialog.js +31 -0
- package/dist/Fieldset.d.ts +21 -0
- package/dist/Fieldset.js +22 -0
- package/dist/FileDrop.d.ts +17 -0
- package/dist/FileDrop.js +14 -0
- package/dist/FormRow.d.ts +46 -0
- package/dist/FormRow.js +39 -0
- package/dist/Hero.d.ts +23 -0
- package/dist/Hero.js +28 -0
- package/dist/Icon.d.ts +40 -0
- package/dist/Icon.js +30 -0
- package/dist/IconButton.d.ts +72 -0
- package/dist/IconButton.js +65 -0
- package/dist/Image.d.ts +58 -0
- package/dist/Image.js +69 -0
- package/dist/InlineEdit.d.ts +22 -0
- package/dist/InlineEdit.js +60 -0
- package/dist/Input.d.ts +40 -0
- package/dist/Input.js +42 -0
- package/dist/InputShell.d.ts +24 -0
- package/dist/InputShell.js +40 -0
- package/dist/Kbd.d.ts +6 -0
- package/dist/Kbd.js +5 -0
- package/dist/KeyValueList.d.ts +34 -0
- package/dist/KeyValueList.js +35 -0
- package/dist/Lightbox.d.ts +45 -0
- package/dist/Lightbox.js +46 -0
- package/dist/ListRow.d.ts +26 -0
- package/dist/ListRow.js +151 -0
- package/dist/Markdown.d.ts +11 -0
- package/dist/Markdown.js +49 -0
- package/dist/MediaTile.d.ts +66 -0
- package/dist/MediaTile.js +50 -0
- package/dist/Menu.d.ts +64 -0
- package/dist/Menu.js +86 -0
- package/dist/MetaList.d.ts +23 -0
- package/dist/MetaList.js +20 -0
- package/dist/Morph.d.ts +41 -0
- package/dist/Morph.js +107 -0
- package/dist/NavigationProgress.d.ts +20 -0
- package/dist/NavigationProgress.js +26 -0
- package/dist/OutlineRegion.d.ts +60 -0
- package/dist/OutlineRegion.js +51 -0
- package/dist/PageFade.d.ts +30 -0
- package/dist/PageFade.js +46 -0
- package/dist/PageHeader.d.ts +26 -0
- package/dist/PageHeader.js +18 -0
- package/dist/PageLayouts.d.ts +100 -0
- package/dist/PageLayouts.js +78 -0
- package/dist/Pagination.d.ts +38 -0
- package/dist/Pagination.js +65 -0
- package/dist/Pill.d.ts +79 -0
- package/dist/Pill.js +121 -0
- package/dist/ProgressBar.d.ts +47 -0
- package/dist/ProgressBar.js +47 -0
- package/dist/RadioGroup.d.ts +55 -0
- package/dist/RadioGroup.js +53 -0
- package/dist/ScrollStrip.d.ts +21 -0
- package/dist/ScrollStrip.js +12 -0
- package/dist/SearchInput.d.ts +9 -0
- package/dist/SearchInput.js +55 -0
- package/dist/Section.d.ts +93 -0
- package/dist/Section.js +55 -0
- package/dist/SegmentedControl.d.ts +47 -0
- package/dist/SegmentedControl.js +78 -0
- package/dist/Select.d.ts +28 -0
- package/dist/Select.js +19 -0
- package/dist/Show.d.ts +33 -0
- package/dist/Show.js +27 -0
- package/dist/SideColumn.d.ts +50 -0
- package/dist/SideColumn.js +45 -0
- package/dist/SidebarLayout.d.ts +32 -0
- package/dist/SidebarLayout.js +77 -0
- package/dist/SiteFooter.d.ts +31 -0
- package/dist/SiteFooter.js +24 -0
- package/dist/SiteSearch.d.ts +40 -0
- package/dist/SiteSearch.js +150 -0
- package/dist/SortableList.d.ts +86 -0
- package/dist/SortableList.js +191 -0
- package/dist/SplitBar.d.ts +29 -0
- package/dist/SplitBar.js +22 -0
- package/dist/Stack.d.ts +114 -0
- package/dist/Stack.js +76 -0
- package/dist/StackedBar.d.ts +64 -0
- package/dist/StackedBar.js +58 -0
- package/dist/StatTile.d.ts +33 -0
- package/dist/StatTile.js +44 -0
- package/dist/StatusPages.d.ts +49 -0
- package/dist/StatusPages.js +63 -0
- package/dist/Steps.d.ts +29 -0
- package/dist/Steps.js +43 -0
- package/dist/StickyBar.d.ts +12 -0
- package/dist/StickyBar.js +10 -0
- package/dist/Switch.d.ts +56 -0
- package/dist/Switch.js +91 -0
- package/dist/Table.d.ts +92 -0
- package/dist/Table.js +92 -0
- package/dist/TableCells.d.ts +97 -0
- package/dist/TableCells.js +104 -0
- package/dist/TableEditCell.d.ts +31 -0
- package/dist/TableEditCell.js +17 -0
- package/dist/TableExpandCell.d.ts +25 -0
- package/dist/TableExpandCell.js +15 -0
- package/dist/Tabs.d.ts +38 -0
- package/dist/Tabs.js +46 -0
- package/dist/TextLink.d.ts +51 -0
- package/dist/TextLink.js +38 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.js +11 -0
- package/dist/Timeline.d.ts +31 -0
- package/dist/Timeline.js +38 -0
- package/dist/ToastRegion.d.ts +44 -0
- package/dist/ToastRegion.js +37 -0
- package/dist/Tooltip.d.ts +46 -0
- package/dist/Tooltip.js +181 -0
- package/dist/TrendChart.d.ts +36 -0
- package/dist/TrendChart.js +58 -0
- package/dist/Video.d.ts +13 -0
- package/dist/Video.js +9 -0
- package/dist/blocked.d.ts +31 -0
- package/dist/blocked.js +31 -0
- package/dist/cardContext.d.ts +8 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardWait.d.ts +13 -0
- package/dist/cardWait.js +16 -0
- package/dist/colourScheme.d.ts +22 -0
- package/dist/colourScheme.js +53 -0
- package/dist/control.d.ts +29 -0
- package/dist/control.js +37 -0
- package/dist/copyScript.d.ts +13 -0
- package/dist/copyScript.js +13 -0
- package/dist/cx.d.ts +19 -0
- package/dist/cx.js +21 -0
- package/dist/density.d.ts +38 -0
- package/dist/density.js +77 -0
- package/dist/emptySlot.d.ts +11 -0
- package/dist/emptySlot.js +16 -0
- package/dist/fieldControl.d.ts +23 -0
- package/dist/fieldControl.js +24 -0
- package/dist/fieldWait.d.ts +30 -0
- package/dist/fieldWait.js +27 -0
- package/dist/foldedColumn.d.ts +18 -0
- package/dist/foldedColumn.js +51 -0
- package/dist/headingLevel.d.ts +10 -0
- package/dist/headingLevel.js +18 -0
- package/dist/highlight.d.ts +18 -0
- package/dist/highlight.js +306 -0
- package/dist/highlightConsole.d.ts +9 -0
- package/dist/highlightConsole.js +42 -0
- package/dist/highlightHtml.d.ts +7 -0
- package/dist/highlightHtml.js +132 -0
- package/dist/highlightKit.d.ts +16 -0
- package/dist/highlightKit.js +23 -0
- package/dist/highlightYaml.d.ts +3 -0
- package/dist/highlightYaml.js +143 -0
- package/dist/icons.d.ts +16 -0
- package/dist/icons.js +108 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +92 -0
- package/dist/isoDate.d.ts +5 -0
- package/dist/isoDate.js +16 -0
- package/dist/labelWords.d.ts +20 -0
- package/dist/labelWords.js +28 -0
- package/dist/layoutWait.d.ts +15 -0
- package/dist/layoutWait.js +18 -0
- package/dist/link.d.ts +82 -0
- package/dist/link.js +68 -0
- package/dist/listRowProps.d.ts +108 -0
- package/dist/listRowProps.js +1 -0
- package/dist/listRowWait.d.ts +6 -0
- package/dist/listRowWait.js +14 -0
- package/dist/modal.d.ts +25 -0
- package/dist/modal.js +61 -0
- package/dist/navFold.d.ts +15 -0
- package/dist/navFold.js +46 -0
- package/dist/pillTip.d.ts +8 -0
- package/dist/pillTip.js +25 -0
- package/dist/props.d.ts +26 -0
- package/dist/props.js +14 -0
- package/dist/scrollEdges.d.ts +12 -0
- package/dist/scrollEdges.js +40 -0
- package/dist/scrollStop.d.ts +32 -0
- package/dist/scrollStop.js +79 -0
- package/dist/sheetSnap.d.ts +27 -0
- package/dist/sheetSnap.js +45 -0
- package/dist/shownDate.d.ts +88 -0
- package/dist/shownDate.js +186 -0
- package/dist/size.d.ts +45 -0
- package/dist/size.js +12 -0
- package/dist/skeleton.d.ts +83 -0
- package/dist/skeleton.js +88 -0
- package/dist/stackGap.d.ts +9 -0
- package/dist/stackGap.js +16 -0
- package/dist/stickyColumn.d.ts +38 -0
- package/dist/stickyColumn.js +38 -0
- package/dist/switcher.d.ts +93 -0
- package/dist/switcher.js +78 -0
- package/dist/tableColumns.d.ts +31 -0
- package/dist/tableColumns.js +72 -0
- package/dist/tableEmpty.d.ts +15 -0
- package/dist/tableEmpty.js +26 -0
- package/dist/tableRow.d.ts +67 -0
- package/dist/tableRow.js +49 -0
- package/dist/tableSort.d.ts +22 -0
- package/dist/tableSort.js +19 -0
- package/dist/textBox.d.ts +10 -0
- package/dist/textBox.js +23 -0
- package/dist/tone.d.ts +11 -0
- package/dist/tone.js +1 -0
- package/dist/trend.d.ts +26 -0
- package/dist/trend.js +64 -0
- package/dist/typography.d.ts +203 -0
- package/dist/typography.js +242 -0
- package/dist/useImageFailed.d.ts +19 -0
- package/dist/useImageFailed.js +21 -0
- package/package.json +84 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import { type BottomSheetSnap } from "./sheetSnap.js";
|
|
4
|
+
export type { BottomSheetSnap } from "./sheetSnap.js";
|
|
5
|
+
export type BottomSheetProps = {
|
|
6
|
+
/** The sheet's accessible name, as a region, and its handle button's. */
|
|
7
|
+
label: string;
|
|
8
|
+
/**
|
|
9
|
+
* The heights it rests at, lowest first, at least two: a number from 0 to 1 is a share of the
|
|
10
|
+
* parent's height, a `"120px"` string is pixels. A snap taller than the parent is held at its height.
|
|
11
|
+
*/
|
|
12
|
+
snaps: readonly [BottomSheetSnap, BottomSheetSnap, ...BottomSheetSnap[]];
|
|
13
|
+
/** The current snap, an index into `snaps`. Render the first (0) first and a page with no JavaScript shows it. */
|
|
14
|
+
snap: number;
|
|
15
|
+
/** Called with the snap to move to: from the handle, a drag, or Escape (back to 0). Set `snap` here. */
|
|
16
|
+
onSnapChange: (snap: number) => void;
|
|
17
|
+
/** The row under the handle: a heading and a count. It stays put while the body scrolls. */
|
|
18
|
+
header?: ReactNode;
|
|
19
|
+
/** Actions pinned under the scrolling body. */
|
|
20
|
+
footer?: ReactNode;
|
|
21
|
+
/** The scrolling body. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Called with the height (px) the sheet rests at: on mount, on every change of `snap` and when the
|
|
25
|
+
* parent resizes. Pad a map camera by it.
|
|
26
|
+
*/
|
|
27
|
+
onHeightChange?: (px: number) => void;
|
|
28
|
+
} & Passthrough;
|
|
29
|
+
/**
|
|
30
|
+
* A non-modal panel docked to the bottom edge of its positioned parent, over a full-screen view (a
|
|
31
|
+
* map, a canvas) that stays usable behind it. It rests at one of its `snaps`; the handle steps
|
|
32
|
+
* through them (Enter and Space), a drag of the handle moves it and releases to the nearest snap
|
|
33
|
+
* (a fling steps on), and Escape inside it returns it to the first. Nothing is made inert and focus
|
|
34
|
+
* never moves. Full width below `md`, a panel at the start edge from `md` up.
|
|
35
|
+
*/
|
|
36
|
+
export declare function BottomSheet({ label, snaps, snap, onSnapChange, header, footer, children, onHeightChange, ...rest }: BottomSheetProps): ReactElement;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState, } from "react";
|
|
3
|
+
import { focusRing } from "./cx.js";
|
|
4
|
+
import { GapProvider } from "./stackGap.js";
|
|
5
|
+
import { releaseVelocity, restingSnap, snapCss, snapPx, } from "./sheetSnap.js";
|
|
6
|
+
const SHEET = "absolute inset-x-0 bottom-0 z-10 flex max-h-full flex-col overflow-hidden rounded-t-2xl border border-b-0 border-slate-200 bg-white pb-[env(safe-area-inset-bottom)] text-slate-900 shadow-2xl transition-[height] duration-200 ease-out data-dragging:transition-none motion-reduce:transition-none md:start-4 md:end-auto md:w-96";
|
|
7
|
+
const HANDLE = `flex h-6 w-full shrink-0 cursor-grab touch-none items-center justify-center text-slate-400 active:cursor-grabbing ${focusRing} focus-visible:-outline-offset-2`;
|
|
8
|
+
/** Pointer travel (px) under which a press on the handle is a tap, not a drag. */
|
|
9
|
+
const TAP = 6;
|
|
10
|
+
/** The pill grip on the handle. */
|
|
11
|
+
const GRIP = (_jsx("svg", { viewBox: "0 0 36 4", fill: "currentColor", "aria-hidden": "true", className: "h-1 w-9", children: _jsx("rect", { width: "36", height: "4", rx: "2" }) }));
|
|
12
|
+
const parentOf = (el) => el.offsetParent instanceof HTMLElement ? el.offsetParent : el.parentElement;
|
|
13
|
+
/** Report the height the sheet rests at: now, on a change of snap, and when its parent resizes. */
|
|
14
|
+
function useReportedHeight(sheet, resting, onHeightChange) {
|
|
15
|
+
const report = useRef(onHeightChange);
|
|
16
|
+
const reported = useRef(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
report.current = onHeightChange;
|
|
19
|
+
});
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const el = sheet.current;
|
|
22
|
+
const parent = el && parentOf(el);
|
|
23
|
+
if (!parent)
|
|
24
|
+
return undefined;
|
|
25
|
+
const send = () => {
|
|
26
|
+
const px = snapPx(resting, parent.clientHeight);
|
|
27
|
+
if (px === reported.current)
|
|
28
|
+
return;
|
|
29
|
+
reported.current = px;
|
|
30
|
+
report.current?.(px);
|
|
31
|
+
};
|
|
32
|
+
send();
|
|
33
|
+
// jsdom (a consumer's own tests) has no ResizeObserver.
|
|
34
|
+
if (typeof ResizeObserver === "undefined")
|
|
35
|
+
return undefined;
|
|
36
|
+
const observer = new ResizeObserver(send);
|
|
37
|
+
observer.observe(parent);
|
|
38
|
+
return () => observer.disconnect();
|
|
39
|
+
}, [sheet, resting]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The handle's drag, on plain pointer events: the height while dragging (`null` at rest) and the
|
|
43
|
+
* handle's handlers. Under 6px of travel a press is a tap and the button's click steps the snap; a
|
|
44
|
+
* drag releases to `restingSnap`, and the click after it is swallowed.
|
|
45
|
+
*/
|
|
46
|
+
function useSheetDrag(sheet, { snaps, snap, onSnapChange }) {
|
|
47
|
+
const drag = useRef(null);
|
|
48
|
+
/** A drag just ended: swallow the click the browser fires after its `pointerup`. */
|
|
49
|
+
const dragged = useRef(false);
|
|
50
|
+
const [dragHeight, setDragHeight] = useState(null);
|
|
51
|
+
const onPointerDown = (event) => {
|
|
52
|
+
// A second finger on the handle mid-drag is ignored: the first pointer's release ends the drag.
|
|
53
|
+
if (drag.current)
|
|
54
|
+
return;
|
|
55
|
+
dragged.current = false;
|
|
56
|
+
const el = sheet.current;
|
|
57
|
+
const parent = el && parentOf(el);
|
|
58
|
+
if (!el || !parent || (event.pointerType === "mouse" && event.button !== 0))
|
|
59
|
+
return;
|
|
60
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
61
|
+
const height = el.getBoundingClientRect().height;
|
|
62
|
+
drag.current = {
|
|
63
|
+
pointer: event.pointerId,
|
|
64
|
+
startY: event.clientY,
|
|
65
|
+
startHeight: height,
|
|
66
|
+
heights: snaps.map((s) => snapPx(s, parent.clientHeight)),
|
|
67
|
+
startSnap: snap,
|
|
68
|
+
samples: [{ height, t: event.timeStamp }],
|
|
69
|
+
moved: false,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const onPointerMove = (event) => {
|
|
73
|
+
const d = drag.current;
|
|
74
|
+
if (!d || d.pointer !== event.pointerId)
|
|
75
|
+
return;
|
|
76
|
+
const travel = event.clientY - d.startY;
|
|
77
|
+
if (!d.moved && Math.abs(travel) < TAP)
|
|
78
|
+
return;
|
|
79
|
+
d.moved = true;
|
|
80
|
+
const height = Math.min(Math.max(d.startHeight - travel, d.heights[0] ?? 0), d.heights.at(-1) ?? 0);
|
|
81
|
+
d.samples = [...d.samples.slice(-1), { height, t: event.timeStamp }];
|
|
82
|
+
setDragHeight(height);
|
|
83
|
+
};
|
|
84
|
+
const release = (event, still) => {
|
|
85
|
+
const d = drag.current;
|
|
86
|
+
if (!d || d.pointer !== event.pointerId)
|
|
87
|
+
return;
|
|
88
|
+
drag.current = null;
|
|
89
|
+
if (!d.moved)
|
|
90
|
+
return;
|
|
91
|
+
dragged.current = true;
|
|
92
|
+
const height = d.samples.at(-1)?.height ?? d.startHeight;
|
|
93
|
+
const velocity = still ? 0 : releaseVelocity(d.samples, event.timeStamp);
|
|
94
|
+
setDragHeight(null);
|
|
95
|
+
onSnapChange(restingSnap(d.heights, height, velocity, d.startSnap));
|
|
96
|
+
};
|
|
97
|
+
const onClick = (event) => {
|
|
98
|
+
// A second finger's tap mid-drag: the drag's release decides the snap.
|
|
99
|
+
if (drag.current)
|
|
100
|
+
return;
|
|
101
|
+
// A keyboard click (`detail` 0) is never the tail of a drag.
|
|
102
|
+
const swallow = dragged.current && event.detail !== 0;
|
|
103
|
+
dragged.current = false;
|
|
104
|
+
if (!swallow)
|
|
105
|
+
onSnapChange((snap + 1) % snaps.length);
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
dragHeight,
|
|
109
|
+
handle: {
|
|
110
|
+
onClick,
|
|
111
|
+
onPointerDown,
|
|
112
|
+
onPointerMove,
|
|
113
|
+
onPointerUp: (event) => release(event, false),
|
|
114
|
+
onPointerCancel: (event) => release(event, true),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A non-modal panel docked to the bottom edge of its positioned parent, over a full-screen view (a
|
|
120
|
+
* map, a canvas) that stays usable behind it. It rests at one of its `snaps`; the handle steps
|
|
121
|
+
* through them (Enter and Space), a drag of the handle moves it and releases to the nearest snap
|
|
122
|
+
* (a fling steps on), and Escape inside it returns it to the first. Nothing is made inert and focus
|
|
123
|
+
* never moves. Full width below `md`, a panel at the start edge from `md` up.
|
|
124
|
+
*/
|
|
125
|
+
export function BottomSheet({ label, snaps, snap, onSnapChange, header, footer, children, onHeightChange, ...rest }) {
|
|
126
|
+
const sheet = useRef(null);
|
|
127
|
+
const bodyId = useId();
|
|
128
|
+
const resting = snaps[snap] ?? snaps[0];
|
|
129
|
+
useReportedHeight(sheet, resting, onHeightChange);
|
|
130
|
+
const { dragHeight, handle } = useSheetDrag(sheet, { snaps, snap, onSnapChange });
|
|
131
|
+
const onKeyDown = (event) => {
|
|
132
|
+
if (event.key !== "Escape" || event.defaultPrevented || snap === 0)
|
|
133
|
+
return;
|
|
134
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
135
|
+
const dialog = target?.closest("dialog");
|
|
136
|
+
if (dialog && sheet.current?.contains(dialog))
|
|
137
|
+
return;
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
onSnapChange(0);
|
|
140
|
+
};
|
|
141
|
+
return (_jsxs("section", { ...rest, ref: sheet, "aria-label": label, onKeyDown: onKeyDown, "data-dragging": dragHeight === null ? undefined : "", className: SHEET, style: { height: dragHeight === null ? snapCss(resting) : `${dragHeight}px` }, children: [_jsx("button", { ...handle, type: "button", "aria-label": label, "aria-expanded": snap > 0, "aria-controls": bodyId, className: HANDLE, children: GRIP }), header != null && (_jsx("div", { className: "flex shrink-0 items-center justify-between gap-3 border-b border-slate-200 px-5.5 pb-3.5", children: header })), _jsx("div", { id: bodyId, className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-5.5 py-4", children: _jsx(GapProvider, { gap: "xs", children: children }) }), footer != null && (_jsx("footer", { className: "flex shrink-0 justify-end gap-2 border-t border-slate-200 px-5.5 py-3.5", children: footer }))] }));
|
|
142
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/** The classes of a crumb that links somewhere, for a router's own <Link>. The current page is plain text, not a link. */
|
|
4
|
+
export declare const crumbLinkClass: string;
|
|
5
|
+
/**
|
|
6
|
+
* A crumb that links: `href`, drawn by the app's router link through `LinkProvider` for an in-app
|
|
7
|
+
* path, else a plain `<a>`. `external` opens in a new tab. The last crumb is the current page and is
|
|
8
|
+
* never a link.
|
|
9
|
+
*/
|
|
10
|
+
export type Crumb = {
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
href: string;
|
|
13
|
+
external?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* `org / project / build / snapshot`: each crumb truncates, and the last is the current page. A
|
|
17
|
+
* crumb is a node, or a `Crumb` object when it links.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Breadcrumbs({ items, label, ...rest }: {
|
|
20
|
+
/** The trail, first to current: a node, or a `Crumb` (`{ label, href, external? }`) for one that links. The last is the current page and never a link. */
|
|
21
|
+
items: Array<Crumb | ReactNode>;
|
|
22
|
+
/**
|
|
23
|
+
* The trail's accessible name, on its `<nav>`, for an app in another language.
|
|
24
|
+
* @default Breadcrumb
|
|
25
|
+
*/
|
|
26
|
+
label?: string | undefined;
|
|
27
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { isValidElement } from "react";
|
|
3
|
+
import { cx, focusRing } from "./cx.js";
|
|
4
|
+
import { renderLink } from "./link.js";
|
|
5
|
+
/** The classes of a crumb that links somewhere, for a router's own <Link>. The current page is plain text, not a link. */
|
|
6
|
+
export const crumbLinkClass = cx("rounded text-slate-500 hover:underline", focusRing);
|
|
7
|
+
function isCrumb(crumb) {
|
|
8
|
+
return typeof crumb === "object" && crumb !== null && !isValidElement(crumb) && "label" in crumb;
|
|
9
|
+
}
|
|
10
|
+
function CrumbContent({ crumb, current, }) {
|
|
11
|
+
if (!isCrumb(crumb))
|
|
12
|
+
return crumb;
|
|
13
|
+
if (current)
|
|
14
|
+
return crumb.label;
|
|
15
|
+
return renderLink({
|
|
16
|
+
href: crumb.href,
|
|
17
|
+
external: crumb.external,
|
|
18
|
+
className: crumbLinkClass,
|
|
19
|
+
children: crumb.label,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `org / project / build / snapshot`: each crumb truncates, and the last is the current page. A
|
|
24
|
+
* crumb is a node, or a `Crumb` object when it links.
|
|
25
|
+
*/
|
|
26
|
+
export function Breadcrumbs({ items, label = "Breadcrumb", ...rest }) {
|
|
27
|
+
const last = items.length - 1;
|
|
28
|
+
return (_jsx("nav", { ...rest, "aria-label": label, className: "min-w-0", children: _jsx("ol", { className: "flex min-w-0 items-center gap-2 text-sm", children: items.map((crumb, index) => (_jsxs("li", { "aria-current": index === last ? "page" : undefined, className: "flex min-w-0 items-center gap-2", children: [index > 0 && (_jsx("span", { "aria-hidden": "true", className: "text-slate-400", children: "/" })), _jsx("span", { className: cx("min-w-0 truncate", index === last ? "font-medium text-slate-900" : "text-slate-500"), children: _jsx(CrumbContent, { crumb: crumb, current: index === last }) })] }, index))) }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/**
|
|
4
|
+
* A bulleted `<ul>`: discs, indented, a small gap between items. `ordered` makes it a numbered
|
|
5
|
+
* `<ol>` (steps a reader follows in order), with the same indent and gap. Its children are `BulletItem`s.
|
|
6
|
+
*/
|
|
7
|
+
export declare function BulletList({ ordered, children, ...rest }: {
|
|
8
|
+
/** A numbered `<ol>` instead of the bulleted `<ul>`, for items whose order matters. */
|
|
9
|
+
ordered?: boolean | undefined;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
} & Passthrough): ReactElement;
|
|
12
|
+
/**
|
|
13
|
+
* One item of a `BulletList`: an `<li>` in the body text's size and ink (the long-form scale inside
|
|
14
|
+
* a `Prose`). A long unbroken string (a URL, a token) breaks at the edge instead of overflowing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function BulletItem({ children, ...rest }: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
import { Text } from "./typography.js";
|
|
4
|
+
/**
|
|
5
|
+
* A bulleted `<ul>`: discs, indented, a small gap between items. `ordered` makes it a numbered
|
|
6
|
+
* `<ol>` (steps a reader follows in order), with the same indent and gap. Its children are `BulletItem`s.
|
|
7
|
+
*/
|
|
8
|
+
export function BulletList({ ordered = false, children, ...rest }) {
|
|
9
|
+
const Tag = ordered ? "ol" : "ul";
|
|
10
|
+
return (_jsx(Tag, { ...rest, className: cx(ordered ? "list-decimal" : "list-disc", "space-y-1 pl-5"), children: children }));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One item of a `BulletList`: an `<li>` in the body text's size and ink (the long-form scale inside
|
|
14
|
+
* a `Prose`). A long unbroken string (a URL, a token) breaks at the edge instead of overflowing.
|
|
15
|
+
*/
|
|
16
|
+
export function BulletItem({ children, ...rest }) {
|
|
17
|
+
return (_jsx(Text, { as: "li", breakWords: true, ...rest, children: children }));
|
|
18
|
+
}
|
package/dist/Button.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactElement, Ref } from "react";
|
|
2
|
+
import { type TypeStep } from "./density.js";
|
|
3
|
+
import type { IconName } from "./icons.js";
|
|
4
|
+
import type { Unstyled } from "./props.js";
|
|
5
|
+
import { type ResponsiveSize, type Size } from "./size.js";
|
|
6
|
+
import type { Tone } from "./tone.js";
|
|
7
|
+
/** A Button's look: `primary` the one main action, `outline` and `ghost` the others, `link` text in running text, `dashed` the add-another row. */
|
|
8
|
+
export type ButtonVariant = "primary" | "outline" | "ghost" | "link" | "dashed";
|
|
9
|
+
/** A Button's height and text, on the library's one `Size` scale. */
|
|
10
|
+
export type ButtonSize = Size;
|
|
11
|
+
/** A Button's tones: `neutral` (the accent fill, the default), `positive` and `danger`. */
|
|
12
|
+
export type ButtonTone = Extract<Tone, "neutral" | "positive" | "danger">;
|
|
13
|
+
/** The padding table and its `md:` twin, for the data test. */
|
|
14
|
+
export declare const buttonSizeTables: {
|
|
15
|
+
box: Record<Size, string>;
|
|
16
|
+
boxMd: Record<Size, string>;
|
|
17
|
+
};
|
|
18
|
+
/** Size, tone and variant: the look of a button, apart from its state. */
|
|
19
|
+
type ButtonLook = {
|
|
20
|
+
/**
|
|
21
|
+
* `primary` is filled, for the one main action; `outline` and `ghost` are quieter; `link` is
|
|
22
|
+
* text with an underline on hover; `dashed` is an "add another" row that fills its container.
|
|
23
|
+
* @default primary
|
|
24
|
+
*/
|
|
25
|
+
variant?: ButtonVariant | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* `sm` is compact, for table rows and toolbars; `lg` is larger, for a hero call to action. Left
|
|
28
|
+
* out, a Button takes the size of the `Card`, `ListRow` or `Table` it sits in, else `md`.
|
|
29
|
+
* `{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS: `md` on a phone,
|
|
30
|
+
* `lg` from 48rem up.
|
|
31
|
+
*
|
|
32
|
+
* The first load paints the right size. Give every control in the row the same value, so it stays
|
|
33
|
+
* aligned.
|
|
34
|
+
* @default md
|
|
35
|
+
*/
|
|
36
|
+
size?: ButtonSize | ResponsiveSize | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* `positive` is green, for accept and approve; `danger` is red, for delete and clear. Not for
|
|
39
|
+
* `dashed`, which has the one look.
|
|
40
|
+
* @default neutral
|
|
41
|
+
*/
|
|
42
|
+
tone?: ButtonTone | undefined;
|
|
43
|
+
/** An icon from the `Icon` set before the label, decorative, at the button's size. */
|
|
44
|
+
icon?: IconName | undefined;
|
|
45
|
+
};
|
|
46
|
+
/** The classes of an idle Button: what `href` draws, and what the tests compare against. */
|
|
47
|
+
export declare function buttonClass(variant?: ButtonVariant, { size, tone }?: Omit<ButtonLook, "variant" | "icon">, step?: TypeStep): string;
|
|
48
|
+
/**
|
|
49
|
+
* The classes of a blocked Button, for an element that is not a button: a pager's Previous on the
|
|
50
|
+
* first page, drawn as text in the same box so the row does not jump.
|
|
51
|
+
*/
|
|
52
|
+
export declare function blockedButtonClass(variant?: ButtonVariant, { size }?: Pick<ButtonLook, "size">, step?: TypeStep): string;
|
|
53
|
+
type ButtonAsButton = ButtonLook & {
|
|
54
|
+
/**
|
|
55
|
+
* Why the button cannot be pressed: greys it flat and blocks it (`aria-disabled`, its click,
|
|
56
|
+
* Enter and Space do nothing) while it stays in the tab order, and shows the reason as its
|
|
57
|
+
* tooltip on hover, keyboard focus and a tap, read out as its description.
|
|
58
|
+
*/
|
|
59
|
+
disabledReason?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The work is in flight: disabled, `aria-busy`, keeps its colour. Wins over `disabledReason`. A
|
|
62
|
+
* string is also the label while busy, in place of the children: `busy={saving && "Saving"}`.
|
|
63
|
+
*/
|
|
64
|
+
busy?: boolean | string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* A toggle: sets `aria-pressed`. On `outline` and `ghost`, `false` draws the neutral off look
|
|
67
|
+
* and `true` the tone's primary fill, so a row of filter chips shows the selected one plainly.
|
|
68
|
+
* Left out, the button is not a toggle, has no `aria-pressed` and keeps its variant's look.
|
|
69
|
+
*/
|
|
70
|
+
pressed?: boolean | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* A small number in a chip after the label: how many are behind the button (the splits a row
|
|
73
|
+
* has, the comments on a thread). It is part of the button's name, "Splits, 3", and `0` is
|
|
74
|
+
* shown. For a button that opens something, also pass `aria-expanded`.
|
|
75
|
+
*
|
|
76
|
+
* Pass `aria-controls` for what it opens too; the caller owns that state.
|
|
77
|
+
*/
|
|
78
|
+
count?: number | undefined;
|
|
79
|
+
href?: undefined;
|
|
80
|
+
external?: undefined;
|
|
81
|
+
/** Reaches the `<button>`, or the `<a>` of a link button, to focus it or measure it. */
|
|
82
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
83
|
+
} & Unstyled<ComponentPropsWithoutRef<"button">>;
|
|
84
|
+
type ButtonAsLink = ButtonLook & {
|
|
85
|
+
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
86
|
+
external?: boolean | undefined;
|
|
87
|
+
disabledReason?: undefined;
|
|
88
|
+
busy?: undefined;
|
|
89
|
+
pressed?: undefined;
|
|
90
|
+
/**
|
|
91
|
+
* A small number in a chip after the label: how many are behind the button (the splits a row
|
|
92
|
+
* has, the comments on a thread). It is part of the button's name, "Splits, 3", and `0` is
|
|
93
|
+
* shown. For a button that opens something, also pass `aria-expanded`.
|
|
94
|
+
*
|
|
95
|
+
* Pass `aria-controls` for what it opens too; the caller owns that state.
|
|
96
|
+
*/
|
|
97
|
+
count?: number | undefined;
|
|
98
|
+
/** Makes the button a link to this URL; an in-app path goes through the app's `LinkProvider`. */
|
|
99
|
+
href: string;
|
|
100
|
+
/** Reaches the `<button>`, or the `<a>` of a link button, to focus it or measure it. */
|
|
101
|
+
ref?: Ref<HTMLAnchorElement> | undefined;
|
|
102
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"a">, "href">>;
|
|
103
|
+
type ButtonProps = ButtonAsButton | ButtonAsLink;
|
|
104
|
+
/**
|
|
105
|
+
* A button in the primary, outline, ghost, link or dashed style (the link has no box: text with an
|
|
106
|
+
* underline on hover, for an in-line action; `dashed` is the full-width "add" row, a dashed
|
|
107
|
+
* outline with muted text that fills its container). `icon` puts an `Icon` before the label.
|
|
108
|
+
* `size="sm"` is compact and `size="lg"` larger, `size={{ base: "md", md: "lg" }}` changes at 48rem,
|
|
109
|
+
* and with no `size` it takes its container's;
|
|
110
|
+
* `tone="positive"` is green and `tone="danger"` is red;
|
|
111
|
+
* `pressed` makes it a toggle: neutral when off, the tone's fill when on. `count` puts a small
|
|
112
|
+
* number chip after the label; the chip is part of the name, and a button that opens something
|
|
113
|
+
* also takes `aria-expanded`.
|
|
114
|
+
* Defaults to `type="button"`. `disabledReason` and `busy` are the two disabled states that say
|
|
115
|
+
* more than a plain `disabled`, which keeps its half-opacity look; `busy="Saving"` also swaps the
|
|
116
|
+
* label. `ref` reaches the `<button>` or the `<a>`. `href` makes it a link instead,
|
|
117
|
+
* with the same look (the app's router link through `LinkProvider` for an in-app path, else a plain
|
|
118
|
+
* `<a>`; `external` opens a new tab).
|
|
119
|
+
*/
|
|
120
|
+
export declare function Button(props: ButtonProps): ReactElement;
|
|
121
|
+
export {};
|
package/dist/Button.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx, focusRing } from "./cx.js";
|
|
3
|
+
import { controlText, useResponsiveDensity, useTypeStep } from "./density.js";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { hasReason, useBlocked } from "./blocked.js";
|
|
6
|
+
import { renderLink } from "./link.js";
|
|
7
|
+
import { sizeClass } from "./size.js";
|
|
8
|
+
const SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
|
|
9
|
+
// Size sets the padding; the text is `controlText`'s, from the size and the type step. The link
|
|
10
|
+
// variant has no box, so it takes the text size only.
|
|
11
|
+
const BOX = {
|
|
12
|
+
sm: "gap-1.5 px-2.5 py-1",
|
|
13
|
+
md: "gap-2 px-4 py-2",
|
|
14
|
+
lg: "gap-2 px-5 py-2.5",
|
|
15
|
+
};
|
|
16
|
+
// `BOX` from the `md` breakpoint up, for a responsive size, every class written out in full.
|
|
17
|
+
const BOX_MD = {
|
|
18
|
+
sm: "md:gap-1.5 md:px-2.5 md:py-1",
|
|
19
|
+
md: "md:gap-2 md:px-4 md:py-2",
|
|
20
|
+
lg: "md:gap-2 md:px-5 md:py-2.5",
|
|
21
|
+
};
|
|
22
|
+
/** The padding table and its `md:` twin, for the data test. */
|
|
23
|
+
export const buttonSizeTables = { box: BOX, boxMd: BOX_MD };
|
|
24
|
+
// A plain `disabled` washes out and ignores the pointer. A busy button is disabled too, but keeps
|
|
25
|
+
// pointer events (the cursor says why) and does not take this; a blocked one is `aria-disabled`.
|
|
26
|
+
const DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
|
|
27
|
+
const LINK = "underline-offset-2";
|
|
28
|
+
const TONE = {
|
|
29
|
+
neutral: {
|
|
30
|
+
primary: {
|
|
31
|
+
color: "border-violet-600 bg-violet-600 text-violet-50",
|
|
32
|
+
hover: "hover:bg-violet-700",
|
|
33
|
+
},
|
|
34
|
+
outline: { color: "border-violet-600 text-violet-600", hover: "hover:bg-violet-50" },
|
|
35
|
+
ghost: { color: "border-transparent text-slate-600", hover: "hover:bg-slate-100" },
|
|
36
|
+
link: {
|
|
37
|
+
color: `border-transparent text-violet-600 ${LINK}`,
|
|
38
|
+
hover: "hover:text-violet-700 hover:underline",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
positive: {
|
|
42
|
+
primary: {
|
|
43
|
+
color: "border-emerald-600 bg-emerald-600 text-emerald-50",
|
|
44
|
+
hover: "hover:bg-emerald-700",
|
|
45
|
+
},
|
|
46
|
+
outline: { color: "border-emerald-200 text-emerald-700", hover: "hover:bg-emerald-50" },
|
|
47
|
+
ghost: { color: "border-transparent text-emerald-700", hover: "hover:bg-emerald-50" },
|
|
48
|
+
link: { color: `border-transparent text-emerald-700 ${LINK}`, hover: "hover:underline" },
|
|
49
|
+
},
|
|
50
|
+
danger: {
|
|
51
|
+
primary: { color: "border-red-600 bg-red-600 text-red-50", hover: "hover:bg-red-700" },
|
|
52
|
+
outline: { color: "border-red-200 text-red-700", hover: "hover:bg-red-50" },
|
|
53
|
+
ghost: { color: "border-transparent text-red-700", hover: "hover:bg-red-50" },
|
|
54
|
+
link: { color: `border-transparent text-red-700 ${LINK}`, hover: "hover:underline" },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// The add row: Card dashed's outline and muted text, lit with the accent on hover. One look, so
|
|
58
|
+
// `tone` does not apply to it.
|
|
59
|
+
const DASHED = {
|
|
60
|
+
color: "border-slate-300 text-slate-500",
|
|
61
|
+
hover: "hover:border-violet-400 hover:text-violet-700",
|
|
62
|
+
};
|
|
63
|
+
// An outline or ghost Button with `pressed` set is a toggle, such as a filter chip: off is neutral
|
|
64
|
+
// (the surface, a hairline, muted text, lit with the accent on hover), on is the tone's primary
|
|
65
|
+
// fill, so the selected one stands out in every theme. A primary is already filled, and link and
|
|
66
|
+
// dashed have no selected state; with `pressed` left out, outline and ghost keep their own look.
|
|
67
|
+
const TOGGLE_OFF = {
|
|
68
|
+
color: "border-slate-200 bg-white text-slate-600",
|
|
69
|
+
hover: "hover:border-violet-400",
|
|
70
|
+
};
|
|
71
|
+
// The count chip: a pill in the button's own text colour (a hairline of `currentColor`), so it reads
|
|
72
|
+
// on every variant and tone and needs no palette entry. The size is a Badge's.
|
|
73
|
+
const COUNT = "inline-flex h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[10px] font-semibold leading-none tabular-nums";
|
|
74
|
+
/** The label, then the count chip. The comma is for a screen reader only, so the name reads "Splits, 3". */
|
|
75
|
+
function withCount(children, count) {
|
|
76
|
+
if (count === undefined)
|
|
77
|
+
return children;
|
|
78
|
+
return (_jsxs(_Fragment, { children: [children, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { className: COUNT, children: count })] }));
|
|
79
|
+
}
|
|
80
|
+
function lookOf(variant, tone, pressed) {
|
|
81
|
+
if (variant === "dashed")
|
|
82
|
+
return DASHED;
|
|
83
|
+
if (pressed !== undefined && (variant === "outline" || variant === "ghost")) {
|
|
84
|
+
return pressed ? TONE[tone].primary : TOGGLE_OFF;
|
|
85
|
+
}
|
|
86
|
+
return TONE[tone][variant];
|
|
87
|
+
}
|
|
88
|
+
// Blocked replaces the variant's colour and hover rather than overriding them, so no `!` is needed.
|
|
89
|
+
const BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
|
|
90
|
+
const BLOCKED_DASHED = "cursor-not-allowed border-slate-200 text-slate-400";
|
|
91
|
+
const BLOCKED_LINK = "cursor-not-allowed border-transparent text-slate-400";
|
|
92
|
+
const BLOCKED_BY_VARIANT = {
|
|
93
|
+
link: BLOCKED_LINK,
|
|
94
|
+
dashed: BLOCKED_DASHED,
|
|
95
|
+
};
|
|
96
|
+
const BUSY = "cursor-progress opacity-85";
|
|
97
|
+
function shape(variant, size, step) {
|
|
98
|
+
return cx(SHAPE, variant !== "link" && sizeClass(BOX, BOX_MD, size), variant === "link" && "gap-1.5", variant === "dashed" && "w-full border-dashed", controlText(size, step, false), focusRing);
|
|
99
|
+
}
|
|
100
|
+
/** The classes of an idle Button: what `href` draws, and what the tests compare against. */
|
|
101
|
+
export function buttonClass(variant = "primary", { size = "md", tone = "neutral" } = {}, step) {
|
|
102
|
+
return idleClass(variant, size, tone, { step });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The classes of a blocked Button, for an element that is not a button: a pager's Previous on the
|
|
106
|
+
* first page, drawn as text in the same box so the row does not jump.
|
|
107
|
+
*/
|
|
108
|
+
export function blockedButtonClass(variant = "primary", { size = "md" } = {}, step) {
|
|
109
|
+
return stateClass({ variant, size }, "blocked", undefined, step);
|
|
110
|
+
}
|
|
111
|
+
function idleClass(variant, size, tone, { step, pressed }) {
|
|
112
|
+
const look = lookOf(variant, tone, pressed);
|
|
113
|
+
return cx(shape(variant, size, step), DISABLED_PLAIN, look.color, look.hover);
|
|
114
|
+
}
|
|
115
|
+
function isLink(props) {
|
|
116
|
+
return props.href !== undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Busy wins over blocked. */
|
|
119
|
+
function stateOf(busy, disabledReason) {
|
|
120
|
+
if (busy)
|
|
121
|
+
return "busy";
|
|
122
|
+
return hasReason(disabledReason) ? "blocked" : "idle";
|
|
123
|
+
}
|
|
124
|
+
/** The classes of a Button in a given state: blocked swaps the colour out, busy keeps it. */
|
|
125
|
+
function stateClass({ variant = "primary", size = "md", tone = "neutral" }, state, pressed, step) {
|
|
126
|
+
if (state === "blocked") {
|
|
127
|
+
return cx(shape(variant, size, step), BLOCKED_BY_VARIANT[variant] ?? BLOCKED);
|
|
128
|
+
}
|
|
129
|
+
if (state === "busy") {
|
|
130
|
+
return cx(shape(variant, size, step), lookOf(variant, tone, pressed).color, BUSY);
|
|
131
|
+
}
|
|
132
|
+
return idleClass(variant, size, tone, { step, pressed });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A button in the primary, outline, ghost, link or dashed style (the link has no box: text with an
|
|
136
|
+
* underline on hover, for an in-line action; `dashed` is the full-width "add" row, a dashed
|
|
137
|
+
* outline with muted text that fills its container). `icon` puts an `Icon` before the label.
|
|
138
|
+
* `size="sm"` is compact and `size="lg"` larger, `size={{ base: "md", md: "lg" }}` changes at 48rem,
|
|
139
|
+
* and with no `size` it takes its container's;
|
|
140
|
+
* `tone="positive"` is green and `tone="danger"` is red;
|
|
141
|
+
* `pressed` makes it a toggle: neutral when off, the tone's fill when on. `count` puts a small
|
|
142
|
+
* number chip after the label; the chip is part of the name, and a button that opens something
|
|
143
|
+
* also takes `aria-expanded`.
|
|
144
|
+
* Defaults to `type="button"`. `disabledReason` and `busy` are the two disabled states that say
|
|
145
|
+
* more than a plain `disabled`, which keeps its half-opacity look; `busy="Saving"` also swaps the
|
|
146
|
+
* label. `ref` reaches the `<button>` or the `<a>`. `href` makes it a link instead,
|
|
147
|
+
* with the same look (the app's router link through `LinkProvider` for an in-app path, else a plain
|
|
148
|
+
* `<a>`; `external` opens a new tab).
|
|
149
|
+
*/
|
|
150
|
+
export function Button(props) {
|
|
151
|
+
return isLink(props) ? _jsx(LinkButton, { ...props }) : _jsx(PlainButton, { ...props });
|
|
152
|
+
}
|
|
153
|
+
/** The icon, the label and the count chip: what a Button holds. */
|
|
154
|
+
function content(icon, size, label) {
|
|
155
|
+
if (icon === undefined)
|
|
156
|
+
return label;
|
|
157
|
+
return (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon, size: size }), label] }));
|
|
158
|
+
}
|
|
159
|
+
function LinkButton({ variant = "primary", size, tone = "neutral", icon, href, external = false, count, children, ...rest }) {
|
|
160
|
+
const drawn = useResponsiveDensity(size);
|
|
161
|
+
const step = useTypeStep();
|
|
162
|
+
return renderLink({
|
|
163
|
+
...rest,
|
|
164
|
+
href,
|
|
165
|
+
external,
|
|
166
|
+
className: buttonClass(variant, { size: drawn, tone }, step),
|
|
167
|
+
children: content(icon, drawn, withCount(children, count)),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function PlainButton({ variant, size, tone, icon, disabledReason, busy = false, pressed, count, children, title, disabled, ...rest }) {
|
|
171
|
+
const drawn = useResponsiveDensity(size);
|
|
172
|
+
const step = useTypeStep();
|
|
173
|
+
const working = Boolean(busy);
|
|
174
|
+
const state = stateOf(working, disabledReason);
|
|
175
|
+
const blocked = state === "blocked";
|
|
176
|
+
const label = working && typeof busy === "string" ? busy : withCount(children, count);
|
|
177
|
+
const { props: guard, tooltip } = useBlocked(blocked ? disabledReason : undefined, {
|
|
178
|
+
...rest,
|
|
179
|
+
title,
|
|
180
|
+
});
|
|
181
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: stateClass({ variant, size: drawn, tone }, state, pressed, step), disabled: disabled || working, "aria-busy": working || undefined, "aria-pressed": pressed, ...rest, ...guard, children: content(icon, drawn, label) }), tooltip] }));
|
|
182
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/**
|
|
4
|
+
* A wrapping row of buttons with one optional item pushed to the far end (a Back link, say). On a
|
|
5
|
+
* narrow viewport the row wraps and `end` stays at the end of the last line. `label` makes it a
|
|
6
|
+
* named `role="group"`. Directly in a `Card` footer it spans the footer, so `end` reaches the far
|
|
7
|
+
* edge.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ButtonGroup({ children, end, label, ...rest }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** One item, pushed to the end of the row. */
|
|
12
|
+
end?: ReactNode;
|
|
13
|
+
/** The accessible name of the group: sets `role="group"` and `aria-label`. */
|
|
14
|
+
label?: string;
|
|
15
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapping row of buttons with one optional item pushed to the far end (a Back link, say). On a
|
|
4
|
+
* narrow viewport the row wraps and `end` stays at the end of the last line. `label` makes it a
|
|
5
|
+
* named `role="group"`. Directly in a `Card` footer it spans the footer, so `end` reaches the far
|
|
6
|
+
* edge.
|
|
7
|
+
*/
|
|
8
|
+
export function ButtonGroup({ children, end, label, ...rest }) {
|
|
9
|
+
return (_jsxs("div", { ...rest, ...(label === undefined ? {} : { role: "group", "aria-label": label }), "data-button-group": "", className: "flex flex-wrap items-center gap-2", children: [children, end ? _jsx("div", { className: "ml-auto", children: end }) : null] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { IconName } from "./icons.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import type { Tone } from "./tone.js";
|
|
5
|
+
/** The soft fill and border of each tone; a toned `Card` uses the same. */
|
|
6
|
+
export declare const TONE_SURFACE: Record<Tone, string>;
|
|
7
|
+
/** The ink of each tone on its surface; a `ToastRegion` toast uses the same. */
|
|
8
|
+
export declare const TONE_TEXT: Record<Tone, string>;
|
|
9
|
+
/**
|
|
10
|
+
* A tinted notice box, with an optional bold title above its body. Its text is text-sm (text-base/7
|
|
11
|
+
* inside a `Prose`, boxed or `banner`). `actions` puts a button or link
|
|
12
|
+
* at the end of the row; `banner` makes it a flat strip (bottom border only, no radius) for the
|
|
13
|
+
* top of a `Card flush` and nowhere else: a padded card or a padded `FullBleedLayout` column
|
|
14
|
+
* would inset it. `align="center"` centres the text. In a page's column the notice is a plain Callout, first in the column's `Stack`. With `actions` the box is `relative`, so a `TextLink
|
|
15
|
+
* stretch` there makes the whole callout its click target, like a link in a table row. `icon`
|
|
16
|
+
* sets one of the library's icons at the start of the box, in the tone's ink. `danger` is
|
|
17
|
+
* `role="alert"` and `warn` is `role="status"`, so a screen reader announces them when they
|
|
18
|
+
* appear; the other tones have no role.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Callout({ tone, icon, title, actions, banner, align, children, ...rest }: {
|
|
21
|
+
/**
|
|
22
|
+
* What the notice means: `neutral` a plain note, `info` something worth knowing, `positive` a
|
|
23
|
+
* result, `warn` a thing to check before going on, `danger` a failure or something that cannot
|
|
24
|
+
* be undone.
|
|
25
|
+
* @default neutral
|
|
26
|
+
*/
|
|
27
|
+
tone?: Tone;
|
|
28
|
+
/** One of the library's icons, at the start of the box beside the text. */
|
|
29
|
+
icon?: IconName | undefined;
|
|
30
|
+
/** A bold line above the body. */
|
|
31
|
+
title?: ReactNode;
|
|
32
|
+
/** A flat strip: `border-b` only and no radius, for the top of a `Card flush` only. */
|
|
33
|
+
banner?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* `center` centres the title and body, for a success that stands alone. With
|
|
36
|
+
* `actions` only the text is centred.
|
|
37
|
+
* @default start
|
|
38
|
+
*/
|
|
39
|
+
align?: "start" | "center" | undefined;
|
|
40
|
+
/** A button or link at the end of the row, beside the title and body. */
|
|
41
|
+
actions?: ReactNode;
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
} & Passthrough): ReactElement;
|