@slashsuite/ui-react 0.12.0 → 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 +101 -44
- package/agent-docs/components/app-shell.md +139 -0
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/avatar-stack.md +64 -0
- package/agent-docs/components/avatar.md +76 -0
- package/agent-docs/components/badge.md +62 -0
- package/agent-docs/components/body-text.md +169 -0
- package/agent-docs/components/bottom-sheet.md +105 -0
- package/agent-docs/components/breadcrumbs.md +66 -0
- package/agent-docs/components/bullet-list.md +54 -0
- package/agent-docs/components/button.md +135 -0
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +87 -0
- package/agent-docs/components/card-grid.md +116 -0
- package/agent-docs/components/card.md +128 -0
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/centered-layout.md +90 -0
- package/agent-docs/components/chat-composer.md +49 -0
- package/agent-docs/components/chat-message.md +61 -0
- package/agent-docs/components/chat-thread.md +49 -0
- package/agent-docs/components/checkbox.md +81 -0
- package/agent-docs/components/cluster.md +108 -0
- package/agent-docs/components/code-example.md +48 -0
- package/agent-docs/components/code.md +72 -0
- package/agent-docs/components/colour-scheme-toggle.md +98 -0
- 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 +51 -0
- package/agent-docs/components/copy-button.md +63 -0
- package/agent-docs/components/copy-line.md +55 -0
- package/agent-docs/components/date-field.md +106 -0
- package/agent-docs/components/date-range-picker.md +108 -0
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/detail-layout.md +147 -0
- package/agent-docs/components/dialog.md +132 -0
- package/agent-docs/components/disclosure.md +70 -0
- package/agent-docs/components/divider.md +62 -0
- package/agent-docs/components/docs-layout.md +164 -0
- package/agent-docs/components/drawer.md +137 -0
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +70 -0
- package/agent-docs/components/field-dialog.md +98 -0
- package/agent-docs/components/field.md +71 -0
- package/agent-docs/components/fieldset.md +82 -0
- package/agent-docs/components/file-drop.md +52 -0
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +144 -0
- package/agent-docs/components/form-row.md +93 -0
- package/agent-docs/components/full-bleed-layout.md +114 -0
- package/agent-docs/components/headings.md +107 -0
- package/agent-docs/components/hero.md +68 -0
- package/agent-docs/components/icon-button.md +90 -0
- package/agent-docs/components/icon.md +59 -0
- package/agent-docs/components/image.md +74 -0
- package/agent-docs/components/input.md +84 -0
- package/agent-docs/components/kbd.md +38 -0
- package/agent-docs/components/key-value-list.md +84 -0
- package/agent-docs/components/lightbox.md +97 -0
- package/agent-docs/components/list-layout.md +152 -0
- package/agent-docs/components/list-row.md +119 -0
- package/agent-docs/components/loading.md +69 -0
- package/agent-docs/components/markdown.md +51 -0
- package/agent-docs/components/media-tile.md +101 -0
- package/agent-docs/components/menu.md +110 -0
- package/agent-docs/components/meta-list.md +69 -0
- package/agent-docs/components/morph.md +134 -0
- package/agent-docs/components/navigation-progress.md +56 -0
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +74 -0
- package/agent-docs/components/page-fade.md +117 -0
- package/agent-docs/components/page-header.md +93 -0
- package/agent-docs/components/pagination.md +64 -0
- package/agent-docs/components/pill.md +105 -0
- 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/progress-bar.md +66 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +87 -0
- package/agent-docs/components/prose.md +41 -0
- package/agent-docs/components/radio-group.md +77 -0
- package/agent-docs/components/scroll-strip.md +48 -0
- package/agent-docs/components/segmented-control.md +135 -0
- package/agent-docs/components/select.md +70 -0
- package/agent-docs/components/show.md +120 -0
- package/agent-docs/components/side-column.md +74 -0
- package/agent-docs/components/sidebar-layout.md +134 -0
- package/agent-docs/components/site-footer.md +63 -0
- package/agent-docs/components/site-search.md +79 -0
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +112 -0
- package/agent-docs/components/split-bar.md +54 -0
- package/agent-docs/components/stack.md +197 -0
- package/agent-docs/components/stacked-bar.md +91 -0
- package/agent-docs/components/stat-tile.md +69 -0
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +112 -0
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/steps.md +74 -0
- package/agent-docs/components/sticky-bar.md +51 -0
- package/agent-docs/components/switch.md +79 -0
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +384 -0
- package/agent-docs/components/tabs.md +178 -0
- package/agent-docs/components/text-link.md +110 -0
- package/agent-docs/components/textarea.md +53 -0
- package/agent-docs/components/timeline.md +79 -0
- package/agent-docs/components/toast.md +91 -0
- package/agent-docs/components/trend-chart.md +61 -0
- package/agent-docs/components/video.md +49 -0
- package/agent-docs/llms.txt +174 -0
- 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 +7 -3
- package/skills/uislash/SKILL.md +20 -0
package/dist/SiteSearch.js
CHANGED
|
@@ -4,45 +4,9 @@ import { Button } from "./Button.js";
|
|
|
4
4
|
import { Dialog } from "./Dialog.js";
|
|
5
5
|
import { Icon } from "./Icon.js";
|
|
6
6
|
import { IconButton } from "./IconButton.js";
|
|
7
|
-
import { Input } from "./Input.js";
|
|
8
7
|
import { Kbd } from "./Kbd.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The items that match `text`, best first: the label starts with it, then the label contains it,
|
|
13
|
-
* then a keyword contains it, then the description does. Case is ignored, and items of the same
|
|
14
|
-
* rank keep their order in `items`. Empty text matches nothing.
|
|
15
|
-
*/
|
|
16
|
-
export function rankSiteSearch(items, text) {
|
|
17
|
-
const query = text.trim().toLowerCase();
|
|
18
|
-
if (query === "")
|
|
19
|
-
return [];
|
|
20
|
-
const rankOf = (item) => {
|
|
21
|
-
const label = item.label.toLowerCase();
|
|
22
|
-
if (label.startsWith(query))
|
|
23
|
-
return 0;
|
|
24
|
-
if (label.includes(query))
|
|
25
|
-
return 1;
|
|
26
|
-
if (item.keywords?.some((keyword) => keyword.toLowerCase().includes(query)))
|
|
27
|
-
return 2;
|
|
28
|
-
if (item.description?.toLowerCase().includes(query))
|
|
29
|
-
return 3;
|
|
30
|
-
return -1;
|
|
31
|
-
};
|
|
32
|
-
return items
|
|
33
|
-
.map((item, index) => ({ item, index, rank: rankOf(item) }))
|
|
34
|
-
.filter((entry) => entry.rank >= 0)
|
|
35
|
-
.toSorted((a, b) => a.rank - b.rank || a.index - b.index)
|
|
36
|
-
.map((entry) => entry.item);
|
|
37
|
-
}
|
|
38
|
-
/** What the live region says for a result count. */
|
|
39
|
-
function countText(query, count) {
|
|
40
|
-
if (query.trim() === "")
|
|
41
|
-
return "";
|
|
42
|
-
if (count === 0)
|
|
43
|
-
return "No results";
|
|
44
|
-
return count === 1 ? "1 result" : `${count} results`;
|
|
45
|
-
}
|
|
8
|
+
import { englishCount, SearchBody } from "./siteSearchBody.js";
|
|
9
|
+
export { rankSiteSearch } from "./siteSearchBody.js";
|
|
46
10
|
// The shortcut's key reads ⌘ K on Apple platforms. The server cannot know, so it renders Ctrl K and
|
|
47
11
|
// the client swaps after hydration.
|
|
48
12
|
const noSubscribe = () => () => { };
|
|
@@ -54,67 +18,23 @@ function isShortcut(event) {
|
|
|
54
18
|
!event.shiftKey &&
|
|
55
19
|
event.key.toLowerCase() === "k");
|
|
56
20
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (event.target instanceof Element && event.target.closest("a[href]")) {
|
|
63
|
-
event.currentTarget.closest("dialog")?.close();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** The result links in the list, in order. */
|
|
67
|
-
function linksIn(list) {
|
|
68
|
-
return list ? [...list.querySelectorAll("a[href]")] : [];
|
|
69
|
-
}
|
|
70
|
-
function SearchBody({ items, label, resultsLabel, }) {
|
|
71
|
-
const [query, setQuery] = useState("");
|
|
72
|
-
const box = useRef(null);
|
|
73
|
-
const list = useRef(null);
|
|
74
|
-
const results = rankSiteSearch(items, query);
|
|
75
|
-
const typed = query.trim() !== "";
|
|
76
|
-
const onFieldKey = (event) => {
|
|
77
|
-
if (event.key === "Escape") {
|
|
78
|
-
// Close here, so no engine spends the first Esc clearing the search field.
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
event.currentTarget.closest("dialog")?.close();
|
|
81
|
-
}
|
|
82
|
-
else if (event.key === "Enter") {
|
|
83
|
-
event.preventDefault();
|
|
84
|
-
linksIn(list.current)[0]?.click();
|
|
85
|
-
}
|
|
86
|
-
else if (event.key === "ArrowDown") {
|
|
87
|
-
const first = linksIn(list.current)[0];
|
|
88
|
-
if (first) {
|
|
89
|
-
event.preventDefault();
|
|
90
|
-
first.focus();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const onListKey = (event) => {
|
|
95
|
-
if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
|
|
96
|
-
return;
|
|
97
|
-
const links = linksIn(list.current);
|
|
98
|
-
const at = links.findIndex((link) => link === document.activeElement);
|
|
99
|
-
if (at < 0)
|
|
100
|
-
return;
|
|
101
|
-
event.preventDefault();
|
|
102
|
-
const next = at + (event.key === "ArrowDown" ? 1 : -1);
|
|
103
|
-
if (next < 0)
|
|
104
|
-
box.current?.querySelector("input")?.focus();
|
|
105
|
-
else
|
|
106
|
-
links[Math.min(next, links.length - 1)]?.focus();
|
|
21
|
+
/** The dialog's words, each with its English default, apart from the props the root span takes. */
|
|
22
|
+
function splitWords({ resultsLabel = "Results", placeholder = "Search", hintLabel = "Type a name", noResultsLabel = "No results for", countLabel = englishCount, allResultsLabel = "See all results for", ...rest }) {
|
|
23
|
+
return {
|
|
24
|
+
words: { resultsLabel, placeholder, hintLabel, noResultsLabel, countLabel, allResultsLabel },
|
|
25
|
+
rest,
|
|
107
26
|
};
|
|
108
|
-
return (_jsxs("div", { ref: box, className: "flex flex-col gap-3", children: [_jsx(Input, { type: "search", icon: "search", "aria-label": label, placeholder: "Search", autoComplete: "off", spellCheck: false, value: query, onChange: (event) => setQuery(event.target.value), onKeyDown: onFieldKey }), _jsx("div", { role: "status", "aria-live": "polite", className: "sr-only", children: countText(query, results.length) }), !typed && _jsx(Text, { tone: "muted", children: "Type a name" }), typed && results.length === 0 && _jsxs(Text, { tone: "muted", children: ["No results for ", query.trim()] }), results.length > 0 && (_jsx("ul", { ref: list, "aria-label": resultsLabel, onKeyDown: onListKey, onClick: onListClick, children: results.map((item, index) => (_jsx("li", { children: _jsx(ListRow, { href: item.href, size: "sm", divided: index > 0, secondary: item.description, children: item.label }) }, item.href))) }))] }));
|
|
109
27
|
}
|
|
110
28
|
/**
|
|
111
29
|
* The site's search: a header button that opens a dialog with a search field over a list of links
|
|
112
30
|
* to the pages that match. Put it in `AppShell`'s `controls` and pass every page as `items`. Ctrl+K
|
|
113
31
|
* (⌘ K on a Mac) opens it from anywhere on the page, and the button shows that key. Typing filters
|
|
114
|
-
* by name, then by `keywords`, then by description; Enter opens the first result,
|
|
115
|
-
* move through them, and Esc closes it and
|
|
32
|
+
* by name, then by `keywords`, then by description; Enter opens the first result (or, with
|
|
33
|
+
* `resultsHref`, the full results page), the arrow keys move through them, and Esc closes it and
|
|
34
|
+
* puts focus back where it was. The field is a `<search>` landmark. Render it once per page.
|
|
116
35
|
*/
|
|
117
|
-
export function SiteSearch({ items, label,
|
|
36
|
+
export function SiteSearch({ items, label, buttonLabel = "Search", resultsHref, size = "sm", ...props }) {
|
|
37
|
+
const { words, rest } = splitWords(props);
|
|
118
38
|
const [open, setOpen] = useState(false);
|
|
119
39
|
const opener = useRef(null);
|
|
120
40
|
const apple = useSyncExternalStore(noSubscribe, isApple, () => false);
|
|
@@ -146,5 +66,5 @@ export function SiteSearch({ items, label, resultsLabel = "Results", ...rest })
|
|
|
146
66
|
if (back?.isConnected && back !== document.body)
|
|
147
67
|
back.focus();
|
|
148
68
|
};
|
|
149
|
-
return (_jsxs("span", { ...rest, className: "inline-flex", children: [_jsx("span", { className: "hidden sm:inline-flex", children: _jsxs(Button, { variant: "outline", size:
|
|
69
|
+
return (_jsxs("span", { ...rest, className: "inline-flex", children: [_jsx("span", { className: "hidden sm:inline-flex", children: _jsxs(Button, { variant: "outline", size: size, "aria-haspopup": "dialog", "aria-keyshortcuts": "Control+K Meta+K", onClick: openFrom, children: [_jsx(Icon, { name: "search", size: "sm" }), buttonLabel, _jsx("span", { className: "-my-1 inline-flex", children: _jsx(Kbd, { "aria-hidden": "true", children: keys }) })] }) }), _jsx("span", { className: "inline-flex sm:hidden", children: _jsx(IconButton, { label: label, size: size, "aria-haspopup": "dialog", "aria-keyshortcuts": "Control+K Meta+K", onClick: openFrom, icon: "search" }) }), open && (_jsx(Dialog, { title: label, width: "md", onClose: close, children: _jsx(SearchBody, { items: items, label: label, resultsHref: resultsHref, words: words }) }))] }));
|
|
150
70
|
}
|
package/dist/Slider.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactElement, type Ref } from "react";
|
|
2
|
+
import { type ControlProps } from "./control.js";
|
|
3
|
+
import type { Unstyled } from "./props.js";
|
|
4
|
+
type SliderProps = ControlProps & {
|
|
5
|
+
/**
|
|
6
|
+
* How the value beside the track is written, in the locale of the app's `I18nProvider` or else
|
|
7
|
+
* the browser's: `{ style: "percent" }` (for a value from 0 to 1), `{ style: "currency",
|
|
8
|
+
* currency: "EUR" }`, `{ style: "unit", unit: "kilogram" }`. Assistive tech reads it the same way.
|
|
9
|
+
*/
|
|
10
|
+
formatOptions?: Intl.NumberFormatOptions | undefined;
|
|
11
|
+
/** The number it holds, controlled, with `onChange`. */
|
|
12
|
+
value?: number | undefined;
|
|
13
|
+
/** The number it starts with, uncontrolled. Without one it starts halfway, as the browser's does. */
|
|
14
|
+
defaultValue?: number | undefined;
|
|
15
|
+
/** The `<input>` itself, for focus control. */
|
|
16
|
+
ref?: Ref<HTMLInputElement> | undefined;
|
|
17
|
+
} & Unstyled<Omit<ComponentPropsWithoutRef<"input">, "size" | "width" | "type" | "value" | "defaultValue" | "children">>;
|
|
18
|
+
/**
|
|
19
|
+
* A range slider for one number between `min` and `max` (0 and 100 unless given), in steps of
|
|
20
|
+
* `step`: the browser's own `<input type="range">` in the accent colour, with its value written
|
|
21
|
+
* beside the track (`formatOptions` sets how) and read out the same way. Put it in a `Field`, which
|
|
22
|
+
* names it and draws the hint and the error, as an `Input`. Arrow keys, Page Up, Page Down, Home and
|
|
23
|
+
* End move it. `size` sets its height and the value's type, to line up with an `Input` of that size;
|
|
24
|
+
* `width` is an `Input`'s. `onChange` is the input's own, on every move. The `ref` reaches the `<input>`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Slider({ formatOptions, value, defaultValue, size, width, ref, onChange, ...own }: SliderProps): ReactElement;
|
|
27
|
+
export {};
|
package/dist/Slider.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { useLocale } from "react-aria-components";
|
|
4
|
+
import { CONTROL_WIDTH, controlHeight } from "./control.js";
|
|
5
|
+
import { cx, focusRing } from "./cx.js";
|
|
6
|
+
import { controlText, useTypeStep } from "./density.js";
|
|
7
|
+
import { useFieldControl } from "./fieldControl.js";
|
|
8
|
+
/** A number bound for the range: the given one, or the browser's default. */
|
|
9
|
+
function bound(given, fallback) {
|
|
10
|
+
const value = Number(given);
|
|
11
|
+
return given === undefined || Number.isNaN(value) ? fallback : value;
|
|
12
|
+
}
|
|
13
|
+
/** Sets both the input's own ref and the consumer's. */
|
|
14
|
+
function bothRefs(own, theirs) {
|
|
15
|
+
return (el) => {
|
|
16
|
+
own.current = el;
|
|
17
|
+
if (typeof theirs === "function")
|
|
18
|
+
theirs(el);
|
|
19
|
+
else if (theirs)
|
|
20
|
+
theirs.current = el;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The number the range shows: the caller's `value`, else its own, read from the input as it moves. */
|
|
24
|
+
function useShownValue(value, defaultValue, inputRef) {
|
|
25
|
+
const [own, setOwn] = useState(defaultValue);
|
|
26
|
+
// With no `defaultValue` the browser picks the start (halfway, on a step), so read it once mounted.
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (own === undefined && inputRef.current)
|
|
29
|
+
setOwn(inputRef.current.valueAsNumber);
|
|
30
|
+
}, [own, inputRef]);
|
|
31
|
+
return [value ?? own, (event) => setOwn(event.currentTarget.valueAsNumber)];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A range slider for one number between `min` and `max` (0 and 100 unless given), in steps of
|
|
35
|
+
* `step`: the browser's own `<input type="range">` in the accent colour, with its value written
|
|
36
|
+
* beside the track (`formatOptions` sets how) and read out the same way. Put it in a `Field`, which
|
|
37
|
+
* names it and draws the hint and the error, as an `Input`. Arrow keys, Page Up, Page Down, Home and
|
|
38
|
+
* End move it. `size` sets its height and the value's type, to line up with an `Input` of that size;
|
|
39
|
+
* `width` is an `Input`'s. `onChange` is the input's own, on every move. The `ref` reaches the `<input>`.
|
|
40
|
+
*/
|
|
41
|
+
export function Slider({ formatOptions, value, defaultValue, size = "md", width = "full", ref, onChange, ...own }) {
|
|
42
|
+
const step = useTypeStep();
|
|
43
|
+
const field = useFieldControl(own);
|
|
44
|
+
const inputRef = useRef(null);
|
|
45
|
+
const attach = useMemo(() => bothRefs(inputRef, ref), [ref]);
|
|
46
|
+
const [shown, track] = useShownValue(value, defaultValue, inputRef);
|
|
47
|
+
const { locale } = useLocale();
|
|
48
|
+
const format = useMemo(() => new Intl.NumberFormat(locale, formatOptions), [locale, formatOptions]);
|
|
49
|
+
const written = shown === undefined ? "" : format.format(shown);
|
|
50
|
+
// The longer of the two ends, drawn unseen under the value, keeps the track still as the value changes.
|
|
51
|
+
const widest = [bound(own.min, 0), bound(own.max, 100)]
|
|
52
|
+
.map((end) => format.format(end))
|
|
53
|
+
.reduce((a, b) => (b.length > a.length ? b : a));
|
|
54
|
+
return (_jsxs("div", { className: cx("flex items-center gap-3", controlHeight(size), width === "auto" ? "inline-flex" : CONTROL_WIDTH[width]), children: [_jsx("input", { ...own, ...field, ref: attach, type: "range", ...(value === undefined ? { defaultValue } : { value }), "aria-valuetext": written || undefined, onChange: (event) => {
|
|
55
|
+
track(event);
|
|
56
|
+
onChange?.(event);
|
|
57
|
+
}, className: cx("h-full min-w-0 flex-1 cursor-pointer rounded-lg accent-violet-600 disabled:cursor-not-allowed disabled:opacity-50", focusRing) }), _jsxs("span", { "aria-hidden": "true", className: cx("grid shrink-0 text-right tabular-nums text-slate-700", controlText(size, step, false)), children: [_jsx("span", { className: "invisible [grid-area:1/1]", children: widest }), _jsx("span", { className: "[grid-area:1/1]", children: written })] })] }));
|
|
58
|
+
}
|
package/dist/SortableList.d.ts
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
-
import { type
|
|
2
|
+
import { type SortableMove } from "./sortableDrop.js";
|
|
3
3
|
import type { Passthrough } from "./props.js";
|
|
4
|
-
|
|
5
|
-
export type SortableMove = {
|
|
6
|
-
/** The `id` of the item that moved. */
|
|
7
|
-
id: string;
|
|
8
|
-
/** The `id` of the `SortableSection` the item lands in. Set whenever the list has sections. */
|
|
9
|
-
section?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The item it was dropped before or after. Absent only for a drop into an empty section, where
|
|
12
|
-
* there is no item to land next to.
|
|
13
|
-
*/
|
|
14
|
-
target?: {
|
|
15
|
-
id: string;
|
|
16
|
-
position: "before" | "after";
|
|
17
|
-
};
|
|
18
|
-
};
|
|
4
|
+
export type { SortableMove };
|
|
19
5
|
/** What a part takes through to its element: `id`, `data-*` and `aria-*`, as every component does. */
|
|
20
6
|
type Through = Passthrough;
|
|
21
|
-
/** A row's section and title; a tail row also lists its section's items, in order. */
|
|
22
|
-
type Place = {
|
|
23
|
-
section?: string;
|
|
24
|
-
title: string;
|
|
25
|
-
tail?: string[];
|
|
26
|
-
};
|
|
27
|
-
/** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
|
|
28
|
-
export declare function dropOperation(target: DropTarget): "move" | "cancel";
|
|
29
|
-
/**
|
|
30
|
-
* The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
|
|
31
|
-
* on a row's centre, or next to the item itself). A drop at a section's tail lands after the
|
|
32
|
-
* section's last other item, or with no target when it has none.
|
|
33
|
-
*/
|
|
34
|
-
export declare function moveOf(places: Map<string, Place>, keys: Iterable<Key>, target: DropTarget): SortableMove | null;
|
|
35
7
|
/**
|
|
36
8
|
* A list the user puts in order: items under section headings, moved by dragging a row or from the
|
|
37
9
|
* keyboard (each row's grip handle, Enter, the arrow keys, Enter to drop, Escape to cancel). A drop
|
|
@@ -63,12 +35,18 @@ type SortableSectionProps = {
|
|
|
63
35
|
* @default Drop here
|
|
64
36
|
*/
|
|
65
37
|
emptyLabel?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The word before `title` in the name of the section's last drop place, which a screen reader
|
|
40
|
+
* announces while a move lands there: "End of Doing".
|
|
41
|
+
* @default End of
|
|
42
|
+
*/
|
|
43
|
+
endLabel?: string | undefined;
|
|
66
44
|
};
|
|
67
45
|
/**
|
|
68
46
|
* One group of a `SortableList` under a heading that shows its title and how many items it holds.
|
|
69
47
|
* An empty section still takes a drop: it shows a quiet "Drop here" row in place of items.
|
|
70
48
|
*/
|
|
71
|
-
export declare function SortableSection({ id, title, children, emptyLabel, ...rest }: SortableSectionProps & Through): ReactElement;
|
|
49
|
+
export declare function SortableSection({ id, title, children, emptyLabel, endLabel, ...rest }: SortableSectionProps & Through): ReactElement;
|
|
72
50
|
type SortableItemProps = {
|
|
73
51
|
/** The item's id, reported in a move. */
|
|
74
52
|
id: string;
|
|
@@ -76,11 +54,17 @@ type SortableItemProps = {
|
|
|
76
54
|
title: string;
|
|
77
55
|
/** A meta line under the title: `Pill`s, an `Avatar`. */
|
|
78
56
|
children?: ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* The word before `title` in the handle's accessible name: "Reorder Write the brief".
|
|
59
|
+
* @default Reorder
|
|
60
|
+
*/
|
|
61
|
+
reorderLabel?: string | undefined;
|
|
79
62
|
};
|
|
80
63
|
/**
|
|
81
64
|
* One row of a `SortableList`: a grip handle, the title, and an optional meta line under it. A
|
|
82
|
-
* pointer drags the row
|
|
83
|
-
*
|
|
65
|
+
* pointer drags the row by its handle only (a drag that starts anywhere else on the row is no
|
|
66
|
+
* drag); the handle (`reorderLabel` and the title, "Reorder <title>") is also how a keyboard or
|
|
67
|
+
* screen reader starts a move. A title cut to one line shows in full in a tooltip on hover, on the
|
|
68
|
+
* row's keyboard focus and on a tap.
|
|
84
69
|
*/
|
|
85
|
-
export declare function SortableItem({ id, title, children, ...rest }: SortableItemProps & Through): ReactElement;
|
|
86
|
-
export {};
|
|
70
|
+
export declare function SortableItem({ id, title, children, reorderLabel, ...rest }: SortableItemProps & Through): ReactElement;
|
package/dist/SortableList.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Children, isValidElement, useId, useMemo, } from "react";
|
|
2
|
+
import { Children, isValidElement, useId, useMemo, useRef, } from "react";
|
|
3
3
|
import { Button, DropIndicator, GridList, GridListHeader, GridListItem, GridListSection, useDragAndDrop, } from "react-aria-components";
|
|
4
|
-
import {
|
|
4
|
+
import { dropOperation, moveOf, ROW_MARK, sectionDelegate, tailKey, } from "./sortableDrop.js";
|
|
5
|
+
import { useSlide } from "./sortableSlide.js";
|
|
6
|
+
import { cx, focusRing, forcedFill } from "./cx.js";
|
|
7
|
+
import { ItemTitle } from "./sortableTitle.js";
|
|
5
8
|
import { dataAttributes } from "./link.js";
|
|
6
9
|
/** The list's box: the Card's border, fill and shadow, clipped to its radius. */
|
|
7
10
|
const FRAME = "w-full overflow-hidden rounded-xl border border-slate-200/70 bg-white shadow-sm outline-none";
|
|
@@ -13,15 +16,15 @@ const AFTER_ROW = "border-slate-200/70 [[role=row]+&]:border-t";
|
|
|
13
16
|
/** A section after another section gets the same hairline above its heading. */
|
|
14
17
|
const AFTER_SECTION = "border-slate-200/70 [[role=rowgroup]+&]:border-t";
|
|
15
18
|
const HEADING = "flex items-center justify-between gap-3 bg-slate-50 px-4 py-2 text-xs font-medium tracking-wide text-slate-600 uppercase";
|
|
16
|
-
const ITEM = "flex w-full
|
|
19
|
+
const ITEM = "flex w-full items-center gap-3 px-4 py-3 text-left text-sm text-slate-900 outline-none hover:bg-slate-50";
|
|
17
20
|
/** The keyboard cursor: the focus ring, drawn inside the row. */
|
|
18
21
|
const ITEM_FOCUSED = "outline-2 -outline-offset-2 outline-violet-600";
|
|
19
22
|
/** An empty section's "Drop here" row. */
|
|
20
23
|
const PLACEHOLDER = "px-4 py-3 text-sm text-slate-500 outline-none";
|
|
21
24
|
/** The tail row of a section with items: takes no room and shows nothing but the drop line. */
|
|
22
25
|
const TAIL = "h-0 overflow-hidden outline-none";
|
|
23
|
-
/**
|
|
24
|
-
const
|
|
26
|
+
/** The handle a pointer drags a row by (the grip and the box over it): only a press that starts on it starts a drag. */
|
|
27
|
+
const GRIP_MARK = "data-sortable-grip";
|
|
25
28
|
/**
|
|
26
29
|
* react-aria drops an `aria-describedby` or `aria-details` it is handed on a row or a section, and
|
|
27
30
|
* sets its own describedby on a row. This draws the element with both: its own ids and the app's.
|
|
@@ -34,16 +37,6 @@ function describedBy({ "aria-describedby": described, "aria-details": details, i
|
|
|
34
37
|
render: (props) => (_jsx("div", { ...props, ...aria, id: id ?? props.id, "aria-describedby": [props["aria-describedby"], described].filter(Boolean).join(" ") || undefined, "aria-details": details ?? props["aria-details"] })),
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
|
-
/**
|
|
38
|
-
* The key of a section's tail row. Every section ends with one: in an empty section it is the "Drop
|
|
39
|
-
* here" row, in one with items it is an empty row of no height. A drop before it is a drop at the
|
|
40
|
-
* end of the section. react-aria's keyboard drop moves cannot step from "after the last item" of a
|
|
41
|
-
* section into the next one (it wraps to the top), but they do step from "before" a row to "before"
|
|
42
|
-
* the next row across sections, so with a tail row the end of each section is a "before" target.
|
|
43
|
-
*/
|
|
44
|
-
function tailKey(section) {
|
|
45
|
-
return `hackcove-sortable-end:${section}`;
|
|
46
|
-
}
|
|
47
40
|
/** The `SortableItem` children of a section, the ones its count counts. */
|
|
48
41
|
function itemsOf(children) {
|
|
49
42
|
return Children.toArray(children).filter((child) => isValidElement(child) && child.type === SortableItem);
|
|
@@ -66,72 +59,6 @@ function placesOf(children) {
|
|
|
66
59
|
}
|
|
67
60
|
return places;
|
|
68
61
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Where a pointer drops: before or after the row it is over, by which half it is in. Over a section
|
|
71
|
-
* heading, or in a gap, it is before the next row below (the first item of that section, or its
|
|
72
|
-
* "Drop here" row), and below every row it is after the last. Never "on" a row.
|
|
73
|
-
*/
|
|
74
|
-
function dropTargetAt(list, y) {
|
|
75
|
-
if (!list)
|
|
76
|
-
return null;
|
|
77
|
-
const top = y + list.getBoundingClientRect().top;
|
|
78
|
-
const rows = [...list.querySelectorAll(`[${ROW_MARK}]`)];
|
|
79
|
-
for (const row of rows) {
|
|
80
|
-
const key = row.dataset.key;
|
|
81
|
-
if (key == null)
|
|
82
|
-
continue;
|
|
83
|
-
const box = row.getBoundingClientRect();
|
|
84
|
-
if (top < box.top)
|
|
85
|
-
return { type: "item", key, dropPosition: "before" };
|
|
86
|
-
if (top <= box.bottom) {
|
|
87
|
-
return {
|
|
88
|
-
type: "item",
|
|
89
|
-
key,
|
|
90
|
-
dropPosition: top < box.top + box.height / 2 ? "before" : "after",
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const last = rows.at(-1)?.dataset.key;
|
|
95
|
-
return last == null ? null : { type: "item", key: last, dropPosition: "after" };
|
|
96
|
-
}
|
|
97
|
-
/** react-aria's pointer drop delegate, aware of sections (the stock one sees only top-level items). */
|
|
98
|
-
function sectionDelegate(listId) {
|
|
99
|
-
return {
|
|
100
|
-
getDropTargetFromPoint: (_x, y) => dropTargetAt(document.getElementById(listId), y),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
|
|
104
|
-
export function dropOperation(target) {
|
|
105
|
-
return target.type === "item" && target.dropPosition !== "on" ? "move" : "cancel";
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
|
|
109
|
-
* on a row's centre, or next to the item itself). A drop at a section's tail lands after the
|
|
110
|
-
* section's last other item, or with no target when it has none.
|
|
111
|
-
*/
|
|
112
|
-
export function moveOf(places, keys, target) {
|
|
113
|
-
const [key] = keys;
|
|
114
|
-
if (key == null || target.type !== "item" || target.dropPosition === "on")
|
|
115
|
-
return null;
|
|
116
|
-
const place = places.get(String(target.key));
|
|
117
|
-
if (!place)
|
|
118
|
-
return null;
|
|
119
|
-
const id = String(key);
|
|
120
|
-
if (String(target.key) === id)
|
|
121
|
-
return null;
|
|
122
|
-
const section = place.section === undefined ? {} : { section: place.section };
|
|
123
|
-
if (place.tail) {
|
|
124
|
-
const last = place.tail.filter((item) => item !== id).at(-1);
|
|
125
|
-
return last === undefined
|
|
126
|
-
? { id, ...section }
|
|
127
|
-
: { id, ...section, target: { id: last, position: "after" } };
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
id,
|
|
131
|
-
...section,
|
|
132
|
-
target: { id: String(target.key), position: target.dropPosition },
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
62
|
/**
|
|
136
63
|
* A list the user puts in order: items under section headings, moved by dragging a row or from the
|
|
137
64
|
* keyboard (each row's grip handle, Enter, the arrow keys, Enter to drop, Escape to cancel). A drop
|
|
@@ -152,6 +79,7 @@ export function SortableList({ label, onReorder, children, ...rest }) {
|
|
|
152
79
|
.toLowerCase()}`;
|
|
153
80
|
const places = placesOf(children);
|
|
154
81
|
const delegate = useMemo(() => sectionDelegate(listId), [listId]);
|
|
82
|
+
useSlide(listId, ROW_MARK);
|
|
155
83
|
const { dragAndDropHooks } = useDragAndDrop({
|
|
156
84
|
getItems: (keys) => [...keys].map((key) => ({
|
|
157
85
|
"text/plain": places.get(String(key))?.title ?? String(key),
|
|
@@ -165,7 +93,7 @@ export function SortableList({ label, onReorder, children, ...rest }) {
|
|
|
165
93
|
if (move)
|
|
166
94
|
onReorder(move);
|
|
167
95
|
},
|
|
168
|
-
renderDropIndicator: (target) => (_jsx(DropIndicator, { target: target, className: "relative h-0 outline-none", children: ({ isDropTarget }) => (_jsx("span", { "aria-hidden": "true", className: cx("absolute inset-x-0 -top-px z-10 block h-0.5", isDropTarget && "bg-violet-600") })) })),
|
|
96
|
+
renderDropIndicator: (target) => (_jsx(DropIndicator, { target: target, className: "relative h-0 outline-none", children: ({ isDropTarget }) => (_jsx("span", { "aria-hidden": "true", className: cx("absolute inset-x-0 -top-px z-10 block h-0.5", isDropTarget && cx("bg-violet-600", forcedFill)) })) })),
|
|
169
97
|
});
|
|
170
98
|
return (_jsx(GridList, { ...describedBy(through, listId), id: listId, "aria-label": label, dragAndDropHooks: dragAndDropHooks, disabledBehavior: "all", className: FRAME, children: children }));
|
|
171
99
|
}
|
|
@@ -173,19 +101,39 @@ export function SortableList({ label, onReorder, children, ...rest }) {
|
|
|
173
101
|
* One group of a `SortableList` under a heading that shows its title and how many items it holds.
|
|
174
102
|
* An empty section still takes a drop: it shows a quiet "Drop here" row in place of items.
|
|
175
103
|
*/
|
|
176
|
-
export function SortableSection({ id, title, children, emptyLabel = "Drop here", ...rest }) {
|
|
104
|
+
export function SortableSection({ id, title, children, emptyLabel = "Drop here", endLabel = "End of", ...rest }) {
|
|
177
105
|
const count = itemsOf(children).length;
|
|
178
106
|
return (_jsxs(GridListSection, { ...describedBy(rest),
|
|
179
107
|
// Sections and items share react-aria's key space; this keeps a section id from colliding with an item's.
|
|
180
|
-
id: `hackcove-sortable-section:${id}`, "aria-label": title, className: AFTER_SECTION, children: [_jsxs(GridListHeader, { className: HEADING, children: [_jsx("span", { children: title }), _jsx("span", { className: "tabular-nums text-slate-500", children: count })] }), children, _jsxs(GridListItem, { id: tailKey(id), textValue: count > 0 ?
|
|
108
|
+
id: `hackcove-sortable-section:${id}`, "aria-label": title, className: AFTER_SECTION, children: [_jsxs(GridListHeader, { className: HEADING, children: [_jsx("span", { children: title }), _jsx("span", { className: "tabular-nums text-slate-500", children: count })] }), children, _jsxs(GridListItem, { id: tailKey(id), textValue: count > 0 ? `${endLabel} ${title}` : emptyLabel, isDisabled: true, [ROW_MARK]: "", className: count > 0 ? TAIL : cx(PLACEHOLDER, AFTER_ROW), children: [_jsx(Button, { slot: "drag", className: "hidden" }), count === 0 && emptyLabel] })] }));
|
|
181
109
|
}
|
|
182
110
|
/** The six-dot grip on each row's handle. */
|
|
183
111
|
const GRIP = (_jsxs("svg", { viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": "true", className: "h-4 w-4", children: [_jsx("circle", { cx: "6", cy: "4", r: "1.25" }), _jsx("circle", { cx: "10", cy: "4", r: "1.25" }), _jsx("circle", { cx: "6", cy: "8", r: "1.25" }), _jsx("circle", { cx: "10", cy: "8", r: "1.25" }), _jsx("circle", { cx: "6", cy: "12", r: "1.25" }), _jsx("circle", { cx: "10", cy: "12", r: "1.25" })] }));
|
|
184
112
|
/**
|
|
185
113
|
* One row of a `SortableList`: a grip handle, the title, and an optional meta line under it. A
|
|
186
|
-
* pointer drags the row
|
|
187
|
-
*
|
|
114
|
+
* pointer drags the row by its handle only (a drag that starts anywhere else on the row is no
|
|
115
|
+
* drag); the handle (`reorderLabel` and the title, "Reorder <title>") is also how a keyboard or
|
|
116
|
+
* screen reader starts a move. A title cut to one line shows in full in a tooltip on hover, on the
|
|
117
|
+
* row's keyboard focus and on a tap.
|
|
188
118
|
*/
|
|
189
|
-
export function SortableItem({ id, title, children, ...rest }) {
|
|
190
|
-
|
|
119
|
+
export function SortableItem({ id, title, children, reorderLabel = "Reorder", ...rest }) {
|
|
120
|
+
const { render, ...data } = describedBy(rest);
|
|
121
|
+
// Where the last press on the row started: a native drag starts from the row, so only this says whether it began on the handle.
|
|
122
|
+
const onGrip = useRef(false);
|
|
123
|
+
return (_jsxs(GridListItem, { ...data, render: (props) => render({
|
|
124
|
+
...props,
|
|
125
|
+
onPointerDownCapture: (event) => {
|
|
126
|
+
onGrip.current =
|
|
127
|
+
event.target instanceof Element && event.target.closest(`[${GRIP_MARK}]`) !== null;
|
|
128
|
+
props.onPointerDownCapture?.(event);
|
|
129
|
+
},
|
|
130
|
+
onDragStartCapture: (event) => {
|
|
131
|
+
if (!onGrip.current) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
event.stopPropagation();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
props.onDragStartCapture?.(event);
|
|
137
|
+
},
|
|
138
|
+
}), id: id, textValue: title, [ROW_MARK]: "", className: ({ isFocusVisible, isDragging }) => cx(ITEM, AFTER_ROW, isFocusVisible && ITEM_FOCUSED, isDragging && "opacity-50"), children: [_jsxs("span", { [GRIP_MARK]: "", className: "relative flex shrink-0", children: [_jsx(Button, { slot: "drag", "aria-label": `${reorderLabel} ${title}`, className: cx("rounded p-0.5 text-slate-400", focusRing), children: GRIP }), _jsx("span", { "aria-hidden": "true", className: "absolute inset-0 cursor-grab" })] }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(ItemTitle, { title: title }), children != null && (_jsx("div", { className: "mt-1 flex flex-wrap items-center gap-2 text-xs text-slate-500", children: children }))] })] }));
|
|
191
139
|
}
|
package/dist/Stack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
|
|
2
|
-
import type { Passthrough
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
3
|
/** The space between a `Stack`'s blocks, on the gap scale: `xs` 8px, `sm` 16px, `md` 24px, `lg` 32px, `xl` 48px (64px from `sm`). */
|
|
4
4
|
export type StackGap = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
5
|
export declare const STACK_GAP: Record<StackGap, string>;
|
|
@@ -100,15 +100,15 @@ type StackProps = StackBase & (({
|
|
|
100
100
|
} & Passthrough) | ({
|
|
101
101
|
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
102
102
|
as: "form";
|
|
103
|
-
} &
|
|
103
|
+
} & Passthrough & Pick<ComponentPropsWithoutRef<"form">, "onSubmit" | "action" | "method" | "noValidate" | "name" | "autoComplete">) | ({
|
|
104
104
|
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
105
105
|
as: "ul";
|
|
106
106
|
/** Drawn in place of the list when it has no children: an `EmptyState`. */
|
|
107
107
|
empty?: ReactNode;
|
|
108
|
-
} &
|
|
108
|
+
} & Passthrough) | ({
|
|
109
109
|
/** The element: `div`, `section`, `form` (takes the form's props), `ul` or `ol` (no markers; each child is an `<li>`). */
|
|
110
110
|
as: "ol";
|
|
111
111
|
/** Drawn in place of the list when it has no children: an `EmptyState`. */
|
|
112
112
|
empty?: ReactNode;
|
|
113
|
-
} &
|
|
113
|
+
} & Passthrough));
|
|
114
114
|
export {};
|
package/dist/StackedBar.d.ts
CHANGED
|
@@ -15,16 +15,25 @@ export type CategoryTone = "cat1" | "cat2" | "cat3" | "cat4" | "cat5" | "cat6" |
|
|
|
15
15
|
export type VizTone = TextTone | CategoryTone;
|
|
16
16
|
/** Tone → text utility, painted as a fill. The `TextTone` colours are shared; `neutral` is the chart's own grey and `cat1` to `cat8` the categorical scale, each remapped by every theme. */
|
|
17
17
|
export declare const VIZ_TONE: Record<VizTone, string>;
|
|
18
|
+
/**
|
|
19
|
+
* The colour of a `StackedBar` part or a `Legend` swatch: a `VizTone`, or `quiet`, the remainder that
|
|
20
|
+
* matters least (not measured, not counted). A quiet part has no fill, so the bar's track shows
|
|
21
|
+
* through and the part reads as the empty end of the bar, quieter than `neutral` in every theme;
|
|
22
|
+
* put it last, where the bar ends.
|
|
23
|
+
* It sits under the 3:1 a chart mark needs, so its value is always named in words: a bar with a
|
|
24
|
+
* quiet part draws its `Legend`, and the key's quiet swatch is the track colour with an edge.
|
|
25
|
+
*/
|
|
26
|
+
export type SegmentTone = VizTone | "quiet";
|
|
18
27
|
/** One part of a `StackedBar`: its `label`, its `value` (its share is `value` over the sum) and its colour. */
|
|
19
28
|
export type StackedSegment = {
|
|
20
29
|
label: string;
|
|
21
30
|
value: number;
|
|
22
|
-
tone:
|
|
31
|
+
tone: SegmentTone;
|
|
23
32
|
};
|
|
24
33
|
/** One entry of a `Legend`: the `label` the colour stands for, its swatch, and an optional `detail` (a count, a share) after it. */
|
|
25
34
|
export type LegendItem = {
|
|
26
35
|
label: string;
|
|
27
|
-
tone:
|
|
36
|
+
tone: SegmentTone;
|
|
28
37
|
/**
|
|
29
38
|
* `solid` (the default) is a filled dot; `dashed` is a dashed ring in the tone's colour with no
|
|
30
39
|
* fill, the key for an outline drawn over the chart (a snapshot overlay).
|
|
@@ -49,12 +58,12 @@ export declare function Legend({ items, loading, loadingLabel, ...rest }: {
|
|
|
49
58
|
* label with its value, so the colours are named in words. While `loading` the bar is one bone (0
|
|
50
59
|
* is a real value) and the key keeps the names it has, without their values.
|
|
51
60
|
*/
|
|
52
|
-
export declare function StackedBar({ items, label, legend, size, loading, loadingLabel, ...rest }: {
|
|
61
|
+
export declare function StackedBar({ items, label, legend: wantsLegend, size, loading, loadingLabel, ...rest }: {
|
|
53
62
|
/** The parts in order, each a `label`, a `value` (its share is the value over the sum) and a `tone`. */
|
|
54
63
|
items: readonly StackedSegment[];
|
|
55
64
|
/** What the bar shows, for a screen reader, which hears it before every part's name and percent. */
|
|
56
65
|
label: string;
|
|
57
|
-
/** Draw the key under the bar. Defaults to false. */
|
|
66
|
+
/** Draw the key under the bar. Defaults to false; a bar with a `quiet` part always draws it. */
|
|
58
67
|
legend?: boolean;
|
|
59
68
|
/**
|
|
60
69
|
* The bar's height: `sm` 6px, `md` 8px, `lg` 12px.
|
package/dist/StackedBar.js
CHANGED
|
@@ -16,12 +16,16 @@ export const VIZ_TONE = {
|
|
|
16
16
|
cat7: "text-rose-600",
|
|
17
17
|
cat8: "text-yellow-600",
|
|
18
18
|
};
|
|
19
|
-
/** The colour of a segment: the tone's text colour, painted as a fill, so no new fill utility
|
|
20
|
-
const FILL = (tone) => cx("bg-current", VIZ_TONE[tone]);
|
|
21
|
-
/** A swatch: a filled dot,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
/** The colour of a segment: the tone's text colour, painted as a fill, so no new fill utility; none for `quiet`. */
|
|
20
|
+
const FILL = (tone) => tone === "quiet" ? "" : cx("bg-current", VIZ_TONE[tone]);
|
|
21
|
+
/** A swatch: a filled dot, a dashed ring in the same colour, or for `quiet` the track's colour with an edge. */
|
|
22
|
+
function SWATCH(item) {
|
|
23
|
+
if (item.tone === "quiet")
|
|
24
|
+
return "border border-slate-300 bg-slate-100";
|
|
25
|
+
return item.swatch === "dashed"
|
|
26
|
+
? cx("border-2 border-dashed border-current", VIZ_TONE[item.tone])
|
|
27
|
+
: FILL(item.tone);
|
|
28
|
+
}
|
|
25
29
|
/**
|
|
26
30
|
* A key to the colours of a chart or a row stripe: a swatch in the `VizTone` colour (a filled
|
|
27
31
|
* dot, or a dashed ring with `swatch="dashed"`), its `label` and an optional `detail` after it. Colour alone does not say it, so the label is always drawn.
|
|
@@ -48,7 +52,8 @@ function WaitingStack({ items, legend, size, name, own, label, attrs, }) {
|
|
|
48
52
|
* label with its value, so the colours are named in words. While `loading` the bar is one bone (0
|
|
49
53
|
* is a real value) and the key keeps the names it has, without their values.
|
|
50
54
|
*/
|
|
51
|
-
export function StackedBar({ items, label, legend = false, size = "md", loading, loadingLabel, ...rest }) {
|
|
55
|
+
export function StackedBar({ items, label, legend: wantsLegend = false, size = "md", loading, loadingLabel, ...rest }) {
|
|
56
|
+
const legend = wantsLegend || items.some((s) => s.tone === "quiet");
|
|
52
57
|
if (useLoading(loading).loading) {
|
|
53
58
|
return (_jsx(WaitingStack, { items: items, legend: legend, size: size, name: label, own: loading, label: loadingLabel, attrs: rest }));
|
|
54
59
|
}
|