@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { FoldedColumn } from "./foldedColumn.js";
|
|
5
|
+
import { useWait } from "./layoutWait.js";
|
|
6
|
+
import { LoadingScope } from "./skeleton.js";
|
|
7
|
+
import { useScrollEdges } from "./scrollEdges.js";
|
|
8
|
+
import { scrollStopProps, useScrollStop } from "./scrollStop.js";
|
|
9
|
+
import { STICKY_ASIDE_MD, STICKY_BAR_MD, STICKY_FADE_MD, STICKY_INK_MD, STICKY_SCROLL_MD, } from "./stickyColumn.js";
|
|
10
|
+
/** The rail's current link: the one `Tabs` marks with `aria-current`. */
|
|
11
|
+
const CURRENT = '[aria-current]:not([aria-current="false"])';
|
|
12
|
+
/** The room the scroller's fade takes at each edge (`STICKY_FADE_MD`'s 1.5rem), in px. */
|
|
13
|
+
const FADE = 24;
|
|
14
|
+
/**
|
|
15
|
+
* Scrolls `scroller` (only it, never the page, which `scrollIntoView` would also move) so `item`
|
|
16
|
+
* sits in the middle of its visible part. Left alone when it is already clear of the faded edges, or
|
|
17
|
+
* when the scroller does not scroll (below `md`, or a rail that fits).
|
|
18
|
+
*/
|
|
19
|
+
function scrollToCentre(scroller, item) {
|
|
20
|
+
if (scroller.scrollHeight <= scroller.clientHeight)
|
|
21
|
+
return;
|
|
22
|
+
const box = scroller.getBoundingClientRect();
|
|
23
|
+
const at = item.getBoundingClientRect();
|
|
24
|
+
if (at.top >= box.top + FADE && at.bottom <= box.bottom - FADE)
|
|
25
|
+
return;
|
|
26
|
+
scroller.scrollTop += at.top + at.height / 2 - (box.top + box.height / 2);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An `aside` of links (the rail) beside the `children` canvas, in the Container the shell already gives every
|
|
30
|
+
* page (a plain `<AppShell>`, no `bleed`): the rail starts at the header logo's x and the canvas
|
|
31
|
+
* ends at the header's right edge. The rail has no background and no border, so it is a list of
|
|
32
|
+
* links on the page; a `Tabs orientation="vertical"` is its content. From `md` it is `w-56` with
|
|
33
|
+
* the canvas filling the rest, and it stays in view under the shell's header as a long page scrolls;
|
|
34
|
+
* a rail taller than the screen scrolls itself, so its last link is reachable. Below `md` it stacks
|
|
35
|
+
* above the canvas and nothing sticks. A long rail sets `asideLabel`:
|
|
36
|
+
* below `md` it then folds behind a disclosure of that name, closed, so the page comes first on a
|
|
37
|
+
* phone, and from `md` it is the same rail; `asideLabel` also names the rail's `<aside>` landmark.
|
|
38
|
+
* Once the page has
|
|
39
|
+
* loaded, a rail that scrolls shows its current link (the one with `aria-current`) in view, and the
|
|
40
|
+
* folded disclosure reads `asideLabel` and the current link's name ("All components: Button"); both
|
|
41
|
+
* need the layout to hydrate.
|
|
42
|
+
* While `loading` the canvas waits (the rail is navigation, drawn as itself) and the layout owns
|
|
43
|
+
* the wait.
|
|
44
|
+
*/
|
|
45
|
+
export function SidebarLayout({ aside, asideLabel, loading, loadingLabel, children, ...rest }) {
|
|
46
|
+
const wait = useWait(loading, loadingLabel);
|
|
47
|
+
const { element, attach, stop } = useScrollStop();
|
|
48
|
+
useScrollEdges(element, "y");
|
|
49
|
+
const [current, setCurrent] = useState(undefined);
|
|
50
|
+
const scrolledTo = useRef(null);
|
|
51
|
+
// The current link is scrolled into view once, and its name goes on the folded disclosure. It is
|
|
52
|
+
// read when the layout mounts and again whenever the rail's links change (a consumer's router
|
|
53
|
+
// moving `aria-current` to another link).
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!element)
|
|
56
|
+
return undefined;
|
|
57
|
+
const sync = () => {
|
|
58
|
+
const item = element.querySelector(CURRENT);
|
|
59
|
+
setCurrent(item?.textContent?.trim() || undefined);
|
|
60
|
+
if (item && item !== scrolledTo.current)
|
|
61
|
+
scrollToCentre(element, item);
|
|
62
|
+
scrolledTo.current = item;
|
|
63
|
+
};
|
|
64
|
+
queueMicrotask(sync);
|
|
65
|
+
const change = new MutationObserver(sync);
|
|
66
|
+
change.observe(element, {
|
|
67
|
+
childList: true,
|
|
68
|
+
subtree: true,
|
|
69
|
+
characterData: true,
|
|
70
|
+
attributes: true,
|
|
71
|
+
attributeFilter: ["aria-current"],
|
|
72
|
+
});
|
|
73
|
+
return () => change.disconnect();
|
|
74
|
+
}, [element]);
|
|
75
|
+
const { props, ring } = scrollStopProps(stop, { label: asideLabel });
|
|
76
|
+
return (_jsxs("div", { ...rest, ...wait.attrs, className: "flex flex-col gap-8 md:flex-row md:gap-10", children: [_jsx("aside", { className: cx("w-full shrink-0 md:w-56", STICKY_ASIDE_MD), "aria-label": asideLabel, children: _jsx("div", { ref: attach, ...props, className: cx(STICKY_SCROLL_MD, STICKY_BAR_MD, STICKY_FADE_MD, ring), children: _jsx("div", { className: STICKY_INK_MD, children: asideLabel === undefined ? (aside) : (_jsx(FoldedColumn, { from: "md", label: current === undefined ? asideLabel : `${asideLabel}: ${current}`, children: aside })) }) }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(LoadingScope, { loading: wait.loading, children: children }), wait.label] })] }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/** One link in a `SiteFooter`'s row: its words, where it goes, and whether it opens a new tab. */
|
|
4
|
+
export type SiteFooterLink = {
|
|
5
|
+
label: string;
|
|
6
|
+
href: string;
|
|
7
|
+
external?: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The footer a site puts in `AppShell`'s `footer` slot: the site's mark linked home with a contact
|
|
11
|
+
* line beside it, a row of the site's own links (Privacy, Terms, GitHub), then lines of fine print.
|
|
12
|
+
* It is not a `<footer>`: the shell draws the one `contentinfo` landmark around its slot. No link
|
|
13
|
+
* columns, newsletter form or social icons: a site footer is this and nothing else.
|
|
14
|
+
*/
|
|
15
|
+
export declare function SiteFooter({ brand, brandHref, brandLabel, links, notes, children, ...rest }: {
|
|
16
|
+
/** The site's mark (a wordmark, a logo), linked to `brandHref`. Left out, there is no brand. */
|
|
17
|
+
brand?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Where the brand links. Needs `brand`.
|
|
20
|
+
* @default "/"
|
|
21
|
+
*/
|
|
22
|
+
brandHref?: string | undefined;
|
|
23
|
+
/** Names the brand link for assistive tech ("PixelSlash home"). Needs `brand`. */
|
|
24
|
+
brandLabel?: string | undefined;
|
|
25
|
+
/** The site's own links (Privacy, Terms, GitHub, a mail address), one wrapping row. */
|
|
26
|
+
links?: SiteFooterLink[] | undefined;
|
|
27
|
+
/** Lines of fine print under the links (a licence, a trademark, a credit), one paragraph each. */
|
|
28
|
+
notes?: ReactNode[] | undefined;
|
|
29
|
+
/** A sentence at body size beside the brand: the contact line ("Email hello@..."). */
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Cluster } from "./Cluster.js";
|
|
3
|
+
import { cx, focusRing } from "./cx.js";
|
|
4
|
+
import { renderLink } from "./link.js";
|
|
5
|
+
import { MetaList } from "./MetaList.js";
|
|
6
|
+
import { Stack } from "./Stack.js";
|
|
7
|
+
import { TextLink } from "./TextLink.js";
|
|
8
|
+
import { Caption } from "./typography.js";
|
|
9
|
+
/**
|
|
10
|
+
* The footer a site puts in `AppShell`'s `footer` slot: the site's mark linked home with a contact
|
|
11
|
+
* line beside it, a row of the site's own links (Privacy, Terms, GitHub), then lines of fine print.
|
|
12
|
+
* It is not a `<footer>`: the shell draws the one `contentinfo` landmark around its slot. No link
|
|
13
|
+
* columns, newsletter form or social icons: a site footer is this and nothing else.
|
|
14
|
+
*/
|
|
15
|
+
export function SiteFooter({ brand, brandHref = "/", brandLabel, links = [], notes = [], children, ...rest }) {
|
|
16
|
+
const top = brand != null || children != null;
|
|
17
|
+
return (_jsxs(Stack, { ...rest, gap: "sm", children: [top && (_jsxs(Cluster, { gap: "md", children: [brand != null &&
|
|
18
|
+
renderLink({
|
|
19
|
+
href: brandHref,
|
|
20
|
+
"aria-label": brandLabel,
|
|
21
|
+
className: cx("rounded text-slate-900", focusRing),
|
|
22
|
+
children: brand,
|
|
23
|
+
}), children] })), links.length > 0 && (_jsx(MetaList, { children: links.map((link) => (_jsx(TextLink, { href: link.href, external: link.external, children: link.label }, `${link.label} ${link.href}`))) })), notes.map((note, index) => (_jsx(Caption, { children: note }, index)))] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/** One page the search can find. */
|
|
4
|
+
export type SiteSearchItem = {
|
|
5
|
+
/** The page's name: the row's label and the first thing matched. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** A muted line under the label, matched last. */
|
|
8
|
+
description?: string | undefined;
|
|
9
|
+
/** Where the row goes. */
|
|
10
|
+
href: string;
|
|
11
|
+
/** Other names the page answers to (the exports it documents), matched like the label but not shown. */
|
|
12
|
+
keywords?: string[] | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The items that match `text`, best first: the label starts with it, then the label contains it,
|
|
16
|
+
* then a keyword contains it, then the description does. Case is ignored, and items of the same
|
|
17
|
+
* rank keep their order in `items`. Empty text matches nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function rankSiteSearch(items: readonly SiteSearchItem[], text: string): SiteSearchItem[];
|
|
20
|
+
/**
|
|
21
|
+
* The site's search: a header button that opens a dialog with a search field over a list of links
|
|
22
|
+
* to the pages that match. Put it in `AppShell`'s `controls` and pass every page as `items`. Ctrl+K
|
|
23
|
+
* (⌘ K on a Mac) opens it from anywhere on the page, and the button shows that key. Typing filters
|
|
24
|
+
* by name, then by `keywords`, then by description; Enter opens the first result, the arrow keys
|
|
25
|
+
* move through them, and Esc closes it and puts focus back where it was. Render it once per page.
|
|
26
|
+
*/
|
|
27
|
+
export declare function SiteSearch({ items, label, resultsLabel, ...rest }: {
|
|
28
|
+
/** Every page to search, in the order ties are listed (the rail's order). */
|
|
29
|
+
items: readonly SiteSearchItem[];
|
|
30
|
+
/**
|
|
31
|
+
* The dialog's title and the phone's icon button's accessible name: "Search components". The wide
|
|
32
|
+
* button is named by its own text, "Search".
|
|
33
|
+
*/
|
|
34
|
+
label: string;
|
|
35
|
+
/**
|
|
36
|
+
* The name of the list of matches, for an app in another language.
|
|
37
|
+
* @default Results
|
|
38
|
+
*/
|
|
39
|
+
resultsLabel?: string | undefined;
|
|
40
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
|
|
3
|
+
import { Button } from "./Button.js";
|
|
4
|
+
import { Dialog } from "./Dialog.js";
|
|
5
|
+
import { Icon } from "./Icon.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { Input } from "./Input.js";
|
|
8
|
+
import { Kbd } from "./Kbd.js";
|
|
9
|
+
import { ListRow } from "./ListRow.js";
|
|
10
|
+
import { Text } from "./typography.js";
|
|
11
|
+
/**
|
|
12
|
+
* The items that match `text`, best first: the label starts with it, then the label contains it,
|
|
13
|
+
* then a keyword contains it, then the description does. Case is ignored, and items of the same
|
|
14
|
+
* rank keep their order in `items`. Empty text matches nothing.
|
|
15
|
+
*/
|
|
16
|
+
export function rankSiteSearch(items, text) {
|
|
17
|
+
const query = text.trim().toLowerCase();
|
|
18
|
+
if (query === "")
|
|
19
|
+
return [];
|
|
20
|
+
const rankOf = (item) => {
|
|
21
|
+
const label = item.label.toLowerCase();
|
|
22
|
+
if (label.startsWith(query))
|
|
23
|
+
return 0;
|
|
24
|
+
if (label.includes(query))
|
|
25
|
+
return 1;
|
|
26
|
+
if (item.keywords?.some((keyword) => keyword.toLowerCase().includes(query)))
|
|
27
|
+
return 2;
|
|
28
|
+
if (item.description?.toLowerCase().includes(query))
|
|
29
|
+
return 3;
|
|
30
|
+
return -1;
|
|
31
|
+
};
|
|
32
|
+
return items
|
|
33
|
+
.map((item, index) => ({ item, index, rank: rankOf(item) }))
|
|
34
|
+
.filter((entry) => entry.rank >= 0)
|
|
35
|
+
.toSorted((a, b) => a.rank - b.rank || a.index - b.index)
|
|
36
|
+
.map((entry) => entry.item);
|
|
37
|
+
}
|
|
38
|
+
/** What the live region says for a result count. */
|
|
39
|
+
function countText(query, count) {
|
|
40
|
+
if (query.trim() === "")
|
|
41
|
+
return "";
|
|
42
|
+
if (count === 0)
|
|
43
|
+
return "No results";
|
|
44
|
+
return count === 1 ? "1 result" : `${count} results`;
|
|
45
|
+
}
|
|
46
|
+
// The shortcut's key reads ⌘ K on Apple platforms. The server cannot know, so it renders Ctrl K and
|
|
47
|
+
// the client swaps after hydration.
|
|
48
|
+
const noSubscribe = () => () => { };
|
|
49
|
+
const isApple = () => /mac|iphone|ipad|ipod/i.test(typeof navigator === "undefined" ? "" : navigator.userAgent);
|
|
50
|
+
/** Ctrl+K or Cmd+K with no other modifier, the one shortcut that opens the search. */
|
|
51
|
+
function isShortcut(event) {
|
|
52
|
+
return ((event.ctrlKey || event.metaKey) &&
|
|
53
|
+
!event.altKey &&
|
|
54
|
+
!event.shiftKey &&
|
|
55
|
+
event.key.toLowerCase() === "k");
|
|
56
|
+
}
|
|
57
|
+
// A link that stays on the page (a hash, an app's router) still closes the search; one opened in a
|
|
58
|
+
// new tab or window leaves it open.
|
|
59
|
+
function onListClick(event) {
|
|
60
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey)
|
|
61
|
+
return;
|
|
62
|
+
if (event.target instanceof Element && event.target.closest("a[href]")) {
|
|
63
|
+
event.currentTarget.closest("dialog")?.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The result links in the list, in order. */
|
|
67
|
+
function linksIn(list) {
|
|
68
|
+
return list ? [...list.querySelectorAll("a[href]")] : [];
|
|
69
|
+
}
|
|
70
|
+
function SearchBody({ items, label, resultsLabel, }) {
|
|
71
|
+
const [query, setQuery] = useState("");
|
|
72
|
+
const box = useRef(null);
|
|
73
|
+
const list = useRef(null);
|
|
74
|
+
const results = rankSiteSearch(items, query);
|
|
75
|
+
const typed = query.trim() !== "";
|
|
76
|
+
const onFieldKey = (event) => {
|
|
77
|
+
if (event.key === "Escape") {
|
|
78
|
+
// Close here, so no engine spends the first Esc clearing the search field.
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
event.currentTarget.closest("dialog")?.close();
|
|
81
|
+
}
|
|
82
|
+
else if (event.key === "Enter") {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
linksIn(list.current)[0]?.click();
|
|
85
|
+
}
|
|
86
|
+
else if (event.key === "ArrowDown") {
|
|
87
|
+
const first = linksIn(list.current)[0];
|
|
88
|
+
if (first) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
first.focus();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const onListKey = (event) => {
|
|
95
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
|
|
96
|
+
return;
|
|
97
|
+
const links = linksIn(list.current);
|
|
98
|
+
const at = links.findIndex((link) => link === document.activeElement);
|
|
99
|
+
if (at < 0)
|
|
100
|
+
return;
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
const next = at + (event.key === "ArrowDown" ? 1 : -1);
|
|
103
|
+
if (next < 0)
|
|
104
|
+
box.current?.querySelector("input")?.focus();
|
|
105
|
+
else
|
|
106
|
+
links[Math.min(next, links.length - 1)]?.focus();
|
|
107
|
+
};
|
|
108
|
+
return (_jsxs("div", { ref: box, className: "flex flex-col gap-3", children: [_jsx(Input, { type: "search", icon: "search", "aria-label": label, placeholder: "Search", autoComplete: "off", spellCheck: false, value: query, onChange: (event) => setQuery(event.target.value), onKeyDown: onFieldKey }), _jsx("div", { role: "status", "aria-live": "polite", className: "sr-only", children: countText(query, results.length) }), !typed && _jsx(Text, { tone: "muted", children: "Type a name" }), typed && results.length === 0 && _jsxs(Text, { tone: "muted", children: ["No results for ", query.trim()] }), results.length > 0 && (_jsx("ul", { ref: list, "aria-label": resultsLabel, onKeyDown: onListKey, onClick: onListClick, children: results.map((item, index) => (_jsx("li", { children: _jsx(ListRow, { href: item.href, size: "sm", divided: index > 0, secondary: item.description, children: item.label }) }, item.href))) }))] }));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The site's search: a header button that opens a dialog with a search field over a list of links
|
|
112
|
+
* to the pages that match. Put it in `AppShell`'s `controls` and pass every page as `items`. Ctrl+K
|
|
113
|
+
* (⌘ K on a Mac) opens it from anywhere on the page, and the button shows that key. Typing filters
|
|
114
|
+
* by name, then by `keywords`, then by description; Enter opens the first result, the arrow keys
|
|
115
|
+
* move through them, and Esc closes it and puts focus back where it was. Render it once per page.
|
|
116
|
+
*/
|
|
117
|
+
export function SiteSearch({ items, label, resultsLabel = "Results", ...rest }) {
|
|
118
|
+
const [open, setOpen] = useState(false);
|
|
119
|
+
const opener = useRef(null);
|
|
120
|
+
const apple = useSyncExternalStore(noSubscribe, isApple, () => false);
|
|
121
|
+
const keys = apple ? "⌘ K" : "Ctrl K";
|
|
122
|
+
// Before paint, so a client-rendered trigger that is on screen already answers the shortcut.
|
|
123
|
+
useLayoutEffect(() => {
|
|
124
|
+
const onKey = (event) => {
|
|
125
|
+
if (event.defaultPrevented || event.repeat || !isShortcut(event))
|
|
126
|
+
return;
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
// Only the press that opens it records the opener; `close` clears it.
|
|
129
|
+
if (!opener.current && document.activeElement instanceof HTMLElement) {
|
|
130
|
+
opener.current = document.activeElement;
|
|
131
|
+
}
|
|
132
|
+
setOpen(true);
|
|
133
|
+
};
|
|
134
|
+
window.addEventListener("keydown", onKey);
|
|
135
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
136
|
+
}, []);
|
|
137
|
+
// A pointer click does not focus a button in every engine, so the trigger is remembered by hand.
|
|
138
|
+
const openFrom = (event) => {
|
|
139
|
+
opener.current = event.currentTarget;
|
|
140
|
+
setOpen(true);
|
|
141
|
+
};
|
|
142
|
+
const close = () => {
|
|
143
|
+
setOpen(false);
|
|
144
|
+
const back = opener.current;
|
|
145
|
+
opener.current = null;
|
|
146
|
+
if (back?.isConnected && back !== document.body)
|
|
147
|
+
back.focus();
|
|
148
|
+
};
|
|
149
|
+
return (_jsxs("span", { ...rest, className: "inline-flex", children: [_jsx("span", { className: "hidden sm:inline-flex", children: _jsxs(Button, { variant: "outline", size: "sm", "aria-haspopup": "dialog", "aria-keyshortcuts": "Control+K Meta+K", onClick: openFrom, children: [_jsx(Icon, { name: "search", size: "sm" }), "Search", _jsx(Kbd, { "aria-hidden": "true", children: keys })] }) }), _jsx("span", { className: "inline-flex sm:hidden", children: _jsx(IconButton, { label: label, size: "sm", "aria-haspopup": "dialog", "aria-keyshortcuts": "Control+K Meta+K", onClick: openFrom, icon: "search" }) }), open && (_jsx(Dialog, { title: label, width: "md", onClose: close, children: _jsx(SearchBody, { items: items, label: label, resultsLabel: resultsLabel }) }))] }));
|
|
150
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import { type DropTarget, type Key } from "react-aria-components";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
/** A move the user made: which item, the section it lands in, and the item it lands next to. */
|
|
5
|
+
export type SortableMove = {
|
|
6
|
+
/** The `id` of the item that moved. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** The `id` of the `SortableSection` the item lands in. Set whenever the list has sections. */
|
|
9
|
+
section?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The item it was dropped before or after. Absent only for a drop into an empty section, where
|
|
12
|
+
* there is no item to land next to.
|
|
13
|
+
*/
|
|
14
|
+
target?: {
|
|
15
|
+
id: string;
|
|
16
|
+
position: "before" | "after";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** What a part takes through to its element: `id`, `data-*` and `aria-*`, as every component does. */
|
|
20
|
+
type Through = Passthrough;
|
|
21
|
+
/** A row's section and title; a tail row also lists its section's items, in order. */
|
|
22
|
+
type Place = {
|
|
23
|
+
section?: string;
|
|
24
|
+
title: string;
|
|
25
|
+
tail?: string[];
|
|
26
|
+
};
|
|
27
|
+
/** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
|
|
28
|
+
export declare function dropOperation(target: DropTarget): "move" | "cancel";
|
|
29
|
+
/**
|
|
30
|
+
* The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
|
|
31
|
+
* on a row's centre, or next to the item itself). A drop at a section's tail lands after the
|
|
32
|
+
* section's last other item, or with no target when it has none.
|
|
33
|
+
*/
|
|
34
|
+
export declare function moveOf(places: Map<string, Place>, keys: Iterable<Key>, target: DropTarget): SortableMove | null;
|
|
35
|
+
/**
|
|
36
|
+
* A list the user puts in order: items under section headings, moved by dragging a row or from the
|
|
37
|
+
* keyboard (each row's grip handle, Enter, the arrow keys, Enter to drop, Escape to cancel). A drop
|
|
38
|
+
* reports `onReorder` with the item, the section it lands in and the item it lands next to; the app
|
|
39
|
+
* applies it to its own data. The list never reorders itself: it shows what its children say.
|
|
40
|
+
*
|
|
41
|
+
* Its children are `SortableSection`s, or `SortableItem`s directly for a list with no sections, each
|
|
42
|
+
* a direct child (map your data straight to them). Moving an item into another section is how the
|
|
43
|
+
* app changes its group, such as a ticket's priority. Two lists on one page never take each other's
|
|
44
|
+
* items.
|
|
45
|
+
*/
|
|
46
|
+
export declare function SortableList({ label, onReorder, children, ...rest }: {
|
|
47
|
+
/** The list's accessible name, read by a screen reader. */
|
|
48
|
+
label: string;
|
|
49
|
+
/** Called once per drop with the move; apply it to your data. */
|
|
50
|
+
onReorder: (move: SortableMove) => void;
|
|
51
|
+
/** `SortableSection`s, or `SortableItem`s for a list with no sections. */
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
} & Through): ReactElement;
|
|
54
|
+
type SortableSectionProps = {
|
|
55
|
+
/** The section's id, reported as `section` in a move that lands in it. */
|
|
56
|
+
id: string;
|
|
57
|
+
/** The heading over its items. */
|
|
58
|
+
title: string;
|
|
59
|
+
/** Its `SortableItem`s, each a direct child. With none it shows a quiet `emptyLabel` row. */
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
/**
|
|
62
|
+
* The quiet row an empty section shows, where a drop lands.
|
|
63
|
+
* @default Drop here
|
|
64
|
+
*/
|
|
65
|
+
emptyLabel?: string | undefined;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* One group of a `SortableList` under a heading that shows its title and how many items it holds.
|
|
69
|
+
* An empty section still takes a drop: it shows a quiet "Drop here" row in place of items.
|
|
70
|
+
*/
|
|
71
|
+
export declare function SortableSection({ id, title, children, emptyLabel, ...rest }: SortableSectionProps & Through): ReactElement;
|
|
72
|
+
type SortableItemProps = {
|
|
73
|
+
/** The item's id, reported in a move. */
|
|
74
|
+
id: string;
|
|
75
|
+
/** Its one line; also what a screen reader announces while it is dragged. */
|
|
76
|
+
title: string;
|
|
77
|
+
/** A meta line under the title: `Pill`s, an `Avatar`. */
|
|
78
|
+
children?: ReactNode;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* One row of a `SortableList`: a grip handle, the title, and an optional meta line under it. A
|
|
82
|
+
* pointer drags the row itself; the handle ("Reorder <title>") is how a keyboard or screen reader
|
|
83
|
+
* starts a move.
|
|
84
|
+
*/
|
|
85
|
+
export declare function SortableItem({ id, title, children, ...rest }: SortableItemProps & Through): ReactElement;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement, useId, useMemo, } from "react";
|
|
3
|
+
import { Button, DropIndicator, GridList, GridListHeader, GridListItem, GridListSection, useDragAndDrop, } from "react-aria-components";
|
|
4
|
+
import { cx, focusRing } from "./cx.js";
|
|
5
|
+
import { dataAttributes } from "./link.js";
|
|
6
|
+
/** The list's box: the Card's border, fill and shadow, clipped to its radius. */
|
|
7
|
+
const FRAME = "w-full overflow-hidden rounded-xl border border-slate-200/70 bg-white shadow-sm outline-none";
|
|
8
|
+
/**
|
|
9
|
+
* A hairline above every row that follows another row (an item, a heading, a drop line), so the
|
|
10
|
+
* first row of the list sits flush under the frame's own border. The line's colour is set apart.
|
|
11
|
+
*/
|
|
12
|
+
const AFTER_ROW = "border-slate-200/70 [[role=row]+&]:border-t";
|
|
13
|
+
/** A section after another section gets the same hairline above its heading. */
|
|
14
|
+
const AFTER_SECTION = "border-slate-200/70 [[role=rowgroup]+&]:border-t";
|
|
15
|
+
const HEADING = "flex items-center justify-between gap-3 bg-slate-50 px-4 py-2 text-xs font-medium tracking-wide text-slate-600 uppercase";
|
|
16
|
+
const ITEM = "flex w-full cursor-grab items-center gap-3 px-4 py-3 text-left text-sm text-slate-900 outline-none hover:bg-slate-50";
|
|
17
|
+
/** The keyboard cursor: the focus ring, drawn inside the row. */
|
|
18
|
+
const ITEM_FOCUSED = "outline-2 -outline-offset-2 outline-violet-600";
|
|
19
|
+
/** An empty section's "Drop here" row. */
|
|
20
|
+
const PLACEHOLDER = "px-4 py-3 text-sm text-slate-500 outline-none";
|
|
21
|
+
/** The tail row of a section with items: takes no room and shows nothing but the drop line. */
|
|
22
|
+
const TAIL = "h-0 overflow-hidden outline-none";
|
|
23
|
+
/** A marker on every row a pointer can drop next to: the items and each section's tail row. */
|
|
24
|
+
const ROW_MARK = "data-sortable-row";
|
|
25
|
+
/**
|
|
26
|
+
* react-aria drops an `aria-describedby` or `aria-details` it is handed on a row or a section, and
|
|
27
|
+
* sets its own describedby on a row. This draws the element with both: its own ids and the app's.
|
|
28
|
+
*/
|
|
29
|
+
function describedBy({ "aria-describedby": described, "aria-details": details, id: _own, ...through }, id) {
|
|
30
|
+
// react-aria passes `data-*` on; every other `aria-*` goes on the element it draws.
|
|
31
|
+
const aria = Object.fromEntries(Object.entries(through).filter(([key]) => key.startsWith("aria-")));
|
|
32
|
+
return {
|
|
33
|
+
...dataAttributes(through),
|
|
34
|
+
render: (props) => (_jsx("div", { ...props, ...aria, id: id ?? props.id, "aria-describedby": [props["aria-describedby"], described].filter(Boolean).join(" ") || undefined, "aria-details": details ?? props["aria-details"] })),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The key of a section's tail row. Every section ends with one: in an empty section it is the "Drop
|
|
39
|
+
* here" row, in one with items it is an empty row of no height. A drop before it is a drop at the
|
|
40
|
+
* end of the section. react-aria's keyboard drop moves cannot step from "after the last item" of a
|
|
41
|
+
* section into the next one (it wraps to the top), but they do step from "before" a row to "before"
|
|
42
|
+
* the next row across sections, so with a tail row the end of each section is a "before" target.
|
|
43
|
+
*/
|
|
44
|
+
function tailKey(section) {
|
|
45
|
+
return `hackcove-sortable-end:${section}`;
|
|
46
|
+
}
|
|
47
|
+
/** The `SortableItem` children of a section, the ones its count counts. */
|
|
48
|
+
function itemsOf(children) {
|
|
49
|
+
return Children.toArray(children).filter((child) => isValidElement(child) && child.type === SortableItem);
|
|
50
|
+
}
|
|
51
|
+
/** Every row's key mapped to its section (and, for a tail row, the section's items), read from the children. */
|
|
52
|
+
function placesOf(children) {
|
|
53
|
+
const places = new Map();
|
|
54
|
+
for (const child of Children.toArray(children)) {
|
|
55
|
+
if (isValidElement(child) && child.type === SortableItem) {
|
|
56
|
+
const { id, title } = child.props;
|
|
57
|
+
places.set(id, { title });
|
|
58
|
+
}
|
|
59
|
+
else if (isValidElement(child) && child.type === SortableSection) {
|
|
60
|
+
const { id: section, children: items } = child.props;
|
|
61
|
+
const own = itemsOf(items);
|
|
62
|
+
for (const item of own)
|
|
63
|
+
places.set(item.props.id, { section, title: item.props.title });
|
|
64
|
+
places.set(tailKey(section), { section, title: "", tail: own.map((item) => item.props.id) });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return places;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Where a pointer drops: before or after the row it is over, by which half it is in. Over a section
|
|
71
|
+
* heading, or in a gap, it is before the next row below (the first item of that section, or its
|
|
72
|
+
* "Drop here" row), and below every row it is after the last. Never "on" a row.
|
|
73
|
+
*/
|
|
74
|
+
function dropTargetAt(list, y) {
|
|
75
|
+
if (!list)
|
|
76
|
+
return null;
|
|
77
|
+
const top = y + list.getBoundingClientRect().top;
|
|
78
|
+
const rows = [...list.querySelectorAll(`[${ROW_MARK}]`)];
|
|
79
|
+
for (const row of rows) {
|
|
80
|
+
const key = row.dataset.key;
|
|
81
|
+
if (key == null)
|
|
82
|
+
continue;
|
|
83
|
+
const box = row.getBoundingClientRect();
|
|
84
|
+
if (top < box.top)
|
|
85
|
+
return { type: "item", key, dropPosition: "before" };
|
|
86
|
+
if (top <= box.bottom) {
|
|
87
|
+
return {
|
|
88
|
+
type: "item",
|
|
89
|
+
key,
|
|
90
|
+
dropPosition: top < box.top + box.height / 2 ? "before" : "after",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const last = rows.at(-1)?.dataset.key;
|
|
95
|
+
return last == null ? null : { type: "item", key: last, dropPosition: "after" };
|
|
96
|
+
}
|
|
97
|
+
/** react-aria's pointer drop delegate, aware of sections (the stock one sees only top-level items). */
|
|
98
|
+
function sectionDelegate(listId) {
|
|
99
|
+
return {
|
|
100
|
+
getDropTargetFromPoint: (_x, y) => dropTargetAt(document.getElementById(listId), y),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
|
|
104
|
+
export function dropOperation(target) {
|
|
105
|
+
return target.type === "item" && target.dropPosition !== "on" ? "move" : "cancel";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
|
|
109
|
+
* on a row's centre, or next to the item itself). A drop at a section's tail lands after the
|
|
110
|
+
* section's last other item, or with no target when it has none.
|
|
111
|
+
*/
|
|
112
|
+
export function moveOf(places, keys, target) {
|
|
113
|
+
const [key] = keys;
|
|
114
|
+
if (key == null || target.type !== "item" || target.dropPosition === "on")
|
|
115
|
+
return null;
|
|
116
|
+
const place = places.get(String(target.key));
|
|
117
|
+
if (!place)
|
|
118
|
+
return null;
|
|
119
|
+
const id = String(key);
|
|
120
|
+
if (String(target.key) === id)
|
|
121
|
+
return null;
|
|
122
|
+
const section = place.section === undefined ? {} : { section: place.section };
|
|
123
|
+
if (place.tail) {
|
|
124
|
+
const last = place.tail.filter((item) => item !== id).at(-1);
|
|
125
|
+
return last === undefined
|
|
126
|
+
? { id, ...section }
|
|
127
|
+
: { id, ...section, target: { id: last, position: "after" } };
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
id,
|
|
131
|
+
...section,
|
|
132
|
+
target: { id: String(target.key), position: target.dropPosition },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A list the user puts in order: items under section headings, moved by dragging a row or from the
|
|
137
|
+
* keyboard (each row's grip handle, Enter, the arrow keys, Enter to drop, Escape to cancel). A drop
|
|
138
|
+
* reports `onReorder` with the item, the section it lands in and the item it lands next to; the app
|
|
139
|
+
* applies it to its own data. The list never reorders itself: it shows what its children say.
|
|
140
|
+
*
|
|
141
|
+
* Its children are `SortableSection`s, or `SortableItem`s directly for a list with no sections, each
|
|
142
|
+
* a direct child (map your data straight to them). Moving an item into another section is how the
|
|
143
|
+
* app changes its group, such as a ticket's priority. Two lists on one page never take each other's
|
|
144
|
+
* items.
|
|
145
|
+
*/
|
|
146
|
+
export function SortableList({ label, onReorder, children, ...rest }) {
|
|
147
|
+
const ownId = useId();
|
|
148
|
+
const { id, ...through } = rest;
|
|
149
|
+
const listId = id ?? ownId;
|
|
150
|
+
const dragType = `application/x-hackcove-sortable-${useId()
|
|
151
|
+
.replace(/[^a-z0-9]/gi, "")
|
|
152
|
+
.toLowerCase()}`;
|
|
153
|
+
const places = placesOf(children);
|
|
154
|
+
const delegate = useMemo(() => sectionDelegate(listId), [listId]);
|
|
155
|
+
const { dragAndDropHooks } = useDragAndDrop({
|
|
156
|
+
getItems: (keys) => [...keys].map((key) => ({
|
|
157
|
+
"text/plain": places.get(String(key))?.title ?? String(key),
|
|
158
|
+
[dragType]: String(key),
|
|
159
|
+
})),
|
|
160
|
+
acceptedDragTypes: [dragType],
|
|
161
|
+
getDropOperation: dropOperation,
|
|
162
|
+
dropTargetDelegate: delegate,
|
|
163
|
+
onMove: (e) => {
|
|
164
|
+
const move = moveOf(places, e.keys, e.target);
|
|
165
|
+
if (move)
|
|
166
|
+
onReorder(move);
|
|
167
|
+
},
|
|
168
|
+
renderDropIndicator: (target) => (_jsx(DropIndicator, { target: target, className: "relative h-0 outline-none", children: ({ isDropTarget }) => (_jsx("span", { "aria-hidden": "true", className: cx("absolute inset-x-0 -top-px z-10 block h-0.5", isDropTarget && "bg-violet-600") })) })),
|
|
169
|
+
});
|
|
170
|
+
return (_jsx(GridList, { ...describedBy(through, listId), id: listId, "aria-label": label, dragAndDropHooks: dragAndDropHooks, disabledBehavior: "all", className: FRAME, children: children }));
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* One group of a `SortableList` under a heading that shows its title and how many items it holds.
|
|
174
|
+
* An empty section still takes a drop: it shows a quiet "Drop here" row in place of items.
|
|
175
|
+
*/
|
|
176
|
+
export function SortableSection({ id, title, children, emptyLabel = "Drop here", ...rest }) {
|
|
177
|
+
const count = itemsOf(children).length;
|
|
178
|
+
return (_jsxs(GridListSection, { ...describedBy(rest),
|
|
179
|
+
// Sections and items share react-aria's key space; this keeps a section id from colliding with an item's.
|
|
180
|
+
id: `hackcove-sortable-section:${id}`, "aria-label": title, className: AFTER_SECTION, children: [_jsxs(GridListHeader, { className: HEADING, children: [_jsx("span", { children: title }), _jsx("span", { className: "tabular-nums text-slate-500", children: count })] }), children, _jsxs(GridListItem, { id: tailKey(id), textValue: count > 0 ? `End of ${title}` : emptyLabel, isDisabled: true, [ROW_MARK]: "", className: count > 0 ? TAIL : cx(PLACEHOLDER, AFTER_ROW), children: [_jsx(Button, { slot: "drag", className: "hidden" }), count === 0 && emptyLabel] })] }));
|
|
181
|
+
}
|
|
182
|
+
/** The six-dot grip on each row's handle. */
|
|
183
|
+
const GRIP = (_jsxs("svg", { viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": "true", className: "h-4 w-4", children: [_jsx("circle", { cx: "6", cy: "4", r: "1.25" }), _jsx("circle", { cx: "10", cy: "4", r: "1.25" }), _jsx("circle", { cx: "6", cy: "8", r: "1.25" }), _jsx("circle", { cx: "10", cy: "8", r: "1.25" }), _jsx("circle", { cx: "6", cy: "12", r: "1.25" }), _jsx("circle", { cx: "10", cy: "12", r: "1.25" })] }));
|
|
184
|
+
/**
|
|
185
|
+
* One row of a `SortableList`: a grip handle, the title, and an optional meta line under it. A
|
|
186
|
+
* pointer drags the row itself; the handle ("Reorder <title>") is how a keyboard or screen reader
|
|
187
|
+
* starts a move.
|
|
188
|
+
*/
|
|
189
|
+
export function SortableItem({ id, title, children, ...rest }) {
|
|
190
|
+
return (_jsxs(GridListItem, { ...describedBy(rest), id: id, textValue: title, [ROW_MARK]: "", className: ({ isFocusVisible, isDragging }) => cx(ITEM, AFTER_ROW, isFocusVisible && ITEM_FOCUSED, isDragging && "opacity-50"), children: [_jsx(Button, { slot: "drag", "aria-label": `Reorder ${title}`, className: cx("shrink-0 rounded p-0.5 text-slate-400", focusRing), children: GRIP }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "truncate", children: title }), children != null && (_jsx("div", { className: "mt-1 flex flex-wrap items-center gap-2 text-xs text-slate-500", children: children }))] })] }));
|
|
191
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type BarSize, type BarTone } from "./ProgressBar.js";
|
|
3
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
|
+
import type { Passthrough } from "./props.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 declare function SplitBar({ a, b, label, names, toneA, toneB, size, loading, loadingLabel, ...rest }: {
|
|
12
|
+
/** The left party's amount; its share is `a` over `a + b`. */
|
|
13
|
+
a: number;
|
|
14
|
+
/** The right party's amount; its share is `b` over `a + b`. */
|
|
15
|
+
b: number;
|
|
16
|
+
/** What the split is, for a screen reader, which hears it before both percentages. */
|
|
17
|
+
label: string;
|
|
18
|
+
/** The left and right parties, spoken before their percentages. */
|
|
19
|
+
names?: readonly [string, string];
|
|
20
|
+
/** The left part's colour, by what it means (`accent`, `positive`, `warn` or `danger`). Defaults to "danger". */
|
|
21
|
+
toneA?: BarTone;
|
|
22
|
+
/** The right part's colour, by what it means (`accent`, `positive`, `warn` or `danger`). Defaults to "positive". */
|
|
23
|
+
toneB?: BarTone;
|
|
24
|
+
/**
|
|
25
|
+
* The bar's height: `sm` 6px, `md` 8px, `lg` 12px.
|
|
26
|
+
* @default md
|
|
27
|
+
*/
|
|
28
|
+
size?: BarSize;
|
|
29
|
+
} & LoadingProps & Passthrough): ReactElement;
|