@zazz-ui/core 0.4.0 → 0.5.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/AUTHORING.md +158 -0
- package/CHANGELOG.md +341 -0
- package/README.md +55 -23
- package/dist/scroll-state-C8mA5gq6.js +1 -0
- package/dist/sri.json +124 -72
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +116794 -0
- package/editor/zazz.html-data.json +1683 -0
- package/editor/zazz.language-data.json +5001 -0
- package/editor/zazz.lint-data.json +152 -0
- package/package.json +12 -5
- package/src/base/_breakpoints.css +12 -0
- package/src/base/_layers.css +8 -9
- package/src/base/_properties-2xl.css +171 -0
- package/src/base/_properties-active.css +107 -0
- package/src/base/_properties-checked.css +107 -0
- package/src/base/_properties-current.css +107 -0
- package/src/base/_properties-disabled.css +107 -0
- package/src/base/_properties-focus-visible.css +107 -0
- package/src/base/_properties-focus-within.css +107 -0
- package/src/base/_properties-hover.css +107 -0
- package/src/base/_properties-lg.css +171 -0
- package/src/base/_properties-md.css +171 -0
- package/src/base/_properties-open.css +107 -0
- package/src/base/_properties-sm.css +171 -0
- package/src/base/_properties-starting.css +55 -0
- package/src/base/_properties-stuck.css +55 -0
- package/src/base/_properties-xl.css +171 -0
- package/src/base/_properties.css +555 -0
- package/src/base/_reset.css +67 -75
- package/src/base/_switches.css +145 -0
- package/src/base/_typography.css +437 -370
- package/src/base/_utilities-box.css +142 -0
- package/src/base/_utilities-color.css +290 -0
- package/src/base/_utilities-effects.css +235 -0
- package/src/base/_utilities-flow.css +312 -0
- package/src/base/_utilities-grid.css +143 -0
- package/src/base/_utilities-margin.css +376 -0
- package/src/base/_utilities-pseudo.css +426 -0
- package/src/base/_utilities-sizing.css +259 -0
- package/src/base/_utilities-spacing.css +190 -0
- package/src/base/_utilities-tier-2xl.css +93 -0
- package/src/base/_utilities-tier-active.css +61 -0
- package/src/base/_utilities-tier-checked.css +61 -0
- package/src/base/_utilities-tier-current.css +61 -0
- package/src/base/_utilities-tier-disabled.css +61 -0
- package/src/base/_utilities-tier-focus-visible.css +61 -0
- package/src/base/_utilities-tier-focus-within.css +61 -0
- package/src/base/_utilities-tier-hover.css +63 -0
- package/src/base/_utilities-tier-lg.css +93 -0
- package/src/base/_utilities-tier-md.css +93 -0
- package/src/base/_utilities-tier-open.css +61 -0
- package/src/base/_utilities-tier-sm.css +93 -0
- package/src/base/_utilities-tier-starting.css +35 -0
- package/src/base/_utilities-tier-stuck.css +114 -0
- package/src/base/_utilities-tier-xl.css +93 -0
- package/src/base/_utilities-typography.css +141 -0
- package/src/base/_variables.css +323 -372
- package/src/base/_view-transitions.css +10 -12
- package/src/base/command-score.d.ts.map +1 -1
- package/src/base/command-score.js +1 -2
- package/src/base/command-score.ts +1 -2
- package/src/base/dialog-lifecycle.js +1 -1
- package/src/base/dialog-lifecycle.ts +1 -1
- package/src/base/embla.d.ts +6 -7
- package/src/base/embla.d.ts.map +1 -1
- package/src/base/embla.js +89 -55
- package/src/base/embla.ts +89 -55
- package/src/base/hotkeys.d.ts +0 -5
- package/src/base/hotkeys.d.ts.map +1 -1
- package/src/base/hotkeys.ts +0 -5
- package/src/base/navigation.d.ts +12 -1
- package/src/base/navigation.d.ts.map +1 -1
- package/src/base/navigation.js +229 -86
- package/src/base/navigation.ts +224 -92
- package/src/base/reveal.js +14 -14
- package/src/base/reveal.ts +14 -14
- package/src/base/scroll-state.d.ts +21 -0
- package/src/base/scroll-state.d.ts.map +1 -0
- package/src/base/scroll-state.js +177 -0
- package/src/base/scroll-state.ts +188 -0
- package/src/base/signals.d.ts +1 -2
- package/src/base/signals.d.ts.map +1 -1
- package/src/base/signals.js +4 -6
- package/src/base/signals.ts +4 -6
- package/src/base/style-format.d.ts +33 -0
- package/src/base/style-format.d.ts.map +1 -0
- package/src/base/style-format.js +160 -0
- package/src/base/style-format.ts +180 -0
- package/src/base/typeahead.d.ts +19 -4
- package/src/base/typeahead.d.ts.map +1 -1
- package/src/base/typeahead.js +68 -21
- package/src/base/typeahead.ts +73 -23
- package/src/base/utilities.d.ts +188 -0
- package/src/base/utilities.d.ts.map +1 -0
- package/src/base/utilities.js +750 -0
- package/src/base/utilities.ts +865 -0
- package/src/base/utils.d.ts +3 -7
- package/src/base/utils.d.ts.map +1 -1
- package/src/base/utils.js +4 -8
- package/src/base/utils.ts +4 -8
- package/src/base/zazz-element.d.ts +14 -8
- package/src/base/zazz-element.d.ts.map +1 -1
- package/src/base/zazz-element.js +14 -8
- package/src/base/zazz-element.ts +15 -8
- package/src/globals.d.ts +1 -1
- package/src/head.d.ts +50 -4
- package/src/head.d.ts.map +1 -1
- package/src/head.js +119 -38
- package/src/head.ts +172 -41
- package/src/index.css +57 -14
- package/src/index.js +5 -0
- package/src/index.ts +6 -0
- package/src/manifest.d.ts +36 -5
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +150 -6
- package/src/manifest.ts +167 -9
- package/src/primitives/accordion/accordion.css +18 -17
- package/src/primitives/accordion/accordion.html +42 -9
- package/src/primitives/alert-dialog/alert-dialog.css +13 -13
- package/src/primitives/alert-dialog/alert-dialog.html +26 -12
- package/src/primitives/autocomplete/autocomplete-groups.html +64 -33
- package/src/primitives/autocomplete/autocomplete.css +45 -43
- package/src/primitives/autocomplete/autocomplete.d.ts +6 -5
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
- package/src/primitives/autocomplete/autocomplete.html +38 -26
- package/src/primitives/autocomplete/autocomplete.js +6 -5
- package/src/primitives/autocomplete/autocomplete.ts +6 -5
- package/src/primitives/avatar/avatar.html +110 -15
- package/src/primitives/badge/badge-icon.html +22 -8
- package/src/primitives/badge/badge.css +401 -128
- package/src/primitives/badge/badge.html +12 -6
- package/src/primitives/breadcrumbs/breadcrumbs.html +25 -5
- package/src/primitives/button/button-icon-only.html +17 -11
- package/src/primitives/button/button-icon.html +9 -3
- package/src/primitives/button/button.css +408 -164
- package/src/primitives/button/button.html +14 -7
- package/src/primitives/button-group/button-group-vertical.html +5 -5
- package/src/primitives/button-group/button-group.css +53 -25
- package/src/primitives/button-group/button-group.html +18 -12
- package/src/primitives/callout/callout.css +114 -0
- package/src/primitives/callout/callout.html +188 -0
- package/src/primitives/card/card-subgrid.html +249 -34
- package/src/primitives/card/card.css +125 -0
- package/src/primitives/card/card.html +141 -20
- package/src/primitives/carousel/carousel.css +30 -20
- package/src/primitives/carousel/carousel.d.ts +7 -10
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.html +420 -84
- package/src/primitives/carousel/carousel.js +1 -1
- package/src/primitives/carousel/carousel.ts +8 -11
- package/src/primitives/checkbox/checkbox-tasklist.html +6 -6
- package/src/primitives/checkbox/checkbox.css +98 -40
- package/src/primitives/checkbox/checkbox.d.ts.map +1 -1
- package/src/primitives/checkbox/checkbox.html +13 -8
- package/src/primitives/checkbox/checkbox.js +7 -9
- package/src/primitives/checkbox/checkbox.ts +7 -15
- package/src/primitives/combobox/combobox-multiselect.html +53 -33
- package/src/primitives/combobox/combobox.css +147 -126
- package/src/primitives/combobox/combobox.d.ts +12 -11
- package/src/primitives/combobox/combobox.d.ts.map +1 -1
- package/src/primitives/combobox/combobox.html +48 -28
- package/src/primitives/combobox/combobox.js +46 -51
- package/src/primitives/combobox/combobox.ts +48 -55
- package/src/primitives/command/command-actions.d.ts +2 -3
- package/src/primitives/command/command-actions.d.ts.map +1 -1
- package/src/primitives/command/command-actions.html +48 -33
- package/src/primitives/command/command-actions.js +12 -10
- package/src/primitives/command/command-actions.ts +12 -13
- package/src/primitives/command/command-dialog.html +49 -25
- package/src/primitives/command/command.css +52 -42
- package/src/primitives/command/command.d.ts +10 -7
- package/src/primitives/command/command.d.ts.map +1 -1
- package/src/primitives/command/command.html +95 -46
- package/src/primitives/command/command.js +30 -13
- package/src/primitives/command/command.ts +30 -12
- package/src/primitives/debug/audit-core.d.ts +64 -0
- package/src/primitives/debug/audit-core.d.ts.map +1 -0
- package/src/primitives/debug/audit-core.js +356 -0
- package/src/primitives/debug/audit-core.ts +535 -0
- package/src/primitives/debug/debug.d.ts +50 -0
- package/src/primitives/debug/debug.d.ts.map +1 -0
- package/src/primitives/debug/debug.js +168 -0
- package/src/primitives/debug/debug.ts +211 -0
- package/src/primitives/dialog/dialog-with-form.html +67 -45
- package/src/primitives/dialog/dialog.css +87 -61
- package/src/primitives/dialog/dialog.html +25 -17
- package/src/primitives/fields/fields.css +108 -134
- package/src/primitives/fields/fields.html +39 -0
- package/src/primitives/input/input-icon-leading.html +3 -3
- package/src/primitives/input/input-icon-trailing.html +3 -3
- package/src/primitives/input/input.css +87 -49
- package/src/primitives/input/input.html +15 -15
- package/src/primitives/input-group/input-group-password-group.html +15 -15
- package/src/primitives/input-group/input-group.css +118 -75
- package/src/primitives/input-group/input-group.html +42 -30
- package/src/primitives/kbd/kbd-group.html +15 -2
- package/src/primitives/kbd/kbd.css +44 -31
- package/src/primitives/kbd/kbd.html +7 -1
- package/src/primitives/layout/layout.css +159 -0
- package/src/primitives/layout/layout.html +35 -0
- package/src/primitives/lightbox/lightbox.css +178 -105
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
- package/src/primitives/lightbox/lightbox.html +138 -166
- package/src/primitives/lightbox/lightbox.js +10 -13
- package/src/primitives/lightbox/lightbox.ts +12 -13
- package/src/primitives/menu/menu-interest.html +60 -18
- package/src/primitives/menu/menu.css +22 -17
- package/src/primitives/menu/menu.d.ts +5 -5
- package/src/primitives/menu/menu.html +195 -40
- package/src/primitives/menu/menu.js +8 -8
- package/src/primitives/menu/menu.ts +8 -8
- package/src/primitives/menubar/menubar-help-search.html +78 -32
- package/src/primitives/menubar/menubar.html +166 -38
- package/src/primitives/meter/meter.css +41 -38
- package/src/primitives/meter/meter.html +44 -9
- package/src/primitives/mobile-menu/mobile-menu.css +47 -40
- package/src/primitives/mobile-menu/mobile-menu.html +1460 -179
- package/src/primitives/navigation-menu/navigation-menu-featured.html +155 -33
- package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +222 -47
- package/src/primitives/navigation-menu/navigation-menu-interest.html +130 -38
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +402 -72
- package/src/primitives/navigation-menu/navigation-menu-simple.html +90 -40
- package/src/primitives/navigation-menu/navigation-menu.css +104 -106
- package/src/primitives/navigation-menu/navigation-menu.html +554 -158
- package/src/primitives/otp/otp.css +43 -44
- package/src/primitives/otp/otp.d.ts +4 -5
- package/src/primitives/otp/otp.d.ts.map +1 -1
- package/src/primitives/otp/otp.html +7 -6
- package/src/primitives/otp/otp.js +13 -18
- package/src/primitives/otp/otp.ts +12 -19
- package/src/primitives/password-group/password-group.css +132 -107
- package/src/primitives/password-group/password-group.d.ts.map +1 -1
- package/src/primitives/password-group/password-group.html +23 -16
- package/src/primitives/password-group/password-group.js +11 -12
- package/src/primitives/password-group/password-group.ts +11 -12
- package/src/primitives/popover/popover.css +89 -95
- package/src/primitives/popover/popover.html +18 -0
- package/src/primitives/progress/progress-indeterminate.html +1 -1
- package/src/primitives/progress/progress.css +34 -35
- package/src/primitives/progress/progress.html +18 -4
- package/src/primitives/prose/prose.html +19 -12
- package/src/primitives/radio/radio.css +83 -46
- package/src/primitives/radio/radio.html +16 -11
- package/src/primitives/reveal/reveal.css +37 -46
- package/src/primitives/reveal/reveal.html +15 -0
- package/src/primitives/scroll-fade/scroll-fade.css +115 -0
- package/src/primitives/scroll-fade/scroll-fade.html +69 -0
- package/src/primitives/select/multiselect.d.ts +8 -10
- package/src/primitives/select/multiselect.d.ts.map +1 -1
- package/src/primitives/select/multiselect.js +23 -27
- package/src/primitives/select/multiselect.ts +23 -29
- package/src/primitives/select/select-align.html +79 -16
- package/src/primitives/select/select-multiple.html +8 -4
- package/src/primitives/select/select-sides.html +104 -21
- package/src/primitives/select/select.css +299 -191
- package/src/primitives/select/select.html +24 -5
- package/src/primitives/separator/separator.css +15 -18
- package/src/primitives/separator/separator.html +37 -10
- package/src/primitives/slider/slider.css +48 -38
- package/src/primitives/slider/slider.html +9 -1
- package/src/primitives/style-guard/style-guard.d.ts +19 -0
- package/src/primitives/style-guard/style-guard.d.ts.map +1 -0
- package/src/primitives/style-guard/style-guard.js +125 -0
- package/src/primitives/style-guard/style-guard.ts +153 -0
- package/src/primitives/switch/switch.css +42 -33
- package/src/primitives/switch/switch.html +11 -6
- package/src/primitives/table/table-alternating.html +1 -1
- package/src/primitives/table/table-grid.html +5 -5
- package/src/primitives/table/table-size-sm.html +1 -1
- package/src/primitives/table/table.css +64 -61
- package/src/primitives/table/table.html +7 -7
- package/src/primitives/tabs/tabs.css +167 -166
- package/src/primitives/tabs/tabs.d.ts +10 -11
- package/src/primitives/tabs/tabs.d.ts.map +1 -1
- package/src/primitives/tabs/tabs.html +192 -36
- package/src/primitives/tabs/tabs.js +14 -15
- package/src/primitives/tabs/tabs.ts +14 -15
- package/src/primitives/textarea/textarea.css +69 -44
- package/src/primitives/textarea/textarea.html +3 -3
- package/src/primitives/toaster/toaster.css +90 -92
- package/src/primitives/toaster/toaster.d.ts +0 -6
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.html +22 -18
- package/src/primitives/toaster/toaster.js +64 -72
- package/src/primitives/toaster/toaster.ts +71 -87
- package/src/primitives/toggle/toggle.css +368 -153
- package/src/primitives/toggle/toggle.html +27 -9
- package/src/primitives/toggle-group/toggle-group-multiple.html +3 -3
- package/src/primitives/toggle-group/toggle-group-vertical.html +4 -4
- package/src/primitives/toggle-group/toggle-group.css +71 -23
- package/src/primitives/toggle-group/toggle-group.html +3 -3
- package/src/primitives/toolbar/toolbar.html +35 -13
- package/src/primitives/tooltip/tooltip-disabled.html +3 -3
- package/src/primitives/tooltip/tooltip-sides.html +36 -14
- package/src/primitives/tooltip/tooltip-with-kbd.html +5 -5
- package/src/primitives/tooltip/tooltip.css +111 -80
- package/src/primitives/tooltip/tooltip.html +3 -3
- package/src/primitives/utilities/aspect-ratio.html +51 -7
- package/src/primitives/utilities/basis.html +64 -11
- package/src/primitives/utilities/col-span.html +65 -9
- package/src/primitives/utilities/compose.html +48 -10
- package/src/primitives/utilities/flex-align.html +89 -19
- package/src/primitives/utilities/flex-direction.html +111 -13
- package/src/primitives/utilities/flex-grow.html +41 -7
- package/src/primitives/utilities/gap.html +158 -19
- package/src/primitives/utilities/grid-cols.html +75 -7
- package/src/primitives/utilities/grid-responsive.html +111 -12
- package/src/primitives/utilities/margin-auto.html +38 -7
- package/src/primitives/utilities/object-fit.html +75 -13
- package/src/primitives/utilities/order.html +40 -4
- package/src/primitives/utilities/overflow.html +74 -20
- package/src/primitives/utilities/padding-compose.html +67 -10
- package/src/primitives/utilities/padding.html +84 -13
- package/src/primitives/utilities/pile.html +29 -0
- package/src/primitives/utilities/position.html +65 -8
- package/src/primitives/utilities/responsive-flex.html +54 -7
- package/src/primitives/utilities/responsive-grid.html +115 -12
- package/src/primitives/utilities/size.html +120 -16
- package/src/primitives/utilities/width.html +123 -16
- package/examples/about.html +0 -583
- package/examples/components.html +0 -1028
- package/examples/forms.html +0 -504
- package/examples/index.html +0 -261
- package/examples/layout.html +0 -313
- package/examples/products.html +0 -839
- package/examples/responsive.html +0 -332
- package/src/base/_layout.css +0 -571
- package/src/base/_utilities.css +0 -6758
- package/src/primitives/utilities/grid-pile.html +0 -5
|
@@ -2,32 +2,29 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview `<ui-multiselect>`: a multi-select styled as a dropdown.
|
|
4
4
|
* @description Light-DOM custom element that progressively enhances a real
|
|
5
|
-
* `<select multiple
|
|
6
|
-
*
|
|
5
|
+
* `<select multiple data-ui="select">`. `appearance: base-select` does not
|
|
6
|
+
* apply to multi-selects in stable engines, so the script hides the
|
|
7
7
|
* select (which remains the form value carrier and source of truth) and
|
|
8
|
-
* stamps a
|
|
8
|
+
* stamps a `[data-ui~="select"]`-look trigger button plus an anchored popover of
|
|
9
9
|
* checkbox rows projected from the options. Checkbox changes write back to
|
|
10
10
|
* `option.selected` and re-dispatch `change` on the select; external writes
|
|
11
11
|
* and form resets flow the other way. Without JavaScript the native
|
|
12
12
|
* multi-select listbox renders: fully functional and accessible.
|
|
13
13
|
*
|
|
14
|
-
* The trigger reads `<first selection> (+N more)`.
|
|
15
|
-
* stable multi-select support this enhancement can retire (see the CSS
|
|
16
|
-
* header note in select.css).
|
|
14
|
+
* The trigger reads `<first selection> (+N more)`.
|
|
17
15
|
*
|
|
18
16
|
* Attributes on `<ui-multiselect>`:
|
|
19
|
-
* - `data-placeholder`: trigger text when nothing is selected.
|
|
20
|
-
* - `data-label-more`: overflow template, default `"(+{n} more)"`.
|
|
21
|
-
* - `data-side` / `data-align`: forwarded to the stamped panel (popover
|
|
17
|
+
* - `data-multiselect-placeholder`: trigger text when nothing is selected.
|
|
18
|
+
* - `data-multiselect-label-more`: overflow template, default `"(+{n} more)"`.
|
|
19
|
+
* - `data-multiselect-side` / `data-multiselect-align`: forwarded to the stamped panel as `data-popover-*` (popover
|
|
22
20
|
* placement matrix).
|
|
23
21
|
*
|
|
24
|
-
* Stamped parts: `multiselect-trigger` (a
|
|
22
|
+
* Stamped parts: `multiselect-trigger` (a `[data-ui~="select"]`-identity button),
|
|
25
23
|
* `multiselect-icon` (chevron), `multiselect-panel` (`[popover]`),
|
|
26
24
|
* `multiselect-option` (label + checkbox per option).
|
|
27
25
|
*/
|
|
28
26
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
|
|
29
27
|
import { effect, state } from "../../base/signals.js";
|
|
30
|
-
// --- Pure derivations (exported for unit tests only) ---
|
|
31
28
|
/**
|
|
32
29
|
* @description Formats the trigger label from the selected option labels.
|
|
33
30
|
*
|
|
@@ -43,7 +40,6 @@ function resolveTriggerLabel(labels, placeholder, moreTemplate) {
|
|
|
43
40
|
return labels[0];
|
|
44
41
|
return `${labels[0]} ${moreTemplate.replace("{n}", String(labels.length - 1))}`;
|
|
45
42
|
}
|
|
46
|
-
// --- Element ---
|
|
47
43
|
let multiselectIdCounter = 0;
|
|
48
44
|
class UiMultiselect extends ZazzElement {
|
|
49
45
|
#stamped = [];
|
|
@@ -53,10 +49,10 @@ class UiMultiselect extends ZazzElement {
|
|
|
53
49
|
if (!(select instanceof HTMLSelectElement))
|
|
54
50
|
return;
|
|
55
51
|
this.#select = select;
|
|
56
|
-
const placeholder = this.getAttribute("data-placeholder") ?? "Select…";
|
|
57
|
-
const moreTemplate = this.getAttribute("data-label-more") ?? "(+{n} more)";
|
|
52
|
+
const placeholder = this.getAttribute("data-multiselect-placeholder") ?? "Select…";
|
|
53
|
+
const moreTemplate = this.getAttribute("data-multiselect-label-more") ?? "(+{n} more)";
|
|
58
54
|
const { trigger, label, panel, checkboxes } = this.#stamp(select);
|
|
59
|
-
select.setAttribute("data-multiselect-
|
|
55
|
+
select.setAttribute("data-multiselect-state", "enhanced");
|
|
60
56
|
const selectedLabels = () => Array.from(select.selectedOptions).map((option) => option.label);
|
|
61
57
|
const selection = state(selectedLabels());
|
|
62
58
|
// Checkbox → option: the select stays the source of truth
|
|
@@ -72,7 +68,7 @@ class UiMultiselect extends ZazzElement {
|
|
|
72
68
|
// External writes and form resets → re-read (reset applies after the event)
|
|
73
69
|
select.addEventListener("change", () => selection.set(selectedLabels()), { signal });
|
|
74
70
|
select.form?.addEventListener("reset", () => queueMicrotask(() => selection.set(selectedLabels())), { signal });
|
|
75
|
-
//
|
|
71
|
+
// Mirror popover open state onto the trigger's aria-expanded
|
|
76
72
|
panel.addEventListener("toggle", (event) => {
|
|
77
73
|
trigger.setAttribute("aria-expanded", String(event.newState === "open"));
|
|
78
74
|
}, { signal });
|
|
@@ -91,7 +87,7 @@ class UiMultiselect extends ZazzElement {
|
|
|
91
87
|
for (const node of this.#stamped)
|
|
92
88
|
node.remove();
|
|
93
89
|
this.#stamped = [];
|
|
94
|
-
this.#select?.removeAttribute("data-multiselect-
|
|
90
|
+
this.#select?.removeAttribute("data-multiselect-state");
|
|
95
91
|
this.#select = null;
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
@@ -106,30 +102,30 @@ class UiMultiselect extends ZazzElement {
|
|
|
106
102
|
const panelId = `ui-multiselect-panel-${++multiselectIdCounter}`;
|
|
107
103
|
const trigger = document.createElement("button");
|
|
108
104
|
trigger.type = "button";
|
|
109
|
-
trigger.
|
|
110
|
-
trigger.setAttribute("data-slot", "
|
|
105
|
+
trigger.dataset.ui = "select";
|
|
106
|
+
trigger.setAttribute("data-multiselect-slot", "trigger");
|
|
111
107
|
trigger.setAttribute("popovertarget", panelId);
|
|
112
108
|
trigger.setAttribute("aria-expanded", "false");
|
|
113
109
|
const label = document.createElement("span");
|
|
114
|
-
label.setAttribute("data-slot", "
|
|
110
|
+
label.setAttribute("data-multiselect-slot", "label");
|
|
115
111
|
const icon = document.createElement("span");
|
|
116
|
-
icon.setAttribute("data-slot", "
|
|
112
|
+
icon.setAttribute("data-multiselect-slot", "icon");
|
|
117
113
|
icon.setAttribute("aria-hidden", "true");
|
|
118
114
|
trigger.append(label, icon);
|
|
119
115
|
const panel = document.createElement("div");
|
|
120
116
|
panel.id = panelId;
|
|
121
|
-
panel.setAttribute("data-slot", "
|
|
117
|
+
panel.setAttribute("data-multiselect-slot", "panel");
|
|
122
118
|
panel.setAttribute("popover", "auto");
|
|
123
|
-
const side = this.getAttribute("data-side");
|
|
124
|
-
const align = this.getAttribute("data-align");
|
|
119
|
+
const side = this.getAttribute("data-multiselect-side");
|
|
120
|
+
const align = this.getAttribute("data-multiselect-align");
|
|
125
121
|
if (side)
|
|
126
|
-
panel.setAttribute("data-side", side);
|
|
122
|
+
panel.setAttribute("data-popover-side", side);
|
|
127
123
|
if (align)
|
|
128
|
-
panel.setAttribute("data-align", align);
|
|
124
|
+
panel.setAttribute("data-popover-align", align);
|
|
129
125
|
const checkboxes = [];
|
|
130
126
|
for (const option of Array.from(select.options)) {
|
|
131
127
|
const row = document.createElement("label");
|
|
132
|
-
row.setAttribute("data-slot", "
|
|
128
|
+
row.setAttribute("data-multiselect-slot", "option");
|
|
133
129
|
const checkbox = document.createElement("input");
|
|
134
130
|
checkbox.type = "checkbox";
|
|
135
131
|
checkbox.checked = option.selected;
|
|
@@ -3,26 +3,24 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview `<ui-multiselect>`: a multi-select styled as a dropdown.
|
|
5
5
|
* @description Light-DOM custom element that progressively enhances a real
|
|
6
|
-
* `<select multiple
|
|
7
|
-
*
|
|
6
|
+
* `<select multiple data-ui="select">`. `appearance: base-select` does not
|
|
7
|
+
* apply to multi-selects in stable engines, so the script hides the
|
|
8
8
|
* select (which remains the form value carrier and source of truth) and
|
|
9
|
-
* stamps a
|
|
9
|
+
* stamps a `[data-ui~="select"]`-look trigger button plus an anchored popover of
|
|
10
10
|
* checkbox rows projected from the options. Checkbox changes write back to
|
|
11
11
|
* `option.selected` and re-dispatch `change` on the select; external writes
|
|
12
12
|
* and form resets flow the other way. Without JavaScript the native
|
|
13
13
|
* multi-select listbox renders: fully functional and accessible.
|
|
14
14
|
*
|
|
15
|
-
* The trigger reads `<first selection> (+N more)`.
|
|
16
|
-
* stable multi-select support this enhancement can retire (see the CSS
|
|
17
|
-
* header note in select.css).
|
|
15
|
+
* The trigger reads `<first selection> (+N more)`.
|
|
18
16
|
*
|
|
19
17
|
* Attributes on `<ui-multiselect>`:
|
|
20
|
-
* - `data-placeholder`: trigger text when nothing is selected.
|
|
21
|
-
* - `data-label-more`: overflow template, default `"(+{n} more)"`.
|
|
22
|
-
* - `data-side` / `data-align`: forwarded to the stamped panel (popover
|
|
18
|
+
* - `data-multiselect-placeholder`: trigger text when nothing is selected.
|
|
19
|
+
* - `data-multiselect-label-more`: overflow template, default `"(+{n} more)"`.
|
|
20
|
+
* - `data-multiselect-side` / `data-multiselect-align`: forwarded to the stamped panel as `data-popover-*` (popover
|
|
23
21
|
* placement matrix).
|
|
24
22
|
*
|
|
25
|
-
* Stamped parts: `multiselect-trigger` (a
|
|
23
|
+
* Stamped parts: `multiselect-trigger` (a `[data-ui~="select"]`-identity button),
|
|
26
24
|
* `multiselect-icon` (chevron), `multiselect-panel` (`[popover]`),
|
|
27
25
|
* `multiselect-option` (label + checkbox per option).
|
|
28
26
|
*/
|
|
@@ -30,8 +28,6 @@
|
|
|
30
28
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.ts";
|
|
31
29
|
import { effect, state } from "../../base/signals.ts";
|
|
32
30
|
|
|
33
|
-
// --- Pure derivations (exported for unit tests only) ---
|
|
34
|
-
|
|
35
31
|
/**
|
|
36
32
|
* @description Formats the trigger label from the selected option labels.
|
|
37
33
|
*
|
|
@@ -50,8 +46,6 @@ function resolveTriggerLabel(
|
|
|
50
46
|
return `${labels[0]} ${moreTemplate.replace("{n}", String(labels.length - 1))}`;
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
// --- Element ---
|
|
54
|
-
|
|
55
49
|
let multiselectIdCounter = 0;
|
|
56
50
|
|
|
57
51
|
class UiMultiselect extends ZazzElement {
|
|
@@ -63,11 +57,11 @@ class UiMultiselect extends ZazzElement {
|
|
|
63
57
|
if (!(select instanceof HTMLSelectElement)) return;
|
|
64
58
|
this.#select = select;
|
|
65
59
|
|
|
66
|
-
const placeholder = this.getAttribute("data-placeholder") ?? "Select…";
|
|
67
|
-
const moreTemplate = this.getAttribute("data-label-more") ?? "(+{n} more)";
|
|
60
|
+
const placeholder = this.getAttribute("data-multiselect-placeholder") ?? "Select…";
|
|
61
|
+
const moreTemplate = this.getAttribute("data-multiselect-label-more") ?? "(+{n} more)";
|
|
68
62
|
|
|
69
63
|
const { trigger, label, panel, checkboxes } = this.#stamp(select);
|
|
70
|
-
select.setAttribute("data-multiselect-
|
|
64
|
+
select.setAttribute("data-multiselect-state", "enhanced");
|
|
71
65
|
|
|
72
66
|
const selectedLabels = (): string[] =>
|
|
73
67
|
Array.from(select.selectedOptions).map((option) => option.label);
|
|
@@ -95,7 +89,7 @@ class UiMultiselect extends ZazzElement {
|
|
|
95
89
|
{ signal },
|
|
96
90
|
);
|
|
97
91
|
|
|
98
|
-
//
|
|
92
|
+
// Mirror popover open state onto the trigger's aria-expanded
|
|
99
93
|
panel.addEventListener(
|
|
100
94
|
"toggle",
|
|
101
95
|
(event) => {
|
|
@@ -121,7 +115,7 @@ class UiMultiselect extends ZazzElement {
|
|
|
121
115
|
protected teardown(): void {
|
|
122
116
|
for (const node of this.#stamped) node.remove();
|
|
123
117
|
this.#stamped = [];
|
|
124
|
-
this.#select?.removeAttribute("data-multiselect-
|
|
118
|
+
this.#select?.removeAttribute("data-multiselect-state");
|
|
125
119
|
this.#select = null;
|
|
126
120
|
}
|
|
127
121
|
|
|
@@ -143,31 +137,31 @@ class UiMultiselect extends ZazzElement {
|
|
|
143
137
|
|
|
144
138
|
const trigger = document.createElement("button");
|
|
145
139
|
trigger.type = "button";
|
|
146
|
-
trigger.
|
|
147
|
-
trigger.setAttribute("data-slot", "
|
|
140
|
+
trigger.dataset.ui = "select";
|
|
141
|
+
trigger.setAttribute("data-multiselect-slot", "trigger");
|
|
148
142
|
trigger.setAttribute("popovertarget", panelId);
|
|
149
143
|
trigger.setAttribute("aria-expanded", "false");
|
|
150
144
|
|
|
151
145
|
const label = document.createElement("span");
|
|
152
|
-
label.setAttribute("data-slot", "
|
|
146
|
+
label.setAttribute("data-multiselect-slot", "label");
|
|
153
147
|
const icon = document.createElement("span");
|
|
154
|
-
icon.setAttribute("data-slot", "
|
|
148
|
+
icon.setAttribute("data-multiselect-slot", "icon");
|
|
155
149
|
icon.setAttribute("aria-hidden", "true");
|
|
156
150
|
trigger.append(label, icon);
|
|
157
151
|
|
|
158
152
|
const panel = document.createElement("div");
|
|
159
153
|
panel.id = panelId;
|
|
160
|
-
panel.setAttribute("data-slot", "
|
|
154
|
+
panel.setAttribute("data-multiselect-slot", "panel");
|
|
161
155
|
panel.setAttribute("popover", "auto");
|
|
162
|
-
const side = this.getAttribute("data-side");
|
|
163
|
-
const align = this.getAttribute("data-align");
|
|
164
|
-
if (side) panel.setAttribute("data-side", side);
|
|
165
|
-
if (align) panel.setAttribute("data-align", align);
|
|
156
|
+
const side = this.getAttribute("data-multiselect-side");
|
|
157
|
+
const align = this.getAttribute("data-multiselect-align");
|
|
158
|
+
if (side) panel.setAttribute("data-popover-side", side);
|
|
159
|
+
if (align) panel.setAttribute("data-popover-align", align);
|
|
166
160
|
|
|
167
161
|
const checkboxes: HTMLInputElement[] = [];
|
|
168
162
|
for (const option of Array.from(select.options)) {
|
|
169
163
|
const row = document.createElement("label");
|
|
170
|
-
row.setAttribute("data-slot", "
|
|
164
|
+
row.setAttribute("data-multiselect-slot", "option");
|
|
171
165
|
const checkbox = document.createElement("input");
|
|
172
166
|
checkbox.type = "checkbox";
|
|
173
167
|
checkbox.checked = option.selected;
|
|
@@ -1,12 +1,37 @@
|
|
|
1
|
-
<div
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<div
|
|
2
|
+
style="
|
|
3
|
+
--display: flex;
|
|
4
|
+
--items: start;
|
|
5
|
+
--gap: 4;
|
|
6
|
+
"
|
|
7
|
+
>
|
|
8
|
+
<div data-ui="field">
|
|
9
|
+
<label data-field-slot="label" for="f-align-start">Start</label>
|
|
10
|
+
<select data-ui="select" id="f-align-start" name="align-start" data-select-align="start">
|
|
5
11
|
<button>
|
|
6
12
|
<selectedcontent></selectedcontent>
|
|
7
13
|
</button>
|
|
8
|
-
<optgroup
|
|
9
|
-
|
|
14
|
+
<optgroup
|
|
15
|
+
label="Sort by"
|
|
16
|
+
style="
|
|
17
|
+
--display: grid;
|
|
18
|
+
--gap: 1px;
|
|
19
|
+
"
|
|
20
|
+
>
|
|
21
|
+
<legend
|
|
22
|
+
style="
|
|
23
|
+
--display: inline-flex;
|
|
24
|
+
--p: 2;
|
|
25
|
+
--font-size: var(--font-size-eyebrow);
|
|
26
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
27
|
+
--leading: var(--leading-eyebrow);
|
|
28
|
+
--tracking: var(--tracking-eyebrow);
|
|
29
|
+
--text-transform: uppercase;
|
|
30
|
+
--text: var(--color-muted-foreground);
|
|
31
|
+
"
|
|
32
|
+
>
|
|
33
|
+
Sort by
|
|
34
|
+
</legend>
|
|
10
35
|
<option value="recent" selected>Most recent</option>
|
|
11
36
|
<option value="popular">Most popular</option>
|
|
12
37
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -15,14 +40,33 @@
|
|
|
15
40
|
</select>
|
|
16
41
|
</div>
|
|
17
42
|
|
|
18
|
-
<div
|
|
19
|
-
<label data-slot="
|
|
20
|
-
<select
|
|
43
|
+
<div data-ui="field">
|
|
44
|
+
<label data-field-slot="label" for="f-align-center">Center</label>
|
|
45
|
+
<select data-ui="select" id="f-align-center" name="align-center" data-select-align="center">
|
|
21
46
|
<button>
|
|
22
47
|
<selectedcontent></selectedcontent>
|
|
23
48
|
</button>
|
|
24
|
-
<optgroup
|
|
25
|
-
|
|
49
|
+
<optgroup
|
|
50
|
+
label="Sort by"
|
|
51
|
+
style="
|
|
52
|
+
--display: grid;
|
|
53
|
+
--gap: 1px;
|
|
54
|
+
"
|
|
55
|
+
>
|
|
56
|
+
<legend
|
|
57
|
+
style="
|
|
58
|
+
--display: inline-flex;
|
|
59
|
+
--p: 2;
|
|
60
|
+
--font-size: var(--font-size-eyebrow);
|
|
61
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
62
|
+
--leading: var(--leading-eyebrow);
|
|
63
|
+
--tracking: var(--tracking-eyebrow);
|
|
64
|
+
--text-transform: uppercase;
|
|
65
|
+
--text: var(--color-muted-foreground);
|
|
66
|
+
"
|
|
67
|
+
>
|
|
68
|
+
Sort by
|
|
69
|
+
</legend>
|
|
26
70
|
<option value="recent" selected>Most recent</option>
|
|
27
71
|
<option value="popular">Most popular</option>
|
|
28
72
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -31,14 +75,33 @@
|
|
|
31
75
|
</select>
|
|
32
76
|
</div>
|
|
33
77
|
|
|
34
|
-
<div
|
|
35
|
-
<label data-slot="
|
|
36
|
-
<select
|
|
78
|
+
<div data-ui="field">
|
|
79
|
+
<label data-field-slot="label" for="f-align-end">End</label>
|
|
80
|
+
<select data-ui="select" id="f-align-end" name="align-end" data-select-align="end">
|
|
37
81
|
<button>
|
|
38
82
|
<selectedcontent></selectedcontent>
|
|
39
83
|
</button>
|
|
40
|
-
<optgroup
|
|
41
|
-
|
|
84
|
+
<optgroup
|
|
85
|
+
label="Sort by"
|
|
86
|
+
style="
|
|
87
|
+
--display: grid;
|
|
88
|
+
--gap: 1px;
|
|
89
|
+
"
|
|
90
|
+
>
|
|
91
|
+
<legend
|
|
92
|
+
style="
|
|
93
|
+
--display: inline-flex;
|
|
94
|
+
--p: 2;
|
|
95
|
+
--font-size: var(--font-size-eyebrow);
|
|
96
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
97
|
+
--leading: var(--leading-eyebrow);
|
|
98
|
+
--tracking: var(--tracking-eyebrow);
|
|
99
|
+
--text-transform: uppercase;
|
|
100
|
+
--text: var(--color-muted-foreground);
|
|
101
|
+
"
|
|
102
|
+
>
|
|
103
|
+
Sort by
|
|
104
|
+
</legend>
|
|
42
105
|
<option value="recent" selected>Most recent</option>
|
|
43
106
|
<option value="popular">Most popular</option>
|
|
44
107
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
<div
|
|
2
|
-
<label data-slot="
|
|
3
|
-
<ui-multiselect
|
|
4
|
-
|
|
1
|
+
<div data-ui="field" style="--max-w: 96">
|
|
2
|
+
<label data-field-slot="label" for="f-tags">Tags</label>
|
|
3
|
+
<ui-multiselect
|
|
4
|
+
data-multiselect-placeholder="Select tags"
|
|
5
|
+
data-multiselect-side="bottom"
|
|
6
|
+
data-multiselect-align="start"
|
|
7
|
+
>
|
|
8
|
+
<select data-ui="select" id="f-tags" name="tags" multiple>
|
|
5
9
|
<option value="design" selected>Design</option>
|
|
6
10
|
<option value="engineering" selected>Engineering</option>
|
|
7
11
|
<option value="research">Research</option>
|
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
<div
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<div
|
|
2
|
+
style="
|
|
3
|
+
--display: grid;
|
|
4
|
+
--place-items: center;
|
|
5
|
+
--grid-cols: 2;
|
|
6
|
+
--gap: 4;
|
|
7
|
+
"
|
|
8
|
+
>
|
|
9
|
+
<div data-ui="field">
|
|
10
|
+
<label data-field-slot="label" for="f-side-top">Top</label>
|
|
11
|
+
<select data-ui="select" id="f-side-top" name="side-top" data-select-side="top">
|
|
5
12
|
<button>
|
|
6
13
|
<selectedcontent></selectedcontent>
|
|
7
14
|
</button>
|
|
8
|
-
<optgroup
|
|
9
|
-
|
|
15
|
+
<optgroup
|
|
16
|
+
label="Sort by"
|
|
17
|
+
style="
|
|
18
|
+
--display: grid;
|
|
19
|
+
--gap: 1px;
|
|
20
|
+
"
|
|
21
|
+
>
|
|
22
|
+
<legend
|
|
23
|
+
style="
|
|
24
|
+
--display: inline-flex;
|
|
25
|
+
--p: 2;
|
|
26
|
+
--font-size: var(--font-size-eyebrow);
|
|
27
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
28
|
+
--leading: var(--leading-eyebrow);
|
|
29
|
+
--tracking: var(--tracking-eyebrow);
|
|
30
|
+
--text-transform: uppercase;
|
|
31
|
+
--text: var(--color-muted-foreground);
|
|
32
|
+
"
|
|
33
|
+
>
|
|
34
|
+
Sort by
|
|
35
|
+
</legend>
|
|
10
36
|
<option value="recent" selected>Most recent</option>
|
|
11
37
|
<option value="popular">Most popular</option>
|
|
12
38
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -15,14 +41,33 @@
|
|
|
15
41
|
</select>
|
|
16
42
|
</div>
|
|
17
43
|
|
|
18
|
-
<div
|
|
19
|
-
<label data-slot="
|
|
20
|
-
<select
|
|
44
|
+
<div data-ui="field">
|
|
45
|
+
<label data-field-slot="label" for="f-side-bottom">Bottom</label>
|
|
46
|
+
<select data-ui="select" id="f-side-bottom" name="side-bottom" data-select-side="bottom">
|
|
21
47
|
<button>
|
|
22
48
|
<selectedcontent></selectedcontent>
|
|
23
49
|
</button>
|
|
24
|
-
<optgroup
|
|
25
|
-
|
|
50
|
+
<optgroup
|
|
51
|
+
label="Sort by"
|
|
52
|
+
style="
|
|
53
|
+
--display: grid;
|
|
54
|
+
--gap: 1px;
|
|
55
|
+
"
|
|
56
|
+
>
|
|
57
|
+
<legend
|
|
58
|
+
style="
|
|
59
|
+
--display: inline-flex;
|
|
60
|
+
--p: 2;
|
|
61
|
+
--font-size: var(--font-size-eyebrow);
|
|
62
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
63
|
+
--leading: var(--leading-eyebrow);
|
|
64
|
+
--tracking: var(--tracking-eyebrow);
|
|
65
|
+
--text-transform: uppercase;
|
|
66
|
+
--text: var(--color-muted-foreground);
|
|
67
|
+
"
|
|
68
|
+
>
|
|
69
|
+
Sort by
|
|
70
|
+
</legend>
|
|
26
71
|
<option value="recent" selected>Most recent</option>
|
|
27
72
|
<option value="popular">Most popular</option>
|
|
28
73
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -31,14 +76,33 @@
|
|
|
31
76
|
</select>
|
|
32
77
|
</div>
|
|
33
78
|
|
|
34
|
-
<div
|
|
35
|
-
<label data-slot="
|
|
36
|
-
<select
|
|
79
|
+
<div data-ui="field">
|
|
80
|
+
<label data-field-slot="label" for="f-side-left">Left</label>
|
|
81
|
+
<select data-ui="select" id="f-side-left" name="side-left" data-select-side="left">
|
|
37
82
|
<button>
|
|
38
83
|
<selectedcontent></selectedcontent>
|
|
39
84
|
</button>
|
|
40
|
-
<optgroup
|
|
41
|
-
|
|
85
|
+
<optgroup
|
|
86
|
+
label="Sort by"
|
|
87
|
+
style="
|
|
88
|
+
--display: grid;
|
|
89
|
+
--gap: 1px;
|
|
90
|
+
"
|
|
91
|
+
>
|
|
92
|
+
<legend
|
|
93
|
+
style="
|
|
94
|
+
--display: inline-flex;
|
|
95
|
+
--p: 2;
|
|
96
|
+
--font-size: var(--font-size-eyebrow);
|
|
97
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
98
|
+
--leading: var(--leading-eyebrow);
|
|
99
|
+
--tracking: var(--tracking-eyebrow);
|
|
100
|
+
--text-transform: uppercase;
|
|
101
|
+
--text: var(--color-muted-foreground);
|
|
102
|
+
"
|
|
103
|
+
>
|
|
104
|
+
Sort by
|
|
105
|
+
</legend>
|
|
42
106
|
<option value="recent" selected>Most recent</option>
|
|
43
107
|
<option value="popular">Most popular</option>
|
|
44
108
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -47,14 +111,33 @@
|
|
|
47
111
|
</select>
|
|
48
112
|
</div>
|
|
49
113
|
|
|
50
|
-
<div
|
|
51
|
-
<label data-slot="
|
|
52
|
-
<select
|
|
114
|
+
<div data-ui="field">
|
|
115
|
+
<label data-field-slot="label" for="f-side-right">Right</label>
|
|
116
|
+
<select data-ui="select" id="f-side-right" name="side-right" data-select-side="right">
|
|
53
117
|
<button>
|
|
54
118
|
<selectedcontent></selectedcontent>
|
|
55
119
|
</button>
|
|
56
|
-
<optgroup
|
|
57
|
-
|
|
120
|
+
<optgroup
|
|
121
|
+
label="Sort by"
|
|
122
|
+
style="
|
|
123
|
+
--display: grid;
|
|
124
|
+
--gap: 1px;
|
|
125
|
+
"
|
|
126
|
+
>
|
|
127
|
+
<legend
|
|
128
|
+
style="
|
|
129
|
+
--display: inline-flex;
|
|
130
|
+
--p: 2;
|
|
131
|
+
--font-size: var(--font-size-eyebrow);
|
|
132
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
133
|
+
--leading: var(--leading-eyebrow);
|
|
134
|
+
--tracking: var(--tracking-eyebrow);
|
|
135
|
+
--text-transform: uppercase;
|
|
136
|
+
--text: var(--color-muted-foreground);
|
|
137
|
+
"
|
|
138
|
+
>
|
|
139
|
+
Sort by
|
|
140
|
+
</legend>
|
|
58
141
|
<option value="recent" selected>Most recent</option>
|
|
59
142
|
<option value="popular">Most popular</option>
|
|
60
143
|
<option value="price-asc">Price: low to high</option>
|