@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,45 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/** The cross glyph on a 20px grid; `MediaTile`'s remove button draws the same one. */
|
|
4
|
+
export declare const CLOSE = "M5.28 4.22a.75.75 0 0 0-1.06 1.06L8.94 10l-4.72 4.72a.75.75 0 1 0 1.06 1.06L10 11.06l4.72 4.72a.75.75 0 1 0 1.06-1.06L11.06 10l4.72-4.72a.75.75 0 0 0-1.06-1.06L10 8.94 5.28 4.22Z";
|
|
5
|
+
export type LightboxProps = {
|
|
6
|
+
/** The viewer's accessible name, e.g. "Photo from Anna". */
|
|
7
|
+
label: string;
|
|
8
|
+
/** The media: one `<img>` or `<video>`, scaled down to fit the screen. */
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
/** A line on the scrim above the media, e.g. who posted it. */
|
|
11
|
+
title?: ReactNode;
|
|
12
|
+
/** A muted line under the title, e.g. when. */
|
|
13
|
+
meta?: ReactNode;
|
|
14
|
+
/** Muted text on the scrim under the media. */
|
|
15
|
+
caption?: ReactNode;
|
|
16
|
+
/** Called when the viewer closes: Esc, a click on the scrim or the close button. */
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
/** Shows a previous button and binds ArrowLeft. Leave it out at the first item. */
|
|
19
|
+
onPrevious?: (() => void) | undefined;
|
|
20
|
+
/** Shows a next button and binds ArrowRight. Leave it out at the last item. */
|
|
21
|
+
onNext?: (() => void) | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The close button's name, for an app in another language.
|
|
24
|
+
* @default Close
|
|
25
|
+
*/
|
|
26
|
+
closeLabel?: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The previous button's name.
|
|
29
|
+
* @default Previous
|
|
30
|
+
*/
|
|
31
|
+
previousLabel?: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The next button's name.
|
|
34
|
+
* @default Next
|
|
35
|
+
*/
|
|
36
|
+
nextLabel?: string | undefined;
|
|
37
|
+
} & Passthrough;
|
|
38
|
+
/**
|
|
39
|
+
* A full-screen photo or video viewer on the browser's own `<dialog>`: it is opened with
|
|
40
|
+
* `showModal()` on mount, so render it only while it is open. The page behind goes inert, Esc
|
|
41
|
+
* closes it and focus stays inside; a click on the scrim around the media and its text closes it
|
|
42
|
+
* too. The scrim stays near-black with light text in every theme. `onPrevious` and `onNext` add
|
|
43
|
+
* step buttons and the arrow keys.
|
|
44
|
+
*/
|
|
45
|
+
export declare function Lightbox({ label, children, title, meta, caption, onClose, onPrevious, onNext, closeLabel, previousLabel, nextLabel, ...rest }: LightboxProps): ReactElement;
|
package/dist/Lightbox.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, } from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { useModal } from "./modal.js";
|
|
5
|
+
import { Tipped } from "./Tooltip.js";
|
|
6
|
+
/**
|
|
7
|
+
* The full-screen viewer, painted with its own scrim: `bg-black/90` and the light text on it are the
|
|
8
|
+
* palette's media-scrim role, which every theme keeps near-black, light themes included.
|
|
9
|
+
*/
|
|
10
|
+
const VIEWER = "fixed inset-0 m-0 size-full max-h-none max-w-none flex-col border-0 bg-black/90 p-0 text-white opacity-0 transition-[opacity,overlay,display] transition-discrete duration-200 open:flex open:opacity-100 starting:open:opacity-0 motion-reduce:transition-none";
|
|
11
|
+
/** A round control on the scrim, with a light focus ring: the accent is too dark on near-black in a light theme. */
|
|
12
|
+
const CONTROL = "inline-flex size-11 shrink-0 items-center justify-center rounded-full text-white transition hover:bg-white/10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white";
|
|
13
|
+
/** The cross glyph on a 20px grid; `MediaTile`'s remove button draws the same one. */
|
|
14
|
+
export const CLOSE = "M5.28 4.22a.75.75 0 0 0-1.06 1.06L8.94 10l-4.72 4.72a.75.75 0 1 0 1.06 1.06L10 11.06l4.72 4.72a.75.75 0 1 0 1.06-1.06L11.06 10l4.72-4.72a.75.75 0 0 0-1.06-1.06L10 8.94 5.28 4.22Z";
|
|
15
|
+
const PREVIOUS = "M12.78 4.22a.75.75 0 0 1 0 1.06L8.06 10l4.72 4.72a.75.75 0 1 1-1.06 1.06l-5.25-5.25a.75.75 0 0 1 0-1.06l5.25-5.25a.75.75 0 0 1 1.06 0Z";
|
|
16
|
+
const NEXT = "M7.22 4.22a.75.75 0 0 1 1.06 0l5.25 5.25a.75.75 0 0 1 0 1.06l-5.25 5.25a.75.75 0 1 1-1.06-1.06L11.94 10 7.22 5.28a.75.75 0 0 1 0-1.06Z";
|
|
17
|
+
/** A round icon button on the scrim, named by `label`, which is also its tooltip. */
|
|
18
|
+
function ScrimButton({ label, path, onClick, }) {
|
|
19
|
+
return (_jsx(Tipped, { text: label, describes: false, own: {}, children: (tip) => (_jsx("button", { type: "button", "aria-label": label, ...tip, onClick: onClick, className: CONTROL, children: _jsx(Icon, { children: _jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", children: _jsx("path", { d: path }) }) }) })) }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A full-screen photo or video viewer on the browser's own `<dialog>`: it is opened with
|
|
23
|
+
* `showModal()` on mount, so render it only while it is open. The page behind goes inert, Esc
|
|
24
|
+
* closes it and focus stays inside; a click on the scrim around the media and its text closes it
|
|
25
|
+
* too. The scrim stays near-black with light text in every theme. `onPrevious` and `onNext` add
|
|
26
|
+
* step buttons and the arrow keys.
|
|
27
|
+
*/
|
|
28
|
+
export function Lightbox({ label, children, title, meta, caption, onClose, onPrevious, onNext, closeLabel = "Close", previousLabel = "Previous", nextLabel = "Next", ...rest }) {
|
|
29
|
+
const dialog = useRef(null);
|
|
30
|
+
const closed = useModal(dialog, onClose);
|
|
31
|
+
const close = () => dialog.current?.close();
|
|
32
|
+
// The scrim is the dialog and the layout boxes in it, marked `data-scrim`; the media, the text and
|
|
33
|
+
// the buttons are not.
|
|
34
|
+
const clicked = (event) => {
|
|
35
|
+
if (event.target instanceof HTMLElement && event.target.hasAttribute("data-scrim"))
|
|
36
|
+
close();
|
|
37
|
+
};
|
|
38
|
+
const stepped = (event) => {
|
|
39
|
+
const step = { ArrowLeft: onPrevious, ArrowRight: onNext }[event.key];
|
|
40
|
+
if (!step)
|
|
41
|
+
return;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
step();
|
|
44
|
+
};
|
|
45
|
+
return (_jsxs("dialog", { ...rest, ref: dialog, "aria-label": label, "data-scrim": "", onClose: closed, onClick: clicked, onKeyDown: stepped, className: VIEWER, children: [_jsxs("header", { "data-scrim": "", className: "flex shrink-0 items-start justify-between gap-3 p-3", children: [_jsxs("div", { className: "min-w-0 px-2 py-1.5", children: [title && _jsx("div", { className: "text-sm font-semibold", children: title }), meta && _jsx("div", { className: "text-xs text-white/70", children: meta })] }), _jsx(ScrimButton, { label: closeLabel, path: CLOSE, onClick: close })] }), _jsxs("div", { "data-scrim": "", className: "flex min-h-0 flex-1 items-center gap-2 px-3", children: [onPrevious && _jsx(ScrimButton, { label: previousLabel, path: PREVIOUS, onClick: onPrevious }), _jsx("div", { "data-scrim": "", className: "flex size-full min-w-0 items-center justify-center *:max-h-full *:max-w-full *:object-contain", children: children }), onNext && _jsx(ScrimButton, { label: nextLabel, path: NEXT, onClick: onNext })] }), _jsx("footer", { "data-scrim": "", className: "flex shrink-0 justify-center px-5 py-4", children: caption && _jsx("p", { className: "max-w-prose text-center text-sm text-white/70", children: caption }) })] }));
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { ListRowProps } from "./listRowProps.js";
|
|
3
|
+
export type { ListRowProps } from "./listRowProps.js";
|
|
4
|
+
/**
|
|
5
|
+
* A full-width row that runs `onClick` (or, with `href`, opens a link) with a hover
|
|
6
|
+
* fill, a left-aligned label and `trailing` content at the far end. The row is a `<div>` with its
|
|
7
|
+
* `<button>` or link stretched over it, so a tap anywhere on the row runs it; a `TextLink`,
|
|
8
|
+
* `Button` or `Checkbox` in the row (in `trailing`, say a "View" link on a row that selects) sits
|
|
9
|
+
* above it and is clickable on its own. A button row's button is named by the label alone. With `expanded` it is the header of a
|
|
10
|
+
* collapsible section: `aria-expanded` and a chevron. Rows sit in a `Card flush`; `divided` draws
|
|
11
|
+
* the line between them, on each row after the first.
|
|
12
|
+
*
|
|
13
|
+
* `secondary` is a second, muted line under the label. `leading` is content before the label (`leadingWidth="thumbnail"` gives it a fixed picture width),
|
|
14
|
+
* `selected` marks the row in view, `focused` the one the keyboard cursor is on and `highlighted` fills
|
|
15
|
+
* the row a list follows (`onPointerEnter`, `onPointerLeave` and `onFocus` reach
|
|
16
|
+
* every form; on a button or linked row the pointer handlers go on the row itself). The label is a
|
|
17
|
+
* `<div>`, so it can hold block content (a name over a path). A row with no `href` and no
|
|
18
|
+
* `onClick` is a plain `<div>` with no action of its own, for one that holds its own buttons:
|
|
19
|
+
* `actions` follow `trailing`, and `revealOnHover` shows them only on hover or focus. Such a row
|
|
20
|
+
* also takes a `panel`, content under the row that starts where the label does (a conversation
|
|
21
|
+
* that opens under its chat); `divided` draws the line above the whole row, panel included, so a
|
|
22
|
+
* list of them is `divided={index > 0}` on each. Inside a row a `Stack` is `xs` apart, and a `sm`
|
|
23
|
+
* row makes the buttons in it `sm`. While `loading` an empty label is a bone, and what the row holds
|
|
24
|
+
* waits with it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ListRow(props: ListRowProps): ReactElement;
|
package/dist/ListRow.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { Chevron } from "./Chevron.js";
|
|
4
|
+
import { cx, focusRing, liftInteractive } from "./cx.js";
|
|
5
|
+
import { DensityProvider } from "./density.js";
|
|
6
|
+
import { renderLink } from "./link.js";
|
|
7
|
+
import { GapProvider } from "./stackGap.js";
|
|
8
|
+
import { LoadingScope, useLoading } from "./skeleton.js";
|
|
9
|
+
import { waitingRow } from "./listRowWait.js";
|
|
10
|
+
import { SELECTED } from "./tableRow.js";
|
|
11
|
+
import { hasReason, useBlocked } from "./blocked.js";
|
|
12
|
+
const ROW_LOOK = "flex w-full items-center gap-3 text-left text-sm text-slate-900";
|
|
13
|
+
const INSET_RING = `${focusRing} focus-visible:-outline-offset-2`;
|
|
14
|
+
/**
|
|
15
|
+
* A button or linked row is a `relative` box; its button or link is an empty overlay, so the row's
|
|
16
|
+
* own links and buttons are not nested in it.
|
|
17
|
+
*/
|
|
18
|
+
const LINK_ROW = `relative ${ROW_LOOK} ${liftInteractive}`;
|
|
19
|
+
const OVERLAY = `link-stretch absolute inset-0 ${INSET_RING}`;
|
|
20
|
+
/** A disabled button row: faded, whatever its fill. Its overlay button is disabled, so the row does not fire. */
|
|
21
|
+
const DISABLED = "opacity-50";
|
|
22
|
+
const STATIC = "group/row flex w-full items-center gap-3 text-sm text-slate-900";
|
|
23
|
+
/**
|
|
24
|
+
* A static row with a `panel`: the row's own line (the label, `trailing`, `actions`) over the panel,
|
|
25
|
+
* `leading` in a column of its own beside both, so the detail starts where the label does.
|
|
26
|
+
*/
|
|
27
|
+
const STATIC_PANEL = "group/row grid w-full items-center gap-3 text-sm text-slate-900";
|
|
28
|
+
const PANEL_COLUMNS = {
|
|
29
|
+
withLeading: "grid-cols-[auto_minmax(0,1fr)]",
|
|
30
|
+
alone: "grid-cols-[minmax(0,1fr)]",
|
|
31
|
+
};
|
|
32
|
+
const FILL = "hover:bg-slate-50";
|
|
33
|
+
/**
|
|
34
|
+
* The row a pointer or keyboard cursor is on: the inset fill, one step deeper than hover, so it
|
|
35
|
+
* still shows on a `bg-slate-50` surface (a `FullBleedLayout` panel, a toned card).
|
|
36
|
+
*/
|
|
37
|
+
const HIGHLIGHTED = "bg-slate-100";
|
|
38
|
+
/** The keyboard cursor: the focus ring, drawn inside the row, on a row that does not hold DOM focus. */
|
|
39
|
+
const FOCUSED = "outline-2 -outline-offset-2 outline-violet-600";
|
|
40
|
+
/** A thumbnail's width. A direct-child image fills it. */
|
|
41
|
+
const THUMBNAIL = "block w-32 [&>img]:block [&>img]:h-auto [&>img]:w-full";
|
|
42
|
+
/**
|
|
43
|
+
* Hidden until the row is hovered or has focus inside it; always shown where any pointer is coarse
|
|
44
|
+
* (a touch screen, hybrids included), and while a `Menu` in it is open, since its menu takes the
|
|
45
|
+
* focus out of the row.
|
|
46
|
+
*/
|
|
47
|
+
const REVEAL = "opacity-0 group-hover/row:opacity-100 group-focus-within/row:opacity-100 any-pointer-coarse:opacity-100 has-[[aria-expanded=true]]:opacity-100";
|
|
48
|
+
const PAD = { sm: "px-3 py-2", md: "px-4 py-3", lg: "px-5 py-4" };
|
|
49
|
+
/** A row with no `href` and no `onClick` is static: it does nothing of its own. */
|
|
50
|
+
function isStatic(props) {
|
|
51
|
+
return props.href === undefined && props.onClick === undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The row's background: the selected fill, else the hover fill unless a plain static row has none. */
|
|
54
|
+
function fillOf(props) {
|
|
55
|
+
if (props.selected)
|
|
56
|
+
return SELECTED;
|
|
57
|
+
if (props.highlighted)
|
|
58
|
+
return HIGHLIGHTED;
|
|
59
|
+
if (isDisabled(props))
|
|
60
|
+
return undefined;
|
|
61
|
+
return isStatic(props) && !props.revealOnHover ? undefined : FILL;
|
|
62
|
+
}
|
|
63
|
+
/** A button row with `disabled` or `disabledReason`: it fades and takes no hover fill. */
|
|
64
|
+
function isDisabled(props) {
|
|
65
|
+
if (hasReason(props.disabledReason))
|
|
66
|
+
return true;
|
|
67
|
+
return !isStatic(props) && "disabled" in props && props.disabled === true;
|
|
68
|
+
}
|
|
69
|
+
/** `panel={open && <Panel />}` is a common way to write it, so `false` is as empty as `null`. */
|
|
70
|
+
function hasPanel(panel) {
|
|
71
|
+
return panel != null && panel !== false;
|
|
72
|
+
}
|
|
73
|
+
function rowBase(props) {
|
|
74
|
+
if (!isStatic(props))
|
|
75
|
+
return LINK_ROW;
|
|
76
|
+
return hasPanel(props.panel) ? STATIC_PANEL : STATIC;
|
|
77
|
+
}
|
|
78
|
+
function look(props) {
|
|
79
|
+
const { size = "md", divided = false, focused = false } = props;
|
|
80
|
+
return cx(rowBase(props), PAD[size], divided && "border-t border-slate-200/70", fillOf(props), isDisabled(props) && DISABLED, focused && FOCUSED);
|
|
81
|
+
}
|
|
82
|
+
function StaticRow(props) {
|
|
83
|
+
const { leading: _l, secondary: _sec, leadingWidth: _lw, trailing: _t, focused: _f, highlighted = false, selected, size: _s, divided: _d, actions, revealOnHover = false, panel, expanded: _e, onClick: _o, href: _h, start, label, end, ...rest } = props;
|
|
84
|
+
const buttons = actions != null && (_jsx("span", { className: cx("flex shrink-0 items-center gap-2", revealOnHover && !highlighted && REVEAL), children: actions }));
|
|
85
|
+
const withPanel = hasPanel(panel);
|
|
86
|
+
return (_jsx("div", { ...rest, ...(selected ? { "aria-current": "true" } : {}), className: cx(look(props), withPanel && PANEL_COLUMNS[start ? "withLeading" : "alone"]), children: withPanel ? (_jsxs(PanelLines, { start: start, panel: panel, children: [label, end, buttons] })) : (_jsxs(_Fragment, { children: [start, label, end, buttons] })) }));
|
|
87
|
+
}
|
|
88
|
+
/** The cells of a static row with a `panel`: `start` beside the row's line (its children), over the panel in the label's column. */
|
|
89
|
+
function PanelLines({ start, panel, children, }) {
|
|
90
|
+
return (_jsxs(_Fragment, { children: [start, _jsx("div", { className: "flex min-w-0 items-center gap-3", children: children }), _jsx("div", { className: cx("min-w-0", Boolean(start) && "col-start-2"), children: panel })] }));
|
|
91
|
+
}
|
|
92
|
+
function LinkRow(props) {
|
|
93
|
+
const { leading: _l, secondary: _sec, leadingWidth: _lw, trailing: _t, focused: _f, highlighted: _hl, selected, expanded: _e, size: _s, divided: _d, actions: _a, revealOnHover: _rh, panel: _p, start, label, end, onPointerEnter, onPointerLeave, ...rest } = props;
|
|
94
|
+
const rowId = useId();
|
|
95
|
+
return (_jsxs("div", { id: rowId, onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, className: look(props), children: [renderLink({
|
|
96
|
+
...(rest["aria-label"] === undefined ? { "aria-labelledby": rowId } : {}),
|
|
97
|
+
...rest,
|
|
98
|
+
...(selected ? { "aria-current": "true" } : {}),
|
|
99
|
+
className: OVERLAY,
|
|
100
|
+
children: null,
|
|
101
|
+
}), start, label, end] }));
|
|
102
|
+
}
|
|
103
|
+
function ButtonRow(props) {
|
|
104
|
+
const { leading: _l, secondary: _sec, leadingWidth: _lw, trailing: _t, focused: _f, highlighted: _hl, selected, expanded, size: _s, divided: _d, actions: _a, revealOnHover: _rh, panel: _p, href: _h, start, label, end, labelId, children: _c, onPointerEnter, onPointerLeave, disabledReason, ...rest } = props;
|
|
105
|
+
const { props: guard, tooltip, blocked } = useBlocked(disabledReason, rest);
|
|
106
|
+
return (_jsxs("div", { onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, className: look(props), children: [_jsx("button", { type: "button", ...(rest["aria-label"] === undefined ? { "aria-labelledby": labelId } : {}), ...rest, ...guard, ...(selected ? { "aria-current": "true" } : {}), ...(expanded === undefined ? {} : { "aria-expanded": expanded }), className: cx(OVERLAY, blocked && "cursor-not-allowed") }), tooltip, expanded !== undefined && _jsx(Chevron, { open: expanded }), start, label, end] }));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A full-width row that runs `onClick` (or, with `href`, opens a link) with a hover
|
|
110
|
+
* fill, a left-aligned label and `trailing` content at the far end. The row is a `<div>` with its
|
|
111
|
+
* `<button>` or link stretched over it, so a tap anywhere on the row runs it; a `TextLink`,
|
|
112
|
+
* `Button` or `Checkbox` in the row (in `trailing`, say a "View" link on a row that selects) sits
|
|
113
|
+
* above it and is clickable on its own. A button row's button is named by the label alone. With `expanded` it is the header of a
|
|
114
|
+
* collapsible section: `aria-expanded` and a chevron. Rows sit in a `Card flush`; `divided` draws
|
|
115
|
+
* the line between them, on each row after the first.
|
|
116
|
+
*
|
|
117
|
+
* `secondary` is a second, muted line under the label. `leading` is content before the label (`leadingWidth="thumbnail"` gives it a fixed picture width),
|
|
118
|
+
* `selected` marks the row in view, `focused` the one the keyboard cursor is on and `highlighted` fills
|
|
119
|
+
* the row a list follows (`onPointerEnter`, `onPointerLeave` and `onFocus` reach
|
|
120
|
+
* every form; on a button or linked row the pointer handlers go on the row itself). The label is a
|
|
121
|
+
* `<div>`, so it can hold block content (a name over a path). A row with no `href` and no
|
|
122
|
+
* `onClick` is a plain `<div>` with no action of its own, for one that holds its own buttons:
|
|
123
|
+
* `actions` follow `trailing`, and `revealOnHover` shows them only on hover or focus. Such a row
|
|
124
|
+
* also takes a `panel`, content under the row that starts where the label does (a conversation
|
|
125
|
+
* that opens under its chat); `divided` draws the line above the whole row, panel included, so a
|
|
126
|
+
* list of them is `divided={index > 0}` on each. Inside a row a `Stack` is `xs` apart, and a `sm`
|
|
127
|
+
* row makes the buttons in it `sm`. While `loading` an empty label is a bone, and what the row holds
|
|
128
|
+
* waits with it.
|
|
129
|
+
*/
|
|
130
|
+
export function ListRow(props) {
|
|
131
|
+
const labelId = useId();
|
|
132
|
+
const { loading, owner } = useLoading(props.loading);
|
|
133
|
+
return (_jsx(GapProvider, { gap: "xs", children: _jsx(DensityProvider, { size: props.size === "sm" ? "sm" : null, children: _jsx(LoadingScope, { loading: loading, children: rowOf(waitingRow(props, loading, owner), labelId) }) }) }));
|
|
134
|
+
}
|
|
135
|
+
/** The row in its form: static with no `href` or `onClick`, a link with `href`, else a button. */
|
|
136
|
+
function rowOf(props, labelId) {
|
|
137
|
+
if (isStatic(props))
|
|
138
|
+
return _jsx(StaticRow, { ...props, ...piecesOf(props) });
|
|
139
|
+
if (props.href !== undefined)
|
|
140
|
+
return _jsx(LinkRow, { ...props, ...piecesOf(props) });
|
|
141
|
+
return _jsx(ButtonRow, { ...props, ...piecesOf(props, labelId), labelId: labelId });
|
|
142
|
+
}
|
|
143
|
+
/** The row's cells. `labelId` names the label, for a button row's button to be labelled by it. */
|
|
144
|
+
function piecesOf(props, labelId) {
|
|
145
|
+
const { leading, leadingWidth, trailing, secondary, children } = props;
|
|
146
|
+
return {
|
|
147
|
+
start: leading != null && (_jsx("span", { className: cx("shrink-0", leadingWidth === "thumbnail" && THUMBNAIL), children: leading })),
|
|
148
|
+
label: (_jsxs("div", { id: labelId, className: "min-w-0 flex-1", children: [children, secondary != null && secondary !== false && (_jsx("div", { className: "text-xs font-normal text-slate-500", children: secondary }))] })),
|
|
149
|
+
end: trailing != null && (_jsx("span", { className: "shrink-0 tabular-nums text-slate-500", children: trailing })),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Passthrough } from "./props.js";
|
|
2
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
3
|
+
/**
|
|
4
|
+
* A small, safe Markdown renderer for short notes: `## ` and `### ` headings, `- ` or `* ` bullets,
|
|
5
|
+
* `**bold**` and paragraphs. Text is rendered as React nodes, never as HTML. While `loading` with
|
|
6
|
+
* no `md` yet it draws a paragraph of bones.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Markdown({ md, loading: ownLoading, loadingLabel, ...rest }: {
|
|
9
|
+
/** The Markdown source; while `loading`, none yet is a paragraph of bones. */
|
|
10
|
+
md: string | undefined;
|
|
11
|
+
} & LoadingProps & Passthrough): import("react").JSX.Element;
|
package/dist/Markdown.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BoneLines, BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
3
|
+
// A minimal, SAFE markdown renderer (headings / bullets / bold). No
|
|
4
|
+
// dangerouslySetInnerHTML: text is rendered as React nodes, so it can't inject HTML.
|
|
5
|
+
function inline(text) {
|
|
6
|
+
return text.split(/(\*\*[^*]+\*\*)/g).map((p, i) => p.startsWith("**") && p.endsWith("**") ? (_jsx("strong", { className: "font-semibold text-slate-900", children: p.slice(2, -2) }, i)) : (_jsx("span", { children: p }, i)));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A small, safe Markdown renderer for short notes: `## ` and `### ` headings, `- ` or `* ` bullets,
|
|
10
|
+
* `**bold**` and paragraphs. Text is rendered as React nodes, never as HTML. While `loading` with
|
|
11
|
+
* no `md` yet it draws a paragraph of bones.
|
|
12
|
+
*/
|
|
13
|
+
export function Markdown({ md, loading: ownLoading, loadingLabel, ...rest }) {
|
|
14
|
+
const { loading, owner } = useLoading(ownLoading);
|
|
15
|
+
if (md === undefined || md === "") {
|
|
16
|
+
return (_jsxs("div", { ...rest, ...busy(owner, loading), className: "space-y-1", children: [loading && (_jsx("p", { className: "text-sm", children: _jsx(BoneLines, {}) })), _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] }));
|
|
17
|
+
}
|
|
18
|
+
const out = [];
|
|
19
|
+
let bullets = [];
|
|
20
|
+
const flush = () => {
|
|
21
|
+
if (bullets.length) {
|
|
22
|
+
out.push(_jsx("ul", { className: "ml-4 list-disc space-y-1", children: bullets }, `u${out.length}`));
|
|
23
|
+
bullets = [];
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
md.split("\n").forEach((ln, i) => {
|
|
27
|
+
const t = ln.trim();
|
|
28
|
+
if (t.startsWith("## ")) {
|
|
29
|
+
flush();
|
|
30
|
+
out.push(_jsx("h2", { className: "mt-4 text-xs font-semibold uppercase tracking-wide text-slate-400 first:mt-0", children: t.slice(3) }, i));
|
|
31
|
+
}
|
|
32
|
+
else if (t.startsWith("### ")) {
|
|
33
|
+
flush();
|
|
34
|
+
out.push(_jsx("h3", { className: "mt-3 text-sm font-semibold text-slate-700", children: t.slice(4) }, i));
|
|
35
|
+
}
|
|
36
|
+
else if (t.startsWith("- ") || t.startsWith("* ")) {
|
|
37
|
+
bullets.push(_jsx("li", { className: "text-sm text-slate-700", children: inline(t.slice(2)) }, i));
|
|
38
|
+
}
|
|
39
|
+
else if (t === "") {
|
|
40
|
+
flush();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
flush();
|
|
44
|
+
out.push(_jsx("p", { className: "text-sm text-slate-700", children: inline(t) }, i));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
flush();
|
|
48
|
+
return (_jsxs("div", { ...rest, ...busy(owner, loading), className: "space-y-1", children: [out, _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { type ImageAspect, type ImageWidth } from "./Image.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
export type MediaTileProps = {
|
|
6
|
+
/** The thumbnail, a local path or a data URL. Left out, or if it fails to load, a placeholder shows. */
|
|
7
|
+
src?: string | undefined;
|
|
8
|
+
/** What the thumbnail shows; it is the tile's name, with `label`. */
|
|
9
|
+
alt: string;
|
|
10
|
+
/** A short line on the bottom edge of the picture, on the media scrim: who posted it, or "Earlier". */
|
|
11
|
+
label?: ReactNode;
|
|
12
|
+
/** Muted text under the picture, e.g. when. */
|
|
13
|
+
caption?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The shape of the thumbnail, as `Image`'s `aspect`; `natural` keeps the picture's own
|
|
16
|
+
* proportions (a chat image) and crops nothing.
|
|
17
|
+
* @default 3:4
|
|
18
|
+
*/
|
|
19
|
+
aspect?: ImageAspect | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* `sm` 96px, `md` 160px or `lg` 256px wide; `full` fills the parent (a tile in a grid).
|
|
22
|
+
* @default md
|
|
23
|
+
*/
|
|
24
|
+
width?: ImageWidth | undefined;
|
|
25
|
+
/** Draws a play mark on the thumbnail: the tile opens a video, not a photo. Say so in `alt` too. */
|
|
26
|
+
video?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Adds a round remove button on the picture's top-right corner, named `removeLabel` and `alt`: a
|
|
29
|
+
* photo attached to a form, until it is sent. It is its own button, beside the tile's, so a tile
|
|
30
|
+
* with `onClick` still opens its `Lightbox`.
|
|
31
|
+
*/
|
|
32
|
+
onRemove?: (() => void) | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The remove button's word, before `alt` in its name and alone as its tooltip.
|
|
35
|
+
* @default Remove
|
|
36
|
+
*/
|
|
37
|
+
removeLabel?: string | undefined;
|
|
38
|
+
} & LoadingProps & Passthrough & ({
|
|
39
|
+
onClick?: undefined;
|
|
40
|
+
href?: undefined;
|
|
41
|
+
external?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
/**
|
|
44
|
+
* Makes the whole tile one button; open a `Lightbox` from it. Without it (or `href`) the
|
|
45
|
+
* tile is a plain, non-interactive block.
|
|
46
|
+
*/
|
|
47
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
48
|
+
href?: undefined;
|
|
49
|
+
external?: undefined;
|
|
50
|
+
} | {
|
|
51
|
+
onClick?: undefined;
|
|
52
|
+
/** Makes the whole tile one link, named as the button form is; an in-app path goes through `LinkProvider`. */
|
|
53
|
+
href: string;
|
|
54
|
+
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
55
|
+
external?: boolean | undefined;
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* A thumbnail tile: a picture in a fixed shape with an optional label on its bottom edge and a
|
|
59
|
+
* caption under it. With `onClick` the whole tile is one button, which is how a grid or a
|
|
60
|
+
* `ScrollStrip` of media opens each item in a `Lightbox`. The label sits on the same near-black
|
|
61
|
+
* media scrim as the Lightbox, in every theme. The thumbnail is cropped to fill its shape, or with
|
|
62
|
+
* `aspect="natural"` shown whole. With `href` the whole tile is one link instead. `onRemove` adds a
|
|
63
|
+
* remove button for a tile that can be taken back out.
|
|
64
|
+
* While `loading` with no `src` yet the picture is a bone of its shape.
|
|
65
|
+
*/
|
|
66
|
+
export declare function MediaTile({ src, alt, label, caption, aspect, width, video, onClick, href, external, onRemove, removeLabel, loading, loadingLabel, ...rest }: MediaTileProps): ReactElement;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx, focusRing } from "./cx.js";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { IMAGE_WIDTH, Image } from "./Image.js";
|
|
5
|
+
import { CLOSE } from "./Lightbox.js";
|
|
6
|
+
import { renderLink } from "./link.js";
|
|
7
|
+
import { BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
|
|
8
|
+
import { Tipped } from "./Tooltip.js";
|
|
9
|
+
const PLAY = "M6.3 2.84A1.5 1.5 0 0 0 4 4.11v11.78a1.5 1.5 0 0 0 2.3 1.27l9.34-5.89a1.5 1.5 0 0 0 0-2.54L6.3 2.84Z";
|
|
10
|
+
/**
|
|
11
|
+
* A thumbnail tile: a picture in a fixed shape with an optional label on its bottom edge and a
|
|
12
|
+
* caption under it. With `onClick` the whole tile is one button, which is how a grid or a
|
|
13
|
+
* `ScrollStrip` of media opens each item in a `Lightbox`. The label sits on the same near-black
|
|
14
|
+
* media scrim as the Lightbox, in every theme. The thumbnail is cropped to fill its shape, or with
|
|
15
|
+
* `aspect="natural"` shown whole. With `href` the whole tile is one link instead. `onRemove` adds a
|
|
16
|
+
* remove button for a tile that can be taken back out.
|
|
17
|
+
* While `loading` with no `src` yet the picture is a bone of its shape.
|
|
18
|
+
*/
|
|
19
|
+
export function MediaTile({ src, alt, label, caption, aspect = "3:4", width = "md", video = false, onClick, href, external = false, onRemove, removeLabel, loading, loadingLabel, ...rest }) {
|
|
20
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
21
|
+
const body = (_jsxs(LoadingScope, { loading: waiting, children: [_jsxs("span", { className: "relative block overflow-hidden rounded-lg", children: [_jsx(Image, { src: src, alt: alt, aspect: aspect }), video && (_jsx("span", { "aria-hidden": "true", className: "absolute inset-0 grid place-items-center", children: _jsx("span", { className: "grid size-10 place-items-center rounded-full bg-black/90 text-white", children: _jsx(Icon, { size: "lg", children: _jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", children: _jsx("path", { d: PLAY }) }) }) }) })), label && (_jsx("span", { className: "absolute inset-x-0 bottom-0 truncate bg-black/90 px-2 py-1 text-xs font-medium text-white", children: label }))] }), caption && _jsx("span", { className: "mt-1 block truncate text-xs text-slate-600", children: caption }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
22
|
+
// With a remove button the tile fills a wrapper that carries the width and the button's anchor.
|
|
23
|
+
const box = cx("block min-w-0 text-left", onRemove ? "w-full" : IMAGE_WIDTH[width]);
|
|
24
|
+
const tile = tileOf({
|
|
25
|
+
rest: { ...rest, ...busy(owner, waiting) },
|
|
26
|
+
onClick,
|
|
27
|
+
href,
|
|
28
|
+
external,
|
|
29
|
+
className: box,
|
|
30
|
+
body,
|
|
31
|
+
});
|
|
32
|
+
if (!onRemove)
|
|
33
|
+
return tile;
|
|
34
|
+
return (_jsxs("div", { className: cx("relative min-w-0", IMAGE_WIDTH[width]), children: [tile, _jsx(RemoveButton, { label: removeLabel, alt: alt, onRemove: onRemove })] }));
|
|
35
|
+
}
|
|
36
|
+
/** The round remove button on a tile's corner, named by its word and the picture's `alt`. */
|
|
37
|
+
function RemoveButton({ label = "Remove", alt, onRemove, }) {
|
|
38
|
+
return (_jsx(Tipped, { text: label, describes: false, own: {}, children: (tip) => (_jsx("button", { type: "button", "aria-label": `${label} ${alt}`, ...tip, onClick: onRemove, className: "absolute top-1 right-1 inline-flex size-8 cursor-pointer items-center justify-center rounded-full bg-black/90 text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white", children: _jsx(Icon, { children: _jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", children: _jsx("path", { d: CLOSE }) }) }) })) }));
|
|
39
|
+
}
|
|
40
|
+
/** The tile itself: one button, one link, or a plain block. */
|
|
41
|
+
function tileOf({ rest, onClick, href, external, className, body, }) {
|
|
42
|
+
const interactive = cx(className, "group rounded-lg", focusRing);
|
|
43
|
+
if (href !== undefined) {
|
|
44
|
+
return renderLink({ ...rest, href, external, className: interactive, children: body });
|
|
45
|
+
}
|
|
46
|
+
if (onClick) {
|
|
47
|
+
return (_jsx("button", { ...rest, type: "button", onClick: onClick, className: interactive, children: body }));
|
|
48
|
+
}
|
|
49
|
+
return (_jsx("div", { ...rest, className: className, children: body }));
|
|
50
|
+
}
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import { type IconButtonTone } from "./IconButton.js";
|
|
3
|
+
import type { IconName } from "./icons.js";
|
|
4
|
+
import { type Passthrough } from "./props.js";
|
|
5
|
+
import type { Size } from "./size.js";
|
|
6
|
+
/** One entry of a `Menu`: an action that runs `onSelect`, or a link to `href`. Never both. */
|
|
7
|
+
export type MenuAction = {
|
|
8
|
+
/** The item's text and its accessible name. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** A leading glyph from the `Icon` set, decorative. */
|
|
11
|
+
icon?: IconName | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* `danger` is red text, for delete, hide and leave. Put it last.
|
|
14
|
+
* @default neutral
|
|
15
|
+
*/
|
|
16
|
+
tone?: IconButtonTone | undefined;
|
|
17
|
+
/** Shown dimmed; the arrows skip it and a press does nothing. */
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
} & ({
|
|
20
|
+
/** Runs when the item is chosen; the menu then closes and focus goes back to the trigger. */
|
|
21
|
+
onSelect: () => void;
|
|
22
|
+
href?: undefined;
|
|
23
|
+
external?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
onSelect?: undefined;
|
|
26
|
+
/** Makes the item a link; an in-app path goes through the app's `LinkProvider`. */
|
|
27
|
+
href: string;
|
|
28
|
+
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
29
|
+
external?: boolean | undefined;
|
|
30
|
+
});
|
|
31
|
+
type MenuProps = Passthrough & {
|
|
32
|
+
/** The trigger's accessible name and the menu's. With `trigger="button"` it is the visible text. */
|
|
33
|
+
label: string;
|
|
34
|
+
/** The actions, in order. */
|
|
35
|
+
items: readonly [MenuAction, ...MenuAction[]];
|
|
36
|
+
/**
|
|
37
|
+
* `icon` is a ghost square button holding three dots, the overflow menu; `button` is an outline
|
|
38
|
+
* `Button` with `label` as its text and a chevron after it, for a menu whose name is worth a word.
|
|
39
|
+
* @default icon
|
|
40
|
+
*/
|
|
41
|
+
trigger?: "icon" | "button" | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The trigger's height, the same steps as `IconButton` and `Button`: `sm` inside a row or a card
|
|
44
|
+
* header. The menu's own text does not change with it.
|
|
45
|
+
* @default md
|
|
46
|
+
*/
|
|
47
|
+
size?: Size | undefined;
|
|
48
|
+
/** Opens on mount, for a story or a test that shows the open menu. */
|
|
49
|
+
defaultOpen?: boolean | undefined;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A button that opens a short list of actions: the overflow menu at the end of a row, a card header
|
|
53
|
+
* or a page header. Keep the one main action in view beside it and put the rest here, the `danger`
|
|
54
|
+
* one last. `items` are data: each a `label` with `onSelect`, or a link with `href` (`external` for
|
|
55
|
+
* a new tab), an optional leading `icon`, `tone="danger"` and `disabled`.
|
|
56
|
+
*
|
|
57
|
+
* `trigger="icon"` (the default) is a ghost three-dot button named by `label`; `trigger="button"` is
|
|
58
|
+
* an outline button reading `label`. The menu opens below the trigger, aligned to its end, and flips
|
|
59
|
+
* when there is no room. The keyboard is the menu button pattern: Enter, Space or ArrowDown open it
|
|
60
|
+
* on the first item, ArrowUp on the last; the arrows, Home, End and a letter move; Enter chooses;
|
|
61
|
+
* Escape closes, and focus goes back to the trigger. `data-*` and `aria-*` land on the trigger.
|
|
62
|
+
*/
|
|
63
|
+
export declare function Menu({ label, items, trigger, size, defaultOpen, ...rest }: MenuProps): ReactElement;
|
|
64
|
+
export {};
|
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { Button as AriaButton, Menu as AriaMenu, MenuItem, MenuTrigger, Popover, } from "react-aria-components";
|
|
4
|
+
import { buttonClass } from "./Button.js";
|
|
5
|
+
import { cx } from "./cx.js";
|
|
6
|
+
import { Icon } from "./Icon.js";
|
|
7
|
+
import { look } from "./IconButton.js";
|
|
8
|
+
import { renderLink } from "./link.js";
|
|
9
|
+
import { Tipped } from "./Tooltip.js";
|
|
10
|
+
import { definedProps } from "./props.js";
|
|
11
|
+
const FRAME = "min-w-44 max-w-[calc(100vw-2rem)] rounded-xl border border-slate-200 bg-white p-1 text-slate-900 shadow-lg outline-none";
|
|
12
|
+
const ITEM = "flex cursor-default items-center gap-2 rounded-lg px-3 py-1.5 text-sm outline-none select-none data-disabled:cursor-not-allowed data-disabled:opacity-50";
|
|
13
|
+
const ITEM_TONE = {
|
|
14
|
+
neutral: { ink: "text-slate-900", focused: "bg-slate-100" },
|
|
15
|
+
danger: { ink: "text-red-700", focused: "bg-red-50" },
|
|
16
|
+
};
|
|
17
|
+
/** The modal `<dialog>` the trigger sits in, if any, so the menu renders inside it and is not inert. */
|
|
18
|
+
function useDialogOf() {
|
|
19
|
+
const [container, setContainer] = useState(undefined);
|
|
20
|
+
// React Aria merges this ref with its own into a new function on every render, so React detaches
|
|
21
|
+
// and reattaches it each time: a detach (`null`) must not clear the container, or the open menu
|
|
22
|
+
// would move to <body> and lose its focus.
|
|
23
|
+
const find = useCallback((el) => {
|
|
24
|
+
if (el)
|
|
25
|
+
setContainer(el.closest("dialog") ?? undefined);
|
|
26
|
+
}, []);
|
|
27
|
+
return { container, find };
|
|
28
|
+
}
|
|
29
|
+
/** What the trigger shows: three dots, or the label and a chevron. */
|
|
30
|
+
function Face({ icon, label, size }) {
|
|
31
|
+
if (icon)
|
|
32
|
+
return _jsx(Icon, { name: "more", size: size });
|
|
33
|
+
return (_jsxs(_Fragment, { children: [label, _jsx(Icon, { name: "chevron-down", size: size })] }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A button that opens a short list of actions: the overflow menu at the end of a row, a card header
|
|
37
|
+
* or a page header. Keep the one main action in view beside it and put the rest here, the `danger`
|
|
38
|
+
* one last. `items` are data: each a `label` with `onSelect`, or a link with `href` (`external` for
|
|
39
|
+
* a new tab), an optional leading `icon`, `tone="danger"` and `disabled`.
|
|
40
|
+
*
|
|
41
|
+
* `trigger="icon"` (the default) is a ghost three-dot button named by `label`; `trigger="button"` is
|
|
42
|
+
* an outline button reading `label`. The menu opens below the trigger, aligned to its end, and flips
|
|
43
|
+
* when there is no room. The keyboard is the menu button pattern: Enter, Space or ArrowDown open it
|
|
44
|
+
* on the first item, ArrowUp on the last; the arrows, Home, End and a letter move; Enter chooses;
|
|
45
|
+
* Escape closes, and focus goes back to the trigger. `data-*` and `aria-*` land on the trigger.
|
|
46
|
+
*/
|
|
47
|
+
export function Menu({ label, items, trigger = "icon", size = "md", defaultOpen = false, ...rest }) {
|
|
48
|
+
const { container, find } = useDialogOf();
|
|
49
|
+
const icon = trigger === "icon";
|
|
50
|
+
// A pointer opens the menu on its first item, as the keyboard's Enter does (the menu button
|
|
51
|
+
// pattern); left to itself, React Aria focuses the menu box. ArrowUp still opens on the last.
|
|
52
|
+
const [pointer, setPointer] = useState(false);
|
|
53
|
+
const button = (_jsx(AriaButton, { ...definedProps(rest), ref: find, onPressStart: (event) => setPointer(event.pointerType !== "keyboard"),
|
|
54
|
+
// ArrowDown and ArrowUp open it with no press: they keep React Aria's first and last item.
|
|
55
|
+
onKeyDown: (event) => {
|
|
56
|
+
setPointer(false);
|
|
57
|
+
event.continuePropagation();
|
|
58
|
+
}, ...(icon ? { "aria-label": label } : {}), className: icon ? look({ variant: "ghost", size }) : buttonClass("outline", { size }), children: _jsx(Face, { icon: icon, label: label, size: size }) }));
|
|
59
|
+
// The three-dot trigger shows its name as the library's tooltip, as an `IconButton` does. React
|
|
60
|
+
// Aria's button takes no pointer handlers, so they sit on a wrapper; focus and keys bubble to it.
|
|
61
|
+
return (_jsxs(MenuTrigger, { defaultOpen: defaultOpen, children: [icon ? (_jsx(Tipped, { text: label, describes: false, own: {}, children: (tip) => (_jsx("span", { className: "inline-flex", ...tip, children: button })) })) : (button), _jsx(Popover, { ...(container ? { UNSTABLE_portalContainer: container } : {}), placement: "bottom end", className: FRAME, children: _jsx(AriaMenu, { className: "outline-none", ...(pointer ? { autoFocus: "first" } : {}), children: items.map((item, index) => (_jsx(Item, { item: item }, `${index}:${item.label}`))) }) })] }));
|
|
62
|
+
}
|
|
63
|
+
function Item({ item }) {
|
|
64
|
+
const tone = ITEM_TONE[item.tone ?? "neutral"];
|
|
65
|
+
const className = ({ isFocused }) => cx(ITEM, tone.ink, isFocused && tone.focused);
|
|
66
|
+
const inside = (_jsxs(_Fragment, { children: [item.icon ? _jsx(Icon, { name: item.icon, size: "md" }) : null, _jsx("span", { className: "min-w-0 flex-1 truncate", children: item.label })] }));
|
|
67
|
+
if (item.href !== undefined) {
|
|
68
|
+
const { href, external = false } = item;
|
|
69
|
+
return (_jsx(MenuItem, { textValue: item.label, href: href, isDisabled: item.disabled ?? false, className: className, render: (props) => {
|
|
70
|
+
// An item with `href` is drawn as an anchor; the `div` form is React Aria's fallback.
|
|
71
|
+
if (!("href" in props))
|
|
72
|
+
return _jsx("div", { ...props });
|
|
73
|
+
// React Aria hands the anchor its role, tab index, handlers and ref; the app's router
|
|
74
|
+
// link draws it when `href` is an in-app path.
|
|
75
|
+
const { href: _href, className: drawn, children: _children, ...aria } = props;
|
|
76
|
+
return renderLink({
|
|
77
|
+
...aria,
|
|
78
|
+
href,
|
|
79
|
+
external,
|
|
80
|
+
className: drawn ?? cx(ITEM, tone.ink),
|
|
81
|
+
children: inside,
|
|
82
|
+
});
|
|
83
|
+
}, children: inside }));
|
|
84
|
+
}
|
|
85
|
+
return (_jsx(MenuItem, { textValue: item.label, onAction: item.onSelect, isDisabled: item.disabled ?? false, className: className, children: inside }));
|
|
86
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
|
+
/** The mark between MetaList items: `·`, `•`, or `none` for a gap alone. */
|
|
5
|
+
export type MetaListSeparator = "·" | "•" | "none";
|
|
6
|
+
/**
|
|
7
|
+
* A wrapping row of facts or links in muted small text, joined by a `·`: branch · SHA · date, or a
|
|
8
|
+
* footer's Privacy · Terms · Email. An item is text, a `Code` or a `TextLink`. The separator is
|
|
9
|
+
* `aria-hidden` and trails each item but the last, held to its item like a comma, so a wrap leaves
|
|
10
|
+
* it at the end of a line and never at the start; `separator` swaps it for a `•` or none. An item never breaks inside itself: the
|
|
11
|
+
* row wraps between items. `mono` sets the whole row in the monospace face, for ids and paths.
|
|
12
|
+
* While `loading` with no items it draws three word-sized bones.
|
|
13
|
+
*/
|
|
14
|
+
export declare function MetaList({ mono, separator, loading: ownLoading, loadingLabel, children, ...rest }: {
|
|
15
|
+
/** The whole row in the monospace face, for ids and paths. */
|
|
16
|
+
mono?: boolean | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The mark between items: `·`, `•`, or `none` for a gap alone.
|
|
19
|
+
* @default ·
|
|
20
|
+
*/
|
|
21
|
+
separator?: MetaListSeparator | undefined;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
} & LoadingProps & Passthrough): ReactElement;
|