@jesusgm/react-components 0.0.0-stage → 0.1.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 +158 -0
- package/dist/components/atoms/avatar/index.d.ts +19 -0
- package/dist/components/atoms/avatar/index.js +44 -0
- package/dist/components/atoms/avatar/index.js.map +1 -0
- package/dist/components/atoms/avatar/styles.css +50 -0
- package/dist/components/atoms/badge/index.d.ts +17 -0
- package/dist/components/atoms/badge/index.js +37 -0
- package/dist/components/atoms/badge/index.js.map +1 -0
- package/dist/components/atoms/badge/styles.css +83 -0
- package/dist/components/atoms/button/index.d.ts +16 -0
- package/dist/components/atoms/button/index.js +22 -0
- package/dist/components/atoms/button/index.js.map +1 -0
- package/dist/components/atoms/button/styles.css +77 -0
- package/dist/components/atoms/checkbox/index.d.ts +13 -0
- package/dist/components/atoms/checkbox/index.js +63 -0
- package/dist/components/atoms/checkbox/index.js.map +1 -0
- package/dist/components/atoms/checkbox/styles.css +87 -0
- package/dist/components/atoms/code-highlighter/index.d.ts +8 -0
- package/dist/components/atoms/code-highlighter/index.js +24 -0
- package/dist/components/atoms/code-highlighter/index.js.map +1 -0
- package/dist/components/atoms/code-highlighter/railscasts.css +1 -0
- package/dist/components/atoms/code-highlighter/styles.css +17 -0
- package/dist/components/atoms/divider/index.d.ts +10 -0
- package/dist/components/atoms/divider/index.js +25 -0
- package/dist/components/atoms/divider/index.js.map +1 -0
- package/dist/components/atoms/divider/styles.css +56 -0
- package/dist/components/atoms/icon/index.d.ts +23 -0
- package/dist/components/atoms/icon/index.js +20 -0
- package/dist/components/atoms/icon/index.js.map +1 -0
- package/dist/components/atoms/icon/styles.css +13 -0
- package/dist/components/atoms/kbd/index.d.ts +7 -0
- package/dist/components/atoms/kbd/index.js +26 -0
- package/dist/components/atoms/kbd/index.js.map +1 -0
- package/dist/components/atoms/kbd/styles.css +29 -0
- package/dist/components/atoms/label/index.d.ts +9 -0
- package/dist/components/atoms/label/index.js +18 -0
- package/dist/components/atoms/label/index.js.map +1 -0
- package/dist/components/atoms/label/styles.css +19 -0
- package/dist/components/atoms/link/index.d.ts +12 -0
- package/dist/components/atoms/link/index.js +32 -0
- package/dist/components/atoms/link/index.js.map +1 -0
- package/dist/components/atoms/link/styles.css +54 -0
- package/dist/components/atoms/progress-bar/index.d.ts +23 -0
- package/dist/components/atoms/progress-bar/index.js +45 -0
- package/dist/components/atoms/progress-bar/index.js.map +1 -0
- package/dist/components/atoms/progress-bar/styles.css +75 -0
- package/dist/components/atoms/radio/context.d.ts +9 -0
- package/dist/components/atoms/radio/context.js +9 -0
- package/dist/components/atoms/radio/context.js.map +1 -0
- package/dist/components/atoms/radio/index.d.ts +15 -0
- package/dist/components/atoms/radio/index.js +44 -0
- package/dist/components/atoms/radio/index.js.map +1 -0
- package/dist/components/atoms/radio/radio-group.d.ts +25 -0
- package/dist/components/atoms/radio/radio-group.js +49 -0
- package/dist/components/atoms/radio/radio-group.js.map +1 -0
- package/dist/components/atoms/radio/styles.css +110 -0
- package/dist/components/atoms/skeleton/index.d.ts +15 -0
- package/dist/components/atoms/skeleton/index.js +38 -0
- package/dist/components/atoms/skeleton/index.js.map +1 -0
- package/dist/components/atoms/skeleton/styles.css +57 -0
- package/dist/components/atoms/spinner/index.d.ts +11 -0
- package/dist/components/atoms/spinner/index.js +22 -0
- package/dist/components/atoms/spinner/index.js.map +1 -0
- package/dist/components/atoms/spinner/styles.css +51 -0
- package/dist/components/atoms/switch/index.d.ts +14 -0
- package/dist/components/atoms/switch/index.js +33 -0
- package/dist/components/atoms/switch/index.js.map +1 -0
- package/dist/components/atoms/switch/styles.css +99 -0
- package/dist/components/atoms/text-input/index.d.ts +20 -0
- package/dist/components/atoms/text-input/index.js +33 -0
- package/dist/components/atoms/text-input/index.js.map +1 -0
- package/dist/components/atoms/text-input/styles.css +80 -0
- package/dist/components/atoms/textarea/index.d.ts +14 -0
- package/dist/components/atoms/textarea/index.js +43 -0
- package/dist/components/atoms/textarea/index.js.map +1 -0
- package/dist/components/atoms/textarea/styles.css +49 -0
- package/dist/components/atoms/typography/index.d.ts +30 -0
- package/dist/components/atoms/typography/index.js +30 -0
- package/dist/components/atoms/typography/index.js.map +1 -0
- package/dist/components/atoms/typography/styles.css +50 -0
- package/dist/components/atoms/video-player/index.d.ts +9 -0
- package/dist/components/atoms/video-player/index.js +17 -0
- package/dist/components/atoms/video-player/index.js.map +1 -0
- package/dist/components/atoms/video-player/styles.css +18 -0
- package/dist/components/atoms/visually-hidden/index.d.ts +7 -0
- package/dist/components/atoms/visually-hidden/index.js +13 -0
- package/dist/components/atoms/visually-hidden/index.js.map +1 -0
- package/dist/components/atoms/visually-hidden/styles.css +12 -0
- package/dist/components/hooks/index.d.ts +3 -0
- package/dist/components/hooks/index.js +4 -0
- package/dist/components/hooks/use-click-outside.d.ts +6 -0
- package/dist/components/hooks/use-click-outside.js +30 -0
- package/dist/components/hooks/use-click-outside.js.map +1 -0
- package/dist/components/hooks/use-controllable-state.d.ts +5 -0
- package/dist/components/hooks/use-controllable-state.js +22 -0
- package/dist/components/hooks/use-controllable-state.js.map +1 -0
- package/dist/components/hooks/use-focus-trap.d.ts +8 -0
- package/dist/components/hooks/use-focus-trap.js +57 -0
- package/dist/components/hooks/use-focus-trap.js.map +1 -0
- package/dist/components/index.d.ts +122 -0
- package/dist/components/index.js +74 -0
- package/dist/components/molecules/accordion/index.d.ts +27 -0
- package/dist/components/molecules/accordion/index.js +98 -0
- package/dist/components/molecules/accordion/index.js.map +1 -0
- package/dist/components/molecules/accordion/styles.css +75 -0
- package/dist/components/molecules/alert/index.d.ts +18 -0
- package/dist/components/molecules/alert/index.js +91 -0
- package/dist/components/molecules/alert/index.js.map +1 -0
- package/dist/components/molecules/alert/styles.css +97 -0
- package/dist/components/molecules/binary-clock/index.d.ts +16 -0
- package/dist/components/molecules/binary-clock/index.js +66 -0
- package/dist/components/molecules/binary-clock/index.js.map +1 -0
- package/dist/components/molecules/binary-clock/styles.css +46 -0
- package/dist/components/molecules/breadcrumb/index.d.ts +23 -0
- package/dist/components/molecules/breadcrumb/index.js +79 -0
- package/dist/components/molecules/breadcrumb/index.js.map +1 -0
- package/dist/components/molecules/breadcrumb/styles.css +61 -0
- package/dist/components/molecules/card/index.d.ts +39 -0
- package/dist/components/molecules/card/index.js +60 -0
- package/dist/components/molecules/card/index.js.map +1 -0
- package/dist/components/molecules/card/styles.css +105 -0
- package/dist/components/molecules/chart/index.d.ts +14 -0
- package/dist/components/molecules/chart/index.js +104 -0
- package/dist/components/molecules/chart/index.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.d.ts +8 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.js +58 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/components/styles.css +64 -0
- package/dist/components/molecules/conflict-resolver/index.d.ts +10 -0
- package/dist/components/molecules/conflict-resolver/index.js +35 -0
- package/dist/components/molecules/conflict-resolver/index.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/types.d.ts +10 -0
- package/dist/components/molecules/dropable-list/draggable.d.ts +9 -0
- package/dist/components/molecules/dropable-list/draggable.js +18 -0
- package/dist/components/molecules/dropable-list/draggable.js.map +1 -0
- package/dist/components/molecules/dropable-list/index.d.ts +20 -0
- package/dist/components/molecules/dropable-list/index.js +52 -0
- package/dist/components/molecules/dropable-list/index.js.map +1 -0
- package/dist/components/molecules/dropable-list/styles.css +63 -0
- package/dist/components/molecules/dropdown-menu/index.d.ts +43 -0
- package/dist/components/molecules/dropdown-menu/index.js +226 -0
- package/dist/components/molecules/dropdown-menu/index.js.map +1 -0
- package/dist/components/molecules/dropdown-menu/styles.css +94 -0
- package/dist/components/molecules/empty-state/index.d.ts +16 -0
- package/dist/components/molecules/empty-state/index.js +32 -0
- package/dist/components/molecules/empty-state/index.js.map +1 -0
- package/dist/components/molecules/empty-state/styles.css +64 -0
- package/dist/components/molecules/file-input/index.d.ts +39 -0
- package/dist/components/molecules/file-input/index.js +121 -0
- package/dist/components/molecules/file-input/index.js.map +1 -0
- package/dist/components/molecules/file-input/styles.css +86 -0
- package/dist/components/molecules/form-field/index.d.ts +38 -0
- package/dist/components/molecules/form-field/index.js +71 -0
- package/dist/components/molecules/form-field/index.js.map +1 -0
- package/dist/components/molecules/form-field/styles.css +43 -0
- package/dist/components/molecules/list/index.d.ts +25 -0
- package/dist/components/molecules/list/index.js +30 -0
- package/dist/components/molecules/list/index.js.map +1 -0
- package/dist/components/molecules/list/styles.css +28 -0
- package/dist/components/molecules/number-stepper/index.d.ts +31 -0
- package/dist/components/molecules/number-stepper/index.js +163 -0
- package/dist/components/molecules/number-stepper/index.js.map +1 -0
- package/dist/components/molecules/number-stepper/styles.css +69 -0
- package/dist/components/molecules/pagination/index.d.ts +39 -0
- package/dist/components/molecules/pagination/index.js +111 -0
- package/dist/components/molecules/pagination/index.js.map +1 -0
- package/dist/components/molecules/pagination/styles.css +41 -0
- package/dist/components/molecules/popover/index.d.ts +22 -0
- package/dist/components/molecules/popover/index.js +76 -0
- package/dist/components/molecules/popover/index.js.map +1 -0
- package/dist/components/molecules/popover/positioning.d.ts +40 -0
- package/dist/components/molecules/popover/positioning.js +115 -0
- package/dist/components/molecules/popover/positioning.js.map +1 -0
- package/dist/components/molecules/popover/styles.css +36 -0
- package/dist/components/molecules/rating/index.d.ts +33 -0
- package/dist/components/molecules/rating/index.js +117 -0
- package/dist/components/molecules/rating/index.js.map +1 -0
- package/dist/components/molecules/rating/styles.css +94 -0
- package/dist/components/molecules/search-input/index.d.ts +23 -0
- package/dist/components/molecules/search-input/index.js +118 -0
- package/dist/components/molecules/search-input/index.js.map +1 -0
- package/dist/components/molecules/search-input/styles.css +69 -0
- package/dist/components/molecules/segmented-control/button-group.d.ts +10 -0
- package/dist/components/molecules/segmented-control/button-group.js +15 -0
- package/dist/components/molecules/segmented-control/button-group.js.map +1 -0
- package/dist/components/molecules/segmented-control/index.d.ts +38 -0
- package/dist/components/molecules/segmented-control/index.js +80 -0
- package/dist/components/molecules/segmented-control/index.js.map +1 -0
- package/dist/components/molecules/segmented-control/styles.css +130 -0
- package/dist/components/molecules/select/index.d.ts +30 -0
- package/dist/components/molecules/select/index.js +48 -0
- package/dist/components/molecules/select/index.js.map +1 -0
- package/dist/components/molecules/select/styles.css +102 -0
- package/dist/components/molecules/tabs/index.d.ts +31 -0
- package/dist/components/molecules/tabs/index.js +87 -0
- package/dist/components/molecules/tabs/index.js.map +1 -0
- package/dist/components/molecules/tabs/styles.css +87 -0
- package/dist/components/molecules/tag-cloud/index.d.ts +16 -0
- package/dist/components/molecules/tag-cloud/index.js +133 -0
- package/dist/components/molecules/tag-cloud/index.js.map +1 -0
- package/dist/components/molecules/tag-cloud/styles.css +29 -0
- package/dist/components/molecules/tooltip/index.d.ts +22 -0
- package/dist/components/molecules/tooltip/index.js +83 -0
- package/dist/components/molecules/tooltip/index.js.map +1 -0
- package/dist/components/molecules/tooltip/styles.css +30 -0
- package/dist/components/molecules/virtualized-list/index.d.ts +5 -0
- package/dist/components/molecules/virtualized-list/index.js +3 -0
- package/dist/components/molecules/virtualized-list/lista/index.d.ts +11 -0
- package/dist/components/molecules/virtualized-list/lista/index.js +30 -0
- package/dist/components/molecules/virtualized-list/lista/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/lista/styles.css +27 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.d.ts +10 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.js +17 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/row/index.d.ts +9 -0
- package/dist/components/molecules/virtualized-list/row/index.js +30 -0
- package/dist/components/molecules/virtualized-list/row/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/types.d.ts +4 -0
- package/dist/components/organisms/combobox/index.d.ts +82 -0
- package/dist/components/organisms/combobox/index.js +386 -0
- package/dist/components/organisms/combobox/index.js.map +1 -0
- package/dist/components/organisms/combobox/styles.css +269 -0
- package/dist/components/organisms/command-palette/index.d.ts +49 -0
- package/dist/components/organisms/command-palette/index.js +239 -0
- package/dist/components/organisms/command-palette/index.js.map +1 -0
- package/dist/components/organisms/command-palette/score.d.ts +12 -0
- package/dist/components/organisms/command-palette/score.js +43 -0
- package/dist/components/organisms/command-palette/score.js.map +1 -0
- package/dist/components/organisms/command-palette/styles.css +212 -0
- package/dist/components/organisms/date-picker/calendar.d.ts +29 -0
- package/dist/components/organisms/date-picker/calendar.js +178 -0
- package/dist/components/organisms/date-picker/calendar.js.map +1 -0
- package/dist/components/organisms/date-picker/date-utils.d.ts +52 -0
- package/dist/components/organisms/date-picker/date-utils.js +139 -0
- package/dist/components/organisms/date-picker/date-utils.js.map +1 -0
- package/dist/components/organisms/date-picker/index.d.ts +54 -0
- package/dist/components/organisms/date-picker/index.js +173 -0
- package/dist/components/organisms/date-picker/index.js.map +1 -0
- package/dist/components/organisms/date-picker/styles.css +179 -0
- package/dist/components/organisms/drawer/index.d.ts +16 -0
- package/dist/components/organisms/drawer/index.js +15 -0
- package/dist/components/organisms/drawer/index.js.map +1 -0
- package/dist/components/organisms/drawer/styles.css +163 -0
- package/dist/components/organisms/editor/index.d.ts +13 -0
- package/dist/components/organisms/editor/index.js +56 -0
- package/dist/components/organisms/editor/index.js.map +1 -0
- package/dist/components/organisms/editor/styles.css +61 -0
- package/dist/components/organisms/form/context.d.ts +7 -0
- package/dist/components/organisms/form/context.js +11 -0
- package/dist/components/organisms/form/context.js.map +1 -0
- package/dist/components/organisms/form/field.d.ts +18 -0
- package/dist/components/organisms/form/field.js +98 -0
- package/dist/components/organisms/form/field.js.map +1 -0
- package/dist/components/organisms/form/form-actions.d.ts +8 -0
- package/dist/components/organisms/form/form-actions.js +13 -0
- package/dist/components/organisms/form/form-actions.js.map +1 -0
- package/dist/components/organisms/form/index.d.ts +24 -0
- package/dist/components/organisms/form/index.js +215 -0
- package/dist/components/organisms/form/index.js.map +1 -0
- package/dist/components/organisms/form/styles.css +29 -0
- package/dist/components/organisms/form/types.d.ts +95 -0
- package/dist/components/organisms/form/validation.d.ts +5 -0
- package/dist/components/organisms/form/validation.js +35 -0
- package/dist/components/organisms/form/validation.js.map +1 -0
- package/dist/components/organisms/header/index.d.ts +40 -0
- package/dist/components/organisms/header/index.js +186 -0
- package/dist/components/organisms/header/index.js.map +1 -0
- package/dist/components/organisms/header/styles.css +126 -0
- package/dist/components/organisms/modal/dialog-base.d.ts +31 -0
- package/dist/components/organisms/modal/dialog-base.js +123 -0
- package/dist/components/organisms/modal/dialog-base.js.map +1 -0
- package/dist/components/organisms/modal/index.d.ts +13 -0
- package/dist/components/organisms/modal/index.js +15 -0
- package/dist/components/organisms/modal/index.js.map +1 -0
- package/dist/components/organisms/modal/styles.css +143 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.d.ts +13 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.js +16 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.js.map +1 -0
- package/dist/components/organisms/presenter/components/slides/simple/styles.css +6 -0
- package/dist/components/organisms/presenter/index.d.ts +17 -0
- package/dist/components/organisms/presenter/index.js +63 -0
- package/dist/components/organisms/presenter/index.js.map +1 -0
- package/dist/components/organisms/presenter/styles.css +75 -0
- package/dist/components/organisms/sidebar/index.d.ts +50 -0
- package/dist/components/organisms/sidebar/index.js +157 -0
- package/dist/components/organisms/sidebar/index.js.map +1 -0
- package/dist/components/organisms/sidebar/styles.css +197 -0
- package/dist/components/organisms/slider/index.d.ts +47 -0
- package/dist/components/organisms/slider/index.js +214 -0
- package/dist/components/organisms/slider/index.js.map +1 -0
- package/dist/components/organisms/slider/styles.css +110 -0
- package/dist/components/organisms/table/components/cell/index.d.ts +8 -0
- package/dist/components/organisms/table/components/cell/index.js +11 -0
- package/dist/components/organisms/table/components/cell/index.js.map +1 -0
- package/dist/components/organisms/table/index.d.ts +29 -0
- package/dist/components/organisms/table/index.js +105 -0
- package/dist/components/organisms/table/index.js.map +1 -0
- package/dist/components/organisms/table/styles.css +66 -0
- package/dist/components/organisms/terminal/index.d.ts +15 -0
- package/dist/components/organisms/terminal/index.js +111 -0
- package/dist/components/organisms/terminal/index.js.map +1 -0
- package/dist/components/organisms/terminal/styles.css +123 -0
- package/dist/components/organisms/toast/index.d.ts +66 -0
- package/dist/components/organisms/toast/index.js +142 -0
- package/dist/components/organisms/toast/index.js.map +1 -0
- package/dist/components/organisms/toast/styles.css +138 -0
- package/dist/components/organisms/wizard/index.d.ts +44 -0
- package/dist/components/organisms/wizard/index.js +171 -0
- package/dist/components/organisms/wizard/index.js.map +1 -0
- package/dist/components/organisms/wizard/styles.css +160 -0
- package/dist/components/utils/cx.d.ts +2 -0
- package/dist/components/utils/cx.js +8 -0
- package/dist/components/utils/cx.js.map +1 -0
- package/dist/components/utils/portal/index.d.ts +9 -0
- package/dist/components/utils/portal/index.js +13 -0
- package/dist/components/utils/portal/index.js.map +1 -0
- package/dist/components/utils/theme-provider/index.d.ts +22 -0
- package/dist/components/utils/theme-provider/index.js +36 -0
- package/dist/components/utils/theme-provider/index.js.map +1 -0
- package/dist/styles.css +743 -0
- package/dist/tokens.css +299 -0
- package/package.json +390 -4
- package/README.md +0 -3
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
.ds-combobox {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: var(--space-1);
|
|
6
|
+
min-width: 200px;
|
|
7
|
+
min-height: var(--control-height-md);
|
|
8
|
+
padding: 0 var(--space-1) 0 var(--control-padding-x-md);
|
|
9
|
+
border: var(--border-width-1) solid var(--color-border-strong);
|
|
10
|
+
border-radius: var(--radius-md);
|
|
11
|
+
background: var(--color-surface);
|
|
12
|
+
color: var(--color-text);
|
|
13
|
+
font-family: var(--font-sans);
|
|
14
|
+
font-size: var(--font-size-sm);
|
|
15
|
+
transition: border-color var(--duration-fast) var(--easing-standard);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.ds-combobox:hover:not(.ds-combobox--disabled) {
|
|
19
|
+
border-color: var(--color-text-subtle);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ds-combobox:focus-within {
|
|
23
|
+
outline: var(--border-width-2) solid var(--color-focus-ring);
|
|
24
|
+
outline-offset: 2px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ds-combobox--multiple {
|
|
28
|
+
padding-top: var(--space-1);
|
|
29
|
+
padding-bottom: var(--space-1);
|
|
30
|
+
padding-left: var(--space-1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.ds-combobox--sm {
|
|
34
|
+
min-height: var(--control-height-sm);
|
|
35
|
+
padding-left: var(--control-padding-x-sm);
|
|
36
|
+
font-size: var(--font-size-xs);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.ds-combobox--lg {
|
|
40
|
+
min-height: var(--control-height-lg);
|
|
41
|
+
padding-left: var(--control-padding-x-lg);
|
|
42
|
+
font-size: var(--font-size-md);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.ds-combobox--multiple.ds-combobox--sm,
|
|
46
|
+
.ds-combobox--multiple.ds-combobox--lg {
|
|
47
|
+
padding-left: var(--space-1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.ds-combobox--full {
|
|
51
|
+
display: flex;
|
|
52
|
+
width: 100%;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ds-combobox--invalid,
|
|
56
|
+
.ds-combobox--invalid:hover:not(.ds-combobox--disabled) {
|
|
57
|
+
border-color: var(--color-danger);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.ds-combobox--disabled {
|
|
61
|
+
background: var(--color-bg-subtle);
|
|
62
|
+
color: var(--color-text-disabled);
|
|
63
|
+
cursor: not-allowed;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.ds-combobox__input {
|
|
67
|
+
flex: 1;
|
|
68
|
+
min-width: 80px;
|
|
69
|
+
height: calc(var(--control-height-md) - 2 * var(--border-width-1));
|
|
70
|
+
padding: 0;
|
|
71
|
+
border: 0;
|
|
72
|
+
background: transparent;
|
|
73
|
+
color: inherit;
|
|
74
|
+
font: inherit;
|
|
75
|
+
outline: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ds-combobox--multiple .ds-combobox__input {
|
|
79
|
+
height: auto;
|
|
80
|
+
min-height: var(--control-height-sm);
|
|
81
|
+
padding-left: var(--space-1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.ds-combobox--sm .ds-combobox__input {
|
|
85
|
+
height: calc(var(--control-height-sm) - 2 * var(--border-width-1));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.ds-combobox--lg .ds-combobox__input {
|
|
89
|
+
height: calc(var(--control-height-lg) - 2 * var(--border-width-1));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.ds-combobox__input::placeholder {
|
|
93
|
+
color: var(--color-text-subtle);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.ds-combobox__input:disabled {
|
|
97
|
+
cursor: not-allowed;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ds-combobox__toggle {
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
flex-shrink: 0;
|
|
105
|
+
align-self: center;
|
|
106
|
+
margin-left: auto;
|
|
107
|
+
width: var(--control-height-sm);
|
|
108
|
+
height: var(--control-height-sm);
|
|
109
|
+
padding: 0;
|
|
110
|
+
border: 0;
|
|
111
|
+
border-radius: var(--radius-sm);
|
|
112
|
+
background: transparent;
|
|
113
|
+
color: var(--color-text-muted);
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.ds-combobox__toggle svg {
|
|
118
|
+
width: var(--icon-size-sm);
|
|
119
|
+
height: var(--icon-size-sm);
|
|
120
|
+
transition: transform var(--duration-fast) var(--easing-standard);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.ds-combobox__toggle[aria-expanded="true"] svg {
|
|
124
|
+
transform: rotate(180deg);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.ds-combobox__toggle:disabled {
|
|
128
|
+
color: var(--color-text-disabled);
|
|
129
|
+
cursor: not-allowed;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.ds-combobox__chip {
|
|
133
|
+
display: inline-flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
gap: var(--space-1);
|
|
136
|
+
max-width: 100%;
|
|
137
|
+
padding: 0 var(--space-1) 0 var(--space-2);
|
|
138
|
+
border-radius: var(--radius-sm);
|
|
139
|
+
background: var(--color-neutral);
|
|
140
|
+
color: var(--color-text);
|
|
141
|
+
font-size: var(--font-size-xs);
|
|
142
|
+
line-height: var(--line-height-normal);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.ds-combobox__chip-label {
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
white-space: nowrap;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.ds-combobox__chip-remove {
|
|
152
|
+
display: inline-flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
justify-content: center;
|
|
155
|
+
padding: 0;
|
|
156
|
+
border: 0;
|
|
157
|
+
border-radius: var(--radius-sm);
|
|
158
|
+
background: transparent;
|
|
159
|
+
color: var(--color-text-muted);
|
|
160
|
+
cursor: pointer;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.ds-combobox__chip-remove svg {
|
|
164
|
+
width: var(--icon-size-sm);
|
|
165
|
+
height: var(--icon-size-sm);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.ds-combobox__chip-remove:hover {
|
|
169
|
+
background: var(--color-neutral-hover);
|
|
170
|
+
color: var(--color-text);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Floating list */
|
|
174
|
+
.ds-combobox__popup {
|
|
175
|
+
position: fixed;
|
|
176
|
+
z-index: var(--z-popover);
|
|
177
|
+
max-height: 320px;
|
|
178
|
+
overflow-y: auto;
|
|
179
|
+
padding: var(--space-1);
|
|
180
|
+
background: var(--color-surface-raised);
|
|
181
|
+
color: var(--color-text);
|
|
182
|
+
border: var(--border-width-1) solid var(--color-border);
|
|
183
|
+
border-radius: var(--radius-md);
|
|
184
|
+
box-shadow: var(--shadow-lg);
|
|
185
|
+
font-family: var(--font-sans);
|
|
186
|
+
font-size: var(--font-size-sm);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.ds-combobox__popup--sm {
|
|
190
|
+
font-size: var(--font-size-xs);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.ds-combobox__popup--lg {
|
|
194
|
+
font-size: var(--font-size-md);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.ds-combobox__listbox {
|
|
198
|
+
margin: 0;
|
|
199
|
+
padding: 0;
|
|
200
|
+
list-style: none;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.ds-combobox__option {
|
|
204
|
+
display: flex;
|
|
205
|
+
align-items: center;
|
|
206
|
+
gap: var(--space-2);
|
|
207
|
+
min-height: var(--control-height-sm);
|
|
208
|
+
padding: var(--space-1) var(--space-2);
|
|
209
|
+
border-radius: var(--radius-sm);
|
|
210
|
+
cursor: pointer;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.ds-combobox__option--active {
|
|
214
|
+
background: var(--color-neutral-hover);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.ds-combobox__option--selected {
|
|
218
|
+
font-weight: var(--font-weight-medium);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.ds-combobox__option--disabled {
|
|
222
|
+
color: var(--color-text-disabled);
|
|
223
|
+
cursor: not-allowed;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.ds-combobox__option--create {
|
|
227
|
+
color: var(--color-primary-text);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.ds-combobox__option-text {
|
|
231
|
+
display: flex;
|
|
232
|
+
flex: 1;
|
|
233
|
+
flex-direction: column;
|
|
234
|
+
min-width: 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.ds-combobox__option-description {
|
|
238
|
+
color: var(--color-text-muted);
|
|
239
|
+
font-size: var(--font-size-xs);
|
|
240
|
+
font-weight: var(--font-weight-regular);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.ds-combobox__match {
|
|
244
|
+
background: transparent;
|
|
245
|
+
color: inherit;
|
|
246
|
+
font-weight: var(--font-weight-bold);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.ds-combobox__check {
|
|
250
|
+
flex-shrink: 0;
|
|
251
|
+
width: var(--icon-size-sm);
|
|
252
|
+
height: var(--icon-size-sm);
|
|
253
|
+
color: var(--color-primary);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.ds-combobox__status {
|
|
257
|
+
display: flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
gap: var(--space-2);
|
|
260
|
+
padding: var(--space-2);
|
|
261
|
+
color: var(--color-text-muted);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@media (prefers-reduced-motion: reduce) {
|
|
265
|
+
.ds-combobox,
|
|
266
|
+
.ds-combobox__toggle svg {
|
|
267
|
+
transition: none;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export { scoreCommand } from "./score";
|
|
3
|
+
export type { ScorableCommand } from "./score";
|
|
4
|
+
export interface CommandPaletteCommand {
|
|
5
|
+
/** Unique id */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Text shown and matched against the query */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Group heading the command is listed under */
|
|
10
|
+
group?: string;
|
|
11
|
+
/** Extra search terms (synonyms) */
|
|
12
|
+
keywords?: string[];
|
|
13
|
+
/** Keyboard shortcut shown with Kbd (display only), e.g. `["Ctrl", "S"]` */
|
|
14
|
+
shortcut?: string[];
|
|
15
|
+
/** Decorative icon */
|
|
16
|
+
icon?: ReactNode;
|
|
17
|
+
/** Runs the command; the palette closes first */
|
|
18
|
+
onSelect: () => void;
|
|
19
|
+
/** Shown but not selectable */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandPaletteProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "children"> {
|
|
23
|
+
/** Whether the palette is shown (controlled) */
|
|
24
|
+
open?: boolean;
|
|
25
|
+
/** Initial open state (uncontrolled) */
|
|
26
|
+
defaultOpen?: boolean;
|
|
27
|
+
/** Called when the palette opens or closes */
|
|
28
|
+
onOpenChange?: (open: boolean) => void;
|
|
29
|
+
/** Commands to search */
|
|
30
|
+
commands: CommandPaletteCommand[];
|
|
31
|
+
/** Placeholder of the search input */
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
/** Message shown when nothing matches */
|
|
34
|
+
emptyText?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* Global shortcut that toggles the palette. `"Meta"` also matches Ctrl, so the default works as
|
|
37
|
+
* ⌘K on macOS and Ctrl+K elsewhere. Pass `null` to disable it.
|
|
38
|
+
*/
|
|
39
|
+
hotkey?: string[] | null;
|
|
40
|
+
/** Accessible name of the dialog */
|
|
41
|
+
"aria-label"?: string;
|
|
42
|
+
/** Accessible name of the search input */
|
|
43
|
+
inputLabel?: string;
|
|
44
|
+
/** Accessible label of the close button */
|
|
45
|
+
closeLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Searchable list of commands in a modal dialog, toggled with a global hotkey (⌘K / Ctrl+K by default). */
|
|
48
|
+
declare function CommandPalette({ open: openProp, defaultOpen, onOpenChange, commands, placeholder, emptyText, hotkey, "aria-label": ariaLabel, inputLabel, closeLabel, className, ...rest }: CommandPaletteProps): import("react").JSX.Element;
|
|
49
|
+
export default CommandPalette;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
2
|
+
import Kbd from "../../atoms/kbd/index.js";
|
|
3
|
+
import { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
4
|
+
import { cx } from "../../utils/cx.js";
|
|
5
|
+
import { DialogBase } from "../modal/dialog-base.js";
|
|
6
|
+
import { scoreCommand } from "./score.js";
|
|
7
|
+
import './styles.css';/* empty css */
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/components/organisms/command-palette/index.tsx
|
|
10
|
+
var MODIFIERS = /* @__PURE__ */ new Set([
|
|
11
|
+
"meta",
|
|
12
|
+
"cmd",
|
|
13
|
+
"command",
|
|
14
|
+
"ctrl",
|
|
15
|
+
"control",
|
|
16
|
+
"alt",
|
|
17
|
+
"option",
|
|
18
|
+
"shift"
|
|
19
|
+
]);
|
|
20
|
+
/** Whether a keyboard event matches a hotkey such as `["Meta", "k"]`. */
|
|
21
|
+
function matchesHotkey(event, hotkey) {
|
|
22
|
+
const keys = hotkey.map((k) => k.toLowerCase());
|
|
23
|
+
const main = keys.find((k) => !MODIFIERS.has(k));
|
|
24
|
+
if (!main || event.key.toLowerCase() !== main) return false;
|
|
25
|
+
const wantsMeta = keys.some((k) => k === "meta" || k === "cmd" || k === "command");
|
|
26
|
+
const wantsCtrl = keys.some((k) => k === "ctrl" || k === "control");
|
|
27
|
+
const wantsAlt = keys.some((k) => k === "alt" || k === "option");
|
|
28
|
+
const wantsShift = keys.includes("shift");
|
|
29
|
+
return (wantsMeta ? event.metaKey || event.ctrlKey : wantsCtrl ? event.ctrlKey && !event.metaKey : !event.metaKey && !event.ctrlKey) && event.altKey === wantsAlt && event.shiftKey === wantsShift;
|
|
30
|
+
}
|
|
31
|
+
/** Searchable list of commands in a modal dialog, toggled with a global hotkey (⌘K / Ctrl+K by default). */
|
|
32
|
+
function CommandPalette({ open: openProp, defaultOpen = false, onOpenChange, commands, placeholder = "Type a command or search…", emptyText = "No results", hotkey = ["Meta", "k"], "aria-label": ariaLabel = "Command palette", inputLabel = "Search commands", closeLabel = "Close", className, ...rest }) {
|
|
33
|
+
const [open, setOpen] = useControllableState(openProp, defaultOpen, onOpenChange);
|
|
34
|
+
const [query, setQuery] = useState("");
|
|
35
|
+
const [activeId, setActiveId] = useState(null);
|
|
36
|
+
const inputRef = useRef(null);
|
|
37
|
+
const id = useId();
|
|
38
|
+
const listboxId = `${id}-listbox`;
|
|
39
|
+
const optionId = (commandId) => `${id}-option-${commandId}`;
|
|
40
|
+
const hotkeyRef = useRef(hotkey);
|
|
41
|
+
hotkeyRef.current = hotkey;
|
|
42
|
+
const hotkeyEnabled = hotkey !== null && hotkey.length > 0;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!hotkeyEnabled) return;
|
|
45
|
+
const onKeyDown = (event) => {
|
|
46
|
+
if (hotkeyRef.current && matchesHotkey(event, hotkeyRef.current)) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
setOpen((prev) => !prev);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
document.addEventListener("keydown", onKeyDown);
|
|
52
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
53
|
+
}, [hotkeyEnabled, setOpen]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (open) setQuery("");
|
|
56
|
+
}, [open]);
|
|
57
|
+
const groups = useMemo(() => {
|
|
58
|
+
const ranked = commands.map((command, index) => ({
|
|
59
|
+
command,
|
|
60
|
+
index,
|
|
61
|
+
score: scoreCommand(query, command)
|
|
62
|
+
})).filter((r) => r.score > 0).sort((a, b) => b.score - a.score || a.index - b.index);
|
|
63
|
+
const map = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const { command } of ranked) {
|
|
65
|
+
let group = map.get(command.group);
|
|
66
|
+
if (!group) {
|
|
67
|
+
group = {
|
|
68
|
+
name: command.group,
|
|
69
|
+
items: []
|
|
70
|
+
};
|
|
71
|
+
map.set(command.group, group);
|
|
72
|
+
}
|
|
73
|
+
group.items.push(command);
|
|
74
|
+
}
|
|
75
|
+
return Array.from(map.values());
|
|
76
|
+
}, [commands, query]);
|
|
77
|
+
const flat = useMemo(() => groups.flatMap((g) => g.items), [groups]);
|
|
78
|
+
const enabled = useMemo(() => flat.filter((c) => !c.disabled), [flat]);
|
|
79
|
+
const enabledRef = useRef(enabled);
|
|
80
|
+
enabledRef.current = enabled;
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
setActiveId(enabledRef.current[0]?.id ?? null);
|
|
83
|
+
}, [query]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!enabled.some((c) => c.id === activeId)) setActiveId(enabled[0]?.id ?? null);
|
|
86
|
+
}, [enabled, activeId]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!activeId || !open) return;
|
|
89
|
+
document.getElementById(optionId(activeId))?.scrollIntoView?.({ block: "nearest" });
|
|
90
|
+
}, [activeId, open]);
|
|
91
|
+
const run = (command) => {
|
|
92
|
+
if (command.disabled) return;
|
|
93
|
+
setOpen(false);
|
|
94
|
+
command.onSelect();
|
|
95
|
+
};
|
|
96
|
+
const onInputKeyDown = (event) => {
|
|
97
|
+
const index = enabled.findIndex((c) => c.id === activeId);
|
|
98
|
+
switch (event.key) {
|
|
99
|
+
case "ArrowDown":
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
if (enabled.length) setActiveId(enabled[(index + 1) % enabled.length].id);
|
|
102
|
+
break;
|
|
103
|
+
case "ArrowUp":
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
if (enabled.length) setActiveId(enabled[(index - 1 + enabled.length) % enabled.length].id);
|
|
106
|
+
break;
|
|
107
|
+
case "Home":
|
|
108
|
+
if (event.ctrlKey || event.metaKey) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
if (enabled.length) setActiveId(enabled[0].id);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case "End":
|
|
114
|
+
if (event.ctrlKey || event.metaKey) {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
if (enabled.length) setActiveId(enabled[enabled.length - 1].id);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
case "Enter": {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
const command = enabled[index];
|
|
122
|
+
if (command) run(command);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const activeCommand = enabled.find((c) => c.id === activeId);
|
|
128
|
+
return /* @__PURE__ */ jsxs(DialogBase, {
|
|
129
|
+
name: "command-palette",
|
|
130
|
+
modifiers: [],
|
|
131
|
+
open,
|
|
132
|
+
onClose: () => setOpen(false),
|
|
133
|
+
initialFocusRef: inputRef,
|
|
134
|
+
closeLabel,
|
|
135
|
+
"aria-label": ariaLabel,
|
|
136
|
+
className,
|
|
137
|
+
...rest,
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsxs("div", {
|
|
140
|
+
className: "ds-command-palette__search",
|
|
141
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
142
|
+
className: "ds-command-palette__search-icon",
|
|
143
|
+
viewBox: "0 0 16 16",
|
|
144
|
+
"aria-hidden": "true",
|
|
145
|
+
focusable: "false",
|
|
146
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
147
|
+
cx: "7",
|
|
148
|
+
cy: "7",
|
|
149
|
+
r: "4.5",
|
|
150
|
+
fill: "none",
|
|
151
|
+
stroke: "currentColor",
|
|
152
|
+
strokeWidth: "1.5"
|
|
153
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
154
|
+
d: "M10.5 10.5L14 14",
|
|
155
|
+
stroke: "currentColor",
|
|
156
|
+
strokeWidth: "1.5",
|
|
157
|
+
strokeLinecap: "round"
|
|
158
|
+
})]
|
|
159
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
160
|
+
ref: inputRef,
|
|
161
|
+
type: "text",
|
|
162
|
+
role: "combobox",
|
|
163
|
+
"aria-label": inputLabel,
|
|
164
|
+
"aria-expanded": "true",
|
|
165
|
+
"aria-controls": listboxId,
|
|
166
|
+
"aria-autocomplete": "list",
|
|
167
|
+
"aria-activedescendant": activeCommand ? optionId(activeCommand.id) : void 0,
|
|
168
|
+
autoComplete: "off",
|
|
169
|
+
spellCheck: false,
|
|
170
|
+
className: "ds-command-palette__input",
|
|
171
|
+
placeholder,
|
|
172
|
+
value: query,
|
|
173
|
+
onChange: (event) => setQuery(event.target.value),
|
|
174
|
+
onKeyDown: onInputKeyDown
|
|
175
|
+
})]
|
|
176
|
+
}),
|
|
177
|
+
/* @__PURE__ */ jsx("div", {
|
|
178
|
+
id: listboxId,
|
|
179
|
+
role: "listbox",
|
|
180
|
+
"aria-label": ariaLabel,
|
|
181
|
+
className: "ds-command-palette__list",
|
|
182
|
+
children: groups.map((group, groupIndex) => {
|
|
183
|
+
const headingId = `${id}-group-${groupIndex}`;
|
|
184
|
+
const options = group.items.map((command) => {
|
|
185
|
+
const active = command.id === activeId;
|
|
186
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
187
|
+
id: optionId(command.id),
|
|
188
|
+
"data-command-id": command.id,
|
|
189
|
+
role: "option",
|
|
190
|
+
"aria-selected": active,
|
|
191
|
+
"aria-disabled": command.disabled || void 0,
|
|
192
|
+
className: cx("ds-command-palette__option", active && "ds-command-palette__option--active", command.disabled && "ds-command-palette__option--disabled"),
|
|
193
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
194
|
+
onMouseMove: () => {
|
|
195
|
+
if (!command.disabled && !active) setActiveId(command.id);
|
|
196
|
+
},
|
|
197
|
+
onClick: () => run(command),
|
|
198
|
+
children: [
|
|
199
|
+
command.icon != null && /* @__PURE__ */ jsx("span", {
|
|
200
|
+
className: "ds-command-palette__icon",
|
|
201
|
+
"aria-hidden": "true",
|
|
202
|
+
children: command.icon
|
|
203
|
+
}),
|
|
204
|
+
/* @__PURE__ */ jsx("span", {
|
|
205
|
+
className: "ds-command-palette__label",
|
|
206
|
+
children: command.label
|
|
207
|
+
}),
|
|
208
|
+
command.shortcut && command.shortcut.length > 0 && /* @__PURE__ */ jsx(Kbd, {
|
|
209
|
+
keys: command.shortcut,
|
|
210
|
+
className: "ds-command-palette__shortcut"
|
|
211
|
+
})
|
|
212
|
+
]
|
|
213
|
+
}, command.id);
|
|
214
|
+
});
|
|
215
|
+
if (!group.name) return /* @__PURE__ */ jsx(Fragment, { children: options }, `__ungrouped-${groupIndex}`);
|
|
216
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
217
|
+
role: "group",
|
|
218
|
+
"aria-labelledby": headingId,
|
|
219
|
+
className: "ds-command-palette__group",
|
|
220
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
221
|
+
id: headingId,
|
|
222
|
+
role: "presentation",
|
|
223
|
+
className: "ds-command-palette__group-heading",
|
|
224
|
+
children: group.name
|
|
225
|
+
}), options]
|
|
226
|
+
}, group.name);
|
|
227
|
+
})
|
|
228
|
+
}),
|
|
229
|
+
/* @__PURE__ */ jsx("div", {
|
|
230
|
+
role: "status",
|
|
231
|
+
className: cx(flat.length === 0 && "ds-command-palette__empty"),
|
|
232
|
+
children: flat.length === 0 ? emptyText : null
|
|
233
|
+
})
|
|
234
|
+
]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
export { CommandPalette as default, scoreCommand };
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_jsxs","_jsx"],"sources":["../../../../src/components/organisms/command-palette/index.tsx"],"sourcesContent":["import {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type KeyboardEvent as ReactKeyboardEvent,\n type ReactNode,\n} from \"react\";\nimport Kbd from \"../../atoms/kbd\";\nimport { useControllableState } from \"../../hooks\";\nimport { cx } from \"../../utils/cx\";\nimport { DialogBase } from \"../modal/dialog-base\";\nimport { scoreCommand } from \"./score\";\nimport \"./styles.css\";\n\nexport { scoreCommand } from \"./score\";\nexport type { ScorableCommand } from \"./score\";\n\nexport interface CommandPaletteCommand {\n /** Unique id */\n id: string;\n /** Text shown and matched against the query */\n label: string;\n /** Group heading the command is listed under */\n group?: string;\n /** Extra search terms (synonyms) */\n keywords?: string[];\n /** Keyboard shortcut shown with Kbd (display only), e.g. `[\"Ctrl\", \"S\"]` */\n shortcut?: string[];\n /** Decorative icon */\n icon?: ReactNode;\n /** Runs the command; the palette closes first */\n onSelect: () => void;\n /** Shown but not selectable */\n disabled?: boolean;\n}\n\nexport interface CommandPaletteProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n /** Whether the palette is shown (controlled) */\n open?: boolean;\n /** Initial open state (uncontrolled) */\n defaultOpen?: boolean;\n /** Called when the palette opens or closes */\n onOpenChange?: (open: boolean) => void;\n /** Commands to search */\n commands: CommandPaletteCommand[];\n /** Placeholder of the search input */\n placeholder?: string;\n /** Message shown when nothing matches */\n emptyText?: ReactNode;\n /**\n * Global shortcut that toggles the palette. `\"Meta\"` also matches Ctrl, so the default works as\n * ⌘K on macOS and Ctrl+K elsewhere. Pass `null` to disable it.\n */\n hotkey?: string[] | null;\n /** Accessible name of the dialog */\n \"aria-label\"?: string;\n /** Accessible name of the search input */\n inputLabel?: string;\n /** Accessible label of the close button */\n closeLabel?: string;\n}\n\nconst MODIFIERS = new Set([\"meta\", \"cmd\", \"command\", \"ctrl\", \"control\", \"alt\", \"option\", \"shift\"]);\n\n/** Whether a keyboard event matches a hotkey such as `[\"Meta\", \"k\"]`. */\nfunction matchesHotkey(event: KeyboardEvent, hotkey: string[]): boolean {\n const keys = hotkey.map((k) => k.toLowerCase());\n const main = keys.find((k) => !MODIFIERS.has(k));\n if (!main || event.key.toLowerCase() !== main) return false;\n const wantsMeta = keys.some((k) => k === \"meta\" || k === \"cmd\" || k === \"command\");\n const wantsCtrl = keys.some((k) => k === \"ctrl\" || k === \"control\");\n const wantsAlt = keys.some((k) => k === \"alt\" || k === \"option\");\n const wantsShift = keys.includes(\"shift\");\n const primary = wantsMeta ? event.metaKey || event.ctrlKey : wantsCtrl ? event.ctrlKey && !event.metaKey : !event.metaKey && !event.ctrlKey;\n return primary && event.altKey === wantsAlt && event.shiftKey === wantsShift;\n}\n\ninterface Group {\n name: string | undefined;\n items: CommandPaletteCommand[];\n}\n\n/** Searchable list of commands in a modal dialog, toggled with a global hotkey (⌘K / Ctrl+K by default). */\nfunction CommandPalette({\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n commands,\n placeholder = \"Type a command or search…\",\n emptyText = \"No results\",\n hotkey = [\"Meta\", \"k\"],\n \"aria-label\": ariaLabel = \"Command palette\",\n inputLabel = \"Search commands\",\n closeLabel = \"Close\",\n className,\n ...rest\n}: CommandPaletteProps) {\n const [open, setOpen] = useControllableState(openProp, defaultOpen, onOpenChange);\n const [query, setQuery] = useState(\"\");\n const [activeId, setActiveId] = useState<string | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const id = useId();\n const listboxId = `${id}-listbox`;\n const optionId = (commandId: string) => `${id}-option-${commandId}`;\n\n const hotkeyRef = useRef(hotkey);\n hotkeyRef.current = hotkey;\n const hotkeyEnabled = hotkey !== null && hotkey.length > 0;\n useEffect(() => {\n if (!hotkeyEnabled) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (hotkeyRef.current && matchesHotkey(event, hotkeyRef.current)) {\n event.preventDefault();\n setOpen((prev) => !prev);\n }\n };\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [hotkeyEnabled, setOpen]);\n\n // Start with an empty query every time the palette opens.\n useEffect(() => {\n if (open) setQuery(\"\");\n }, [open]);\n\n const groups = useMemo<Group[]>(() => {\n const ranked = commands\n .map((command, index) => ({ command, index, score: scoreCommand(query, command) }))\n .filter((r) => r.score > 0)\n .sort((a, b) => b.score - a.score || a.index - b.index);\n const map = new Map<string | undefined, Group>();\n for (const { command } of ranked) {\n let group = map.get(command.group);\n if (!group) {\n group = { name: command.group, items: [] };\n map.set(command.group, group);\n }\n group.items.push(command);\n }\n return Array.from(map.values());\n }, [commands, query]);\n\n const flat = useMemo(() => groups.flatMap((g) => g.items), [groups]);\n const enabled = useMemo(() => flat.filter((c) => !c.disabled), [flat]);\n\n // Typing moves the active option back to the best match.\n const enabledRef = useRef(enabled);\n enabledRef.current = enabled;\n useEffect(() => {\n setActiveId(enabledRef.current[0]?.id ?? null);\n }, [query]);\n\n // Keep the active option valid: default to the first enabled match.\n useEffect(() => {\n if (!enabled.some((c) => c.id === activeId)) setActiveId(enabled[0]?.id ?? null);\n }, [enabled, activeId]);\n\n useEffect(() => {\n if (!activeId || !open) return;\n document.getElementById(optionId(activeId))?.scrollIntoView?.({ block: \"nearest\" });\n }, [activeId, open]);\n\n const run = (command: CommandPaletteCommand) => {\n if (command.disabled) return;\n setOpen(false);\n command.onSelect();\n };\n\n const onInputKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {\n const index = enabled.findIndex((c) => c.id === activeId);\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (enabled.length) setActiveId(enabled[(index + 1) % enabled.length].id);\n break;\n case \"ArrowUp\":\n event.preventDefault();\n if (enabled.length) setActiveId(enabled[(index - 1 + enabled.length) % enabled.length].id);\n break;\n case \"Home\":\n if (event.ctrlKey || event.metaKey) {\n event.preventDefault();\n if (enabled.length) setActiveId(enabled[0].id);\n }\n break;\n case \"End\":\n if (event.ctrlKey || event.metaKey) {\n event.preventDefault();\n if (enabled.length) setActiveId(enabled[enabled.length - 1].id);\n }\n break;\n case \"Enter\": {\n event.preventDefault();\n const command = enabled[index];\n if (command) run(command);\n break;\n }\n }\n };\n\n const activeCommand = enabled.find((c) => c.id === activeId);\n\n return (\n <DialogBase\n name=\"command-palette\"\n modifiers={[]}\n open={open}\n onClose={() => setOpen(false)}\n initialFocusRef={inputRef}\n closeLabel={closeLabel}\n aria-label={ariaLabel}\n className={className}\n {...rest}\n >\n <div className=\"ds-command-palette__search\">\n <svg className=\"ds-command-palette__search-icon\" viewBox=\"0 0 16 16\" aria-hidden=\"true\" focusable=\"false\">\n <circle cx=\"7\" cy=\"7\" r=\"4.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n <path d=\"M10.5 10.5L14 14\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n <input\n ref={inputRef}\n type=\"text\"\n role=\"combobox\"\n aria-label={inputLabel}\n aria-expanded=\"true\"\n aria-controls={listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant={activeCommand ? optionId(activeCommand.id) : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n className=\"ds-command-palette__input\"\n placeholder={placeholder}\n value={query}\n onChange={(event) => setQuery(event.target.value)}\n onKeyDown={onInputKeyDown}\n />\n </div>\n <div id={listboxId} role=\"listbox\" aria-label={ariaLabel} className=\"ds-command-palette__list\">\n {groups.map((group, groupIndex) => {\n const headingId = `${id}-group-${groupIndex}`;\n const options = group.items.map((command) => {\n const active = command.id === activeId;\n return (\n <div\n key={command.id}\n id={optionId(command.id)}\n data-command-id={command.id}\n role=\"option\"\n aria-selected={active}\n aria-disabled={command.disabled || undefined}\n className={cx(\n \"ds-command-palette__option\",\n active && \"ds-command-palette__option--active\",\n command.disabled && \"ds-command-palette__option--disabled\"\n )}\n onMouseDown={(event) => event.preventDefault()}\n onMouseMove={() => {\n if (!command.disabled && !active) setActiveId(command.id);\n }}\n onClick={() => run(command)}\n >\n {command.icon != null && (\n <span className=\"ds-command-palette__icon\" aria-hidden=\"true\">\n {command.icon}\n </span>\n )}\n <span className=\"ds-command-palette__label\">{command.label}</span>\n {command.shortcut && command.shortcut.length > 0 && (\n <Kbd keys={command.shortcut} className=\"ds-command-palette__shortcut\" />\n )}\n </div>\n );\n });\n if (!group.name) {\n return <Fragment key={`__ungrouped-${groupIndex}`}>{options}</Fragment>;\n }\n return (\n <div key={group.name} role=\"group\" aria-labelledby={headingId} className=\"ds-command-palette__group\">\n <div id={headingId} role=\"presentation\" className=\"ds-command-palette__group-heading\">\n {group.name}\n </div>\n {options}\n </div>\n );\n })}\n </div>\n <div role=\"status\" className={cx(flat.length === 0 && \"ds-command-palette__empty\")}>\n {flat.length === 0 ? emptyText : null}\n </div>\n </DialogBase>\n );\n}\n\nexport default CommandPalette;\n"],"mappings":";;;;;;;;;AAkEA,IAAM,4BAAY,IAAI,IAAI;CAAC;CAAQ;CAAO;CAAW;CAAQ;CAAW;CAAO;CAAU;AAAO,CAAC;;AAGjG,SAAS,cAAc,OAAsB,QAA2B;CACtE,MAAM,OAAO,OAAO,KAAK,MAAM,EAAE,YAAY,CAAC;CAC9C,MAAM,OAAO,KAAK,MAAM,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;CAC/C,IAAI,CAAC,QAAQ,MAAM,IAAI,YAAY,MAAM,MAAM,OAAO;CACtD,MAAM,YAAY,KAAK,MAAM,MAAM,MAAM,UAAU,MAAM,SAAS,MAAM,SAAS;CACjF,MAAM,YAAY,KAAK,MAAM,MAAM,MAAM,UAAU,MAAM,SAAS;CAClE,MAAM,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,QAAQ;CAC/D,MAAM,aAAa,KAAK,SAAS,OAAO;CAExC,QADgB,YAAY,MAAM,WAAW,MAAM,UAAU,YAAY,MAAM,WAAW,CAAC,MAAM,UAAU,CAAC,MAAM,WAAW,CAAC,MAAM,YAClH,MAAM,WAAW,YAAY,MAAM,aAAa;AACpE;;AAQA,SAAS,eAAe,EACtB,MAAM,UACN,cAAc,OACd,cACA,UACA,cAAc,6BACd,YAAY,cACZ,SAAS,CAAC,QAAQ,GAAG,GACrB,cAAc,YAAY,mBAC1B,aAAa,mBACb,aAAa,SACb,WACA,GAAG,QACmB;CACtB,MAAM,CAAC,MAAM,WAAW,qBAAqB,UAAU,aAAa,YAAY;CAChF,MAAM,C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|
3
|
+
label: string;
|
|
4
|
+
keywords?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Relevance of `command` for `query`: `0` means no match, higher is better.
|
|
8
|
+
* Matches the label and the keywords case-insensitively: exact > prefix > word prefix > substring > in-order
|
|
9
|
+
* characters (fuzzy). Keyword matches rank slightly below label matches; shorter labels win ties.
|
|
10
|
+
* An empty query matches everything with score 1.
|
|
11
|
+
*/
|
|
12
|
+
export declare function scoreCommand(query: string, command: ScorableCommand): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/components/organisms/command-palette/score.ts
|
|
2
|
+
var isWordBoundary = (text, index) => index === 0 || !/[\p{L}\p{N}]/u.test(text[index - 1]);
|
|
3
|
+
function scoreText(query, text) {
|
|
4
|
+
const hay = text.toLowerCase();
|
|
5
|
+
if (hay === query) return 120;
|
|
6
|
+
if (hay.startsWith(query)) return 100;
|
|
7
|
+
let index = hay.indexOf(query);
|
|
8
|
+
while (index !== -1) {
|
|
9
|
+
if (isWordBoundary(hay, index)) return 80;
|
|
10
|
+
index = hay.indexOf(query, index + 1);
|
|
11
|
+
}
|
|
12
|
+
if (hay.includes(query)) return 60;
|
|
13
|
+
let pos = 0;
|
|
14
|
+
let first = -1;
|
|
15
|
+
let boundaryHits = 0;
|
|
16
|
+
for (const char of query) {
|
|
17
|
+
const found = hay.indexOf(char, pos);
|
|
18
|
+
if (found === -1) return 0;
|
|
19
|
+
if (first === -1) first = found;
|
|
20
|
+
if (isWordBoundary(hay, found)) boundaryHits++;
|
|
21
|
+
pos = found + 1;
|
|
22
|
+
}
|
|
23
|
+
const span = pos - first;
|
|
24
|
+
return 10 + 20 * (query.length / span) + 2 * boundaryHits;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Relevance of `command` for `query`: `0` means no match, higher is better.
|
|
28
|
+
* Matches the label and the keywords case-insensitively: exact > prefix > word prefix > substring > in-order
|
|
29
|
+
* characters (fuzzy). Keyword matches rank slightly below label matches; shorter labels win ties.
|
|
30
|
+
* An empty query matches everything with score 1.
|
|
31
|
+
*/
|
|
32
|
+
function scoreCommand(query, command) {
|
|
33
|
+
const q = query.trim().toLowerCase();
|
|
34
|
+
if (q === "") return 1;
|
|
35
|
+
const labelScore = scoreText(q, command.label);
|
|
36
|
+
const keywordScore = Math.max(0, ...(command.keywords ?? []).map((k) => scoreText(q, k) - 5));
|
|
37
|
+
const best = Math.max(labelScore, keywordScore);
|
|
38
|
+
if (best <= 0) return 0;
|
|
39
|
+
return best + 1 / (1 + command.label.length);
|
|
40
|
+
}
|
|
41
|
+
export { scoreCommand };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","names":[],"sources":["../../../../src/components/organisms/command-palette/score.ts"],"sourcesContent":["/** Minimal shape needed to score a command. */\nexport interface ScorableCommand {\n label: string;\n keywords?: string[];\n}\n\nconst isWordBoundary = (text: string, index: number) => index === 0 || !/[\\p{L}\\p{N}]/u.test(text[index - 1]);\n\nfunction scoreText(query: string, text: string): number {\n const hay = text.toLowerCase();\n if (hay === query) return 120;\n if (hay.startsWith(query)) return 100;\n let index = hay.indexOf(query);\n while (index !== -1) {\n if (isWordBoundary(hay, index)) return 80;\n index = hay.indexOf(query, index + 1);\n }\n if (hay.includes(query)) return 60;\n\n // Subsequence: every query character, in order. Tighter spans and word-start hits score higher.\n let pos = 0;\n let first = -1;\n let boundaryHits = 0;\n for (const char of query) {\n const found = hay.indexOf(char, pos);\n if (found === -1) return 0;\n if (first === -1) first = found;\n if (isWordBoundary(hay, found)) boundaryHits++;\n pos = found + 1;\n }\n const span = pos - first;\n return 10 + 20 * (query.length / span) + 2 * boundaryHits;\n}\n\n/**\n * Relevance of `command` for `query`: `0` means no match, higher is better.\n * Matches the label and the keywords case-insensitively: exact > prefix > word prefix > substring > in-order\n * characters (fuzzy). Keyword matches rank slightly below label matches; shorter labels win ties.\n * An empty query matches everything with score 1.\n */\nexport function scoreCommand(query: string, command: ScorableCommand): number {\n const q = query.trim().toLowerCase();\n if (q === \"\") return 1;\n const labelScore = scoreText(q, command.label);\n const keywordScore = Math.max(0, ...(command.keywords ?? []).map((k) => scoreText(q, k) - 5));\n const best = Math.max(labelScore, keywordScore);\n if (best <= 0) return 0;\n return best + 1 / (1 + command.label.length);\n}\n"],"mappings":";AAMA,IAAM,kBAAkB,MAAc,UAAkB,UAAU,KAAK,CAAC,gBAAgB,KAAK,KAAK,QAAQ,EAAE;AAE5G,SAAS,UAAU,OAAe,MAAsB;CACtD,MAAM,MAAM,KAAK,YAAY;CAC7B,IAAI,QAAQ,OAAO,OAAO;CAC1B,IAAI,IAAI,WAAW,KAAK,GAAG,OAAO;CAClC,IAAI,QAAQ,IAAI,QAAQ,KAAK;CAC7B,OAAO,UAAU,IAAI;EACnB,IAAI,eAAe,KAAK,KAAK,GAAG,OAAO;EACvC,QAAQ,IAAI,QAAQ,OAAO,QAAQ,CAAC;CACtC;CACA,IAAI,IAAI,SAAS,KAAK,GAAG,OAAO;CAGhC,IAAI,MAAM;CACV,IAAI,QAAQ;CACZ,IAAI,eAAe;CACnB,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,IAAI,QAAQ,MAAM,GAAG;EACnC,IAAI,UAAU,IAAI,OAAO;EACzB,IAAI,UAAU,IAAI,QAAQ;EAC1B,IAAI,eAAe,KAAK,KAAK,GAAG;EAChC,MAAM,QAAQ;CAChB;CACA,MAAM,OAAO,MAAM;CACnB,OAAO,KAAK,MAAM,MAAM,SAAS,QAAQ,IAAI;AAC/C;;;;;;;AAQA,SAAgB,aAAa,OAAe,SAAkC;CAC5E,MAAM,IAAI,MAAM,KAAK,CAAC,CAAC,YAAY;CACnC,IAAI,MAAM,IAAI,OAAO;CACrB,MAAM,aAAa,UAAU,GAAG,QAAQ,KAAK;CAC7C,MAAM,eAAe,KAAK,IAAI,GAAG,IAAI,QAAQ,YAAY,CAAC,EAAA,CAA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