@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/Morph.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
3
3
|
import { flushSync } from "react-dom";
|
|
4
4
|
// Keeps letters and digits and writes every other character, `-` and `_` included, as
|
|
5
5
|
// `_<hex code point>_`, so two different pairs never give one name and no character can end the
|
|
@@ -22,6 +22,33 @@ const css = (n) => `[data-morph="${n}"][data-morph-near]{view-transition-name:${
|
|
|
22
22
|
// all (in the browser, with an IntersectionObserver), so on the server or without one the set is
|
|
23
23
|
// empty and refreshMorphs does nothing.
|
|
24
24
|
const remeasures = new Set();
|
|
25
|
+
// How many mounted, active Morphs carry each transition name, so a second one with the same name
|
|
26
|
+
// and item warns in development: the browser skips a morph whose name appears twice on a page.
|
|
27
|
+
const mounted = new Map();
|
|
28
|
+
function isDev() {
|
|
29
|
+
try {
|
|
30
|
+
return process.env.NODE_ENV !== "production";
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Counts a mounted name, warning once when a second element takes it; returns the release. */
|
|
37
|
+
function claim(n, name, item) {
|
|
38
|
+
const count = (mounted.get(n) ?? 0) + 1;
|
|
39
|
+
mounted.set(n, count);
|
|
40
|
+
if (count === 2 && isDev()) {
|
|
41
|
+
// oxlint-disable-next-line no-console -- the one development warning the component gives
|
|
42
|
+
console.warn(`Morph: two mounted Morphs share name "${name}" and item "${String(item)}", so the browser skips the morph. Give each its own item, or pass active={false} to all but one.`);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
const left = (mounted.get(n) ?? 1) - 1;
|
|
46
|
+
if (left === 0)
|
|
47
|
+
mounted.delete(n);
|
|
48
|
+
else
|
|
49
|
+
mounted.set(n, left);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
25
52
|
/**
|
|
26
53
|
* Measures every mounted Morph again, at once, so a card a router has just scrolled on screen
|
|
27
54
|
* carries its transition name before the browser captures the new page. Call it right after the
|
|
@@ -45,25 +72,8 @@ export function refreshMorphs() {
|
|
|
45
72
|
remeasure();
|
|
46
73
|
});
|
|
47
74
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
* the View Transitions API. Wrap the card in the list and the element on the detail page, each with
|
|
51
|
-
* the same `name` and the record's id as `item`: the browser morphs one into the other over 450 ms. The same
|
|
52
|
-
* `name` and `item` may appear only once on a page; two on one page and the browser skips the
|
|
53
|
-
* morph, so a list passes each record's own id. The morph runs only when the change is wrapped in a
|
|
54
|
-
* view transition: `startPageTransition`, or a router's own option (TanStack Router
|
|
55
|
-
* `defaultViewTransition: true` on `createRouter`, or `viewTransition` on a `Link`; React Router's
|
|
56
|
-
* `viewTransition`, Astro's `ClientRouter`). Otherwise, or where the browser has no View
|
|
57
|
-
* Transitions, it renders and behaves as a plain `<div>`. Inside a `PageFade` the page fades while
|
|
58
|
-
* this element morphs. While it is named (near the screen) the div is a stacking context, so a
|
|
59
|
-
* dropdown inside it cannot rise above a sticky header outside it: portal overlays to the body. Under
|
|
60
|
-
* `prefers-reduced-motion: reduce` it swaps with no animation; a router's own transition of the
|
|
61
|
-
* rest of the page is the router's to quiet. A Morph more than a screen above or below the viewport
|
|
62
|
-
* carries no transition name until it scrolls near, so a long list costs only what is on screen.
|
|
63
|
-
*/
|
|
64
|
-
export function Morph({ name, item, children, ...rest }) {
|
|
65
|
-
const n = morphName(name, item);
|
|
66
|
-
const ref = useRef(null);
|
|
75
|
+
/** Whether the element in `ref` is within a screen of the viewport, measured as it scrolls. */
|
|
76
|
+
function useNear(ref) {
|
|
67
77
|
// Named until measured, so the server render and an engine with no IntersectionObserver keep the
|
|
68
78
|
// name. The layout effect's update is flushed with the render, so inside a view transition's
|
|
69
79
|
// update the new page's far cards are already unnamed when the browser captures it. A parent's
|
|
@@ -102,6 +112,44 @@ export function Morph({ name, item, children, ...rest }) {
|
|
|
102
112
|
remeasures.delete(remeasure);
|
|
103
113
|
observer.disconnect();
|
|
104
114
|
};
|
|
105
|
-
}, []);
|
|
106
|
-
return
|
|
115
|
+
}, [ref]);
|
|
116
|
+
return near;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* An element that grows into its counterpart on the next page, and shrinks back on Back, through
|
|
120
|
+
* the View Transitions API. Wrap the card in the list and the element on the detail page, each with
|
|
121
|
+
* the same `name` and the record's id as `item`: the browser morphs one into the other over 450 ms. The same
|
|
122
|
+
* `name` and `item` may appear only once on a page; two on one page and the browser skips the
|
|
123
|
+
* morph, so a list passes each record's own id. The morph runs only when the change is wrapped in a
|
|
124
|
+
* view transition: `startPageTransition`, or a router's own option (TanStack Router
|
|
125
|
+
* `defaultViewTransition: true` on `createRouter`, or `viewTransition` on a `Link`; React Router's
|
|
126
|
+
* `viewTransition`, Astro's `ClientRouter`). Otherwise, or where the browser has no View
|
|
127
|
+
* Transitions, it renders and behaves as a plain `<div>`. Inside a `PageFade` the page fades while
|
|
128
|
+
* this element morphs. While it is named (near the screen) the div is a stacking context, so a
|
|
129
|
+
* dropdown inside it cannot rise above a sticky header outside it: portal overlays to the body. Under
|
|
130
|
+
* `prefers-reduced-motion: reduce` it swaps with no animation; a router's own transition of the
|
|
131
|
+
* rest of the page is the router's to quiet. A Morph more than a screen above or below the viewport
|
|
132
|
+
* carries no transition name until it scrolls near, so a long list costs only what is on screen.
|
|
133
|
+
* In a list, `as="li"` makes it the list's item. When one record shows twice on a page, pass
|
|
134
|
+
* `active={false}` to the copy that should not morph; in development two active Morphs with the
|
|
135
|
+
* same `name` and `item` log a console warning.
|
|
136
|
+
*/
|
|
137
|
+
export function Morph({ name, item, as = "div", active = true, children, ...rest }) {
|
|
138
|
+
const n = morphName(name, item);
|
|
139
|
+
const ref = useRef(null);
|
|
140
|
+
// In development, two active Morphs with one name and item warn: the browser would skip the morph.
|
|
141
|
+
useEffect(() => (active ? claim(n, name, item) : undefined), [active, n, name, item]);
|
|
142
|
+
const near = useNear(ref);
|
|
143
|
+
const named = active && near;
|
|
144
|
+
const style = _jsx("style", { children: css(n) });
|
|
145
|
+
// A grid, so the one child (a Card in a CardGrid) still fills the row's height.
|
|
146
|
+
if (as === "li") {
|
|
147
|
+
// A list holds only `li`, so the stylesheet goes inside the item; a <style> is never a grid item.
|
|
148
|
+
return (_jsxs("li", { ...rest, ref: (el) => {
|
|
149
|
+
ref.current = el;
|
|
150
|
+
}, "data-morph": n, "data-morph-near": named ? "" : undefined, className: "grid", children: [style, children] }));
|
|
151
|
+
}
|
|
152
|
+
return (_jsxs(_Fragment, { children: [style, _jsx("div", { ...rest, ref: (el) => {
|
|
153
|
+
ref.current = el;
|
|
154
|
+
}, "data-morph": n, "data-morph-near": named ? "" : undefined, className: "grid", children: children })] }));
|
|
107
155
|
}
|
|
@@ -6,8 +6,8 @@ import type { Passthrough } from "./props.js";
|
|
|
6
6
|
* and render it once per app, beside the page frame. It draws exactly what `loading` says: the bar
|
|
7
7
|
* while it is true and nothing while it is false. The stylesheet holds it invisible for the first
|
|
8
8
|
* 150ms, so a fast navigation shows nothing. It is fixed to the viewport and overlays the top of
|
|
9
|
-
* the header, so nothing on the page moves. Under `prefers-reduced-motion: reduce`
|
|
10
|
-
* bar.
|
|
9
|
+
* the header, so nothing on the page moves. Under `prefers-reduced-motion: reduce` the segment
|
|
10
|
+
* slides slowly and evenly instead: a still, full bar would read as finished.
|
|
11
11
|
*/
|
|
12
12
|
export declare function NavigationProgress({ loading, label, ...rest }: {
|
|
13
13
|
/** True while a navigation is pending, e.g. from the router's state. */
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forcedFill } from "./cx.js";
|
|
2
3
|
import { BAR_FILL } from "./ProgressBar.js";
|
|
3
4
|
// The one place the bar's motion lives: a stylesheet, as Tailwind classes cannot declare
|
|
4
5
|
// `@keyframes`. Nothing here is a timer in script: the 150ms wait is the opacity animation's own
|
|
5
6
|
// delay (backwards fill, so the bar is invisible until it ends), and a navigation that finishes
|
|
6
7
|
// first removes the bar before it ever showed. A segment slides across the bar; under reduced
|
|
7
|
-
// motion it
|
|
8
|
+
// motion it slides slowly and evenly, still a segment, since a still full-width bar reads as done.
|
|
9
|
+
// No colour in it, which the bar's own class carries.
|
|
8
10
|
const css = `@keyframes hc-navigation-progress-in{from{opacity:0}to{opacity:1}}
|
|
9
11
|
@keyframes hc-navigation-progress{from{transform:translateX(-100%)}to{transform:translateX(250%)}}
|
|
10
12
|
[data-navigation-progress]{animation:hc-navigation-progress-in .01s linear 150ms backwards}
|
|
11
13
|
[data-navigation-progress-bar]{width:40%;animation:hc-navigation-progress 1.4s ease-in-out infinite}
|
|
12
|
-
@media (prefers-reduced-motion:reduce){[data-navigation-progress-bar]{
|
|
14
|
+
@media (prefers-reduced-motion:reduce){[data-navigation-progress-bar]{animation-duration:4s;animation-timing-function:linear}}`;
|
|
13
15
|
/**
|
|
14
16
|
* A thin indeterminate bar along the top edge of the viewport, in the accent tone, for a route
|
|
15
17
|
* change that is under way and has no known length. Pass `loading` from the router's pending state
|
|
16
18
|
* and render it once per app, beside the page frame. It draws exactly what `loading` says: the bar
|
|
17
19
|
* while it is true and nothing while it is false. The stylesheet holds it invisible for the first
|
|
18
20
|
* 150ms, so a fast navigation shows nothing. It is fixed to the viewport and overlays the top of
|
|
19
|
-
* the header, so nothing on the page moves. Under `prefers-reduced-motion: reduce`
|
|
20
|
-
* bar.
|
|
21
|
+
* the header, so nothing on the page moves. Under `prefers-reduced-motion: reduce` the segment
|
|
22
|
+
* slides slowly and evenly instead: a still, full bar would read as finished.
|
|
21
23
|
*/
|
|
22
24
|
export function NavigationProgress({ loading, label = "Loading page", ...rest }) {
|
|
23
25
|
if (!loading)
|
|
24
26
|
return null;
|
|
25
|
-
return (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("div", { ...rest, role: "progressbar", "aria-label": label, "data-navigation-progress": "", className: "pointer-events-none fixed inset-x-0 top-0 z-50 h-[3px] overflow-hidden", children: _jsx("div", { "data-navigation-progress-bar": "", className: `h-full ${BAR_FILL.accent}` }) })] }));
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("div", { ...rest, role: "progressbar", "aria-label": label, "data-navigation-progress": "", className: "pointer-events-none fixed inset-x-0 top-0 z-50 h-[3px] overflow-hidden", children: _jsx("div", { "data-navigation-progress-bar": "", className: `h-full ${BAR_FILL.accent} ${forcedFill}` }) })] }));
|
|
26
28
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { type ControlProps } from "./control.js";
|
|
3
|
+
import { type Passthrough } from "./props.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
export type NumberFieldProps = {
|
|
6
|
+
/** The field's visible label, above it. Without one, name the field with `aria-label`. */
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
/** A muted line under the field that says more; it stays while an error shows under it. */
|
|
9
|
+
hint?: ReactNode;
|
|
10
|
+
/** Marks the field invalid and shows this in red under the hint, announced politely. */
|
|
11
|
+
error?: ReactNode;
|
|
12
|
+
/** The number shown, controlled, with `onChange`. `NaN` is an empty field. */
|
|
13
|
+
value?: number | undefined;
|
|
14
|
+
/** The number it starts with, uncontrolled. */
|
|
15
|
+
defaultValue?: number | undefined;
|
|
16
|
+
/** Called with the new number when it is committed (a step, or leaving the field); `NaN` when it is cleared. */
|
|
17
|
+
onChange?: ((value: number) => void) | undefined;
|
|
18
|
+
/** The smallest number allowed: the minus button stops there, and a smaller typed one is raised to it. */
|
|
19
|
+
minValue?: number | undefined;
|
|
20
|
+
/** The largest number allowed: the plus button stops there, and a larger typed one is lowered to it. */
|
|
21
|
+
maxValue?: number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* How far one press of a button or an arrow key moves the number; a typed number snaps to it.
|
|
24
|
+
* @default 1
|
|
25
|
+
*/
|
|
26
|
+
step?: number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* How the number is written, in the locale of the app's `I18nProvider` or else the browser's:
|
|
29
|
+
* `{ style: "currency", currency: "EUR" }`, `{ style: "percent" }`, `{ maximumFractionDigits: 2 }`.
|
|
30
|
+
* The person types in the same format.
|
|
31
|
+
*/
|
|
32
|
+
formatOptions?: Intl.NumberFormatOptions | undefined;
|
|
33
|
+
/** Posts the number in a form under this key, as plain digits whatever the format. */
|
|
34
|
+
name?: string | undefined;
|
|
35
|
+
/** Disables the field and its buttons. */
|
|
36
|
+
disabled?: boolean | undefined;
|
|
37
|
+
/** Marks the number required: the field is `aria-required`, and an empty one is invalid. */
|
|
38
|
+
required?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the minus button, for an app in another language.
|
|
41
|
+
* @default Decrease
|
|
42
|
+
*/
|
|
43
|
+
decrementLabel?: string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The name of the plus button, for an app in another language.
|
|
46
|
+
* @default Increase
|
|
47
|
+
*/
|
|
48
|
+
incrementLabel?: string | undefined;
|
|
49
|
+
} & ControlProps & LoadingProps & Passthrough;
|
|
50
|
+
/** The stepper's size tables and their `md:` twins, for the data test. */
|
|
51
|
+
export declare const numberSizeTables: {
|
|
52
|
+
box: Record<import("./size.js").Size, string>;
|
|
53
|
+
boxMd: Record<import("./size.js").Size, string>;
|
|
54
|
+
icon: Record<import("./size.js").Size, string>;
|
|
55
|
+
iconMd: Record<import("./size.js").Size, string>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A number with a minus and a plus button either side of it, for a quantity, a count or an amount:
|
|
59
|
+
* React Aria's `NumberField`. The person types the number or steps it by `step` with the buttons,
|
|
60
|
+
* the arrow keys, Page Up and Page Down; `minValue` and `maxValue` stop the buttons and clamp a
|
|
61
|
+
* typed number when the field is left. `formatOptions` writes it as a currency, a percent or with
|
|
62
|
+
* fixed decimals in the app's locale, and the person types in that format. `label`, `hint`, `error`,
|
|
63
|
+
* `required` and `disabled` are a `DateField`'s; `size` and `width` an `Input`'s. While `loading`
|
|
64
|
+
* the label is drawn and the field is a bone of its height.
|
|
65
|
+
*/
|
|
66
|
+
export declare function NumberField({ loading, loadingLabel, ...field }: NumberFieldProps): ReactElement;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, FieldError, Group, Input, NumberField as AriaNumberField, Text, } from "react-aria-components";
|
|
3
|
+
import { CONTROL_WIDTH, controlHeight } from "./control.js";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { fieldFlags, FieldLabel, frameClass, useLabelClass } from "./DateField.js";
|
|
6
|
+
import { controlText, useFieldType, useTypeStep } from "./density.js";
|
|
7
|
+
import { ErrorLine } from "./Field.js";
|
|
8
|
+
import { WaitingField } from "./fieldWait.js";
|
|
9
|
+
import { iconGlyph } from "./icons.js";
|
|
10
|
+
import { definedProps } from "./props.js";
|
|
11
|
+
import { sizeClass } from "./size.js";
|
|
12
|
+
import { useLoading } from "./skeleton.js";
|
|
13
|
+
/** A stepper button's width, by `size`: square with the field's height. */
|
|
14
|
+
const STEP_BOX = { sm: "w-6.5", md: "w-9.5", lg: "w-11.5" };
|
|
15
|
+
const STEP_BOX_MD = {
|
|
16
|
+
sm: "md:w-6.5",
|
|
17
|
+
md: "md:w-9.5",
|
|
18
|
+
lg: "md:w-11.5",
|
|
19
|
+
};
|
|
20
|
+
/** A stepper button's icon, by `size`. */
|
|
21
|
+
const STEP_ICON = {
|
|
22
|
+
sm: "[&>svg]:size-3.5",
|
|
23
|
+
md: "[&>svg]:size-4",
|
|
24
|
+
lg: "[&>svg]:size-5",
|
|
25
|
+
};
|
|
26
|
+
const STEP_ICON_MD = {
|
|
27
|
+
sm: "md:[&>svg]:size-3.5",
|
|
28
|
+
md: "md:[&>svg]:size-4",
|
|
29
|
+
lg: "md:[&>svg]:size-5",
|
|
30
|
+
};
|
|
31
|
+
/** The stepper's size tables and their `md:` twins, for the data test. */
|
|
32
|
+
export const numberSizeTables = {
|
|
33
|
+
box: STEP_BOX,
|
|
34
|
+
boxMd: STEP_BOX_MD,
|
|
35
|
+
icon: STEP_ICON,
|
|
36
|
+
iconMd: STEP_ICON_MD,
|
|
37
|
+
};
|
|
38
|
+
const STEP_LOOK = "flex shrink-0 cursor-pointer items-center justify-center self-stretch text-slate-500 transition hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-50";
|
|
39
|
+
/** A minus or plus button. React Aria keeps it out of the tab order: the arrow keys step the number. */
|
|
40
|
+
function StepButton({ slot, label, size, }) {
|
|
41
|
+
return (_jsx(Button, { slot: slot, "aria-label": label, className: cx(STEP_LOOK, slot === "decrement" ? "rounded-l-lg" : "rounded-r-lg", sizeClass(STEP_BOX, STEP_BOX_MD, size), sizeClass(STEP_ICON, STEP_ICON_MD, size)), children: iconGlyph(slot === "decrement" ? "minus" : "plus") }));
|
|
42
|
+
}
|
|
43
|
+
/** The hint and, under it, the error line: the given `error`, or React Aria's own message. */
|
|
44
|
+
function NumberNotes({ hint, error }) {
|
|
45
|
+
const { note } = useFieldType();
|
|
46
|
+
return (_jsxs(_Fragment, { children: [hint ? (_jsx(Text, { slot: "description", className: cx("text-slate-500", note), children: hint })) : null, _jsx(FieldError, { className: "block", children: (validation) => _jsx(ErrorLine, { error: error || validation.validationErrors.join(" ") }) })] }));
|
|
47
|
+
}
|
|
48
|
+
/** A number field drawn: the label, the minus button, the number, the plus button, the notes. */
|
|
49
|
+
function ShownNumberField({ label, hint, error, disabled, required, size = "md", width = "full", decrementLabel = "Decrease", incrementLabel = "Increase", ...rest }) {
|
|
50
|
+
const step = useTypeStep();
|
|
51
|
+
return (_jsxs(AriaNumberField, { ...definedProps(rest), ...fieldFlags(disabled, required), ...(error ? { isInvalid: true } : {}), className: cx("flex flex-col gap-1.5", CONTROL_WIDTH[width]), children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), controlHeight(size)), children: [_jsx(StepButton, { slot: "decrement", label: decrementLabel, size: size }), _jsx(Input, { className: cx("h-full min-w-0 flex-1 bg-white text-center tabular-nums text-slate-900 outline-none", controlText(size, step, true)) }), _jsx(StepButton, { slot: "increment", label: incrementLabel, size: size })] }), _jsx(NumberNotes, { hint: hint, error: error })] }));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A number with a minus and a plus button either side of it, for a quantity, a count or an amount:
|
|
55
|
+
* React Aria's `NumberField`. The person types the number or steps it by `step` with the buttons,
|
|
56
|
+
* the arrow keys, Page Up and Page Down; `minValue` and `maxValue` stop the buttons and clamp a
|
|
57
|
+
* typed number when the field is left. `formatOptions` writes it as a currency, a percent or with
|
|
58
|
+
* fixed decimals in the app's locale, and the person types in that format. `label`, `hint`, `error`,
|
|
59
|
+
* `required` and `disabled` are a `DateField`'s; `size` and `width` an `Input`'s. While `loading`
|
|
60
|
+
* the label is drawn and the field is a bone of its height.
|
|
61
|
+
*/
|
|
62
|
+
export function NumberField({ loading, loadingLabel, ...field }) {
|
|
63
|
+
const labelClass = useLabelClass();
|
|
64
|
+
if (useLoading(loading).loading) {
|
|
65
|
+
return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
|
|
66
|
+
}
|
|
67
|
+
return _jsx(ShownNumberField, { ...field });
|
|
68
|
+
}
|
package/dist/OutlineRegion.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ImgHTMLAttributes, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { type ImageAspect, type ImageWidth } from "./Image.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import type { Tone } from "./tone.js";
|
|
5
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
6
|
/** A box in a picture's own units (an image's pixels): its top-left corner and its size. */
|
|
5
7
|
export type RegionRect = {
|
|
6
8
|
x: number;
|
|
@@ -8,6 +10,12 @@ export type RegionRect = {
|
|
|
8
10
|
width: number;
|
|
9
11
|
height: number;
|
|
10
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* An `OutlineRegion`'s colour: `accent` (the default), or the shared `Tone`s that have a strong
|
|
15
|
+
* edge, `positive`, `warn` and `danger`. `neutral` and `info` are left out: their edges are pale
|
|
16
|
+
* lines that would not stand out on a picture.
|
|
17
|
+
*/
|
|
18
|
+
export type OutlineRegionTone = "accent" | Extract<Tone, "positive" | "warn" | "danger">;
|
|
11
19
|
/**
|
|
12
20
|
* An accent outline over one area of a picture, such as a screenshot's ignored or flagged region.
|
|
13
21
|
* `rect` is in the picture's own units and `within` is the picture's full size in the same units;
|
|
@@ -15,8 +23,13 @@ export type RegionRect = {
|
|
|
15
23
|
* over the picture. `label` is a small tag in its top-left
|
|
16
24
|
* corner; `hatched` stripes the inside, for an area that is left out. It takes no pointer events,
|
|
17
25
|
* so it never blocks the picture or a layer drawn over it.
|
|
26
|
+
*
|
|
27
|
+
* `tone` colours it by what the area is (`positive`, `warn`, `danger`; `accent` by default),
|
|
28
|
+
* `dashed` draws the edge dashed, for an area that is proposed or approximate, and `active` draws a
|
|
29
|
+
* thicker edge, for the one region the app has picked (the one hovered in a list beside the
|
|
30
|
+
* picture, say). The app sets `active`; the region has no hover state of its own.
|
|
18
31
|
*/
|
|
19
|
-
export declare function OutlineRegion({ rect, within, label, hatched, ...rest }: {
|
|
32
|
+
export declare function OutlineRegion({ rect, within, label, hatched, tone, dashed, active, ...rest }: {
|
|
20
33
|
/** The area, in the picture's own units. */
|
|
21
34
|
rect: RegionRect;
|
|
22
35
|
/** The picture's full size, in the same units as `rect`. */
|
|
@@ -28,11 +41,27 @@ export declare function OutlineRegion({ rect, within, label, hatched, ...rest }:
|
|
|
28
41
|
label?: ReactNode;
|
|
29
42
|
/** Stripes the inside, for an area left out (ignored, masked). */
|
|
30
43
|
hatched?: boolean | undefined;
|
|
31
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The colour: `accent`, `positive`, `warn` or `danger`.
|
|
46
|
+
* @default accent
|
|
47
|
+
*/
|
|
48
|
+
tone?: OutlineRegionTone | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Draws the edge dashed, for an area that is proposed or approximate.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
dashed?: boolean | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Draws a thicker edge, for the region the app has picked. The app sets it; there is no hover state.
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
active?: boolean | undefined;
|
|
59
|
+
} & Passthrough): ReactElement;
|
|
32
60
|
/**
|
|
33
61
|
* A picture with a hairline edge, and `children` laid over it: the `OutlineRegion`s that mark its
|
|
34
|
-
* areas.
|
|
35
|
-
*
|
|
62
|
+
* areas. `onLoad`, `id`, `data-*` and `aria-*` go to the `<img>`, so the app can read the picture's
|
|
63
|
+
* own size for `within`. While `loading` with no `src` yet it is a bone of the frame's shape (4:3
|
|
64
|
+
* for a `natural` one), as an `Image` is.
|
|
36
65
|
*
|
|
37
66
|
* It sizes as `Image` does. `width` is `full` (the parent's width) or 96, 160 or 256px. `aspect`
|
|
38
67
|
* `natural` keeps the picture's own proportions; any other shape letterboxes it (contain, never a
|
|
@@ -40,9 +69,9 @@ export declare function OutlineRegion({ rect, within, label, hatched, ...rest }:
|
|
|
40
69
|
* picture itself, not the box, so each stays on its spot. A letterboxed picture needs its own size:
|
|
41
70
|
* a screenshot has one; an SVG needs `width` and `height` on its root, not only a `viewBox`.
|
|
42
71
|
*/
|
|
43
|
-
export declare function RegionFrame({ src, alt, aspect, width, children, ...rest }: {
|
|
44
|
-
/** The picture
|
|
45
|
-
src
|
|
72
|
+
export declare function RegionFrame({ src, alt, aspect, width, loading, loadingLabel, children, ...rest }: {
|
|
73
|
+
/** The picture; left out while it is not known yet, with `loading`. */
|
|
74
|
+
src?: string | undefined;
|
|
46
75
|
/** What the picture shows; `""` for one that only decorates. */
|
|
47
76
|
alt: string;
|
|
48
77
|
/**
|
|
@@ -57,4 +86,6 @@ export declare function RegionFrame({ src, alt, aspect, width, children, ...rest
|
|
|
57
86
|
width?: ImageWidth | undefined;
|
|
58
87
|
/** The `OutlineRegion`s over the picture. */
|
|
59
88
|
children?: ReactNode;
|
|
60
|
-
} &
|
|
89
|
+
} & LoadingProps & Passthrough &
|
|
90
|
+
/** Fires once the picture is in, so the app can read its own size for `within`. */
|
|
91
|
+
Pick<ImgHTMLAttributes<HTMLImageElement>, "onLoad">): ReactElement;
|
package/dist/OutlineRegion.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cx } from "./cx.js";
|
|
3
3
|
import { IMAGE_WIDTH } from "./Image.js";
|
|
4
|
+
import { passthroughOf, useLoading, WaitingBone } from "./skeleton.js";
|
|
4
5
|
/** Thin accent stripes, drawn in the box's own colour, for an area that is left out. */
|
|
5
6
|
const HATCH = "absolute inset-0 opacity-40 bg-[repeating-linear-gradient(45deg,currentColor_0_1px,transparent_1px_6px)]";
|
|
7
|
+
/** Each tone's outline (with the hatch's colour) and its tag. */
|
|
8
|
+
const REGION_TONE = {
|
|
9
|
+
accent: { box: "border-violet-600 text-violet-600", tag: "bg-violet-600 text-violet-50" },
|
|
10
|
+
positive: { box: "border-emerald-600 text-emerald-700", tag: "bg-emerald-600 text-emerald-50" },
|
|
11
|
+
warn: { box: "border-amber-600 text-amber-700", tag: "bg-amber-50 text-amber-800" },
|
|
12
|
+
danger: { box: "border-red-600 text-red-700", tag: "bg-red-600 text-red-50" },
|
|
13
|
+
};
|
|
6
14
|
/**
|
|
7
15
|
* An accent outline over one area of a picture, such as a screenshot's ignored or flagged region.
|
|
8
16
|
* `rect` is in the picture's own units and `within` is the picture's full size in the same units;
|
|
@@ -10,20 +18,27 @@ const HATCH = "absolute inset-0 opacity-40 bg-[repeating-linear-gradient(45deg,c
|
|
|
10
18
|
* over the picture. `label` is a small tag in its top-left
|
|
11
19
|
* corner; `hatched` stripes the inside, for an area that is left out. It takes no pointer events,
|
|
12
20
|
* so it never blocks the picture or a layer drawn over it.
|
|
21
|
+
*
|
|
22
|
+
* `tone` colours it by what the area is (`positive`, `warn`, `danger`; `accent` by default),
|
|
23
|
+
* `dashed` draws the edge dashed, for an area that is proposed or approximate, and `active` draws a
|
|
24
|
+
* thicker edge, for the one region the app has picked (the one hovered in a list beside the
|
|
25
|
+
* picture, say). The app sets `active`; the region has no hover state of its own.
|
|
13
26
|
*/
|
|
14
|
-
export function OutlineRegion({ rect, within, label, hatched = false, ...rest }) {
|
|
15
|
-
|
|
27
|
+
export function OutlineRegion({ rect, within, label, hatched = false, tone = "accent", dashed = false, active = false, ...rest }) {
|
|
28
|
+
const colour = REGION_TONE[tone];
|
|
29
|
+
return (_jsxs("div", { ...rest, className: cx("pointer-events-none absolute", active ? "border-4" : "border-2", dashed && "border-dashed", colour.box), style: {
|
|
16
30
|
left: `${(rect.x / within.width) * 100}%`,
|
|
17
31
|
top: `${(rect.y / within.height) * 100}%`,
|
|
18
32
|
width: `${(rect.width / within.width) * 100}%`,
|
|
19
33
|
height: `${(rect.height / within.height) * 100}%`,
|
|
20
|
-
}, children: [hatched && _jsx("span", { "aria-hidden": "true", className: HATCH }), label != null && (_jsx("span", { className: "absolute top-0 left-0
|
|
34
|
+
}, children: [hatched && _jsx("span", { "aria-hidden": "true", className: HATCH }), label != null && (_jsx("span", { className: cx("absolute top-0 left-0 px-1 text-xs leading-tight", colour.tag), children: label }))] }));
|
|
21
35
|
}
|
|
22
36
|
/** The shapes `RegionFrame` letterboxes a picture into, as `Image`'s `aspect`, or `natural` (its own). */
|
|
23
37
|
const FRAME_ASPECT = {
|
|
24
38
|
square: "aspect-square",
|
|
25
39
|
"4:3": "aspect-[4/3]",
|
|
26
40
|
"3:2": "aspect-[3/2]",
|
|
41
|
+
"16:10": "aspect-[16/10]",
|
|
27
42
|
"16:9": "aspect-video",
|
|
28
43
|
"3:4": "aspect-[3/4]",
|
|
29
44
|
"9:16": "aspect-[9/16]",
|
|
@@ -31,8 +46,9 @@ const FRAME_ASPECT = {
|
|
|
31
46
|
};
|
|
32
47
|
/**
|
|
33
48
|
* A picture with a hairline edge, and `children` laid over it: the `OutlineRegion`s that mark its
|
|
34
|
-
* areas.
|
|
35
|
-
*
|
|
49
|
+
* areas. `onLoad`, `id`, `data-*` and `aria-*` go to the `<img>`, so the app can read the picture's
|
|
50
|
+
* own size for `within`. While `loading` with no `src` yet it is a bone of the frame's shape (4:3
|
|
51
|
+
* for a `natural` one), as an `Image` is.
|
|
36
52
|
*
|
|
37
53
|
* It sizes as `Image` does. `width` is `full` (the parent's width) or 96, 160 or 256px. `aspect`
|
|
38
54
|
* `natural` keeps the picture's own proportions; any other shape letterboxes it (contain, never a
|
|
@@ -40,7 +56,16 @@ const FRAME_ASPECT = {
|
|
|
40
56
|
* picture itself, not the box, so each stays on its spot. A letterboxed picture needs its own size:
|
|
41
57
|
* a screenshot has one; an SVG needs `width` and `height` on its root, not only a `viewBox`.
|
|
42
58
|
*/
|
|
43
|
-
export function RegionFrame({ src, alt, aspect = "natural", width = "full", children, ...rest }) {
|
|
59
|
+
export function RegionFrame({ src, alt, aspect = "natural", width = "full", loading, loadingLabel, children, ...rest }) {
|
|
60
|
+
const waiting = useLoading(loading).loading;
|
|
61
|
+
if (!src) {
|
|
62
|
+
// No picture yet: a bone while it is on its way, else the empty frame of its shape.
|
|
63
|
+
const shape = aspect === "natural" ? "aspect-[4/3]" : FRAME_ASPECT[aspect];
|
|
64
|
+
if (waiting) {
|
|
65
|
+
return (_jsx(WaitingBone, { own: loading, label: loadingLabel, shape: cx("block w-full", shape), root: cx("block", IMAGE_WIDTH[width]), attrs: alt ? { ...passthroughOf(rest), role: "img", "aria-label": alt } : passthroughOf(rest) }));
|
|
66
|
+
}
|
|
67
|
+
return (_jsx("div", { ...passthroughOf(rest), ...(alt ? { role: "img", "aria-label": alt } : {}), className: cx("relative border border-slate-200 bg-slate-100", shape, IMAGE_WIDTH[width]), children: children }));
|
|
68
|
+
}
|
|
44
69
|
if (aspect === "natural") {
|
|
45
70
|
return (_jsxs("div", { className: cx("relative border border-slate-200", IMAGE_WIDTH[width]), children: [_jsx("img", { ...rest, src: src, alt: alt, className: "block w-full" }), children] }));
|
|
46
71
|
}
|
package/dist/PageFade.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import type { Passthrough } from "./props.js";
|
|
|
14
14
|
* cannot rise above a sticky header outside it: portal overlays to the body. The default one is
|
|
15
15
|
* not. Under `prefers-reduced-motion: reduce` the content swaps with no fade; a named one quiets
|
|
16
16
|
* only its own box, and a router's own transition of the rest of the page is the router's to quiet.
|
|
17
|
+
* It is where `startPageTransition` puts the focus after the change: it takes focus from script,
|
|
18
|
+
* never from Tab, and draws no ring for it.
|
|
17
19
|
*/
|
|
18
20
|
export declare function PageFade({ name, children, ...rest }: {
|
|
19
21
|
/** A view-transition name for this box, a CSS identifier (letters, digits, `-`, `_`), for a region no taller than the screen that fades apart from the page. */
|
|
@@ -21,10 +23,12 @@ export declare function PageFade({ name, children, ...rest }: {
|
|
|
21
23
|
children: ReactNode;
|
|
22
24
|
} & Passthrough): ReactElement;
|
|
23
25
|
/**
|
|
24
|
-
* Run `update` inside a view transition, so a `PageFade` cross-fades
|
|
25
|
-
*
|
|
26
|
-
* is
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* Run `update` inside a view transition, so a `PageFade` cross-fades, then move the focus to the
|
|
27
|
+
* new view (the page's `PageFade`), unless it is on a tab or a radio, which switch in place.
|
|
28
|
+
* `update` is a synchronous state change, flushed at once as the browser needs the new DOM; for a
|
|
29
|
+
* router's navigation, which is async, use the router's own view-transition option instead (and its
|
|
30
|
+
* own focus handling). Where the browser has no View Transitions, or the user prefers reduced
|
|
31
|
+
* motion, `update` just runs, and the focus moves the same. Call it from an event handler, not
|
|
32
|
+
* during render.
|
|
29
33
|
*/
|
|
30
34
|
export declare function startPageTransition(update: () => void): void;
|
package/dist/PageFade.js
CHANGED
|
@@ -24,23 +24,54 @@ const css = (name) => name === undefined
|
|
|
24
24
|
* cannot rise above a sticky header outside it: portal overlays to the body. The default one is
|
|
25
25
|
* not. Under `prefers-reduced-motion: reduce` the content swaps with no fade; a named one quiets
|
|
26
26
|
* only its own box, and a router's own transition of the rest of the page is the router's to quiet.
|
|
27
|
+
* It is where `startPageTransition` puts the focus after the change: it takes focus from script,
|
|
28
|
+
* never from Tab, and draws no ring for it.
|
|
27
29
|
*/
|
|
28
30
|
export function PageFade({ name, children, ...rest }) {
|
|
29
|
-
return (_jsxs(_Fragment, { children: [_jsx("style", { children: css(name) }), _jsx("div", { ...rest, "data-page-fade": name, children: children })] }));
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { children: css(name) }), _jsx("div", { ...rest, "data-page-fade": name, "data-page-view": "", className: "focus:outline-none", children: children })] }));
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
34
|
+
* Put the focus on the new view: the page's `PageFade` (the unnamed one, else the first), so the
|
|
35
|
+
* keyboard and a screen reader continue from the new content, not from a control left behind or
|
|
36
|
+
* the top of the page. Focus on a tab or a radio (Tabs, SegmentedControl) stays: those switch a
|
|
37
|
+
* view in place and keep their own arrow keys.
|
|
38
|
+
*/
|
|
39
|
+
function focusView(before) {
|
|
40
|
+
const active = document.activeElement;
|
|
41
|
+
if (active instanceof Element && active.closest('[role="tab"],[role="radio"]'))
|
|
42
|
+
return;
|
|
43
|
+
// The new view put the focus somewhere itself (an `autoFocus` field): leave it there.
|
|
44
|
+
if (active !== before && active !== document.body && active !== null)
|
|
45
|
+
return;
|
|
46
|
+
const views = [...document.querySelectorAll("[data-page-view]")];
|
|
47
|
+
const view = views.find((el) => !el.hasAttribute("data-page-fade")) ?? views[0];
|
|
48
|
+
if (!view)
|
|
49
|
+
return;
|
|
50
|
+
if (!view.hasAttribute("tabindex"))
|
|
51
|
+
view.tabIndex = -1;
|
|
52
|
+
view.focus({ preventScroll: true });
|
|
53
|
+
}
|
|
54
|
+
/** Run `update` now, so the DOM is the new view's, then move the focus to it. */
|
|
55
|
+
function swap(update) {
|
|
56
|
+
const before = document.activeElement;
|
|
57
|
+
flushSync(update);
|
|
58
|
+
focusView(before);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Run `update` inside a view transition, so a `PageFade` cross-fades, then move the focus to the
|
|
62
|
+
* new view (the page's `PageFade`), unless it is on a tab or a radio, which switch in place.
|
|
63
|
+
* `update` is a synchronous state change, flushed at once as the browser needs the new DOM; for a
|
|
64
|
+
* router's navigation, which is async, use the router's own view-transition option instead (and its
|
|
65
|
+
* own focus handling). Where the browser has no View Transitions, or the user prefers reduced
|
|
66
|
+
* motion, `update` just runs, and the focus moves the same. Call it from an event handler, not
|
|
67
|
+
* during render.
|
|
37
68
|
*/
|
|
38
69
|
export function startPageTransition(update) {
|
|
39
70
|
const reduce = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
40
71
|
if (reduce || typeof document.startViewTransition !== "function") {
|
|
41
|
-
update
|
|
72
|
+
swap(update);
|
|
42
73
|
return;
|
|
43
74
|
}
|
|
44
75
|
// A skipped transition (a second one starting, a hidden tab) rejects `ready`; the update still ran.
|
|
45
|
-
document.startViewTransition(() =>
|
|
76
|
+
document.startViewTransition(() => swap(update)).ready.catch(() => { });
|
|
46
77
|
}
|
package/dist/PageLayouts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { type PageHeaderProps } from "./PageHeader.js";
|
|
3
|
-
import { type StackGap } from "./Stack.js";
|
|
3
|
+
import { type StackGap, type StackWidth } from "./Stack.js";
|
|
4
4
|
import type { Passthrough, Unstyled } from "./props.js";
|
|
5
5
|
export { CardGrid } from "./CardGrid.js";
|
|
6
6
|
import { type LoadingProps } from "./skeleton.js";
|
|
@@ -32,10 +32,15 @@ export declare function DetailLayout({ aside, asideLabel, sticky, children, brea
|
|
|
32
32
|
sticky?: boolean | undefined;
|
|
33
33
|
children: ReactNode;
|
|
34
34
|
} & Passthrough): ReactElement;
|
|
35
|
-
/** A form page: header (no header `actions`), then a `max-w-3xl` column that starts at the Container's start edge (it is not re-centred), with an `actions` row at the end. `error` is the submit's failure, a danger `Callout` (an alert) directly above that row. Other props go on the `<form>`. While `loading` it owns the wait and passes it to everything inside, the header too. */
|
|
36
|
-
export declare function FormLayout({ actions, error, children, breadcrumbs, title, description, tabs, loading, loadingLabel, ...form }: Omit<PageHeaderProps, "actions"> & {
|
|
35
|
+
/** A form page: header (no header `actions`), then a `max-w-3xl` column that starts at the Container's start edge (it is not re-centred), with an `actions` row at the end. `note` is a muted line under that row, set apart from the form: a closing remark about the whole submit (when you will hear back, what happens next), never a field's hint. `error` is the submit's failure, a danger `Callout` (an alert) directly above that row. Other props go on the `<form>`. While `loading` it owns the wait and passes it to everything inside, the header too. */
|
|
36
|
+
export declare function FormLayout({ actions, note, error, children, breadcrumbs, title, description, tabs, loading, loadingLabel, ...form }: Omit<PageHeaderProps, "actions"> & {
|
|
37
37
|
/** The row at the end of the form: its submit and cancel buttons. */
|
|
38
38
|
actions?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* A muted line under the `actions`, set apart from them: a closing remark about the whole form
|
|
41
|
+
* ("We reply within two working days."). A note about one field is that `Field`'s `hint`.
|
|
42
|
+
*/
|
|
43
|
+
note?: ReactNode;
|
|
39
44
|
/**
|
|
40
45
|
* What went wrong with the whole submit (the server refused it, no connection), announced as an
|
|
41
46
|
* alert directly above the `actions`. An error about one field is that `Field`'s `error`.
|
|
@@ -43,6 +48,11 @@ export declare function FormLayout({ actions, error, children, breadcrumbs, titl
|
|
|
43
48
|
error?: ReactNode;
|
|
44
49
|
children: ReactNode;
|
|
45
50
|
} & Unstyled<Omit<ComponentPropsWithoutRef<"form">, "title">>): ReactElement;
|
|
51
|
+
/**
|
|
52
|
+
* The `StackWidth`s a text page takes. `compact` (28rem) is one card's column, too narrow for a page
|
|
53
|
+
* of text with a header, and `default` would be `full` under a second name in a page column.
|
|
54
|
+
*/
|
|
55
|
+
type ProseWidth = Extract<StackWidth, "narrow" | "wide" | "full">;
|
|
46
56
|
/**
|
|
47
57
|
* A text page: header, then `children` stacked `gap` apart (`md` by default), all in one column that
|
|
48
58
|
* starts at the Container's start edge (it is not re-centred, so the title does not jump). `width`
|
|
@@ -59,10 +69,10 @@ export declare function ProseLayout({ width, gap, children, breadcrumbs, title,
|
|
|
59
69
|
*/
|
|
60
70
|
gap?: StackGap | undefined;
|
|
61
71
|
/**
|
|
62
|
-
* The column's width: `narrow` max-w-3xl, `wide` max-w-5xl, `full` the Container's width.
|
|
72
|
+
* The column's width, as a `Stack`'s: `narrow` max-w-3xl, `wide` max-w-5xl, `full` the Container's width.
|
|
63
73
|
* @default narrow
|
|
64
74
|
*/
|
|
65
|
-
width?:
|
|
75
|
+
width?: ProseWidth | undefined;
|
|
66
76
|
children?: ReactNode;
|
|
67
77
|
} & Passthrough): ReactElement;
|
|
68
78
|
/**
|