@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,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "remix/ui/jsx-runtime";
|
|
2
|
+
import { fg } from "@sdxc/u/color";
|
|
3
|
+
import { text, weight } from "@sdxc/u/typography";
|
|
4
|
+
import { attrs } from "remix/ui";
|
|
5
|
+
/**
|
|
6
|
+
* `data-field-error` applied through {@link attrs} unless a consumer
|
|
7
|
+
* overrides it, marking the host as a field's error slot so a validation
|
|
8
|
+
* script can locate it via the field's `aria-describedby` list.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_FIELD_ERROR_ATTRIBUTE = true;
|
|
11
|
+
/**
|
|
12
|
+
* Renders a field's validation message. `id` falls back to `handle.id` so
|
|
13
|
+
* a sibling `aria-describedby` can target it via `data-field-error`; pass
|
|
14
|
+
* `hidden` to keep it out of layout until the field is invalid.
|
|
15
|
+
*
|
|
16
|
+
* @param handle Runtime handle carrying the host `<span>`'s props.
|
|
17
|
+
* @returns The render function producing the error message's markup.
|
|
18
|
+
* @example
|
|
19
|
+
* <input id="email" type="email" required aria-describedby="email-error" />
|
|
20
|
+
* <FieldError id="email-error">{t("fields.email.required")}</FieldError>
|
|
21
|
+
* @example
|
|
22
|
+
* <input type="email" required aria-describedby={handle.id} />
|
|
23
|
+
* <FieldError hidden={!errors.email}>{errors.email}</FieldError>
|
|
24
|
+
*/
|
|
25
|
+
export function FieldError(handle) {
|
|
26
|
+
return () => {
|
|
27
|
+
let { id, mix, ...rest } = handle.props;
|
|
28
|
+
return (_jsx("span", { id: id ?? handle.id, ...rest, mix: [
|
|
29
|
+
attrs({ "data-field-error": DEFAULT_FIELD_ERROR_ATTRIBUTE }),
|
|
30
|
+
fg("danger"),
|
|
31
|
+
weight("medium"),
|
|
32
|
+
text("sm"),
|
|
33
|
+
mix,
|
|
34
|
+
] }));
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pressable surface that opens the platform's file picker, backed by a
|
|
3
|
+
* native `<input type="file">` wrapped in a `<label>` so the platform itself
|
|
4
|
+
* handles the trigger-to-picker wiring. Its visible content renders inside
|
|
5
|
+
* the same label as a button-like surface, colored, weighted, and sized
|
|
6
|
+
* through the same semantic contract as this library's other pressable
|
|
7
|
+
* controls.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/ui";
|
|
13
|
+
/**
|
|
14
|
+
* Prop types for {@link FileTrigger}.
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace FileTrigger {
|
|
17
|
+
/**
|
|
18
|
+
* Semantic color role, each mapped to its matching `--ui-*` variables.
|
|
19
|
+
*/
|
|
20
|
+
type Color = "brand" | "neutral" | "success" | "warning" | "danger";
|
|
21
|
+
/**
|
|
22
|
+
* Visual weight the trigger renders with: a solid fill with an on-solid
|
|
23
|
+
* foreground, a transparent fill with a strong colored border, or a fully
|
|
24
|
+
* transparent fill with just a colored label.
|
|
25
|
+
*/
|
|
26
|
+
type Variant = "solid" | "outline" | "ghost";
|
|
27
|
+
/**
|
|
28
|
+
* Size variant controlling the trigger's padding and font size.
|
|
29
|
+
*/
|
|
30
|
+
type Size = "sm" | "md" | "lg";
|
|
31
|
+
/**
|
|
32
|
+
* Per-part styling for the elements this component composes besides its
|
|
33
|
+
* own host `<input>`.
|
|
34
|
+
*/
|
|
35
|
+
interface PartsProps {
|
|
36
|
+
/** Styling for the `<label>` rendering as the trigger's visible, pressable surface. */
|
|
37
|
+
trigger?: TagProps<"label">["mix"];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Props accepted by {@link FileTrigger}. Every native `<input type="file">`
|
|
41
|
+
* attribute applies unchanged except `type` (fixed `"file"`), `role` (not
|
|
42
|
+
* overridable on a file input), and `size` (repurposed for visual size).
|
|
43
|
+
*/
|
|
44
|
+
interface Props extends Omit<TagProps<"input">, "type" | "role" | "size"> {
|
|
45
|
+
/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */
|
|
46
|
+
color?: Color;
|
|
47
|
+
/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */
|
|
48
|
+
variant?: Variant;
|
|
49
|
+
/** Size variant. Defaults to {@link DEFAULT_SIZE}. */
|
|
50
|
+
size?: Size;
|
|
51
|
+
/**
|
|
52
|
+
* Switches the picker from choosing individual files to choosing whole
|
|
53
|
+
* directories, carrying every file nested inside the chosen directory.
|
|
54
|
+
*/
|
|
55
|
+
acceptDirectory?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The trigger's visible content, rendered inside the same `<label>` that
|
|
58
|
+
* wraps the host `<input>` — an icon, text, or both, kept decorative so
|
|
59
|
+
* the platform's label-to-control association reaches the input on click.
|
|
60
|
+
*/
|
|
61
|
+
children?: RemixNode;
|
|
62
|
+
/** Per-part styling for this component's internally composed elements. */
|
|
63
|
+
parts?: PartsProps;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Renders a native `<input type="file">` wrapped in a `<label>` styled
|
|
68
|
+
* through this library's shared `data-color`/`data-variant`/`data-size`
|
|
69
|
+
* contract; in dev mode, content lacking an accessible name logs a warning.
|
|
70
|
+
*
|
|
71
|
+
* @param handle Runtime handle carrying the host `<input>`'s props.
|
|
72
|
+
* @returns The render function producing the trigger's markup.
|
|
73
|
+
* @example
|
|
74
|
+
* <FileTrigger name="avatar" accept="image/png, image/jpeg">
|
|
75
|
+
* {t("profile.chooseFile")}
|
|
76
|
+
* </FileTrigger>
|
|
77
|
+
* @example
|
|
78
|
+
* <FileTrigger name="attachments" multiple color="brand" variant="outline">
|
|
79
|
+
* {t("thread.attachFiles")}
|
|
80
|
+
* </FileTrigger>
|
|
81
|
+
* @example
|
|
82
|
+
* <FileTrigger name="folder" acceptDirectory aria-label={t("importer.chooseFolder")} />
|
|
83
|
+
*/
|
|
84
|
+
export declare function FileTrigger(handle: Handle<FileTrigger.Props>): () => import("remix/ui").RemixElement;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/ui/jsx-runtime";
|
|
2
|
+
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
3
|
+
import { bg, border, fg, outline } from "@sdxc/u/color";
|
|
4
|
+
import { opacity, rounded } from "@sdxc/u/effects";
|
|
5
|
+
import { cursor, userSelect } from "@sdxc/u/general";
|
|
6
|
+
import { gap, inlineFlex, items, justify } from "@sdxc/u/layout";
|
|
7
|
+
import { pb, pi } from "@sdxc/u/size";
|
|
8
|
+
import { active, data, hover, when } from "@sdxc/u/state";
|
|
9
|
+
import { text, weight } from "@sdxc/u/typography";
|
|
10
|
+
import { attrs } from "remix/ui";
|
|
11
|
+
import { interactiveTransition } from "../styles/interactive-transition.js";
|
|
12
|
+
import { hasAccessibleText } from "../utils/has-accessible-text.js";
|
|
13
|
+
/** Semantic color role {@link FileTrigger} falls back to when `color` is omitted. */
|
|
14
|
+
const DEFAULT_COLOR = "neutral";
|
|
15
|
+
/** Visual weight {@link FileTrigger} falls back to when `variant` is omitted. */
|
|
16
|
+
const DEFAULT_VARIANT = "solid";
|
|
17
|
+
/** Size variant {@link FileTrigger} falls back to when `size` is omitted. */
|
|
18
|
+
const DEFAULT_SIZE = "md";
|
|
19
|
+
/**
|
|
20
|
+
* Renders a native `<input type="file">` wrapped in a `<label>` styled
|
|
21
|
+
* through this library's shared `data-color`/`data-variant`/`data-size`
|
|
22
|
+
* contract; in dev mode, content lacking an accessible name logs a warning.
|
|
23
|
+
*
|
|
24
|
+
* @param handle Runtime handle carrying the host `<input>`'s props.
|
|
25
|
+
* @returns The render function producing the trigger's markup.
|
|
26
|
+
* @example
|
|
27
|
+
* <FileTrigger name="avatar" accept="image/png, image/jpeg">
|
|
28
|
+
* {t("profile.chooseFile")}
|
|
29
|
+
* </FileTrigger>
|
|
30
|
+
* @example
|
|
31
|
+
* <FileTrigger name="attachments" multiple color="brand" variant="outline">
|
|
32
|
+
* {t("thread.attachFiles")}
|
|
33
|
+
* </FileTrigger>
|
|
34
|
+
* @example
|
|
35
|
+
* <FileTrigger name="folder" acceptDirectory aria-label={t("importer.chooseFolder")} />
|
|
36
|
+
*/
|
|
37
|
+
export function FileTrigger(handle) {
|
|
38
|
+
return () => {
|
|
39
|
+
let { color, variant, size, acceptDirectory, children, parts, mix, ...rest } = handle.props;
|
|
40
|
+
let resolvedColor = color ?? DEFAULT_COLOR;
|
|
41
|
+
let resolvedVariant = variant ?? DEFAULT_VARIANT;
|
|
42
|
+
let resolvedSize = size ?? DEFAULT_SIZE;
|
|
43
|
+
if (import.meta.env.DEV &&
|
|
44
|
+
!handle.props["aria-label"] &&
|
|
45
|
+
!handle.props["aria-labelledby"] &&
|
|
46
|
+
!hasAccessibleText(children)) {
|
|
47
|
+
console.warn("FileTrigger: a trigger with no visible label text needs an `aria-label` describing what it opens — assistive technology has no accessible name to announce otherwise.");
|
|
48
|
+
}
|
|
49
|
+
return (_jsxs("label", { "data-slot": "trigger", "data-color": resolvedColor, "data-variant": resolvedVariant, "data-size": resolvedSize, mix: [
|
|
50
|
+
interactiveTransition(),
|
|
51
|
+
inlineFlex(),
|
|
52
|
+
items("center"),
|
|
53
|
+
justify("center"),
|
|
54
|
+
gap(2),
|
|
55
|
+
rounded("md"),
|
|
56
|
+
weight("medium"),
|
|
57
|
+
when("&:has(input:focus-visible)", [
|
|
58
|
+
outline({ color: "brand.ring", offset: 2 }),
|
|
59
|
+
data("color", "neutral", outline("neutral.ring")),
|
|
60
|
+
data("color", "success", outline("success.ring")),
|
|
61
|
+
data("color", "warning", outline("warning.ring")),
|
|
62
|
+
data("color", "danger", outline("danger.ring")),
|
|
63
|
+
]),
|
|
64
|
+
when("&:has(input:disabled)", [opacity(50), cursor("not-allowed")]),
|
|
65
|
+
cursor("default"),
|
|
66
|
+
userSelect(),
|
|
67
|
+
pi("1rem"),
|
|
68
|
+
pb("0.5rem"),
|
|
69
|
+
text("sm"),
|
|
70
|
+
data("size", "sm", [pi("0.75rem"), pb("0.375rem"), text("xs")]),
|
|
71
|
+
data("size", "lg", [pi("1.25rem"), pb("0.625rem"), text("base")]),
|
|
72
|
+
data("variant", "solid", [
|
|
73
|
+
data("color", "brand", [
|
|
74
|
+
bg("brand.solid"),
|
|
75
|
+
fg("brand.onSolid"),
|
|
76
|
+
hover(bg("brand.bg-solid-hover")),
|
|
77
|
+
active(bg("brand.bg-solid-pressed")),
|
|
78
|
+
]),
|
|
79
|
+
data("color", "neutral", [
|
|
80
|
+
bg("neutral.solid"),
|
|
81
|
+
fg("neutral.onSolid"),
|
|
82
|
+
hover(bg("neutral.bg-solid-hover")),
|
|
83
|
+
active(bg("neutral.bg-solid-pressed")),
|
|
84
|
+
]),
|
|
85
|
+
data("color", "success", [
|
|
86
|
+
bg("success.solid"),
|
|
87
|
+
fg("success.onSolid"),
|
|
88
|
+
hover(bg("success.bg-solid-hover")),
|
|
89
|
+
active(bg("success.bg-solid-pressed")),
|
|
90
|
+
]),
|
|
91
|
+
data("color", "warning", [
|
|
92
|
+
bg("warning.solid"),
|
|
93
|
+
fg("warning.onSolid"),
|
|
94
|
+
hover(bg("warning.bg-solid-hover")),
|
|
95
|
+
active(bg("warning.bg-solid-pressed")),
|
|
96
|
+
]),
|
|
97
|
+
data("color", "danger", [
|
|
98
|
+
bg("danger.solid"),
|
|
99
|
+
fg("danger.onSolid"),
|
|
100
|
+
hover(bg("danger.bg-solid-hover")),
|
|
101
|
+
active(bg("danger.bg-solid-pressed")),
|
|
102
|
+
]),
|
|
103
|
+
]),
|
|
104
|
+
data("variant", "outline", [
|
|
105
|
+
border({ width: 2, noStyleDefault: true }),
|
|
106
|
+
bg("transparent"),
|
|
107
|
+
data("color", "brand", [
|
|
108
|
+
border("brand.strong"),
|
|
109
|
+
fg("brand"),
|
|
110
|
+
hover(bg("brand.tint")),
|
|
111
|
+
active(bg("brand.bg-tint-hover")),
|
|
112
|
+
]),
|
|
113
|
+
data("color", "neutral", [
|
|
114
|
+
border("neutral.strong"),
|
|
115
|
+
fg("neutral"),
|
|
116
|
+
hover(bg("neutral.tint")),
|
|
117
|
+
active(bg("neutral.bg-tint-hover")),
|
|
118
|
+
]),
|
|
119
|
+
data("color", "success", [
|
|
120
|
+
border("success.strong"),
|
|
121
|
+
fg("success"),
|
|
122
|
+
hover(bg("success.tint")),
|
|
123
|
+
active(bg("success.bg-tint-hover")),
|
|
124
|
+
]),
|
|
125
|
+
data("color", "warning", [
|
|
126
|
+
border("warning.strong"),
|
|
127
|
+
fg("warning"),
|
|
128
|
+
hover(bg("warning.tint")),
|
|
129
|
+
active(bg("warning.bg-tint-hover")),
|
|
130
|
+
]),
|
|
131
|
+
data("color", "danger", [
|
|
132
|
+
border("danger.strong"),
|
|
133
|
+
fg("danger"),
|
|
134
|
+
hover(bg("danger.tint")),
|
|
135
|
+
active(bg("danger.bg-tint-hover")),
|
|
136
|
+
]),
|
|
137
|
+
]),
|
|
138
|
+
data("variant", "ghost", [
|
|
139
|
+
bg("transparent"),
|
|
140
|
+
data("color", "brand", [
|
|
141
|
+
fg("brand"),
|
|
142
|
+
hover(bg("brand.tint")),
|
|
143
|
+
active(bg("brand.bg-tint-hover")),
|
|
144
|
+
]),
|
|
145
|
+
data("color", "neutral", [
|
|
146
|
+
fg("neutral"),
|
|
147
|
+
hover(bg("neutral.bg-tint-hover")),
|
|
148
|
+
active(bg("neutral.bg-tint-pressed")),
|
|
149
|
+
]),
|
|
150
|
+
data("color", "success", [
|
|
151
|
+
fg("success"),
|
|
152
|
+
hover(bg("success.tint")),
|
|
153
|
+
active(bg("success.bg-tint-hover")),
|
|
154
|
+
]),
|
|
155
|
+
data("color", "warning", [
|
|
156
|
+
fg("warning"),
|
|
157
|
+
hover(bg("warning.tint")),
|
|
158
|
+
active(bg("warning.bg-tint-hover")),
|
|
159
|
+
]),
|
|
160
|
+
data("color", "danger", [
|
|
161
|
+
fg("danger"),
|
|
162
|
+
hover(bg("danger.tint")),
|
|
163
|
+
active(bg("danger.bg-tint-hover")),
|
|
164
|
+
]),
|
|
165
|
+
]),
|
|
166
|
+
parts?.trigger,
|
|
167
|
+
], children: [children, _jsx("input", { type: "file", ...rest, mix: [acceptDirectory && attrs({ webkitdirectory: true }), visuallyHidden(), mix] })] }));
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wrapper every multi-field layout starts from: a native `<form>` laying
|
|
3
|
+
* its children out in a single spaced column, and the point where a parsed
|
|
4
|
+
* validation result enters the tree. Set `issues` from a `parseSafe` (or any
|
|
5
|
+
* other Standard Schema compliant) result and every field beneath it can
|
|
6
|
+
* pick out its own errors by name through component context, with no
|
|
7
|
+
* `issues` prop threaded down by hand.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/ui";
|
|
13
|
+
/**
|
|
14
|
+
* Prop types for {@link Form} and the context value it provides to
|
|
15
|
+
* descendant fields.
|
|
16
|
+
*/
|
|
17
|
+
export declare namespace Form {
|
|
18
|
+
/**
|
|
19
|
+
* A single validation failure as reported by a Standard Schema compliant
|
|
20
|
+
* validator. `path` locates the field the issue belongs to — a plain key,
|
|
21
|
+
* an index, or a `{ key }` segment — or is omitted for a form-level issue.
|
|
22
|
+
*/
|
|
23
|
+
interface Issue {
|
|
24
|
+
/** Human-readable failure message, rendered verbatim by a field's `FieldError`. */
|
|
25
|
+
readonly message: string;
|
|
26
|
+
/** Field location of the issue, e.g. `["email"]` or `["address", "zip"]`. Omitted for a form-level issue. */
|
|
27
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
28
|
+
readonly key: PropertyKey;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Value {@link Form} stores in component context. A field reads it with
|
|
33
|
+
* `handle.context.get(Form)` to find its own issues by name and learn
|
|
34
|
+
* whether it's the field that should carry `autofocus` on this render.
|
|
35
|
+
*/
|
|
36
|
+
interface Context {
|
|
37
|
+
/**
|
|
38
|
+
* Every issue whose `path` resolves to `name` (segments joined with
|
|
39
|
+
* `"."`, e.g. `"address.zip"`), or an empty array when the field has
|
|
40
|
+
* none.
|
|
41
|
+
*
|
|
42
|
+
* @param name Field name to look up, matching its `name` attribute.
|
|
43
|
+
* @returns The issues addressed to that field, in {@link Form.Props.issues} order.
|
|
44
|
+
*/
|
|
45
|
+
getIssues(name: string): ReadonlyArray<Issue>;
|
|
46
|
+
/**
|
|
47
|
+
* `true` for the single field name that comes first among
|
|
48
|
+
* {@link Form.Props.issues}, so exactly one invalid field renders
|
|
49
|
+
* `autofocus`, landing keyboard focus on it after a server re-render.
|
|
50
|
+
*
|
|
51
|
+
* @param name Field name to check, matching its `name` attribute.
|
|
52
|
+
* @returns Whether `name` is the first invalid field this render.
|
|
53
|
+
*/
|
|
54
|
+
isFirstInvalid(name: string): boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Props accepted by {@link Form}.
|
|
58
|
+
*/
|
|
59
|
+
interface Props extends TagProps<"form"> {
|
|
60
|
+
/**
|
|
61
|
+
* Validation issues from a `parseSafe` (or equivalent Standard Schema)
|
|
62
|
+
* result, provided to every descendant field through component
|
|
63
|
+
* context. Defaults to no issues, matching a first render.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* let result = parseSafe(ContactSchema, await request.formData());
|
|
67
|
+
* if (!result.success) return ctx.render(<ContactPage issues={result.issues} />, { status: 400 });
|
|
68
|
+
*/
|
|
69
|
+
issues?: ReadonlyArray<Issue>;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Renders a native `<form>` laying children out in a single column, and
|
|
74
|
+
* provides {@link Form.Context} so descendant fields resolve their own
|
|
75
|
+
* issues by name and focus the first invalid field with no client JS.
|
|
76
|
+
*
|
|
77
|
+
* @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.
|
|
78
|
+
* @returns The render function producing the form's markup.
|
|
79
|
+
* @example
|
|
80
|
+
* let result = parseSafe(ContactSchema, formData);
|
|
81
|
+
* <Form method="post" issues={result.success ? undefined : result.issues}>
|
|
82
|
+
* <TextField name="email" label={t("contact.email")} />
|
|
83
|
+
* <Button type="submit">{t("contact.submit")}</Button>
|
|
84
|
+
* </Form>
|
|
85
|
+
*/
|
|
86
|
+
export declare function Form(handle: Handle<Form.Props, Form.Context>): () => import("remix/ui").RemixElement;
|
|
87
|
+
/**
|
|
88
|
+
* What a field resolved for its own validation state this render, from its
|
|
89
|
+
* own props and from whatever the enclosing {@link Form} knows about it.
|
|
90
|
+
*/
|
|
91
|
+
export interface FieldIssueState {
|
|
92
|
+
/** Message the field renders through its `FieldError`, or `undefined` for a field with nothing to report. */
|
|
93
|
+
errorMessage: RemixNode | undefined;
|
|
94
|
+
/** Whether this is the field that should carry `autofocus`, so focus lands on the first problem after a server round-trip. */
|
|
95
|
+
isFirstInvalid: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reads the {@link Form.Context} provided by the nearest ancestor
|
|
99
|
+
* {@link Form}, resolving to `undefined` when no Form wraps the caller so
|
|
100
|
+
* every field renders safely inside or outside a Form.
|
|
101
|
+
*
|
|
102
|
+
* @param handle Runtime handle of the field performing the lookup.
|
|
103
|
+
* @returns The enclosing form's context, or `undefined` where no Form wraps the caller.
|
|
104
|
+
*/
|
|
105
|
+
export declare function readFormContext(handle: Handle<unknown, any>): Form.Context | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the validation state a field renders: an explicit `errorMessage`
|
|
108
|
+
* always wins over a matching {@link Form} issue for `name`, which is how
|
|
109
|
+
* `Form`'s `issues` reach a field with no per-field prop threaded by hand.
|
|
110
|
+
*
|
|
111
|
+
* @param handle Runtime handle of the field resolving its state.
|
|
112
|
+
* @param name The field's `name` attribute, used to look its issues up.
|
|
113
|
+
* @param errorMessage An `errorMessage` passed directly to the field, if any.
|
|
114
|
+
* @returns The message to render and whether this field carries `autofocus`.
|
|
115
|
+
* @example
|
|
116
|
+
* let { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, "email", handle.props.errorMessage);
|
|
117
|
+
*/
|
|
118
|
+
export declare function resolveFieldIssue(handle: Handle<unknown, any>, name: string | undefined, errorMessage?: RemixNode): FieldIssueState;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx } from "remix/ui/jsx-runtime";
|
|
2
|
+
import { flex, flexCol, gap } from "@sdxc/u/layout";
|
|
3
|
+
/** {@link Form.Props.issues} fallback for a first, not-yet-submitted render. */
|
|
4
|
+
const DEFAULT_ISSUES = [];
|
|
5
|
+
/** Shared empty result {@link Form.Context.getIssues} returns for a field with no matching issue. */
|
|
6
|
+
const NO_ISSUES = [];
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the flat field name an issue's `path` addresses, joining every
|
|
9
|
+
* segment with `"."` (`["address", "zip"]` becomes `"address.zip"`).
|
|
10
|
+
*
|
|
11
|
+
* @param path Issue path to resolve, or `undefined` for a form-level issue.
|
|
12
|
+
* @returns The joined field name, or `undefined` when `path` is missing or empty.
|
|
13
|
+
*/
|
|
14
|
+
function resolveFieldName(path) {
|
|
15
|
+
if (!path || path.length === 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
return path
|
|
18
|
+
.map((segment) => (typeof segment === "object" ? String(segment.key) : String(segment)))
|
|
19
|
+
.join(".");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Groups `issues` by the field name each one's `path` resolves to, dropping
|
|
23
|
+
* form-level issues that carry no path.
|
|
24
|
+
*
|
|
25
|
+
* @param issues Issues to group, typically {@link Form.Props.issues} as-is.
|
|
26
|
+
* @returns A map from field name to every issue addressed to it, in `issues` order.
|
|
27
|
+
*/
|
|
28
|
+
function groupIssuesByField(issues) {
|
|
29
|
+
let byField = new Map();
|
|
30
|
+
for (let issue of issues) {
|
|
31
|
+
let name = resolveFieldName(issue.path);
|
|
32
|
+
if (name === undefined)
|
|
33
|
+
continue;
|
|
34
|
+
let bucket = byField.get(name);
|
|
35
|
+
if (bucket)
|
|
36
|
+
bucket.push(issue);
|
|
37
|
+
else
|
|
38
|
+
byField.set(name, [issue]);
|
|
39
|
+
}
|
|
40
|
+
return byField;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Renders a native `<form>` laying children out in a single column, and
|
|
44
|
+
* provides {@link Form.Context} so descendant fields resolve their own
|
|
45
|
+
* issues by name and focus the first invalid field with no client JS.
|
|
46
|
+
*
|
|
47
|
+
* @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.
|
|
48
|
+
* @returns The render function producing the form's markup.
|
|
49
|
+
* @example
|
|
50
|
+
* let result = parseSafe(ContactSchema, formData);
|
|
51
|
+
* <Form method="post" issues={result.success ? undefined : result.issues}>
|
|
52
|
+
* <TextField name="email" label={t("contact.email")} />
|
|
53
|
+
* <Button type="submit">{t("contact.submit")}</Button>
|
|
54
|
+
* </Form>
|
|
55
|
+
*/
|
|
56
|
+
export function Form(handle) {
|
|
57
|
+
return () => {
|
|
58
|
+
let { issues = DEFAULT_ISSUES, mix, ...rest } = handle.props;
|
|
59
|
+
let byField = groupIssuesByField(issues);
|
|
60
|
+
let firstInvalidField = issues
|
|
61
|
+
.map((issue) => resolveFieldName(issue.path))
|
|
62
|
+
.find((name) => name !== undefined);
|
|
63
|
+
handle.context.set({
|
|
64
|
+
getIssues(name) {
|
|
65
|
+
return byField.get(name) ?? NO_ISSUES;
|
|
66
|
+
},
|
|
67
|
+
isFirstInvalid(name) {
|
|
68
|
+
return name === firstInvalidField;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return _jsx("form", { ...rest, mix: [flex(), flexCol(), gap(4), mix] });
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads the {@link Form.Context} provided by the nearest ancestor
|
|
76
|
+
* {@link Form}, resolving to `undefined` when no Form wraps the caller so
|
|
77
|
+
* every field renders safely inside or outside a Form.
|
|
78
|
+
*
|
|
79
|
+
* @param handle Runtime handle of the field performing the lookup.
|
|
80
|
+
* @returns The enclosing form's context, or `undefined` where no Form wraps the caller.
|
|
81
|
+
*/
|
|
82
|
+
export function readFormContext(handle) {
|
|
83
|
+
try {
|
|
84
|
+
return handle.context.get(Form);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the validation state a field renders: an explicit `errorMessage`
|
|
92
|
+
* always wins over a matching {@link Form} issue for `name`, which is how
|
|
93
|
+
* `Form`'s `issues` reach a field with no per-field prop threaded by hand.
|
|
94
|
+
*
|
|
95
|
+
* @param handle Runtime handle of the field resolving its state.
|
|
96
|
+
* @param name The field's `name` attribute, used to look its issues up.
|
|
97
|
+
* @param errorMessage An `errorMessage` passed directly to the field, if any.
|
|
98
|
+
* @returns The message to render and whether this field carries `autofocus`.
|
|
99
|
+
* @example
|
|
100
|
+
* let { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, "email", handle.props.errorMessage);
|
|
101
|
+
*/
|
|
102
|
+
export function resolveFieldIssue(handle, name, errorMessage) {
|
|
103
|
+
if (name === undefined)
|
|
104
|
+
return { errorMessage, isFirstInvalid: false };
|
|
105
|
+
let context = readFormContext(handle);
|
|
106
|
+
if (!context)
|
|
107
|
+
return { errorMessage, isFirstInvalid: false };
|
|
108
|
+
let resolved = errorMessage ?? context.getIssues(name)[0]?.message;
|
|
109
|
+
return {
|
|
110
|
+
errorMessage: resolved,
|
|
111
|
+
isFirstInvalid: Boolean(resolved) && context.isFirstInvalid(name),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An interactive row list built from plain, already-ordered markup: each
|
|
3
|
+
* {@link GridList.Item} carries a stable key a paired selection,
|
|
4
|
+
* keyboard-navigation, or reorder behavior can read, while the list itself
|
|
5
|
+
* renders as a fully static document by default. {@link GridList.Section}
|
|
6
|
+
* groups related rows under an optional {@link GridList.Header} label,
|
|
7
|
+
* {@link GridList.LoadMoreItem} holds a trailing loading placeholder, and
|
|
8
|
+
* {@link GridList.DragHandle} marks the one element inside a row a
|
|
9
|
+
* pointer-driven reorder behavior may grab.
|
|
10
|
+
*
|
|
11
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
12
|
+
* @copyright Sergio Xalambrí 2026
|
|
13
|
+
*/
|
|
14
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/ui";
|
|
15
|
+
import { SentinelRow } from "./sentinel-row.js";
|
|
16
|
+
/**
|
|
17
|
+
* Prop types for {@link GridList} and its compound parts.
|
|
18
|
+
*/
|
|
19
|
+
export declare namespace GridList {
|
|
20
|
+
/**
|
|
21
|
+
* Arrangement of {@link GridList.Item} rows: `"stack"` renders them as a
|
|
22
|
+
* single column, `"grid"` wraps them into a multi-column layout growing
|
|
23
|
+
* from two columns up to four as the list's own container widens.
|
|
24
|
+
*/
|
|
25
|
+
type Layout = "stack" | "grid";
|
|
26
|
+
/**
|
|
27
|
+
* Per-part styling for the elements {@link GridList} renders besides its
|
|
28
|
+
* own host.
|
|
29
|
+
*/
|
|
30
|
+
interface PartsProps {
|
|
31
|
+
/**
|
|
32
|
+
* Styling for the inner wrapper that switches between the `"stack"`
|
|
33
|
+
* and `"grid"` layouts and virtualizes a long list through
|
|
34
|
+
* `content-visibility: auto`.
|
|
35
|
+
*/
|
|
36
|
+
list?: TagProps<"div">["mix"];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Props accepted by {@link GridList}.
|
|
40
|
+
*/
|
|
41
|
+
interface Props extends TagProps<"div"> {
|
|
42
|
+
/** Row arrangement. Defaults to {@link DEFAULT_LAYOUT}. */
|
|
43
|
+
layout?: Layout;
|
|
44
|
+
/** {@link GridList.Item}, {@link GridList.Section}, and {@link GridList.LoadMoreItem} rows to render. */
|
|
45
|
+
children: RemixNode;
|
|
46
|
+
/** Per-part styling for the list's internal row-list wrapper. */
|
|
47
|
+
parts?: PartsProps;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Props accepted by {@link GridList.Item}.
|
|
51
|
+
*/
|
|
52
|
+
interface ItemProps extends TagProps<"div"> {
|
|
53
|
+
/**
|
|
54
|
+
* Stable identifier for this row, mirrored onto both the rendered
|
|
55
|
+
* element's own `id` and a `data-rmx-key` attribute, so the row is already
|
|
56
|
+
* correlation-ready for a paired behavior once one is attached.
|
|
57
|
+
*/
|
|
58
|
+
id: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Props accepted by {@link GridList.Section}.
|
|
62
|
+
*/
|
|
63
|
+
interface SectionProps extends TagProps<"div"> {
|
|
64
|
+
/** The section's optional {@link GridList.Header} label, followed by its {@link GridList.Item} rows. */
|
|
65
|
+
children: RemixNode;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Props accepted by {@link GridList.Header}.
|
|
69
|
+
*/
|
|
70
|
+
interface HeaderProps extends TagProps<"header"> {
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Props accepted by {@link GridList.LoadMoreItem}.
|
|
74
|
+
*/
|
|
75
|
+
interface LoadMoreItemProps extends TagProps<"div"> {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Props accepted by {@link GridList.DragHandle}: every native `<button>`
|
|
79
|
+
* attribute except `type`, fixed to `"button"` so it never submits an
|
|
80
|
+
* enclosing form, and `children`, fixed to the handle's own grip glyph.
|
|
81
|
+
*/
|
|
82
|
+
interface DragHandleProps extends Omit<TagProps<"button">, "type" | "children"> {
|
|
83
|
+
/** Accessible name for the icon-only control, e.g. "Reorder" or "Drag to reorder". */
|
|
84
|
+
"aria-label": string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Renders the list's root host as a bordered `<div>` with `role="grid"`,
|
|
89
|
+
* keeping its row-list layer in an inner wrapper since a `@container` query
|
|
90
|
+
* can't resolve against the host that declares it; reach `parts.list` to adjust it.
|
|
91
|
+
*
|
|
92
|
+
* @param handle Runtime handle carrying the host `<div>`'s props.
|
|
93
|
+
* @returns The render function producing the list's markup.
|
|
94
|
+
* @example
|
|
95
|
+
* <GridList aria-label={t("playlist.title")}>
|
|
96
|
+
* <GridList.Item id="track-1">{t("playlist.track", { title: "Intro" })}</GridList.Item>
|
|
97
|
+
* <GridList.Item id="track-2">{t("playlist.track", { title: "Chorus" })}</GridList.Item>
|
|
98
|
+
* </GridList>
|
|
99
|
+
* @example
|
|
100
|
+
* <GridList aria-label={t("gallery.title")} layout="grid">
|
|
101
|
+
* <GridList.Item id="photo-1">{t("gallery.photo", { name: "Sunset" })}</GridList.Item>
|
|
102
|
+
* <GridList.Item id="photo-2">{t("gallery.photo", { name: "Harbor" })}</GridList.Item>
|
|
103
|
+
* </GridList>
|
|
104
|
+
*/
|
|
105
|
+
export declare function GridList(handle: Handle<GridList.Props>): () => import("remix/ui").RemixElement;
|
|
106
|
+
export declare namespace GridList {
|
|
107
|
+
var Item: (handle: Handle<GridList.ItemProps>) => () => import("remix/ui").RemixElement;
|
|
108
|
+
var Section: (handle: Handle<GridList.SectionProps>) => () => import("remix/ui").RemixElement;
|
|
109
|
+
var Header: (handle: Handle<GridList.HeaderProps>) => () => import("remix/ui").RemixElement;
|
|
110
|
+
var LoadMoreItem: typeof SentinelRow;
|
|
111
|
+
var DragHandle: (handle: Handle<GridList.DragHandleProps>) => () => import("remix/ui").RemixElement;
|
|
112
|
+
}
|