@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,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The visitor's live `prefers-reduced-motion` preference, read through a
|
|
3
|
+
* single `matchMedia` query — the one check every motion-aware mixin
|
|
4
|
+
* consults before choosing between a full motion effect and its instant or
|
|
5
|
+
* opacity-only alternative.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Reads whether the visitor's platform currently requests reduced motion.
|
|
12
|
+
*
|
|
13
|
+
* @returns `true` when the platform's `prefers-reduced-motion` setting is `reduce`, `false` otherwise.
|
|
14
|
+
* @example
|
|
15
|
+
* let behavior: ScrollBehavior = prefersReducedMotion() ? "instant" : "smooth";
|
|
16
|
+
*/
|
|
17
|
+
export function prefersReducedMotion() {
|
|
18
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id and aria wiring shared by every labeled, described, and validated
|
|
3
|
+
* field convenience wrapper: the resolved semantic color role, the resolved
|
|
4
|
+
* invalid state, the ids reserved for the field's description and error
|
|
5
|
+
* paragraphs, and the joined `aria-describedby` value linking the control to
|
|
6
|
+
* whichever of the two are present. Every field wrapper derives this same
|
|
7
|
+
* handful of values from its own stable identifier and props right after
|
|
8
|
+
* destructuring, so this module gives that computation one home instead of a
|
|
9
|
+
* copy per field type.
|
|
10
|
+
*
|
|
11
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
12
|
+
* @copyright Sergio Xalambrí 2026
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Semantic color role shared by every field convenience wrapper's control,
|
|
16
|
+
* each mapped to its matching `--ui-*` variables.
|
|
17
|
+
*/
|
|
18
|
+
export type FieldColor = "brand" | "neutral" | "success" | "warning" | "danger";
|
|
19
|
+
/**
|
|
20
|
+
* The full range of values a native `aria-invalid` attribute accepts: a plain
|
|
21
|
+
* boolean, its string form, or the finer-grained `"grammar"`/`"spelling"`
|
|
22
|
+
* validity distinction.
|
|
23
|
+
*/
|
|
24
|
+
export type AriaInvalid = boolean | "true" | "false" | "grammar" | "spelling";
|
|
25
|
+
/**
|
|
26
|
+
* What a field actually renders into `aria-invalid`: one of the tokens that
|
|
27
|
+
* says something, or nothing at all for a valid field. Serializing `true` as
|
|
28
|
+
* the bare attribute name yields `aria-invalid=""`, which resolves to valid.
|
|
29
|
+
*/
|
|
30
|
+
export type AriaInvalidToken = "true" | "grammar" | "spelling";
|
|
31
|
+
/**
|
|
32
|
+
* Inputs {@link resolveFieldWiring} reads off a field convenience wrapper's
|
|
33
|
+
* own props to compute its wiring.
|
|
34
|
+
*/
|
|
35
|
+
export interface FieldWiringOptions {
|
|
36
|
+
/** Semantic color role for the control's focus ring. Falls back to {@link DEFAULT_FIELD_COLOR} when omitted. */
|
|
37
|
+
color?: FieldColor;
|
|
38
|
+
/**
|
|
39
|
+
* Validation message rendered beneath the control. Only its presence is
|
|
40
|
+
* read, never its content: it marks the field invalid and reserves an id
|
|
41
|
+
* for its own error paragraph, unless `ariaInvalid` overrides it.
|
|
42
|
+
*/
|
|
43
|
+
errorMessage?: unknown;
|
|
44
|
+
/**
|
|
45
|
+
* Supporting description rendered beneath the control. Only its presence
|
|
46
|
+
* is read, never its content: it reserves an id for its own paragraph.
|
|
47
|
+
*/
|
|
48
|
+
description?: unknown;
|
|
49
|
+
/** Explicit override for the field's invalid state. Defaults to whether `errorMessage` is set. */
|
|
50
|
+
ariaInvalid?: AriaInvalid;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolved id and aria wiring {@link resolveFieldWiring} produces for a
|
|
54
|
+
* single field convenience wrapper instance.
|
|
55
|
+
*/
|
|
56
|
+
export interface FieldWiring {
|
|
57
|
+
/** Resolved semantic color role for the control's focus ring. */
|
|
58
|
+
resolvedColor: FieldColor;
|
|
59
|
+
/** Resolved invalid state for the control's `aria-invalid`, or `undefined` when the field is valid. */
|
|
60
|
+
resolvedInvalid: AriaInvalidToken | undefined;
|
|
61
|
+
/** Id for the field's description paragraph, or `undefined` when no description is set. */
|
|
62
|
+
descriptionId: string | undefined;
|
|
63
|
+
/** Id for the field's error paragraph, or `undefined` when no error message is set. */
|
|
64
|
+
errorId: string | undefined;
|
|
65
|
+
/** Space-joined `aria-describedby` value referencing whichever of `descriptionId`/`errorId` are set, or `undefined` when neither is. */
|
|
66
|
+
describedBy: string | undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Computes the id and aria wiring a labeled, described, and validated field
|
|
70
|
+
* convenience wrapper needs: the resolved color role, resolved invalid
|
|
71
|
+
* state, description/error paragraph ids, and joined `aria-describedby`.
|
|
72
|
+
*
|
|
73
|
+
* @param id The field instance's own stable identifier, prefixed onto its description and error paragraph ids.
|
|
74
|
+
* @param options The field's own color, error message, description, and invalid override.
|
|
75
|
+
* @returns The resolved color, invalid state, description/error ids, and joined `aria-describedby` value.
|
|
76
|
+
* @example
|
|
77
|
+
* resolveFieldWiring("email", { color: "brand", errorMessage: "Required" });
|
|
78
|
+
* // { resolvedColor: "brand", resolvedInvalid: "true", descriptionId: undefined, errorId: "email-error", describedBy: "email-error" }
|
|
79
|
+
* @example
|
|
80
|
+
* resolveFieldWiring("username", { description: "3-20 characters" });
|
|
81
|
+
* // { resolvedColor: "neutral", resolvedInvalid: undefined, descriptionId: "username-description", errorId: undefined, describedBy: "username-description" }
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolveFieldWiring(id: string, options: FieldWiringOptions): FieldWiring;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id and aria wiring shared by every labeled, described, and validated
|
|
3
|
+
* field convenience wrapper: the resolved semantic color role, the resolved
|
|
4
|
+
* invalid state, the ids reserved for the field's description and error
|
|
5
|
+
* paragraphs, and the joined `aria-describedby` value linking the control to
|
|
6
|
+
* whichever of the two are present. Every field wrapper derives this same
|
|
7
|
+
* handful of values from its own stable identifier and props right after
|
|
8
|
+
* destructuring, so this module gives that computation one home instead of a
|
|
9
|
+
* copy per field type.
|
|
10
|
+
*
|
|
11
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
12
|
+
* @copyright Sergio Xalambrí 2026
|
|
13
|
+
*/
|
|
14
|
+
/** Semantic color role {@link resolveFieldWiring} falls back to when `color` is omitted. */
|
|
15
|
+
const DEFAULT_FIELD_COLOR = "neutral";
|
|
16
|
+
/**
|
|
17
|
+
* Computes the id and aria wiring a labeled, described, and validated field
|
|
18
|
+
* convenience wrapper needs: the resolved color role, resolved invalid
|
|
19
|
+
* state, description/error paragraph ids, and joined `aria-describedby`.
|
|
20
|
+
*
|
|
21
|
+
* @param id The field instance's own stable identifier, prefixed onto its description and error paragraph ids.
|
|
22
|
+
* @param options The field's own color, error message, description, and invalid override.
|
|
23
|
+
* @returns The resolved color, invalid state, description/error ids, and joined `aria-describedby` value.
|
|
24
|
+
* @example
|
|
25
|
+
* resolveFieldWiring("email", { color: "brand", errorMessage: "Required" });
|
|
26
|
+
* // { resolvedColor: "brand", resolvedInvalid: "true", descriptionId: undefined, errorId: "email-error", describedBy: "email-error" }
|
|
27
|
+
* @example
|
|
28
|
+
* resolveFieldWiring("username", { description: "3-20 characters" });
|
|
29
|
+
* // { resolvedColor: "neutral", resolvedInvalid: undefined, descriptionId: "username-description", errorId: undefined, describedBy: "username-description" }
|
|
30
|
+
*/
|
|
31
|
+
export function resolveFieldWiring(id, options) {
|
|
32
|
+
let { color, errorMessage, description, ariaInvalid } = options;
|
|
33
|
+
let resolvedColor = color ?? DEFAULT_FIELD_COLOR;
|
|
34
|
+
let resolvedInvalid = resolveAriaInvalid(ariaInvalid ?? Boolean(errorMessage));
|
|
35
|
+
let descriptionId = description ? `${id}-description` : undefined;
|
|
36
|
+
let errorId = errorMessage ? `${id}-error` : undefined;
|
|
37
|
+
let describedBy = [descriptionId, errorId].filter(Boolean).join(" ") || undefined;
|
|
38
|
+
return { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Folds any accepted invalid state into the token a field can safely render,
|
|
42
|
+
* or `undefined` for a field that is valid.
|
|
43
|
+
*
|
|
44
|
+
* @param invalid The state a field resolved from its own props.
|
|
45
|
+
* @returns The token to render, or `undefined` to render no attribute at all.
|
|
46
|
+
*/
|
|
47
|
+
function resolveAriaInvalid(invalid) {
|
|
48
|
+
if (invalid === true || invalid === "true")
|
|
49
|
+
return "true";
|
|
50
|
+
if (invalid === "grammar" || invalid === "spelling")
|
|
51
|
+
return invalid;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes how far a value has traveled across a numeric range as a
|
|
3
|
+
* percentage — the fill math behind a single-value range control's track,
|
|
4
|
+
* built on the same clamp/round primitives a color channel or picking
|
|
5
|
+
* surface already reaches for, so a percentage held to `[0, 100]` and
|
|
6
|
+
* rounded to two decimal places stays a single shared computation instead of
|
|
7
|
+
* a hand-rolled copy per control.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Computes how far `value` has traveled from `min` toward `max` as a
|
|
14
|
+
* percentage, clamped to `[0, 100]` and rounded to two decimal places;
|
|
15
|
+
* returns `0` for a collapsed or inverted range instead of dividing by zero.
|
|
16
|
+
*
|
|
17
|
+
* @param min Lower bound of the range.
|
|
18
|
+
* @param max Upper bound of the range.
|
|
19
|
+
* @param value Current value the fill represents.
|
|
20
|
+
* @returns The clamped, rounded fill percentage, e.g. `42.5`.
|
|
21
|
+
* @example
|
|
22
|
+
* resolveFillPercent(0, 100, 25); // 25
|
|
23
|
+
* @example
|
|
24
|
+
* resolveFillPercent(0, 10, 15); // 100 (clamped)
|
|
25
|
+
* @example
|
|
26
|
+
* resolveFillPercent(0, 0, 5); // 0 (collapsed range)
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveFillPercent(min: number, max: number, value: number): number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes how far a value has traveled across a numeric range as a
|
|
3
|
+
* percentage — the fill math behind a single-value range control's track,
|
|
4
|
+
* built on the same clamp/round primitives a color channel or picking
|
|
5
|
+
* surface already reaches for, so a percentage held to `[0, 100]` and
|
|
6
|
+
* rounded to two decimal places stays a single shared computation instead of
|
|
7
|
+
* a hand-rolled copy per control.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import { clampChannel, roundChannel } from "./color-math.js";
|
|
13
|
+
/**
|
|
14
|
+
* Computes how far `value` has traveled from `min` toward `max` as a
|
|
15
|
+
* percentage, clamped to `[0, 100]` and rounded to two decimal places;
|
|
16
|
+
* returns `0` for a collapsed or inverted range instead of dividing by zero.
|
|
17
|
+
*
|
|
18
|
+
* @param min Lower bound of the range.
|
|
19
|
+
* @param max Upper bound of the range.
|
|
20
|
+
* @param value Current value the fill represents.
|
|
21
|
+
* @returns The clamped, rounded fill percentage, e.g. `42.5`.
|
|
22
|
+
* @example
|
|
23
|
+
* resolveFillPercent(0, 100, 25); // 25
|
|
24
|
+
* @example
|
|
25
|
+
* resolveFillPercent(0, 10, 15); // 100 (clamped)
|
|
26
|
+
* @example
|
|
27
|
+
* resolveFillPercent(0, 0, 5); // 0 (collapsed range)
|
|
28
|
+
*/
|
|
29
|
+
export function resolveFillPercent(min, max, value) {
|
|
30
|
+
if (max <= min)
|
|
31
|
+
return 0;
|
|
32
|
+
let percent = ((value - min) / (max - min)) * 100;
|
|
33
|
+
return roundChannel(clampChannel(percent, 0, 100), 2);
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to a fixed decimal precision, discarding floating-point
|
|
3
|
+
* noise — shared by every module under `utils/` that cleans up a computed
|
|
4
|
+
* value before formatting, comparing, or plotting it: a color channel
|
|
5
|
+
* rounded to a whole number, or an SVG coordinate cleared of the
|
|
6
|
+
* `1e-16`-scale drift `Math.sin`/`Math.cos` leaves in a "clean" angle.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Rounds `value` to `precision` decimal places.
|
|
13
|
+
*
|
|
14
|
+
* @param value Value to round.
|
|
15
|
+
* @param precision Decimal places to keep. Defaults to `0`.
|
|
16
|
+
* @returns `value` rounded to `precision` decimal places.
|
|
17
|
+
* @example
|
|
18
|
+
* roundChannel(127.6); // 128
|
|
19
|
+
* @example
|
|
20
|
+
* roundChannel(0.4567, 2); // 0.46
|
|
21
|
+
*/
|
|
22
|
+
export declare function roundChannel(value: number, precision?: number): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to a fixed decimal precision, discarding floating-point
|
|
3
|
+
* noise — shared by every module under `utils/` that cleans up a computed
|
|
4
|
+
* value before formatting, comparing, or plotting it: a color channel
|
|
5
|
+
* rounded to a whole number, or an SVG coordinate cleared of the
|
|
6
|
+
* `1e-16`-scale drift `Math.sin`/`Math.cos` leaves in a "clean" angle.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Rounds `value` to `precision` decimal places.
|
|
13
|
+
*
|
|
14
|
+
* @param value Value to round.
|
|
15
|
+
* @param precision Decimal places to keep. Defaults to `0`.
|
|
16
|
+
* @returns `value` rounded to `precision` decimal places.
|
|
17
|
+
* @example
|
|
18
|
+
* roundChannel(127.6); // 128
|
|
19
|
+
* @example
|
|
20
|
+
* roundChannel(0.4567, 2); // 0.46
|
|
21
|
+
*/
|
|
22
|
+
export function roundChannel(value, precision = 0) {
|
|
23
|
+
let factor = 10 ** precision;
|
|
24
|
+
return Math.round(value * factor) / factor;
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The border, tinted background, and emphasized foreground one semantic
|
|
3
|
+
* color role contributes to a bordered, tinted panel — a full-width status
|
|
4
|
+
* or placeholder panel's coloring for a single `&[data-color="..."]` branch
|
|
5
|
+
* — read from that color's own `--ui-*` variables, so the panel follows
|
|
6
|
+
* whatever values the active theme assigns them.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { SemanticColor } from "./semantic-color.js";
|
|
12
|
+
/**
|
|
13
|
+
* The `borderColor`, `backgroundColor`, and `color` declarations a tinted
|
|
14
|
+
* panel sets for one {@link SemanticColor}.
|
|
15
|
+
*/
|
|
16
|
+
export interface SemanticColorPanelStyle {
|
|
17
|
+
/** Border color, read from that color's `--ui-*-border` variable. */
|
|
18
|
+
borderColor: string;
|
|
19
|
+
/** Tinted background color, read from that color's `--ui-*-bg-tint` variable. */
|
|
20
|
+
backgroundColor: string;
|
|
21
|
+
/** Emphasized foreground color, read from that color's `--ui-*-fg-emphasis` variable. */
|
|
22
|
+
color: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds the border, tinted background, and emphasized foreground one
|
|
26
|
+
* semantic color contributes to a tinted panel, each read from that color's
|
|
27
|
+
* own `--ui-*` variables.
|
|
28
|
+
*
|
|
29
|
+
* @param color The semantic color to build the style for.
|
|
30
|
+
* @returns The `borderColor`, `backgroundColor`, and `color` declarations for `color`.
|
|
31
|
+
* @example
|
|
32
|
+
* semanticColorPanelStyle("danger");
|
|
33
|
+
* // { borderColor: "var(--ui-danger-border)", backgroundColor: "var(--ui-danger-bg-tint)", color: "var(--ui-danger-fg-emphasis)" }
|
|
34
|
+
*/
|
|
35
|
+
export declare function semanticColorPanelStyle(color: SemanticColor): SemanticColorPanelStyle;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The border, tinted background, and emphasized foreground one semantic
|
|
3
|
+
* color role contributes to a bordered, tinted panel — a full-width status
|
|
4
|
+
* or placeholder panel's coloring for a single `&[data-color="..."]` branch
|
|
5
|
+
* — read from that color's own `--ui-*` variables, so the panel follows
|
|
6
|
+
* whatever values the active theme assigns them.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Builds the border, tinted background, and emphasized foreground one
|
|
13
|
+
* semantic color contributes to a tinted panel, each read from that color's
|
|
14
|
+
* own `--ui-*` variables.
|
|
15
|
+
*
|
|
16
|
+
* @param color The semantic color to build the style for.
|
|
17
|
+
* @returns The `borderColor`, `backgroundColor`, and `color` declarations for `color`.
|
|
18
|
+
* @example
|
|
19
|
+
* semanticColorPanelStyle("danger");
|
|
20
|
+
* // { borderColor: "var(--ui-danger-border)", backgroundColor: "var(--ui-danger-bg-tint)", color: "var(--ui-danger-fg-emphasis)" }
|
|
21
|
+
*/
|
|
22
|
+
export function semanticColorPanelStyle(color) {
|
|
23
|
+
return {
|
|
24
|
+
borderColor: `var(--ui-${color}-border)`,
|
|
25
|
+
backgroundColor: `var(--ui-${color}-bg-tint)`,
|
|
26
|
+
color: `var(--ui-${color}-fg-emphasis)`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The semantic color role shared by every component that colors itself
|
|
3
|
+
* through one of five tones rather than an arbitrary palette — a status
|
|
4
|
+
* message's tint, a badge's fill, a button's emphasis. Each tone maps to its
|
|
5
|
+
* own set of `--ui-*` variables (border, tint, solid background,
|
|
6
|
+
* foreground, focus ring, …), so a component reads this single literal
|
|
7
|
+
* union and lets the theme resolve every actual color value from it.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* One of the five semantic tones a component colors itself with: `"brand"`,
|
|
14
|
+
* `"neutral"`, `"success"`, `"warning"`, or `"danger"`. Every component's own
|
|
15
|
+
* `Color` type resolves to this shared union, keeping tone naming consistent.
|
|
16
|
+
*/
|
|
17
|
+
export type SemanticColor = "brand" | "neutral" | "success" | "warning" | "danger";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The semantic color role shared by every component that colors itself
|
|
3
|
+
* through one of five tones rather than an arbitrary palette — a status
|
|
4
|
+
* message's tint, a badge's fill, a button's emphasis. Each tone maps to its
|
|
5
|
+
* own set of `--ui-*` variables (border, tint, solid background,
|
|
6
|
+
* foreground, focus ring, …), so a component reads this single literal
|
|
7
|
+
* union and lets the theme resolve every actual color value from it.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dev-mode missing-accessible-name check shared by every icon-only
|
|
3
|
+
* control, landmark, and group across the component catalog. A control logs
|
|
4
|
+
* a `console.warn` only when a consumer has supplied it no way to announce
|
|
5
|
+
* itself to assistive technology: no `aria-label`, no `aria-labelledby`, and,
|
|
6
|
+
* where the control can otherwise fall back to its own visible content, no
|
|
7
|
+
* text in its `children` either. Every component wires the check to its own
|
|
8
|
+
* message describing what it is and what it needs, right after destructuring
|
|
9
|
+
* its props.
|
|
10
|
+
*
|
|
11
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
12
|
+
* @copyright Sergio Xalambrí 2026
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The two ARIA attributes this module's checks read to tell whether a
|
|
16
|
+
* consumer already supplied an accessible name explicitly, regardless of
|
|
17
|
+
* whatever other props a component's own type carries alongside them.
|
|
18
|
+
*/
|
|
19
|
+
export interface AccessibleNameProps {
|
|
20
|
+
"aria-label"?: unknown;
|
|
21
|
+
"aria-labelledby"?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Logs `message` through `console.warn`, in dev mode only, when `props`
|
|
25
|
+
* carries neither `aria-label` nor `aria-labelledby` and `children` resolves to
|
|
26
|
+
* no visible text — leaving assistive technology no accessible name to announce.
|
|
27
|
+
*
|
|
28
|
+
* @param props The component's own props, read for `aria-label` and `aria-labelledby`.
|
|
29
|
+
* @param children The component's own `children` prop, walked by {@link hasAccessibleText} for visible text.
|
|
30
|
+
* @param message The dev-mode warning to log when none of the three supply an accessible name.
|
|
31
|
+
* @example
|
|
32
|
+
* warnIfNoAccessibleName(
|
|
33
|
+
* handle.props,
|
|
34
|
+
* children,
|
|
35
|
+
* "Button: an icon-only button needs an `aria-label` describing what it does.",
|
|
36
|
+
* );
|
|
37
|
+
*/
|
|
38
|
+
export declare function warnIfNoAccessibleName(props: AccessibleNameProps, children: unknown, message: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Logs `message` through `console.warn`, in dev mode only, when `props`
|
|
41
|
+
* carries neither `aria-label` nor `aria-labelledby` — for a host such as a
|
|
42
|
+
* navigation landmark or grouping wrapper with no `children` fallback of its own.
|
|
43
|
+
*
|
|
44
|
+
* @param props The component's own props, read for `aria-label` and `aria-labelledby`.
|
|
45
|
+
* @param message The dev-mode warning to log when neither attribute supplies an accessible name.
|
|
46
|
+
* @example
|
|
47
|
+
* warnIfNoAccessibleLabel(
|
|
48
|
+
* handle.props,
|
|
49
|
+
* 'Pagination: needs an "aria-label" or "aria-labelledby" identifying which set of results it paginates.',
|
|
50
|
+
* );
|
|
51
|
+
*/
|
|
52
|
+
export declare function warnIfNoAccessibleLabel(props: AccessibleNameProps, message: string): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dev-mode missing-accessible-name check shared by every icon-only
|
|
3
|
+
* control, landmark, and group across the component catalog. A control logs
|
|
4
|
+
* a `console.warn` only when a consumer has supplied it no way to announce
|
|
5
|
+
* itself to assistive technology: no `aria-label`, no `aria-labelledby`, and,
|
|
6
|
+
* where the control can otherwise fall back to its own visible content, no
|
|
7
|
+
* text in its `children` either. Every component wires the check to its own
|
|
8
|
+
* message describing what it is and what it needs, right after destructuring
|
|
9
|
+
* its props.
|
|
10
|
+
*
|
|
11
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
12
|
+
* @copyright Sergio Xalambrí 2026
|
|
13
|
+
*/
|
|
14
|
+
import { hasAccessibleText } from "./has-accessible-text.js";
|
|
15
|
+
/**
|
|
16
|
+
* Logs `message` through `console.warn`, in dev mode only, when `props`
|
|
17
|
+
* carries neither `aria-label` nor `aria-labelledby` and `children` resolves to
|
|
18
|
+
* no visible text — leaving assistive technology no accessible name to announce.
|
|
19
|
+
*
|
|
20
|
+
* @param props The component's own props, read for `aria-label` and `aria-labelledby`.
|
|
21
|
+
* @param children The component's own `children` prop, walked by {@link hasAccessibleText} for visible text.
|
|
22
|
+
* @param message The dev-mode warning to log when none of the three supply an accessible name.
|
|
23
|
+
* @example
|
|
24
|
+
* warnIfNoAccessibleName(
|
|
25
|
+
* handle.props,
|
|
26
|
+
* children,
|
|
27
|
+
* "Button: an icon-only button needs an `aria-label` describing what it does.",
|
|
28
|
+
* );
|
|
29
|
+
*/
|
|
30
|
+
export function warnIfNoAccessibleName(props, children, message) {
|
|
31
|
+
if (import.meta.env.DEV &&
|
|
32
|
+
!props["aria-label"] &&
|
|
33
|
+
!props["aria-labelledby"] &&
|
|
34
|
+
!hasAccessibleText(children)) {
|
|
35
|
+
console.warn(message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Logs `message` through `console.warn`, in dev mode only, when `props`
|
|
40
|
+
* carries neither `aria-label` nor `aria-labelledby` — for a host such as a
|
|
41
|
+
* navigation landmark or grouping wrapper with no `children` fallback of its own.
|
|
42
|
+
*
|
|
43
|
+
* @param props The component's own props, read for `aria-label` and `aria-labelledby`.
|
|
44
|
+
* @param message The dev-mode warning to log when neither attribute supplies an accessible name.
|
|
45
|
+
* @example
|
|
46
|
+
* warnIfNoAccessibleLabel(
|
|
47
|
+
* handle.props,
|
|
48
|
+
* 'Pagination: needs an "aria-label" or "aria-labelledby" identifying which set of results it paginates.',
|
|
49
|
+
* );
|
|
50
|
+
*/
|
|
51
|
+
export function warnIfNoAccessibleLabel(props, message) {
|
|
52
|
+
if (import.meta.env.DEV && !props["aria-label"] && !props["aria-labelledby"]) {
|
|
53
|
+
console.warn(message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cookie-write every mixin persisting client-side state across a full
|
|
3
|
+
* page navigation repeats on its own: a Sidebar's collapsed flag, a theme
|
|
4
|
+
* switch's active mode, or any other single value a mixin mirrors into a
|
|
5
|
+
* cookie so the next server render can read it back and start already in the
|
|
6
|
+
* same state, ahead of hydration ever running.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Seconds a cookie written by {@link writeCookie} stays valid when a call
|
|
13
|
+
* omits `maxAgeSeconds` — a year, long enough that a returning visitor's
|
|
14
|
+
* persisted state outlives typical browsing gaps.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ONE_YEAR_SECONDS: number;
|
|
17
|
+
/**
|
|
18
|
+
* Writes `value` under `name` into a `path=/`, `samesite=lax` cookie, so the
|
|
19
|
+
* next full navigation's server render can read it back and start already in
|
|
20
|
+
* the same state, ahead of hydration ever running.
|
|
21
|
+
*
|
|
22
|
+
* @param name Cookie name to write the value under.
|
|
23
|
+
* @param value Value to persist — interpolated directly into the cookie
|
|
24
|
+
* string, so a boolean persists as `"true"`/`"false"` and a string persists
|
|
25
|
+
* as-is.
|
|
26
|
+
* @param maxAgeSeconds Seconds the cookie stays valid before a browser drops
|
|
27
|
+
* it. Defaults to {@link ONE_YEAR_SECONDS}.
|
|
28
|
+
* @example
|
|
29
|
+
* writeCookie("app-sidebar:collapsed", true);
|
|
30
|
+
* @example
|
|
31
|
+
* writeCookie("ui:theme", "dark");
|
|
32
|
+
* @example
|
|
33
|
+
* writeCookie("ui:announcement-dismissed", true, 60 * 60 * 24 * 7);
|
|
34
|
+
*/
|
|
35
|
+
export declare function writeCookie(name: string, value: string | boolean, maxAgeSeconds?: number): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cookie-write every mixin persisting client-side state across a full
|
|
3
|
+
* page navigation repeats on its own: a Sidebar's collapsed flag, a theme
|
|
4
|
+
* switch's active mode, or any other single value a mixin mirrors into a
|
|
5
|
+
* cookie so the next server render can read it back and start already in the
|
|
6
|
+
* same state, ahead of hydration ever running.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Seconds a cookie written by {@link writeCookie} stays valid when a call
|
|
13
|
+
* omits `maxAgeSeconds` — a year, long enough that a returning visitor's
|
|
14
|
+
* persisted state outlives typical browsing gaps.
|
|
15
|
+
*/
|
|
16
|
+
export const ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
|
|
17
|
+
/**
|
|
18
|
+
* Writes `value` under `name` into a `path=/`, `samesite=lax` cookie, so the
|
|
19
|
+
* next full navigation's server render can read it back and start already in
|
|
20
|
+
* the same state, ahead of hydration ever running.
|
|
21
|
+
*
|
|
22
|
+
* @param name Cookie name to write the value under.
|
|
23
|
+
* @param value Value to persist — interpolated directly into the cookie
|
|
24
|
+
* string, so a boolean persists as `"true"`/`"false"` and a string persists
|
|
25
|
+
* as-is.
|
|
26
|
+
* @param maxAgeSeconds Seconds the cookie stays valid before a browser drops
|
|
27
|
+
* it. Defaults to {@link ONE_YEAR_SECONDS}.
|
|
28
|
+
* @example
|
|
29
|
+
* writeCookie("app-sidebar:collapsed", true);
|
|
30
|
+
* @example
|
|
31
|
+
* writeCookie("ui:theme", "dark");
|
|
32
|
+
* @example
|
|
33
|
+
* writeCookie("ui:announcement-dismissed", true, 60 * 60 * 24 * 7);
|
|
34
|
+
*/
|
|
35
|
+
export function writeCookie(name, value, maxAgeSeconds = ONE_YEAR_SECONDS) {
|
|
36
|
+
document.cookie = `${name}=${value}; path=/; max-age=${maxAgeSeconds}; samesite=lax`;
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sdxc/ui",
|
|
3
|
+
"version": "0.0.0-pre.1",
|
|
4
|
+
"description": "Styled, accessible remix/ui components rendered as server HTML",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./animations": "./dist/animations/index.js",
|
|
11
|
+
"./behaviors": "./dist/behaviors/index.js",
|
|
12
|
+
"./mixins": "./dist/mixins/index.js",
|
|
13
|
+
"./styles": "./dist/styles/index.js",
|
|
14
|
+
"./utils": "./dist/utils/index.js",
|
|
15
|
+
"./reset.css": "./src/reset.css",
|
|
16
|
+
"./theme.css": "./src/theme.css"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@sdxc/icons": "0.0.0-pre.1",
|
|
20
|
+
"@sdxc/u": "0.0.0-pre.1",
|
|
21
|
+
"remix": "3.0.0-rc.2"
|
|
22
|
+
},
|
|
23
|
+
"gitHead": "e96a064f9208eb667923f57374e2cdaac73c72fb",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/sergiodxa/monorepo.git",
|
|
30
|
+
"directory": "packages/ui"
|
|
31
|
+
}
|
|
32
|
+
}
|