@datum-cloud/datum-ui 0.6.1 → 0.7.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/README.md +10 -0
- package/dist/action-row-DnhBhMtt.mjs +22 -0
- package/dist/app-navigation/index.mjs +2 -2
- package/dist/{app-navigation-84ro28PU.mjs → app-navigation-D0EBWUwJ.mjs} +48 -3
- package/dist/autocomplete/index.mjs +1 -1
- package/dist/autocomplete-DdbTQe6u.mjs +141 -0
- package/dist/autosearch/index.mjs +100 -92
- package/dist/avatar-stack/index.mjs +1 -1
- package/dist/{avatar-stack-oVr8tsU7.mjs → avatar-stack-CDhlA1Nm.mjs} +1 -1
- package/dist/calendar/index.mjs +1 -1
- package/dist/{calendar-DEkCw7I1.mjs → calendar-C-Hbf74r.mjs} +4 -4
- package/dist/{calendar-date-picker-CDT-8Ha8.mjs → calendar-date-picker-BaykEs6j.mjs} +324 -240
- package/dist/code-editor/index.mjs +1 -1
- package/dist/components/base/date-picker/index.d.ts +4 -0
- package/dist/components/base/date-picker/index.d.ts.map +1 -0
- package/dist/components/base/date-picker/types.d.ts +7 -0
- package/dist/components/base/date-picker/types.d.ts.map +1 -0
- package/dist/components/base/date-picker/use-date-constraints.d.ts +8 -0
- package/dist/components/base/date-picker/use-date-constraints.d.ts.map +1 -0
- package/dist/components/base/index.d.ts +3 -0
- package/dist/components/base/index.d.ts.map +1 -1
- package/dist/components/base/mobile-sheet/context.d.ts +13 -0
- package/dist/components/base/mobile-sheet/context.d.ts.map +1 -0
- package/dist/components/base/mobile-sheet/index.d.ts +3 -0
- package/dist/components/base/mobile-sheet/index.d.ts.map +1 -0
- package/dist/components/base/mobile-sheet/mobile-sheet.d.ts +14 -0
- package/dist/components/base/mobile-sheet/mobile-sheet.d.ts.map +1 -0
- package/dist/components/base/option-picker/index.d.ts +5 -0
- package/dist/components/base/option-picker/index.d.ts.map +1 -0
- package/dist/components/base/option-picker/option-list.d.ts +3 -0
- package/dist/components/base/option-picker/option-list.d.ts.map +1 -0
- package/dist/components/base/option-picker/types.d.ts +71 -0
- package/dist/components/base/option-picker/types.d.ts.map +1 -0
- package/dist/components/base/option-picker/use-option-picker.d.ts +4 -0
- package/dist/components/base/option-picker/use-option-picker.d.ts.map +1 -0
- package/dist/components/base/responsive-dropdown/index.d.ts +2 -0
- package/dist/components/base/responsive-dropdown/index.d.ts.map +1 -0
- package/dist/components/base/responsive-dropdown/responsive-dropdown.d.ts +25 -0
- package/dist/components/base/responsive-dropdown/responsive-dropdown.d.ts.map +1 -0
- package/dist/components/base/responsive-popover/index.d.ts +2 -0
- package/dist/components/base/responsive-popover/index.d.ts.map +1 -0
- package/dist/components/base/responsive-popover/responsive-popover.d.ts +46 -0
- package/dist/components/base/responsive-popover/responsive-popover.d.ts.map +1 -0
- package/dist/components/base/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/features/app-navigation/app-navigation.d.ts +5 -3
- package/dist/components/features/app-navigation/app-navigation.d.ts.map +1 -1
- package/dist/components/features/autocomplete/autocomplete.d.ts +2 -2
- package/dist/components/features/autocomplete/autocomplete.d.ts.map +1 -1
- package/dist/components/features/autocomplete/autocomplete.types.d.ts +7 -16
- package/dist/components/features/autocomplete/autocomplete.types.d.ts.map +1 -1
- package/dist/components/features/autocomplete/trigger.d.ts +20 -0
- package/dist/components/features/autocomplete/trigger.d.ts.map +1 -0
- package/dist/components/features/autosearch/autosearch.d.ts +1 -1
- package/dist/components/features/autosearch/autosearch.d.ts.map +1 -1
- package/dist/components/features/autosearch/autosearch.types.d.ts +4 -0
- package/dist/components/features/autosearch/autosearch.types.d.ts.map +1 -1
- package/dist/components/features/calendar-date-picker/calendar-date-picker.d.ts +3 -37
- package/dist/components/features/calendar-date-picker/calendar-date-picker.d.ts.map +1 -1
- package/dist/components/features/calendar-date-picker/calendar-header.d.ts +13 -0
- package/dist/components/features/calendar-date-picker/calendar-header.d.ts.map +1 -0
- package/dist/components/features/calendar-date-picker/calendar-presets.d.ts +9 -0
- package/dist/components/features/calendar-date-picker/calendar-presets.d.ts.map +1 -0
- package/dist/components/features/calendar-date-picker/date-trigger.d.ts +24 -0
- package/dist/components/features/calendar-date-picker/date-trigger.d.ts.map +1 -0
- package/dist/components/features/calendar-date-picker/index.d.ts +2 -1
- package/dist/components/features/calendar-date-picker/index.d.ts.map +1 -1
- package/dist/components/features/calendar-date-picker/types.d.ts +42 -0
- package/dist/components/features/calendar-date-picker/types.d.ts.map +1 -0
- package/dist/components/features/calendar-date-picker/use-calendar-date-picker.d.ts +48 -0
- package/dist/components/features/calendar-date-picker/use-calendar-date-picker.d.ts.map +1 -0
- package/dist/components/features/data-table/components/row-actions.d.ts +1 -1
- package/dist/components/features/data-table/components/row-actions.d.ts.map +1 -1
- package/dist/components/features/data-table/filters/checkbox-filter.d.ts +1 -1
- package/dist/components/features/data-table/filters/checkbox-filter.d.ts.map +1 -1
- package/dist/components/features/data-table/filters/select-filter.d.ts +1 -1
- package/dist/components/features/data-table/filters/select-filter.d.ts.map +1 -1
- package/dist/components/features/data-table/types.d.ts +11 -12
- package/dist/components/features/data-table/types.d.ts.map +1 -1
- package/dist/components/features/date-time-picker/date-time-picker.d.ts +1 -1
- package/dist/components/features/date-time-picker/date-time-picker.d.ts.map +1 -1
- package/dist/components/features/date-time-picker/types.d.ts +23 -0
- package/dist/components/features/date-time-picker/types.d.ts.map +1 -1
- package/dist/components/features/form/components/form-combobox.d.ts +7 -44
- package/dist/components/features/form/components/form-combobox.d.ts.map +1 -1
- package/dist/components/features/form/components/form-dialog.d.ts +2 -1
- package/dist/components/features/form/components/form-dialog.d.ts.map +1 -1
- package/dist/components/features/form/components/form-field.d.ts +1 -1
- package/dist/components/features/form/components/form-field.d.ts.map +1 -1
- package/dist/components/features/form/types/index.d.ts +4 -0
- package/dist/components/features/form/types/index.d.ts.map +1 -1
- package/dist/components/features/index.d.ts +2 -0
- package/dist/components/features/index.d.ts.map +1 -1
- package/dist/components/features/more-actions/action-row.d.ts +9 -0
- package/dist/components/features/more-actions/action-row.d.ts.map +1 -0
- package/dist/components/features/more-actions/index.d.ts +3 -1
- package/dist/components/features/more-actions/index.d.ts.map +1 -1
- package/dist/components/features/more-actions/more-actions.d.ts +8 -14
- package/dist/components/features/more-actions/more-actions.d.ts.map +1 -1
- package/dist/components/features/more-actions/types.d.ts +24 -0
- package/dist/components/features/more-actions/types.d.ts.map +1 -0
- package/dist/components/features/multi-select/index.d.ts +3 -0
- package/dist/components/features/multi-select/index.d.ts.map +1 -0
- package/dist/components/features/multi-select/multi-select.d.ts +147 -0
- package/dist/components/features/multi-select/multi-select.d.ts.map +1 -0
- package/dist/components/features/page-title/page-title.d.ts.map +1 -1
- package/dist/components/features/rich-text-editor/index.d.ts +4 -0
- package/dist/components/features/rich-text-editor/index.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/rich-text-content.d.ts +3 -0
- package/dist/components/features/rich-text-editor/rich-text-content.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/rich-text-editor.d.ts +28 -0
- package/dist/components/features/rich-text-editor/rich-text-editor.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/bold-toolbar.d.ts +2 -0
- package/dist/components/features/rich-text-editor/toolbar/bold-toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/italic-toolbar.d.ts +2 -0
- package/dist/components/features/rich-text-editor/toolbar/italic-toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/link-toolbar.d.ts +2 -0
- package/dist/components/features/rich-text-editor/toolbar/link-toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/strike-toolbar.d.ts +2 -0
- package/dist/components/features/rich-text-editor/toolbar/strike-toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/toolbar-button.d.ts +17 -0
- package/dist/components/features/rich-text-editor/toolbar/toolbar-button.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/toolbar.d.ts +6 -0
- package/dist/components/features/rich-text-editor/toolbar/toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/toolbar/underline-toolbar.d.ts +2 -0
- package/dist/components/features/rich-text-editor/toolbar/underline-toolbar.d.ts.map +1 -0
- package/dist/components/features/rich-text-editor/types.d.ts +20 -0
- package/dist/components/features/rich-text-editor/types.d.ts.map +1 -0
- package/dist/components/features/tag-input/tag-input.d.ts +12 -1
- package/dist/components/features/tag-input/tag-input.d.ts.map +1 -1
- package/dist/components/features/task-queue/core/task-queue-dropdown.d.ts.map +1 -1
- package/dist/components/features/time-picker/time-picker.d.ts +1 -17
- package/dist/components/features/time-picker/time-picker.d.ts.map +1 -1
- package/dist/components/features/time-picker/types.d.ts +20 -18
- package/dist/components/features/time-picker/types.d.ts.map +1 -1
- package/dist/components/features/time-picker/use-time-slots.d.ts +10 -0
- package/dist/components/features/time-picker/use-time-slots.d.ts.map +1 -0
- package/dist/components/features/time-range-picker/components/absolute-range-panel.d.ts.map +1 -1
- package/dist/components/features/time-range-picker/time-range-picker.d.ts.map +1 -1
- package/dist/data-table/index.mjs +60 -175
- package/dist/date-picker/index.mjs +2 -2
- package/dist/date-time-picker/index.mjs +1 -1
- package/dist/{date-time-picker-BomrW07W.mjs → date-time-picker-DKOxrhmc.mjs} +64 -49
- package/dist/dropdown/index.mjs +109 -1
- package/dist/dropzone/index.mjs +1 -1
- package/dist/empty-content/index.mjs +1 -1
- package/dist/form/adapters/conform/index.mjs +2 -2
- package/dist/form/adapters/rhf/index.mjs +2 -2
- package/dist/form/index.mjs +2 -2
- package/dist/form/stepper/index.mjs +3 -3
- package/dist/{form-B3rQ4CH9.mjs → form-CCNN9VtJ.mjs} +27 -30
- package/dist/grid/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.mjs +4 -3
- package/dist/hooks/use-breakpoint.d.ts +9 -0
- package/dist/hooks/use-breakpoint.d.ts.map +1 -0
- package/dist/index.mjs +48 -41
- package/dist/input-number/index.mjs +1 -1
- package/dist/loader-overlay/index.mjs +1 -1
- package/dist/map/index.mjs +1 -1
- package/dist/{map-CWIQ-eql.mjs → map-DRzZDNtB.mjs} +83 -4
- package/dist/mobile-sheet/index.mjs +2 -0
- package/dist/mobile-sheet-BxMvkzAj.mjs +61 -0
- package/dist/more-actions/index.mjs +3 -2
- package/dist/more-actions-Ca5qqd0H.mjs +49 -0
- package/dist/multi-select/index.mjs +2 -0
- package/dist/multi-select-DM_dxnSV.mjs +235 -0
- package/dist/page-title/index.mjs +1 -1
- package/dist/{page-title-ChsnpBiH.mjs → page-title-ChLiv6gB.mjs} +3 -2
- package/dist/popover/index.mjs +1 -1
- package/dist/radio-group/index.mjs +1 -1
- package/dist/responsive-dropdown/index.mjs +2 -0
- package/dist/responsive-dropdown-IFroDgKn.mjs +53 -0
- package/dist/responsive-popover/index.mjs +2 -0
- package/dist/responsive-popover-D-t9bxSN.mjs +61 -0
- package/dist/rich-text-editor/index.mjs +2 -0
- package/dist/rich-text-editor-CQH_U4T5.mjs +293 -0
- package/dist/select/index.mjs +1 -1
- package/dist/sheet/index.mjs +2 -2
- package/dist/{sheet-BzXksqYY.mjs → sheet-LhUgozvg.mjs} +1 -1
- package/dist/sidebar/index.mjs +1 -1
- package/dist/{sidebar-BnhnjvfO.mjs → sidebar-B8LQJiNI.mjs} +3 -3
- package/dist/skeleton/index.mjs +1 -1
- package/dist/{skeleton-D1MUhAVo.mjs → skeleton-D4HOEiOZ.mjs} +1 -1
- package/dist/spinner/index.mjs +1 -1
- package/dist/stepper/index.mjs +1 -1
- package/dist/styles/canela.css +23 -0
- package/dist/styles/fonts/CanelaText-Regular.ttf +0 -0
- package/dist/styles/tokens/figma-tokens.css +4 -0
- package/dist/switch/index.mjs +1 -1
- package/dist/table/index.mjs +1 -1
- package/dist/tag-input/index.mjs +1 -1
- package/dist/{tag-input-T9cUX9-G.mjs → tag-input-Bf4GMptp.mjs} +29 -14
- package/dist/task-queue/index.mjs +1 -1
- package/dist/{task-queue-dropdown-Wcbj-f0V.mjs → task-queue-dropdown-D-LncEWm.mjs} +39 -39
- package/dist/textarea/index.mjs +1 -1
- package/dist/theme/index.mjs +1 -1
- package/dist/time-picker/index.mjs +1 -1
- package/dist/time-picker-BZF5jbF6.mjs +99 -0
- package/dist/{to-api-format-Bh3c01gr.mjs → to-api-format-CgKcC9SK.mjs} +144 -119
- package/dist/toast/index.mjs +2 -2
- package/dist/{toast-DpxlFNNx.mjs → toast-DDdLgY53.mjs} +1 -1
- package/dist/tooltip/index.mjs +1 -1
- package/dist/{tooltip-Cruvl5F6.mjs → tooltip-a7NTDCWw.mjs} +74 -17
- package/dist/transfer/index.mjs +1 -1
- package/dist/{types-BZNk3q65.mjs → types-CKIe2WlV.mjs} +2 -2
- package/dist/typography/index.mjs +1 -1
- package/dist/use-breakpoint-DGcVmB3c.mjs +36 -0
- package/dist/{use-copy-to-clipboard-uNeeVHC4.mjs → use-copy-to-clipboard-D7KyLIAt.mjs} +1 -1
- package/dist/use-date-constraints-R3H4lIoT.mjs +41 -0
- package/dist/use-option-picker-BXQOfyrK.mjs +215 -0
- package/dist/visually-hidden/index.mjs +1 -1
- package/package.json +61 -6
- package/dist/autocomplete-CkYJueBL.mjs +0 -293
- package/dist/combobox/index.mjs +0 -2
- package/dist/combobox-B-C9lJeD.mjs +0 -97
- package/dist/components/features/combobox/combobox.d.ts +0 -27
- package/dist/components/features/combobox/combobox.d.ts.map +0 -1
- package/dist/components/features/combobox/index.d.ts +0 -3
- package/dist/components/features/combobox/index.d.ts.map +0 -1
- package/dist/components/features/combobox/types.d.ts +0 -84
- package/dist/components/features/combobox/types.d.ts.map +0 -1
- package/dist/dropdown-DZiAt-jS.mjs +0 -110
- package/dist/dropdown-menu-lALvDnab.mjs +0 -85
- package/dist/more-actions-ILnEZq_E.mjs +0 -52
- package/dist/time-picker-BoF7pZZ2.mjs +0 -43
- /package/dist/{adapter-context-rWveHhDd.mjs → adapter-context-NyGTDZYq.mjs} +0 -0
- /package/dist/{col-1T0Q3SlH.mjs → col-DISdGlqY.mjs} +0 -0
- /package/dist/{dropzone-ogtpQ4fy.mjs → dropzone-Bt0plEuw.mjs} +0 -0
- /package/dist/{empty-content-C63GPJ5d.mjs → empty-content-CBh5bbtJ.mjs} +0 -0
- /package/dist/{form-context-Ccxm-wqL.mjs → form-context-CeKyvO-A.mjs} +0 -0
- /package/dist/{hooks-D8r2M2U6.mjs → hooks-DQXVwbrs.mjs} +0 -0
- /package/dist/{input-number-a7uydAsw.mjs → input-number-Diu-C6d5.mjs} +0 -0
- /package/dist/{loader-overlay-BTFdkp7W.mjs → loader-overlay-C2WDla6V.mjs} +0 -0
- /package/dist/{map-leaflet-imports-CRSKA79m.mjs → map-leaflet-imports-BkUrNU37.mjs} +0 -0
- /package/dist/{popover-FJAcbYoH.mjs → popover-JOuXJOZ2.mjs} +0 -0
- /package/dist/{radio-group-CiITR0LO.mjs → radio-group-70UjJBb5.mjs} +0 -0
- /package/dist/{select-CiLR_DiQ.mjs → select-zxwykvQn.mjs} +0 -0
- /package/dist/{sheet-Di3b-oPu.mjs → sheet-DVEToCVY.mjs} +0 -0
- /package/dist/{skeleton-BKl4mfJt.mjs → skeleton-D2xuJdE1.mjs} +0 -0
- /package/dist/{spinner-OyOf9-Yu.mjs → spinner-CgPI3DDi.mjs} +0 -0
- /package/dist/{stepper-DvIOp0hh.mjs → stepper-Beb-zbdL.mjs} +0 -0
- /package/dist/{switch-DQJQhPIQ.mjs → switch-DcSF42Kc.mjs} +0 -0
- /package/dist/{table-Cdsh-39-.mjs → table-DWGT4cqh.mjs} +0 -0
- /package/dist/{textarea-BwD-MmTV.mjs → textarea-BoChBcFz.mjs} +0 -0
- /package/dist/{themes-DG1md8FI.mjs → themes-CAiN4b6G.mjs} +0 -0
- /package/dist/{toast-BWnN5fax.mjs → toast-D5XD7goD.mjs} +0 -0
- /package/dist/{transfer-46C-rFFW.mjs → transfer-CoGPwOc6.mjs} +0 -0
- /package/dist/{typography-ClB8k55E.mjs → typography-TRKP_CLT.mjs} +0 -0
- /package/dist/{use-display-touched-I39aXEBD.mjs → use-display-touched-8VGszCqj.mjs} +0 -0
- /package/dist/{visuallyhidden-BLUsJpYH.mjs → visuallyhidden-BHOPczmW.mjs} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { endOfDay, startOfDay } from "date-fns";
|
|
3
|
+
//#region src/components/base/date-picker/use-date-constraints.ts
|
|
4
|
+
function useDateConstraints({ minDate, maxDate, disablePast, disableFuture }) {
|
|
5
|
+
const today = useMemo(() => /* @__PURE__ */ new Date(), []);
|
|
6
|
+
const effectiveMinDate = useMemo(() => {
|
|
7
|
+
let min = minDate;
|
|
8
|
+
if (disablePast) {
|
|
9
|
+
const todayStart = startOfDay(today);
|
|
10
|
+
min = min ? min > todayStart ? min : todayStart : todayStart;
|
|
11
|
+
}
|
|
12
|
+
return min;
|
|
13
|
+
}, [
|
|
14
|
+
minDate,
|
|
15
|
+
disablePast,
|
|
16
|
+
today
|
|
17
|
+
]);
|
|
18
|
+
const effectiveMaxDate = useMemo(() => {
|
|
19
|
+
let max = maxDate;
|
|
20
|
+
if (disableFuture) {
|
|
21
|
+
const todayEnd = endOfDay(today);
|
|
22
|
+
max = max ? max < todayEnd ? max : todayEnd : todayEnd;
|
|
23
|
+
}
|
|
24
|
+
return max;
|
|
25
|
+
}, [
|
|
26
|
+
maxDate,
|
|
27
|
+
disableFuture,
|
|
28
|
+
today
|
|
29
|
+
]);
|
|
30
|
+
return {
|
|
31
|
+
effectiveMinDate,
|
|
32
|
+
effectiveMaxDate,
|
|
33
|
+
isDateDisabled: useCallback((date) => {
|
|
34
|
+
if (effectiveMinDate && date < effectiveMinDate) return true;
|
|
35
|
+
if (effectiveMaxDate && date > effectiveMaxDate) return true;
|
|
36
|
+
return false;
|
|
37
|
+
}, [effectiveMinDate, effectiveMaxDate])
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useDateConstraints as t };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { a as CommandInput, i as CommandGroup, o as CommandItem, r as CommandEmpty, s as CommandList, t as Command } from "./command-DqHWukGK.mjs";
|
|
2
|
+
import { t as LoaderOverlay } from "./loader-overlay-C2WDla6V.mjs";
|
|
3
|
+
import { CheckIcon } from "lucide-react";
|
|
4
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
7
|
+
//#region src/components/base/option-picker/types.ts
|
|
8
|
+
/**
|
|
9
|
+
* Detect whether an options prop is grouped.
|
|
10
|
+
*
|
|
11
|
+
* Treats empty arrays as flat (zero-option lists do not need group headings).
|
|
12
|
+
*/
|
|
13
|
+
function isGroupedOptions(options) {
|
|
14
|
+
if (options.length === 0) return false;
|
|
15
|
+
return "options" in options[0];
|
|
16
|
+
}
|
|
17
|
+
/** Internal helper — flatten grouped or flat options into a single array. */
|
|
18
|
+
function flattenOptions(options) {
|
|
19
|
+
return isGroupedOptions(options) ? options.flatMap((g) => g.options) : options;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/base/option-picker/option-list.tsx
|
|
23
|
+
function defaultRenderOption(option, isSelected) {
|
|
24
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
|
|
25
|
+
className: "flex min-w-0 flex-1 flex-col",
|
|
26
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
27
|
+
className: "truncate",
|
|
28
|
+
children: option.label
|
|
29
|
+
}), option.description && /* @__PURE__ */ jsx("span", {
|
|
30
|
+
className: "text-muted-foreground truncate text-xs",
|
|
31
|
+
children: option.description
|
|
32
|
+
})]
|
|
33
|
+
}), isSelected && /* @__PURE__ */ jsx(CheckIcon, { className: "text-primary ml-auto size-4 shrink-0" })] });
|
|
34
|
+
}
|
|
35
|
+
function OptionList({ picker, searchPlaceholder, disableSearch, emptyContent, renderOption, header, footer, loading, virtualize, itemSize = 36, listClassName }) {
|
|
36
|
+
const { filteredOptions, search, setSearch, isSelected, toggle, creatableValue } = picker;
|
|
37
|
+
const grouped = isGroupedOptions(filteredOptions);
|
|
38
|
+
const row = renderOption ?? defaultRenderOption;
|
|
39
|
+
const canVirtualize = virtualize && !grouped;
|
|
40
|
+
return /* @__PURE__ */ jsxs(Command, {
|
|
41
|
+
shouldFilter: false,
|
|
42
|
+
children: [
|
|
43
|
+
header,
|
|
44
|
+
!disableSearch && /* @__PURE__ */ jsx(CommandInput, {
|
|
45
|
+
className: "!text-xs placeholder:text-xs",
|
|
46
|
+
placeholder: searchPlaceholder,
|
|
47
|
+
value: search,
|
|
48
|
+
onValueChange: setSearch
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ jsxs(CommandList, {
|
|
51
|
+
ref: picker.listRef,
|
|
52
|
+
className: listClassName,
|
|
53
|
+
children: [
|
|
54
|
+
loading && /* @__PURE__ */ jsx(LoaderOverlay, {}),
|
|
55
|
+
/* @__PURE__ */ jsx(CommandEmpty, { children: emptyContent ?? "No results found." }),
|
|
56
|
+
grouped ? filteredOptions.map((group) => /* @__PURE__ */ jsx(CommandGroup, {
|
|
57
|
+
heading: group.label,
|
|
58
|
+
children: group.options.map((option) => /* @__PURE__ */ jsx(CommandItem, {
|
|
59
|
+
value: option.value,
|
|
60
|
+
disabled: option.disabled,
|
|
61
|
+
onSelect: () => toggle(option.value),
|
|
62
|
+
children: row(option, isSelected(option.value))
|
|
63
|
+
}, option.value))
|
|
64
|
+
}, group.label)) : canVirtualize ? /* @__PURE__ */ jsx(VirtualCommandGroup, {
|
|
65
|
+
options: filteredOptions,
|
|
66
|
+
isSelected,
|
|
67
|
+
toggle,
|
|
68
|
+
renderOption: row,
|
|
69
|
+
listRef: picker.listRef,
|
|
70
|
+
itemSize
|
|
71
|
+
}) : /* @__PURE__ */ jsx(CommandGroup, { children: filteredOptions.map((option) => /* @__PURE__ */ jsx(CommandItem, {
|
|
72
|
+
value: option.value,
|
|
73
|
+
disabled: option.disabled,
|
|
74
|
+
onSelect: () => toggle(option.value),
|
|
75
|
+
children: row(option, isSelected(option.value))
|
|
76
|
+
}, option.value)) }),
|
|
77
|
+
creatableValue && /* @__PURE__ */ jsx(CommandGroup, { children: /* @__PURE__ */ jsx(CommandItem, {
|
|
78
|
+
value: `__create_${creatableValue}`,
|
|
79
|
+
onSelect: () => toggle(creatableValue),
|
|
80
|
+
children: /* @__PURE__ */ jsxs("span", { children: [
|
|
81
|
+
"Use \"",
|
|
82
|
+
creatableValue,
|
|
83
|
+
"\""
|
|
84
|
+
] })
|
|
85
|
+
}) })
|
|
86
|
+
]
|
|
87
|
+
}),
|
|
88
|
+
footer
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function VirtualCommandGroup({ options, isSelected, toggle, renderOption, listRef, itemSize }) {
|
|
93
|
+
const virtualizer = useVirtualizer({
|
|
94
|
+
count: options.length,
|
|
95
|
+
getScrollElement: () => listRef.current,
|
|
96
|
+
estimateSize: () => itemSize,
|
|
97
|
+
overscan: 8
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ jsx(CommandGroup, { children: /* @__PURE__ */ jsx("div", {
|
|
100
|
+
style: {
|
|
101
|
+
height: virtualizer.getTotalSize(),
|
|
102
|
+
position: "relative"
|
|
103
|
+
},
|
|
104
|
+
children: virtualizer.getVirtualItems().map((virtualRow) => {
|
|
105
|
+
const option = options[virtualRow.index];
|
|
106
|
+
return /* @__PURE__ */ jsx("div", {
|
|
107
|
+
style: {
|
|
108
|
+
position: "absolute",
|
|
109
|
+
top: 0,
|
|
110
|
+
left: 0,
|
|
111
|
+
width: "100%",
|
|
112
|
+
transform: `translateY(${virtualRow.start}px)`
|
|
113
|
+
},
|
|
114
|
+
children: /* @__PURE__ */ jsx(CommandItem, {
|
|
115
|
+
value: option.value,
|
|
116
|
+
disabled: option.disabled,
|
|
117
|
+
onSelect: () => toggle(option.value),
|
|
118
|
+
children: renderOption(option, isSelected(option.value))
|
|
119
|
+
})
|
|
120
|
+
}, option.value);
|
|
121
|
+
})
|
|
122
|
+
}) });
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/components/base/option-picker/use-option-picker.ts
|
|
126
|
+
function useOptionPicker(args) {
|
|
127
|
+
const { options, multiple, value, defaultValue, onValueChange, onSearchChange, creatable = false, closeOnSelect = true, onOpenChange } = args;
|
|
128
|
+
const [internalValue, setInternalValue] = useState(() => {
|
|
129
|
+
if (value !== void 0) return Array.isArray(value) ? value : [value];
|
|
130
|
+
if (defaultValue !== void 0) return Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
131
|
+
return [];
|
|
132
|
+
});
|
|
133
|
+
const selection = useMemo(() => {
|
|
134
|
+
if (value === void 0) return internalValue;
|
|
135
|
+
return Array.isArray(value) ? value : [value];
|
|
136
|
+
}, [value, internalValue]);
|
|
137
|
+
const selectionSet = useMemo(() => new Set(selection), [selection]);
|
|
138
|
+
const [search, setSearchState] = useState("");
|
|
139
|
+
const setSearch = useCallback((next) => {
|
|
140
|
+
setSearchState(next);
|
|
141
|
+
onSearchChange?.(next);
|
|
142
|
+
}, [onSearchChange]);
|
|
143
|
+
const isSelected = useCallback((v) => selectionSet.has(v), [selectionSet]);
|
|
144
|
+
const toggle = useCallback((v) => {
|
|
145
|
+
if (multiple) {
|
|
146
|
+
const next = selectionSet.has(v) ? selection.filter((x) => x !== v) : [...selection, v];
|
|
147
|
+
if (value === void 0) setInternalValue(next);
|
|
148
|
+
onValueChange?.(next);
|
|
149
|
+
} else {
|
|
150
|
+
if (value === void 0) setInternalValue([v]);
|
|
151
|
+
onValueChange?.(v);
|
|
152
|
+
if (closeOnSelect) onOpenChange(false);
|
|
153
|
+
}
|
|
154
|
+
}, [
|
|
155
|
+
multiple,
|
|
156
|
+
selection,
|
|
157
|
+
selectionSet,
|
|
158
|
+
value,
|
|
159
|
+
onValueChange,
|
|
160
|
+
closeOnSelect,
|
|
161
|
+
onOpenChange
|
|
162
|
+
]);
|
|
163
|
+
const clear = useCallback(() => {
|
|
164
|
+
if (!multiple) return;
|
|
165
|
+
if (value === void 0) setInternalValue([]);
|
|
166
|
+
onValueChange?.([]);
|
|
167
|
+
}, [
|
|
168
|
+
multiple,
|
|
169
|
+
value,
|
|
170
|
+
onValueChange
|
|
171
|
+
]);
|
|
172
|
+
const filteredOptions = useMemo(() => {
|
|
173
|
+
if (onSearchChange || !search) return options;
|
|
174
|
+
const q = search.toLowerCase().trim();
|
|
175
|
+
if (!q) return options;
|
|
176
|
+
if (isGroupedOptions(options)) return options.map((g) => ({
|
|
177
|
+
label: g.label,
|
|
178
|
+
options: g.options.filter((o) => o.label.toLowerCase().includes(q))
|
|
179
|
+
})).filter((g) => g.options.length > 0);
|
|
180
|
+
return options.filter((o) => o.label.toLowerCase().includes(q));
|
|
181
|
+
}, [
|
|
182
|
+
options,
|
|
183
|
+
search,
|
|
184
|
+
onSearchChange
|
|
185
|
+
]);
|
|
186
|
+
const hasMatches = useMemo(() => {
|
|
187
|
+
if (isGroupedOptions(filteredOptions)) return filteredOptions.some((g) => g.options.length > 0);
|
|
188
|
+
return filteredOptions.length > 0;
|
|
189
|
+
}, [filteredOptions]);
|
|
190
|
+
const creatableValue = useMemo(() => {
|
|
191
|
+
if (!creatable || multiple) return null;
|
|
192
|
+
const trimmed = search.trim();
|
|
193
|
+
if (!trimmed) return null;
|
|
194
|
+
return flattenOptions(options).some((o) => o.label.toLowerCase() === trimmed.toLowerCase()) ? null : trimmed;
|
|
195
|
+
}, [
|
|
196
|
+
creatable,
|
|
197
|
+
multiple,
|
|
198
|
+
search,
|
|
199
|
+
options
|
|
200
|
+
]);
|
|
201
|
+
return {
|
|
202
|
+
search,
|
|
203
|
+
setSearch,
|
|
204
|
+
filteredOptions,
|
|
205
|
+
hasMatches,
|
|
206
|
+
isSelected,
|
|
207
|
+
toggle,
|
|
208
|
+
clear,
|
|
209
|
+
hasSelection: selection.length > 0,
|
|
210
|
+
creatableValue,
|
|
211
|
+
listRef: useRef(null)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { OptionList as n, useOptionPicker as t };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as VisuallyHidden } from "../visuallyhidden-
|
|
1
|
+
import { t as VisuallyHidden } from "../visuallyhidden-BHOPczmW.mjs";
|
|
2
2
|
export { VisuallyHidden };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datum-cloud/datum-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/datum-cloud/datum-ui"
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"style": "./dist/styles/root.css",
|
|
20
20
|
"default": "./dist/styles/root.css"
|
|
21
21
|
},
|
|
22
|
+
"./styles/canela": {
|
|
23
|
+
"style": "./dist/styles/canela.css",
|
|
24
|
+
"default": "./dist/styles/canela.css"
|
|
25
|
+
},
|
|
22
26
|
"./theme": {
|
|
23
27
|
"source": "./src/components/themes/index.ts",
|
|
24
28
|
"types": "./dist/components/themes/index.d.ts",
|
|
@@ -139,6 +143,21 @@
|
|
|
139
143
|
"types": "./dist/components/base/radio-group/index.d.ts",
|
|
140
144
|
"default": "./dist/radio-group/index.mjs"
|
|
141
145
|
},
|
|
146
|
+
"./responsive-dropdown": {
|
|
147
|
+
"source": "./src/components/base/responsive-dropdown/index.ts",
|
|
148
|
+
"types": "./dist/components/base/responsive-dropdown/index.d.ts",
|
|
149
|
+
"default": "./dist/responsive-dropdown/index.mjs"
|
|
150
|
+
},
|
|
151
|
+
"./responsive-popover": {
|
|
152
|
+
"source": "./src/components/base/responsive-popover/index.ts",
|
|
153
|
+
"types": "./dist/components/base/responsive-popover/index.d.ts",
|
|
154
|
+
"default": "./dist/responsive-popover/index.mjs"
|
|
155
|
+
},
|
|
156
|
+
"./rich-text-editor": {
|
|
157
|
+
"source": "./src/components/features/rich-text-editor/index.ts",
|
|
158
|
+
"types": "./dist/components/features/rich-text-editor/index.d.ts",
|
|
159
|
+
"default": "./dist/rich-text-editor/index.mjs"
|
|
160
|
+
},
|
|
142
161
|
"./select": {
|
|
143
162
|
"source": "./src/components/base/select/index.ts",
|
|
144
163
|
"types": "./dist/components/base/select/index.d.ts",
|
|
@@ -209,11 +228,6 @@
|
|
|
209
228
|
"types": "./dist/components/features/autosearch/index.d.ts",
|
|
210
229
|
"default": "./dist/autosearch/index.mjs"
|
|
211
230
|
},
|
|
212
|
-
"./combobox": {
|
|
213
|
-
"source": "./src/components/features/combobox/index.ts",
|
|
214
|
-
"types": "./dist/components/features/combobox/index.d.ts",
|
|
215
|
-
"default": "./dist/combobox/index.mjs"
|
|
216
|
-
},
|
|
217
231
|
"./avatar-stack": {
|
|
218
232
|
"source": "./src/components/features/avatar-stack/index.ts",
|
|
219
233
|
"types": "./dist/components/features/avatar-stack/index.d.ts",
|
|
@@ -284,6 +298,11 @@
|
|
|
284
298
|
"types": "./dist/exports/map.d.ts",
|
|
285
299
|
"default": "./dist/map/index.mjs"
|
|
286
300
|
},
|
|
301
|
+
"./mobile-sheet": {
|
|
302
|
+
"source": "./src/components/base/mobile-sheet/index.ts",
|
|
303
|
+
"types": "./dist/components/base/mobile-sheet/index.d.ts",
|
|
304
|
+
"default": "./dist/mobile-sheet/index.mjs"
|
|
305
|
+
},
|
|
287
306
|
"./more-actions": {
|
|
288
307
|
"source": "./src/components/features/more-actions/index.ts",
|
|
289
308
|
"types": "./dist/components/features/more-actions/index.d.ts",
|
|
@@ -348,6 +367,11 @@
|
|
|
348
367
|
"source": "./src/components/features/transfer/index.ts",
|
|
349
368
|
"types": "./dist/components/features/transfer/index.d.ts",
|
|
350
369
|
"default": "./dist/transfer/index.mjs"
|
|
370
|
+
},
|
|
371
|
+
"./multi-select": {
|
|
372
|
+
"source": "./src/components/features/multi-select/index.ts",
|
|
373
|
+
"types": "./dist/components/features/multi-select/index.d.ts",
|
|
374
|
+
"default": "./dist/multi-select/index.mjs"
|
|
351
375
|
}
|
|
352
376
|
},
|
|
353
377
|
"main": "./dist/index.mjs",
|
|
@@ -368,6 +392,12 @@
|
|
|
368
392
|
"@stepperize/react": ">=4",
|
|
369
393
|
"@tanstack/react-table": ">=8",
|
|
370
394
|
"@tanstack/react-virtual": ">=3",
|
|
395
|
+
"@tiptap/extension-character-count": ">=3",
|
|
396
|
+
"@tiptap/extension-link": ">=3",
|
|
397
|
+
"@tiptap/extension-placeholder": ">=3",
|
|
398
|
+
"@tiptap/extension-underline": ">=3",
|
|
399
|
+
"@tiptap/react": ">=3",
|
|
400
|
+
"@tiptap/starter-kit": ">=3",
|
|
371
401
|
"date-fns": ">=4",
|
|
372
402
|
"date-fns-tz": ">=3",
|
|
373
403
|
"js-yaml": "^4.1.0",
|
|
@@ -420,6 +450,24 @@
|
|
|
420
450
|
"@tanstack/react-virtual": {
|
|
421
451
|
"optional": true
|
|
422
452
|
},
|
|
453
|
+
"@tiptap/extension-character-count": {
|
|
454
|
+
"optional": true
|
|
455
|
+
},
|
|
456
|
+
"@tiptap/extension-link": {
|
|
457
|
+
"optional": true
|
|
458
|
+
},
|
|
459
|
+
"@tiptap/extension-placeholder": {
|
|
460
|
+
"optional": true
|
|
461
|
+
},
|
|
462
|
+
"@tiptap/extension-underline": {
|
|
463
|
+
"optional": true
|
|
464
|
+
},
|
|
465
|
+
"@tiptap/react": {
|
|
466
|
+
"optional": true
|
|
467
|
+
},
|
|
468
|
+
"@tiptap/starter-kit": {
|
|
469
|
+
"optional": true
|
|
470
|
+
},
|
|
423
471
|
"date-fns": {
|
|
424
472
|
"optional": true
|
|
425
473
|
},
|
|
@@ -503,6 +551,7 @@
|
|
|
503
551
|
"class-variance-authority": "^0.7.1",
|
|
504
552
|
"clsx": "^2.1.1",
|
|
505
553
|
"cmdk": "^1",
|
|
554
|
+
"isomorphic-dompurify": "^3.8.0",
|
|
506
555
|
"tailwind-merge": "^3.5.0",
|
|
507
556
|
"tw-animate-css": "^1"
|
|
508
557
|
},
|
|
@@ -519,6 +568,12 @@
|
|
|
519
568
|
"@testing-library/jest-dom": "^6",
|
|
520
569
|
"@testing-library/react": "^16",
|
|
521
570
|
"@testing-library/user-event": "^14",
|
|
571
|
+
"@tiptap/extension-character-count": "^3.22.3",
|
|
572
|
+
"@tiptap/extension-link": "^3.22.3",
|
|
573
|
+
"@tiptap/extension-placeholder": "^3.22.3",
|
|
574
|
+
"@tiptap/extension-underline": "^3.22.3",
|
|
575
|
+
"@tiptap/react": "^3.22.3",
|
|
576
|
+
"@tiptap/starter-kit": "^3.22.3",
|
|
522
577
|
"@types/js-yaml": "^4.0.9",
|
|
523
578
|
"@types/leaflet": "^1.9.21",
|
|
524
579
|
"@types/leaflet-draw": "^1.0.13",
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { t as cn } from "./cn-D2KYQ917.mjs";
|
|
2
|
-
import { a as CommandInput, i as CommandGroup, o as CommandItem, r as CommandEmpty, s as CommandList, t as Command } from "./command-DqHWukGK.mjs";
|
|
3
|
-
import { i as PopoverTrigger, r as PopoverContent, t as Popover } from "./popover-FJAcbYoH.mjs";
|
|
4
|
-
import { t as LoaderOverlay } from "./loader-overlay-BTFdkp7W.mjs";
|
|
5
|
-
import { CheckIcon, ChevronDown } from "lucide-react";
|
|
6
|
-
import * as React$1 from "react";
|
|
7
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
9
|
-
//#region src/components/features/autocomplete/autocomplete.tsx
|
|
10
|
-
function isGroupedOptions(options) {
|
|
11
|
-
return options.length > 0 && "options" in options[0];
|
|
12
|
-
}
|
|
13
|
-
function flattenOptions(options) {
|
|
14
|
-
if (isGroupedOptions(options)) return options.flatMap((g) => g.options);
|
|
15
|
-
return options;
|
|
16
|
-
}
|
|
17
|
-
function Trigger({ ref, selectedOption, renderValue, placeholder, loading, disabled, open, id, className, ...rest }) {
|
|
18
|
-
let displayContent;
|
|
19
|
-
if (!selectedOption) displayContent = /* @__PURE__ */ jsx("span", {
|
|
20
|
-
className: "text-muted-foreground",
|
|
21
|
-
children: placeholder
|
|
22
|
-
});
|
|
23
|
-
else if (renderValue) displayContent = renderValue(selectedOption);
|
|
24
|
-
else displayContent = /* @__PURE__ */ jsx("span", {
|
|
25
|
-
className: "truncate",
|
|
26
|
-
children: selectedOption.label
|
|
27
|
-
});
|
|
28
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
29
|
-
ref,
|
|
30
|
-
type: "button",
|
|
31
|
-
id,
|
|
32
|
-
role: "combobox",
|
|
33
|
-
"aria-expanded": open,
|
|
34
|
-
disabled: disabled || loading,
|
|
35
|
-
className: cn("text-input-foreground placeholder:text-input-placeholder", "border-input-border bg-input-background/50 relative flex h-10 w-full items-center justify-between rounded-lg border px-3 py-2 text-left text-sm transition-all", "focus-visible:border-input-focus-border focus-visible:shadow-(--input-focus-shadow)", "focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-hidden", "aria-invalid:border-destructive", (disabled || loading) && "cursor-not-allowed opacity-50", className),
|
|
36
|
-
...rest,
|
|
37
|
-
children: [
|
|
38
|
-
loading && /* @__PURE__ */ jsx(LoaderOverlay, {}),
|
|
39
|
-
/* @__PURE__ */ jsx("div", {
|
|
40
|
-
className: "min-w-0 flex-1",
|
|
41
|
-
children: displayContent
|
|
42
|
-
}),
|
|
43
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground ml-2 size-4 shrink-0" })
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
Trigger.displayName = "AutocompleteTrigger";
|
|
48
|
-
function DefaultOptionContent({ option, isSelected }) {
|
|
49
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
50
|
-
className: "flex w-full items-center justify-between gap-2",
|
|
51
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
52
|
-
className: "min-w-0 flex-1",
|
|
53
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
54
|
-
className: "truncate text-sm",
|
|
55
|
-
children: option.label
|
|
56
|
-
}), option.description && /* @__PURE__ */ jsx("p", {
|
|
57
|
-
className: "text-muted-foreground mt-0.5 line-clamp-2 text-xs",
|
|
58
|
-
children: option.description
|
|
59
|
-
})]
|
|
60
|
-
}), isSelected && /* @__PURE__ */ jsx(CheckIcon, { className: "text-primary size-4 shrink-0" })]
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function StaticOptions({ options, selectedValue, onSelect, renderOption }) {
|
|
64
|
-
const renderItem = (option) => {
|
|
65
|
-
const isSelected = option.value === selectedValue;
|
|
66
|
-
return /* @__PURE__ */ jsx(CommandItem, {
|
|
67
|
-
value: option.value,
|
|
68
|
-
keywords: [option.label, option.description ?? ""],
|
|
69
|
-
disabled: option.disabled,
|
|
70
|
-
onSelect: () => onSelect(option.value),
|
|
71
|
-
className: "cursor-pointer justify-between px-3 py-2 text-xs",
|
|
72
|
-
children: renderOption ? renderOption(option, isSelected) : /* @__PURE__ */ jsx(DefaultOptionContent, {
|
|
73
|
-
option,
|
|
74
|
-
isSelected
|
|
75
|
-
})
|
|
76
|
-
}, option.value);
|
|
77
|
-
};
|
|
78
|
-
if (isGroupedOptions(options)) return /* @__PURE__ */ jsx(Fragment$1, { children: options.map((group, index) => /* @__PURE__ */ jsx(CommandGroup, {
|
|
79
|
-
heading: group.label,
|
|
80
|
-
className: index > 0 ? "border-t pt-1" : "",
|
|
81
|
-
children: group.options.map(renderItem)
|
|
82
|
-
}, group.label)) });
|
|
83
|
-
return /* @__PURE__ */ jsx(CommandGroup, {
|
|
84
|
-
className: "p-0",
|
|
85
|
-
children: options.map(renderItem)
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
function VirtualizedOptions({ options, selectedValue, onSelect, renderOption, itemSize = 36, listClassName }) {
|
|
89
|
-
const flatOptions = flattenOptions(options);
|
|
90
|
-
const parentRef = React$1.useRef(null);
|
|
91
|
-
const virtualizer = useVirtualizer({
|
|
92
|
-
count: flatOptions.length,
|
|
93
|
-
getScrollElement: () => parentRef.current,
|
|
94
|
-
estimateSize: () => itemSize
|
|
95
|
-
});
|
|
96
|
-
React$1.useEffect(() => {
|
|
97
|
-
if (selectedValue) {
|
|
98
|
-
const index = flatOptions.findIndex((o) => o.value === selectedValue);
|
|
99
|
-
if (index >= 0) virtualizer.scrollToIndex(index, { align: "center" });
|
|
100
|
-
}
|
|
101
|
-
}, [
|
|
102
|
-
selectedValue,
|
|
103
|
-
flatOptions,
|
|
104
|
-
virtualizer
|
|
105
|
-
]);
|
|
106
|
-
return /* @__PURE__ */ jsx("div", {
|
|
107
|
-
ref: parentRef,
|
|
108
|
-
className: cn("max-h-[200px] overflow-auto", listClassName),
|
|
109
|
-
children: /* @__PURE__ */ jsx(CommandGroup, { children: /* @__PURE__ */ jsx("div", {
|
|
110
|
-
style: { height: `${virtualizer.getTotalSize()}px` },
|
|
111
|
-
className: "relative w-full",
|
|
112
|
-
children: virtualizer.getVirtualItems().map((virtualItem) => {
|
|
113
|
-
const option = flatOptions[virtualItem.index];
|
|
114
|
-
const isSelected = option.value === selectedValue;
|
|
115
|
-
return /* @__PURE__ */ jsx(CommandItem, {
|
|
116
|
-
value: option.value,
|
|
117
|
-
keywords: [option.label, option.description ?? ""],
|
|
118
|
-
disabled: option.disabled,
|
|
119
|
-
onSelect: () => onSelect(option.value),
|
|
120
|
-
className: "absolute top-0 left-0 w-full cursor-pointer justify-between px-3 py-2 text-xs",
|
|
121
|
-
style: {
|
|
122
|
-
height: `${virtualItem.size}px`,
|
|
123
|
-
transform: `translateY(${virtualItem.start}px)`
|
|
124
|
-
},
|
|
125
|
-
children: renderOption ? renderOption(option, isSelected) : /* @__PURE__ */ jsx(DefaultOptionContent, {
|
|
126
|
-
option,
|
|
127
|
-
isSelected
|
|
128
|
-
})
|
|
129
|
-
}, option.value);
|
|
130
|
-
})
|
|
131
|
-
}) })
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Autocomplete - A searchable select component
|
|
136
|
-
*
|
|
137
|
-
* Standalone, form-agnostic combobox built on Popover + Command (cmdk).
|
|
138
|
-
* Supports flat/grouped options, virtualization, custom rendering, and async search.
|
|
139
|
-
*
|
|
140
|
-
* @example Basic usage
|
|
141
|
-
* ```tsx
|
|
142
|
-
* <Autocomplete
|
|
143
|
-
* value={country}
|
|
144
|
-
* onValueChange={setCountry}
|
|
145
|
-
* options={countries}
|
|
146
|
-
* placeholder="Select country..."
|
|
147
|
-
* />
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* @example Async search
|
|
151
|
-
* ```tsx
|
|
152
|
-
* <Autocomplete
|
|
153
|
-
* value={userId}
|
|
154
|
-
* onValueChange={setUserId}
|
|
155
|
-
* options={users ?? []}
|
|
156
|
-
* onSearchChange={setSearch}
|
|
157
|
-
* loading={isLoading}
|
|
158
|
-
* placeholder="Search users..."
|
|
159
|
-
* />
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
function Autocomplete({ options, value, onValueChange, onSearchChange, searchPlaceholder = "Search...", disableSearch = false, renderOption, renderValue, placeholder = "Select...", emptyContent = "No results found", footer, creatable = false, creatableLabel, virtualize = false, itemSize = 36, loading = false, modal = false, disabled = false, name, id, className, triggerClassName, contentClassName, listClassName }) {
|
|
163
|
-
const [open, setOpen] = React$1.useState(false);
|
|
164
|
-
const [search, setSearch] = React$1.useState("");
|
|
165
|
-
const flatOptions = React$1.useMemo(() => flattenOptions(options), [options]);
|
|
166
|
-
const selectedOption = React$1.useMemo(() => flatOptions.find((o) => o.value === value), [flatOptions, value]);
|
|
167
|
-
const displayOption = React$1.useMemo(() => {
|
|
168
|
-
if (selectedOption) return selectedOption;
|
|
169
|
-
if (creatable && value) return {
|
|
170
|
-
value,
|
|
171
|
-
label: value
|
|
172
|
-
};
|
|
173
|
-
}, [
|
|
174
|
-
selectedOption,
|
|
175
|
-
creatable,
|
|
176
|
-
value
|
|
177
|
-
]);
|
|
178
|
-
const isExternalSearch = !!onSearchChange;
|
|
179
|
-
const trimmedSearch = React$1.useMemo(() => search.trim(), [search]);
|
|
180
|
-
const showCreatableItem = React$1.useMemo(() => {
|
|
181
|
-
if (!creatable || trimmedSearch.length === 0) return false;
|
|
182
|
-
const needle = trimmedSearch.toLowerCase();
|
|
183
|
-
return !flatOptions.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
|
|
184
|
-
}, [
|
|
185
|
-
creatable,
|
|
186
|
-
trimmedSearch,
|
|
187
|
-
flatOptions
|
|
188
|
-
]);
|
|
189
|
-
const handleSelect = React$1.useCallback((optionValue) => {
|
|
190
|
-
onValueChange?.(optionValue);
|
|
191
|
-
setSearch("");
|
|
192
|
-
setOpen(false);
|
|
193
|
-
}, [onValueChange]);
|
|
194
|
-
const handleCreatableSelect = React$1.useCallback(() => {
|
|
195
|
-
onValueChange?.(trimmedSearch);
|
|
196
|
-
setSearch("");
|
|
197
|
-
setOpen(false);
|
|
198
|
-
}, [onValueChange, trimmedSearch]);
|
|
199
|
-
const handleOpenChange = React$1.useCallback((nextOpen) => {
|
|
200
|
-
setOpen(nextOpen);
|
|
201
|
-
if (!nextOpen) {
|
|
202
|
-
setSearch("");
|
|
203
|
-
if (isExternalSearch) onSearchChange?.("");
|
|
204
|
-
}
|
|
205
|
-
}, [isExternalSearch, onSearchChange]);
|
|
206
|
-
const handleSearchChange = React$1.useCallback((val) => {
|
|
207
|
-
setSearch(val);
|
|
208
|
-
if (isExternalSearch) onSearchChange?.(val);
|
|
209
|
-
}, [isExternalSearch, onSearchChange]);
|
|
210
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
211
|
-
className: cn("relative", className),
|
|
212
|
-
children: [/* @__PURE__ */ jsxs(Popover, {
|
|
213
|
-
open,
|
|
214
|
-
onOpenChange: handleOpenChange,
|
|
215
|
-
modal,
|
|
216
|
-
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
217
|
-
asChild: true,
|
|
218
|
-
children: /* @__PURE__ */ jsx(Trigger, {
|
|
219
|
-
selectedOption: displayOption,
|
|
220
|
-
renderValue,
|
|
221
|
-
placeholder,
|
|
222
|
-
loading,
|
|
223
|
-
disabled,
|
|
224
|
-
open,
|
|
225
|
-
id,
|
|
226
|
-
className: triggerClassName
|
|
227
|
-
})
|
|
228
|
-
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
229
|
-
className: cn("popover-content-width-full p-0", contentClassName),
|
|
230
|
-
align: "start",
|
|
231
|
-
children: /* @__PURE__ */ jsxs(Command, {
|
|
232
|
-
shouldFilter: !isExternalSearch && !creatable,
|
|
233
|
-
defaultValue: value,
|
|
234
|
-
children: [
|
|
235
|
-
!disableSearch && /* @__PURE__ */ jsx(CommandInput, {
|
|
236
|
-
className: "placeholder:text-secondary/60 h-7 border-none text-xs placeholder:text-xs focus-visible:ring-0",
|
|
237
|
-
iconClassName: "text-secondary size-3.5",
|
|
238
|
-
wrapperClassName: "px-3 py-2",
|
|
239
|
-
placeholder: searchPlaceholder,
|
|
240
|
-
value: search,
|
|
241
|
-
onValueChange: handleSearchChange
|
|
242
|
-
}),
|
|
243
|
-
/* @__PURE__ */ jsxs(CommandList, {
|
|
244
|
-
className: cn(!virtualize && "max-h-[300px]", listClassName),
|
|
245
|
-
children: [
|
|
246
|
-
!showCreatableItem && /* @__PURE__ */ jsx(CommandEmpty, { children: typeof emptyContent === "string" ? /* @__PURE__ */ jsx("span", {
|
|
247
|
-
className: "text-muted-foreground text-xs",
|
|
248
|
-
children: emptyContent
|
|
249
|
-
}) : emptyContent }),
|
|
250
|
-
virtualize ? /* @__PURE__ */ jsx(VirtualizedOptions, {
|
|
251
|
-
options,
|
|
252
|
-
selectedValue: value,
|
|
253
|
-
onSelect: handleSelect,
|
|
254
|
-
renderOption,
|
|
255
|
-
itemSize,
|
|
256
|
-
listClassName
|
|
257
|
-
}) : /* @__PURE__ */ jsx(StaticOptions, {
|
|
258
|
-
options,
|
|
259
|
-
selectedValue: value,
|
|
260
|
-
onSelect: handleSelect,
|
|
261
|
-
renderOption
|
|
262
|
-
}),
|
|
263
|
-
showCreatableItem && /* @__PURE__ */ jsx(CommandGroup, {
|
|
264
|
-
forceMount: true,
|
|
265
|
-
className: "p-0",
|
|
266
|
-
children: /* @__PURE__ */ jsx(CommandItem, {
|
|
267
|
-
forceMount: true,
|
|
268
|
-
value: `\0creatable:${trimmedSearch}`,
|
|
269
|
-
keywords: [trimmedSearch],
|
|
270
|
-
onSelect: handleCreatableSelect,
|
|
271
|
-
className: "cursor-pointer px-3 py-2 text-xs",
|
|
272
|
-
children: creatableLabel ? creatableLabel(trimmedSearch) : `Use "${trimmedSearch}"`
|
|
273
|
-
})
|
|
274
|
-
})
|
|
275
|
-
]
|
|
276
|
-
}),
|
|
277
|
-
footer && /* @__PURE__ */ jsx("div", {
|
|
278
|
-
className: "border-t",
|
|
279
|
-
children: footer
|
|
280
|
-
})
|
|
281
|
-
]
|
|
282
|
-
})
|
|
283
|
-
})]
|
|
284
|
-
}), name && /* @__PURE__ */ jsx("input", {
|
|
285
|
-
type: "hidden",
|
|
286
|
-
name,
|
|
287
|
-
value: value ?? ""
|
|
288
|
-
})]
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
Autocomplete.displayName = "Autocomplete";
|
|
292
|
-
//#endregion
|
|
293
|
-
export { Autocomplete as t };
|
package/dist/combobox/index.mjs
DELETED