@slashsuite/ui-react 0.0.0-stage → 0.11.3
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 +548 -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/Switch.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Unstyled } from "./props.js";
|
|
3
|
+
import type { Size } from "./size.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
type Naming = {
|
|
6
|
+
/** The text beside the switch; the whole label is a click target. */
|
|
7
|
+
label: NonNullable<ReactNode>;
|
|
8
|
+
"aria-label"?: string | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
label?: undefined;
|
|
11
|
+
/** A bare switch (a table cell) has no words to name it: this is its name. */
|
|
12
|
+
"aria-label": string;
|
|
13
|
+
};
|
|
14
|
+
type SwitchProps = Naming & {
|
|
15
|
+
/** Whether it is on, when the caller owns it (with `onChange`). */
|
|
16
|
+
checked?: boolean | undefined;
|
|
17
|
+
/** Whether it starts on, when the switch keeps its own state. */
|
|
18
|
+
defaultChecked?: boolean | undefined;
|
|
19
|
+
/** Called with the next value when the person flips it. Not called while `busy`. */
|
|
20
|
+
onChange?: ((checked: boolean) => void) | undefined;
|
|
21
|
+
/** A muted line under the label that says more. It is the switch's `aria-describedby`. */
|
|
22
|
+
hint?: ReactNode;
|
|
23
|
+
/** Replaces the hint with a red line (`role="alert"`) and makes the switch `aria-invalid`. */
|
|
24
|
+
error?: ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* The label's text size and the switch with it.
|
|
27
|
+
* @default md
|
|
28
|
+
*/
|
|
29
|
+
size?: Size | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The change is being saved: `aria-busy`, and a click or a key does nothing. It keeps its colour
|
|
32
|
+
* and its focus, which a native `disabled` would lose when the save starts.
|
|
33
|
+
*/
|
|
34
|
+
busy?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Why the switch cannot be flipped: it washes out and is blocked (`aria-disabled`; a click,
|
|
37
|
+
* Enter and Space do nothing) while it keeps its focus, and the reason is its tooltip on hover,
|
|
38
|
+
* keyboard focus and a tap, read out as its description.
|
|
39
|
+
*/
|
|
40
|
+
disabledReason?: string | undefined;
|
|
41
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "type" | "role" | "children" | "onChange" | "aria-checked" | "aria-busy" | "aria-disabled" | "aria-label">>;
|
|
42
|
+
/**
|
|
43
|
+
* An on/off switch for a setting that takes effect at once, usually by saving it to a server: a
|
|
44
|
+
* native `<button role="switch" aria-checked>`. The caller owns `checked` and flips it in
|
|
45
|
+
* `onChange`, or gives `defaultChecked` and the switch keeps its own state. A value sent with a
|
|
46
|
+
* form is a `Checkbox`, not a Switch. Give it a `label`
|
|
47
|
+
* (the whole label is the click target), or in a table cell leave the label out and name it with
|
|
48
|
+
* `aria-label`. `hint` is a muted line under the label; `error` replaces it with a red line
|
|
49
|
+
* (`role="alert"`) and makes the switch `aria-invalid`. The note is the switch's
|
|
50
|
+
* `aria-describedby`. `size` is `sm`, `md` (the default) or `lg`. `busy` is for the save in
|
|
51
|
+
* flight: clicks and keys do nothing, and the switch keeps its colour and its focus.
|
|
52
|
+
* `disabledReason` blocks it, focusable, with the reason as its tooltip. `disabled` is the native
|
|
53
|
+
* one, washed out. While `loading` the label is drawn and the track is a bone of its size.
|
|
54
|
+
*/
|
|
55
|
+
export declare function Switch({ loading, loadingLabel, ...props }: SwitchProps & LoadingProps): ReactElement;
|
|
56
|
+
export {};
|
package/dist/Switch.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { cx, focusRing } from "./cx.js";
|
|
4
|
+
import { useNote, Words } from "./labelWords.js";
|
|
5
|
+
import { useBlocked } from "./blocked.js";
|
|
6
|
+
import { WaitingChoice } from "./fieldWait.js";
|
|
7
|
+
import { useLoading } from "./skeleton.js";
|
|
8
|
+
/**
|
|
9
|
+
* The label's gap and text, the track, its thumb and the thumb's slide, by `size`. The track is a
|
|
10
|
+
* 2px border plus 2px of padding, so the thumb is the track's height less 8px and slides the
|
|
11
|
+
* track's width less 8px less its own width.
|
|
12
|
+
*/
|
|
13
|
+
const SIZE = {
|
|
14
|
+
sm: { label: "gap-2 text-xs", track: "h-5 w-9", thumb: "h-3 w-3", slide: "translate-x-4" },
|
|
15
|
+
md: { label: "gap-2.5 text-sm", track: "h-6 w-11", thumb: "h-4 w-4", slide: "translate-x-5" },
|
|
16
|
+
lg: { label: "gap-3 text-base", track: "h-7 w-13", thumb: "h-5 w-5", slide: "translate-x-6" },
|
|
17
|
+
};
|
|
18
|
+
// Off is an outline of the text colour with a thumb of the same colour; on is the accent filled,
|
|
19
|
+
// with a thumb in its pale text colour. `border-current` and `bg-current` are no palette colour.
|
|
20
|
+
const OFF = "border-current text-slate-500";
|
|
21
|
+
const ON = "border-violet-600 bg-violet-600 text-violet-50";
|
|
22
|
+
/** `not-allowed` for a disabled switch, `progress` for a busy one, and the pointer otherwise. */
|
|
23
|
+
function cursorOf(disabled, busy) {
|
|
24
|
+
if (disabled)
|
|
25
|
+
return "cursor-not-allowed";
|
|
26
|
+
return busy ? "cursor-progress" : "cursor-pointer";
|
|
27
|
+
}
|
|
28
|
+
/** A disabled switch washes out as a Button does; a busy one is only a little dimmer. */
|
|
29
|
+
function washOf(disabled, busy) {
|
|
30
|
+
return cx(cursorOf(disabled, busy), disabled && "opacity-50", busy && "opacity-85");
|
|
31
|
+
}
|
|
32
|
+
/** The switch itself: the track, with the thumb in it. */
|
|
33
|
+
function Track({ checked, onChange, size, busy, disabled, onClick, className, ...rest }) {
|
|
34
|
+
const { track, thumb, slide } = SIZE[size];
|
|
35
|
+
return (_jsx("button", { type: "button", role: "switch", "aria-checked": checked, "aria-busy": busy || undefined, "aria-disabled": busy || undefined, disabled: disabled, className: cx("inline-flex shrink-0 items-center rounded-full border-2 p-0.5", track, checked ? ON : OFF, className, focusRing), onClick: (event) => {
|
|
36
|
+
onClick?.(event);
|
|
37
|
+
if (event.defaultPrevented || busy)
|
|
38
|
+
return;
|
|
39
|
+
onChange(!checked);
|
|
40
|
+
}, ...rest, children: _jsx("span", { "aria-hidden": "true", className: cx("block rounded-full bg-current transition-transform motion-reduce:transition-none", thumb, checked ? slide : "translate-x-0") }) }));
|
|
41
|
+
}
|
|
42
|
+
/** The switch's state: the caller's `checked` when given, else its own from `defaultChecked`. */
|
|
43
|
+
function useChecked(checked, defaultChecked, onChange) {
|
|
44
|
+
const [own, setOwn] = useState(defaultChecked);
|
|
45
|
+
return [
|
|
46
|
+
checked ?? own,
|
|
47
|
+
(next) => {
|
|
48
|
+
if (checked === undefined)
|
|
49
|
+
setOwn(next);
|
|
50
|
+
onChange?.(next);
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
/** The switch inside its label, the note under the words. */
|
|
55
|
+
function Labelled({ label, hint, error, noteId, size, wash, children, }) {
|
|
56
|
+
const start = noteId !== undefined;
|
|
57
|
+
return (_jsxs("label", { className: cx("inline-flex text-slate-700", start ? "items-start" : "items-center", SIZE[size].label, wash), children: [children, _jsx("span", { className: cx(start && "mt-0.5"), children: _jsx(Words, { label: label, hint: hint, error: error, id: noteId }) })] }));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* An on/off switch for a setting that takes effect at once, usually by saving it to a server: a
|
|
61
|
+
* native `<button role="switch" aria-checked>`. The caller owns `checked` and flips it in
|
|
62
|
+
* `onChange`, or gives `defaultChecked` and the switch keeps its own state. A value sent with a
|
|
63
|
+
* form is a `Checkbox`, not a Switch. Give it a `label`
|
|
64
|
+
* (the whole label is the click target), or in a table cell leave the label out and name it with
|
|
65
|
+
* `aria-label`. `hint` is a muted line under the label; `error` replaces it with a red line
|
|
66
|
+
* (`role="alert"`) and makes the switch `aria-invalid`. The note is the switch's
|
|
67
|
+
* `aria-describedby`. `size` is `sm`, `md` (the default) or `lg`. `busy` is for the save in
|
|
68
|
+
* flight: clicks and keys do nothing, and the switch keeps its colour and its focus.
|
|
69
|
+
* `disabledReason` blocks it, focusable, with the reason as its tooltip. `disabled` is the native
|
|
70
|
+
* one, washed out. While `loading` the label is drawn and the track is a bone of its size.
|
|
71
|
+
*/
|
|
72
|
+
export function Switch({ loading, loadingLabel, ...props }) {
|
|
73
|
+
if (useLoading(loading).loading) {
|
|
74
|
+
const size = props.size ?? "md";
|
|
75
|
+
return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx("items-center", SIZE[size].label), shape: cx(SIZE[size].track, "rounded-full"), attrs: props }));
|
|
76
|
+
}
|
|
77
|
+
return _jsx(ShownSwitch, { ...props });
|
|
78
|
+
}
|
|
79
|
+
/** A switch with its track drawn. */
|
|
80
|
+
function ShownSwitch({ label, hint, error, checked, defaultChecked = false, onChange, size = "md", busy = false, disabledReason, "aria-describedby": describedBy, ...rest }) {
|
|
81
|
+
const { noteId, describedIds, invalid } = useNote(hint, error, describedBy);
|
|
82
|
+
const [on, flip] = useChecked(checked, defaultChecked, onChange);
|
|
83
|
+
const { props: guard, tooltip, blocked, } = useBlocked(disabledReason, {
|
|
84
|
+
...rest,
|
|
85
|
+
"aria-describedby": describedIds || undefined,
|
|
86
|
+
});
|
|
87
|
+
const off = rest.disabled === true || blocked;
|
|
88
|
+
const wash = washOf(off, busy);
|
|
89
|
+
const track = (_jsx(Track, { ...rest, checked: on, onChange: flip, size: size, busy: busy, className: label === undefined ? wash : cursorOf(off, busy), ...(invalid ? { "aria-invalid": true } : {}), ...guard }));
|
|
90
|
+
return (_jsxs(_Fragment, { children: [label === undefined ? (track) : (_jsx(Labelled, { label: label, hint: hint, error: error, noteId: noteId, size: size, wash: wash, children: track })), tooltip] }));
|
|
91
|
+
}
|
package/dist/Table.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Size } from "./size.js";
|
|
3
|
+
import { type Rest, type RowMark } from "./tableRow.js";
|
|
4
|
+
export { TableCell, TableHeaderCell, type CellTone } from "./TableCells.js";
|
|
5
|
+
export { TableExpandCell } from "./TableExpandCell.js";
|
|
6
|
+
export type { TableSort } from "./tableSort.js";
|
|
7
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
8
|
+
/**
|
|
9
|
+
* A list of records in a rounded, bordered card that scrolls sideways on a narrow screen. Compose it
|
|
10
|
+
* from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label`
|
|
11
|
+
* names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its
|
|
12
|
+
* own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A
|
|
13
|
+
* column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end
|
|
14
|
+
* alignment and tabular figures. `size` is the row padding, and the controls in the rows follow it
|
|
15
|
+
* (`sm` by default). Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
|
|
16
|
+
* body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the
|
|
17
|
+
* table keeps its role and its name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Table({ label, size, loading, loadingLabel, children, ...rest }: {
|
|
20
|
+
/** Names the table for assistive tech; it is not drawn. */
|
|
21
|
+
label: string;
|
|
22
|
+
/**
|
|
23
|
+
* The row padding; the buttons and fields in the rows take the same size.
|
|
24
|
+
* @default sm
|
|
25
|
+
*/
|
|
26
|
+
size?: Size | undefined;
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
} & LoadingProps & Rest<"table">): ReactElement;
|
|
29
|
+
/** The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card. Holds one `TableRow` of `TableHeaderCell`s. */
|
|
30
|
+
export declare function TableHead({ children, ...rest }: {
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
} & Rest<"thead">): ReactElement;
|
|
33
|
+
/**
|
|
34
|
+
* The `<tbody>`: the rows, each with a line above it and, unless the table is in a card, a fill on
|
|
35
|
+
* hover. With no rows it draws `empty` (an `EmptyState`, one muted line here) in one cell that spans
|
|
36
|
+
* every column the head declares; the head stays drawn, so the reader sees what the table holds.
|
|
37
|
+
* In a loading `Table` a body with no rows draws five rows of bones instead, never `empty`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function TableBody({ empty, children, ...rest }: {
|
|
40
|
+
/** Shown in one full-width cell when there are no rows: an `EmptyState`. */
|
|
41
|
+
empty?: ReactNode;
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
} & Rest<"tbody">): ReactElement;
|
|
44
|
+
/**
|
|
45
|
+
* The `<tfoot>`: totals and subtotals. Its cells are strong by default and each row has a firmer
|
|
46
|
+
* line above it, alone and in a card alike. Put it after `TableBody`; a row of it takes
|
|
47
|
+
* no `tone`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function TableFoot({ children, ...rest }: {
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
} & Rest<"tfoot">): ReactElement;
|
|
52
|
+
/**
|
|
53
|
+
* A `<tr>`, `relative`: the anchor a `TextLink stretch` (with `href`) stretches to. Any other link, button or
|
|
54
|
+
* control in the row (a `TextLink`, a `Button`, a `Checkbox`) sits above that link and is clickable
|
|
55
|
+
* on its own, with no class from the caller. Use it in the head and the
|
|
56
|
+
* body. In the body it also draws the line above the row and, unless the table is in a card, the hover
|
|
57
|
+
* fill. `selected` marks the current row (the one open beside the table, the one being edited): the
|
|
58
|
+
* `ListRow` selected fill and `aria-current`, the row whose detail is open, not a multi-select; it wins over `tone` and `stripe`. `tone` marks the row's status (see `RowTone`): a stripe on the leading edge and a soft fill,
|
|
59
|
+
* or `muted` to fade it. A toned row keeps its fill on hover (the status stays readable), so a
|
|
60
|
+
* linked row's link, not a hover fill, says it is clickable. `stripe` is the stripe alone, in the
|
|
61
|
+
* `TextTone` colours (the first five names of a `StackedBar` segment's `VizTone`), with no fill: the row keeps its hover
|
|
62
|
+
* and its own look. Give `tone` or `stripe`, not both. Body rows only; colour alone does not say it,
|
|
63
|
+
* so name the status in a cell too (a `Pill`). A bold subtotal is not a tone: a total of the whole
|
|
64
|
+
* table is a `TableFoot` row, and a subtotal among the body's rows is `emphasis`, the same look.
|
|
65
|
+
*/
|
|
66
|
+
export declare function TableRow({ tone, stripe, emphasis, selected, children, ...rest }: RowMark & {
|
|
67
|
+
/**
|
|
68
|
+
* The row in view (its detail open beside the table): the selected fill and `aria-current`. Body
|
|
69
|
+
* rows only.
|
|
70
|
+
*
|
|
71
|
+
* As on a `ListRow`, it is not a multi-select, and a selected row takes no `tone`.
|
|
72
|
+
*/
|
|
73
|
+
selected?: boolean | undefined;
|
|
74
|
+
children: ReactNode;
|
|
75
|
+
} & Rest<"tr">): ReactElement;
|
|
76
|
+
/**
|
|
77
|
+
* A full-width group header in the body: a tinted row with a `label` that spans every column the
|
|
78
|
+
* head declares (or `colSpan` columns), and optional `trailing` content at the far end (a count, a
|
|
79
|
+
* subtotal, a small button). The group's rows follow it. For a panel of other content across the
|
|
80
|
+
* whole row, use a `TableCell span="full"` instead.
|
|
81
|
+
*/
|
|
82
|
+
export declare function TableGroupRow({ label, trailing, colSpan, ...rest }: {
|
|
83
|
+
/** The group's name, at the start of the row. */
|
|
84
|
+
label: ReactNode;
|
|
85
|
+
/** Content at the far end of the row: a count, a subtotal, a small button. */
|
|
86
|
+
trailing?: ReactNode;
|
|
87
|
+
/**
|
|
88
|
+
* How many columns the header spans.
|
|
89
|
+
* @default every column the `TableHead` declares
|
|
90
|
+
*/
|
|
91
|
+
colSpan?: number | undefined;
|
|
92
|
+
} & Rest<"tr">): ReactElement;
|
package/dist/Table.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { useInCard } from "./cardContext.js";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { DensityProvider } from "./density.js";
|
|
6
|
+
import { hasNoChildren } from "./emptySlot.js";
|
|
7
|
+
import { columnCount, numericColumns, TableContext, withColumns } from "./tableColumns.js";
|
|
8
|
+
import { rowClass, SectionContext, SELECTED, BODY_LINE, PAD, } from "./tableRow.js";
|
|
9
|
+
export { TableCell, TableHeaderCell } from "./TableCells.js";
|
|
10
|
+
export { TableExpandCell } from "./TableExpandCell.js";
|
|
11
|
+
import { BoneRows, EmptyRow } from "./tableEmpty.js";
|
|
12
|
+
import { BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
|
|
13
|
+
/**
|
|
14
|
+
* A list of records in a rounded, bordered card that scrolls sideways on a narrow screen. Compose it
|
|
15
|
+
* from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label`
|
|
16
|
+
* names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its
|
|
17
|
+
* own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A
|
|
18
|
+
* column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end
|
|
19
|
+
* alignment and tabular figures. `size` is the row padding, and the controls in the rows follow it
|
|
20
|
+
* (`sm` by default). Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
|
|
21
|
+
* body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the
|
|
22
|
+
* table keeps its role and its name.
|
|
23
|
+
*/
|
|
24
|
+
export function Table({ label, size = "sm", loading, loadingLabel, children, ...rest }) {
|
|
25
|
+
const plain = useInCard();
|
|
26
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
27
|
+
const numeric = numericColumns(children, TableHead, TableRow);
|
|
28
|
+
const columns = columnCount(children, TableHead, TableRow);
|
|
29
|
+
return (_jsx(TableContext.Provider, { value: { plain, size, numeric, columns }, children: _jsx(DensityProvider, { size: size, children: _jsxs("div", { className: cx("overflow-x-auto", !plain && "rounded-xl border border-slate-200/70 bg-white shadow-sm"), children: [_jsxs("table", { ...rest, ...busy(owner, waiting), className: "w-full text-left text-sm", children: [_jsx("caption", { className: "sr-only", children: label }), _jsx(LoadingScope, { loading: waiting, children: children })] }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }) }) }));
|
|
30
|
+
}
|
|
31
|
+
/** The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card. Holds one `TableRow` of `TableHeaderCell`s. */
|
|
32
|
+
export function TableHead({ children, ...rest }) {
|
|
33
|
+
const { plain } = useContext(TableContext);
|
|
34
|
+
return (_jsx("thead", { ...rest, className: cx("text-xs uppercase tracking-wide text-slate-500", !plain && "bg-slate-50"), children: _jsx(SectionContext.Provider, { value: "head", children: children }) }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The `<tbody>`: the rows, each with a line above it and, unless the table is in a card, a fill on
|
|
38
|
+
* hover. With no rows it draws `empty` (an `EmptyState`, one muted line here) in one cell that spans
|
|
39
|
+
* every column the head declares; the head stays drawn, so the reader sees what the table holds.
|
|
40
|
+
* In a loading `Table` a body with no rows draws five rows of bones instead, never `empty`.
|
|
41
|
+
*/
|
|
42
|
+
export function TableBody({ empty, children, ...rest }) {
|
|
43
|
+
const waiting = useLoading(undefined).loading;
|
|
44
|
+
return (_jsx("tbody", { ...rest, children: _jsx(SectionContext.Provider, { value: "body", children: _jsx(BodyRows, { waiting: waiting, empty: empty, children: children }) }) }));
|
|
45
|
+
}
|
|
46
|
+
/** What a body holds: its rows; with none, bones while loading (loading beats empty), else `empty`. */
|
|
47
|
+
function BodyRows({ waiting, empty, children, }) {
|
|
48
|
+
if (!hasNoChildren(children))
|
|
49
|
+
return children;
|
|
50
|
+
if (waiting)
|
|
51
|
+
return _jsx(BoneRows, {});
|
|
52
|
+
return empty != null && _jsx(EmptyRow, { children: empty });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The `<tfoot>`: totals and subtotals. Its cells are strong by default and each row has a firmer
|
|
56
|
+
* line above it, alone and in a card alike. Put it after `TableBody`; a row of it takes
|
|
57
|
+
* no `tone`.
|
|
58
|
+
*/
|
|
59
|
+
export function TableFoot({ children, ...rest }) {
|
|
60
|
+
return (_jsx("tfoot", { ...rest, children: _jsx(SectionContext.Provider, { value: "foot", children: children }) }));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A `<tr>`, `relative`: the anchor a `TextLink stretch` (with `href`) stretches to. Any other link, button or
|
|
64
|
+
* control in the row (a `TextLink`, a `Button`, a `Checkbox`) sits above that link and is clickable
|
|
65
|
+
* on its own, with no class from the caller. Use it in the head and the
|
|
66
|
+
* body. In the body it also draws the line above the row and, unless the table is in a card, the hover
|
|
67
|
+
* fill. `selected` marks the current row (the one open beside the table, the one being edited): the
|
|
68
|
+
* `ListRow` selected fill and `aria-current`, the row whose detail is open, not a multi-select; it wins over `tone` and `stripe`. `tone` marks the row's status (see `RowTone`): a stripe on the leading edge and a soft fill,
|
|
69
|
+
* or `muted` to fade it. A toned row keeps its fill on hover (the status stays readable), so a
|
|
70
|
+
* linked row's link, not a hover fill, says it is clickable. `stripe` is the stripe alone, in the
|
|
71
|
+
* `TextTone` colours (the first five names of a `StackedBar` segment's `VizTone`), with no fill: the row keeps its hover
|
|
72
|
+
* and its own look. Give `tone` or `stripe`, not both. Body rows only; colour alone does not say it,
|
|
73
|
+
* so name the status in a cell too (a `Pill`). A bold subtotal is not a tone: a total of the whole
|
|
74
|
+
* table is a `TableFoot` row, and a subtotal among the body's rows is `emphasis`, the same look.
|
|
75
|
+
*/
|
|
76
|
+
export function TableRow({ tone, stripe, emphasis = false, selected = false, children, ...rest }) {
|
|
77
|
+
const outer = useContext(SectionContext);
|
|
78
|
+
const { plain } = useContext(TableContext);
|
|
79
|
+
const section = emphasis && outer === "body" ? "foot" : outer;
|
|
80
|
+
const current = selected && section === "body";
|
|
81
|
+
return (_jsx(SectionContext.Provider, { value: section, children: _jsx("tr", { ...rest, ...(current ? { "aria-current": true } : {}), className: current ? cx(BODY_LINE, SELECTED) : rowClass(section, plain, tone, stripe), children: withColumns(children) }) }));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A full-width group header in the body: a tinted row with a `label` that spans every column the
|
|
85
|
+
* head declares (or `colSpan` columns), and optional `trailing` content at the far end (a count, a
|
|
86
|
+
* subtotal, a small button). The group's rows follow it. For a panel of other content across the
|
|
87
|
+
* whole row, use a `TableCell span="full"` instead.
|
|
88
|
+
*/
|
|
89
|
+
export function TableGroupRow({ label, trailing, colSpan, ...rest }) {
|
|
90
|
+
const { size, columns } = useContext(TableContext);
|
|
91
|
+
return (_jsx("tr", { ...rest, className: "relative border-t border-slate-200/70 bg-slate-50", children: _jsx("th", { scope: "rowgroup", colSpan: colSpan ?? columns, className: cx(PAD[size].group, "text-left text-sm"), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "font-medium text-slate-900", children: label }), trailing != null && trailing !== false && (_jsx("span", { className: "shrink-0 font-normal text-slate-500", children: trailing }))] }) }) }));
|
|
92
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import { type Align, type Rest } from "./tableRow.js";
|
|
3
|
+
import { type SortProps } from "./tableSort.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
import type { Tone } from "./tone.js";
|
|
6
|
+
/**
|
|
7
|
+
* The text of a cell: its weight and colour. `neutral` (the default), `strong` and `muted` are the
|
|
8
|
+
* plain ones; the rest are the shared tones, for an amount that carries a meaning (a gain, an
|
|
9
|
+
* overspend). Colour alone does not say it, so a signed figure or a word says it too.
|
|
10
|
+
*/
|
|
11
|
+
export type CellTone = "strong" | "muted" | Tone;
|
|
12
|
+
/**
|
|
13
|
+
* A column title, `<th scope="col">`. `numeric` declares a column of figures, once: the title and
|
|
14
|
+
* every cell under it take end alignment and tabular figures. A column with nothing to show in its
|
|
15
|
+
* head (a row's actions) takes `label` instead of `children`: the name a screen reader hears
|
|
16
|
+
* ("Actions"), visually hidden so the head keeps its column. `sort` and `onSort` make the column
|
|
17
|
+
* sortable: the title becomes a button that asks for the next direction, and the column says where
|
|
18
|
+
* it stands with `aria-sort`. The app sorts its rows; the table never does.
|
|
19
|
+
*/
|
|
20
|
+
export declare function TableHeaderCell({ numeric, align, children, label, sort, onSort, ...rest }: {
|
|
21
|
+
/** A column of figures: this title and the cells under it are end aligned, the cells in tabular figures. */
|
|
22
|
+
numeric?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The title's horizontal alignment; `end` over a column of buttons, `center` over a centred column.
|
|
25
|
+
* @default end for a numeric column, else start
|
|
26
|
+
*/
|
|
27
|
+
align?: Align | undefined;
|
|
28
|
+
} & ({
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
label?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
children?: undefined;
|
|
33
|
+
/** The column's name for a screen reader, visually hidden, for a column with no visible title (a row's actions). */
|
|
34
|
+
label: string;
|
|
35
|
+
}) & ({
|
|
36
|
+
sort?: undefined;
|
|
37
|
+
onSort?: undefined;
|
|
38
|
+
} | (SortProps & {
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
label?: undefined;
|
|
41
|
+
})) & Rest<"th", "align" | "scope" | "aria-sort">): ReactElement;
|
|
42
|
+
/** A step of a hierarchy under a row: the cell's own start padding plus 1rem a level. */
|
|
43
|
+
type Indent = 1 | 2 | 3;
|
|
44
|
+
/**
|
|
45
|
+
* A `<td>`. `tone` is the text weight and colour (see `CellTone`; in a `TableFoot` it defaults to
|
|
46
|
+
* `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
|
|
47
|
+
* numeric already), `mono` a small mono face. `secondary` is a second,
|
|
48
|
+
* muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
|
|
49
|
+
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver), a cell
|
|
50
|
+
* that holds a control or a link takes that content's width, and a `numeric` or `mono` cell (a
|
|
51
|
+
* figure, a code, a type) never breaks. `truncate` caps a long value's width, cuts it with
|
|
52
|
+
* an ellipsis on one line and puts the full text in a `title`; the content is then plain text (strings and
|
|
53
|
+
* numbers), since that is what the title shows. `colSpan` passes through: a cell that
|
|
54
|
+
* spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
|
|
55
|
+
* table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
|
|
56
|
+
* column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
|
|
57
|
+
* While `loading` an empty cell draws one bone, the width of a short value.
|
|
58
|
+
*/
|
|
59
|
+
export declare function TableCell({ span, colSpan, align, tone, numeric, mono, truncate, indent, secondary, loading, loadingLabel, children, ...rest }: {
|
|
60
|
+
/**
|
|
61
|
+
* The cell's horizontal alignment; `center` for a full-width note.
|
|
62
|
+
* @default end for a numeric cell, else start
|
|
63
|
+
*/
|
|
64
|
+
align?: Align | undefined;
|
|
65
|
+
/** Sets the cell in by this many levels (1 to 3), for a line under a parent row. Start-aligned cells only. */
|
|
66
|
+
indent?: Indent | undefined;
|
|
67
|
+
/** The text weight and colour (see `CellTone`). In a `TableFoot` it defaults to `strong`. */
|
|
68
|
+
tone?: CellTone | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* A figure: end aligned, tabular figures, and the cell never wraps.
|
|
71
|
+
* @default the column's, from a `numeric` head cell
|
|
72
|
+
*/
|
|
73
|
+
numeric?: boolean | undefined;
|
|
74
|
+
/** A small monospace face for a code or a type, and the cell never wraps. */
|
|
75
|
+
mono?: boolean | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Caps the width and cuts a long value with an ellipsis on one line, the full text in a `title`.
|
|
78
|
+
* Plain text content only.
|
|
79
|
+
*
|
|
80
|
+
* Without it, a prose cell wraps down to a floor so it never becomes a sliver, a cell that holds
|
|
81
|
+
* a control or a link (a `Pill`, a `Switch`, a `Button`, a `TextLink`) takes its content's width,
|
|
82
|
+
* and a `numeric` or `mono` cell never breaks.
|
|
83
|
+
*/
|
|
84
|
+
truncate?: boolean | undefined;
|
|
85
|
+
/** A second, muted line under the content. */
|
|
86
|
+
secondary?: ReactNode;
|
|
87
|
+
children?: ReactNode;
|
|
88
|
+
} & ({
|
|
89
|
+
span?: undefined;
|
|
90
|
+
/** How many columns the cell spans; `span="full"` spans them all without a count. */
|
|
91
|
+
colSpan?: number | undefined;
|
|
92
|
+
} | {
|
|
93
|
+
/** `full` spans every column the head declares: a panel under a row, an open row's detail. */
|
|
94
|
+
span: "full";
|
|
95
|
+
colSpan?: undefined;
|
|
96
|
+
}) & LoadingProps & Rest<"td", "align" | "colSpan">): ReactElement;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, useContext } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { TableContext, useNumericColumn } from "./tableColumns.js";
|
|
5
|
+
import { ALIGN, PAD, SectionContext } from "./tableRow.js";
|
|
6
|
+
import { SortButton } from "./tableSort.js";
|
|
7
|
+
import { Bone, BusyLabel, busy, isEmptySlot, useLoading } from "./skeleton.js";
|
|
8
|
+
import { CELL_BONE } from "./tableEmpty.js";
|
|
9
|
+
import { TEXT_TONE } from "./typography.js";
|
|
10
|
+
const TONE = {
|
|
11
|
+
strong: "font-medium text-slate-900",
|
|
12
|
+
neutral: "text-slate-700",
|
|
13
|
+
...TEXT_TONE,
|
|
14
|
+
};
|
|
15
|
+
/** A plain column title, or the hidden `label` of a column with none. */
|
|
16
|
+
function HeadTitle({ label, children }) {
|
|
17
|
+
return label === undefined ? children : _jsx("span", { className: "sr-only", children: label });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A column title, `<th scope="col">`. `numeric` declares a column of figures, once: the title and
|
|
21
|
+
* every cell under it take end alignment and tabular figures. A column with nothing to show in its
|
|
22
|
+
* head (a row's actions) takes `label` instead of `children`: the name a screen reader hears
|
|
23
|
+
* ("Actions"), visually hidden so the head keeps its column. `sort` and `onSort` make the column
|
|
24
|
+
* sortable: the title becomes a button that asks for the next direction, and the column says where
|
|
25
|
+
* it stands with `aria-sort`. The app sorts its rows; the table never does.
|
|
26
|
+
*/
|
|
27
|
+
export function TableHeaderCell({ numeric = false, align = numeric ? "end" : "start", children, label, sort, onSort, ...rest }) {
|
|
28
|
+
const { size } = useContext(TableContext);
|
|
29
|
+
const sorted = sort === "ascending" || sort === "descending";
|
|
30
|
+
return (_jsx("th", { ...rest, scope: "col", ...(sorted ? { "aria-sort": sort } : {}), className: cx("whitespace-nowrap font-medium", PAD[size].head, ALIGN[align]), children: sort !== undefined && onSort !== undefined ? (_jsx(SortButton, { sort: sort, onSort: onSort, align: align, children: children })) : (_jsx(HeadTitle, { label: label, children: children })) }));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The wrapping rule: a figure or code never breaks; prose wraps, down to `min-w-48`. A cell that
|
|
34
|
+
* holds an element (a link, a `Pill`, a `Switch`, a `Button`) takes its content's width.
|
|
35
|
+
*/
|
|
36
|
+
function figureClass(numeric, mono, prose) {
|
|
37
|
+
if (!numeric && !mono)
|
|
38
|
+
return prose ? "min-w-48" : "";
|
|
39
|
+
return cx("whitespace-nowrap", numeric && "tabular-nums", mono && "font-mono text-xs");
|
|
40
|
+
}
|
|
41
|
+
/** The widest a `truncate` cell grows. */
|
|
42
|
+
const TRUNCATE_WIDTH = "max-w-xs";
|
|
43
|
+
/** Where a `truncate` cell's capped box sits, so it follows the cell's alignment. */
|
|
44
|
+
const TRUNCATE_ALIGN = {
|
|
45
|
+
start: undefined,
|
|
46
|
+
center: "mx-auto",
|
|
47
|
+
end: "ml-auto",
|
|
48
|
+
};
|
|
49
|
+
const INDENT = {
|
|
50
|
+
sm: { 1: "pl-8", 2: "pl-12", 3: "pl-16" },
|
|
51
|
+
md: { 1: "pl-9", 2: "pl-13", 3: "pl-17" },
|
|
52
|
+
lg: { 1: "pl-10", 2: "pl-14", 3: "pl-18" },
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A `<td>`. `tone` is the text weight and colour (see `CellTone`; in a `TableFoot` it defaults to
|
|
56
|
+
* `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
|
|
57
|
+
* numeric already), `mono` a small mono face. `secondary` is a second,
|
|
58
|
+
* muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
|
|
59
|
+
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver), a cell
|
|
60
|
+
* that holds a control or a link takes that content's width, and a `numeric` or `mono` cell (a
|
|
61
|
+
* figure, a code, a type) never breaks. `truncate` caps a long value's width, cuts it with
|
|
62
|
+
* an ellipsis on one line and puts the full text in a `title`; the content is then plain text (strings and
|
|
63
|
+
* numbers), since that is what the title shows. `colSpan` passes through: a cell that
|
|
64
|
+
* spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
|
|
65
|
+
* table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
|
|
66
|
+
* column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
|
|
67
|
+
* While `loading` an empty cell draws one bone, the width of a short value.
|
|
68
|
+
*/
|
|
69
|
+
export function TableCell({ span, colSpan, align, tone, numeric, mono = false, truncate = false, indent, secondary, loading, loadingLabel, children, ...rest }) {
|
|
70
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
71
|
+
const bone = waiting && isEmptySlot(children);
|
|
72
|
+
const foot = useContext(SectionContext) === "foot";
|
|
73
|
+
const { size, columns } = useContext(TableContext);
|
|
74
|
+
const column = useNumericColumn();
|
|
75
|
+
const figure = numeric ?? column;
|
|
76
|
+
const side = align ?? (figure ? "end" : "start");
|
|
77
|
+
return (_jsxs("td", { ...rest, ...busy(owner, waiting), colSpan: span === "full" ? columns : colSpan, className: cellClass({
|
|
78
|
+
align: side,
|
|
79
|
+
size,
|
|
80
|
+
indent,
|
|
81
|
+
tone,
|
|
82
|
+
foot,
|
|
83
|
+
numeric: figure,
|
|
84
|
+
mono,
|
|
85
|
+
prose: isProse(children),
|
|
86
|
+
}), children: [_jsx(CellBody, { align: side, truncate: truncate, secondary: secondary, children: bone ? _jsx(Bone, { shape: CELL_BONE }) : children }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
87
|
+
}
|
|
88
|
+
/** The classes of a cell: the tone (`strong` by default in a foot, and a foot's cells are medium whatever the tone), then the wrapping rule. */
|
|
89
|
+
function cellClass({ align, size, indent, tone, foot, numeric, mono, prose, }) {
|
|
90
|
+
const resolved = tone ?? (foot ? "strong" : "neutral");
|
|
91
|
+
return cx(PAD[size].cell, align === "start" && indent !== undefined && INDENT[size][indent], ALIGN[align], TONE[resolved], foot && resolved !== "strong" && "font-medium", figureClass(numeric, mono, prose));
|
|
92
|
+
}
|
|
93
|
+
const isText = (node) => typeof node === "string" || typeof node === "number";
|
|
94
|
+
/** Prose: at least one part, every one text. An empty cell (a bone) is not prose and keeps no width. */
|
|
95
|
+
function isProse(children) {
|
|
96
|
+
const parts = Children.toArray(children);
|
|
97
|
+
return parts.length > 0 && parts.every(isText);
|
|
98
|
+
}
|
|
99
|
+
/** What a cell holds: the content, cut to one line with its full text in a `title` when `truncate`, then the `secondary` line. */
|
|
100
|
+
function CellBody({ align, truncate, secondary, children, }) {
|
|
101
|
+
const parts = Children.toArray(children);
|
|
102
|
+
const text = parts.every(isText) ? parts.join("") : undefined;
|
|
103
|
+
return (_jsxs(_Fragment, { children: [truncate ? (_jsx("div", { className: cx(TRUNCATE_WIDTH, "truncate", TRUNCATE_ALIGN[align]), title: text, children: children })) : (children), secondary != null && secondary !== false && (_jsx("div", { className: "text-xs font-normal text-slate-500", children: secondary }))] }));
|
|
104
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ComponentProps, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { TableCell } from "./Table.js";
|
|
3
|
+
/** `TableCell`'s props without its content, kept a union so `span` and `colSpan` stay apart. */
|
|
4
|
+
type CellProps = ComponentProps<typeof TableCell> extends infer Props ? Props extends unknown ? Omit<Props, "children" | "truncate"> : never : never;
|
|
5
|
+
/**
|
|
6
|
+
* A `TableCell` whose value opens an editor in place: a cell that holds one `InlineEdit` and
|
|
7
|
+
* nothing else. It shows `children` as a button with a dotted underline; a click, Enter or Space
|
|
8
|
+
* swaps it for `renderEditor(close)` and moves the focus into the editor. The editor calls `close`
|
|
9
|
+
* when it has saved, and Esc closes it: both put the focus back on the value. A press outside it or
|
|
10
|
+
* Tab out of it closes it too and leaves the focus where it went, so the editor saves its value on
|
|
11
|
+
* its own change or submit, never on a close. Put the control in the cell itself, not in a popover
|
|
12
|
+
* of its own, which counts as outside. Takes `TableCell`'s `align`, `tone`, `numeric`, `mono`,
|
|
13
|
+
* `indent`, `secondary` and `span`. For an edit trigger in a cell that holds other content too, put an
|
|
14
|
+
* `InlineEdit` in a `TableCell`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function TableEditCell({ label, renderEditor, children, ...cell }: {
|
|
17
|
+
/** What the button does, for a screen reader, heard after the value: "Edit category". It also names the editor. */
|
|
18
|
+
label: string;
|
|
19
|
+
/**
|
|
20
|
+
* The control that edits the value, drawn while open. `close` shuts it and returns the focus to
|
|
21
|
+
* the value.
|
|
22
|
+
*
|
|
23
|
+
* Call `close` once the control has saved: a press outside the cell, Tab out of it and Esc all
|
|
24
|
+
* close it without a save, so save on the control's own change or submit. The control sits in the
|
|
25
|
+
* cell, not in a popover of its own.
|
|
26
|
+
*/
|
|
27
|
+
renderEditor: (close: () => void) => ReactNode;
|
|
28
|
+
/** The value, shown while closed. */
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
} & CellProps): ReactElement;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { InlineEdit } from "./InlineEdit.js";
|
|
3
|
+
import { TableCell } from "./Table.js";
|
|
4
|
+
/**
|
|
5
|
+
* A `TableCell` whose value opens an editor in place: a cell that holds one `InlineEdit` and
|
|
6
|
+
* nothing else. It shows `children` as a button with a dotted underline; a click, Enter or Space
|
|
7
|
+
* swaps it for `renderEditor(close)` and moves the focus into the editor. The editor calls `close`
|
|
8
|
+
* when it has saved, and Esc closes it: both put the focus back on the value. A press outside it or
|
|
9
|
+
* Tab out of it closes it too and leaves the focus where it went, so the editor saves its value on
|
|
10
|
+
* its own change or submit, never on a close. Put the control in the cell itself, not in a popover
|
|
11
|
+
* of its own, which counts as outside. Takes `TableCell`'s `align`, `tone`, `numeric`, `mono`,
|
|
12
|
+
* `indent`, `secondary` and `span`. For an edit trigger in a cell that holds other content too, put an
|
|
13
|
+
* `InlineEdit` in a `TableCell`.
|
|
14
|
+
*/
|
|
15
|
+
export function TableEditCell({ label, renderEditor, children, ...cell }) {
|
|
16
|
+
return (_jsx(TableCell, { ...cell, children: _jsx(InlineEdit, { label: label, renderEditor: renderEditor, children: children }) }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/**
|
|
4
|
+
* The cell that opens and closes the row it sits in: a small ghost button with a chevron that turns
|
|
5
|
+
* down when `expanded`, named by `label` (visually hidden) and, with a `count`, the count chip after
|
|
6
|
+
* it, so it reads "Details, 3". The app holds `expanded` and renders what opens under the row: a
|
|
7
|
+
* `TableRow` with one `TableCell span="full"`, or indented child rows. Give its column a head of
|
|
8
|
+
* `<TableHeaderCell label="Details" />`. `aria-controls` names what it opens; other props go on the
|
|
9
|
+
* `<td>`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function TableExpandCell({ expanded, label, count, onClick, "aria-controls": controls, ...rest }: {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the row is open.
|
|
14
|
+
*
|
|
15
|
+
* Hold it yourself and render what opens under the row: a `TableRow` with one `TableCell
|
|
16
|
+
* span="full"`, or indented child rows. Head the column `<TableHeaderCell label="Details" />`.
|
|
17
|
+
*/
|
|
18
|
+
expanded: boolean;
|
|
19
|
+
/** The button's name, visually hidden: "Details". */
|
|
20
|
+
label: string;
|
|
21
|
+
/** A count chip after the chevron: how many lines open under the row. */
|
|
22
|
+
count?: number | undefined;
|
|
23
|
+
/** Opens or closes the row: the app flips `expanded`. */
|
|
24
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
25
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "./Button.js";
|
|
3
|
+
import { Chevron } from "./Chevron.js";
|
|
4
|
+
import { TableCell } from "./TableCells.js";
|
|
5
|
+
/**
|
|
6
|
+
* The cell that opens and closes the row it sits in: a small ghost button with a chevron that turns
|
|
7
|
+
* down when `expanded`, named by `label` (visually hidden) and, with a `count`, the count chip after
|
|
8
|
+
* it, so it reads "Details, 3". The app holds `expanded` and renders what opens under the row: a
|
|
9
|
+
* `TableRow` with one `TableCell span="full"`, or indented child rows. Give its column a head of
|
|
10
|
+
* `<TableHeaderCell label="Details" />`. `aria-controls` names what it opens; other props go on the
|
|
11
|
+
* `<td>`.
|
|
12
|
+
*/
|
|
13
|
+
export function TableExpandCell({ expanded, label, count, onClick, "aria-controls": controls, ...rest }) {
|
|
14
|
+
return (_jsx(TableCell, { ...rest, children: _jsxs(Button, { variant: "ghost", size: "sm", "aria-expanded": expanded, "aria-controls": controls, count: count, onClick: onClick, children: [_jsx(Chevron, { open: expanded }), _jsx("span", { className: "sr-only", children: label })] }) }));
|
|
15
|
+
}
|