@sdxc/ui 0.0.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +812 -0
- package/dist/animations/index.d.ts +12 -0
- package/dist/animations/index.js +12 -0
- package/dist/animations/keyframes.d.ts +162 -0
- package/dist/animations/keyframes.js +297 -0
- package/dist/animations/scroll.d.ts +154 -0
- package/dist/animations/scroll.js +228 -0
- package/dist/animations/tokens.d.ts +47 -0
- package/dist/animations/tokens.js +47 -0
- package/dist/animations/transitions.d.ts +143 -0
- package/dist/animations/transitions.js +147 -0
- package/dist/behaviors/announcer.d.ts +90 -0
- package/dist/behaviors/announcer.js +93 -0
- package/dist/behaviors/calendar-model.d.ts +218 -0
- package/dist/behaviors/calendar-model.js +376 -0
- package/dist/behaviors/drag-session.d.ts +119 -0
- package/dist/behaviors/drag-session.js +110 -0
- package/dist/behaviors/filter-model.d.ts +117 -0
- package/dist/behaviors/filter-model.js +185 -0
- package/dist/behaviors/index.d.ts +16 -0
- package/dist/behaviors/index.js +16 -0
- package/dist/behaviors/resize-session.d.ts +115 -0
- package/dist/behaviors/resize-session.js +157 -0
- package/dist/behaviors/scroll-follow-model.d.ts +180 -0
- package/dist/behaviors/scroll-follow-model.js +197 -0
- package/dist/behaviors/selection-model.d.ts +129 -0
- package/dist/behaviors/selection-model.js +259 -0
- package/dist/behaviors/toaster.d.ts +144 -0
- package/dist/behaviors/toaster.js +228 -0
- package/dist/components/accordion.d.ts +93 -0
- package/dist/components/accordion.js +165 -0
- package/dist/components/alert-dialog.d.ts +110 -0
- package/dist/components/alert-dialog.js +169 -0
- package/dist/components/alert.d.ts +109 -0
- package/dist/components/alert.js +160 -0
- package/dist/components/aspect-ratio.d.ts +44 -0
- package/dist/components/aspect-ratio.js +35 -0
- package/dist/components/attachment.d.ts +146 -0
- package/dist/components/attachment.js +320 -0
- package/dist/components/avatar.d.ts +118 -0
- package/dist/components/avatar.js +89 -0
- package/dist/components/badge.d.ts +66 -0
- package/dist/components/badge.js +129 -0
- package/dist/components/breadcrumbs.d.ts +67 -0
- package/dist/components/breadcrumbs.js +121 -0
- package/dist/components/bubble.d.ts +91 -0
- package/dist/components/bubble.js +216 -0
- package/dist/components/button.d.ts +78 -0
- package/dist/components/button.js +207 -0
- package/dist/components/calendar.d.ts +166 -0
- package/dist/components/calendar.js +320 -0
- package/dist/components/card.d.ts +82 -0
- package/dist/components/card.js +126 -0
- package/dist/components/carousel.d.ts +96 -0
- package/dist/components/carousel.js +214 -0
- package/dist/components/chart.d.ts +485 -0
- package/dist/components/chart.js +563 -0
- package/dist/components/checkbox-group.d.ts +58 -0
- package/dist/components/checkbox-group.js +53 -0
- package/dist/components/checkbox.d.ts +61 -0
- package/dist/components/checkbox.js +81 -0
- package/dist/components/color-area.d.ts +83 -0
- package/dist/components/color-area.js +251 -0
- package/dist/components/color-field.d.ts +128 -0
- package/dist/components/color-field.js +73 -0
- package/dist/components/color-picker.d.ts +132 -0
- package/dist/components/color-picker.js +183 -0
- package/dist/components/color-slider.d.ts +103 -0
- package/dist/components/color-slider.js +198 -0
- package/dist/components/color-swatch-picker.d.ts +106 -0
- package/dist/components/color-swatch-picker.js +75 -0
- package/dist/components/color-swatch.d.ts +57 -0
- package/dist/components/color-swatch.js +82 -0
- package/dist/components/color-wheel.d.ts +58 -0
- package/dist/components/color-wheel.js +160 -0
- package/dist/components/combobox.d.ts +73 -0
- package/dist/components/combobox.js +108 -0
- package/dist/components/command.d.ts +80 -0
- package/dist/components/command.js +151 -0
- package/dist/components/confirm.d.ts +124 -0
- package/dist/components/confirm.js +56 -0
- package/dist/components/context-menu.d.ts +108 -0
- package/dist/components/context-menu.js +200 -0
- package/dist/components/date-field.d.ts +110 -0
- package/dist/components/date-field.js +49 -0
- package/dist/components/date-picker.d.ts +136 -0
- package/dist/components/date-picker.js +155 -0
- package/dist/components/date-range-picker.d.ts +152 -0
- package/dist/components/date-range-picker.js +106 -0
- package/dist/components/description.d.ts +36 -0
- package/dist/components/description.js +21 -0
- package/dist/components/dialog.d.ts +97 -0
- package/dist/components/dialog.js +203 -0
- package/dist/components/disclosure.d.ts +85 -0
- package/dist/components/disclosure.js +180 -0
- package/dist/components/drawer.d.ts +82 -0
- package/dist/components/drawer.js +162 -0
- package/dist/components/drop-indicator.d.ts +43 -0
- package/dist/components/drop-indicator.js +47 -0
- package/dist/components/drop-zone.d.ts +73 -0
- package/dist/components/drop-zone.js +54 -0
- package/dist/components/empty.d.ts +89 -0
- package/dist/components/empty.js +129 -0
- package/dist/components/field-error.d.ts +41 -0
- package/dist/components/field-error.js +36 -0
- package/dist/components/file-trigger.d.ts +84 -0
- package/dist/components/file-trigger.js +169 -0
- package/dist/components/form.d.ts +118 -0
- package/dist/components/form.js +113 -0
- package/dist/components/grid-list.d.ts +112 -0
- package/dist/components/grid-list.js +220 -0
- package/dist/components/group.d.ts +45 -0
- package/dist/components/group.js +44 -0
- package/dist/components/header.d.ts +33 -0
- package/dist/components/header.js +29 -0
- package/dist/components/heading-scope.d.ts +83 -0
- package/dist/components/heading-scope.js +82 -0
- package/dist/components/heading.d.ts +50 -0
- package/dist/components/heading.js +31 -0
- package/dist/components/hover-card.d.ts +77 -0
- package/dist/components/hover-card.js +151 -0
- package/dist/components/image-placeholder.d.ts +105 -0
- package/dist/components/image-placeholder.js +212 -0
- package/dist/components/index.d.ts +109 -0
- package/dist/components/index.js +109 -0
- package/dist/components/input.d.ts +53 -0
- package/dist/components/input.js +76 -0
- package/dist/components/item.d.ts +97 -0
- package/dist/components/item.js +185 -0
- package/dist/components/keyboard.d.ts +33 -0
- package/dist/components/keyboard.js +20 -0
- package/dist/components/label.d.ts +38 -0
- package/dist/components/label.js +24 -0
- package/dist/components/link-button.d.ts +59 -0
- package/dist/components/link-button.js +174 -0
- package/dist/components/link.d.ts +43 -0
- package/dist/components/link.js +85 -0
- package/dist/components/listbox.d.ts +119 -0
- package/dist/components/listbox.js +114 -0
- package/dist/components/logo.d.ts +117 -0
- package/dist/components/logo.js +89 -0
- package/dist/components/marker.d.ts +82 -0
- package/dist/components/marker.js +163 -0
- package/dist/components/menu.d.ts +90 -0
- package/dist/components/menu.js +146 -0
- package/dist/components/menubar.d.ts +54 -0
- package/dist/components/menubar.js +118 -0
- package/dist/components/message-scroller.d.ts +109 -0
- package/dist/components/message-scroller.js +180 -0
- package/dist/components/message.d.ts +104 -0
- package/dist/components/message.js +200 -0
- package/dist/components/meter.d.ts +60 -0
- package/dist/components/meter.js +110 -0
- package/dist/components/modal.d.ts +71 -0
- package/dist/components/modal.js +120 -0
- package/dist/components/nav-link.d.ts +53 -0
- package/dist/components/nav-link.js +83 -0
- package/dist/components/navigation-menu.d.ts +150 -0
- package/dist/components/navigation-menu.js +381 -0
- package/dist/components/number-field.d.ts +76 -0
- package/dist/components/number-field.js +190 -0
- package/dist/components/otp-field.d.ts +68 -0
- package/dist/components/otp-field.js +46 -0
- package/dist/components/overlay-arrow.d.ts +51 -0
- package/dist/components/overlay-arrow.js +77 -0
- package/dist/components/pagination.d.ts +67 -0
- package/dist/components/pagination.js +164 -0
- package/dist/components/popover.d.ts +69 -0
- package/dist/components/popover.js +68 -0
- package/dist/components/progress-bar.d.ts +53 -0
- package/dist/components/progress-bar.js +90 -0
- package/dist/components/radio-group.d.ts +102 -0
- package/dist/components/radio-group.js +114 -0
- package/dist/components/range-calendar.d.ts +169 -0
- package/dist/components/range-calendar.js +216 -0
- package/dist/components/resizable.d.ts +98 -0
- package/dist/components/resizable.js +151 -0
- package/dist/components/scroll-area.d.ts +54 -0
- package/dist/components/scroll-area.js +89 -0
- package/dist/components/search-field.d.ts +55 -0
- package/dist/components/search-field.js +49 -0
- package/dist/components/section.d.ts +37 -0
- package/dist/components/section.js +22 -0
- package/dist/components/select.d.ts +96 -0
- package/dist/components/select.js +285 -0
- package/dist/components/selection-indicator.d.ts +47 -0
- package/dist/components/selection-indicator.js +50 -0
- package/dist/components/sentinel-row.d.ts +22 -0
- package/dist/components/sentinel-row.js +29 -0
- package/dist/components/separator.d.ts +35 -0
- package/dist/components/separator.js +48 -0
- package/dist/components/shared-element.d.ts +45 -0
- package/dist/components/shared-element.js +48 -0
- package/dist/components/sheet.d.ts +78 -0
- package/dist/components/sheet.js +167 -0
- package/dist/components/sidebar.d.ts +288 -0
- package/dist/components/sidebar.js +1068 -0
- package/dist/components/skeleton.d.ts +36 -0
- package/dist/components/skeleton.js +38 -0
- package/dist/components/slider.d.ts +102 -0
- package/dist/components/slider.js +179 -0
- package/dist/components/spinner.d.ts +55 -0
- package/dist/components/spinner.js +51 -0
- package/dist/components/switch.d.ts +47 -0
- package/dist/components/switch.js +82 -0
- package/dist/components/table.d.ts +139 -0
- package/dist/components/table.js +216 -0
- package/dist/components/tabs.d.ts +124 -0
- package/dist/components/tabs.js +246 -0
- package/dist/components/tag-group.d.ts +83 -0
- package/dist/components/tag-group.js +157 -0
- package/dist/components/text-field.d.ts +119 -0
- package/dist/components/text-field.js +51 -0
- package/dist/components/text.d.ts +34 -0
- package/dist/components/text.js +19 -0
- package/dist/components/textarea.d.ts +52 -0
- package/dist/components/textarea.js +82 -0
- package/dist/components/time-field.d.ts +110 -0
- package/dist/components/time-field.js +48 -0
- package/dist/components/toast.d.ts +149 -0
- package/dist/components/toast.js +365 -0
- package/dist/components/toggle-button.d.ts +115 -0
- package/dist/components/toggle-button.js +237 -0
- package/dist/components/toolbar.d.ts +47 -0
- package/dist/components/toolbar.js +54 -0
- package/dist/components/tooltip.d.ts +52 -0
- package/dist/components/tooltip.js +92 -0
- package/dist/components/tree.d.ts +123 -0
- package/dist/components/tree.js +239 -0
- package/dist/components/typeset.d.ts +53 -0
- package/dist/components/typeset.js +271 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/mixins/aria-checked.d.ts +42 -0
- package/dist/mixins/aria-checked.js +127 -0
- package/dist/mixins/attachment-trigger.d.ts +64 -0
- package/dist/mixins/attachment-trigger.js +190 -0
- package/dist/mixins/calendar-keys.d.ts +27 -0
- package/dist/mixins/calendar-keys.js +113 -0
- package/dist/mixins/carousel-controls.d.ts +30 -0
- package/dist/mixins/carousel-controls.js +222 -0
- package/dist/mixins/chart-tooltip.d.ts +118 -0
- package/dist/mixins/chart-tooltip.js +323 -0
- package/dist/mixins/clear-field.d.ts +60 -0
- package/dist/mixins/clear-field.js +100 -0
- package/dist/mixins/color-area-drag.d.ts +58 -0
- package/dist/mixins/color-area-drag.js +162 -0
- package/dist/mixins/color-channel-sync.d.ts +73 -0
- package/dist/mixins/color-channel-sync.js +169 -0
- package/dist/mixins/color-preview.d.ts +28 -0
- package/dist/mixins/color-preview.js +77 -0
- package/dist/mixins/color-wheel-drag.d.ts +58 -0
- package/dist/mixins/color-wheel-drag.js +139 -0
- package/dist/mixins/combobox-filter.d.ts +59 -0
- package/dist/mixins/combobox-filter.js +81 -0
- package/dist/mixins/command-filter.d.ts +55 -0
- package/dist/mixins/command-filter.js +121 -0
- package/dist/mixins/command-keys.d.ts +31 -0
- package/dist/mixins/command-keys.js +116 -0
- package/dist/mixins/context-menu.d.ts +24 -0
- package/dist/mixins/context-menu.js +64 -0
- package/dist/mixins/copy-to-clipboard.d.ts +64 -0
- package/dist/mixins/copy-to-clipboard.js +109 -0
- package/dist/mixins/dismiss.d.ts +77 -0
- package/dist/mixins/dismiss.js +151 -0
- package/dist/mixins/drag-reorder.d.ts +88 -0
- package/dist/mixins/drag-reorder.js +214 -0
- package/dist/mixins/drop-zone.d.ts +52 -0
- package/dist/mixins/drop-zone.js +132 -0
- package/dist/mixins/dual-range.d.ts +60 -0
- package/dist/mixins/dual-range.js +100 -0
- package/dist/mixins/grid-list-keys.d.ts +34 -0
- package/dist/mixins/grid-list-keys.js +260 -0
- package/dist/mixins/heading-level-fallback.d.ts +81 -0
- package/dist/mixins/heading-level-fallback.js +112 -0
- package/dist/mixins/hotkey.d.ts +26 -0
- package/dist/mixins/hotkey.js +132 -0
- package/dist/mixins/image-fallback.d.ts +57 -0
- package/dist/mixins/image-fallback.js +86 -0
- package/dist/mixins/index.d.ts +48 -0
- package/dist/mixins/index.js +48 -0
- package/dist/mixins/listbox-keys.d.ts +52 -0
- package/dist/mixins/listbox-keys.js +63 -0
- package/dist/mixins/long-press.d.ts +76 -0
- package/dist/mixins/long-press.js +130 -0
- package/dist/mixins/menu-keys.d.ts +40 -0
- package/dist/mixins/menu-keys.js +117 -0
- package/dist/mixins/menubar-keys.d.ts +59 -0
- package/dist/mixins/menubar-keys.js +230 -0
- package/dist/mixins/message-follow.d.ts +56 -0
- package/dist/mixins/message-follow.js +368 -0
- package/dist/mixins/otp-slots.d.ts +53 -0
- package/dist/mixins/otp-slots.js +175 -0
- package/dist/mixins/persist.d.ts +36 -0
- package/dist/mixins/persist.js +78 -0
- package/dist/mixins/press-toggle.d.ts +43 -0
- package/dist/mixins/press-toggle.js +61 -0
- package/dist/mixins/range-preview.d.ts +26 -0
- package/dist/mixins/range-preview.js +120 -0
- package/dist/mixins/resize-handle.d.ts +101 -0
- package/dist/mixins/resize-handle.js +288 -0
- package/dist/mixins/stepper.d.ts +81 -0
- package/dist/mixins/stepper.js +194 -0
- package/dist/mixins/tab-keys.d.ts +30 -0
- package/dist/mixins/tab-keys.js +63 -0
- package/dist/mixins/theme-toggle.d.ts +82 -0
- package/dist/mixins/theme-toggle.js +158 -0
- package/dist/mixins/track-host-node.d.ts +34 -0
- package/dist/mixins/track-host-node.js +42 -0
- package/dist/mixins/treeKeys.d.ts +57 -0
- package/dist/mixins/treeKeys.js +266 -0
- package/dist/mixins/validate.d.ts +65 -0
- package/dist/mixins/validate.js +139 -0
- package/dist/mixins/view-transition.d.ts +56 -0
- package/dist/mixins/view-transition.js +111 -0
- package/dist/styles/chart-palette.d.ts +34 -0
- package/dist/styles/chart-palette.js +27 -0
- package/dist/styles/field-stack-layout.d.ts +27 -0
- package/dist/styles/field-stack-layout.js +16 -0
- package/dist/styles/floating-surface.d.ts +32 -0
- package/dist/styles/floating-surface.js +30 -0
- package/dist/styles/graphic-host.d.ts +25 -0
- package/dist/styles/graphic-host.js +18 -0
- package/dist/styles/index.d.ts +20 -0
- package/dist/styles/index.js +20 -0
- package/dist/styles/interactive-transition.d.ts +32 -0
- package/dist/styles/interactive-transition.js +32 -0
- package/dist/styles/legend-toggle.d.ts +29 -0
- package/dist/styles/legend-toggle.js +24 -0
- package/dist/styles/output-caption-text.d.ts +22 -0
- package/dist/styles/output-caption-text.js +15 -0
- package/dist/styles/panel-chrome.d.ts +34 -0
- package/dist/styles/panel-chrome.js +26 -0
- package/dist/styles/range-thumb-appearance.d.ts +36 -0
- package/dist/styles/range-thumb-appearance.js +76 -0
- package/dist/styles/rtl-aware-gradient-direction.d.ts +28 -0
- package/dist/styles/rtl-aware-gradient-direction.js +28 -0
- package/dist/styles/semantic-color-panel.d.ts +35 -0
- package/dist/styles/semantic-color-panel.js +41 -0
- package/dist/utils/chart-marker-indices.d.ts +22 -0
- package/dist/utils/chart-marker-indices.js +45 -0
- package/dist/utils/chart-path.d.ts +86 -0
- package/dist/utils/chart-path.js +122 -0
- package/dist/utils/chart-scale.d.ts +182 -0
- package/dist/utils/chart-scale.js +221 -0
- package/dist/utils/color-math.d.ts +252 -0
- package/dist/utils/color-math.js +480 -0
- package/dist/utils/command-event.d.ts +24 -0
- package/dist/utils/command-event.js +26 -0
- package/dist/utils/css-styles.d.ts +21 -0
- package/dist/utils/css-styles.js +11 -0
- package/dist/utils/decorative-icon.d.ts +15 -0
- package/dist/utils/decorative-icon.js +15 -0
- package/dist/utils/disabled-selector.d.ts +22 -0
- package/dist/utils/disabled-selector.js +22 -0
- package/dist/utils/dispatch-change.d.ts +17 -0
- package/dist/utils/dispatch-change.js +19 -0
- package/dist/utils/field-parts.d.ts +26 -0
- package/dist/utils/field-parts.js +12 -0
- package/dist/utils/full-turn-radians.d.ts +16 -0
- package/dist/utils/full-turn-radians.js +16 -0
- package/dist/utils/geometry.d.ts +14 -0
- package/dist/utils/geometry.js +9 -0
- package/dist/utils/has-accessible-text.d.ts +19 -0
- package/dist/utils/has-accessible-text.js +30 -0
- package/dist/utils/hue-spectrum.d.ts +19 -0
- package/dist/utils/hue-spectrum.js +19 -0
- package/dist/utils/index.d.ts +35 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/is-new-primary-press.d.ts +29 -0
- package/dist/utils/is-new-primary-press.js +31 -0
- package/dist/utils/keyboard-nav.d.ts +64 -0
- package/dist/utils/keyboard-nav.js +79 -0
- package/dist/utils/merge-style.d.ts +33 -0
- package/dist/utils/merge-style.js +30 -0
- package/dist/utils/paired-range-inputs.d.ts +26 -0
- package/dist/utils/paired-range-inputs.js +29 -0
- package/dist/utils/placement.d.ts +18 -0
- package/dist/utils/placement.js +12 -0
- package/dist/utils/prefers-reduced-motion.d.ts +17 -0
- package/dist/utils/prefers-reduced-motion.js +19 -0
- package/dist/utils/resolve-field-wiring.d.ts +83 -0
- package/dist/utils/resolve-field-wiring.js +53 -0
- package/dist/utils/resolve-fill-percent.d.ts +28 -0
- package/dist/utils/resolve-fill-percent.js +34 -0
- package/dist/utils/round-precision.d.ts +22 -0
- package/dist/utils/round-precision.js +25 -0
- package/dist/utils/semantic-color-panel.d.ts +35 -0
- package/dist/utils/semantic-color-panel.js +28 -0
- package/dist/utils/semantic-color.d.ts +17 -0
- package/dist/utils/semantic-color.js +11 -0
- package/dist/utils/warn-if-no-accessible-name.d.ts +52 -0
- package/dist/utils/warn-if-no-accessible-name.js +55 -0
- package/dist/utils/write-cookie.d.ts +35 -0
- package/dist/utils/write-cookie.js +37 -0
- package/package.json +32 -0
- package/src/reset.css +223 -0
- package/src/theme.css +146 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-updates a ColorField's paired swatch preview as the person typing
|
|
3
|
+
* into its text control lands on a value the chosen color notation actually
|
|
4
|
+
* accepts, reflecting every keystroke a script can observe that no CSS
|
|
5
|
+
* selector or HTML attribute can react to on its own.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
11
|
+
import { formatRgb, parseColor } from "../utils/color-math.js";
|
|
12
|
+
/**
|
|
13
|
+
* CSS custom property {@link colorPreview} writes a successfully parsed
|
|
14
|
+
* color onto. A swatch already paints its own fill from this same property,
|
|
15
|
+
* so overwriting it here is the whole update.
|
|
16
|
+
*/
|
|
17
|
+
const SWATCH_VALUE_PROPERTY = "--ui-color-swatch-value";
|
|
18
|
+
/**
|
|
19
|
+
* Selector {@link colorPreview} uses to find its host's paired swatch: any
|
|
20
|
+
* descendant already carrying `data-slot="swatch"`, set the moment a
|
|
21
|
+
* swatch renders, regardless of which component composes it into the field.
|
|
22
|
+
*/
|
|
23
|
+
const SWATCH_SELECTOR = '[data-slot="swatch"]';
|
|
24
|
+
/**
|
|
25
|
+
* Finds the single swatch element nested under `host`, identified by
|
|
26
|
+
* {@link SWATCH_SELECTOR}, regardless of the swatch's position among the
|
|
27
|
+
* host's other descendants.
|
|
28
|
+
*
|
|
29
|
+
* @param host ColorField wrapping host the swatch renders inside.
|
|
30
|
+
* @returns The matched swatch element, or `null` when the host renders
|
|
31
|
+
* without one.
|
|
32
|
+
*/
|
|
33
|
+
function findSwatch(host) {
|
|
34
|
+
return host.querySelector(SWATCH_SELECTOR);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Live-updates a ColorField's paired swatch preview as its text control's
|
|
38
|
+
* value changes, running each `input` event's value through `parseColor()`
|
|
39
|
+
* and writing successful parses onto the swatch found via {@link findSwatch}.
|
|
40
|
+
*
|
|
41
|
+
* @returns A mixin descriptor for a ColorField wrapping host's `mix` prop.
|
|
42
|
+
* @example
|
|
43
|
+
* <div mix={colorPreview()}>
|
|
44
|
+
* <input
|
|
45
|
+
* type="text"
|
|
46
|
+
* pattern="#[0-9a-fA-F]{6}"
|
|
47
|
+
* defaultValue="#3b82f6"
|
|
48
|
+
* aria-label={t("colorField.label")}
|
|
49
|
+
* />
|
|
50
|
+
* <ColorSwatch value="#3b82f6" />
|
|
51
|
+
* </div>
|
|
52
|
+
*/
|
|
53
|
+
export const colorPreview = createMixin((handle) => {
|
|
54
|
+
let hasWarnedMissingSwatch = false;
|
|
55
|
+
return () => createElement(handle.element, {
|
|
56
|
+
mix: [
|
|
57
|
+
on("input", (event) => {
|
|
58
|
+
let target = event.target;
|
|
59
|
+
if (!(target instanceof HTMLInputElement))
|
|
60
|
+
return;
|
|
61
|
+
let parsed = parseColor(target.value);
|
|
62
|
+
if (parsed === null)
|
|
63
|
+
return;
|
|
64
|
+
let host = event.currentTarget;
|
|
65
|
+
let swatch = findSwatch(host);
|
|
66
|
+
if (swatch === null) {
|
|
67
|
+
if (import.meta.env.DEV && !hasWarnedMissingSwatch) {
|
|
68
|
+
hasWarnedMissingSwatch = true;
|
|
69
|
+
console.warn(`colorPreview(): no element matching ${SWATCH_SELECTOR} found beneath the ColorField host to update.`);
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
swatch.style.setProperty(SWATCH_VALUE_PROPERTY, formatRgb(parsed));
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reshapes a ColorWheel's underlying hue input into a ring the moment it
|
|
3
|
+
* attaches, then drags the root as one angular gesture: measures the
|
|
4
|
+
* pointer's clockwise angle around the root's center, converts it to a hue,
|
|
5
|
+
* and writes the hue input's `valueAsNumber`.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { MixinFactory } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* `data-*` attribute {@link colorWheelDrag} sets to
|
|
13
|
+
* {@link COLOR_WHEEL_SHAPE_CIRCULAR} on its host the moment it attaches, so
|
|
14
|
+
* ColorWheel's own static `css()` styling repaints its track as a ring.
|
|
15
|
+
*/
|
|
16
|
+
export declare const COLOR_WHEEL_SHAPE_ATTRIBUTE = "data-shape";
|
|
17
|
+
/**
|
|
18
|
+
* Value {@link colorWheelDrag} writes to {@link COLOR_WHEEL_SHAPE_ATTRIBUTE}
|
|
19
|
+
* on attach.
|
|
20
|
+
*/
|
|
21
|
+
export declare const COLOR_WHEEL_SHAPE_CIRCULAR = "circular";
|
|
22
|
+
/** DOM event type dispatched by {@link colorWheelDrag} on its host whenever a pointer gesture writes the underlying hue input to a new value. */
|
|
23
|
+
declare const COLOR_WHEEL_CHANGE_EVENT: "ui:color-wheel-change";
|
|
24
|
+
declare global {
|
|
25
|
+
interface HTMLElementEventMap {
|
|
26
|
+
[COLOR_WHEEL_CHANGE_EVENT]: ColorWheelChangeEvent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Dispatched on a ColorWheel's host by {@link colorWheelDrag} whenever a
|
|
31
|
+
* pointer gesture writes the underlying hue input to a new value, so a
|
|
32
|
+
* consumer can react to the settled hue without reading the `<input>` itself.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ColorWheelChangeEvent extends Event {
|
|
35
|
+
/** Settled hue, in degrees, `0`–`360`, after mapping the pointer's angle through {@link angleToHue}. */
|
|
36
|
+
readonly hue: number;
|
|
37
|
+
/**
|
|
38
|
+
* @param hue Settled hue value at dispatch time.
|
|
39
|
+
*/
|
|
40
|
+
constructor(hue: number);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adds pointer-driven, angular dragging to a ColorWheel root, reshaping its
|
|
44
|
+
* hue input into a ring via {@link COLOR_WHEEL_SHAPE_ATTRIBUTE}, then mapping
|
|
45
|
+
* each captured pointer's angle to a hue and dispatching {@link ColorWheelChangeEvent} on settled values.
|
|
46
|
+
*
|
|
47
|
+
* @returns A mixin descriptor for a ColorWheel root's `mix` prop.
|
|
48
|
+
* @example
|
|
49
|
+
* <div
|
|
50
|
+
* role="group"
|
|
51
|
+
* aria-label={hueLabel}
|
|
52
|
+
* mix={[colorWheelDrag(), css({ position: "relative" })]}
|
|
53
|
+
* >
|
|
54
|
+
* <input type="range" min={0} max={360} step={1} defaultValue={0} aria-label={hueLabel} />
|
|
55
|
+
* </div>
|
|
56
|
+
*/
|
|
57
|
+
export declare const colorWheelDrag: MixinFactory<HTMLElement>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reshapes a ColorWheel's underlying hue input into a ring the moment it
|
|
3
|
+
* attaches, then drags the root as one angular gesture: measures the
|
|
4
|
+
* pointer's clockwise angle around the root's center, converts it to a hue,
|
|
5
|
+
* and writes the hue input's `valueAsNumber`.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
11
|
+
import { angleFromCenter, angleToHue, roundChannel } from "../utils/color-math.js";
|
|
12
|
+
/**
|
|
13
|
+
* `data-*` attribute {@link colorWheelDrag} sets to
|
|
14
|
+
* {@link COLOR_WHEEL_SHAPE_CIRCULAR} on its host the moment it attaches, so
|
|
15
|
+
* ColorWheel's own static `css()` styling repaints its track as a ring.
|
|
16
|
+
*/
|
|
17
|
+
export const COLOR_WHEEL_SHAPE_ATTRIBUTE = "data-shape";
|
|
18
|
+
/**
|
|
19
|
+
* Value {@link colorWheelDrag} writes to {@link COLOR_WHEEL_SHAPE_ATTRIBUTE}
|
|
20
|
+
* on attach.
|
|
21
|
+
*/
|
|
22
|
+
export const COLOR_WHEEL_SHAPE_CIRCULAR = "circular";
|
|
23
|
+
/** DOM event type dispatched by {@link colorWheelDrag} on its host whenever a pointer gesture writes the underlying hue input to a new value. */
|
|
24
|
+
const COLOR_WHEEL_CHANGE_EVENT = "ui:color-wheel-change";
|
|
25
|
+
/**
|
|
26
|
+
* Dispatched on a ColorWheel's host by {@link colorWheelDrag} whenever a
|
|
27
|
+
* pointer gesture writes the underlying hue input to a new value, so a
|
|
28
|
+
* consumer can react to the settled hue without reading the `<input>` itself.
|
|
29
|
+
*/
|
|
30
|
+
export class ColorWheelChangeEvent extends Event {
|
|
31
|
+
/** Settled hue, in degrees, `0`–`360`, after mapping the pointer's angle through {@link angleToHue}. */
|
|
32
|
+
hue;
|
|
33
|
+
/**
|
|
34
|
+
* @param hue Settled hue value at dispatch time.
|
|
35
|
+
*/
|
|
36
|
+
constructor(hue) {
|
|
37
|
+
super(COLOR_WHEEL_CHANGE_EVENT, { bubbles: true });
|
|
38
|
+
this.hue = hue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Finds the single native range input a ColorWheel renders for its hue value
|
|
43
|
+
* — the one input {@link colorWheelDrag} writes on every pointer gesture.
|
|
44
|
+
*
|
|
45
|
+
* @param host ColorWheel root element the mixin is applied to.
|
|
46
|
+
* @returns The matched hue input, or `undefined` when none is found.
|
|
47
|
+
*/
|
|
48
|
+
function findHueInput(host) {
|
|
49
|
+
return host.querySelector('input[type="range"]') ?? undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Measures `host`'s own center point in viewport coordinates — the origin
|
|
53
|
+
* {@link angleFromCenter} measures a pointer's position against, so the
|
|
54
|
+
* angle reads correctly regardless of where or how large the ring renders.
|
|
55
|
+
*
|
|
56
|
+
* @param host ColorWheel root element to measure.
|
|
57
|
+
* @returns The center point, in viewport coordinates.
|
|
58
|
+
*/
|
|
59
|
+
function measureCenter(host) {
|
|
60
|
+
let rect = host.getBoundingClientRect();
|
|
61
|
+
return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Measures `point` as a clockwise angle around `host`'s own center, converts
|
|
65
|
+
* it to a hue through {@link angleToHue}, writes the rounded result onto
|
|
66
|
+
* `hueInput.valueAsNumber`, and dispatches {@link ColorWheelChangeEvent} on `host`.
|
|
67
|
+
*
|
|
68
|
+
* @param host ColorWheel root element the pointer position measures against.
|
|
69
|
+
* @param hueInput The wheel's underlying hue input to write.
|
|
70
|
+
* @param point Pointer position, in viewport coordinates.
|
|
71
|
+
*/
|
|
72
|
+
function applyPointerHue(host, hueInput, point) {
|
|
73
|
+
let center = measureCenter(host);
|
|
74
|
+
let angle = angleFromCenter(center, point);
|
|
75
|
+
let hue = roundChannel(angleToHue(angle));
|
|
76
|
+
hueInput.valueAsNumber = hue;
|
|
77
|
+
host.dispatchEvent(new ColorWheelChangeEvent(hue));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Adds pointer-driven, angular dragging to a ColorWheel root, reshaping its
|
|
81
|
+
* hue input into a ring via {@link COLOR_WHEEL_SHAPE_ATTRIBUTE}, then mapping
|
|
82
|
+
* each captured pointer's angle to a hue and dispatching {@link ColorWheelChangeEvent} on settled values.
|
|
83
|
+
*
|
|
84
|
+
* @returns A mixin descriptor for a ColorWheel root's `mix` prop.
|
|
85
|
+
* @example
|
|
86
|
+
* <div
|
|
87
|
+
* role="group"
|
|
88
|
+
* aria-label={hueLabel}
|
|
89
|
+
* mix={[colorWheelDrag(), css({ position: "relative" })]}
|
|
90
|
+
* >
|
|
91
|
+
* <input type="range" min={0} max={360} step={1} defaultValue={0} aria-label={hueLabel} />
|
|
92
|
+
* </div>
|
|
93
|
+
*/
|
|
94
|
+
export const colorWheelDrag = createMixin((handle) => {
|
|
95
|
+
let hostNode;
|
|
96
|
+
let activePointerId;
|
|
97
|
+
handle.addEventListener("insert", (event) => {
|
|
98
|
+
hostNode = event.node;
|
|
99
|
+
hostNode.setAttribute(COLOR_WHEEL_SHAPE_ATTRIBUTE, COLOR_WHEEL_SHAPE_CIRCULAR);
|
|
100
|
+
});
|
|
101
|
+
handle.addEventListener("remove", () => {
|
|
102
|
+
hostNode = undefined;
|
|
103
|
+
activePointerId = undefined;
|
|
104
|
+
});
|
|
105
|
+
return () => createElement(handle.element, {
|
|
106
|
+
mix: [
|
|
107
|
+
on("pointerdown", (event) => {
|
|
108
|
+
if (activePointerId !== undefined || !event.isPrimary || event.button !== 0)
|
|
109
|
+
return;
|
|
110
|
+
if (!hostNode)
|
|
111
|
+
return;
|
|
112
|
+
let hueInput = findHueInput(hostNode);
|
|
113
|
+
if (!hueInput)
|
|
114
|
+
return;
|
|
115
|
+
activePointerId = event.pointerId;
|
|
116
|
+
hostNode.setPointerCapture(event.pointerId);
|
|
117
|
+
applyPointerHue(hostNode, hueInput, { x: event.clientX, y: event.clientY });
|
|
118
|
+
}),
|
|
119
|
+
on("pointermove", (event) => {
|
|
120
|
+
if (event.pointerId !== activePointerId || !hostNode)
|
|
121
|
+
return;
|
|
122
|
+
let hueInput = findHueInput(hostNode);
|
|
123
|
+
if (!hueInput)
|
|
124
|
+
return;
|
|
125
|
+
applyPointerHue(hostNode, hueInput, { x: event.clientX, y: event.clientY });
|
|
126
|
+
}),
|
|
127
|
+
on("pointerup", (event) => {
|
|
128
|
+
if (event.pointerId !== activePointerId)
|
|
129
|
+
return;
|
|
130
|
+
activePointerId = undefined;
|
|
131
|
+
}),
|
|
132
|
+
on("pointercancel", (event) => {
|
|
133
|
+
if (event.pointerId !== activePointerId)
|
|
134
|
+
return;
|
|
135
|
+
activePointerId = undefined;
|
|
136
|
+
}),
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts `remix/ui/combobox`'s input behavior onto a ComboBox's text input:
|
|
3
|
+
* narrows the popup's options to the typed text, moves the active option
|
|
4
|
+
* with arrow keys, and commits or clears the draft on blur and `Escape`,
|
|
5
|
+
* mirroring the result as `aria-activedescendant` and `aria-expanded`.
|
|
6
|
+
* Without JS the input renders as a plain text field beside every option,
|
|
7
|
+
* so all options stay tabbable and readable by assistive technology.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import type { MixinFactory } from "remix/ui";
|
|
13
|
+
/** DOM event type dispatched by {@link comboboxFilter} whenever the draft filter or the active option changes. */
|
|
14
|
+
declare const FILTER_CHANGE_EVENT: "ui:combobox-filter-change";
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementEventMap {
|
|
17
|
+
[FILTER_CHANGE_EVENT]: ComboboxFilterChangeEvent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Dispatched on a ComboBox's input by {@link comboboxFilter} whenever the
|
|
22
|
+
* filter text, active option, or open state moves, letting a consumer
|
|
23
|
+
* react to live narrowing without reading `remix/ui/combobox`'s context.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ComboboxFilterChangeEvent extends Event {
|
|
26
|
+
/** Id of the option `Enter` would commit right now, or `null` when none is active. */
|
|
27
|
+
readonly activeOptionId: string | null;
|
|
28
|
+
/** Draft text the popup's options are currently narrowed by. */
|
|
29
|
+
readonly filterText: string;
|
|
30
|
+
/** `true` while the popup is open and showing the narrowed option list. */
|
|
31
|
+
readonly isOpen: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @param init Snapshot of the combobox's filter state at dispatch time.
|
|
34
|
+
*/
|
|
35
|
+
constructor(init: {
|
|
36
|
+
activeOptionId: string | null;
|
|
37
|
+
filterText: string;
|
|
38
|
+
isOpen: boolean;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Turns a ComboBox's text input into the as-you-type filter for its popup
|
|
43
|
+
* option list by delegating typing, arrow-key movement, and blur/`Escape`
|
|
44
|
+
* commit to `remix/ui/combobox`'s `input()` primitive.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* <combobox.Context name="airport">
|
|
48
|
+
* <input mix={[inputStyle, comboboxFilter()]} placeholder="Search airports" />
|
|
49
|
+
* <div mix={[popoverStyle, combobox.popover()]}>
|
|
50
|
+
* <div mix={[listStyle, combobox.list()]}>
|
|
51
|
+
* {airports.map((airport) => (
|
|
52
|
+
* <div key={airport.value} mix={[optionStyle, combobox.option(airport)]}>{airport.label}</div>
|
|
53
|
+
* ))}
|
|
54
|
+
* </div>
|
|
55
|
+
* </div>
|
|
56
|
+
* </combobox.Context>
|
|
57
|
+
*/
|
|
58
|
+
export declare const comboboxFilter: MixinFactory<HTMLInputElement>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts `remix/ui/combobox`'s input behavior onto a ComboBox's text input:
|
|
3
|
+
* narrows the popup's options to the typed text, moves the active option
|
|
4
|
+
* with arrow keys, and commits or clears the draft on blur and `Escape`,
|
|
5
|
+
* mirroring the result as `aria-activedescendant` and `aria-expanded`.
|
|
6
|
+
* Without JS the input renders as a plain text field beside every option,
|
|
7
|
+
* so all options stay tabbable and readable by assistive technology.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import { createMixin } from "remix/ui";
|
|
13
|
+
import * as combobox from "remix/ui/combobox/primitives";
|
|
14
|
+
/** DOM event type dispatched by {@link comboboxFilter} whenever the draft filter or the active option changes. */
|
|
15
|
+
const FILTER_CHANGE_EVENT = "ui:combobox-filter-change";
|
|
16
|
+
/**
|
|
17
|
+
* Dispatched on a ComboBox's input by {@link comboboxFilter} whenever the
|
|
18
|
+
* filter text, active option, or open state moves, letting a consumer
|
|
19
|
+
* react to live narrowing without reading `remix/ui/combobox`'s context.
|
|
20
|
+
*/
|
|
21
|
+
export class ComboboxFilterChangeEvent extends Event {
|
|
22
|
+
/** Id of the option `Enter` would commit right now, or `null` when none is active. */
|
|
23
|
+
activeOptionId;
|
|
24
|
+
/** Draft text the popup's options are currently narrowed by. */
|
|
25
|
+
filterText;
|
|
26
|
+
/** `true` while the popup is open and showing the narrowed option list. */
|
|
27
|
+
isOpen;
|
|
28
|
+
/**
|
|
29
|
+
* @param init Snapshot of the combobox's filter state at dispatch time.
|
|
30
|
+
*/
|
|
31
|
+
constructor(init) {
|
|
32
|
+
super(FILTER_CHANGE_EVENT, { bubbles: true });
|
|
33
|
+
this.activeOptionId = init.activeOptionId;
|
|
34
|
+
this.filterText = init.filterText;
|
|
35
|
+
this.isOpen = init.isOpen;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Turns a ComboBox's text input into the as-you-type filter for its popup
|
|
40
|
+
* option list by delegating typing, arrow-key movement, and blur/`Escape`
|
|
41
|
+
* commit to `remix/ui/combobox`'s `input()` primitive.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* <combobox.Context name="airport">
|
|
45
|
+
* <input mix={[inputStyle, comboboxFilter()]} placeholder="Search airports" />
|
|
46
|
+
* <div mix={[popoverStyle, combobox.popover()]}>
|
|
47
|
+
* <div mix={[listStyle, combobox.list()]}>
|
|
48
|
+
* {airports.map((airport) => (
|
|
49
|
+
* <div key={airport.value} mix={[optionStyle, combobox.option(airport)]}>{airport.label}</div>
|
|
50
|
+
* ))}
|
|
51
|
+
* </div>
|
|
52
|
+
* </div>
|
|
53
|
+
* </combobox.Context>
|
|
54
|
+
*/
|
|
55
|
+
export const comboboxFilter = createMixin((handle) => {
|
|
56
|
+
let context = handle.context.get(combobox.Context);
|
|
57
|
+
let hostNode;
|
|
58
|
+
let lastFilterText = context.filterText;
|
|
59
|
+
let lastActiveOptionId = context.activeId ?? null;
|
|
60
|
+
let lastIsOpen = context.isOpen;
|
|
61
|
+
handle.addEventListener("insert", (event) => {
|
|
62
|
+
hostNode = event.node;
|
|
63
|
+
});
|
|
64
|
+
handle.addEventListener("remove", () => {
|
|
65
|
+
hostNode = undefined;
|
|
66
|
+
});
|
|
67
|
+
return () => {
|
|
68
|
+
let filterText = context.filterText;
|
|
69
|
+
let activeOptionId = context.activeId ?? null;
|
|
70
|
+
let isOpen = context.isOpen;
|
|
71
|
+
if (filterText !== lastFilterText ||
|
|
72
|
+
activeOptionId !== lastActiveOptionId ||
|
|
73
|
+
isOpen !== lastIsOpen) {
|
|
74
|
+
lastFilterText = filterText;
|
|
75
|
+
lastActiveOptionId = activeOptionId;
|
|
76
|
+
lastIsOpen = isOpen;
|
|
77
|
+
hostNode?.dispatchEvent(new ComboboxFilterChangeEvent({ activeOptionId, filterText, isOpen }));
|
|
78
|
+
}
|
|
79
|
+
return combobox.input();
|
|
80
|
+
};
|
|
81
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search-as-you-type filtering for a Command root: reads the query typed
|
|
3
|
+
* into the marked search input, hands it to a `FilterModel` instance, and
|
|
4
|
+
* mirrors the matched set onto the pre-rendered items as `hidden`,
|
|
5
|
+
* toggling the empty-state element. Without JS every item and the
|
|
6
|
+
* empty-state element render at once, reachable in Tab order and find-in-page.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { FilterModel } from "../behaviors/filter-model.js";
|
|
12
|
+
/**
|
|
13
|
+
* Attribute the search input exposes itself on — `Command.Input`'s own
|
|
14
|
+
* `<input>` carries this automatically, and `commandFilter()` forwards its
|
|
15
|
+
* typed value into {@link FilterModel.setQuery}.
|
|
16
|
+
*/
|
|
17
|
+
export declare const COMMAND_INPUT_ATTRIBUTE = "data-command-input";
|
|
18
|
+
/**
|
|
19
|
+
* Attribute every filterable item exposes itself on — the same `data-value`
|
|
20
|
+
* attribute `Command.Item` already sets, so pre-rendered items need no
|
|
21
|
+
* extra wiring to become filterable; its value is matched against the query.
|
|
22
|
+
*/
|
|
23
|
+
export declare const COMMAND_ITEM_ATTRIBUTE = "data-value";
|
|
24
|
+
/**
|
|
25
|
+
* Attribute the empty-state element exposes itself on — `Command.Empty`
|
|
26
|
+
* carries this automatically. `commandFilter()` toggles its `hidden`
|
|
27
|
+
* property opposite {@link FilterModel.isEmpty}.
|
|
28
|
+
*/
|
|
29
|
+
export declare const COMMAND_EMPTY_ATTRIBUTE = "data-command-empty";
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the id a DOM item correlates to a {@link FilterModel.Option}:
|
|
32
|
+
* its own `id` attribute when set, doubling as an `aria-activedescendant`
|
|
33
|
+
* target, otherwise its position among the other items.
|
|
34
|
+
*
|
|
35
|
+
* @param item Item element read from the DOM.
|
|
36
|
+
* @param index Item's position among the other items carrying {@link COMMAND_ITEM_ATTRIBUTE}.
|
|
37
|
+
* @returns The id to correlate this item with in the model's option set.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getCommandItemId(item: HTMLElement, index: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Filters a Command root's pre-rendered items as the user types, hiding
|
|
42
|
+
* everything that doesn't match the current query and toggling the
|
|
43
|
+
* empty-state element when nothing does.
|
|
44
|
+
*
|
|
45
|
+
* @param model Behavior class instance owning the query, matched option set, and active option.
|
|
46
|
+
* @example
|
|
47
|
+
* let model = new FilterModel();
|
|
48
|
+
* <Command mix={commandFilter(model)}>
|
|
49
|
+
* <Command.Input />
|
|
50
|
+
* <Command.Item id="home" value="Home">Home</Command.Item>
|
|
51
|
+
* <Command.Item id="settings" value="Settings">Settings</Command.Item>
|
|
52
|
+
* <Command.Empty>No matches</Command.Empty>
|
|
53
|
+
* </Command>
|
|
54
|
+
*/
|
|
55
|
+
export declare const commandFilter: import("remix/ui").MixinFactory<HTMLElement, [model: FilterModel], import("remix/ui").ElementProps>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search-as-you-type filtering for a Command root: reads the query typed
|
|
3
|
+
* into the marked search input, hands it to a `FilterModel` instance, and
|
|
4
|
+
* mirrors the matched set onto the pre-rendered items as `hidden`,
|
|
5
|
+
* toggling the empty-state element. Without JS every item and the
|
|
6
|
+
* empty-state element render at once, reachable in Tab order and find-in-page.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
12
|
+
/**
|
|
13
|
+
* Attribute the search input exposes itself on — `Command.Input`'s own
|
|
14
|
+
* `<input>` carries this automatically, and `commandFilter()` forwards its
|
|
15
|
+
* typed value into {@link FilterModel.setQuery}.
|
|
16
|
+
*/
|
|
17
|
+
export const COMMAND_INPUT_ATTRIBUTE = "data-command-input";
|
|
18
|
+
/**
|
|
19
|
+
* Attribute every filterable item exposes itself on — the same `data-value`
|
|
20
|
+
* attribute `Command.Item` already sets, so pre-rendered items need no
|
|
21
|
+
* extra wiring to become filterable; its value is matched against the query.
|
|
22
|
+
*/
|
|
23
|
+
export const COMMAND_ITEM_ATTRIBUTE = "data-value";
|
|
24
|
+
/**
|
|
25
|
+
* Attribute the empty-state element exposes itself on — `Command.Empty`
|
|
26
|
+
* carries this automatically. `commandFilter()` toggles its `hidden`
|
|
27
|
+
* property opposite {@link FilterModel.isEmpty}.
|
|
28
|
+
*/
|
|
29
|
+
export const COMMAND_EMPTY_ATTRIBUTE = "data-command-empty";
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the id a DOM item correlates to a {@link FilterModel.Option}:
|
|
32
|
+
* its own `id` attribute when set, doubling as an `aria-activedescendant`
|
|
33
|
+
* target, otherwise its position among the other items.
|
|
34
|
+
*
|
|
35
|
+
* @param item Item element read from the DOM.
|
|
36
|
+
* @param index Item's position among the other items carrying {@link COMMAND_ITEM_ATTRIBUTE}.
|
|
37
|
+
* @returns The id to correlate this item with in the model's option set.
|
|
38
|
+
*/
|
|
39
|
+
export function getCommandItemId(item, index) {
|
|
40
|
+
return item.id !== "" ? item.id : String(index);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reads every item beneath `root` into the option set a `FilterModel`
|
|
44
|
+
* filters over, using each item's own text when {@link COMMAND_ITEM_ATTRIBUTE}
|
|
45
|
+
* carries no value.
|
|
46
|
+
*
|
|
47
|
+
* @param root Command root element the items are read from.
|
|
48
|
+
* @returns The current option set, in document order.
|
|
49
|
+
*/
|
|
50
|
+
function collectOptions(root) {
|
|
51
|
+
let items = root.querySelectorAll(`[${COMMAND_ITEM_ATTRIBUTE}]`);
|
|
52
|
+
let options = [];
|
|
53
|
+
for (let [index, item] of items.entries()) {
|
|
54
|
+
let value = item.getAttribute(COMMAND_ITEM_ATTRIBUTE) || item.textContent?.trim() || "";
|
|
55
|
+
options.push({ id: getCommandItemId(item, index), value });
|
|
56
|
+
}
|
|
57
|
+
return options;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Mirrors a `FilterModel`'s matched set onto the item list beneath `root`
|
|
61
|
+
* as `hidden`, and toggles the empty-state element opposite
|
|
62
|
+
* {@link FilterModel.isEmpty}.
|
|
63
|
+
*
|
|
64
|
+
* @param root Command root element the items and empty-state element are read from.
|
|
65
|
+
* @param model Model whose current matches and empty state get mirrored onto the DOM.
|
|
66
|
+
*/
|
|
67
|
+
function syncMatches(root, model) {
|
|
68
|
+
let items = root.querySelectorAll(`[${COMMAND_ITEM_ATTRIBUTE}]`);
|
|
69
|
+
for (let [index, item] of items.entries()) {
|
|
70
|
+
item.hidden = !model.isMatch(getCommandItemId(item, index));
|
|
71
|
+
}
|
|
72
|
+
let empty = root.querySelector(`[${COMMAND_EMPTY_ATTRIBUTE}]`);
|
|
73
|
+
if (empty !== null)
|
|
74
|
+
empty.hidden = !model.isEmpty;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Filters a Command root's pre-rendered items as the user types, hiding
|
|
78
|
+
* everything that doesn't match the current query and toggling the
|
|
79
|
+
* empty-state element when nothing does.
|
|
80
|
+
*
|
|
81
|
+
* @param model Behavior class instance owning the query, matched option set, and active option.
|
|
82
|
+
* @example
|
|
83
|
+
* let model = new FilterModel();
|
|
84
|
+
* <Command mix={commandFilter(model)}>
|
|
85
|
+
* <Command.Input />
|
|
86
|
+
* <Command.Item id="home" value="Home">Home</Command.Item>
|
|
87
|
+
* <Command.Item id="settings" value="Settings">Settings</Command.Item>
|
|
88
|
+
* <Command.Empty>No matches</Command.Empty>
|
|
89
|
+
* </Command>
|
|
90
|
+
*/
|
|
91
|
+
export const commandFilter = createMixin((handle) => {
|
|
92
|
+
let hostNode;
|
|
93
|
+
let boundModel;
|
|
94
|
+
handle.addEventListener("insert", (event) => {
|
|
95
|
+
hostNode = event.node;
|
|
96
|
+
boundModel?.setOptions(collectOptions(hostNode));
|
|
97
|
+
});
|
|
98
|
+
handle.addEventListener("remove", () => {
|
|
99
|
+
hostNode = undefined;
|
|
100
|
+
});
|
|
101
|
+
return (model) => {
|
|
102
|
+
if (boundModel !== model) {
|
|
103
|
+
boundModel = model;
|
|
104
|
+
model.addEventListener("change", () => {
|
|
105
|
+
if (hostNode !== undefined)
|
|
106
|
+
syncMatches(hostNode, model);
|
|
107
|
+
}, { signal: handle.signal });
|
|
108
|
+
}
|
|
109
|
+
return createElement(handle.element, {
|
|
110
|
+
mix: [
|
|
111
|
+
on("input", (event) => {
|
|
112
|
+
if (!(event.target instanceof HTMLInputElement))
|
|
113
|
+
return;
|
|
114
|
+
if (!event.target.hasAttribute(COMMAND_INPUT_ATTRIBUTE))
|
|
115
|
+
return;
|
|
116
|
+
model.setQuery(event.target.value);
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arrow-key and Enter navigation for a Command root already paired with
|
|
3
|
+
* `commandFilter(model)`: arrow keys move `model`'s active match across the
|
|
4
|
+
* visible items, mirrored onto `aria-selected` and `aria-activedescendant`;
|
|
5
|
+
* Enter clicks whatever control the active item nests. Without JS every
|
|
6
|
+
* item stays independently activatable in ordinary Tab order.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { FilterModel } from "../behaviors/filter-model.js";
|
|
12
|
+
/**
|
|
13
|
+
* Adds ArrowDown/ArrowUp/Enter navigation to a Command root already paired
|
|
14
|
+
* with `commandFilter(model)`, mirroring the active match onto
|
|
15
|
+
* `aria-selected` and `aria-activedescendant`, and activating it on Enter.
|
|
16
|
+
*
|
|
17
|
+
* @param model The same `FilterModel` instance passed to `commandFilter()`.
|
|
18
|
+
* @example
|
|
19
|
+
* let model = new FilterModel();
|
|
20
|
+
* <Command mix={[commandFilter(model), commandKeys(model)]}>
|
|
21
|
+
* <Command.Input />
|
|
22
|
+
* <Command.Item id="home" value="Home">
|
|
23
|
+
* <a href="/">Home</a>
|
|
24
|
+
* </Command.Item>
|
|
25
|
+
* <Command.Item id="settings" value="Settings">
|
|
26
|
+
* <a href="/settings">Settings</a>
|
|
27
|
+
* </Command.Item>
|
|
28
|
+
* <Command.Empty>No matches</Command.Empty>
|
|
29
|
+
* </Command>
|
|
30
|
+
*/
|
|
31
|
+
export declare const commandKeys: import("remix/ui").MixinFactory<HTMLElement, [model: FilterModel], import("remix/ui").ElementProps>;
|