@slashsuite/ui-react 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATING.md +386 -8
- package/README.md +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +1 -0
- package/dist/Button.js +4 -3
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +113 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/cx.d.ts +22 -3
- package/dist/cx.js +22 -3
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +15 -1
- package/dist/density.js +27 -8
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +45 -0
- package/dist/stateMachineDots.js +162 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +27 -0
- package/dist/useFlowLayout.js +119 -0
- package/package.json +3 -2
package/dist/Mark.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A highlighted run inside text: a `<mark>`, on the warn tint, such as the words a search matched
|
|
4
|
+
* in a result. It takes the surrounding size and weight. Mark the words that matter to what the
|
|
5
|
+
* reader is doing, not emphasis: that is `Text strong`.
|
|
6
|
+
*/
|
|
7
|
+
export function Mark({ children, ...rest }) {
|
|
8
|
+
return (_jsx("mark", { ...rest, className: "rounded-sm bg-amber-50 px-0.5 text-amber-800", children: children }));
|
|
9
|
+
}
|
package/dist/Markdown.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import type { Passthrough } from "./props.js";
|
|
2
2
|
import { type LoadingProps } from "./skeleton.js";
|
|
3
3
|
/**
|
|
4
|
-
* A small, safe Markdown renderer for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A small, safe Markdown renderer for notes and for rich text from a CMS: `## ` and `### `
|
|
5
|
+
* headings, `- ` or `* ` bullets, `1. ` numbered lists, `**bold**`, `[links](href)`, a picture on a
|
|
6
|
+
* line of its own (``), GFM tables and paragraphs. Text is rendered as React nodes, never
|
|
7
|
+
* as HTML. A link is a `TextLink` (an in-app path goes through `LinkProvider`) and is kept only if
|
|
8
|
+
* its address is a web, mail or phone address or a path on this site; any other (`javascript:`)
|
|
9
|
+
* keeps its words and drops the link. A picture is an `Image` in its own shape, and a table a
|
|
10
|
+
* `Table` named by the heading above it, or `tableLabel`. While `loading` with no `md` yet it
|
|
11
|
+
* draws a paragraph of bones.
|
|
12
|
+
*
|
|
13
|
+
* A `## ` heading is one level below the heading that holds the Markdown (an `h2` on the page, an
|
|
14
|
+
* `h3` in a `Section`, an `h4` in a titled `Card` there) and a `### ` one below that, never past
|
|
15
|
+
* `h6`, so the notes keep the page's outline.
|
|
7
16
|
*/
|
|
8
|
-
export declare function Markdown({ md, loading: ownLoading, loadingLabel, ...rest }: {
|
|
17
|
+
export declare function Markdown({ md, tableLabel, loading: ownLoading, loadingLabel, ...rest }: {
|
|
9
18
|
/** The Markdown source; while `loading`, none yet is a paragraph of bones. */
|
|
10
19
|
md: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The name a table takes when no heading comes before it, for an app in another language.
|
|
22
|
+
* @default Table
|
|
23
|
+
*/
|
|
24
|
+
tableLabel?: string | undefined;
|
|
11
25
|
} & LoadingProps & Passthrough): import("react").JSX.Element;
|
package/dist/Markdown.js
CHANGED
|
@@ -1,49 +1,188 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useHeadingLevel } from "./headingLevel.js";
|
|
3
|
+
import { Image } from "./Image.js";
|
|
2
4
|
import { BoneLines, BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
import { Table, TableBody, TableHead, TableRow } from "./Table.js";
|
|
6
|
+
import { TableCell, TableHeaderCell } from "./TableCells.js";
|
|
7
|
+
import { TextLink } from "./TextLink.js";
|
|
8
|
+
// A minimal, SAFE markdown renderer. No dangerouslySetInnerHTML: text is rendered as React nodes, so
|
|
9
|
+
// it can't inject HTML, and a link or picture whose address is not on the safe list is dropped.
|
|
10
|
+
/** A link's address is kept only if it is a web, mail or phone address, or one on this site. */
|
|
11
|
+
const SAFE_HREF = /^(https?:|mailto:|tel:|\/|#|\?|\.\/|\.\.\/)/i;
|
|
12
|
+
/** A picture's address is kept only if it is a web address, one on this site, or a data URL of an image. */
|
|
13
|
+
const SAFE_SRC = /^(https?:|\/|\.\/|\.\.\/|data:image\/)/i;
|
|
14
|
+
/** `**bold**`, `[words](href)` and an inline ``, which stays text: a picture is a line of its own. */
|
|
15
|
+
const INLINE = /(\*\*[^*]+\*\*|!?\[[^\]]*\]\([^)\s]*\))/g;
|
|
16
|
+
const LINK = /^\[([^\]]*)\]\(([^)\s]*)\)$/;
|
|
17
|
+
const IMAGE = /^!\[([^\]]*)\]\(([^)\s]*)\)$/;
|
|
5
18
|
function inline(text) {
|
|
6
|
-
return text.split(
|
|
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 = [];
|
|
19
|
+
return text.split(INLINE).map((p, i) => {
|
|
20
|
+
if (p.startsWith("**") && p.endsWith("**") && p.length > 4) {
|
|
21
|
+
return (_jsx("strong", { className: "font-semibold text-slate-900", children: p.slice(2, -2) }, i));
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const link = LINK.exec(p);
|
|
24
|
+
if (link) {
|
|
25
|
+
const [, words = "", href = ""] = link;
|
|
26
|
+
if (!SAFE_HREF.test(href))
|
|
27
|
+
return _jsx("span", { children: words }, i);
|
|
28
|
+
return (_jsx(TextLink, { href: href, underline: true, children: words }, i));
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
return _jsx("span", { children: p }, i);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** The level of a `### ` heading: one below a `## `, never past 6. */
|
|
34
|
+
const SUB = { 2: 3, 3: 4, 4: 5, 5: 6, 6: 6 };
|
|
35
|
+
const BULLET = /^[-*] /;
|
|
36
|
+
const NUMBERED = /^(\d+)[.)] /;
|
|
37
|
+
const TABLE_RULE = /^\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?$/;
|
|
38
|
+
/** The cells of a `| a | b |` row, trimmed. */
|
|
39
|
+
function cells(row) {
|
|
40
|
+
return row
|
|
41
|
+
.trim()
|
|
42
|
+
.replace(/^\|/, "")
|
|
43
|
+
.replace(/\|$/, "")
|
|
44
|
+
.split("|")
|
|
45
|
+
.map((c) => c.trim());
|
|
46
|
+
}
|
|
47
|
+
/** A column's alignment from its rule: `:--` start, `:-:` center, `--:` end. */
|
|
48
|
+
function alignOf(rule) {
|
|
49
|
+
const left = rule.startsWith(":");
|
|
50
|
+
const right = rule.endsWith(":");
|
|
51
|
+
if (left && right)
|
|
52
|
+
return "center";
|
|
53
|
+
return right ? "end" : "start";
|
|
54
|
+
}
|
|
55
|
+
/** A GFM table: its head row, its rule and its body rows, named by the heading above it. */
|
|
56
|
+
function table(lines, label, key) {
|
|
57
|
+
const [head = "", rule = "", ...body] = lines;
|
|
58
|
+
const titles = cells(head);
|
|
59
|
+
const align = cells(rule).map(alignOf);
|
|
60
|
+
return (_jsxs(Table, { label: label, children: [_jsx(TableHead, { children: _jsx(TableRow, { children: titles.map((title, i) => (_jsx(TableHeaderCell, { align: align[i], children: inline(title) }, i))) }) }), _jsx(TableBody, { children: body.map((row, r) => (_jsx(TableRow, { children: titles.map((_, i) => (_jsx(TableCell, { align: align[i], children: inline(cells(row)[i] ?? "") }, i))) }, r))) })] }, key));
|
|
61
|
+
}
|
|
62
|
+
/** A list item's line, bulleted or numbered, or nothing. */
|
|
63
|
+
function itemOf(t) {
|
|
64
|
+
if (BULLET.test(t))
|
|
65
|
+
return { kind: "ul", start: 1, text: t.slice(2) };
|
|
66
|
+
const numbered = NUMBERED.exec(t);
|
|
67
|
+
if (!numbered)
|
|
68
|
+
return undefined;
|
|
69
|
+
const [marker = "", n = "1"] = numbered;
|
|
70
|
+
return { kind: "ol", start: Number(n), text: t.slice(marker.length) };
|
|
71
|
+
}
|
|
72
|
+
/** What one line is, when it is not the start of a table. */
|
|
73
|
+
function lineOf(t) {
|
|
74
|
+
if (t === "")
|
|
75
|
+
return { kind: "blank" };
|
|
76
|
+
if (t.startsWith("## "))
|
|
77
|
+
return { kind: "h2", text: t.slice(3) };
|
|
78
|
+
if (t.startsWith("### "))
|
|
79
|
+
return { kind: "h3", text: t.slice(4) };
|
|
80
|
+
const item = itemOf(t);
|
|
81
|
+
if (item)
|
|
82
|
+
return item;
|
|
83
|
+
const image = IMAGE.exec(t);
|
|
84
|
+
if (image)
|
|
85
|
+
return { kind: "image", alt: image[1] ?? "", src: image[2] ?? "" };
|
|
86
|
+
return { kind: "p", text: t };
|
|
87
|
+
}
|
|
88
|
+
/** The source's blocks, a table's lines gathered into one. */
|
|
89
|
+
function parse(md) {
|
|
90
|
+
const lines = md.split("\n").map((ln) => ln.trim());
|
|
91
|
+
const out = [];
|
|
92
|
+
let i = 0;
|
|
93
|
+
while (i < lines.length) {
|
|
94
|
+
const t = lines[i] ?? "";
|
|
95
|
+
if (t.startsWith("|") && TABLE_RULE.test(lines[i + 1] ?? "")) {
|
|
96
|
+
let end = i + 2;
|
|
97
|
+
while (lines[end]?.startsWith("|"))
|
|
98
|
+
end++;
|
|
99
|
+
out.push({ kind: "table", rows: lines.slice(i, end) });
|
|
100
|
+
i = end;
|
|
35
101
|
}
|
|
36
|
-
else
|
|
37
|
-
|
|
102
|
+
else {
|
|
103
|
+
out.push(lineOf(t));
|
|
104
|
+
i++;
|
|
38
105
|
}
|
|
39
|
-
|
|
40
|
-
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** A run of list items of one kind, as a `ul` or an `ol` that counts from the first item's number. */
|
|
110
|
+
function list(items, kind, key) {
|
|
111
|
+
const lis = items.map((it, i) => (_jsx("li", { className: "text-sm text-slate-700", children: inline(it.text) }, i)));
|
|
112
|
+
if (kind === "ul") {
|
|
113
|
+
return (_jsx("ul", { className: "ml-4 list-disc space-y-1", children: lis }, key));
|
|
114
|
+
}
|
|
115
|
+
const start = items[0]?.start ?? 1;
|
|
116
|
+
return (_jsx("ol", { start: start === 1 ? undefined : start, className: "ml-5 list-decimal space-y-1", children: lis }, key));
|
|
117
|
+
}
|
|
118
|
+
/** Everything but a list item, drawn. */
|
|
119
|
+
function single(block, key, h, label) {
|
|
120
|
+
switch (block.kind) {
|
|
121
|
+
case "h2":
|
|
122
|
+
return (_jsx(h.H2, { className: "mt-4 text-xs font-semibold uppercase tracking-wide text-slate-400 first:mt-0", children: block.text }, key));
|
|
123
|
+
case "h3":
|
|
124
|
+
return (_jsx(h.H3, { className: "mt-3 text-sm font-semibold text-slate-700", children: block.text }, key));
|
|
125
|
+
case "table":
|
|
126
|
+
return table(block.rows, label, key);
|
|
127
|
+
case "image":
|
|
128
|
+
return (_jsx("div", { className: "py-1", children: _jsx(Image, { src: SAFE_SRC.test(block.src) ? block.src : undefined, alt: block.alt, aspect: "natural" }) }, key));
|
|
129
|
+
case "p":
|
|
130
|
+
return (_jsx("p", { className: "text-sm text-slate-700", children: inline(block.text) }, key));
|
|
131
|
+
default:
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** The run of list items of one kind from `from`, and the index after it. */
|
|
136
|
+
function run(all, from, kind) {
|
|
137
|
+
const items = [];
|
|
138
|
+
let i = from;
|
|
139
|
+
for (let b = all[i]; b?.kind === kind; b = all[++i])
|
|
140
|
+
items.push(b);
|
|
141
|
+
return [items, i];
|
|
142
|
+
}
|
|
143
|
+
/** The blocks of `md` drawn: its `## ` headings at `top`, its `### ` at `sub`. */
|
|
144
|
+
function blocks(md, top, sub, tableLabel) {
|
|
145
|
+
const h = { H2: `h${top}`, H3: `h${sub}` };
|
|
146
|
+
const out = [];
|
|
147
|
+
// A table is named by the heading above it, as a reader finds it.
|
|
148
|
+
let label = tableLabel;
|
|
149
|
+
const all = parse(md);
|
|
150
|
+
let i = 0;
|
|
151
|
+
for (let block = all[0]; block; block = all[i]) {
|
|
152
|
+
if (block.kind === "ul" || block.kind === "ol") {
|
|
153
|
+
const [items, next] = run(all, i, block.kind);
|
|
154
|
+
out.push(list(items, block.kind, i));
|
|
155
|
+
i = next;
|
|
41
156
|
}
|
|
42
157
|
else {
|
|
43
|
-
|
|
44
|
-
|
|
158
|
+
if (block.kind === "h2" || block.kind === "h3")
|
|
159
|
+
label = block.text;
|
|
160
|
+
out.push(single(block, i, h, label));
|
|
161
|
+
i++;
|
|
45
162
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A small, safe Markdown renderer for notes and for rich text from a CMS: `## ` and `### `
|
|
168
|
+
* headings, `- ` or `* ` bullets, `1. ` numbered lists, `**bold**`, `[links](href)`, a picture on a
|
|
169
|
+
* line of its own (``), GFM tables and paragraphs. Text is rendered as React nodes, never
|
|
170
|
+
* as HTML. A link is a `TextLink` (an in-app path goes through `LinkProvider`) and is kept only if
|
|
171
|
+
* its address is a web, mail or phone address or a path on this site; any other (`javascript:`)
|
|
172
|
+
* keeps its words and drops the link. A picture is an `Image` in its own shape, and a table a
|
|
173
|
+
* `Table` named by the heading above it, or `tableLabel`. While `loading` with no `md` yet it
|
|
174
|
+
* draws a paragraph of bones.
|
|
175
|
+
*
|
|
176
|
+
* A `## ` heading is one level below the heading that holds the Markdown (an `h2` on the page, an
|
|
177
|
+
* `h3` in a `Section`, an `h4` in a titled `Card` there) and a `### ` one below that, never past
|
|
178
|
+
* `h6`, so the notes keep the page's outline.
|
|
179
|
+
*/
|
|
180
|
+
export function Markdown({ md, tableLabel = "Table", loading: ownLoading, loadingLabel, ...rest }) {
|
|
181
|
+
const { loading, owner } = useLoading(ownLoading);
|
|
182
|
+
const level = useHeadingLevel(undefined);
|
|
183
|
+
if (md === undefined || md === "") {
|
|
184
|
+
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 })] }));
|
|
185
|
+
}
|
|
186
|
+
const out = blocks(md, level, SUB[level], tableLabel);
|
|
48
187
|
return (_jsxs("div", { ...rest, ...busy(owner, loading), className: "space-y-1", children: [out, _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] }));
|
|
49
188
|
}
|
package/dist/MediaTile.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export type MediaTileProps = {
|
|
|
11
11
|
label?: ReactNode;
|
|
12
12
|
/** Muted text under the picture, e.g. when. */
|
|
13
13
|
caption?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* A short word pinned to the picture's top-right corner on the media scrim: a count, "New" or a
|
|
16
|
+
* size. Text only; it is part of the tile's name. With `onRemove` the button takes that corner,
|
|
17
|
+
* so the badge sits top-left.
|
|
18
|
+
*/
|
|
19
|
+
badge?: string | undefined;
|
|
14
20
|
/**
|
|
15
21
|
* The shape of the thumbnail, as `Image`'s `aspect`; `natural` keeps the picture's own
|
|
16
22
|
* proportions (a chat image) and crops nothing.
|
|
@@ -18,7 +24,7 @@ export type MediaTileProps = {
|
|
|
18
24
|
*/
|
|
19
25
|
aspect?: ImageAspect | undefined;
|
|
20
26
|
/**
|
|
21
|
-
* `sm` 96px, `md` 160px
|
|
27
|
+
* `sm` 96px, `md` 160px, `lg` 256px or `xl` 448px wide; `full` fills the parent (a tile in a grid).
|
|
22
28
|
* @default md
|
|
23
29
|
*/
|
|
24
30
|
width?: ImageWidth | undefined;
|
|
@@ -60,7 +66,7 @@ export type MediaTileProps = {
|
|
|
60
66
|
* `ScrollStrip` of media opens each item in a `Lightbox`. The label sits on the same near-black
|
|
61
67
|
* media scrim as the Lightbox, in every theme. The thumbnail is cropped to fill its shape, or with
|
|
62
68
|
* `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.
|
|
69
|
+
* remove button for a tile that can be taken back out. `badge` pins a short word to a top corner.
|
|
64
70
|
* While `loading` with no `src` yet the picture is a bone of its shape.
|
|
65
71
|
*/
|
|
66
|
-
export declare function MediaTile({ src, alt, label, caption, aspect, width, video, onClick, href, external, onRemove, removeLabel, loading, loadingLabel, ...rest }: MediaTileProps): ReactElement;
|
|
72
|
+
export declare function MediaTile({ src, alt, label, caption, badge, aspect, width, video, onClick, href, external, onRemove, removeLabel, loading, loadingLabel, ...rest }: MediaTileProps): ReactElement;
|
package/dist/MediaTile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cx, focusRing } from "./cx.js";
|
|
3
3
|
import { Icon } from "./Icon.js";
|
|
4
4
|
import { IMAGE_WIDTH, Image } from "./Image.js";
|
|
@@ -13,12 +13,12 @@ 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
|
|
|
13
13
|
* `ScrollStrip` of media opens each item in a `Lightbox`. The label sits on the same near-black
|
|
14
14
|
* media scrim as the Lightbox, in every theme. The thumbnail is cropped to fill its shape, or with
|
|
15
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.
|
|
16
|
+
* remove button for a tile that can be taken back out. `badge` pins a short word to a top corner.
|
|
17
17
|
* While `loading` with no `src` yet the picture is a bone of its shape.
|
|
18
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 }) {
|
|
19
|
+
export function MediaTile({ src, alt, label, caption, badge, aspect = "3:4", width = "md", video = false, onClick, href, external = false, onRemove, removeLabel, loading, loadingLabel, ...rest }) {
|
|
20
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 }),
|
|
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 }), _jsx(TileMarks, { video: video, badge: badge, badgeStart: onRemove !== undefined }), 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
22
|
// With a remove button the tile fills a wrapper that carries the width and the button's anchor.
|
|
23
23
|
const box = cx("block min-w-0 text-left", onRemove ? "w-full" : IMAGE_WIDTH[width]);
|
|
24
24
|
const tile = tileOf({
|
|
@@ -33,6 +33,10 @@ export function MediaTile({ src, alt, label, caption, aspect = "3:4", width = "m
|
|
|
33
33
|
return tile;
|
|
34
34
|
return (_jsxs("div", { className: cx("relative min-w-0", IMAGE_WIDTH[width]), children: [tile, _jsx(RemoveButton, { label: removeLabel, alt: alt, onRemove: onRemove })] }));
|
|
35
35
|
}
|
|
36
|
+
/** The marks laid over a tile's picture: the play mark for a video, and the badge in a top corner. */
|
|
37
|
+
function TileMarks({ video, badge, badgeStart, }) {
|
|
38
|
+
return (_jsxs(_Fragment, { children: [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 }) }) }) }) })), badge && (_jsx("span", { className: cx("absolute top-1 truncate rounded bg-black/90 px-1.5 py-0.5 text-xs font-medium text-white", badgeStart ? "left-1 max-w-[calc(100%-2.75rem)]" : "right-1 max-w-[calc(100%-0.5rem)]"), children: badge }))] }));
|
|
39
|
+
}
|
|
36
40
|
/** The round remove button on a tile's corner, named by its word and the picture's `alt`. */
|
|
37
41
|
function RemoveButton({ label = "Remove", alt, onRemove, }) {
|
|
38
42
|
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 }) }) }) })) }));
|
package/dist/Menu.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type IconButtonTone } from "./IconButton.js";
|
|
|
3
3
|
import type { IconName } from "./icons.js";
|
|
4
4
|
import { type Passthrough } from "./props.js";
|
|
5
5
|
import type { Size } from "./size.js";
|
|
6
|
-
/** One entry of a `Menu`: an action that runs `
|
|
6
|
+
/** One entry of a `Menu`: an action that runs `onClick`, or a link to `href`. Never both. */
|
|
7
7
|
export type MenuAction = {
|
|
8
8
|
/** The item's text and its accessible name. */
|
|
9
9
|
label: string;
|
|
@@ -14,15 +14,18 @@ export type MenuAction = {
|
|
|
14
14
|
* @default neutral
|
|
15
15
|
*/
|
|
16
16
|
tone?: IconButtonTone | undefined;
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Why the item cannot be chosen: it is shown dimmed with the reason as a muted line under its
|
|
19
|
+
* label (its description), the arrows skip it and a press does nothing.
|
|
20
|
+
*/
|
|
21
|
+
disabledReason?: string | undefined;
|
|
19
22
|
} & ({
|
|
20
23
|
/** Runs when the item is chosen; the menu then closes and focus goes back to the trigger. */
|
|
21
|
-
|
|
24
|
+
onClick: () => void;
|
|
22
25
|
href?: undefined;
|
|
23
26
|
external?: undefined;
|
|
24
27
|
} | {
|
|
25
|
-
|
|
28
|
+
onClick?: undefined;
|
|
26
29
|
/** Makes the item a link; an in-app path goes through the app's `LinkProvider`. */
|
|
27
30
|
href: string;
|
|
28
31
|
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
@@ -47,12 +50,20 @@ type MenuProps = Passthrough & {
|
|
|
47
50
|
size?: Size | undefined;
|
|
48
51
|
/** Opens on mount, for a story or a test that shows the open menu. */
|
|
49
52
|
defaultOpen?: boolean | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Holds the menu open or shut from the app's own state (a keyboard shortcut that opens it). Pass
|
|
55
|
+
* `onOpenChange` with it, or the trigger, Escape and a choice cannot change it.
|
|
56
|
+
*/
|
|
57
|
+
open?: boolean | undefined;
|
|
58
|
+
/** Runs with the new state when the trigger, Escape, a click outside or a choice opens or shuts it. */
|
|
59
|
+
onOpenChange?: ((open: boolean) => void) | undefined;
|
|
50
60
|
};
|
|
51
61
|
/**
|
|
52
62
|
* A button that opens a short list of actions: the overflow menu at the end of a row, a card header
|
|
53
63
|
* 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 `
|
|
55
|
-
* a new tab), an optional leading `icon`, `tone="danger"` and `
|
|
64
|
+
* one last. `items` are data: each a `label` with `onClick`, or a link with `href` (`external` for
|
|
65
|
+
* a new tab), an optional leading `icon`, `tone="danger"` and `disabledReason`. `open` and
|
|
66
|
+
* `onOpenChange` hold it open from the app's own state.
|
|
56
67
|
*
|
|
57
68
|
* `trigger="icon"` (the default) is a ghost three-dot button named by `label`; `trigger="button"` is
|
|
58
69
|
* an outline button reading `label`. The menu opens below the trigger, aligned to its end, and flips
|
|
@@ -60,5 +71,5 @@ type MenuProps = Passthrough & {
|
|
|
60
71
|
* on the first item, ArrowUp on the last; the arrows, Home, End and a letter move; Enter chooses;
|
|
61
72
|
* Escape closes, and focus goes back to the trigger. `data-*` and `aria-*` land on the trigger.
|
|
62
73
|
*/
|
|
63
|
-
export declare function Menu({ label, items, trigger, size, defaultOpen, ...rest }: MenuProps): ReactElement;
|
|
74
|
+
export declare function Menu({ label, items, trigger, size, defaultOpen, open, onOpenChange, ...rest }: MenuProps): ReactElement;
|
|
64
75
|
export {};
|
package/dist/Menu.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useState } from "react";
|
|
3
|
-
import { Button as AriaButton, Menu as AriaMenu, MenuItem, MenuTrigger, Popover, } from "react-aria-components";
|
|
3
|
+
import { Button as AriaButton, Menu as AriaMenu, MenuItem, MenuTrigger, Popover, Text as AriaText, } from "react-aria-components";
|
|
4
4
|
import { buttonClass } from "./Button.js";
|
|
5
5
|
import { cx } from "./cx.js";
|
|
6
6
|
import { Icon } from "./Icon.js";
|
|
7
7
|
import { look } from "./IconButton.js";
|
|
8
|
+
import { hasReason } from "./blocked.js";
|
|
8
9
|
import { renderLink } from "./link.js";
|
|
9
10
|
import { Tipped } from "./Tooltip.js";
|
|
10
11
|
import { definedProps } from "./props.js";
|
|
11
12
|
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-
|
|
13
|
+
const ITEM = "flex cursor-pointer 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
14
|
const ITEM_TONE = {
|
|
14
15
|
neutral: { ink: "text-slate-900", focused: "bg-slate-100" },
|
|
15
16
|
danger: { ink: "text-red-700", focused: "bg-red-50" },
|
|
@@ -35,8 +36,9 @@ function Face({ icon, label, size }) {
|
|
|
35
36
|
/**
|
|
36
37
|
* A button that opens a short list of actions: the overflow menu at the end of a row, a card header
|
|
37
38
|
* 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 `
|
|
39
|
-
* a new tab), an optional leading `icon`, `tone="danger"` and `
|
|
39
|
+
* one last. `items` are data: each a `label` with `onClick`, or a link with `href` (`external` for
|
|
40
|
+
* a new tab), an optional leading `icon`, `tone="danger"` and `disabledReason`. `open` and
|
|
41
|
+
* `onOpenChange` hold it open from the app's own state.
|
|
40
42
|
*
|
|
41
43
|
* `trigger="icon"` (the default) is a ghost three-dot button named by `label`; `trigger="button"` is
|
|
42
44
|
* an outline button reading `label`. The menu opens below the trigger, aligned to its end, and flips
|
|
@@ -44,7 +46,7 @@ function Face({ icon, label, size }) {
|
|
|
44
46
|
* on the first item, ArrowUp on the last; the arrows, Home, End and a letter move; Enter chooses;
|
|
45
47
|
* Escape closes, and focus goes back to the trigger. `data-*` and `aria-*` land on the trigger.
|
|
46
48
|
*/
|
|
47
|
-
export function Menu({ label, items, trigger = "icon", size = "md", defaultOpen = false, ...rest }) {
|
|
49
|
+
export function Menu({ label, items, trigger = "icon", size = "md", defaultOpen = false, open, onOpenChange, ...rest }) {
|
|
48
50
|
const { container, find } = useDialogOf();
|
|
49
51
|
const icon = trigger === "icon";
|
|
50
52
|
// A pointer opens the menu on its first item, as the keyboard's Enter does (the menu button
|
|
@@ -58,29 +60,29 @@ export function Menu({ label, items, trigger = "icon", size = "md", defaultOpen
|
|
|
58
60
|
}, ...(icon ? { "aria-label": label } : {}), className: icon ? look({ variant: "ghost", size }) : buttonClass("outline", { size }), children: _jsx(Face, { icon: icon, label: label, size: size }) }));
|
|
59
61
|
// The three-dot trigger shows its name as the library's tooltip, as an `IconButton` does. React
|
|
60
62
|
// 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}`))) }) })] }));
|
|
63
|
+
return (_jsxs(MenuTrigger, { defaultOpen: defaultOpen, ...definedProps({ isOpen: open, onOpenChange }), 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
64
|
}
|
|
63
65
|
function Item({ item }) {
|
|
64
66
|
const tone = ITEM_TONE[item.tone ?? "neutral"];
|
|
65
67
|
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,
|
|
68
|
+
const inside = (_jsxs(_Fragment, { children: [item.icon ? _jsx(Icon, { name: item.icon, size: "md" }) : null, _jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx(AriaText, { slot: "label", className: "truncate", children: item.label }), hasReason(item.disabledReason) ? (_jsx(AriaText, { slot: "description", className: "text-xs text-slate-500", children: item.disabledReason })) : null] })] }));
|
|
67
69
|
if (item.href !== undefined) {
|
|
68
70
|
const { href, external = false } = item;
|
|
69
|
-
return (_jsx(MenuItem, { textValue: item.label, href: href, isDisabled: item.
|
|
71
|
+
return (_jsx(MenuItem, { textValue: item.label, href: href, isDisabled: hasReason(item.disabledReason), className: className, render: (props) => {
|
|
70
72
|
// An item with `href` is drawn as an anchor; the `div` form is React Aria's fallback.
|
|
71
73
|
if (!("href" in props))
|
|
72
74
|
return _jsx("div", { ...props });
|
|
73
75
|
// React Aria hands the anchor its role, tab index, handlers and ref; the app's router
|
|
74
76
|
// link draws it when `href` is an in-app path.
|
|
75
|
-
const { href: _href, className: drawn, children
|
|
77
|
+
const { href: _href, className: drawn, children, ...aria } = props;
|
|
76
78
|
return renderLink({
|
|
77
79
|
...aria,
|
|
80
|
+
children,
|
|
78
81
|
href,
|
|
79
82
|
external,
|
|
80
83
|
className: drawn ?? cx(ITEM, tone.ink),
|
|
81
|
-
children: inside,
|
|
82
84
|
});
|
|
83
85
|
}, children: inside }));
|
|
84
86
|
}
|
|
85
|
-
return (_jsx(MenuItem, { textValue: item.label, onAction: item.
|
|
87
|
+
return (_jsx(MenuItem, { textValue: item.label, onAction: item.onClick, isDisabled: hasReason(item.disabledReason), className: className, children: inside }));
|
|
86
88
|
}
|
package/dist/MetaList.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export type MetaListSeparator = "·" | "•" | "none";
|
|
|
6
6
|
/**
|
|
7
7
|
* A wrapping row of facts or links in muted small text, joined by a `·`: branch · SHA · date, or a
|
|
8
8
|
* footer's Privacy · Terms · Email. An item is text, a `Code` or a `TextLink`. The separator is
|
|
9
|
-
* `aria-hidden` and
|
|
10
|
-
* it
|
|
11
|
-
*
|
|
9
|
+
* `aria-hidden` and leads every item in a slot of its own; the list starts one slot before its box,
|
|
10
|
+
* which clips it, so the separator of whichever item starts a line falls outside and no line starts
|
|
11
|
+
* or ends with one, at any width. `separator` swaps it for a `•` or none. An item never breaks
|
|
12
|
+
* inside itself: the row wraps between items. `mono` sets the whole row in the monospace face, for ids and paths.
|
|
12
13
|
* While `loading` with no items it draws three word-sized bones.
|
|
13
14
|
*/
|
|
14
15
|
export declare function MetaList({ mono, separator, loading: ownLoading, loadingLabel, children, ...rest }: {
|
package/dist/MetaList.js
CHANGED
|
@@ -3,12 +3,18 @@ import { Children } from "react";
|
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { Bone, BusyLabel, busy, isEmptySlot, LoadingScope, useLoading, } from "./skeleton.js";
|
|
5
5
|
import { Caption } from "./typography.js";
|
|
6
|
+
/** The width of the slot before each item, and the list's start pulled back by it: a mark with room each side, or a gap alone. */
|
|
7
|
+
const SLOT = {
|
|
8
|
+
mark: { slot: "w-7", list: "-ms-7" },
|
|
9
|
+
none: { slot: "w-3", list: "-ms-3" },
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* A wrapping row of facts or links in muted small text, joined by a `·`: branch · SHA · date, or a
|
|
8
13
|
* footer's Privacy · Terms · Email. An item is text, a `Code` or a `TextLink`. The separator is
|
|
9
|
-
* `aria-hidden` and
|
|
10
|
-
* it
|
|
11
|
-
*
|
|
14
|
+
* `aria-hidden` and leads every item in a slot of its own; the list starts one slot before its box,
|
|
15
|
+
* which clips it, so the separator of whichever item starts a line falls outside and no line starts
|
|
16
|
+
* or ends with one, at any width. `separator` swaps it for a `•` or none. An item never breaks
|
|
17
|
+
* inside itself: the row wraps between items. `mono` sets the whole row in the monospace face, for ids and paths.
|
|
12
18
|
* While `loading` with no items it draws three word-sized bones.
|
|
13
19
|
*/
|
|
14
20
|
export function MetaList({ mono = false, separator = "·", loading: ownLoading, loadingLabel, children, ...rest }) {
|
|
@@ -16,5 +22,7 @@ export function MetaList({ mono = false, separator = "·", loading: ownLoading,
|
|
|
16
22
|
const items = loading && isEmptySlot(children)
|
|
17
23
|
? [0, 1, 2].map((i) => (_jsx(Bone, { shape: "inline-block h-[0.6lh] w-16 rounded align-middle" }, i)))
|
|
18
24
|
: Children.toArray(children);
|
|
19
|
-
|
|
25
|
+
const slot = SLOT[separator === "none" ? "none" : "mark"];
|
|
26
|
+
// The box clips sideways only, with a little room at the start for a link's focus ring.
|
|
27
|
+
return (_jsx("div", { className: "-ms-1 overflow-x-clip ps-1", children: _jsxs("ul", { ...rest, ...busy(owner, loading), className: cx("flex flex-wrap items-center gap-y-1 text-sm text-slate-500", slot.list, mono && "font-mono"), children: [items.map((child, index) => (_jsxs("li", { className: "inline-flex items-center whitespace-nowrap", children: [_jsx("span", { "aria-hidden": "true", className: cx("inline-block text-center", slot.slot), children: separator !== "none" && _jsx(Caption, { as: "span", children: separator }) }), _jsx(LoadingScope, { loading: loading, children: child })] }, index))), owner && loading && (_jsx("li", { className: "sr-only", children: _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel }) }))] }) }));
|
|
20
28
|
}
|
package/dist/Morph.d.ts
CHANGED
|
@@ -31,11 +31,25 @@ export declare function refreshMorphs(): void;
|
|
|
31
31
|
* `prefers-reduced-motion: reduce` it swaps with no animation; a router's own transition of the
|
|
32
32
|
* rest of the page is the router's to quiet. A Morph more than a screen above or below the viewport
|
|
33
33
|
* carries no transition name until it scrolls near, so a long list costs only what is on screen.
|
|
34
|
+
* In a list, `as="li"` makes it the list's item. When one record shows twice on a page, pass
|
|
35
|
+
* `active={false}` to the copy that should not morph; in development two active Morphs with the
|
|
36
|
+
* same `name` and `item` log a console warning.
|
|
34
37
|
*/
|
|
35
|
-
export declare function Morph({ name, item, children, ...rest }: {
|
|
38
|
+
export declare function Morph({ name, item, as, active, children, ...rest }: {
|
|
36
39
|
/** What the element is, shared by the card and its detail: `"shop"`, `"product"`. Any text. */
|
|
37
40
|
name: string;
|
|
38
41
|
/** Which one, usually the record's id. Any text or number; unique on the page for one `name`. */
|
|
39
42
|
item: string | number;
|
|
43
|
+
/**
|
|
44
|
+
* The element it renders: `"div"` (the default), or `"li"` for a card that is an item of a list,
|
|
45
|
+
* so the list stays a `ul` of `li`.
|
|
46
|
+
*/
|
|
47
|
+
as?: "div" | "li" | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Whether it carries its transition name; `true` by default. Pass `false` to every copy but one
|
|
50
|
+
* when the same record shows twice on a page (a featured card and the same card in the list), so
|
|
51
|
+
* only the one that should grow into the detail is named.
|
|
52
|
+
*/
|
|
53
|
+
active?: boolean | undefined;
|
|
40
54
|
children: ReactNode;
|
|
41
55
|
} & Passthrough): ReactElement;
|