@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
package/dist/SplitBar.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
import { BAR_FILL, BAR_TRACK, announcedPercent, sharePercent, WaitingBar, } from "./ProgressBar.js";
|
|
4
|
+
import { useLoading } from "./skeleton.js";
|
|
5
|
+
/**
|
|
6
|
+
* A bar split between two parties, `a` on the left and `b` on the right, each sized by its share of
|
|
7
|
+
* `a + b`. `label` names the split for a screen reader, which hears both percentages; give `names`
|
|
8
|
+
* (left, right) so it hears whose is whose. Put the parties' names under the bar yourself.
|
|
9
|
+
* While `loading` it is one bone the bar's size, since 0 is a real value.
|
|
10
|
+
*/
|
|
11
|
+
export function SplitBar({ a, b, label, names, toneA = "danger", toneB = "positive", size = "md", loading, loadingLabel, ...rest }) {
|
|
12
|
+
const waiting = useLoading(loading).loading;
|
|
13
|
+
if (waiting) {
|
|
14
|
+
const attrs = { ...rest, role: "img", "aria-label": label };
|
|
15
|
+
return _jsx(WaitingBar, { own: loading, label: loadingLabel, size: size, attrs: attrs });
|
|
16
|
+
}
|
|
17
|
+
const shareA = sharePercent(a, a + b);
|
|
18
|
+
const shareB = a + b > 0 ? 100 - shareA : 0;
|
|
19
|
+
const percentA = announcedPercent(a, a + b);
|
|
20
|
+
const percentB = a + b > 0 ? 100 - percentA : 0;
|
|
21
|
+
return (_jsxs("div", { ...rest, role: "img", "aria-label": `${label}: ${names ? `${names[0]} ${percentA}%, ${names[1]} ${percentB}%` : `${percentA}% / ${percentB}%`}`, className: cx("flex overflow-hidden rounded-full bg-slate-100", BAR_TRACK[size]), children: [_jsx("div", { className: BAR_FILL[toneA], style: { width: `${shareA}%` } }), _jsx("div", { className: BAR_FILL[toneB], style: { width: `${shareB}%` } })] }));
|
|
22
|
+
}
|
package/dist/Stack.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough, Unstyled } from "./props.js";
|
|
3
|
+
/** The space between a `Stack`'s blocks, on the gap scale: `xs` 8px, `sm` 16px, `md` 24px, `lg` 32px, `xl` 48px (64px from `sm`). */
|
|
4
|
+
export type StackGap = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
|
+
export declare const STACK_GAP: Record<StackGap, string>;
|
|
6
|
+
/** The breakpoint from which a `Stack` turns from a column into a row: `sm`, `md` or `lg`. */
|
|
7
|
+
export type StackRowFrom = "sm" | "md" | "lg";
|
|
8
|
+
/** The breakpoint where a `rowFrom` Stack turns from a column into a row. */
|
|
9
|
+
export declare const STACK_ROW_FROM: Record<StackRowFrom, string>;
|
|
10
|
+
/** A `Stack`'s width cap at the start edge: `compact`, `narrow` (a reading measure), `default`, `wide` or `full`. */
|
|
11
|
+
export type StackWidth = "compact" | "narrow" | "default" | "wide" | "full";
|
|
12
|
+
/** `default` adds nothing: the Stack is as wide as its parent. */
|
|
13
|
+
export declare const STACK_WIDTH: Record<StackWidth, string | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* A vertical column of blocks a fixed `gap` apart: `xs` between lines of text (a heading and the
|
|
16
|
+
* line under it), `sm` inside a group, `md` between blocks, `lg` between groups, `xl` between a page's top-level blocks
|
|
17
|
+
* (`gap-12`, `sm:gap-16`: the one responsive page rhythm). Left out, the gap comes from where the
|
|
18
|
+
* Stack sits: `xs` inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`, `Callout` or `ListRow`, and
|
|
19
|
+
* `md` on the page.
|
|
20
|
+
*
|
|
21
|
+
* `width` caps the column: `compact` is the width of one card or one picture's column (28rem),
|
|
22
|
+
* `narrow` is a reading measure, `wide` is wider again, `full` is the parent's whole width and
|
|
23
|
+
* `default` sets nothing. A capped Stack starts at its parent's start edge (it is never re-centred),
|
|
24
|
+
* so its first line lines up with every other block on the page. A width cap on any one block (a
|
|
25
|
+
* `Card`, an `Image`) is a Stack around it.
|
|
26
|
+
*
|
|
27
|
+
* `align="start"` keeps each child at its own width, capped at the column's (a `Button` under a
|
|
28
|
+
* form's fields); left out, every child spans the column.
|
|
29
|
+
*
|
|
30
|
+
* `divided` draws a line between each pair of children and sets them touching, with no gap: it is
|
|
31
|
+
* for rows that carry their own padding (`ListRow`s in a `Card flush`). Space and a line between
|
|
32
|
+
* blocks is a `Divider` in the Stack instead.
|
|
33
|
+
*
|
|
34
|
+
* `rowFrom` turns the column into a row from `sm`, `md` or `lg` (a column below it): the blocks sit
|
|
35
|
+
* side by side, `gap` apart, and a `ClusterGrow` around one of them takes the width left. Without it the
|
|
36
|
+
* Stack is always a column; a row that is a row at every width is a `Cluster`.
|
|
37
|
+
*
|
|
38
|
+
* `as` is a closed set: `div` (default), `section`, `form`, `ul` or `ol`. A `form` takes the form
|
|
39
|
+
* props (`onSubmit`, `action`, `method`, `noValidate`, ...). A `ul` or `ol` is drawn with no
|
|
40
|
+
* markers and its children are `<li>`s, as in `BulletList` and `Timeline`: the Stack does not wrap
|
|
41
|
+
* them, so a child is one list item and `Text as="li"` or a bare `<li>` both work. A `ul` or `ol`
|
|
42
|
+
* takes `empty` (an `EmptyState`, one muted line here), drawn in place of the list when it has no
|
|
43
|
+
* children.
|
|
44
|
+
*/
|
|
45
|
+
export declare function Stack(props: StackProps): ReactElement;
|
|
46
|
+
/** Where a Stack's children sit across the column: `stretch` spans it, `start` keeps each child's own width. */
|
|
47
|
+
export type StackAlign = "stretch" | "start";
|
|
48
|
+
type StackBase = {
|
|
49
|
+
/**
|
|
50
|
+
* Caps the column: `compact` max-w-md (one card or one picture's column), `narrow` max-w-3xl (a
|
|
51
|
+
* reading measure), `wide` max-w-5xl, `full` the parent's whole width, `default` sets nothing.
|
|
52
|
+
* @default default
|
|
53
|
+
*/
|
|
54
|
+
width?: StackWidth | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Where the children sit across the column: `stretch` spans it, `start` keeps each child at its
|
|
57
|
+
* own width (a `Button` under a form's fields).
|
|
58
|
+
* @default stretch
|
|
59
|
+
*/
|
|
60
|
+
align?: StackAlign | undefined;
|
|
61
|
+
children?: ReactNode;
|
|
62
|
+
} & (StackSpaced | StackDivided);
|
|
63
|
+
/** A Stack whose blocks are a gap apart. */
|
|
64
|
+
type StackSpaced = {
|
|
65
|
+
/**
|
|
66
|
+
* The space between blocks: `xs` gap-2, `sm` gap-4, `md` gap-6, `lg` gap-8, `xl` gap-12 (gap-16 from `sm`).
|
|
67
|
+
* @default xs inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`, `Callout` or `ListRow`, else md
|
|
68
|
+
*/
|
|
69
|
+
gap?: StackGap | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* A line between each pair of children, which then touch (no gap): rows that carry their own
|
|
72
|
+
* padding. Space and a line between blocks is a `Divider` in the Stack instead.
|
|
73
|
+
*
|
|
74
|
+
* Such as `ListRow`s in a `Card flush`.
|
|
75
|
+
*/
|
|
76
|
+
divided?: false | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Turns the column into a row from this breakpoint (`sm`, `md` or `lg`), a column below it: a main
|
|
79
|
+
* area beside a side column on a wide screen, stacked on a phone. In the row the blocks sit side by side
|
|
80
|
+
* the same `gap` apart and are as tall as the tallest; wrap the one that takes the width left in a
|
|
81
|
+
* `ClusterGrow`. Left out, the Stack is always a column.
|
|
82
|
+
*/
|
|
83
|
+
rowFrom?: StackRowFrom | undefined;
|
|
84
|
+
};
|
|
85
|
+
/** A Stack of rows with a line between each pair and no gap. */
|
|
86
|
+
type StackDivided = {
|
|
87
|
+
/**
|
|
88
|
+
* A line between each pair of children, which then touch (no gap): rows that carry their own
|
|
89
|
+
* padding. Space and a line between blocks is a `Divider` in the Stack instead.
|
|
90
|
+
*
|
|
91
|
+
* Such as `ListRow`s in a `Card flush`.
|
|
92
|
+
*/
|
|
93
|
+
divided: true;
|
|
94
|
+
gap?: never;
|
|
95
|
+
rowFrom?: never;
|
|
96
|
+
};
|
|
97
|
+
type StackProps = StackBase & (({
|
|
98
|
+
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
99
|
+
as?: "div" | "section";
|
|
100
|
+
} & Passthrough) | ({
|
|
101
|
+
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
102
|
+
as: "form";
|
|
103
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"form">, "children">>) | ({
|
|
104
|
+
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
105
|
+
as: "ul";
|
|
106
|
+
/** Drawn in place of the list when it has no children: an `EmptyState`. */
|
|
107
|
+
empty?: ReactNode;
|
|
108
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"ul">, "children">>) | ({
|
|
109
|
+
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
110
|
+
as: "ol";
|
|
111
|
+
/** Drawn in place of the list when it has no children: an `EmptyState`. */
|
|
112
|
+
empty?: ReactNode;
|
|
113
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"ol">, "children">>));
|
|
114
|
+
export {};
|
package/dist/Stack.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import {} from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { useStackGap } from "./stackGap.js";
|
|
5
|
+
import { EmptySlot, hasNoChildren } from "./emptySlot.js";
|
|
6
|
+
export const STACK_GAP = {
|
|
7
|
+
xs: "gap-2",
|
|
8
|
+
sm: "gap-4",
|
|
9
|
+
md: "gap-6",
|
|
10
|
+
lg: "gap-8",
|
|
11
|
+
xl: "gap-12 sm:gap-16",
|
|
12
|
+
};
|
|
13
|
+
/** The breakpoint where a `rowFrom` Stack turns from a column into a row. */
|
|
14
|
+
export const STACK_ROW_FROM = {
|
|
15
|
+
sm: "sm:flex-row",
|
|
16
|
+
md: "md:flex-row",
|
|
17
|
+
lg: "lg:flex-row",
|
|
18
|
+
};
|
|
19
|
+
/** `default` adds nothing: the Stack is as wide as its parent. */
|
|
20
|
+
export const STACK_WIDTH = {
|
|
21
|
+
compact: "max-w-md",
|
|
22
|
+
narrow: "max-w-3xl",
|
|
23
|
+
default: undefined,
|
|
24
|
+
wide: "max-w-5xl",
|
|
25
|
+
full: "w-full",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A vertical column of blocks a fixed `gap` apart: `xs` between lines of text (a heading and the
|
|
29
|
+
* line under it), `sm` inside a group, `md` between blocks, `lg` between groups, `xl` between a page's top-level blocks
|
|
30
|
+
* (`gap-12`, `sm:gap-16`: the one responsive page rhythm). Left out, the gap comes from where the
|
|
31
|
+
* Stack sits: `xs` inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`, `Callout` or `ListRow`, and
|
|
32
|
+
* `md` on the page.
|
|
33
|
+
*
|
|
34
|
+
* `width` caps the column: `compact` is the width of one card or one picture's column (28rem),
|
|
35
|
+
* `narrow` is a reading measure, `wide` is wider again, `full` is the parent's whole width and
|
|
36
|
+
* `default` sets nothing. A capped Stack starts at its parent's start edge (it is never re-centred),
|
|
37
|
+
* so its first line lines up with every other block on the page. A width cap on any one block (a
|
|
38
|
+
* `Card`, an `Image`) is a Stack around it.
|
|
39
|
+
*
|
|
40
|
+
* `align="start"` keeps each child at its own width, capped at the column's (a `Button` under a
|
|
41
|
+
* form's fields); left out, every child spans the column.
|
|
42
|
+
*
|
|
43
|
+
* `divided` draws a line between each pair of children and sets them touching, with no gap: it is
|
|
44
|
+
* for rows that carry their own padding (`ListRow`s in a `Card flush`). Space and a line between
|
|
45
|
+
* blocks is a `Divider` in the Stack instead.
|
|
46
|
+
*
|
|
47
|
+
* `rowFrom` turns the column into a row from `sm`, `md` or `lg` (a column below it): the blocks sit
|
|
48
|
+
* side by side, `gap` apart, and a `ClusterGrow` around one of them takes the width left. Without it the
|
|
49
|
+
* Stack is always a column; a row that is a row at every width is a `Cluster`.
|
|
50
|
+
*
|
|
51
|
+
* `as` is a closed set: `div` (default), `section`, `form`, `ul` or `ol`. A `form` takes the form
|
|
52
|
+
* props (`onSubmit`, `action`, `method`, `noValidate`, ...). A `ul` or `ol` is drawn with no
|
|
53
|
+
* markers and its children are `<li>`s, as in `BulletList` and `Timeline`: the Stack does not wrap
|
|
54
|
+
* them, so a child is one list item and `Text as="li"` or a bare `<li>` both work. A `ul` or `ol`
|
|
55
|
+
* takes `empty` (an `EmptyState`, one muted line here), drawn in place of the list when it has no
|
|
56
|
+
* children.
|
|
57
|
+
*/
|
|
58
|
+
export function Stack(props) {
|
|
59
|
+
const { empty, ...rest } = { empty: undefined, ...props };
|
|
60
|
+
if ((rest.as === "ul" || rest.as === "ol") && empty != null && hasNoChildren(rest.children)) {
|
|
61
|
+
return _jsx(EmptySlot, { size: "sm", children: empty });
|
|
62
|
+
}
|
|
63
|
+
return _jsx(StackList, { ...rest });
|
|
64
|
+
}
|
|
65
|
+
/** The Stack itself, once its empty slot is settled. */
|
|
66
|
+
function StackList({ gap, width = "default", rowFrom, align = "stretch", divided = false, as = "div", children, ...rest }) {
|
|
67
|
+
const spacing = STACK_GAP[useStackGap(gap)];
|
|
68
|
+
return (_jsx(Box, { tag: as, className: cx("flex flex-col", (as === "ul" || as === "ol") && "list-none", rowFrom && STACK_ROW_FROM[rowFrom],
|
|
69
|
+
// The line colour sits on the Stack and each row after the first inherits it, so the
|
|
70
|
+
// theme's remap of the one line utility reaches every line.
|
|
71
|
+
divided ? "border-slate-200/70 *:not-first:border-t *:not-first:border-inherit" : spacing, align === "start" && "items-start *:max-w-full", STACK_WIDTH[width], "*:data-page-header:mb-0"), ...rest, children: children }));
|
|
72
|
+
}
|
|
73
|
+
/** The element `as` picked, drawn with props already narrowed by `StackProps`. */
|
|
74
|
+
function Box({ tag: Tag, ...props }) {
|
|
75
|
+
return _jsx(Tag, { ...props });
|
|
76
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type BarSize } from "./ProgressBar.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
import { type TextTone } from "./typography.js";
|
|
6
|
+
/** The categorical scale: eight colours that say only "this category", never good or bad. */
|
|
7
|
+
export type CategoryTone = "cat1" | "cat2" | "cat3" | "cat4" | "cat5" | "cat6" | "cat7" | "cat8";
|
|
8
|
+
/**
|
|
9
|
+
* The colour of a `StackedBar` segment, a `Legend` swatch or a `TrendChart` series: the `TextTone`
|
|
10
|
+
* names, painted as a fill, or a category colour, `cat1` to `cat8`. On a chart `neutral` is a grey
|
|
11
|
+
* of its own that sits apart from `muted` (for "unmeasured" next to "same"), and `accent` is the
|
|
12
|
+
* theme's accent, apart from `info`. Categories with no meaning take `cat1` upwards in order; good
|
|
13
|
+
* and bad take the meaning tones; one chart never mixes the two.
|
|
14
|
+
*/
|
|
15
|
+
export type VizTone = TextTone | CategoryTone;
|
|
16
|
+
/** Tone → text utility, painted as a fill. The `TextTone` colours are shared; `neutral` is the chart's own grey and `cat1` to `cat8` the categorical scale, each remapped by every theme. */
|
|
17
|
+
export declare const VIZ_TONE: Record<VizTone, string>;
|
|
18
|
+
/** One part of a `StackedBar`: its `label`, its `value` (its share is `value` over the sum) and its colour. */
|
|
19
|
+
export type StackedSegment = {
|
|
20
|
+
label: string;
|
|
21
|
+
value: number;
|
|
22
|
+
tone: VizTone;
|
|
23
|
+
};
|
|
24
|
+
/** One entry of a `Legend`: the `label` the colour stands for, its swatch, and an optional `detail` (a count, a share) after it. */
|
|
25
|
+
export type LegendItem = {
|
|
26
|
+
label: string;
|
|
27
|
+
tone: VizTone;
|
|
28
|
+
/**
|
|
29
|
+
* `solid` (the default) is a filled dot; `dashed` is a dashed ring in the tone's colour with no
|
|
30
|
+
* fill, the key for an outline drawn over the chart (a snapshot overlay).
|
|
31
|
+
*/
|
|
32
|
+
swatch?: "solid" | "dashed" | undefined;
|
|
33
|
+
detail?: string | number | undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A key to the colours of a chart or a row stripe: a swatch in the `VizTone` colour (a filled
|
|
37
|
+
* dot, or a dashed ring with `swatch="dashed"`), its `label` and an optional `detail` after it. Colour alone does not say it, so the label is always drawn.
|
|
38
|
+
* `StackedBar legend` draws one under the bar from its segments.
|
|
39
|
+
* While `loading` with no `items` it draws three entries of bones.
|
|
40
|
+
*/
|
|
41
|
+
export declare function Legend({ items, loading, loadingLabel, ...rest }: {
|
|
42
|
+
/** One entry per colour: its `label`, its `tone`, an optional `swatch` and `detail` (a count, a share). */
|
|
43
|
+
items: readonly LegendItem[];
|
|
44
|
+
} & LoadingProps & Passthrough): ReactElement;
|
|
45
|
+
/**
|
|
46
|
+
* A bar of any number of parts, each sized by its share of the sum, in the order given. A part with
|
|
47
|
+
* no value is zero wide. `label` names the bar for a screen reader, which hears every part's name
|
|
48
|
+
* and whole percent (rounded, so they may not add up to exactly 100). `legend` draws a `Legend` under the bar, each part's
|
|
49
|
+
* label with its value, so the colours are named in words. While `loading` the bar is one bone (0
|
|
50
|
+
* is a real value) and the key keeps the names it has, without their values.
|
|
51
|
+
*/
|
|
52
|
+
export declare function StackedBar({ items, label, legend, size, loading, loadingLabel, ...rest }: {
|
|
53
|
+
/** The parts in order, each a `label`, a `value` (its share is the value over the sum) and a `tone`. */
|
|
54
|
+
items: readonly StackedSegment[];
|
|
55
|
+
/** What the bar shows, for a screen reader, which hears it before every part's name and percent. */
|
|
56
|
+
label: string;
|
|
57
|
+
/** Draw the key under the bar. Defaults to false. */
|
|
58
|
+
legend?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The bar's height: `sm` 6px, `md` 8px, `lg` 12px.
|
|
61
|
+
* @default md
|
|
62
|
+
*/
|
|
63
|
+
size?: BarSize;
|
|
64
|
+
} & LoadingProps & Passthrough): ReactElement;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
import { announcedPercent, BAR_TRACK, sharePercent } from "./ProgressBar.js";
|
|
4
|
+
import { Bone, BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
|
|
5
|
+
import { TEXT_TONE } from "./typography.js";
|
|
6
|
+
/** Tone → text utility, painted as a fill. The `TextTone` colours are shared; `neutral` is the chart's own grey and `cat1` to `cat8` the categorical scale, each remapped by every theme. */
|
|
7
|
+
export const VIZ_TONE = {
|
|
8
|
+
...TEXT_TONE,
|
|
9
|
+
neutral: "text-neutral-500",
|
|
10
|
+
cat1: "text-indigo-600",
|
|
11
|
+
cat2: "text-orange-600",
|
|
12
|
+
cat3: "text-teal-600",
|
|
13
|
+
cat4: "text-pink-600",
|
|
14
|
+
cat5: "text-lime-600",
|
|
15
|
+
cat6: "text-fuchsia-600",
|
|
16
|
+
cat7: "text-rose-600",
|
|
17
|
+
cat8: "text-yellow-600",
|
|
18
|
+
};
|
|
19
|
+
/** The colour of a segment: the tone's text colour, painted as a fill, so no new fill utility. */
|
|
20
|
+
const FILL = (tone) => cx("bg-current", VIZ_TONE[tone]);
|
|
21
|
+
/** A swatch: a filled dot, or a dashed ring in the same colour. */
|
|
22
|
+
const SWATCH = (item) => item.swatch === "dashed"
|
|
23
|
+
? cx("border-2 border-dashed border-current", VIZ_TONE[item.tone])
|
|
24
|
+
: FILL(item.tone);
|
|
25
|
+
/**
|
|
26
|
+
* A key to the colours of a chart or a row stripe: a swatch in the `VizTone` colour (a filled
|
|
27
|
+
* dot, or a dashed ring with `swatch="dashed"`), its `label` and an optional `detail` after it. Colour alone does not say it, so the label is always drawn.
|
|
28
|
+
* `StackedBar legend` draws one under the bar from its segments.
|
|
29
|
+
* While `loading` with no `items` it draws three entries of bones.
|
|
30
|
+
*/
|
|
31
|
+
export function Legend({ items, loading, loadingLabel, ...rest }) {
|
|
32
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
33
|
+
return (_jsxs("ul", { ...rest, ...busy(owner, waiting), className: "flex flex-wrap gap-x-4 gap-y-1 text-xs text-slate-600", children: [waiting && items.length === 0 && _jsx(LegendBones, {}), owner && waiting && (_jsx("li", { className: "sr-only", children: _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel }) })), items.map((item) => (_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("span", { "aria-hidden": "true", className: cx("size-2.5 shrink-0 rounded-full", SWATCH(item)) }), _jsx("span", { children: item.label }), item.detail !== undefined && (_jsx("span", { className: "tabular-nums text-slate-500", children: item.detail }))] }, item.label)))] }));
|
|
34
|
+
}
|
|
35
|
+
/** Three entries of bones, a swatch and a word each, for a key whose entries are not here yet. */
|
|
36
|
+
function LegendBones() {
|
|
37
|
+
return (_jsx(_Fragment, { children: [0, 1, 2].map((i) => (_jsxs("li", { "aria-hidden": "true", className: "flex items-center gap-1.5", children: [_jsx(Bone, { shape: "size-2.5 shrink-0 rounded-full" }), _jsx(Bone, { shape: "h-[0.6lh] w-12 rounded" })] }, i))) }));
|
|
38
|
+
}
|
|
39
|
+
/** A bar still waiting for its figures: the track a bone, and the key's names if it has them. */
|
|
40
|
+
function WaitingStack({ items, legend, size, name, own, label, attrs, }) {
|
|
41
|
+
const { loading, owner } = useLoading(own);
|
|
42
|
+
return (_jsxs("div", { ...attrs, ...busy(owner, loading), className: "flex flex-col gap-2", children: [_jsx("span", { role: "img", "aria-label": name, className: "block", children: _jsx(Bone, { shape: cx("block w-full rounded-full", BAR_TRACK[size]) }) }), legend && (_jsx(LoadingScope, { loading: true, children: _jsx(Legend, { items: items.map((s) => ({ label: s.label, tone: s.tone })) }) })), _jsx(BusyLabel, { owner: owner, loading: loading, label: label })] }));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A bar of any number of parts, each sized by its share of the sum, in the order given. A part with
|
|
46
|
+
* no value is zero wide. `label` names the bar for a screen reader, which hears every part's name
|
|
47
|
+
* and whole percent (rounded, so they may not add up to exactly 100). `legend` draws a `Legend` under the bar, each part's
|
|
48
|
+
* label with its value, so the colours are named in words. While `loading` the bar is one bone (0
|
|
49
|
+
* is a real value) and the key keeps the names it has, without their values.
|
|
50
|
+
*/
|
|
51
|
+
export function StackedBar({ items, label, legend = false, size = "md", loading, loadingLabel, ...rest }) {
|
|
52
|
+
if (useLoading(loading).loading) {
|
|
53
|
+
return (_jsx(WaitingStack, { items: items, legend: legend, size: size, name: label, own: loading, label: loadingLabel, attrs: rest }));
|
|
54
|
+
}
|
|
55
|
+
const total = items.reduce((sum, s) => sum + Math.max(0, s.value), 0);
|
|
56
|
+
const spoken = items.map((s) => `${s.label} ${announcedPercent(s.value, total)}%`).join(", ");
|
|
57
|
+
return (_jsxs("div", { ...rest, className: "flex flex-col gap-2", children: [_jsx("div", { role: "img", "aria-label": `${label}: ${spoken}`, className: cx("flex overflow-hidden rounded-full bg-slate-100", BAR_TRACK[size]), children: items.map((s) => (_jsx("div", { className: FILL(s.tone), style: { width: `${sharePercent(s.value, total)}%` } }, s.label))) }), legend && (_jsx(Legend, { items: items.map((s) => ({ label: s.label, tone: s.tone, detail: s.value })) }))] }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
|
+
/** The colour of a tile's value (and of its accent bar): plain ink, green, amber or red. */
|
|
5
|
+
export type StatTileTone = "neutral" | "positive" | "warn" | "danger";
|
|
6
|
+
/**
|
|
7
|
+
* One headline figure: an uppercase caption over a large tabular-nums value, with an optional
|
|
8
|
+
* hint line beneath. `tone` colours the value; `accent` adds a bar across the top edge in the same
|
|
9
|
+
* tone. `trend` draws a small line under the value in the same colour. Pass the value already
|
|
10
|
+
* formatted. While `loading`, a `label` or `value` not here yet is a bone; the hint and the trend
|
|
11
|
+
* are drawn only once given.
|
|
12
|
+
*/
|
|
13
|
+
export declare function StatTile({ label, value, hint, tone, accent, trend, loading: ownLoading, loadingLabel, ...rest }: {
|
|
14
|
+
/** The small uppercase caption over the value. */
|
|
15
|
+
label: ReactNode;
|
|
16
|
+
/** The figure, already formatted, large and in tabular figures. */
|
|
17
|
+
value: ReactNode;
|
|
18
|
+
/** A muted line under the value. */
|
|
19
|
+
hint?: ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* What the figure means: `neutral` (the default) a plain figure, `positive` good or on track,
|
|
22
|
+
* `warn` at risk, `danger` failed or over. Say it in the text too: colour alone says nothing to a
|
|
23
|
+
* screen reader.
|
|
24
|
+
*/
|
|
25
|
+
tone?: StatTileTone;
|
|
26
|
+
/** A bar across the top edge in the tone's colour. */
|
|
27
|
+
accent?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The figure over time, oldest first: a sparkline under the value, in its colour, on a scale
|
|
30
|
+
* from 0. It is decoration, so say the trend in `hint` as well.
|
|
31
|
+
*/
|
|
32
|
+
trend?: readonly number[];
|
|
33
|
+
} & LoadingProps & Passthrough): ReactElement;
|
package/dist/StatTile.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
import { BAR_FILL } from "./ProgressBar.js";
|
|
4
|
+
import { Bone, BusyLabel, busy, isEmptySlot, useLoading } from "./skeleton.js";
|
|
5
|
+
import { drawn, largest, plotY, runs, scaleMax } from "./trend.js";
|
|
6
|
+
import { Overline } from "./typography.js";
|
|
7
|
+
const VALUE = {
|
|
8
|
+
neutral: "text-slate-900",
|
|
9
|
+
positive: "text-emerald-700",
|
|
10
|
+
warn: "text-amber-700",
|
|
11
|
+
danger: "text-red-700",
|
|
12
|
+
};
|
|
13
|
+
const BAR = {
|
|
14
|
+
neutral: BAR_FILL.accent,
|
|
15
|
+
positive: BAR_FILL.positive,
|
|
16
|
+
warn: BAR_FILL.warn,
|
|
17
|
+
danger: BAR_FILL.danger,
|
|
18
|
+
};
|
|
19
|
+
const LABEL_BONE = "inline-block h-[0.6lh] w-20 rounded align-middle";
|
|
20
|
+
const VALUE_BONE = "inline-block h-[0.7lh] w-28 rounded-md align-middle";
|
|
21
|
+
/** A slot's content, or a bone of `shape` while loading with nothing in it. */
|
|
22
|
+
function slot(loading, content, shape) {
|
|
23
|
+
return loading && isEmptySlot(content) ? _jsx(Bone, { shape: shape }) : content;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One headline figure: an uppercase caption over a large tabular-nums value, with an optional
|
|
27
|
+
* hint line beneath. `tone` colours the value; `accent` adds a bar across the top edge in the same
|
|
28
|
+
* tone. `trend` draws a small line under the value in the same colour. Pass the value already
|
|
29
|
+
* formatted. While `loading`, a `label` or `value` not here yet is a bone; the hint and the trend
|
|
30
|
+
* are drawn only once given.
|
|
31
|
+
*/
|
|
32
|
+
export function StatTile({ label, value, hint, tone = "neutral", accent = false, trend, loading: ownLoading, loadingLabel, ...rest }) {
|
|
33
|
+
const { loading, owner } = useLoading(ownLoading);
|
|
34
|
+
return (_jsxs("div", { ...rest, ...busy(owner, loading), className: "relative overflow-hidden rounded-xl border border-slate-200/70 bg-white p-5 shadow-sm", children: [accent && (_jsx("span", { "aria-hidden": "true", className: cx("absolute inset-x-0 top-0 h-1", BAR[tone]) })), _jsx(Overline, { as: "p", loading: false, children: slot(loading, label, LABEL_BONE) }), _jsx("p", { className: cx("mt-2 text-3xl font-bold tabular-nums", VALUE[tone]), children: slot(loading, value, VALUE_BONE) }), _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel }), trend !== undefined && trend.length > 0 && _jsx(Sparkline, { values: trend, tone: tone }), hint != null && _jsx("p", { className: "mt-1 text-xs text-slate-500", children: hint })] }));
|
|
35
|
+
}
|
|
36
|
+
/** The tile's trend line: edge to edge, `h-8`, in the value's colour. Hidden from assistive tech. */
|
|
37
|
+
function Sparkline({ values, tone, }) {
|
|
38
|
+
const max = scaleMax(largest([values]));
|
|
39
|
+
const step = values.length > 1 ? 100 / (values.length - 1) : 0;
|
|
40
|
+
return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 100 100", preserveAspectRatio: "none", className: cx("mt-3 block h-8 w-full overflow-visible", VALUE[tone]), children: runs(values.map((value, i) => {
|
|
41
|
+
const y = drawn(value);
|
|
42
|
+
return y === null ? null : { x: values.length > 1 ? step * i : 50, y: plotY(y, max) };
|
|
43
|
+
})).map((points) => (_jsx("polyline", { points: points, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke" }, points))) }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
type StatusPageProps = {
|
|
4
|
+
/** Replaces the default heading. */
|
|
5
|
+
title?: ReactNode;
|
|
6
|
+
/** Replaces the default body copy. */
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* The page's own buttons, before "Back to home", which turns outline beside them. This is the one
|
|
10
|
+
* way to a button worded differently; there is no label prop.
|
|
11
|
+
*/
|
|
12
|
+
actions?: ReactNode;
|
|
13
|
+
} & Passthrough;
|
|
14
|
+
/**
|
|
15
|
+
* 404: the page is not there. `numeral` draws a large "404" above the title, for a site whose 404
|
|
16
|
+
* is a designed page; the digits are fixed. Off, the page is the title and copy alone.
|
|
17
|
+
*/
|
|
18
|
+
export declare function NotFound({ numeral, ...props }: StatusPageProps & {
|
|
19
|
+
/** Draws a large "404" above the title. Off by default. The digits are fixed: there is no text prop. */
|
|
20
|
+
numeral?: boolean | undefined;
|
|
21
|
+
}): ReactElement;
|
|
22
|
+
/**
|
|
23
|
+
* 500 or any failure. `detail` is the error text, shown in a `CodeBlock` under the copy; pass it
|
|
24
|
+
* only where a reader may see it (a request id, a message), never a stack trace. `onRetry` adds a
|
|
25
|
+
* "Try again" button, unless `actions` replaces it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ErrorPage({ detail, onRetry, actions, ...props }: StatusPageProps & {
|
|
28
|
+
/** The error text, in a `CodeBlock` under the copy: a request id or a message a reader may see, never a stack trace. */
|
|
29
|
+
detail?: string;
|
|
30
|
+
/** Adds a "Try again" button that calls it, unless `actions` replaces the button. */
|
|
31
|
+
onRetry?: () => void;
|
|
32
|
+
}): ReactElement;
|
|
33
|
+
/** The device has no connection. `onRetry` adds a "Try again" button, unless `actions` replaces it. */
|
|
34
|
+
export declare function Offline({ onRetry, actions, ...props }: StatusPageProps & {
|
|
35
|
+
/** Adds a "Try again" button that calls it, unless `actions` replaces the button. */
|
|
36
|
+
onRetry?: () => void;
|
|
37
|
+
}): ReactElement;
|
|
38
|
+
/**
|
|
39
|
+
* The site is down on purpose and will be back: the page for planned downtime, such as an upgrade.
|
|
40
|
+
* A failure is an `ErrorPage`, and no connection is `Offline`. It has no "Back to home": home is
|
|
41
|
+
* the site that is down.
|
|
42
|
+
*/
|
|
43
|
+
export declare function Maintenance(props: StatusPageProps): ReactElement;
|
|
44
|
+
/**
|
|
45
|
+
* 403: signed in, or not, but not allowed here. The page for a route that exists and the reader may
|
|
46
|
+
* not see; a route that is not there is a `NotFound`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function Forbidden(props: StatusPageProps): ReactElement;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "./Button.js";
|
|
3
|
+
import { CodeBlock } from "./CodeBlock.js";
|
|
4
|
+
import { useHome } from "./link.js";
|
|
5
|
+
import { CenteredLayout } from "./PageLayouts.js";
|
|
6
|
+
/** "Back to home", to the `LinkProvider`'s `home`: the primary button alone, outline after the page's actions. */
|
|
7
|
+
function HomeLink({ outline }) {
|
|
8
|
+
return (_jsx(Button, { href: useHome(), variant: outline ? "outline" : "primary", children: "Back to home" }));
|
|
9
|
+
}
|
|
10
|
+
function StatusPage({ copy, title, children, actions, extra, mark, homeward = true, ...rest }) {
|
|
11
|
+
const home = homeward && _jsx(HomeLink, { outline: Boolean(actions) });
|
|
12
|
+
return (_jsxs(CenteredLayout, { ...rest, mark: mark, title: title ?? copy.title, description: children ?? copy.body, children: [extra, (actions || home) && (_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [actions, home] }))] }));
|
|
13
|
+
}
|
|
14
|
+
const retry = (onRetry) => onRetry && _jsx(Button, { onClick: onRetry, children: "Try again" });
|
|
15
|
+
/**
|
|
16
|
+
* 404: the page is not there. `numeral` draws a large "404" above the title, for a site whose 404
|
|
17
|
+
* is a designed page; the digits are fixed. Off, the page is the title and copy alone.
|
|
18
|
+
*/
|
|
19
|
+
export function NotFound({ numeral = false, ...props }) {
|
|
20
|
+
return (_jsx(StatusPage, { copy: {
|
|
21
|
+
title: "Page not found",
|
|
22
|
+
body: "The page you are looking for does not exist or has moved.",
|
|
23
|
+
}, mark: numeral ? (_jsx("p", { className: "text-6xl font-semibold tracking-tight text-violet-600", children: "404" })) : undefined, ...props }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 500 or any failure. `detail` is the error text, shown in a `CodeBlock` under the copy; pass it
|
|
27
|
+
* only where a reader may see it (a request id, a message), never a stack trace. `onRetry` adds a
|
|
28
|
+
* "Try again" button, unless `actions` replaces it.
|
|
29
|
+
*/
|
|
30
|
+
export function ErrorPage({ detail, onRetry, actions, ...props }) {
|
|
31
|
+
return (_jsx(StatusPage, { copy: {
|
|
32
|
+
title: "Something went wrong",
|
|
33
|
+
body: "An error stopped this page from loading. You can try again.",
|
|
34
|
+
}, actions: actions ?? retry(onRetry), extra: detail && _jsx(CodeBlock, { label: "Error", children: detail }), ...props }));
|
|
35
|
+
}
|
|
36
|
+
/** The device has no connection. `onRetry` adds a "Try again" button, unless `actions` replaces it. */
|
|
37
|
+
export function Offline({ onRetry, actions, ...props }) {
|
|
38
|
+
return (_jsx(StatusPage, { copy: {
|
|
39
|
+
title: "You are offline",
|
|
40
|
+
body: "Check your connection and try again.",
|
|
41
|
+
}, actions: actions ?? retry(onRetry), ...props }));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The site is down on purpose and will be back: the page for planned downtime, such as an upgrade.
|
|
45
|
+
* A failure is an `ErrorPage`, and no connection is `Offline`. It has no "Back to home": home is
|
|
46
|
+
* the site that is down.
|
|
47
|
+
*/
|
|
48
|
+
export function Maintenance(props) {
|
|
49
|
+
return (_jsx(StatusPage, { homeward: false, copy: {
|
|
50
|
+
title: "Down for maintenance",
|
|
51
|
+
body: "We are making improvements and will be back shortly.",
|
|
52
|
+
}, ...props }));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 403: signed in, or not, but not allowed here. The page for a route that exists and the reader may
|
|
56
|
+
* not see; a route that is not there is a `NotFound`.
|
|
57
|
+
*/
|
|
58
|
+
export function Forbidden(props) {
|
|
59
|
+
return (_jsx(StatusPage, { copy: {
|
|
60
|
+
title: "Access denied",
|
|
61
|
+
body: "You do not have permission to view this page.",
|
|
62
|
+
}, ...props }));
|
|
63
|
+
}
|
package/dist/Steps.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import type { Size } from "./size.js";
|
|
4
|
+
/** A `Steps` scale: `md` the small list down a column, `lg` the steps across a landing page. */
|
|
5
|
+
export type StepsSize = Extract<Size, "md" | "lg">;
|
|
6
|
+
/**
|
|
7
|
+
* A numbered list of things to do, in order: a `title` and, under it, a line of `children`. The
|
|
8
|
+
* numbers are counted by CSS, so `Step`s can sit in a fragment or behind a condition and still run
|
|
9
|
+
* 1, 2, 3. For the way into a product ("install, log in, run"), not for progress: nothing here is
|
|
10
|
+
* done or current. A wizard's progress indicator is a different part.
|
|
11
|
+
*
|
|
12
|
+
* `size="lg"` is the steps across a landing page: from `md` they sit side by side in equal columns,
|
|
13
|
+
* each number at feature size over a large title; below `md` they stack. Use it for two to four
|
|
14
|
+
* steps.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Steps({ size, children, ...rest }: {
|
|
17
|
+
/**
|
|
18
|
+
* `md` a small list down a column; `lg` the steps across a landing page from `md` (two to four).
|
|
19
|
+
* @default md
|
|
20
|
+
*/
|
|
21
|
+
size?: StepsSize | undefined;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
} & Passthrough): ReactElement;
|
|
24
|
+
/** One step of `Steps`: a `title` and the `children` as the detail under it, at its `Steps`' size. */
|
|
25
|
+
export declare function Step({ title, children, ...rest }: {
|
|
26
|
+
/** What to do; `children` is the detail under it. */
|
|
27
|
+
title: ReactNode;
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
} & Passthrough): ReactElement;
|
package/dist/Steps.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
/** The size a `Step` reads from its `Steps`. Internal. */
|
|
4
|
+
const StepsSizeContext = createContext("md");
|
|
5
|
+
// Each scale's classes are written out whole, so Tailwind sees them.
|
|
6
|
+
const LIST = {
|
|
7
|
+
md: "flex list-none flex-col gap-3 text-left [counter-reset:step]",
|
|
8
|
+
lg: "grid list-none grid-cols-1 gap-8 text-left [counter-reset:step] md:auto-cols-fr md:grid-flow-col md:gap-6",
|
|
9
|
+
};
|
|
10
|
+
const ITEM = {
|
|
11
|
+
md: {
|
|
12
|
+
item: "grid grid-cols-[1.625rem_1fr] gap-3 [counter-increment:step]",
|
|
13
|
+
number: "flex size-[1.625rem] items-center justify-center rounded-full bg-violet-50 text-xs font-semibold tabular-nums text-violet-600 before:content-[counter(step)]",
|
|
14
|
+
body: "min-w-0 pt-0.5",
|
|
15
|
+
title: "text-sm/5 font-medium text-slate-900",
|
|
16
|
+
detail: "mt-1 text-sm/5 text-slate-600",
|
|
17
|
+
},
|
|
18
|
+
lg: {
|
|
19
|
+
item: "flex flex-col gap-4 [counter-increment:step]",
|
|
20
|
+
number: "flex size-10 items-center justify-center rounded-full bg-violet-50 text-lg font-semibold tabular-nums text-violet-600 before:content-[counter(step)]",
|
|
21
|
+
body: "min-w-0",
|
|
22
|
+
title: "text-lg/7 font-semibold text-slate-900",
|
|
23
|
+
detail: "mt-2 text-base/7 text-slate-600",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A numbered list of things to do, in order: a `title` and, under it, a line of `children`. The
|
|
28
|
+
* numbers are counted by CSS, so `Step`s can sit in a fragment or behind a condition and still run
|
|
29
|
+
* 1, 2, 3. For the way into a product ("install, log in, run"), not for progress: nothing here is
|
|
30
|
+
* done or current. A wizard's progress indicator is a different part.
|
|
31
|
+
*
|
|
32
|
+
* `size="lg"` is the steps across a landing page: from `md` they sit side by side in equal columns,
|
|
33
|
+
* each number at feature size over a large title; below `md` they stack. Use it for two to four
|
|
34
|
+
* steps.
|
|
35
|
+
*/
|
|
36
|
+
export function Steps({ size = "md", children, ...rest }) {
|
|
37
|
+
return (_jsx(StepsSizeContext.Provider, { value: size, children: _jsx("ol", { role: "list", ...rest, className: LIST[size], children: children }) }));
|
|
38
|
+
}
|
|
39
|
+
/** One step of `Steps`: a `title` and the `children` as the detail under it, at its `Steps`' size. */
|
|
40
|
+
export function Step({ title, children, ...rest }) {
|
|
41
|
+
const scale = ITEM[useContext(StepsSizeContext)];
|
|
42
|
+
return (_jsxs("li", { ...rest, className: scale.item, children: [_jsx("span", { "aria-hidden": "true", className: scale.number }), _jsxs("div", { className: scale.body, children: [_jsx("div", { className: scale.title, children: title }), children != null && _jsx("div", { className: scale.detail, children: children })] })] }));
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/**
|
|
4
|
+
* A full-width row that sticks under AppShell's header as the page scrolls: a filter or actions
|
|
5
|
+
* bar, or a viewer's title and its actions. It sits on the surface with a bottom line and pads its
|
|
6
|
+
* content as the Container pads a page. Put a `Cluster` in it for the row's layout. It spans its
|
|
7
|
+
* parent, so it belongs at the top of an `AppShell bleed` page; `FullBleedLayout`'s `bar` is one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function StickyBar({ children, ...rest }: Passthrough & {
|
|
10
|
+
/** The bar's content, usually one `Cluster` (`justify="between"` for a title and its actions). */
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): ReactElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A full-width row that sticks under AppShell's header as the page scrolls: a filter or actions
|
|
4
|
+
* bar, or a viewer's title and its actions. It sits on the surface with a bottom line and pads its
|
|
5
|
+
* content as the Container pads a page. Put a `Cluster` in it for the row's layout. It spans its
|
|
6
|
+
* parent, so it belongs at the top of an `AppShell bleed` page; `FullBleedLayout`'s `bar` is one.
|
|
7
|
+
*/
|
|
8
|
+
export function StickyBar({ children, ...rest }) {
|
|
9
|
+
return (_jsx("div", { ...rest, className: "sticky top-[var(--app-header,0px)] z-5 border-b border-slate-200 bg-white px-4 py-2 sm:px-6", children: children }));
|
|
10
|
+
}
|