@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps `aria-checked` on a native checked-state control in sync with its
|
|
3
|
+
* live checkedness, since the attribute is static and won't follow a
|
|
4
|
+
* control's state on its own. Opt-in, for a control inside a hydrated
|
|
5
|
+
* island: with no JavaScript, assistive technology reads checkedness off
|
|
6
|
+
* the control itself already.
|
|
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 {@link ariaChecked} owns on its host. It carries a token rather
|
|
14
|
+
* than a flag — `"true"`, `"false"`, or `"mixed"` — since an empty value is
|
|
15
|
+
* none of the tokens ARIA defines and resolves to the attribute's default.
|
|
16
|
+
*/
|
|
17
|
+
const CHECKED_ATTRIBUTE = "aria-checked";
|
|
18
|
+
/** Input `type` whose checkedness is shared across a whole group rather than owned by one control. */
|
|
19
|
+
const RADIO_TYPE = "radio";
|
|
20
|
+
/**
|
|
21
|
+
* Matches the radios {@link syncAriaChecked} refreshes alongside the one that
|
|
22
|
+
* fired: every radio in the group already carrying {@link CHECKED_ATTRIBUTE},
|
|
23
|
+
* the set that opted into this mixin.
|
|
24
|
+
*/
|
|
25
|
+
const GROUP_SELECTOR = `input[type="${RADIO_TYPE}"][${CHECKED_ATTRIBUTE}]`;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the token for a control that has not been rendered yet, from props
|
|
28
|
+
* alone. `indeterminate` is DOM-only, so only a prop set at render time is
|
|
29
|
+
* visible here; a live toggle is caught by {@link liveToken} instead.
|
|
30
|
+
*
|
|
31
|
+
* @param props Props the host element is being rendered with.
|
|
32
|
+
* @returns `"mixed"` for a partially-checked control, otherwise the token matching its initial checkedness.
|
|
33
|
+
*/
|
|
34
|
+
function initialToken(props) {
|
|
35
|
+
if (props.indeterminate === true)
|
|
36
|
+
return "mixed";
|
|
37
|
+
return (props.checked ?? props.defaultChecked) === true ? "true" : "false";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reads the token straight off a mounted control's live properties, which is
|
|
41
|
+
* the only state that stays true after the user has interacted with it.
|
|
42
|
+
*
|
|
43
|
+
* @param control Mounted checkbox or radio to read.
|
|
44
|
+
* @returns `"mixed"` for a control whose `indeterminate` property is set, otherwise the token matching `checked`.
|
|
45
|
+
*/
|
|
46
|
+
function liveToken(control) {
|
|
47
|
+
if (control.indeterminate)
|
|
48
|
+
return "mixed";
|
|
49
|
+
return control.checked ? "true" : "false";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Every radio sharing `control`'s group that already carries
|
|
53
|
+
* {@link CHECKED_ATTRIBUTE}, scoped by name and form owner. Names are compared
|
|
54
|
+
* in script since a `name` may hold characters a CSS selector would escape.
|
|
55
|
+
*
|
|
56
|
+
* @param control Radio whose group is collected.
|
|
57
|
+
* @returns The group's radios, empty for an unnamed radio, which the platform groups with nothing.
|
|
58
|
+
*/
|
|
59
|
+
function groupMembers(control) {
|
|
60
|
+
if (control.name === "")
|
|
61
|
+
return [];
|
|
62
|
+
let form = control.form;
|
|
63
|
+
let candidates = form === null
|
|
64
|
+
? control.ownerDocument.querySelectorAll(GROUP_SELECTOR)
|
|
65
|
+
: form.querySelectorAll(GROUP_SELECTOR);
|
|
66
|
+
let members = [];
|
|
67
|
+
for (let candidate of candidates) {
|
|
68
|
+
if (candidate.name !== control.name)
|
|
69
|
+
continue;
|
|
70
|
+
if (candidate.form !== control.form)
|
|
71
|
+
continue;
|
|
72
|
+
members.push(candidate);
|
|
73
|
+
}
|
|
74
|
+
return members;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Rewrites {@link CHECKED_ATTRIBUTE} on `control`, and on its sibling radios,
|
|
78
|
+
* since picking one radio unchecks another with no `change` event of its own.
|
|
79
|
+
* Call this directly after a programmatic checked/indeterminate write or a form reset, neither of which fires `change`.
|
|
80
|
+
*
|
|
81
|
+
* @param control Mounted checkbox or radio whose attribute is brought back in line.
|
|
82
|
+
* @example
|
|
83
|
+
* selectAll.indeterminate = someButNotAllSelected;
|
|
84
|
+
* syncAriaChecked(selectAll);
|
|
85
|
+
*/
|
|
86
|
+
export function syncAriaChecked(control) {
|
|
87
|
+
control.setAttribute(CHECKED_ATTRIBUTE, liveToken(control));
|
|
88
|
+
if (control.type !== RADIO_TYPE)
|
|
89
|
+
return;
|
|
90
|
+
for (let member of groupMembers(control)) {
|
|
91
|
+
if (member === control)
|
|
92
|
+
continue;
|
|
93
|
+
member.setAttribute(CHECKED_ATTRIBUTE, liveToken(member));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adds `aria-checked` to a checkbox, switch, or radio, syncing it from the
|
|
98
|
+
* host's own render-time state and again on every `change`. Apply the mixin
|
|
99
|
+
* to every radio in a shared group — a change refreshes only the ones that carry it.
|
|
100
|
+
*
|
|
101
|
+
* @returns A mixin descriptor for a checkbox's, switch's, or radio's `mix` prop.
|
|
102
|
+
* @see {@link syncAriaChecked} to resync after a programmatic checked/indeterminate write or a form reset, neither of which fires `change`.
|
|
103
|
+
* @example
|
|
104
|
+
* <Switch name="notifications" defaultChecked mix={[ariaChecked()]}>
|
|
105
|
+
* {t("settings.notifications.label")}
|
|
106
|
+
* </Switch>
|
|
107
|
+
* @example
|
|
108
|
+
* <Checkbox name="terms" mix={[ariaChecked()]}>{t("signup.acceptTerms")}</Checkbox>
|
|
109
|
+
* @example
|
|
110
|
+
* // A radio's own input sits behind the `parts.input` passthrough.
|
|
111
|
+
* <RadioGroup.Radio value="express" parts={{ input: [ariaChecked()] }}>
|
|
112
|
+
* {t("shipping.express")}
|
|
113
|
+
* </RadioGroup.Radio>
|
|
114
|
+
*/
|
|
115
|
+
export const ariaChecked = createMixin((handle) => {
|
|
116
|
+
handle.addEventListener("insert", (event) => {
|
|
117
|
+
syncAriaChecked(event.node);
|
|
118
|
+
});
|
|
119
|
+
return (props) => createElement(handle.element, {
|
|
120
|
+
[CHECKED_ATTRIBUTE]: initialToken(props),
|
|
121
|
+
mix: [
|
|
122
|
+
on("change", (event) => {
|
|
123
|
+
syncAriaChecked(event.currentTarget);
|
|
124
|
+
}),
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an Attachment.Trigger's whole card into a single activation target,
|
|
3
|
+
* following its `href` or opening the `<dialog>` its `commandfor` names.
|
|
4
|
+
* Nested controls such as Attachment.Action buttons keep answering their
|
|
5
|
+
* own click, tap, and keypress independently, since script is the only way
|
|
6
|
+
* to exempt one descendant from a parent's activation handling.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { MixinFactory } from "remix/ui";
|
|
12
|
+
/** DOM event type dispatched on a host by {@link attachmentTrigger} right before it follows a link or opens a dialog. */
|
|
13
|
+
declare const ATTACHMENT_TRIGGER_EVENT: "ui:attachment-trigger";
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementEventMap {
|
|
16
|
+
[ATTACHMENT_TRIGGER_EVENT]: AttachmentTriggerEvent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Dispatched on an Attachment.Trigger host by {@link attachmentTrigger}
|
|
21
|
+
* right before it follows a link or opens a dialog, so a consumer can react
|
|
22
|
+
* — log analytics, swap in a custom viewer — or cancel it with `preventDefault()` to stop the default effect.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AttachmentTriggerEvent extends Event {
|
|
25
|
+
/** The `href` this activation is about to follow, or `null` when it opens a dialog instead. */
|
|
26
|
+
readonly href: string | null;
|
|
27
|
+
/**
|
|
28
|
+
* @param href The `href` this activation is about to follow, or `null` for a dialog activation.
|
|
29
|
+
*/
|
|
30
|
+
constructor(href: string | null);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Makes an Attachment.Trigger's whole card activatable as a link or dialog
|
|
34
|
+
* trigger through the same `href`/`commandfor` attributes {@link resolveAction}
|
|
35
|
+
* reads; an `aria-disabled="true"` host ignores every activation, and nested controls keep answering their own click, tap, and keypress independently.
|
|
36
|
+
*
|
|
37
|
+
* @returns A mixin descriptor for an Attachment.Trigger's `mix` prop.
|
|
38
|
+
* @example
|
|
39
|
+
* <Attachment.Trigger href="/files/quarterly-report.pdf" mix={attachmentTrigger()}>
|
|
40
|
+
* <Attachment state="done">
|
|
41
|
+
* <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>
|
|
42
|
+
* <Attachment.Content>
|
|
43
|
+
* <Attachment.Title>quarterly-report.pdf</Attachment.Title>
|
|
44
|
+
* </Attachment.Content>
|
|
45
|
+
* <Attachment.Actions>
|
|
46
|
+
* <Attachment.Action aria-label={t("attachment.download")}>
|
|
47
|
+
* <DownloadIcon />
|
|
48
|
+
* </Attachment.Action>
|
|
49
|
+
* </Attachment.Actions>
|
|
50
|
+
* </Attachment>
|
|
51
|
+
* </Attachment.Trigger>
|
|
52
|
+
* @example
|
|
53
|
+
* <Attachment.Trigger commandfor="quarterly-report-preview" mix={attachmentTrigger()}>
|
|
54
|
+
* <Attachment state="done">
|
|
55
|
+
* <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>
|
|
56
|
+
* <Attachment.Content>
|
|
57
|
+
* <Attachment.Title>quarterly-report.pdf</Attachment.Title>
|
|
58
|
+
* </Attachment.Content>
|
|
59
|
+
* </Attachment>
|
|
60
|
+
* </Attachment.Trigger>
|
|
61
|
+
* <Dialog id="quarterly-report-preview">...</Dialog>
|
|
62
|
+
*/
|
|
63
|
+
export declare const attachmentTrigger: MixinFactory<HTMLElement>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an Attachment.Trigger's whole card into a single activation target,
|
|
3
|
+
* following its `href` or opening the `<dialog>` its `commandfor` names.
|
|
4
|
+
* Nested controls such as Attachment.Action buttons keep answering their
|
|
5
|
+
* own click, tap, and keypress independently, since script is the only way
|
|
6
|
+
* to exempt one descendant from a parent's activation handling.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
12
|
+
/**
|
|
13
|
+
* Selector matching a native interactive control nested in the card — an
|
|
14
|
+
* Attachment.Action button, a form control, an editable region — that
|
|
15
|
+
* {@link attachmentTrigger} always lets handle its own activation.
|
|
16
|
+
*/
|
|
17
|
+
const NATIVE_CONTROL_SELECTOR = 'a[href], button, input:not([type="hidden"]), select, textarea, summary, audio[controls], video[controls], [contenteditable=""], [contenteditable="true"]';
|
|
18
|
+
/**
|
|
19
|
+
* `command` value {@link attachmentTrigger} acts on for a `commandfor`
|
|
20
|
+
* host — the only Invoker Commands keyword that opens a `<dialog>`. Assumed
|
|
21
|
+
* by default when `command` is omitted, since opening is all a trigger does.
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_DIALOG_COMMAND = "show-modal";
|
|
24
|
+
/** DOM event type dispatched on a host by {@link attachmentTrigger} right before it follows a link or opens a dialog. */
|
|
25
|
+
const ATTACHMENT_TRIGGER_EVENT = "ui:attachment-trigger";
|
|
26
|
+
/**
|
|
27
|
+
* Dispatched on an Attachment.Trigger host by {@link attachmentTrigger}
|
|
28
|
+
* right before it follows a link or opens a dialog, so a consumer can react
|
|
29
|
+
* — log analytics, swap in a custom viewer — or cancel it with `preventDefault()` to stop the default effect.
|
|
30
|
+
*/
|
|
31
|
+
export class AttachmentTriggerEvent extends Event {
|
|
32
|
+
/** The `href` this activation is about to follow, or `null` when it opens a dialog instead. */
|
|
33
|
+
href;
|
|
34
|
+
/**
|
|
35
|
+
* @param href The `href` this activation is about to follow, or `null` for a dialog activation.
|
|
36
|
+
*/
|
|
37
|
+
constructor(href) {
|
|
38
|
+
super(ATTACHMENT_TRIGGER_EVENT, { bubbles: true, cancelable: true });
|
|
39
|
+
this.href = href;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reads what a card activation should do from the host's own attributes:
|
|
44
|
+
* an `href` wins as a link; otherwise a `commandfor` reference resolves
|
|
45
|
+
* against {@link DEFAULT_DIALOG_COMMAND} and must name a `<dialog>` element.
|
|
46
|
+
*
|
|
47
|
+
* @param host Element {@link attachmentTrigger} is mixed onto.
|
|
48
|
+
* @returns The resolved action, or `undefined` when the host has nothing configured to do.
|
|
49
|
+
*/
|
|
50
|
+
function resolveAction(host) {
|
|
51
|
+
let href = host.getAttribute("href");
|
|
52
|
+
if (href)
|
|
53
|
+
return { kind: "link", href };
|
|
54
|
+
let commandForId = host.getAttribute("commandfor");
|
|
55
|
+
if (commandForId === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
let command = host.getAttribute("command") ?? DEFAULT_DIALOG_COMMAND;
|
|
58
|
+
if (command !== DEFAULT_DIALOG_COMMAND) {
|
|
59
|
+
if (import.meta.env.DEV) {
|
|
60
|
+
console.warn(`attachmentTrigger(): unsupported command "${command}" — only "${DEFAULT_DIALOG_COMMAND}" opens a dialog from a card activation.`);
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
let dialog = document.getElementById(commandForId);
|
|
65
|
+
if (!(dialog instanceof HTMLDialogElement)) {
|
|
66
|
+
if (import.meta.env.DEV) {
|
|
67
|
+
console.warn(`attachmentTrigger(): commandfor="${commandForId}" doesn't reference a <dialog> element.`);
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return { kind: "dialog", dialog };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Reports whether `target` sits inside a {@link NATIVE_CONTROL_SELECTOR}
|
|
75
|
+
* match that isn't `host` itself, telling a click bubbling up from a nested
|
|
76
|
+
* native control apart from one landing on the card's own surface.
|
|
77
|
+
*
|
|
78
|
+
* @param host Element {@link attachmentTrigger} is mixed onto.
|
|
79
|
+
* @param target Event target the activation originated from.
|
|
80
|
+
* @returns Whether `target` is inside a native control nested in `host`.
|
|
81
|
+
*/
|
|
82
|
+
function isNativeControlDescendant(host, target) {
|
|
83
|
+
let control = target.closest(NATIVE_CONTROL_SELECTOR);
|
|
84
|
+
return control !== null && control !== host && host.contains(control);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Dispatches {@link AttachmentTriggerEvent} on `host` and, unless a
|
|
88
|
+
* listener cancels it, carries out `action` — opening its dialog, or
|
|
89
|
+
* following its link in a new tab, a named `target`, or in place, per the host's own attributes.
|
|
90
|
+
*
|
|
91
|
+
* @param host Element {@link attachmentTrigger} is mixed onto.
|
|
92
|
+
* @param action Action resolved by {@link resolveAction} for this activation.
|
|
93
|
+
* @param newTab Whether the activation itself (a modifier-held click, a middle click) asked for a new tab.
|
|
94
|
+
*/
|
|
95
|
+
function performAction(host, action, newTab) {
|
|
96
|
+
let allowed = host.dispatchEvent(new AttachmentTriggerEvent(action.kind === "link" ? action.href : null));
|
|
97
|
+
if (!allowed)
|
|
98
|
+
return;
|
|
99
|
+
if (action.kind === "dialog") {
|
|
100
|
+
if (!action.dialog.open)
|
|
101
|
+
action.dialog.showModal();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let hostTarget = host.getAttribute("target");
|
|
105
|
+
if (newTab || hostTarget === "_blank")
|
|
106
|
+
window.open(action.href, "_blank", "noopener,noreferrer");
|
|
107
|
+
else if (hostTarget)
|
|
108
|
+
window.open(action.href, hostTarget);
|
|
109
|
+
else
|
|
110
|
+
location.assign(action.href);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Makes an Attachment.Trigger's whole card activatable as a link or dialog
|
|
114
|
+
* trigger through the same `href`/`commandfor` attributes {@link resolveAction}
|
|
115
|
+
* reads; an `aria-disabled="true"` host ignores every activation, and nested controls keep answering their own click, tap, and keypress independently.
|
|
116
|
+
*
|
|
117
|
+
* @returns A mixin descriptor for an Attachment.Trigger's `mix` prop.
|
|
118
|
+
* @example
|
|
119
|
+
* <Attachment.Trigger href="/files/quarterly-report.pdf" mix={attachmentTrigger()}>
|
|
120
|
+
* <Attachment state="done">
|
|
121
|
+
* <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>
|
|
122
|
+
* <Attachment.Content>
|
|
123
|
+
* <Attachment.Title>quarterly-report.pdf</Attachment.Title>
|
|
124
|
+
* </Attachment.Content>
|
|
125
|
+
* <Attachment.Actions>
|
|
126
|
+
* <Attachment.Action aria-label={t("attachment.download")}>
|
|
127
|
+
* <DownloadIcon />
|
|
128
|
+
* </Attachment.Action>
|
|
129
|
+
* </Attachment.Actions>
|
|
130
|
+
* </Attachment>
|
|
131
|
+
* </Attachment.Trigger>
|
|
132
|
+
* @example
|
|
133
|
+
* <Attachment.Trigger commandfor="quarterly-report-preview" mix={attachmentTrigger()}>
|
|
134
|
+
* <Attachment state="done">
|
|
135
|
+
* <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>
|
|
136
|
+
* <Attachment.Content>
|
|
137
|
+
* <Attachment.Title>quarterly-report.pdf</Attachment.Title>
|
|
138
|
+
* </Attachment.Content>
|
|
139
|
+
* </Attachment>
|
|
140
|
+
* </Attachment.Trigger>
|
|
141
|
+
* <Dialog id="quarterly-report-preview">...</Dialog>
|
|
142
|
+
*/
|
|
143
|
+
export const attachmentTrigger = createMixin((handle) => {
|
|
144
|
+
return () => createElement(handle.element, {
|
|
145
|
+
mix: [
|
|
146
|
+
on("click", (event) => {
|
|
147
|
+
let host = event.currentTarget;
|
|
148
|
+
if (host.getAttribute("aria-disabled") === "true")
|
|
149
|
+
return;
|
|
150
|
+
if (!(event.target instanceof Element) || isNativeControlDescendant(host, event.target)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let action = resolveAction(host);
|
|
154
|
+
if (!action)
|
|
155
|
+
return;
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
performAction(host, action, event.ctrlKey || event.metaKey || event.shiftKey);
|
|
158
|
+
}),
|
|
159
|
+
on("auxclick", (event) => {
|
|
160
|
+
if (event.button !== 1)
|
|
161
|
+
return;
|
|
162
|
+
let host = event.currentTarget;
|
|
163
|
+
if (host.getAttribute("aria-disabled") === "true")
|
|
164
|
+
return;
|
|
165
|
+
if (!(event.target instanceof Element) || isNativeControlDescendant(host, event.target)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
let action = resolveAction(host);
|
|
169
|
+
if (!action || action.kind !== "link")
|
|
170
|
+
return;
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
performAction(host, action, true);
|
|
173
|
+
}),
|
|
174
|
+
on("keydown", (event) => {
|
|
175
|
+
let host = event.currentTarget;
|
|
176
|
+
if (event.target !== host)
|
|
177
|
+
return;
|
|
178
|
+
if (host.getAttribute("aria-disabled") === "true")
|
|
179
|
+
return;
|
|
180
|
+
let action = resolveAction(host);
|
|
181
|
+
if (!action)
|
|
182
|
+
return;
|
|
183
|
+
if (event.key !== "Enter" && !(event.key === " " && action.kind === "dialog"))
|
|
184
|
+
return;
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
performAction(host, action, event.ctrlKey || event.metaKey || event.shiftKey);
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard navigation for a Calendar grid: moves day/week/month focus on a
|
|
3
|
+
* `CalendarModel` from Arrow/Page/Home/End keys, then mirrors the model's
|
|
4
|
+
* focused day back onto the grid as roving `tabindex` and DOM focus.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { CalendarModel } from "../behaviors/calendar-model.js";
|
|
10
|
+
/**
|
|
11
|
+
* Attribute every calendar day cell exposes its date on, in local
|
|
12
|
+
* `YYYY-MM-DD` form, that `calendarKeys()` matches against a
|
|
13
|
+
* `CalendarModel`'s focused day to move roving `tabindex` and DOM focus.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CALENDAR_DAY_DATE_ATTRIBUTE = "data-date";
|
|
16
|
+
/**
|
|
17
|
+
* Adds keyboard navigation to a Calendar grid: each key delegates to the
|
|
18
|
+
* matching `CalendarModel` method, and any `focusedDate` change — from a key
|
|
19
|
+
* or another caller of the model — re-syncs roving `tabindex` and DOM focus.
|
|
20
|
+
*
|
|
21
|
+
* @param model Behavior class instance owning the grid's focused day, visible
|
|
22
|
+
* month, and range selection state.
|
|
23
|
+
* @example
|
|
24
|
+
* let model = new CalendarModel();
|
|
25
|
+
* <div role="grid" mix={[calendarKeys(model)]} />
|
|
26
|
+
*/
|
|
27
|
+
export declare const calendarKeys: import("remix/ui").MixinFactory<HTMLElement, [model: CalendarModel], import("remix/ui").ElementProps>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard navigation for a Calendar grid: moves day/week/month focus on a
|
|
3
|
+
* `CalendarModel` from Arrow/Page/Home/End keys, then mirrors the model's
|
|
4
|
+
* focused day back onto the grid as roving `tabindex` and DOM focus.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
10
|
+
/**
|
|
11
|
+
* Attribute every calendar day cell exposes its date on, in local
|
|
12
|
+
* `YYYY-MM-DD` form, that `calendarKeys()` matches against a
|
|
13
|
+
* `CalendarModel`'s focused day to move roving `tabindex` and DOM focus.
|
|
14
|
+
*/
|
|
15
|
+
export const CALENDAR_DAY_DATE_ATTRIBUTE = "data-date";
|
|
16
|
+
/**
|
|
17
|
+
* Formats a date as the local calendar-day key every day cell's
|
|
18
|
+
* `data-date` attribute carries, so the focused day can be matched by a
|
|
19
|
+
* plain string comparison instead of re-deriving `Date` equality per cell.
|
|
20
|
+
*
|
|
21
|
+
* @param date Date to format.
|
|
22
|
+
* @returns The date's local year, month, and day as `YYYY-MM-DD`.
|
|
23
|
+
*/
|
|
24
|
+
function toDateKey(date) {
|
|
25
|
+
let year = String(date.getFullYear()).padStart(4, "0");
|
|
26
|
+
let month = String(date.getMonth() + 1).padStart(2, "0");
|
|
27
|
+
let day = String(date.getDate()).padStart(2, "0");
|
|
28
|
+
return `${year}-${month}-${day}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Adds keyboard navigation to a Calendar grid: each key delegates to the
|
|
32
|
+
* matching `CalendarModel` method, and any `focusedDate` change — from a key
|
|
33
|
+
* or another caller of the model — re-syncs roving `tabindex` and DOM focus.
|
|
34
|
+
*
|
|
35
|
+
* @param model Behavior class instance owning the grid's focused day, visible
|
|
36
|
+
* month, and range selection state.
|
|
37
|
+
* @example
|
|
38
|
+
* let model = new CalendarModel();
|
|
39
|
+
* <div role="grid" mix={[calendarKeys(model)]} />
|
|
40
|
+
*/
|
|
41
|
+
export const calendarKeys = createMixin((handle) => {
|
|
42
|
+
let hostNode;
|
|
43
|
+
let boundModel;
|
|
44
|
+
handle.addEventListener("insert", (event) => {
|
|
45
|
+
hostNode = event.node;
|
|
46
|
+
});
|
|
47
|
+
handle.addEventListener("remove", () => {
|
|
48
|
+
hostNode = undefined;
|
|
49
|
+
});
|
|
50
|
+
/** Mirrors `model.focusedDate` onto the grid as roving tabindex and DOM focus. */
|
|
51
|
+
function syncFocusedCell(model) {
|
|
52
|
+
if (!hostNode)
|
|
53
|
+
return;
|
|
54
|
+
let focusedKey = toDateKey(model.focusedDate);
|
|
55
|
+
let cells = hostNode.querySelectorAll(`[${CALENDAR_DAY_DATE_ATTRIBUTE}]`);
|
|
56
|
+
for (let cell of cells) {
|
|
57
|
+
let isFocusedCell = cell.getAttribute(CALENDAR_DAY_DATE_ATTRIBUTE) === focusedKey;
|
|
58
|
+
cell.tabIndex = isFocusedCell ? 0 : -1;
|
|
59
|
+
if (isFocusedCell && document.activeElement !== cell) {
|
|
60
|
+
cell.focus();
|
|
61
|
+
cell.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return (model) => {
|
|
66
|
+
if (boundModel !== model) {
|
|
67
|
+
boundModel = model;
|
|
68
|
+
model.addEventListener("change", () => syncFocusedCell(model), {
|
|
69
|
+
signal: handle.signal,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return createElement(handle.element, {
|
|
73
|
+
mix: [
|
|
74
|
+
on("keydown", (event) => {
|
|
75
|
+
switch (event.key) {
|
|
76
|
+
case "ArrowUp":
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
model.focusPreviousWeek();
|
|
79
|
+
return;
|
|
80
|
+
case "ArrowDown":
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
model.focusNextWeek();
|
|
83
|
+
return;
|
|
84
|
+
case "ArrowLeft":
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
model.focusPreviousDay();
|
|
87
|
+
return;
|
|
88
|
+
case "ArrowRight":
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
model.focusNextDay();
|
|
91
|
+
return;
|
|
92
|
+
case "PageUp":
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
model.focusPreviousMonth();
|
|
95
|
+
return;
|
|
96
|
+
case "PageDown":
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
model.focusNextMonth();
|
|
99
|
+
return;
|
|
100
|
+
case "Home":
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
model.focusMonthStart();
|
|
103
|
+
return;
|
|
104
|
+
case "End":
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
model.focusMonthEnd();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the `--ui-prev`, `--ui-next`, and `--ui-goto` commands a Carousel's
|
|
3
|
+
* invoker buttons dispatch at its viewport, turning each into an
|
|
4
|
+
* `Element.scrollBy()` call, and keeps every matching invoker's `disabled`
|
|
5
|
+
* state in sync with whichever scroll edge the viewport currently sits at.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Attribute every Carousel slide exposes itself on. {@link carouselControls}
|
|
12
|
+
* queries every element carrying this attribute beneath the viewport, in
|
|
13
|
+
* document order, to resolve the slide a `--ui-goto` command targets.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide";
|
|
16
|
+
/**
|
|
17
|
+
* Adds `--ui-prev`/`--ui-next`/`--ui-goto` command handling to a Carousel
|
|
18
|
+
* viewport, scrolling by page or to a `data-slide` index and re-syncing every
|
|
19
|
+
* invoker button's disabled state on every command, scroll, and resize.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <div id="cart-carousel" mix={carouselControls()}>
|
|
23
|
+
* <div data-carousel-slide>Slide 1</div>
|
|
24
|
+
* <div data-carousel-slide>Slide 2</div>
|
|
25
|
+
* </div>
|
|
26
|
+
* <button commandfor="cart-carousel" command="--ui-prev">Previous</button>
|
|
27
|
+
* <button commandfor="cart-carousel" command="--ui-next">Next</button>
|
|
28
|
+
* <button commandfor="cart-carousel" command="--ui-goto" data-slide="1">Slide 2</button>
|
|
29
|
+
*/
|
|
30
|
+
export declare const carouselControls: import("remix/ui").MixinFactory<HTMLElement, [], import("remix/ui").ElementProps>;
|