@seekalfred/primitives 0.6.0 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -15
- package/dist/activity-heatmap/activity-heatmap.d.ts +92 -0
- package/dist/activity-heatmap/activity-heatmap.js +699 -0
- package/dist/activity-heatmap/activity-heatmap.js.map +1 -0
- package/dist/activity-heatmap/index.d.ts +2 -0
- package/dist/activity-heatmap/index.js +2 -0
- package/dist/alert/alert.d.ts +53 -4
- package/dist/alert/alert.js +100 -11
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +58 -18
- package/dist/alert-dialog/alert-dialog.js +152 -9
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/alert-dialog/index.d.ts +2 -2
- package/dist/alert-dialog/index.js +2 -2
- package/dist/animated-counter/animated-counter.d.ts +38 -0
- package/dist/animated-counter/animated-counter.js +230 -0
- package/dist/animated-counter/animated-counter.js.map +1 -0
- package/dist/animated-counter/index.d.ts +2 -0
- package/dist/animated-counter/index.js +2 -0
- package/dist/announcement-bar/announcement-bar.d.ts +67 -0
- package/dist/announcement-bar/announcement-bar.js +364 -0
- package/dist/announcement-bar/announcement-bar.js.map +1 -0
- package/dist/announcement-bar/index.d.ts +2 -0
- package/dist/announcement-bar/index.js +2 -0
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart.d.ts +51 -0
- package/dist/bar-chart/bar-chart.js +565 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/index.d.ts +2 -0
- package/dist/bar-chart/index.js +2 -0
- package/dist/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/breadcrumb/breadcrumb.js +12 -3
- package/dist/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/brush-chart/brush-chart.d.ts +64 -0
- package/dist/brush-chart/brush-chart.js +1056 -0
- package/dist/brush-chart/brush-chart.js.map +1 -0
- package/dist/brush-chart/index.d.ts +2 -0
- package/dist/brush-chart/index.js +2 -0
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button.js +31 -21
- package/dist/button/button.js.map +1 -1
- package/dist/button-group/button-group.js +3 -4
- package/dist/button-group/button-group.js.map +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/card-stack/card-stack.d.ts +54 -0
- package/dist/card-stack/card-stack.js +492 -0
- package/dist/card-stack/card-stack.js.map +1 -0
- package/dist/card-stack/index.d.ts +2 -0
- package/dist/card-stack/index.js +2 -0
- package/dist/carousel/carousel.d.ts +77 -0
- package/dist/carousel/carousel.js +415 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/carousel/index.d.ts +2 -0
- package/dist/carousel/index.js +2 -0
- package/dist/checkbox/checkbox.js +4 -4
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +37 -0
- package/dist/chip-group/chip-group.js +148 -0
- package/dist/chip-group/chip-group.js.map +1 -0
- package/dist/chip-group/index.d.ts +2 -0
- package/dist/chip-group/index.js +2 -0
- package/dist/copy-button/copy-button.d.ts +18 -2
- package/dist/copy-button/copy-button.js +29 -8
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/countdown/countdown.d.ts +45 -0
- package/dist/countdown/countdown.js +298 -0
- package/dist/countdown/countdown.js.map +1 -0
- package/dist/countdown/index.d.ts +2 -0
- package/dist/countdown/index.js +2 -0
- package/dist/date-picker/picker-parts.js +1 -1
- package/dist/date-picker/picker-parts.js.map +1 -1
- package/dist/dialog/dialog.js +1 -1
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +86 -0
- package/dist/donut-chart/donut-chart.js +593 -0
- package/dist/donut-chart/donut-chart.js.map +1 -0
- package/dist/donut-chart/index.d.ts +2 -0
- package/dist/donut-chart/index.js +2 -0
- package/dist/empty-state/empty-state.d.ts +42 -10
- package/dist/empty-state/empty-state.js +44 -26
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.js +1 -1
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +50 -26
- package/dist/filter-bar/filter-bar.js +317 -157
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +45 -0
- package/dist/gauge/gauge.js +219 -0
- package/dist/gauge/gauge.js.map +1 -0
- package/dist/gauge/index.d.ts +2 -0
- package/dist/gauge/index.js +2 -0
- package/dist/in-view-title/in-view-title.d.ts +33 -0
- package/dist/in-view-title/in-view-title.js +119 -0
- package/dist/in-view-title/in-view-title.js.map +1 -0
- package/dist/in-view-title/index.d.ts +2 -0
- package/dist/in-view-title/index.js +2 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.js +52 -12
- package/dist/input/input.js +4 -4
- package/dist/input/input.js.map +1 -1
- package/dist/lib/cn.js +11 -1
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/field-message.js +28 -10
- package/dist/lib/field-message.js.map +1 -1
- package/dist/lib/field-shell.js +10 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +31 -9
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/flag-emoji.js +50 -0
- package/dist/lib/flag-emoji.js.map +1 -0
- package/dist/lib/flip.js +11 -3
- package/dist/lib/flip.js.map +1 -1
- package/dist/lib/menu-highlight.js +64 -0
- package/dist/lib/menu-highlight.js.map +1 -0
- package/dist/lib/motion.js +9 -2
- package/dist/lib/motion.js.map +1 -1
- package/dist/lib/rolling-value.js +1 -1
- package/dist/lib/rolling-value.js.map +1 -1
- package/dist/lib/spring-tween.js +500 -0
- package/dist/lib/spring-tween.js.map +1 -0
- package/dist/lib/swap-text.js +3 -1
- package/dist/lib/swap-text.js.map +1 -1
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -0
- package/dist/line-chart/index.js +2 -0
- package/dist/line-chart/line-chart.d.ts +116 -0
- package/dist/line-chart/line-chart.js +740 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/mention-input/index.d.ts +2 -0
- package/dist/mention-input/index.js +2 -0
- package/dist/mention-input/mention-input.d.ts +98 -0
- package/dist/mention-input/mention-input.js +576 -0
- package/dist/mention-input/mention-input.js.map +1 -0
- package/dist/menu/menu.d.ts +2 -0
- package/dist/menu/menu.js +23 -12
- package/dist/menu/menu.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -0
- package/dist/money-input/index.js +2 -0
- package/dist/money-input/money-input.d.ts +86 -0
- package/dist/money-input/money-input.js +613 -0
- package/dist/money-input/money-input.js.map +1 -0
- package/dist/morph-select/index.d.ts +2 -0
- package/dist/morph-select/index.js +2 -0
- package/dist/morph-select/morph-select.d.ts +89 -0
- package/dist/morph-select/morph-select.js +712 -0
- package/dist/morph-select/morph-select.js.map +1 -0
- package/dist/multi-select/index.d.ts +2 -0
- package/dist/multi-select/index.js +2 -0
- package/dist/multi-select/multi-select.d.ts +77 -0
- package/dist/multi-select/multi-select.js +209 -0
- package/dist/multi-select/multi-select.js.map +1 -0
- package/dist/number-field/index.d.ts +2 -0
- package/dist/number-field/index.js +2 -0
- package/dist/number-field/number-field.d.ts +42 -0
- package/dist/number-field/number-field.js +199 -0
- package/dist/number-field/number-field.js.map +1 -0
- package/dist/onboarding-checklist/index.d.ts +2 -0
- package/dist/onboarding-checklist/index.js +2 -0
- package/dist/onboarding-checklist/onboarding-checklist.d.ts +55 -0
- package/dist/onboarding-checklist/onboarding-checklist.js +577 -0
- package/dist/onboarding-checklist/onboarding-checklist.js.map +1 -0
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +39 -10
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/phone-input/index.d.ts +3 -0
- package/dist/phone-input/index.js +3 -0
- package/dist/phone-input/phone-countries.d.ts +29 -0
- package/dist/phone-input/phone-countries.js +170 -0
- package/dist/phone-input/phone-countries.js.map +1 -0
- package/dist/phone-input/phone-input.d.ts +66 -0
- package/dist/phone-input/phone-input.js +440 -0
- package/dist/phone-input/phone-input.js.map +1 -0
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +51 -2
- package/dist/popover/popover.js +59 -8
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/progress.d.ts +16 -2
- package/dist/progress/progress.js +16 -9
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +110 -10
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/reactions/index.d.ts +2 -0
- package/dist/reactions/index.js +2 -0
- package/dist/reactions/reactions.d.ts +50 -0
- package/dist/reactions/reactions.js +315 -0
- package/dist/reactions/reactions.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +3 -0
- package/dist/rich-text-editor/index.js +2 -0
- package/dist/rich-text-editor/rich-text-editor.d.ts +70 -0
- package/dist/rich-text-editor/rich-text-editor.js +909 -0
- package/dist/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/rich-text-editor/rich-text-engine.d.ts +16 -0
- package/dist/rich-text-editor/rich-text-engine.js +366 -0
- package/dist/rich-text-editor/rich-text-engine.js.map +1 -0
- package/dist/rich-text-editor/rich-text-html.js +174 -0
- package/dist/rich-text-editor/rich-text-html.js.map +1 -0
- package/dist/rich-text-editor/rich-text-icons.js +43 -0
- package/dist/rich-text-editor/rich-text-icons.js.map +1 -0
- package/dist/ridgeline/index.d.ts +2 -0
- package/dist/ridgeline/index.js +2 -0
- package/dist/ridgeline/ridgeline.d.ts +55 -0
- package/dist/ridgeline/ridgeline.js +701 -0
- package/dist/ridgeline/ridgeline.js.map +1 -0
- package/dist/scroll-area/index.d.ts +2 -2
- package/dist/scroll-area/index.js +2 -2
- package/dist/scroll-area/scroll-area.d.ts +68 -31
- package/dist/scroll-area/scroll-area.js +212 -62
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/evaluate.d.ts +14 -0
- package/dist/scrub-input/evaluate.js +72 -0
- package/dist/scrub-input/evaluate.js.map +1 -0
- package/dist/scrub-input/index.d.ts +3 -0
- package/dist/scrub-input/index.js +3 -0
- package/dist/scrub-input/scrub-input.d.ts +74 -0
- package/dist/scrub-input/scrub-input.js +486 -0
- package/dist/scrub-input/scrub-input.js.map +1 -0
- package/dist/search-field/search-field.d.ts +24 -2
- package/dist/search-field/search-field.js +24 -9
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +3 -1
- package/dist/select/select.js +28 -14
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +22 -10
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sheet/sheet.js +2 -1
- package/dist/sheet/sheet.js.map +1 -1
- package/dist/shortcut-recorder/index.d.ts +3 -0
- package/dist/shortcut-recorder/index.js +3 -0
- package/dist/shortcut-recorder/shortcut-model.d.ts +27 -0
- package/dist/shortcut-recorder/shortcut-model.js +206 -0
- package/dist/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/shortcut-recorder/shortcut-recorder.d.ts +93 -0
- package/dist/shortcut-recorder/shortcut-recorder.js +489 -0
- package/dist/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/slider/index.d.ts +2 -2
- package/dist/slider/slider.d.ts +46 -14
- package/dist/slider/slider.js +151 -67
- package/dist/slider/slider.js.map +1 -1
- package/dist/slope-chart/index.d.ts +2 -0
- package/dist/slope-chart/index.js +2 -0
- package/dist/slope-chart/slope-chart.d.ts +54 -0
- package/dist/slope-chart/slope-chart.js +568 -0
- package/dist/slope-chart/slope-chart.js.map +1 -0
- package/dist/sparkline/index.d.ts +2 -0
- package/dist/sparkline/index.js +2 -0
- package/dist/sparkline/sparkline.d.ts +46 -0
- package/dist/sparkline/sparkline.js +390 -0
- package/dist/sparkline/sparkline.js.map +1 -0
- package/dist/split-bar/index.d.ts +2 -0
- package/dist/split-bar/index.js +2 -0
- package/dist/split-bar/split-bar.d.ts +62 -0
- package/dist/split-bar/split-bar.js +513 -0
- package/dist/split-bar/split-bar.js.map +1 -0
- package/dist/split-button/split-button.d.ts +1 -1
- package/dist/split-button/split-button.js +12 -11
- package/dist/split-button/split-button.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +58 -5
- package/dist/stat-card/stat-card.js +144 -17
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/stepper/index.d.ts +2 -0
- package/dist/stepper/index.js +2 -0
- package/dist/stepper/stepper.d.ts +51 -0
- package/dist/stepper/stepper.js +215 -0
- package/dist/stepper/stepper.js.map +1 -0
- package/dist/streamgraph/index.d.ts +2 -0
- package/dist/streamgraph/index.js +2 -0
- package/dist/streamgraph/streamgraph.d.ts +70 -0
- package/dist/streamgraph/streamgraph.js +613 -0
- package/dist/streamgraph/streamgraph.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/swipe-actions/index.d.ts +2 -0
- package/dist/swipe-actions/index.js +2 -0
- package/dist/swipe-actions/swipe-actions.d.ts +67 -0
- package/dist/swipe-actions/swipe-actions.js +552 -0
- package/dist/swipe-actions/swipe-actions.js.map +1 -0
- package/dist/switch/switch.js +2 -2
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +55 -3
- package/dist/table/table.js +340 -165
- package/dist/table/table.js.map +1 -1
- package/dist/tabs/tabs.js +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tag-input/index.d.ts +2 -0
- package/dist/tag-input/index.js +2 -0
- package/dist/tag-input/tag-input.d.ts +40 -0
- package/dist/tag-input/tag-input.js +269 -0
- package/dist/tag-input/tag-input.js.map +1 -0
- package/dist/text-morph/index.d.ts +2 -0
- package/dist/text-morph/index.js +2 -0
- package/dist/text-morph/text-morph.d.ts +23 -0
- package/dist/text-morph/text-morph.js +21 -0
- package/dist/text-morph/text-morph.js.map +1 -0
- package/dist/text-reveal/index.d.ts +2 -0
- package/dist/text-reveal/index.js +2 -0
- package/dist/text-reveal/text-reveal.d.ts +27 -0
- package/dist/text-reveal/text-reveal.js +51 -0
- package/dist/text-reveal/text-reveal.js.map +1 -0
- package/dist/text-shimmer/index.d.ts +2 -0
- package/dist/text-shimmer/index.js +2 -0
- package/dist/text-shimmer/text-shimmer.d.ts +29 -0
- package/dist/text-shimmer/text-shimmer.js +29 -0
- package/dist/text-shimmer/text-shimmer.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +35 -7
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/index.d.ts +2 -2
- package/dist/toast/index.js +2 -2
- package/dist/toast/toast.d.ts +7 -1
- package/dist/toast/toast.js +82 -40
- package/dist/toast/toast.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +9 -2
- package/dist/tooltip/tooltip.js +7 -7
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/treemap/index.d.ts +2 -0
- package/dist/treemap/index.js +2 -0
- package/dist/treemap/treemap.d.ts +53 -0
- package/dist/treemap/treemap.js +699 -0
- package/dist/treemap/treemap.js.map +1 -0
- package/dist/usage-meter/index.d.ts +2 -0
- package/dist/usage-meter/index.js +2 -0
- package/dist/usage-meter/usage-meter.d.ts +80 -0
- package/dist/usage-meter/usage-meter.js +458 -0
- package/dist/usage-meter/usage-meter.js.map +1 -0
- package/dist/waffle-chart/index.d.ts +2 -0
- package/dist/waffle-chart/index.js +2 -0
- package/dist/waffle-chart/waffle-chart.d.ts +57 -0
- package/dist/waffle-chart/waffle-chart.js +426 -0
- package/dist/waffle-chart/waffle-chart.js.map +1 -0
- package/package.json +165 -3
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn, cnAll } from "../lib/cn.js";
|
|
3
|
+
import { prefersReducedMotion, useExitBackstop, useIsomorphicLayoutEffect, useLeavingItems } from "../lib/motion.js";
|
|
4
|
+
import { labelVariants } from "../label/label.js";
|
|
5
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/morph-select/morph-select.tsx
|
|
8
|
+
const TYPEAHEAD_RESET = 600;
|
|
9
|
+
const PAGE = 8;
|
|
10
|
+
const isGroup = (item) => "options" in item;
|
|
11
|
+
/** Loose options between groups gather into unlabelled sections, so the list keeps the order it was given. */
|
|
12
|
+
function normalize(items) {
|
|
13
|
+
const out = [];
|
|
14
|
+
items.forEach((item, index) => {
|
|
15
|
+
if (isGroup(item)) {
|
|
16
|
+
out.push({
|
|
17
|
+
key: `group-${index}`,
|
|
18
|
+
label: item.label,
|
|
19
|
+
options: item.options
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const last = out[out.length - 1];
|
|
24
|
+
if (last && !last.label) last.options.push(item);
|
|
25
|
+
else out.push({
|
|
26
|
+
key: `loose-${index}`,
|
|
27
|
+
options: [item]
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
const matches = (option, needle) => `${option.label} ${option.meta ?? ""} ${option.keywords ?? ""}`.toLowerCase().includes(needle);
|
|
33
|
+
/** The closed trigger's width, rounded up. offsetWidth rounds to the nearest pixel, and half a pixel short is enough to ellipsize the label. */
|
|
34
|
+
function triggerWidth(node) {
|
|
35
|
+
const exact = node.getBoundingClientRect().width;
|
|
36
|
+
const rounded = node.offsetWidth;
|
|
37
|
+
return Math.abs(exact - rounded) <= .5 ? Math.ceil(exact - .01) : rounded + 1;
|
|
38
|
+
}
|
|
39
|
+
/** The layout the closed trigger and its invisible measuring copy share, so the copy's width is the trigger's. */
|
|
40
|
+
const triggerLayout = "box-border flex h-(--ms-h) items-center gap-2 ps-(--ms-pad) pe-10 font-medium whitespace-nowrap";
|
|
41
|
+
const iconClass = "grid size-5 flex-none place-items-center text-text-secondary [&>svg]:size-4 [&>img]:size-5 [&>img]:rounded-full [&>img]:object-cover";
|
|
42
|
+
/** The label a layer shows: the icon, then the text, or the placeholder. */
|
|
43
|
+
function Value({ option, placeholder }) {
|
|
44
|
+
if (!option) return /* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: "font-normal text-muted-foreground",
|
|
46
|
+
children: placeholder
|
|
47
|
+
});
|
|
48
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [option.icon ? /* @__PURE__ */ jsx("span", {
|
|
49
|
+
className: iconClass,
|
|
50
|
+
"aria-hidden": "true",
|
|
51
|
+
children: option.icon
|
|
52
|
+
}) : null, /* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "min-w-0 truncate",
|
|
54
|
+
children: option.label
|
|
55
|
+
})] });
|
|
56
|
+
}
|
|
57
|
+
/** A replaced label on its way out, popped out of flow where it stood and lifting away. */
|
|
58
|
+
function LeavingLayer({ id, rect, dir, fly, onDone, children }) {
|
|
59
|
+
const remove = useCallback(() => onDone(id), [onDone, id]);
|
|
60
|
+
useExitBackstop(true, remove);
|
|
61
|
+
return /* @__PURE__ */ jsx("span", {
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
"data-leaving": "",
|
|
64
|
+
onAnimationEnd: (event) => {
|
|
65
|
+
if (event.target === event.currentTarget) remove();
|
|
66
|
+
},
|
|
67
|
+
style: {
|
|
68
|
+
...rect,
|
|
69
|
+
"--dir": fly ? 1 : dir * 1.5
|
|
70
|
+
},
|
|
71
|
+
className: "absolute flex min-w-0 items-center gap-2 motion-safe:animate-field-swap-out motion-reduce:animate-fade-out",
|
|
72
|
+
children
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function MorphSelect({ label, labelHidden = false, items, value, defaultValue = null, onValueChange, placeholder = "Select", searchable = "auto", searchPlaceholder, panelWidth = 272, maxListHeight = 296, align = "start", size = "md", name, disabled = false, id, isInvalid = false, errorMessage, className }) {
|
|
76
|
+
const uid = useId();
|
|
77
|
+
const labelId = `${uid}-label`;
|
|
78
|
+
const errorId = `${uid}-error`;
|
|
79
|
+
const showError = isInvalid && errorMessage != null;
|
|
80
|
+
const listId = `${uid}-list`;
|
|
81
|
+
const optionId = (index) => `${uid}-option-${index}`;
|
|
82
|
+
const rootRef = useRef(null);
|
|
83
|
+
const anchorRef = useRef(null);
|
|
84
|
+
const shapeRef = useRef(null);
|
|
85
|
+
const measureRef = useRef(null);
|
|
86
|
+
const faceRef = useRef(null);
|
|
87
|
+
const scrollRef = useRef(null);
|
|
88
|
+
const triggerRef = useRef(null);
|
|
89
|
+
const [outsideLabel, setOutsideLabel] = useState(false);
|
|
90
|
+
const inputRef = useRef(null);
|
|
91
|
+
const slotRef = useRef(null);
|
|
92
|
+
const layerRef = useRef(null);
|
|
93
|
+
const highlightRef = useRef(null);
|
|
94
|
+
const searchRowRef = useRef(null);
|
|
95
|
+
const optionRefs = useRef(/* @__PURE__ */ new Map());
|
|
96
|
+
const sections = useMemo(() => normalize(items), [items]);
|
|
97
|
+
const all = useMemo(() => sections.flatMap((section) => section.options), [sections]);
|
|
98
|
+
const indexOf = useMemo(() => new Map(all.map((option, index) => [option.value, index])), [all]);
|
|
99
|
+
const canSearch = searchable === "auto" ? all.length > 8 : searchable;
|
|
100
|
+
const [inner, setInner] = useState(defaultValue);
|
|
101
|
+
const selected = value !== void 0 ? value : inner;
|
|
102
|
+
const selectedOption = selected === null ? void 0 : all.find((option) => option.value === selected);
|
|
103
|
+
const [open, setOpen] = useState(false);
|
|
104
|
+
const [query, setQuery] = useState("");
|
|
105
|
+
const [active, setActive] = useState(null);
|
|
106
|
+
const [change, setChange] = useState({
|
|
107
|
+
value: null,
|
|
108
|
+
dir: 1,
|
|
109
|
+
fly: null
|
|
110
|
+
});
|
|
111
|
+
const needle = query.trim().toLowerCase();
|
|
112
|
+
const visibleSections = useMemo(() => needle ? sections.map((section) => ({
|
|
113
|
+
...section,
|
|
114
|
+
options: section.options.filter((option) => matches(option, needle))
|
|
115
|
+
})).filter((section) => section.options.length) : sections, [needle, sections]);
|
|
116
|
+
const enabled = useMemo(() => visibleSections.flatMap((section) => section.options).filter((option) => !option.disabled), [visibleSections]);
|
|
117
|
+
const current = active !== null && enabled.some((option) => option.value === active) ? active : enabled[0]?.value ?? null;
|
|
118
|
+
const resultCount = visibleSections.reduce((sum, section) => sum + section.options.length, 0);
|
|
119
|
+
const sizes = useRef({
|
|
120
|
+
trigger: 0,
|
|
121
|
+
lid: 0,
|
|
122
|
+
listW: 0,
|
|
123
|
+
listH: 0
|
|
124
|
+
});
|
|
125
|
+
const live = useRef({
|
|
126
|
+
open: false,
|
|
127
|
+
anchorW: 0
|
|
128
|
+
});
|
|
129
|
+
const place = useCallback(() => {
|
|
130
|
+
const { trigger, lid, listW, listH } = sizes.current;
|
|
131
|
+
const shape = shapeRef.current;
|
|
132
|
+
const anchor = anchorRef.current;
|
|
133
|
+
if (!trigger || !lid || !shape || !anchor) return;
|
|
134
|
+
const isOpen = live.current.open;
|
|
135
|
+
if (trigger !== live.current.anchorW) {
|
|
136
|
+
anchor.toggleAttribute("data-widening", trigger > live.current.anchorW);
|
|
137
|
+
live.current.anchorW = trigger;
|
|
138
|
+
}
|
|
139
|
+
anchor.style.width = `${trigger}px`;
|
|
140
|
+
shape.style.width = `${isOpen ? Math.max(trigger, listW) : trigger}px`;
|
|
141
|
+
shape.style.height = `${isOpen ? lid + listH : lid}px`;
|
|
142
|
+
}, []);
|
|
143
|
+
const read = useCallback(() => {
|
|
144
|
+
const measure = measureRef.current;
|
|
145
|
+
const face = faceRef.current;
|
|
146
|
+
const root = rootRef.current;
|
|
147
|
+
if (!measure || !face || !root) return;
|
|
148
|
+
const trigger = triggerWidth(measure);
|
|
149
|
+
root.style.setProperty("--ms-trigger-w", `${trigger}px`);
|
|
150
|
+
sizes.current = {
|
|
151
|
+
trigger,
|
|
152
|
+
lid: measure.offsetHeight,
|
|
153
|
+
listW: face.offsetWidth,
|
|
154
|
+
listH: face.offsetHeight
|
|
155
|
+
};
|
|
156
|
+
place();
|
|
157
|
+
}, [place]);
|
|
158
|
+
useIsomorphicLayoutEffect(() => {
|
|
159
|
+
const measure = measureRef.current;
|
|
160
|
+
const face = faceRef.current;
|
|
161
|
+
const root = rootRef.current;
|
|
162
|
+
if (!measure || !face || !root) return;
|
|
163
|
+
read();
|
|
164
|
+
shapeRef.current?.offsetWidth;
|
|
165
|
+
root.setAttribute("data-ready", "");
|
|
166
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
167
|
+
const observer = new ResizeObserver(read);
|
|
168
|
+
observer.observe(measure);
|
|
169
|
+
observer.observe(face);
|
|
170
|
+
return () => observer.disconnect();
|
|
171
|
+
}, [read]);
|
|
172
|
+
useIsomorphicLayoutEffect(() => {
|
|
173
|
+
if (live.current.open === open) return;
|
|
174
|
+
live.current.open = open;
|
|
175
|
+
read();
|
|
176
|
+
}, [open, read]);
|
|
177
|
+
const scrollIntent = useRef(false);
|
|
178
|
+
useIsomorphicLayoutEffect(() => {
|
|
179
|
+
const highlight = highlightRef.current;
|
|
180
|
+
if (!highlight) return;
|
|
181
|
+
const node = open && current !== null ? optionRefs.current.get(current) : void 0;
|
|
182
|
+
if (!node) {
|
|
183
|
+
highlight.removeAttribute("data-on");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const top = node.offsetTop;
|
|
187
|
+
const height = node.offsetHeight;
|
|
188
|
+
highlight.toggleAttribute("data-jump", !highlight.hasAttribute("data-on") || prefersReducedMotion());
|
|
189
|
+
highlight.style.translate = `0 ${top}px`;
|
|
190
|
+
highlight.style.height = `${height}px`;
|
|
191
|
+
highlight.setAttribute("data-on", "");
|
|
192
|
+
const scroller = scrollRef.current;
|
|
193
|
+
if (scroller && scrollIntent.current) {
|
|
194
|
+
scrollIntent.current = false;
|
|
195
|
+
const pad = 6;
|
|
196
|
+
if (top < scroller.scrollTop + pad) scroller.scrollTop = top - pad;
|
|
197
|
+
else if (top + height > scroller.scrollTop + scroller.clientHeight - pad) scroller.scrollTop = top + height - scroller.clientHeight + pad;
|
|
198
|
+
}
|
|
199
|
+
}, [
|
|
200
|
+
current,
|
|
201
|
+
open,
|
|
202
|
+
visibleSections
|
|
203
|
+
]);
|
|
204
|
+
useIsomorphicLayoutEffect(() => {
|
|
205
|
+
setOutsideLabel(id != null && (triggerRef.current?.labels?.length ?? 0) > 0);
|
|
206
|
+
}, [id]);
|
|
207
|
+
const showSearch = open && canSearch;
|
|
208
|
+
useIsomorphicLayoutEffect(() => {
|
|
209
|
+
triggerRef.current?.toggleAttribute("inert", showSearch);
|
|
210
|
+
searchRowRef.current?.toggleAttribute("inert", !showSearch);
|
|
211
|
+
const face = faceRef.current;
|
|
212
|
+
if (!face) return;
|
|
213
|
+
face.toggleAttribute("inert", !open);
|
|
214
|
+
if (open) face.removeAttribute("aria-hidden");
|
|
215
|
+
else face.setAttribute("aria-hidden", "true");
|
|
216
|
+
}, [open, showSearch]);
|
|
217
|
+
const pendingFocus = useRef(null);
|
|
218
|
+
useIsomorphicLayoutEffect(() => {
|
|
219
|
+
const target = pendingFocus.current;
|
|
220
|
+
pendingFocus.current = null;
|
|
221
|
+
if (target === "input") inputRef.current?.focus({ preventScroll: true });
|
|
222
|
+
if (target === "trigger") triggerRef.current?.focus({ preventScroll: true });
|
|
223
|
+
}, [open]);
|
|
224
|
+
const typeahead = useRef({
|
|
225
|
+
buffer: "",
|
|
226
|
+
at: 0
|
|
227
|
+
});
|
|
228
|
+
/** Space opens and picks on keydown; the click a button fires on the matching keyup must not undo it. */
|
|
229
|
+
const suppressClick = useRef(false);
|
|
230
|
+
const [announcement, setAnnouncement] = useState("");
|
|
231
|
+
function openList(focus, seed = "") {
|
|
232
|
+
if (disabled || open) return;
|
|
233
|
+
setQuery(seed);
|
|
234
|
+
setActive(focus !== void 0 ? focus : selected);
|
|
235
|
+
scrollIntent.current = true;
|
|
236
|
+
pendingFocus.current = canSearch ? "input" : "trigger";
|
|
237
|
+
setAnnouncement("");
|
|
238
|
+
setOpen(true);
|
|
239
|
+
}
|
|
240
|
+
const close = useCallback((restoreFocus) => {
|
|
241
|
+
typeahead.current.buffer = "";
|
|
242
|
+
if (restoreFocus) pendingFocus.current = "trigger";
|
|
243
|
+
setOpen(false);
|
|
244
|
+
}, []);
|
|
245
|
+
function commit(option, source) {
|
|
246
|
+
if (!option || option.disabled) return;
|
|
247
|
+
if (option.value !== selected) {
|
|
248
|
+
let fly = null;
|
|
249
|
+
const slot = slotRef.current;
|
|
250
|
+
const part = source?.querySelector("[data-part='value']");
|
|
251
|
+
if (!prefersReducedMotion() && part && slot) {
|
|
252
|
+
const from = part.getBoundingClientRect();
|
|
253
|
+
const to = slot.getBoundingClientRect();
|
|
254
|
+
fly = {
|
|
255
|
+
x: from.left - to.left,
|
|
256
|
+
y: from.top + from.height / 2 - (to.top + to.height / 2)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const from = selected === null ? -1 : indexOf.get(selected) ?? -1;
|
|
260
|
+
const to = indexOf.get(option.value) ?? 0;
|
|
261
|
+
setChange({
|
|
262
|
+
value: option.value,
|
|
263
|
+
dir: from < 0 ? 1 : Math.sign(to - from) || 1,
|
|
264
|
+
fly
|
|
265
|
+
});
|
|
266
|
+
if (value === void 0) setInner(option.value);
|
|
267
|
+
onValueChange?.(option.value, option);
|
|
268
|
+
}
|
|
269
|
+
close(true);
|
|
270
|
+
}
|
|
271
|
+
function typeTo(char) {
|
|
272
|
+
const now = performance.now();
|
|
273
|
+
const state = typeahead.current;
|
|
274
|
+
state.buffer = now - state.at > TYPEAHEAD_RESET ? char : state.buffer + char;
|
|
275
|
+
state.at = now;
|
|
276
|
+
const buffer = state.buffer.toLowerCase();
|
|
277
|
+
const repeated = buffer.split("").every((letter) => letter === buffer[0]);
|
|
278
|
+
const search = repeated ? buffer[0] : buffer;
|
|
279
|
+
const pool = all.filter((option) => !option.disabled);
|
|
280
|
+
const from = open ? current : selected;
|
|
281
|
+
const at = pool.findIndex((option) => option.value === from);
|
|
282
|
+
const offset = repeated || buffer.length === 1 ? 1 : 0;
|
|
283
|
+
return [...pool.slice(at + offset), ...pool.slice(0, at + offset)].find((option) => option.label.toLowerCase().startsWith(search));
|
|
284
|
+
}
|
|
285
|
+
function move(to) {
|
|
286
|
+
if (to === void 0 || to === null) return;
|
|
287
|
+
scrollIntent.current = true;
|
|
288
|
+
setActive(to);
|
|
289
|
+
}
|
|
290
|
+
function onKey(event, fromInput) {
|
|
291
|
+
const { key } = event;
|
|
292
|
+
if (key === " " && !fromInput) suppressClick.current = true;
|
|
293
|
+
const printable = key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey;
|
|
294
|
+
const typing = performance.now() - typeahead.current.at < TYPEAHEAD_RESET && typeahead.current.buffer.length > 0;
|
|
295
|
+
if (!open) {
|
|
296
|
+
if (key === "ArrowDown" || key === "ArrowUp" || key === "Enter" || key === " " && !typing) {
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
openList();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (key === "Home" || key === "End") {
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
const pool = all.filter((option) => !option.disabled);
|
|
304
|
+
openList((key === "Home" ? pool[0] : pool[pool.length - 1])?.value ?? null);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (printable) {
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
if (canSearch) openList(void 0, key);
|
|
310
|
+
else openList(typeTo(key)?.value ?? selected);
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const at = enabled.findIndex((option) => option.value === current);
|
|
315
|
+
const caretKeys = fromInput && query.length > 0;
|
|
316
|
+
const pick = () => commit(enabled[at], optionRefs.current.get(current ?? ""));
|
|
317
|
+
switch (key) {
|
|
318
|
+
case "ArrowDown":
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
move(enabled[Math.min(enabled.length - 1, at + 1)]?.value);
|
|
321
|
+
return;
|
|
322
|
+
case "ArrowUp":
|
|
323
|
+
event.preventDefault();
|
|
324
|
+
if (event.altKey) {
|
|
325
|
+
pick();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
move(enabled[Math.max(0, at - 1)]?.value);
|
|
329
|
+
return;
|
|
330
|
+
case "PageDown":
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
move(enabled[Math.min(enabled.length - 1, at + PAGE)]?.value);
|
|
333
|
+
return;
|
|
334
|
+
case "PageUp":
|
|
335
|
+
event.preventDefault();
|
|
336
|
+
move(enabled[Math.max(0, at - PAGE)]?.value);
|
|
337
|
+
return;
|
|
338
|
+
case "Home":
|
|
339
|
+
if (caretKeys) return;
|
|
340
|
+
event.preventDefault();
|
|
341
|
+
move(enabled[0]?.value);
|
|
342
|
+
return;
|
|
343
|
+
case "End":
|
|
344
|
+
if (caretKeys) return;
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
move(enabled[enabled.length - 1]?.value);
|
|
347
|
+
return;
|
|
348
|
+
case "Enter":
|
|
349
|
+
event.preventDefault();
|
|
350
|
+
pick();
|
|
351
|
+
return;
|
|
352
|
+
case "Escape":
|
|
353
|
+
event.preventDefault();
|
|
354
|
+
event.stopPropagation();
|
|
355
|
+
close(true);
|
|
356
|
+
return;
|
|
357
|
+
case "Tab":
|
|
358
|
+
close(false);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (fromInput) return;
|
|
362
|
+
if (key === " " && !typing) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
pick();
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (printable) {
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
move(typeTo(key)?.value);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
if (!open) return;
|
|
374
|
+
const down = (event) => {
|
|
375
|
+
if (!rootRef.current?.contains(event.target)) close(false);
|
|
376
|
+
};
|
|
377
|
+
document.addEventListener("pointerdown", down);
|
|
378
|
+
return () => document.removeEventListener("pointerdown", down);
|
|
379
|
+
}, [close, open]);
|
|
380
|
+
function onBlur(event) {
|
|
381
|
+
const next = event.relatedTarget;
|
|
382
|
+
if (open && next && !event.currentTarget.contains(next)) close(false);
|
|
383
|
+
}
|
|
384
|
+
function onQuery(next) {
|
|
385
|
+
setQuery(next);
|
|
386
|
+
setActive(null);
|
|
387
|
+
scrollIntent.current = true;
|
|
388
|
+
if (scrollRef.current) scrollRef.current.scrollTop = 0;
|
|
389
|
+
const text = next.trim().toLowerCase();
|
|
390
|
+
const count = text ? all.filter((option) => matches(option, text)).length : all.length;
|
|
391
|
+
setAnnouncement(text ? count ? `${count} ${count === 1 ? "option" : "options"}` : "No matches" : "");
|
|
392
|
+
}
|
|
393
|
+
const layerKey = selected ?? "__empty";
|
|
394
|
+
const flying = change.value === selected ? change.fly : null;
|
|
395
|
+
const { leaving, changed, remove } = useLeavingItems(layerKey, {
|
|
396
|
+
key: layerKey,
|
|
397
|
+
node: /* @__PURE__ */ jsx(Value, {
|
|
398
|
+
option: selectedOption,
|
|
399
|
+
placeholder
|
|
400
|
+
}),
|
|
401
|
+
dir: change.dir,
|
|
402
|
+
fly: Boolean(flying)
|
|
403
|
+
}, () => layerRef.current);
|
|
404
|
+
const rootStyle = {
|
|
405
|
+
"--ms-panel-w": `${panelWidth}px`,
|
|
406
|
+
"--ms-list-max": `${maxListHeight}px`
|
|
407
|
+
};
|
|
408
|
+
const layerStyle = {
|
|
409
|
+
"--dir": change.dir,
|
|
410
|
+
...flying ? {
|
|
411
|
+
"--fly-x": `${flying.x}px`,
|
|
412
|
+
"--fly-y": `${flying.y}px`
|
|
413
|
+
} : {}
|
|
414
|
+
};
|
|
415
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
416
|
+
ref: rootRef,
|
|
417
|
+
"data-slot": "morph-select",
|
|
418
|
+
"data-open": open || void 0,
|
|
419
|
+
"data-align": align,
|
|
420
|
+
"data-size": size,
|
|
421
|
+
"data-disabled": disabled || void 0,
|
|
422
|
+
"data-invalid": isInvalid || void 0,
|
|
423
|
+
style: rootStyle,
|
|
424
|
+
onBlur,
|
|
425
|
+
className: cn("morph-select-root group/ms relative inline-grid min-w-0 justify-items-start gap-2 font-sans leading-(--leading-normal) text-foreground data-[align=end]:justify-items-end data-[open]:z-30 data-[size=sm]:text-sm data-[size=md]:text-base data-[size=lg]:text-base", className),
|
|
426
|
+
children: [
|
|
427
|
+
/* @__PURE__ */ jsx("span", {
|
|
428
|
+
id: labelId,
|
|
429
|
+
"data-slot": "morph-select-label",
|
|
430
|
+
className: cnAll(labelVariants(), labelHidden && "sr-only"),
|
|
431
|
+
children: label
|
|
432
|
+
}),
|
|
433
|
+
/* @__PURE__ */ jsxs("div", {
|
|
434
|
+
ref: anchorRef,
|
|
435
|
+
className: "morph-select-anchor",
|
|
436
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
437
|
+
ref: measureRef,
|
|
438
|
+
"aria-hidden": "true",
|
|
439
|
+
className: cnAll(triggerLayout, "morph-select-measure"),
|
|
440
|
+
children: /* @__PURE__ */ jsx(Value, {
|
|
441
|
+
option: selectedOption,
|
|
442
|
+
placeholder
|
|
443
|
+
})
|
|
444
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
445
|
+
ref: shapeRef,
|
|
446
|
+
"data-slot": "morph-select-shape",
|
|
447
|
+
"data-open": open || void 0,
|
|
448
|
+
"data-disabled": disabled || void 0,
|
|
449
|
+
"data-invalid": isInvalid || void 0,
|
|
450
|
+
className: "morph-select-shape",
|
|
451
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
452
|
+
className: "absolute inset-x-0 top-0 z-10 h-(--ms-h)",
|
|
453
|
+
children: [
|
|
454
|
+
/* @__PURE__ */ jsx("button", {
|
|
455
|
+
ref: triggerRef,
|
|
456
|
+
id,
|
|
457
|
+
type: "button",
|
|
458
|
+
role: "combobox",
|
|
459
|
+
"data-slot": "morph-select-trigger",
|
|
460
|
+
"aria-labelledby": outsideLabel ? void 0 : labelId,
|
|
461
|
+
"aria-invalid": isInvalid || void 0,
|
|
462
|
+
"aria-describedby": showError ? errorId : void 0,
|
|
463
|
+
"aria-haspopup": "listbox",
|
|
464
|
+
"aria-expanded": open,
|
|
465
|
+
"aria-controls": listId,
|
|
466
|
+
"aria-activedescendant": open && !canSearch && current !== null ? optionId(indexOf.get(current) ?? 0) : void 0,
|
|
467
|
+
disabled,
|
|
468
|
+
tabIndex: showSearch ? -1 : 0,
|
|
469
|
+
onClick: () => {
|
|
470
|
+
if (suppressClick.current) {
|
|
471
|
+
suppressClick.current = false;
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (open) close(true);
|
|
475
|
+
else openList();
|
|
476
|
+
},
|
|
477
|
+
onKeyDown: (event) => onKey(event, false),
|
|
478
|
+
onKeyUp: (event) => {
|
|
479
|
+
if (event.key === " ") window.setTimeout(() => {
|
|
480
|
+
suppressClick.current = false;
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
className: cnAll(triggerLayout, "absolute inset-0 w-full cursor-pointer border-0 bg-transparent text-start text-foreground outline-none [font-family:inherit] [font-size:inherit] [line-height:inherit] [letter-spacing:inherit] [-webkit-tap-highlight-color:transparent] [touch-action:manipulation] disabled:cursor-not-allowed"),
|
|
484
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
485
|
+
ref: slotRef,
|
|
486
|
+
"data-hidden": showSearch || void 0,
|
|
487
|
+
className: "relative block h-full min-w-0 flex-1 data-[hidden]:opacity-0 motion-safe:transition-opacity motion-safe:duration-(--duration-instant) motion-safe:ease-settle",
|
|
488
|
+
children: [leaving.map((item) => /* @__PURE__ */ jsx(LeavingLayer, {
|
|
489
|
+
id: item.id,
|
|
490
|
+
rect: item.rect,
|
|
491
|
+
dir: item.value.dir,
|
|
492
|
+
fly: item.value.fly,
|
|
493
|
+
onDone: remove,
|
|
494
|
+
children: item.value.node
|
|
495
|
+
}, item.id)), /* @__PURE__ */ jsx("span", {
|
|
496
|
+
ref: layerRef,
|
|
497
|
+
style: layerStyle,
|
|
498
|
+
className: cnAll("absolute inset-0 flex min-w-0 items-center gap-2", changed && (flying ? "motion-safe:animate-morph-select-fly motion-reduce:animate-fade-in" : "motion-safe:animate-select-value-in motion-reduce:animate-fade-in")),
|
|
499
|
+
children: /* @__PURE__ */ jsx(Value, {
|
|
500
|
+
option: selectedOption,
|
|
501
|
+
placeholder
|
|
502
|
+
})
|
|
503
|
+
}, layerKey)]
|
|
504
|
+
})
|
|
505
|
+
}),
|
|
506
|
+
canSearch ? /* @__PURE__ */ jsxs("div", {
|
|
507
|
+
ref: searchRowRef,
|
|
508
|
+
className: cnAll("absolute inset-0 flex items-center gap-2 ps-(--ms-pad) pe-1.5 motion-safe:transition-opacity motion-safe:duration-(--duration-quick) motion-safe:ease-settle", showSearch ? "opacity-100" : "pointer-events-none opacity-0"),
|
|
509
|
+
children: [
|
|
510
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
511
|
+
"aria-hidden": "true",
|
|
512
|
+
viewBox: "0 0 16 16",
|
|
513
|
+
fill: "none",
|
|
514
|
+
stroke: "currentColor",
|
|
515
|
+
strokeWidth: "1.75",
|
|
516
|
+
strokeLinecap: "round",
|
|
517
|
+
strokeLinejoin: "round",
|
|
518
|
+
className: "size-4 flex-none text-muted-foreground",
|
|
519
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
520
|
+
cx: "7",
|
|
521
|
+
cy: "7",
|
|
522
|
+
r: "4.25"
|
|
523
|
+
}), /* @__PURE__ */ jsx("path", { d: "m10.5 10.5 3 3" })]
|
|
524
|
+
}),
|
|
525
|
+
/* @__PURE__ */ jsx("input", {
|
|
526
|
+
ref: inputRef,
|
|
527
|
+
type: "text",
|
|
528
|
+
role: "combobox",
|
|
529
|
+
"data-slot": "morph-select-search",
|
|
530
|
+
"aria-label": `Search ${label.toLowerCase()}`,
|
|
531
|
+
"aria-invalid": isInvalid || void 0,
|
|
532
|
+
"aria-describedby": showError ? errorId : void 0,
|
|
533
|
+
"aria-expanded": open,
|
|
534
|
+
"aria-controls": listId,
|
|
535
|
+
"aria-autocomplete": "list",
|
|
536
|
+
"aria-activedescendant": open && current !== null ? optionId(indexOf.get(current) ?? 0) : void 0,
|
|
537
|
+
placeholder: searchPlaceholder ?? selectedOption?.label ?? "Search",
|
|
538
|
+
value: query,
|
|
539
|
+
autoComplete: "off",
|
|
540
|
+
spellCheck: false,
|
|
541
|
+
onChange: (event) => onQuery(event.target.value),
|
|
542
|
+
onKeyDown: (event) => onKey(event, true),
|
|
543
|
+
className: "h-full min-w-0 flex-1 border-0 bg-transparent p-0 [font:inherit] text-foreground outline-none placeholder:text-muted-foreground"
|
|
544
|
+
}),
|
|
545
|
+
query ? /* @__PURE__ */ jsx("button", {
|
|
546
|
+
type: "button",
|
|
547
|
+
"aria-label": "Clear search",
|
|
548
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
549
|
+
onClick: () => {
|
|
550
|
+
onQuery("");
|
|
551
|
+
inputRef.current?.focus();
|
|
552
|
+
},
|
|
553
|
+
className: "grid size-6 flex-none cursor-pointer place-items-center rounded-pill border-0 bg-muted p-0 text-text-secondary outline-none motion-safe:animate-field-clear-in motion-reduce:animate-fade-in hover:text-foreground",
|
|
554
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
555
|
+
"aria-hidden": "true",
|
|
556
|
+
viewBox: "0 0 16 16",
|
|
557
|
+
fill: "none",
|
|
558
|
+
stroke: "currentColor",
|
|
559
|
+
strokeWidth: "1.75",
|
|
560
|
+
strokeLinecap: "round",
|
|
561
|
+
className: "size-3.5",
|
|
562
|
+
children: /* @__PURE__ */ jsx("path", { d: "m4 4 8 8M12 4l-8 8" })
|
|
563
|
+
})
|
|
564
|
+
}) : null,
|
|
565
|
+
/* @__PURE__ */ jsx("button", {
|
|
566
|
+
type: "button",
|
|
567
|
+
"aria-label": `Close ${label.toLowerCase()}`,
|
|
568
|
+
onClick: () => close(true),
|
|
569
|
+
className: "size-9 flex-none cursor-pointer rounded-pill border-0 bg-transparent p-0 outline-none motion-safe:transition-[background-color] motion-safe:duration-(--duration-quick) motion-safe:ease-settle hover:bg-muted"
|
|
570
|
+
})
|
|
571
|
+
]
|
|
572
|
+
}) : null,
|
|
573
|
+
/* @__PURE__ */ jsx("svg", {
|
|
574
|
+
"aria-hidden": "true",
|
|
575
|
+
viewBox: "0 0 16 16",
|
|
576
|
+
fill: "none",
|
|
577
|
+
stroke: "currentColor",
|
|
578
|
+
strokeWidth: "1.75",
|
|
579
|
+
strokeLinecap: "round",
|
|
580
|
+
strokeLinejoin: "round",
|
|
581
|
+
className: "pointer-events-none absolute end-4 top-1/2 -mt-2 size-4 text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-data-[open]/ms:rotate-180",
|
|
582
|
+
children: /* @__PURE__ */ jsx("path", { d: "m4 6 4 4 4-4" })
|
|
583
|
+
})
|
|
584
|
+
]
|
|
585
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
586
|
+
ref: faceRef,
|
|
587
|
+
"data-open": open || void 0,
|
|
588
|
+
className: "morph-select-face",
|
|
589
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
590
|
+
ref: scrollRef,
|
|
591
|
+
className: "max-h-(--ms-list-max) overflow-y-auto overscroll-contain pt-1.5 [scrollbar-width:thin]",
|
|
592
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
593
|
+
id: listId,
|
|
594
|
+
role: "listbox",
|
|
595
|
+
"aria-labelledby": labelId,
|
|
596
|
+
className: "relative grid grid-cols-1 gap-0.5",
|
|
597
|
+
children: [
|
|
598
|
+
/* @__PURE__ */ jsx("span", {
|
|
599
|
+
ref: highlightRef,
|
|
600
|
+
"aria-hidden": "true",
|
|
601
|
+
className: "morph-select-highlight"
|
|
602
|
+
}),
|
|
603
|
+
visibleSections.map((section) => {
|
|
604
|
+
const rows = section.options.map((option) => {
|
|
605
|
+
const index = indexOf.get(option.value) ?? 0;
|
|
606
|
+
const isSelected = option.value === selected;
|
|
607
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
608
|
+
id: optionId(index),
|
|
609
|
+
role: "option",
|
|
610
|
+
"aria-selected": isSelected,
|
|
611
|
+
"aria-disabled": option.disabled || void 0,
|
|
612
|
+
"data-slot": "morph-select-option",
|
|
613
|
+
"data-active": option.value === current || void 0,
|
|
614
|
+
ref: (node) => {
|
|
615
|
+
if (node) optionRefs.current.set(option.value, node);
|
|
616
|
+
else optionRefs.current.delete(option.value);
|
|
617
|
+
},
|
|
618
|
+
onPointerMove: (event) => {
|
|
619
|
+
if (event.pointerType === "mouse" && !option.disabled && option.value !== current) setActive(option.value);
|
|
620
|
+
},
|
|
621
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
622
|
+
onClick: (event) => commit(option, event.currentTarget),
|
|
623
|
+
className: "morph-select-option relative box-border flex min-h-9 cursor-pointer select-none items-center gap-2 rounded-lg text-text-secondary outline-none data-[active]:text-foreground aria-selected:text-foreground aria-disabled:cursor-not-allowed aria-disabled:opacity-(--opacity-disabled) motion-safe:transition-colors motion-safe:duration-(--duration-quick) motion-safe:ease-settle",
|
|
624
|
+
children: [
|
|
625
|
+
/* @__PURE__ */ jsxs("span", {
|
|
626
|
+
"data-part": "value",
|
|
627
|
+
className: "flex min-w-0 flex-1 items-center gap-2 font-medium",
|
|
628
|
+
children: [option.icon ? /* @__PURE__ */ jsx("span", {
|
|
629
|
+
className: iconClass,
|
|
630
|
+
"aria-hidden": "true",
|
|
631
|
+
children: option.icon
|
|
632
|
+
}) : null, /* @__PURE__ */ jsx("span", {
|
|
633
|
+
className: "min-w-0 truncate",
|
|
634
|
+
children: option.label
|
|
635
|
+
})]
|
|
636
|
+
}),
|
|
637
|
+
option.meta ? /* @__PURE__ */ jsx("span", {
|
|
638
|
+
className: "flex-none text-xs tabular-nums text-muted-foreground",
|
|
639
|
+
children: option.meta
|
|
640
|
+
}) : null,
|
|
641
|
+
/* @__PURE__ */ jsx("span", {
|
|
642
|
+
"aria-hidden": "true",
|
|
643
|
+
"data-on": isSelected || void 0,
|
|
644
|
+
className: "grid size-4 flex-none scale-60 place-items-center text-foreground opacity-0 data-[on]:scale-100 data-[on]:opacity-100 motion-safe:transition-[opacity,scale] motion-safe:duration-(--duration-quick) motion-safe:ease-settle",
|
|
645
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
646
|
+
viewBox: "0 0 16 16",
|
|
647
|
+
fill: "none",
|
|
648
|
+
stroke: "currentColor",
|
|
649
|
+
strokeWidth: "1.75",
|
|
650
|
+
strokeLinecap: "round",
|
|
651
|
+
strokeLinejoin: "round",
|
|
652
|
+
className: "size-4",
|
|
653
|
+
children: /* @__PURE__ */ jsx("path", { d: "m3.5 8.5 3 3 6-6" })
|
|
654
|
+
})
|
|
655
|
+
})
|
|
656
|
+
]
|
|
657
|
+
}, option.value);
|
|
658
|
+
});
|
|
659
|
+
return section.label ? /* @__PURE__ */ jsxs("div", {
|
|
660
|
+
role: "group",
|
|
661
|
+
"aria-labelledby": `${uid}-${section.key}`,
|
|
662
|
+
className: "grid grid-cols-1 gap-0.5 not-first:mt-1",
|
|
663
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
664
|
+
id: `${uid}-${section.key}`,
|
|
665
|
+
role: "presentation",
|
|
666
|
+
className: "px-2.5 pt-2 pb-1 text-xs text-muted-foreground",
|
|
667
|
+
children: section.label
|
|
668
|
+
}), rows]
|
|
669
|
+
}, section.key) : /* @__PURE__ */ jsx("div", {
|
|
670
|
+
role: "presentation",
|
|
671
|
+
className: "grid grid-cols-1 gap-0.5 not-first:mt-1",
|
|
672
|
+
children: rows
|
|
673
|
+
}, section.key);
|
|
674
|
+
}),
|
|
675
|
+
resultCount === 0 ? /* @__PURE__ */ jsxs("p", {
|
|
676
|
+
className: "m-0 px-2.5 pt-3 pb-3.5 text-sm text-muted-foreground",
|
|
677
|
+
children: [
|
|
678
|
+
"No matches for “",
|
|
679
|
+
query.trim(),
|
|
680
|
+
"”"
|
|
681
|
+
]
|
|
682
|
+
}) : null
|
|
683
|
+
]
|
|
684
|
+
})
|
|
685
|
+
})
|
|
686
|
+
})]
|
|
687
|
+
})]
|
|
688
|
+
}),
|
|
689
|
+
showError ? /* @__PURE__ */ jsx("span", {
|
|
690
|
+
id: errorId,
|
|
691
|
+
"data-slot": "morph-select-error",
|
|
692
|
+
className: "text-sm leading-(--leading-normal) text-destructive-strong",
|
|
693
|
+
children: errorMessage
|
|
694
|
+
}) : null,
|
|
695
|
+
name ? /* @__PURE__ */ jsx("input", {
|
|
696
|
+
type: "hidden",
|
|
697
|
+
name,
|
|
698
|
+
value: selected ?? ""
|
|
699
|
+
}) : null,
|
|
700
|
+
/* @__PURE__ */ jsx("span", {
|
|
701
|
+
className: "sr-only",
|
|
702
|
+
role: "status",
|
|
703
|
+
"aria-live": "polite",
|
|
704
|
+
children: announcement
|
|
705
|
+
})
|
|
706
|
+
]
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
//#endregion
|
|
710
|
+
export { MorphSelect };
|
|
711
|
+
|
|
712
|
+
//# sourceMappingURL=morph-select.js.map
|