@constructive-io/ui 0.4.1 → 0.6.1
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/LICENSE +21 -0
- package/README.md +17 -22
- package/dist/button-D4vqTxhp.d.cts +20 -0
- package/dist/button-D4vqTxhp.d.ts +20 -0
- package/dist/components/alert-dialog.cjs +129 -0
- package/dist/components/alert-dialog.cjs.map +1 -0
- package/dist/components/alert-dialog.d.cts +33 -0
- package/dist/components/alert-dialog.d.ts +23 -21
- package/dist/components/alert-dialog.js +98 -296
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/alert.cjs +62 -0
- package/dist/components/alert.cjs.map +1 -0
- package/dist/components/alert.d.cts +19 -0
- package/dist/components/alert.d.ts +18 -13
- package/dist/components/alert.js +49 -31
- package/dist/components/alert.js.map +1 -1
- package/dist/components/app-bar.cjs +81 -0
- package/dist/components/app-bar.cjs.map +1 -0
- package/dist/components/app-bar.d.cts +27 -0
- package/dist/components/app-bar.d.ts +27 -0
- package/dist/components/app-bar.js +77 -0
- package/dist/components/app-bar.js.map +1 -0
- package/dist/components/app-shell.cjs +267 -0
- package/dist/components/app-shell.cjs.map +1 -0
- package/dist/components/app-shell.d.cts +98 -0
- package/dist/components/app-shell.d.ts +98 -0
- package/dist/components/app-shell.js +264 -0
- package/dist/components/app-shell.js.map +1 -0
- package/dist/components/autocomplete.cjs +167 -0
- package/dist/components/autocomplete.cjs.map +1 -0
- package/dist/components/autocomplete.d.cts +28 -0
- package/dist/components/autocomplete.d.ts +24 -24
- package/dist/components/autocomplete.js +146 -397
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/avatar.cjs +39 -0
- package/dist/components/avatar.cjs.map +1 -0
- package/dist/components/avatar.d.cts +13 -0
- package/dist/components/avatar.d.ts +11 -11
- package/dist/components/avatar.js +24 -27
- package/dist/components/avatar.js.map +1 -1
- package/dist/components/badge.cjs +48 -0
- package/dist/components/badge.cjs.map +1 -0
- package/dist/components/badge.d.cts +15 -0
- package/dist/components/badge.d.ts +13 -13
- package/dist/components/badge.js +39 -38
- package/dist/components/badge.js.map +1 -1
- package/dist/components/breadcrumb.cjs +89 -0
- package/dist/components/breadcrumb.cjs.map +1 -0
- package/dist/components/breadcrumb.d.cts +15 -0
- package/dist/components/breadcrumb.d.ts +14 -13
- package/dist/components/breadcrumb.js +63 -137
- package/dist/components/breadcrumb.js.map +1 -1
- package/dist/components/button.cjs +75 -0
- package/dist/components/button.cjs.map +1 -0
- package/dist/components/button.d.cts +2 -0
- package/dist/components/button.d.ts +2 -17
- package/dist/components/button.js +66 -57
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar-rac.cjs +72 -0
- package/dist/components/calendar-rac.cjs.map +1 -0
- package/dist/components/calendar-rac.d.cts +13 -0
- package/dist/components/calendar-rac.d.ts +8 -8
- package/dist/components/calendar-rac.js +49 -61
- package/dist/components/calendar-rac.js.map +1 -1
- package/dist/components/card.cjs +86 -0
- package/dist/components/card.cjs.map +1 -0
- package/dist/components/card.d.cts +17 -0
- package/dist/components/card.d.ts +15 -17
- package/dist/components/card.js +58 -57
- package/dist/components/card.js.map +1 -1
- package/dist/components/checkbox-group.cjs +19 -0
- package/dist/components/checkbox-group.cjs.map +1 -0
- package/dist/components/checkbox-group.d.cts +7 -0
- package/dist/components/checkbox-group.d.ts +5 -5
- package/dist/components/checkbox-group.js +12 -10
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/checkbox.cjs +67 -0
- package/dist/components/checkbox.cjs.map +1 -0
- package/dist/components/checkbox.d.cts +8 -0
- package/dist/components/checkbox.d.ts +6 -6
- package/dist/components/checkbox.js +58 -61
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/collapsible.cjs +90 -0
- package/dist/components/collapsible.cjs.map +1 -0
- package/dist/components/collapsible.d.cts +45 -0
- package/dist/components/collapsible.d.ts +19 -28
- package/dist/components/collapsible.js +74 -112
- package/dist/components/collapsible.js.map +1 -1
- package/dist/components/combobox.cjs +257 -0
- package/dist/components/combobox.cjs.map +1 -0
- package/dist/components/combobox.d.cts +44 -0
- package/dist/components/combobox.d.ts +36 -36
- package/dist/components/combobox.js +229 -515
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/command.cjs +139 -0
- package/dist/components/command.cjs.map +1 -0
- package/dist/components/command.d.cts +24 -0
- package/dist/components/command.d.ts +22 -22
- package/dist/components/command.js +109 -240
- package/dist/components/command.js.map +1 -1
- package/dist/components/dialog.cjs +139 -0
- package/dist/components/dialog.cjs.map +1 -0
- package/dist/components/dialog.d.cts +31 -0
- package/dist/components/dialog.d.ts +27 -31
- package/dist/components/dialog.js +112 -429
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/dock.cjs +90 -0
- package/dist/components/dock.cjs.map +1 -0
- package/dist/components/dock.d.cts +30 -0
- package/dist/components/dock.d.ts +25 -26
- package/dist/components/dock.js +78 -104
- package/dist/components/dock.js.map +1 -1
- package/dist/components/drawer.cjs +115 -0
- package/dist/components/drawer.cjs.map +1 -0
- package/dist/components/drawer.d.cts +16 -0
- package/dist/components/drawer.d.ts +15 -15
- package/dist/components/drawer.js +77 -121
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/dropdown-menu.cjs +217 -0
- package/dist/components/dropdown-menu.cjs.map +1 -0
- package/dist/components/dropdown-menu.d.cts +53 -0
- package/dist/components/dropdown-menu.d.ts +49 -46
- package/dist/components/dropdown-menu.js +177 -357
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/empty.cjs +72 -0
- package/dist/components/empty.cjs.map +1 -0
- package/dist/components/empty.d.cts +15 -0
- package/dist/components/empty.d.ts +15 -0
- package/dist/components/empty.js +64 -0
- package/dist/components/empty.js.map +1 -0
- package/dist/components/field.cjs +186 -0
- package/dist/components/field.cjs.map +1 -0
- package/dist/components/field.d.cts +46 -0
- package/dist/components/field.d.ts +44 -49
- package/dist/components/field.js +166 -108
- package/dist/components/field.js.map +1 -1
- package/dist/components/flickering-grid.cjs +153 -0
- package/dist/components/flickering-grid.cjs.map +1 -0
- package/dist/components/flickering-grid.d.cts +16 -0
- package/dist/components/flickering-grid.d.ts +14 -13
- package/dist/components/flickering-grid.js +144 -141
- package/dist/components/flickering-grid.js.map +1 -1
- package/dist/components/flow-zoom-panel.cjs +62 -0
- package/dist/components/flow-zoom-panel.cjs.map +1 -0
- package/dist/components/flow-zoom-panel.d.cts +12 -0
- package/dist/components/flow-zoom-panel.d.ts +12 -0
- package/dist/components/flow-zoom-panel.js +61 -0
- package/dist/components/flow-zoom-panel.js.map +1 -0
- package/dist/components/form-control.cjs +65 -0
- package/dist/components/form-control.cjs.map +1 -0
- package/dist/components/form-control.d.cts +15 -0
- package/dist/components/form-control.d.ts +11 -11
- package/dist/components/form-control.js +56 -167
- package/dist/components/form-control.js.map +1 -1
- package/dist/components/form.cjs +102 -0
- package/dist/components/form.cjs.map +1 -0
- package/dist/components/form.d.cts +2 -0
- package/dist/components/form.d.ts +2 -37
- package/dist/components/form.js +76 -163
- package/dist/components/form.js.map +1 -1
- package/dist/components/input-group.cjs +70 -0
- package/dist/components/input-group.cjs.map +1 -0
- package/dist/components/input-group.d.cts +16 -0
- package/dist/components/input-group.d.ts +14 -16
- package/dist/components/input-group.js +51 -163
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/input.cjs +37 -0
- package/dist/components/input.cjs.map +1 -0
- package/dist/components/input.d.cts +2 -0
- package/dist/components/input.d.ts +2 -11
- package/dist/components/input.js +30 -54
- package/dist/components/input.js.map +1 -1
- package/dist/components/json-input.cjs +147 -0
- package/dist/components/json-input.cjs.map +1 -0
- package/dist/components/json-input.d.cts +26 -0
- package/dist/components/json-input.d.ts +20 -19
- package/dist/components/json-input.js +132 -340
- package/dist/components/json-input.js.map +1 -1
- package/dist/components/label.cjs +27 -0
- package/dist/components/label.cjs.map +1 -0
- package/dist/components/label.d.cts +11 -0
- package/dist/components/label.d.ts +6 -6
- package/dist/components/label.js +17 -20
- package/dist/components/label.js.map +1 -1
- package/dist/components/motion-grid.cjs +68 -0
- package/dist/components/motion-grid.cjs.map +1 -0
- package/dist/components/motion-grid.d.cts +20 -0
- package/dist/components/motion-grid.d.ts +15 -15
- package/dist/components/motion-grid.js +59 -75
- package/dist/components/motion-grid.js.map +1 -1
- package/dist/components/multi-select.cjs +573 -0
- package/dist/components/multi-select.cjs.map +1 -0
- package/dist/components/multi-select.d.cts +198 -0
- package/dist/components/multi-select.d.ts +173 -173
- package/dist/components/multi-select.js +562 -874
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/page-header.cjs +30 -0
- package/dist/components/page-header.cjs.map +1 -0
- package/dist/components/page-header.d.cts +17 -0
- package/dist/components/page-header.d.ts +11 -11
- package/dist/components/page-header.js +23 -11
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/pagination.cjs +95 -0
- package/dist/components/pagination.cjs.map +1 -0
- package/dist/components/pagination.d.cts +17 -0
- package/dist/components/pagination.d.ts +15 -17
- package/dist/components/pagination.js +70 -128
- package/dist/components/pagination.js.map +1 -1
- package/dist/components/popover.cjs +97 -0
- package/dist/components/popover.cjs.map +1 -0
- package/dist/components/popover.d.cts +40 -0
- package/dist/components/popover.d.ts +33 -28
- package/dist/components/popover.js +78 -178
- package/dist/components/popover.js.map +1 -1
- package/dist/components/portal.cjs +156 -0
- package/dist/components/portal.cjs.map +1 -0
- package/dist/components/portal.d.cts +118 -0
- package/dist/components/portal.d.ts +33 -23
- package/dist/components/portal.js +128 -57
- package/dist/components/portal.js.map +1 -1
- package/dist/components/progress.cjs +30 -0
- package/dist/components/progress.cjs.map +1 -0
- package/dist/components/progress.d.cts +10 -0
- package/dist/components/progress.d.ts +8 -8
- package/dist/components/progress.js +21 -24
- package/dist/components/progress.js.map +1 -1
- package/dist/components/progressive-blur-scroll-container.cjs +76 -0
- package/dist/components/progressive-blur-scroll-container.cjs.map +1 -0
- package/dist/components/progressive-blur-scroll-container.d.cts +25 -0
- package/dist/components/progressive-blur-scroll-container.d.ts +19 -19
- package/dist/components/progressive-blur-scroll-container.js +70 -137
- package/dist/components/progressive-blur-scroll-container.js.map +1 -1
- package/dist/components/progressive-blur.cjs +46 -0
- package/dist/components/progressive-blur.cjs.map +1 -0
- package/dist/components/progressive-blur.d.cts +17 -0
- package/dist/components/progressive-blur.d.ts +15 -14
- package/dist/components/progressive-blur.js +38 -63
- package/dist/components/progressive-blur.js.map +1 -1
- package/dist/components/radio-group.cjs +38 -0
- package/dist/components/radio-group.cjs.map +1 -0
- package/dist/components/radio-group.d.cts +10 -0
- package/dist/components/radio-group.d.ts +8 -8
- package/dist/components/radio-group.js +28 -30
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/record-picker.cjs +8 -0
- package/dist/components/record-picker.d.cts +16 -0
- package/dist/components/record-picker.d.ts +13 -13
- package/dist/components/record-picker.js +5 -364
- package/dist/components/resizable.cjs +50 -0
- package/dist/components/resizable.cjs.map +1 -0
- package/dist/components/resizable.d.cts +11 -0
- package/dist/components/resizable.d.ts +10 -10
- package/dist/components/resizable.js +29 -37
- package/dist/components/resizable.js.map +1 -1
- package/dist/components/responsive-diagram.cjs +56 -0
- package/dist/components/responsive-diagram.cjs.map +1 -0
- package/dist/components/responsive-diagram.d.cts +10 -0
- package/dist/components/responsive-diagram.d.ts +7 -7
- package/dist/components/responsive-diagram.js +50 -60
- package/dist/components/responsive-diagram.js.map +1 -1
- package/dist/components/scroll-area.cjs +46 -0
- package/dist/components/scroll-area.cjs.map +1 -0
- package/dist/components/scroll-area.d.cts +12 -0
- package/dist/components/scroll-area.d.ts +11 -11
- package/dist/components/scroll-area.js +35 -62
- package/dist/components/scroll-area.js.map +1 -1
- package/dist/components/select.cjs +204 -0
- package/dist/components/select.cjs.map +1 -0
- package/dist/components/select.d.cts +47 -0
- package/dist/components/select.d.ts +38 -38
- package/dist/components/select.js +172 -269
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.cjs +23 -0
- package/dist/components/separator.cjs.map +1 -0
- package/dist/components/separator.d.cts +2 -0
- package/dist/components/separator.d.ts +2 -11
- package/dist/components/separator.js +14 -18
- package/dist/components/separator.js.map +1 -1
- package/dist/components/sheet.cjs +19 -0
- package/dist/components/sheet.d.cts +107 -0
- package/dist/components/sheet.d.ts +85 -90
- package/dist/components/sheet.js +3 -598
- package/dist/components/sidebar.cjs +29 -0
- package/dist/components/sidebar.d.cts +67 -0
- package/dist/components/sidebar.d.ts +63 -73
- package/dist/components/sidebar.js +3 -1215
- package/dist/components/skeleton.cjs +24 -0
- package/dist/components/skeleton.cjs.map +1 -0
- package/dist/components/skeleton.d.cts +11 -0
- package/dist/components/skeleton.d.ts +10 -6
- package/dist/components/skeleton.js +15 -10
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/sonner.cjs +23 -0
- package/dist/components/sonner.cjs.map +1 -0
- package/dist/components/sonner.d.cts +10 -0
- package/dist/components/sonner.d.ts +7 -7
- package/dist/components/sonner.js +17 -18
- package/dist/components/sonner.js.map +1 -1
- package/dist/components/stack/index.cjs +44 -0
- package/dist/components/stack/index.d.cts +2 -0
- package/dist/components/stack/index.d.ts +2 -674
- package/dist/components/stack/index.js +3 -1444
- package/dist/components/stepper.cjs +160 -0
- package/dist/components/stepper.cjs.map +1 -0
- package/dist/components/stepper.d.cts +32 -0
- package/dist/components/stepper.d.ts +27 -25
- package/dist/components/stepper.js +133 -261
- package/dist/components/stepper.js.map +1 -1
- package/dist/components/switch.cjs +35 -0
- package/dist/components/switch.cjs.map +1 -0
- package/dist/components/switch.d.cts +8 -0
- package/dist/components/switch.d.ts +7 -7
- package/dist/components/switch.js +26 -34
- package/dist/components/switch.js.map +1 -1
- package/dist/components/table.cjs +85 -0
- package/dist/components/table.cjs.map +1 -0
- package/dist/components/table.d.cts +23 -0
- package/dist/components/table.d.ts +23 -15
- package/dist/components/table.js +56 -46
- package/dist/components/table.js.map +1 -1
- package/dist/components/tabs.cjs +49 -0
- package/dist/components/tabs.cjs.map +1 -0
- package/dist/components/tabs.d.cts +10 -0
- package/dist/components/tabs.d.ts +9 -9
- package/dist/components/tabs.js +31 -36
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/tags.cjs +132 -0
- package/dist/components/tags.cjs.map +1 -0
- package/dist/components/tags.d.cts +36 -0
- package/dist/components/tags.d.ts +24 -28
- package/dist/components/tags.js +114 -438
- package/dist/components/tags.js.map +1 -1
- package/dist/components/textarea.cjs +34 -0
- package/dist/components/textarea.cjs.map +1 -0
- package/dist/components/textarea.d.cts +10 -0
- package/dist/components/textarea.d.ts +8 -8
- package/dist/components/textarea.js +27 -48
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/toast/index.cjs +9 -0
- package/dist/components/toast/index.d.cts +2 -0
- package/dist/components/toast/index.d.ts +2 -52
- package/dist/components/toast/index.js +3 -623
- package/dist/components/tooltip.cjs +67 -0
- package/dist/components/tooltip.cjs.map +1 -0
- package/dist/components/tooltip.d.cts +2 -0
- package/dist/components/tooltip.d.ts +2 -29
- package/dist/components/tooltip.js +53 -166
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/unlink-button.cjs +24 -0
- package/dist/components/unlink-button.cjs.map +1 -0
- package/dist/components/unlink-button.d.cts +14 -0
- package/dist/components/unlink-button.d.ts +11 -11
- package/dist/components/unlink-button.js +18 -86
- package/dist/components/unlink-button.js.map +1 -1
- package/dist/form-DgRTv7O7.d.ts +54 -0
- package/dist/form-DoZEWSzb.d.cts +54 -0
- package/dist/index-CjA4CENl.d.cts +684 -0
- package/dist/index-CjA4CENl.d.ts +684 -0
- package/dist/index-UnM04j0t.d.cts +58 -0
- package/dist/index-UnM04j0t.d.ts +58 -0
- package/dist/index.cjs +408 -9346
- package/dist/index.d.cts +224 -2548
- package/dist/index.d.ts +224 -2548
- package/dist/index.js +65 -9022
- package/dist/input-CBrCuMH8.d.cts +11 -0
- package/dist/input-CBrCuMH8.d.ts +11 -0
- package/dist/motion-config-COCFHq1L.cjs +271 -0
- package/dist/motion-config-COCFHq1L.cjs.map +1 -0
- package/dist/motion-config-COsZ6azM.js +241 -0
- package/dist/motion-config-COsZ6azM.js.map +1 -0
- package/dist/record-picker-BbxngCeV.js +162 -0
- package/dist/record-picker-BbxngCeV.js.map +1 -0
- package/dist/record-picker-Bz4FApxD.cjs +167 -0
- package/dist/record-picker-Bz4FApxD.cjs.map +1 -0
- package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
- package/dist/separator-BQEsr0Rc.d.cts +11 -0
- package/dist/separator-BQEsr0Rc.d.ts +11 -0
- package/dist/sheet-BLHnhLRH.js +425 -0
- package/dist/sheet-BLHnhLRH.js.map +1 -0
- package/dist/sheet-BdA0rfIz.cjs +515 -0
- package/dist/sheet-BdA0rfIz.cjs.map +1 -0
- package/dist/sidebar-CPy_fibW.cjs +608 -0
- package/dist/sidebar-CPy_fibW.cjs.map +1 -0
- package/dist/sidebar-Cfax0g0_.js +463 -0
- package/dist/sidebar-Cfax0g0_.js.map +1 -0
- package/dist/slot-C-jEfihz.cjs +122 -0
- package/dist/slot-C-jEfihz.cjs.map +1 -0
- package/dist/slot-EL8zfLG0.js +97 -0
- package/dist/slot-EL8zfLG0.js.map +1 -0
- package/dist/stack-DKdvlOM6.cjs +1771 -0
- package/dist/stack-DKdvlOM6.cjs.map +1 -0
- package/dist/stack-jMdxDrex.js +1531 -0
- package/dist/stack-jMdxDrex.js.map +1 -0
- package/dist/toast-D6MqijT2.cjs +316 -0
- package/dist/toast-D6MqijT2.cjs.map +1 -0
- package/dist/toast-D_BOLzm3.js +287 -0
- package/dist/toast-D_BOLzm3.js.map +1 -0
- package/dist/tooltip-CTRQoN1A.d.cts +29 -0
- package/dist/tooltip-CTRQoN1A.d.ts +29 -0
- package/dist/utils-BkMLyah9.js +12 -0
- package/dist/utils-BkMLyah9.js.map +1 -0
- package/dist/utils-CzTQ3-VI.cjs +17 -0
- package/dist/utils-CzTQ3-VI.cjs.map +1 -0
- package/package.json +288 -47
- package/src/styles/globals.css +155 -203
- package/dist/components/org-chart/index.d.ts +0 -54
- package/dist/components/org-chart/index.js +0 -861
- package/dist/components/org-chart/index.js.map +0 -1
- package/dist/components/record-picker.js.map +0 -1
- package/dist/components/sheet.js.map +0 -1
- package/dist/components/sidebar.js.map +0 -1
- package/dist/components/stack/index.js.map +0 -1
- package/dist/components/toast/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,882 +1,570 @@
|
|
|
1
|
-
|
|
2
|
-
import * as React5 from 'react';
|
|
3
|
-
import { cva } from 'class-variance-authority';
|
|
4
|
-
import { XCircle, XIcon, ChevronDown, SearchIcon, CheckIcon } from 'lucide-react';
|
|
5
|
-
import { clsx } from 'clsx';
|
|
6
|
-
import { twMerge } from 'tailwind-merge';
|
|
7
|
-
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
|
-
import { Popover as Popover$1 } from '@base-ui/react/popover';
|
|
9
|
-
import { Separator as Separator$1 } from '@base-ui/react/separator';
|
|
1
|
+
'use client';
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
secondary: "bg-secondary text-secondary-foreground [button,a&]:hover:bg-secondary/90",
|
|
34
|
-
success: "bg-success/8 text-success-foreground dark:bg-success/16",
|
|
35
|
-
warning: "bg-warning/8 text-warning-foreground dark:bg-warning/16"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
var Badge = React5.forwardRef(({ className, variant, size, ...props }, ref) => /* @__PURE__ */ jsx("span", { ref, "data-slot": "badge", className: cn(badgeVariants({ variant, size }), className), ...props }));
|
|
41
|
-
Badge.displayName = "Badge";
|
|
42
|
-
var PORTAL_ROOT_ID = "portal-root";
|
|
43
|
-
var PortalContext = React5.createContext({
|
|
44
|
-
layer: "base",
|
|
45
|
-
depth: 0,
|
|
46
|
-
floatingPortalStrategy: "root",
|
|
47
|
-
floatingZIndex: "default"
|
|
48
|
-
});
|
|
49
|
-
function useRootPortalContainer() {
|
|
50
|
-
const [container, setContainer] = React5.useState(null);
|
|
51
|
-
React5.useLayoutEffect(() => {
|
|
52
|
-
const el = document.getElementById(PORTAL_ROOT_ID);
|
|
53
|
-
setContainer(el);
|
|
54
|
-
}, []);
|
|
55
|
-
return container;
|
|
56
|
-
}
|
|
57
|
-
function useFloatingOverlayPortalProps() {
|
|
58
|
-
const rootContainer = useRootPortalContainer();
|
|
59
|
-
const { floatingPortalStrategy, floatingZIndex } = React5.useContext(PortalContext);
|
|
60
|
-
const container = floatingPortalStrategy === "nested" ? void 0 : rootContainer ?? null;
|
|
61
|
-
const zIndexClass = floatingZIndex === "elevated" ? "z-[var(--z-layer-floating-elevated)]" : "z-[var(--z-layer-floating)]";
|
|
62
|
-
return { container, zIndexClass };
|
|
63
|
-
}
|
|
64
|
-
function composeRefs(...refs) {
|
|
65
|
-
return (node) => {
|
|
66
|
-
refs.forEach((ref) => {
|
|
67
|
-
if (typeof ref === "function") {
|
|
68
|
-
ref(node);
|
|
69
|
-
} else if (ref != null) {
|
|
70
|
-
ref.current = node;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function mergeProps(slotProps, childProps) {
|
|
76
|
-
const overrideProps = { ...childProps };
|
|
77
|
-
for (const propName in childProps) {
|
|
78
|
-
if (propName === "ref") continue;
|
|
79
|
-
const slotPropValue = slotProps[propName];
|
|
80
|
-
const childPropValue = childProps[propName];
|
|
81
|
-
if (/^on[A-Z]/.test(propName) && typeof slotPropValue === "function" && typeof childPropValue === "function") {
|
|
82
|
-
overrideProps[propName] = (...args) => {
|
|
83
|
-
childPropValue(...args);
|
|
84
|
-
slotPropValue(...args);
|
|
85
|
-
};
|
|
86
|
-
} else if (propName === "className" && typeof slotPropValue === "string" && typeof childPropValue === "string") {
|
|
87
|
-
overrideProps[propName] = `${slotPropValue} ${childPropValue}`.trim();
|
|
88
|
-
} else if (propName === "style" && typeof slotPropValue === "object" && typeof childPropValue === "object") {
|
|
89
|
-
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return { ...slotProps, ...overrideProps };
|
|
93
|
-
}
|
|
94
|
-
function mergePropsWithRef(parentProps, childElement) {
|
|
95
|
-
const childProps = childElement.props;
|
|
96
|
-
const parentRef = parentProps.ref;
|
|
97
|
-
const childRef = childProps.ref;
|
|
98
|
-
const mergedProps = mergeProps(parentProps, childProps);
|
|
99
|
-
if (parentRef || childRef) {
|
|
100
|
-
mergedProps.ref = composeRefs(parentRef, childRef);
|
|
101
|
-
}
|
|
102
|
-
return mergedProps;
|
|
103
|
-
}
|
|
104
|
-
function isSlottable(child) {
|
|
105
|
-
return React5.isValidElement(child);
|
|
106
|
-
}
|
|
107
|
-
var Slot = React5.forwardRef((props, forwardedRef) => {
|
|
108
|
-
const { children, ...slotProps } = props;
|
|
109
|
-
if (isSlottable(children)) {
|
|
110
|
-
const childProps = children.props;
|
|
111
|
-
const childRef = childProps.ref;
|
|
112
|
-
return React5.cloneElement(children, {
|
|
113
|
-
...mergeProps(slotProps, childProps),
|
|
114
|
-
ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (React5.Children.count(children) > 1) {
|
|
118
|
-
const childrenArray = React5.Children.toArray(children);
|
|
119
|
-
const slottableChild = childrenArray.find(
|
|
120
|
-
(child) => React5.isValidElement(child) && child.type === Slottable
|
|
121
|
-
);
|
|
122
|
-
if (slottableChild) {
|
|
123
|
-
const newElement = slottableChild.props.children;
|
|
124
|
-
if (isSlottable(newElement)) {
|
|
125
|
-
const newElementProps = newElement.props;
|
|
126
|
-
const newChildren = childrenArray.map((child) => {
|
|
127
|
-
if (child === slottableChild) {
|
|
128
|
-
return React5.Children.count(newElementProps.children) > 1 ? React5.Children.only(null) : newElementProps.children;
|
|
129
|
-
}
|
|
130
|
-
return child;
|
|
131
|
-
});
|
|
132
|
-
const childRef = newElementProps.ref;
|
|
133
|
-
return React5.cloneElement(newElement, {
|
|
134
|
-
...mergeProps(slotProps, newElementProps),
|
|
135
|
-
ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef,
|
|
136
|
-
children: newChildren
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
3
|
+
import { t as cn } from "../utils-BkMLyah9.js";
|
|
4
|
+
import { Badge } from "./badge.js";
|
|
5
|
+
import { Separator } from "./separator.js";
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
7
|
+
import * as React$1 from "react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { cva } from "class-variance-authority";
|
|
10
|
+
import { CheckIcon, ChevronDown, SearchIcon, XCircle, XIcon } from "lucide-react";
|
|
11
|
+
|
|
12
|
+
//#region src/components/multi-select.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Variants for the multi-select component to handle different styles.
|
|
15
|
+
* Uses class-variance-authority (cva) to define different styles based on "variant" prop.
|
|
16
|
+
*/
|
|
17
|
+
const multiSelectVariants = cva("m-0.5 inline-flex items-center gap-0.5 rounded-full border px-2 py-1 text-xs", {
|
|
18
|
+
variants: { variant: {
|
|
19
|
+
default: "border-foreground/10 text-foreground bg-card",
|
|
20
|
+
secondary: "border-foreground/10 bg-secondary text-secondary-foreground",
|
|
21
|
+
destructive: "border-transparent bg-destructive text-destructive-foreground",
|
|
22
|
+
inverted: "inverted"
|
|
23
|
+
} },
|
|
24
|
+
defaultVariants: { variant: "default" }
|
|
142
25
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Individual option item component
|
|
28
|
+
*/
|
|
29
|
+
function OptionItem({ option, isSelected, onSelect, highlightedIndex, index, setHighlightedIndex }) {
|
|
30
|
+
const isHighlighted = highlightedIndex === index;
|
|
31
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
32
|
+
role: "option",
|
|
33
|
+
"aria-selected": isSelected,
|
|
34
|
+
"aria-disabled": option.disabled,
|
|
35
|
+
"data-highlighted": isHighlighted,
|
|
36
|
+
"data-selected": isSelected,
|
|
37
|
+
"data-disabled": option.disabled,
|
|
38
|
+
tabIndex: -1,
|
|
39
|
+
className: cn("relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none", "data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground", "data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50"),
|
|
40
|
+
onClick: (e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
if (!option.disabled) onSelect();
|
|
44
|
+
},
|
|
45
|
+
onMouseEnter: () => setHighlightedIndex(index),
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx("div", {
|
|
48
|
+
className: cn("border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border", isSelected ? "bg-primary text-primary-foreground" : "opacity-60 [&_svg]:invisible"),
|
|
49
|
+
"aria-hidden": "true",
|
|
50
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { className: "h-4 w-4" })
|
|
51
|
+
}),
|
|
52
|
+
option.icon && /* @__PURE__ */ jsx(option.icon, {
|
|
53
|
+
className: "text-muted-foreground mr-2 h-4 w-4",
|
|
54
|
+
"aria-hidden": "true"
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ jsx("span", { children: option.label }),
|
|
57
|
+
option.description && /* @__PURE__ */ jsx("span", {
|
|
58
|
+
className: "text-muted-foreground ml-2 text-xs",
|
|
59
|
+
children: option.description
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
});
|
|
169
63
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
64
|
+
const MultiSelect = React$1.forwardRef(({ options, onValueChange, variant, defaultValue = [], placeholder = "Select options", maxCount = 3, className, searchable = true, emptyIndicator, autoSize = false, singleLine = false, popoverClassName, disabled = false, responsive, minWidth, maxWidth, dropdownMaxHeight, deduplicateOptions = false, footerContent, resetOnDefaultValueChange = true, closeOnSelect = false, onClick, ...props }, ref) => {
|
|
65
|
+
const [selectedValues, setSelectedValues] = React$1.useState(defaultValue);
|
|
66
|
+
const [isPopoverOpen, setIsPopoverOpen] = React$1.useState(false);
|
|
67
|
+
const [searchValue, setSearchValue] = React$1.useState("");
|
|
68
|
+
const [highlightedIndex, setHighlightedIndex] = React$1.useState(-1);
|
|
69
|
+
const multiSelectId = React$1.useId();
|
|
70
|
+
const listboxId = `${multiSelectId}-listbox`;
|
|
71
|
+
const triggerDescriptionId = `${multiSelectId}-description`;
|
|
72
|
+
const selectedCountId = `${multiSelectId}-count`;
|
|
73
|
+
const searchInputId = `${multiSelectId}-search`;
|
|
74
|
+
const searchInputRef = React$1.useRef(null);
|
|
75
|
+
const listRef = React$1.useRef(null);
|
|
76
|
+
const prevDefaultValueRef = React$1.useRef(defaultValue);
|
|
77
|
+
const isGroupedOptions = React$1.useCallback((opts) => {
|
|
78
|
+
return opts.length > 0 && "heading" in opts[0];
|
|
79
|
+
}, []);
|
|
80
|
+
const arraysEqual = React$1.useCallback((a, b) => {
|
|
81
|
+
if (a.length !== b.length) return false;
|
|
82
|
+
const sortedA = [...a].sort();
|
|
83
|
+
const sortedB = [...b].sort();
|
|
84
|
+
return sortedA.every((val, index) => val === sortedB[index]);
|
|
85
|
+
}, []);
|
|
86
|
+
const resetToDefault = React$1.useCallback(() => {
|
|
87
|
+
setSelectedValues(defaultValue);
|
|
88
|
+
setIsPopoverOpen(false);
|
|
89
|
+
setSearchValue("");
|
|
90
|
+
onValueChange(defaultValue);
|
|
91
|
+
}, [defaultValue, onValueChange]);
|
|
92
|
+
const buttonRef = React$1.useRef(null);
|
|
93
|
+
React$1.useImperativeHandle(ref, () => ({
|
|
94
|
+
reset: resetToDefault,
|
|
95
|
+
getSelectedValues: () => selectedValues,
|
|
96
|
+
setSelectedValues: (values) => {
|
|
97
|
+
setSelectedValues(values);
|
|
98
|
+
onValueChange(values);
|
|
99
|
+
},
|
|
100
|
+
clear: () => {
|
|
101
|
+
setSelectedValues([]);
|
|
102
|
+
onValueChange([]);
|
|
103
|
+
},
|
|
104
|
+
focus: () => {
|
|
105
|
+
if (buttonRef.current) {
|
|
106
|
+
buttonRef.current.focus();
|
|
107
|
+
const originalOutline = buttonRef.current.style.outline;
|
|
108
|
+
const originalOutlineOffset = buttonRef.current.style.outlineOffset;
|
|
109
|
+
buttonRef.current.style.outline = "2px solid hsl(var(--ring))";
|
|
110
|
+
buttonRef.current.style.outlineOffset = "2px";
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
if (buttonRef.current) {
|
|
113
|
+
buttonRef.current.style.outline = originalOutline;
|
|
114
|
+
buttonRef.current.style.outlineOffset = originalOutlineOffset;
|
|
115
|
+
}
|
|
116
|
+
}, 1e3);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}), [
|
|
120
|
+
resetToDefault,
|
|
121
|
+
selectedValues,
|
|
122
|
+
onValueChange
|
|
123
|
+
]);
|
|
124
|
+
const [screenSize, setScreenSize] = React$1.useState("desktop");
|
|
125
|
+
React$1.useEffect(() => {
|
|
126
|
+
if (typeof window === "undefined") return;
|
|
127
|
+
const handleResize = () => {
|
|
128
|
+
const width = window.innerWidth;
|
|
129
|
+
if (width < 640) setScreenSize("mobile");
|
|
130
|
+
else if (width < 1024) setScreenSize("tablet");
|
|
131
|
+
else setScreenSize("desktop");
|
|
132
|
+
};
|
|
133
|
+
handleResize();
|
|
134
|
+
window.addEventListener("resize", handleResize);
|
|
135
|
+
return () => {
|
|
136
|
+
if (typeof window !== "undefined") window.removeEventListener("resize", handleResize);
|
|
137
|
+
};
|
|
138
|
+
}, []);
|
|
139
|
+
const getResponsiveSettings = () => {
|
|
140
|
+
if (!responsive) return {
|
|
141
|
+
maxCount,
|
|
142
|
+
hideIcons: false,
|
|
143
|
+
compactMode: false
|
|
144
|
+
};
|
|
145
|
+
if (responsive === true) {
|
|
146
|
+
const currentSettings = {
|
|
147
|
+
mobile: {
|
|
148
|
+
maxCount: 2,
|
|
149
|
+
hideIcons: false,
|
|
150
|
+
compactMode: true
|
|
151
|
+
},
|
|
152
|
+
tablet: {
|
|
153
|
+
maxCount: 4,
|
|
154
|
+
hideIcons: false,
|
|
155
|
+
compactMode: false
|
|
156
|
+
},
|
|
157
|
+
desktop: {
|
|
158
|
+
maxCount: 6,
|
|
159
|
+
hideIcons: false,
|
|
160
|
+
compactMode: false
|
|
161
|
+
}
|
|
162
|
+
}[screenSize];
|
|
163
|
+
return {
|
|
164
|
+
maxCount: currentSettings?.maxCount ?? maxCount,
|
|
165
|
+
hideIcons: currentSettings?.hideIcons ?? false,
|
|
166
|
+
compactMode: currentSettings?.compactMode ?? false
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const currentSettings = responsive[screenSize];
|
|
170
|
+
return {
|
|
171
|
+
maxCount: currentSettings?.maxCount ?? maxCount,
|
|
172
|
+
hideIcons: currentSettings?.hideIcons ?? false,
|
|
173
|
+
compactMode: currentSettings?.compactMode ?? false
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const responsiveSettings = getResponsiveSettings();
|
|
177
|
+
const getAllOptions = React$1.useCallback(() => {
|
|
178
|
+
if (options.length === 0) return [];
|
|
179
|
+
let allOptions;
|
|
180
|
+
if (isGroupedOptions(options)) allOptions = options.flatMap((group) => group.options);
|
|
181
|
+
else allOptions = options;
|
|
182
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
183
|
+
const duplicates = [];
|
|
184
|
+
const uniqueOptions = [];
|
|
185
|
+
allOptions.forEach((option) => {
|
|
186
|
+
if (valueSet.has(option.value)) {
|
|
187
|
+
duplicates.push(option.value);
|
|
188
|
+
if (!deduplicateOptions) uniqueOptions.push(option);
|
|
189
|
+
} else {
|
|
190
|
+
valueSet.add(option.value);
|
|
191
|
+
uniqueOptions.push(option);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
if (process.env.NODE_ENV === "development" && duplicates.length > 0) console.warn(`MultiSelect: Duplicate option values ${deduplicateOptions ? "automatically removed" : "detected"}: ${duplicates.join(", ")}. ${deduplicateOptions ? "Duplicates have been removed automatically." : "This may cause unexpected behavior. Consider setting 'deduplicateOptions={true}' or ensure all option values are unique."}`);
|
|
195
|
+
return deduplicateOptions ? uniqueOptions : allOptions;
|
|
196
|
+
}, [
|
|
197
|
+
options,
|
|
198
|
+
deduplicateOptions,
|
|
199
|
+
isGroupedOptions
|
|
200
|
+
]);
|
|
201
|
+
const getOptionByValue = React$1.useCallback((value) => {
|
|
202
|
+
const option = getAllOptions().find((option) => option.value === value);
|
|
203
|
+
if (!option && process.env.NODE_ENV === "development") console.warn(`MultiSelect: Option with value "${value}" not found in options list`);
|
|
204
|
+
return option;
|
|
205
|
+
}, [getAllOptions]);
|
|
206
|
+
const filteredOptions = React$1.useMemo(() => {
|
|
207
|
+
if (!searchable || !searchValue) return options;
|
|
208
|
+
if (options.length === 0) return [];
|
|
209
|
+
if (isGroupedOptions(options)) return options.map((group) => ({
|
|
210
|
+
...group,
|
|
211
|
+
options: group.options.filter((option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase()))
|
|
212
|
+
})).filter((group) => group.options.length > 0);
|
|
213
|
+
return options.filter((option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase()));
|
|
214
|
+
}, [
|
|
215
|
+
options,
|
|
216
|
+
searchValue,
|
|
217
|
+
searchable,
|
|
218
|
+
isGroupedOptions
|
|
219
|
+
]);
|
|
220
|
+
const flatFilteredOptions = React$1.useMemo(() => {
|
|
221
|
+
if (isGroupedOptions(filteredOptions)) return filteredOptions.flatMap((group) => group.options);
|
|
222
|
+
return filteredOptions;
|
|
223
|
+
}, [filteredOptions, isGroupedOptions]);
|
|
224
|
+
const toggleOption = React$1.useCallback((optionValue) => {
|
|
225
|
+
if (disabled) return;
|
|
226
|
+
if (getOptionByValue(optionValue)?.disabled) return;
|
|
227
|
+
const newSelectedValues = selectedValues.includes(optionValue) ? selectedValues.filter((value) => value !== optionValue) : [...selectedValues, optionValue];
|
|
228
|
+
setSelectedValues(newSelectedValues);
|
|
229
|
+
onValueChange(newSelectedValues);
|
|
230
|
+
if (closeOnSelect) setIsPopoverOpen(false);
|
|
231
|
+
}, [
|
|
232
|
+
disabled,
|
|
233
|
+
getOptionByValue,
|
|
234
|
+
selectedValues,
|
|
235
|
+
onValueChange,
|
|
236
|
+
closeOnSelect
|
|
237
|
+
]);
|
|
238
|
+
const handleClear = () => {
|
|
239
|
+
if (disabled) return;
|
|
240
|
+
setSelectedValues([]);
|
|
241
|
+
onValueChange([]);
|
|
242
|
+
};
|
|
243
|
+
const handleTogglePopover = () => {
|
|
244
|
+
if (disabled) return;
|
|
245
|
+
setIsPopoverOpen((prev) => !prev);
|
|
246
|
+
};
|
|
247
|
+
const clearExtraOptions = () => {
|
|
248
|
+
if (disabled) return;
|
|
249
|
+
const newSelectedValues = selectedValues.slice(0, responsiveSettings.maxCount);
|
|
250
|
+
setSelectedValues(newSelectedValues);
|
|
251
|
+
onValueChange(newSelectedValues);
|
|
252
|
+
};
|
|
253
|
+
const handleKeyDown = React$1.useCallback((event) => {
|
|
254
|
+
const optionsCount = flatFilteredOptions.length;
|
|
255
|
+
if (optionsCount === 0) return;
|
|
256
|
+
switch (event.key) {
|
|
257
|
+
case "ArrowDown":
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
setHighlightedIndex((prev) => prev < optionsCount - 1 ? prev + 1 : 0);
|
|
260
|
+
break;
|
|
261
|
+
case "ArrowUp":
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
setHighlightedIndex((prev) => prev > 0 ? prev - 1 : optionsCount - 1);
|
|
264
|
+
break;
|
|
265
|
+
case "Enter":
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
if (highlightedIndex >= 0 && highlightedIndex < optionsCount) {
|
|
268
|
+
const option = flatFilteredOptions[highlightedIndex];
|
|
269
|
+
if (option && !option.disabled) toggleOption(option.value);
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
case "Escape":
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
setIsPopoverOpen(false);
|
|
275
|
+
break;
|
|
276
|
+
case "Backspace":
|
|
277
|
+
if (!searchValue && selectedValues.length > 0) {
|
|
278
|
+
const newSelectedValues = [...selectedValues];
|
|
279
|
+
newSelectedValues.pop();
|
|
280
|
+
setSelectedValues(newSelectedValues);
|
|
281
|
+
onValueChange(newSelectedValues);
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}, [
|
|
286
|
+
flatFilteredOptions,
|
|
287
|
+
highlightedIndex,
|
|
288
|
+
toggleOption,
|
|
289
|
+
searchValue,
|
|
290
|
+
selectedValues,
|
|
291
|
+
onValueChange
|
|
292
|
+
]);
|
|
293
|
+
React$1.useEffect(() => {
|
|
294
|
+
if (!resetOnDefaultValueChange) return;
|
|
295
|
+
const prevDefaultValue = prevDefaultValueRef.current;
|
|
296
|
+
if (!arraysEqual(prevDefaultValue, defaultValue)) {
|
|
297
|
+
if (!arraysEqual(selectedValues, defaultValue)) setSelectedValues(defaultValue);
|
|
298
|
+
prevDefaultValueRef.current = [...defaultValue];
|
|
299
|
+
}
|
|
300
|
+
}, [
|
|
301
|
+
defaultValue,
|
|
302
|
+
selectedValues,
|
|
303
|
+
arraysEqual,
|
|
304
|
+
resetOnDefaultValueChange
|
|
305
|
+
]);
|
|
306
|
+
const getWidthConstraints = () => {
|
|
307
|
+
return {
|
|
308
|
+
minWidth: minWidth || (screenSize === "mobile" ? "0px" : "200px"),
|
|
309
|
+
maxWidth: maxWidth || "100%",
|
|
310
|
+
width: autoSize ? "auto" : "100%"
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
const widthConstraints = getWidthConstraints();
|
|
314
|
+
const effectiveDropdownMaxHeight = React$1.useMemo(() => {
|
|
315
|
+
if (dropdownMaxHeight) return dropdownMaxHeight;
|
|
316
|
+
return screenSize === "mobile" ? "70vh" : "60vh";
|
|
317
|
+
}, [dropdownMaxHeight, screenSize]);
|
|
318
|
+
React$1.useEffect(() => {
|
|
319
|
+
if (!isPopoverOpen) {
|
|
320
|
+
setSearchValue("");
|
|
321
|
+
setHighlightedIndex(-1);
|
|
322
|
+
}
|
|
323
|
+
}, [isPopoverOpen]);
|
|
324
|
+
React$1.useEffect(() => {
|
|
325
|
+
if (isPopoverOpen && searchable && searchInputRef.current) {
|
|
326
|
+
const timer = setTimeout(() => {
|
|
327
|
+
searchInputRef.current?.focus();
|
|
328
|
+
}, 0);
|
|
329
|
+
return () => clearTimeout(timer);
|
|
330
|
+
}
|
|
331
|
+
}, [isPopoverOpen, searchable]);
|
|
332
|
+
React$1.useEffect(() => {
|
|
333
|
+
setHighlightedIndex(flatFilteredOptions.length > 0 ? 0 : -1);
|
|
334
|
+
}, [searchValue, flatFilteredOptions.length]);
|
|
335
|
+
const totalFilteredCount = React$1.useMemo(() => {
|
|
336
|
+
if (isGroupedOptions(filteredOptions)) return filteredOptions.reduce((acc, group) => acc + group.options.length, 0);
|
|
337
|
+
return filteredOptions.length;
|
|
338
|
+
}, [filteredOptions, isGroupedOptions]);
|
|
339
|
+
let optionIndex = 0;
|
|
340
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Popover, {
|
|
341
|
+
open: isPopoverOpen,
|
|
342
|
+
onOpenChange: setIsPopoverOpen,
|
|
343
|
+
children: [
|
|
344
|
+
/* @__PURE__ */ jsx("div", {
|
|
345
|
+
id: triggerDescriptionId,
|
|
346
|
+
className: "sr-only",
|
|
347
|
+
children: "Multi-select dropdown. Use arrow keys to navigate, Enter to select, and Escape to close."
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ jsx("div", {
|
|
350
|
+
id: selectedCountId,
|
|
351
|
+
className: "sr-only",
|
|
352
|
+
"aria-live": "polite",
|
|
353
|
+
children: selectedValues.length === 0 ? "No options selected" : `${selectedValues.length} option${selectedValues.length === 1 ? "" : "s"} selected: ${selectedValues.map((value) => getOptionByValue(value)?.label).filter(Boolean).join(", ")}`
|
|
354
|
+
}),
|
|
355
|
+
/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
356
|
+
asChild: true,
|
|
357
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
358
|
+
ref: buttonRef,
|
|
359
|
+
type: "button",
|
|
360
|
+
...props,
|
|
361
|
+
onClick: (event) => {
|
|
362
|
+
if (disabled) return;
|
|
363
|
+
onClick?.(event);
|
|
364
|
+
handleTogglePopover();
|
|
365
|
+
},
|
|
366
|
+
disabled,
|
|
367
|
+
role: "combobox",
|
|
368
|
+
"aria-expanded": isPopoverOpen,
|
|
369
|
+
"aria-haspopup": "listbox",
|
|
370
|
+
"aria-controls": isPopoverOpen ? listboxId : void 0,
|
|
371
|
+
"aria-describedby": `${triggerDescriptionId} ${selectedCountId}`,
|
|
372
|
+
"aria-label": `Multi-select: ${selectedValues.length} of ${getAllOptions().length} options selected. ${placeholder}`,
|
|
373
|
+
className: cn(`border-input/70 focus-visible:border-primary/60 focus-visible:ring-primary/20 flex items-center
|
|
374
|
+
justify-between rounded-md border bg-transparent pr-1 pl-2 shadow-xs transition-[color,box-shadow,scale]
|
|
375
|
+
duration-150 ease-out outline-none focus-visible:ring-[3px] motion-safe:active:not-disabled:scale-[0.96]
|
|
376
|
+
motion-reduce:transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50`, singleLine ? "h-8 min-h-8 py-0.5 text-xs" : "h-auto min-h-10 py-2 text-sm", autoSize && "w-auto", !autoSize && "w-full", responsiveSettings.compactMode && "min-h-9 py-1.5 text-xs", className),
|
|
377
|
+
style: {
|
|
378
|
+
minWidth: widthConstraints.minWidth,
|
|
379
|
+
maxWidth: widthConstraints.maxWidth,
|
|
380
|
+
width: widthConstraints.width
|
|
381
|
+
},
|
|
382
|
+
children: selectedValues.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
383
|
+
className: "flex w-full items-center justify-between",
|
|
384
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
385
|
+
className: cn("flex items-center gap-1", singleLine ? "multiselect-singleline-scroll overflow-x-auto" : "flex-wrap", responsiveSettings.compactMode && "gap-0.5"),
|
|
386
|
+
children: [selectedValues.slice(0, responsiveSettings.maxCount).map((value) => {
|
|
387
|
+
const option = getOptionByValue(value);
|
|
388
|
+
const IconComponent = option?.icon;
|
|
389
|
+
const customStyle = option?.style;
|
|
390
|
+
if (!option) return null;
|
|
391
|
+
const badgeStyle = {
|
|
392
|
+
...customStyle?.badgeColor && { backgroundColor: customStyle.badgeColor },
|
|
393
|
+
...customStyle?.gradient && {
|
|
394
|
+
background: customStyle.gradient,
|
|
395
|
+
color: "white"
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
return /* @__PURE__ */ jsxs(Badge, {
|
|
399
|
+
className: cn(multiSelectVariants({ variant }), customStyle?.gradient && "border-transparent text-white", responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs", singleLine && "py-0.5", screenSize === "mobile" && "max-w-[120px] truncate", singleLine && "flex-shrink-0 whitespace-nowrap", "[&>svg]:pointer-events-auto"),
|
|
400
|
+
style: badgeStyle,
|
|
401
|
+
children: [
|
|
402
|
+
IconComponent && !responsiveSettings.hideIcons && /* @__PURE__ */ jsx(IconComponent, {
|
|
403
|
+
className: cn("mr-2 h-4 w-4", responsiveSettings.compactMode && "mr-1 h-3 w-3", customStyle?.iconColor && "text-current"),
|
|
404
|
+
...customStyle?.iconColor && { style: { color: customStyle.iconColor } }
|
|
405
|
+
}),
|
|
406
|
+
/* @__PURE__ */ jsx("span", {
|
|
407
|
+
className: cn(screenSize === "mobile" && "truncate"),
|
|
408
|
+
children: option.label
|
|
409
|
+
}),
|
|
410
|
+
/* @__PURE__ */ jsx("div", {
|
|
411
|
+
role: "button",
|
|
412
|
+
tabIndex: 0,
|
|
413
|
+
onClick: (event) => {
|
|
414
|
+
event.stopPropagation();
|
|
415
|
+
toggleOption(value);
|
|
416
|
+
},
|
|
417
|
+
onKeyDown: (event) => {
|
|
418
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
event.stopPropagation();
|
|
421
|
+
toggleOption(value);
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
"aria-label": `Remove ${option.label} from selection`,
|
|
425
|
+
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1 focus:ring-white/50 focus:outline-none",
|
|
426
|
+
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
427
|
+
})
|
|
428
|
+
]
|
|
429
|
+
}, value);
|
|
430
|
+
}).filter(Boolean), selectedValues.length > responsiveSettings.maxCount && /* @__PURE__ */ jsxs(Badge, {
|
|
431
|
+
className: cn("text-foreground border-foreground/10 bg-transparent", multiSelectVariants({ variant }), responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs", singleLine && "flex-shrink-0 whitespace-nowrap", "[&>svg]:pointer-events-auto"),
|
|
432
|
+
children: [`+ ${selectedValues.length - responsiveSettings.maxCount} more`, /* @__PURE__ */ jsx("div", {
|
|
433
|
+
role: "button",
|
|
434
|
+
tabIndex: 0,
|
|
435
|
+
onClick: (event) => {
|
|
436
|
+
event.stopPropagation();
|
|
437
|
+
clearExtraOptions();
|
|
438
|
+
},
|
|
439
|
+
onKeyDown: (event) => {
|
|
440
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
441
|
+
event.preventDefault();
|
|
442
|
+
event.stopPropagation();
|
|
443
|
+
clearExtraOptions();
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
"aria-label": "Clear extra selected options",
|
|
447
|
+
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1\n focus:ring-white/50 focus:outline-none",
|
|
448
|
+
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
449
|
+
})]
|
|
450
|
+
})]
|
|
451
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
452
|
+
className: "flex items-center justify-between",
|
|
453
|
+
children: [
|
|
454
|
+
/* @__PURE__ */ jsx("div", {
|
|
455
|
+
role: "button",
|
|
456
|
+
tabIndex: 0,
|
|
457
|
+
onClick: (event) => {
|
|
458
|
+
event.stopPropagation();
|
|
459
|
+
handleClear();
|
|
460
|
+
},
|
|
461
|
+
onKeyDown: (event) => {
|
|
462
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
463
|
+
event.preventDefault();
|
|
464
|
+
event.stopPropagation();
|
|
465
|
+
handleClear();
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
"aria-label": `Clear all ${selectedValues.length} selected options`,
|
|
469
|
+
className: "text-muted-foreground hover:text-foreground focus:ring-ring mx-2 flex h-4 w-4\n cursor-pointer items-center justify-center rounded-sm focus:ring-2 focus:ring-offset-1\n focus:outline-none",
|
|
470
|
+
children: /* @__PURE__ */ jsx(XIcon, { className: "h-4 w-4" })
|
|
471
|
+
}),
|
|
472
|
+
/* @__PURE__ */ jsx(Separator, {
|
|
473
|
+
orientation: "vertical",
|
|
474
|
+
className: "flex h-full min-h-6"
|
|
475
|
+
}),
|
|
476
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })
|
|
477
|
+
]
|
|
478
|
+
})]
|
|
479
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
480
|
+
className: "mx-auto flex w-full items-center justify-between",
|
|
481
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
482
|
+
className: "text-muted-foreground mx-1 text-sm",
|
|
483
|
+
children: placeholder
|
|
484
|
+
}), /* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })]
|
|
485
|
+
})
|
|
486
|
+
})
|
|
487
|
+
}),
|
|
488
|
+
/* @__PURE__ */ jsx(PopoverContent, {
|
|
489
|
+
id: listboxId,
|
|
490
|
+
"aria-label": "Available options",
|
|
491
|
+
className: cn("w-(--anchor-width) overflow-hidden p-0", popoverClassName),
|
|
492
|
+
style: {
|
|
493
|
+
minWidth: widthConstraints.minWidth,
|
|
494
|
+
maxWidth: widthConstraints.maxWidth,
|
|
495
|
+
width: widthConstraints.width === "auto" ? "auto" : void 0,
|
|
496
|
+
maxHeight: effectiveDropdownMaxHeight,
|
|
497
|
+
touchAction: "manipulation"
|
|
498
|
+
},
|
|
499
|
+
align: "start",
|
|
500
|
+
onEscapeKeyDown: () => setIsPopoverOpen(false),
|
|
501
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
502
|
+
className: "flex h-full max-h-[inherit] flex-col",
|
|
503
|
+
onKeyDown: handleKeyDown,
|
|
504
|
+
children: [
|
|
505
|
+
searchable && /* @__PURE__ */ jsxs("div", {
|
|
506
|
+
className: "flex items-center border-b px-3",
|
|
507
|
+
children: [/* @__PURE__ */ jsx(SearchIcon, { className: "text-muted-foreground mr-2 h-4 w-4 shrink-0 opacity-50" }), /* @__PURE__ */ jsx("input", {
|
|
508
|
+
ref: searchInputRef,
|
|
509
|
+
id: searchInputId,
|
|
510
|
+
type: "text",
|
|
511
|
+
placeholder: "Search options...",
|
|
512
|
+
value: searchValue,
|
|
513
|
+
onChange: (e) => setSearchValue(e.target.value),
|
|
514
|
+
"aria-label": "Search through available options",
|
|
515
|
+
className: "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
516
|
+
})]
|
|
517
|
+
}),
|
|
518
|
+
/* @__PURE__ */ jsx("div", {
|
|
519
|
+
ref: listRef,
|
|
520
|
+
role: "listbox",
|
|
521
|
+
"aria-multiselectable": "true",
|
|
522
|
+
className: "multiselect-scrollbar scrollbar-neutral-thin overscroll-contain min-h-0 flex-1 overflow-y-auto p-1",
|
|
523
|
+
children: totalFilteredCount === 0 ? /* @__PURE__ */ jsx("div", {
|
|
524
|
+
className: "text-muted-foreground py-6 text-center text-sm",
|
|
525
|
+
children: emptyIndicator || "No results found."
|
|
526
|
+
}) : isGroupedOptions(filteredOptions) ? filteredOptions.map((group) => /* @__PURE__ */ jsxs("div", {
|
|
527
|
+
role: "group",
|
|
528
|
+
"aria-labelledby": `group-${group.heading}`,
|
|
529
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
530
|
+
id: `group-${group.heading}`,
|
|
531
|
+
className: "text-muted-foreground px-2 py-1.5 text-xs font-medium",
|
|
532
|
+
children: group.heading
|
|
533
|
+
}), group.options.map((option) => {
|
|
534
|
+
const currentIndex = optionIndex++;
|
|
535
|
+
return /* @__PURE__ */ jsx(OptionItem, {
|
|
536
|
+
option,
|
|
537
|
+
isSelected: selectedValues.includes(option.value),
|
|
538
|
+
onSelect: () => toggleOption(option.value),
|
|
539
|
+
highlightedIndex,
|
|
540
|
+
index: currentIndex,
|
|
541
|
+
setHighlightedIndex
|
|
542
|
+
}, option.value);
|
|
543
|
+
})]
|
|
544
|
+
}, group.heading)) : filteredOptions.map((option) => {
|
|
545
|
+
const currentIndex = optionIndex++;
|
|
546
|
+
return /* @__PURE__ */ jsx(OptionItem, {
|
|
547
|
+
option,
|
|
548
|
+
isSelected: selectedValues.includes(option.value),
|
|
549
|
+
onSelect: () => toggleOption(option.value),
|
|
550
|
+
highlightedIndex,
|
|
551
|
+
index: currentIndex,
|
|
552
|
+
setHighlightedIndex
|
|
553
|
+
}, option.value);
|
|
554
|
+
})
|
|
555
|
+
}),
|
|
556
|
+
footerContent && /* @__PURE__ */ jsx("div", {
|
|
557
|
+
className: "border-t p-1",
|
|
558
|
+
children: footerContent
|
|
559
|
+
})
|
|
560
|
+
]
|
|
561
|
+
})
|
|
562
|
+
})
|
|
563
|
+
]
|
|
564
|
+
}) });
|
|
236
565
|
});
|
|
237
|
-
function OptionItem({
|
|
238
|
-
option,
|
|
239
|
-
isSelected,
|
|
240
|
-
onSelect,
|
|
241
|
-
highlightedIndex,
|
|
242
|
-
index,
|
|
243
|
-
setHighlightedIndex
|
|
244
|
-
}) {
|
|
245
|
-
const isHighlighted = highlightedIndex === index;
|
|
246
|
-
return /* @__PURE__ */ jsxs(
|
|
247
|
-
"div",
|
|
248
|
-
{
|
|
249
|
-
role: "option",
|
|
250
|
-
"aria-selected": isSelected,
|
|
251
|
-
"aria-disabled": option.disabled,
|
|
252
|
-
"data-highlighted": isHighlighted,
|
|
253
|
-
"data-selected": isSelected,
|
|
254
|
-
"data-disabled": option.disabled,
|
|
255
|
-
tabIndex: -1,
|
|
256
|
-
className: cn(
|
|
257
|
-
"relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
|
|
258
|
-
"data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground",
|
|
259
|
-
"data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50"
|
|
260
|
-
),
|
|
261
|
-
onClick: (e) => {
|
|
262
|
-
e.preventDefault();
|
|
263
|
-
e.stopPropagation();
|
|
264
|
-
if (!option.disabled) {
|
|
265
|
-
onSelect();
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
onMouseEnter: () => setHighlightedIndex(index),
|
|
269
|
-
children: [
|
|
270
|
-
/* @__PURE__ */ jsx(
|
|
271
|
-
"div",
|
|
272
|
-
{
|
|
273
|
-
className: cn(
|
|
274
|
-
"border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
|
275
|
-
isSelected ? "bg-primary text-primary-foreground" : "opacity-60 [&_svg]:invisible"
|
|
276
|
-
),
|
|
277
|
-
"aria-hidden": "true",
|
|
278
|
-
children: /* @__PURE__ */ jsx(CheckIcon, { className: "h-4 w-4" })
|
|
279
|
-
}
|
|
280
|
-
),
|
|
281
|
-
option.icon && /* @__PURE__ */ jsx(option.icon, { className: "text-muted-foreground mr-2 h-4 w-4", "aria-hidden": "true" }),
|
|
282
|
-
/* @__PURE__ */ jsx("span", { children: option.label }),
|
|
283
|
-
option.description && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground ml-2 text-xs", children: option.description })
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
var MultiSelect = React5.forwardRef(
|
|
289
|
-
({
|
|
290
|
-
options,
|
|
291
|
-
onValueChange,
|
|
292
|
-
variant,
|
|
293
|
-
defaultValue = [],
|
|
294
|
-
placeholder = "Select options",
|
|
295
|
-
maxCount = 3,
|
|
296
|
-
className,
|
|
297
|
-
searchable = true,
|
|
298
|
-
emptyIndicator,
|
|
299
|
-
autoSize = false,
|
|
300
|
-
singleLine = false,
|
|
301
|
-
popoverClassName,
|
|
302
|
-
disabled = false,
|
|
303
|
-
responsive,
|
|
304
|
-
minWidth,
|
|
305
|
-
maxWidth,
|
|
306
|
-
dropdownMaxHeight,
|
|
307
|
-
deduplicateOptions = false,
|
|
308
|
-
footerContent,
|
|
309
|
-
resetOnDefaultValueChange = true,
|
|
310
|
-
closeOnSelect = false,
|
|
311
|
-
onClick,
|
|
312
|
-
...props
|
|
313
|
-
}, ref) => {
|
|
314
|
-
const [selectedValues, setSelectedValues] = React5.useState(defaultValue);
|
|
315
|
-
const [isPopoverOpen, setIsPopoverOpen] = React5.useState(false);
|
|
316
|
-
const [searchValue, setSearchValue] = React5.useState("");
|
|
317
|
-
const [highlightedIndex, setHighlightedIndex] = React5.useState(-1);
|
|
318
|
-
const multiSelectId = React5.useId();
|
|
319
|
-
const listboxId = `${multiSelectId}-listbox`;
|
|
320
|
-
const triggerDescriptionId = `${multiSelectId}-description`;
|
|
321
|
-
const selectedCountId = `${multiSelectId}-count`;
|
|
322
|
-
const searchInputId = `${multiSelectId}-search`;
|
|
323
|
-
const searchInputRef = React5.useRef(null);
|
|
324
|
-
const listRef = React5.useRef(null);
|
|
325
|
-
const prevDefaultValueRef = React5.useRef(defaultValue);
|
|
326
|
-
const isGroupedOptions = React5.useCallback(
|
|
327
|
-
(opts) => {
|
|
328
|
-
return opts.length > 0 && "heading" in opts[0];
|
|
329
|
-
},
|
|
330
|
-
[]
|
|
331
|
-
);
|
|
332
|
-
const arraysEqual = React5.useCallback((a, b) => {
|
|
333
|
-
if (a.length !== b.length) return false;
|
|
334
|
-
const sortedA = [...a].sort();
|
|
335
|
-
const sortedB = [...b].sort();
|
|
336
|
-
return sortedA.every((val, index) => val === sortedB[index]);
|
|
337
|
-
}, []);
|
|
338
|
-
const resetToDefault = React5.useCallback(() => {
|
|
339
|
-
setSelectedValues(defaultValue);
|
|
340
|
-
setIsPopoverOpen(false);
|
|
341
|
-
setSearchValue("");
|
|
342
|
-
onValueChange(defaultValue);
|
|
343
|
-
}, [defaultValue, onValueChange]);
|
|
344
|
-
const buttonRef = React5.useRef(null);
|
|
345
|
-
React5.useImperativeHandle(
|
|
346
|
-
ref,
|
|
347
|
-
() => ({
|
|
348
|
-
reset: resetToDefault,
|
|
349
|
-
getSelectedValues: () => selectedValues,
|
|
350
|
-
setSelectedValues: (values) => {
|
|
351
|
-
setSelectedValues(values);
|
|
352
|
-
onValueChange(values);
|
|
353
|
-
},
|
|
354
|
-
clear: () => {
|
|
355
|
-
setSelectedValues([]);
|
|
356
|
-
onValueChange([]);
|
|
357
|
-
},
|
|
358
|
-
focus: () => {
|
|
359
|
-
if (buttonRef.current) {
|
|
360
|
-
buttonRef.current.focus();
|
|
361
|
-
const originalOutline = buttonRef.current.style.outline;
|
|
362
|
-
const originalOutlineOffset = buttonRef.current.style.outlineOffset;
|
|
363
|
-
buttonRef.current.style.outline = "2px solid hsl(var(--ring))";
|
|
364
|
-
buttonRef.current.style.outlineOffset = "2px";
|
|
365
|
-
setTimeout(() => {
|
|
366
|
-
if (buttonRef.current) {
|
|
367
|
-
buttonRef.current.style.outline = originalOutline;
|
|
368
|
-
buttonRef.current.style.outlineOffset = originalOutlineOffset;
|
|
369
|
-
}
|
|
370
|
-
}, 1e3);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}),
|
|
374
|
-
[resetToDefault, selectedValues, onValueChange]
|
|
375
|
-
);
|
|
376
|
-
const [screenSize, setScreenSize] = React5.useState("desktop");
|
|
377
|
-
React5.useEffect(() => {
|
|
378
|
-
if (typeof window === "undefined") return;
|
|
379
|
-
const handleResize = () => {
|
|
380
|
-
const width = window.innerWidth;
|
|
381
|
-
if (width < 640) {
|
|
382
|
-
setScreenSize("mobile");
|
|
383
|
-
} else if (width < 1024) {
|
|
384
|
-
setScreenSize("tablet");
|
|
385
|
-
} else {
|
|
386
|
-
setScreenSize("desktop");
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
handleResize();
|
|
390
|
-
window.addEventListener("resize", handleResize);
|
|
391
|
-
return () => {
|
|
392
|
-
if (typeof window !== "undefined") {
|
|
393
|
-
window.removeEventListener("resize", handleResize);
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
}, []);
|
|
397
|
-
const getResponsiveSettings = () => {
|
|
398
|
-
if (!responsive) {
|
|
399
|
-
return {
|
|
400
|
-
maxCount,
|
|
401
|
-
hideIcons: false,
|
|
402
|
-
compactMode: false
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
if (responsive === true) {
|
|
406
|
-
const defaultResponsive = {
|
|
407
|
-
mobile: { maxCount: 2, hideIcons: false, compactMode: true },
|
|
408
|
-
tablet: { maxCount: 4, hideIcons: false, compactMode: false },
|
|
409
|
-
desktop: { maxCount: 6, hideIcons: false, compactMode: false }
|
|
410
|
-
};
|
|
411
|
-
const currentSettings2 = defaultResponsive[screenSize];
|
|
412
|
-
return {
|
|
413
|
-
maxCount: currentSettings2?.maxCount ?? maxCount,
|
|
414
|
-
hideIcons: currentSettings2?.hideIcons ?? false,
|
|
415
|
-
compactMode: currentSettings2?.compactMode ?? false
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
const currentSettings = responsive[screenSize];
|
|
419
|
-
return {
|
|
420
|
-
maxCount: currentSettings?.maxCount ?? maxCount,
|
|
421
|
-
hideIcons: currentSettings?.hideIcons ?? false,
|
|
422
|
-
compactMode: currentSettings?.compactMode ?? false
|
|
423
|
-
};
|
|
424
|
-
};
|
|
425
|
-
const responsiveSettings = getResponsiveSettings();
|
|
426
|
-
const getAllOptions = React5.useCallback(() => {
|
|
427
|
-
if (options.length === 0) return [];
|
|
428
|
-
let allOptions;
|
|
429
|
-
if (isGroupedOptions(options)) {
|
|
430
|
-
allOptions = options.flatMap((group) => group.options);
|
|
431
|
-
} else {
|
|
432
|
-
allOptions = options;
|
|
433
|
-
}
|
|
434
|
-
const valueSet = /* @__PURE__ */ new Set();
|
|
435
|
-
const duplicates = [];
|
|
436
|
-
const uniqueOptions = [];
|
|
437
|
-
allOptions.forEach((option) => {
|
|
438
|
-
if (valueSet.has(option.value)) {
|
|
439
|
-
duplicates.push(option.value);
|
|
440
|
-
if (!deduplicateOptions) {
|
|
441
|
-
uniqueOptions.push(option);
|
|
442
|
-
}
|
|
443
|
-
} else {
|
|
444
|
-
valueSet.add(option.value);
|
|
445
|
-
uniqueOptions.push(option);
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
if (process.env.NODE_ENV === "development" && duplicates.length > 0) {
|
|
449
|
-
const action = deduplicateOptions ? "automatically removed" : "detected";
|
|
450
|
-
console.warn(
|
|
451
|
-
`MultiSelect: Duplicate option values ${action}: ${duplicates.join(", ")}. ${deduplicateOptions ? "Duplicates have been removed automatically." : "This may cause unexpected behavior. Consider setting 'deduplicateOptions={true}' or ensure all option values are unique."}`
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
return deduplicateOptions ? uniqueOptions : allOptions;
|
|
455
|
-
}, [options, deduplicateOptions, isGroupedOptions]);
|
|
456
|
-
const getOptionByValue = React5.useCallback(
|
|
457
|
-
(value) => {
|
|
458
|
-
const option = getAllOptions().find((option2) => option2.value === value);
|
|
459
|
-
if (!option && process.env.NODE_ENV === "development") {
|
|
460
|
-
console.warn(`MultiSelect: Option with value "${value}" not found in options list`);
|
|
461
|
-
}
|
|
462
|
-
return option;
|
|
463
|
-
},
|
|
464
|
-
[getAllOptions]
|
|
465
|
-
);
|
|
466
|
-
const filteredOptions = React5.useMemo(() => {
|
|
467
|
-
if (!searchable || !searchValue) return options;
|
|
468
|
-
if (options.length === 0) return [];
|
|
469
|
-
if (isGroupedOptions(options)) {
|
|
470
|
-
return options.map((group) => ({
|
|
471
|
-
...group,
|
|
472
|
-
options: group.options.filter(
|
|
473
|
-
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase())
|
|
474
|
-
)
|
|
475
|
-
})).filter((group) => group.options.length > 0);
|
|
476
|
-
}
|
|
477
|
-
return options.filter(
|
|
478
|
-
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase())
|
|
479
|
-
);
|
|
480
|
-
}, [options, searchValue, searchable, isGroupedOptions]);
|
|
481
|
-
const flatFilteredOptions = React5.useMemo(() => {
|
|
482
|
-
if (isGroupedOptions(filteredOptions)) {
|
|
483
|
-
return filteredOptions.flatMap((group) => group.options);
|
|
484
|
-
}
|
|
485
|
-
return filteredOptions;
|
|
486
|
-
}, [filteredOptions, isGroupedOptions]);
|
|
487
|
-
const toggleOption = React5.useCallback(
|
|
488
|
-
(optionValue) => {
|
|
489
|
-
if (disabled) return;
|
|
490
|
-
const option = getOptionByValue(optionValue);
|
|
491
|
-
if (option?.disabled) return;
|
|
492
|
-
const newSelectedValues = selectedValues.includes(optionValue) ? selectedValues.filter((value) => value !== optionValue) : [...selectedValues, optionValue];
|
|
493
|
-
setSelectedValues(newSelectedValues);
|
|
494
|
-
onValueChange(newSelectedValues);
|
|
495
|
-
if (closeOnSelect) {
|
|
496
|
-
setIsPopoverOpen(false);
|
|
497
|
-
}
|
|
498
|
-
},
|
|
499
|
-
[disabled, getOptionByValue, selectedValues, onValueChange, closeOnSelect]
|
|
500
|
-
);
|
|
501
|
-
const handleClear = () => {
|
|
502
|
-
if (disabled) return;
|
|
503
|
-
setSelectedValues([]);
|
|
504
|
-
onValueChange([]);
|
|
505
|
-
};
|
|
506
|
-
const handleTogglePopover = () => {
|
|
507
|
-
if (disabled) return;
|
|
508
|
-
setIsPopoverOpen((prev) => !prev);
|
|
509
|
-
};
|
|
510
|
-
const clearExtraOptions = () => {
|
|
511
|
-
if (disabled) return;
|
|
512
|
-
const newSelectedValues = selectedValues.slice(0, responsiveSettings.maxCount);
|
|
513
|
-
setSelectedValues(newSelectedValues);
|
|
514
|
-
onValueChange(newSelectedValues);
|
|
515
|
-
};
|
|
516
|
-
const handleKeyDown = React5.useCallback(
|
|
517
|
-
(event) => {
|
|
518
|
-
const optionsCount = flatFilteredOptions.length;
|
|
519
|
-
if (optionsCount === 0) return;
|
|
520
|
-
switch (event.key) {
|
|
521
|
-
case "ArrowDown":
|
|
522
|
-
event.preventDefault();
|
|
523
|
-
setHighlightedIndex((prev) => prev < optionsCount - 1 ? prev + 1 : 0);
|
|
524
|
-
break;
|
|
525
|
-
case "ArrowUp":
|
|
526
|
-
event.preventDefault();
|
|
527
|
-
setHighlightedIndex((prev) => prev > 0 ? prev - 1 : optionsCount - 1);
|
|
528
|
-
break;
|
|
529
|
-
case "Enter":
|
|
530
|
-
event.preventDefault();
|
|
531
|
-
if (highlightedIndex >= 0 && highlightedIndex < optionsCount) {
|
|
532
|
-
const option = flatFilteredOptions[highlightedIndex];
|
|
533
|
-
if (option && !option.disabled) {
|
|
534
|
-
toggleOption(option.value);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
break;
|
|
538
|
-
case "Escape":
|
|
539
|
-
event.preventDefault();
|
|
540
|
-
setIsPopoverOpen(false);
|
|
541
|
-
break;
|
|
542
|
-
case "Backspace":
|
|
543
|
-
if (!searchValue && selectedValues.length > 0) {
|
|
544
|
-
const newSelectedValues = [...selectedValues];
|
|
545
|
-
newSelectedValues.pop();
|
|
546
|
-
setSelectedValues(newSelectedValues);
|
|
547
|
-
onValueChange(newSelectedValues);
|
|
548
|
-
}
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
[flatFilteredOptions, highlightedIndex, toggleOption, searchValue, selectedValues, onValueChange]
|
|
553
|
-
);
|
|
554
|
-
React5.useEffect(() => {
|
|
555
|
-
if (!resetOnDefaultValueChange) return;
|
|
556
|
-
const prevDefaultValue = prevDefaultValueRef.current;
|
|
557
|
-
if (!arraysEqual(prevDefaultValue, defaultValue)) {
|
|
558
|
-
if (!arraysEqual(selectedValues, defaultValue)) {
|
|
559
|
-
setSelectedValues(defaultValue);
|
|
560
|
-
}
|
|
561
|
-
prevDefaultValueRef.current = [...defaultValue];
|
|
562
|
-
}
|
|
563
|
-
}, [defaultValue, selectedValues, arraysEqual, resetOnDefaultValueChange]);
|
|
564
|
-
const getWidthConstraints = () => {
|
|
565
|
-
const defaultMinWidth = screenSize === "mobile" ? "0px" : "200px";
|
|
566
|
-
const effectiveMinWidth = minWidth || defaultMinWidth;
|
|
567
|
-
const effectiveMaxWidth = maxWidth || "100%";
|
|
568
|
-
return {
|
|
569
|
-
minWidth: effectiveMinWidth,
|
|
570
|
-
maxWidth: effectiveMaxWidth,
|
|
571
|
-
width: autoSize ? "auto" : "100%"
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
const widthConstraints = getWidthConstraints();
|
|
575
|
-
const effectiveDropdownMaxHeight = React5.useMemo(() => {
|
|
576
|
-
if (dropdownMaxHeight) return dropdownMaxHeight;
|
|
577
|
-
return screenSize === "mobile" ? "70vh" : "60vh";
|
|
578
|
-
}, [dropdownMaxHeight, screenSize]);
|
|
579
|
-
React5.useEffect(() => {
|
|
580
|
-
if (!isPopoverOpen) {
|
|
581
|
-
setSearchValue("");
|
|
582
|
-
setHighlightedIndex(-1);
|
|
583
|
-
}
|
|
584
|
-
}, [isPopoverOpen]);
|
|
585
|
-
React5.useEffect(() => {
|
|
586
|
-
if (isPopoverOpen && searchable && searchInputRef.current) {
|
|
587
|
-
const timer = setTimeout(() => {
|
|
588
|
-
searchInputRef.current?.focus();
|
|
589
|
-
}, 0);
|
|
590
|
-
return () => clearTimeout(timer);
|
|
591
|
-
}
|
|
592
|
-
}, [isPopoverOpen, searchable]);
|
|
593
|
-
React5.useEffect(() => {
|
|
594
|
-
setHighlightedIndex(flatFilteredOptions.length > 0 ? 0 : -1);
|
|
595
|
-
}, [searchValue, flatFilteredOptions.length]);
|
|
596
|
-
const totalFilteredCount = React5.useMemo(() => {
|
|
597
|
-
if (isGroupedOptions(filteredOptions)) {
|
|
598
|
-
return filteredOptions.reduce((acc, group) => acc + group.options.length, 0);
|
|
599
|
-
}
|
|
600
|
-
return filteredOptions.length;
|
|
601
|
-
}, [filteredOptions, isGroupedOptions]);
|
|
602
|
-
let optionIndex = 0;
|
|
603
|
-
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Popover, { open: isPopoverOpen, onOpenChange: setIsPopoverOpen, children: [
|
|
604
|
-
/* @__PURE__ */ jsx("div", { id: triggerDescriptionId, className: "sr-only", children: "Multi-select dropdown. Use arrow keys to navigate, Enter to select, and Escape to close." }),
|
|
605
|
-
/* @__PURE__ */ jsx("div", { id: selectedCountId, className: "sr-only", "aria-live": "polite", children: selectedValues.length === 0 ? "No options selected" : `${selectedValues.length} option${selectedValues.length === 1 ? "" : "s"} selected: ${selectedValues.map((value) => getOptionByValue(value)?.label).filter(Boolean).join(", ")}` }),
|
|
606
|
-
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
607
|
-
"button",
|
|
608
|
-
{
|
|
609
|
-
ref: buttonRef,
|
|
610
|
-
type: "button",
|
|
611
|
-
...props,
|
|
612
|
-
onClick: (event) => {
|
|
613
|
-
if (disabled) return;
|
|
614
|
-
onClick?.(event);
|
|
615
|
-
handleTogglePopover();
|
|
616
|
-
},
|
|
617
|
-
disabled,
|
|
618
|
-
role: "combobox",
|
|
619
|
-
"aria-expanded": isPopoverOpen,
|
|
620
|
-
"aria-haspopup": "listbox",
|
|
621
|
-
"aria-controls": isPopoverOpen ? listboxId : void 0,
|
|
622
|
-
"aria-describedby": `${triggerDescriptionId} ${selectedCountId}`,
|
|
623
|
-
"aria-label": `Multi-select: ${selectedValues.length} of ${getAllOptions().length} options selected. ${placeholder}`,
|
|
624
|
-
className: cn(
|
|
625
|
-
`border-input/70 focus-visible:border-primary/60 focus-visible:ring-primary/20 flex items-center
|
|
626
|
-
justify-between rounded-md border bg-transparent pr-1 pl-2 shadow-xs transition-[color,box-shadow]
|
|
627
|
-
outline-none focus-visible:ring-[3px] active:scale-100 disabled:pointer-events-none disabled:opacity-50`,
|
|
628
|
-
singleLine ? "h-8 min-h-8 py-0.5 text-xs" : "h-auto min-h-10 py-2 text-sm",
|
|
629
|
-
autoSize && "w-auto",
|
|
630
|
-
!autoSize && "w-full",
|
|
631
|
-
responsiveSettings.compactMode && "min-h-9 py-1.5 text-xs",
|
|
632
|
-
className
|
|
633
|
-
),
|
|
634
|
-
style: {
|
|
635
|
-
minWidth: widthConstraints.minWidth,
|
|
636
|
-
maxWidth: widthConstraints.maxWidth,
|
|
637
|
-
width: widthConstraints.width
|
|
638
|
-
},
|
|
639
|
-
children: selectedValues.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between", children: [
|
|
640
|
-
/* @__PURE__ */ jsxs(
|
|
641
|
-
"div",
|
|
642
|
-
{
|
|
643
|
-
className: cn(
|
|
644
|
-
"flex items-center gap-1",
|
|
645
|
-
singleLine ? "multiselect-singleline-scroll overflow-x-auto" : "flex-wrap",
|
|
646
|
-
responsiveSettings.compactMode && "gap-0.5"
|
|
647
|
-
),
|
|
648
|
-
children: [
|
|
649
|
-
selectedValues.slice(0, responsiveSettings.maxCount).map((value) => {
|
|
650
|
-
const option = getOptionByValue(value);
|
|
651
|
-
const IconComponent = option?.icon;
|
|
652
|
-
const customStyle = option?.style;
|
|
653
|
-
if (!option) {
|
|
654
|
-
return null;
|
|
655
|
-
}
|
|
656
|
-
const badgeStyle = {
|
|
657
|
-
...customStyle?.badgeColor && {
|
|
658
|
-
backgroundColor: customStyle.badgeColor
|
|
659
|
-
},
|
|
660
|
-
...customStyle?.gradient && {
|
|
661
|
-
background: customStyle.gradient,
|
|
662
|
-
color: "white"
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
return /* @__PURE__ */ jsxs(
|
|
666
|
-
Badge,
|
|
667
|
-
{
|
|
668
|
-
className: cn(
|
|
669
|
-
multiSelectVariants({ variant }),
|
|
670
|
-
customStyle?.gradient && "border-transparent text-white",
|
|
671
|
-
responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs",
|
|
672
|
-
singleLine && "py-0.5",
|
|
673
|
-
screenSize === "mobile" && "max-w-[120px] truncate",
|
|
674
|
-
singleLine && "flex-shrink-0 whitespace-nowrap",
|
|
675
|
-
"[&>svg]:pointer-events-auto"
|
|
676
|
-
),
|
|
677
|
-
style: badgeStyle,
|
|
678
|
-
children: [
|
|
679
|
-
IconComponent && !responsiveSettings.hideIcons && /* @__PURE__ */ jsx(
|
|
680
|
-
IconComponent,
|
|
681
|
-
{
|
|
682
|
-
className: cn(
|
|
683
|
-
"mr-2 h-4 w-4",
|
|
684
|
-
responsiveSettings.compactMode && "mr-1 h-3 w-3",
|
|
685
|
-
customStyle?.iconColor && "text-current"
|
|
686
|
-
),
|
|
687
|
-
...customStyle?.iconColor && {
|
|
688
|
-
style: { color: customStyle.iconColor }
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
),
|
|
692
|
-
/* @__PURE__ */ jsx("span", { className: cn(screenSize === "mobile" && "truncate"), children: option.label }),
|
|
693
|
-
/* @__PURE__ */ jsx(
|
|
694
|
-
"div",
|
|
695
|
-
{
|
|
696
|
-
role: "button",
|
|
697
|
-
tabIndex: 0,
|
|
698
|
-
onClick: (event) => {
|
|
699
|
-
event.stopPropagation();
|
|
700
|
-
toggleOption(value);
|
|
701
|
-
},
|
|
702
|
-
onKeyDown: (event) => {
|
|
703
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
704
|
-
event.preventDefault();
|
|
705
|
-
event.stopPropagation();
|
|
706
|
-
toggleOption(value);
|
|
707
|
-
}
|
|
708
|
-
},
|
|
709
|
-
"aria-label": `Remove ${option.label} from selection`,
|
|
710
|
-
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1 focus:ring-white/50 focus:outline-none",
|
|
711
|
-
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
712
|
-
}
|
|
713
|
-
)
|
|
714
|
-
]
|
|
715
|
-
},
|
|
716
|
-
value
|
|
717
|
-
);
|
|
718
|
-
}).filter(Boolean),
|
|
719
|
-
selectedValues.length > responsiveSettings.maxCount && /* @__PURE__ */ jsxs(
|
|
720
|
-
Badge,
|
|
721
|
-
{
|
|
722
|
-
className: cn(
|
|
723
|
-
"text-foreground border-foreground/10 bg-transparent",
|
|
724
|
-
multiSelectVariants({ variant }),
|
|
725
|
-
responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs",
|
|
726
|
-
singleLine && "flex-shrink-0 whitespace-nowrap",
|
|
727
|
-
"[&>svg]:pointer-events-auto"
|
|
728
|
-
),
|
|
729
|
-
children: [
|
|
730
|
-
`+ ${selectedValues.length - responsiveSettings.maxCount} more`,
|
|
731
|
-
/* @__PURE__ */ jsx(
|
|
732
|
-
"div",
|
|
733
|
-
{
|
|
734
|
-
role: "button",
|
|
735
|
-
tabIndex: 0,
|
|
736
|
-
onClick: (event) => {
|
|
737
|
-
event.stopPropagation();
|
|
738
|
-
clearExtraOptions();
|
|
739
|
-
},
|
|
740
|
-
onKeyDown: (event) => {
|
|
741
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
742
|
-
event.preventDefault();
|
|
743
|
-
event.stopPropagation();
|
|
744
|
-
clearExtraOptions();
|
|
745
|
-
}
|
|
746
|
-
},
|
|
747
|
-
"aria-label": "Clear extra selected options",
|
|
748
|
-
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1\n focus:ring-white/50 focus:outline-none",
|
|
749
|
-
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
750
|
-
}
|
|
751
|
-
)
|
|
752
|
-
]
|
|
753
|
-
}
|
|
754
|
-
)
|
|
755
|
-
]
|
|
756
|
-
}
|
|
757
|
-
),
|
|
758
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
759
|
-
/* @__PURE__ */ jsx(
|
|
760
|
-
"div",
|
|
761
|
-
{
|
|
762
|
-
role: "button",
|
|
763
|
-
tabIndex: 0,
|
|
764
|
-
onClick: (event) => {
|
|
765
|
-
event.stopPropagation();
|
|
766
|
-
handleClear();
|
|
767
|
-
},
|
|
768
|
-
onKeyDown: (event) => {
|
|
769
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
770
|
-
event.preventDefault();
|
|
771
|
-
event.stopPropagation();
|
|
772
|
-
handleClear();
|
|
773
|
-
}
|
|
774
|
-
},
|
|
775
|
-
"aria-label": `Clear all ${selectedValues.length} selected options`,
|
|
776
|
-
className: "text-muted-foreground hover:text-foreground focus:ring-ring mx-2 flex h-4 w-4\n cursor-pointer items-center justify-center rounded-sm focus:ring-2 focus:ring-offset-1\n focus:outline-none",
|
|
777
|
-
children: /* @__PURE__ */ jsx(XIcon, { className: "h-4 w-4" })
|
|
778
|
-
}
|
|
779
|
-
),
|
|
780
|
-
/* @__PURE__ */ jsx(Separator, { orientation: "vertical", className: "flex h-full min-h-6" }),
|
|
781
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })
|
|
782
|
-
] })
|
|
783
|
-
] }) : /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full items-center justify-between", children: [
|
|
784
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground mx-1 text-sm", children: placeholder }),
|
|
785
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })
|
|
786
|
-
] })
|
|
787
|
-
}
|
|
788
|
-
) }),
|
|
789
|
-
/* @__PURE__ */ jsx(
|
|
790
|
-
PopoverContent,
|
|
791
|
-
{
|
|
792
|
-
id: listboxId,
|
|
793
|
-
"aria-label": "Available options",
|
|
794
|
-
className: cn("w-(--anchor-width) overflow-hidden p-0", popoverClassName),
|
|
795
|
-
style: {
|
|
796
|
-
minWidth: widthConstraints.minWidth,
|
|
797
|
-
maxWidth: widthConstraints.maxWidth,
|
|
798
|
-
width: widthConstraints.width === "auto" ? "auto" : void 0,
|
|
799
|
-
maxHeight: effectiveDropdownMaxHeight,
|
|
800
|
-
touchAction: "manipulation"
|
|
801
|
-
},
|
|
802
|
-
align: "start",
|
|
803
|
-
onEscapeKeyDown: () => setIsPopoverOpen(false),
|
|
804
|
-
children: /* @__PURE__ */ jsxs("div", { className: "flex h-full max-h-[inherit] flex-col", onKeyDown: handleKeyDown, children: [
|
|
805
|
-
searchable && /* @__PURE__ */ jsxs("div", { className: "flex items-center border-b px-3", children: [
|
|
806
|
-
/* @__PURE__ */ jsx(SearchIcon, { className: "text-muted-foreground mr-2 h-4 w-4 shrink-0 opacity-50" }),
|
|
807
|
-
/* @__PURE__ */ jsx(
|
|
808
|
-
"input",
|
|
809
|
-
{
|
|
810
|
-
ref: searchInputRef,
|
|
811
|
-
id: searchInputId,
|
|
812
|
-
type: "text",
|
|
813
|
-
placeholder: "Search options...",
|
|
814
|
-
value: searchValue,
|
|
815
|
-
onChange: (e) => setSearchValue(e.target.value),
|
|
816
|
-
"aria-label": "Search through available options",
|
|
817
|
-
className: "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
818
|
-
}
|
|
819
|
-
)
|
|
820
|
-
] }),
|
|
821
|
-
/* @__PURE__ */ jsx(
|
|
822
|
-
"div",
|
|
823
|
-
{
|
|
824
|
-
ref: listRef,
|
|
825
|
-
role: "listbox",
|
|
826
|
-
"aria-multiselectable": "true",
|
|
827
|
-
className: "multiselect-scrollbar scrollbar-neutral-thin overscroll-contain min-h-0 flex-1 overflow-y-auto p-1",
|
|
828
|
-
children: totalFilteredCount === 0 ? /* @__PURE__ */ jsx("div", { className: "text-muted-foreground py-6 text-center text-sm", children: emptyIndicator || "No results found." }) : isGroupedOptions(filteredOptions) ? filteredOptions.map((group) => /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": `group-${group.heading}`, children: [
|
|
829
|
-
/* @__PURE__ */ jsx(
|
|
830
|
-
"div",
|
|
831
|
-
{
|
|
832
|
-
id: `group-${group.heading}`,
|
|
833
|
-
className: "text-muted-foreground px-2 py-1.5 text-xs font-medium",
|
|
834
|
-
children: group.heading
|
|
835
|
-
}
|
|
836
|
-
),
|
|
837
|
-
group.options.map((option) => {
|
|
838
|
-
const currentIndex = optionIndex++;
|
|
839
|
-
const isSelected = selectedValues.includes(option.value);
|
|
840
|
-
return /* @__PURE__ */ jsx(
|
|
841
|
-
OptionItem,
|
|
842
|
-
{
|
|
843
|
-
option,
|
|
844
|
-
isSelected,
|
|
845
|
-
onSelect: () => toggleOption(option.value),
|
|
846
|
-
highlightedIndex,
|
|
847
|
-
index: currentIndex,
|
|
848
|
-
setHighlightedIndex
|
|
849
|
-
},
|
|
850
|
-
option.value
|
|
851
|
-
);
|
|
852
|
-
})
|
|
853
|
-
] }, group.heading)) : filteredOptions.map((option) => {
|
|
854
|
-
const currentIndex = optionIndex++;
|
|
855
|
-
const isSelected = selectedValues.includes(option.value);
|
|
856
|
-
return /* @__PURE__ */ jsx(
|
|
857
|
-
OptionItem,
|
|
858
|
-
{
|
|
859
|
-
option,
|
|
860
|
-
isSelected,
|
|
861
|
-
onSelect: () => toggleOption(option.value),
|
|
862
|
-
highlightedIndex,
|
|
863
|
-
index: currentIndex,
|
|
864
|
-
setHighlightedIndex
|
|
865
|
-
},
|
|
866
|
-
option.value
|
|
867
|
-
);
|
|
868
|
-
})
|
|
869
|
-
}
|
|
870
|
-
),
|
|
871
|
-
footerContent && /* @__PURE__ */ jsx("div", { className: "border-t p-1", children: footerContent })
|
|
872
|
-
] })
|
|
873
|
-
}
|
|
874
|
-
)
|
|
875
|
-
] }) });
|
|
876
|
-
}
|
|
877
|
-
);
|
|
878
566
|
MultiSelect.displayName = "MultiSelect";
|
|
879
567
|
|
|
568
|
+
//#endregion
|
|
880
569
|
export { MultiSelect };
|
|
881
|
-
//# sourceMappingURL=multi-select.js.map
|
|
882
570
|
//# sourceMappingURL=multi-select.js.map
|