@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,563 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/ui/jsx-runtime";
|
|
2
|
+
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
3
|
+
import { bg, fg, fill, fillOpacity, outline, stroke, strokeLinecap, strokeLinejoin, strokeWidth, vectorEffect, } from "@sdxc/u/color";
|
|
4
|
+
import { opacity, rounded, shadow, transition, transitionDuration } from "@sdxc/u/effects";
|
|
5
|
+
import { cursor, pointerEvents, raw, userSelect } from "@sdxc/u/general";
|
|
6
|
+
import { absolute, block, flex, flexWrap, gap, inlineBlock, inlineFlex, items, relative, shrink, } from "@sdxc/u/layout";
|
|
7
|
+
import { media } from "@sdxc/u/responsive";
|
|
8
|
+
import { bs, is, pb, pi } from "@sdxc/u/size";
|
|
9
|
+
import { z } from "@sdxc/u/stacking";
|
|
10
|
+
import { focusVisible, hover, when } from "@sdxc/u/state";
|
|
11
|
+
import { scaleProperty, translateProperty } from "@sdxc/u/transform";
|
|
12
|
+
import { fontSize, leading, nowrap, textDecoration, weight } from "@sdxc/u/typography";
|
|
13
|
+
import { attrs } from "remix/ui";
|
|
14
|
+
import { durations, easings } from "../animations/tokens.js";
|
|
15
|
+
import { CHART_COLOR_SLOT_COUNT, chartPalette } from "../styles/chart-palette.js";
|
|
16
|
+
import { legendToggle } from "../styles/legend-toggle.js";
|
|
17
|
+
import { computeMarkerIndices } from "../utils/chart-marker-indices.js";
|
|
18
|
+
import { arcPath, areaPath, linePath } from "../utils/chart-path.js";
|
|
19
|
+
import { bandScale, linearScale, pieAngles, ticks } from "../utils/chart-scale.js";
|
|
20
|
+
import { warnIfNoAccessibleLabel } from "../utils/warn-if-no-accessible-name.js";
|
|
21
|
+
/** Categorical color {@link Chart.Line} falls back to when `color` is omitted. */
|
|
22
|
+
const DEFAULT_LINE_COLOR = 1;
|
|
23
|
+
/** Categorical color {@link Chart.Area} falls back to when `color` is omitted. */
|
|
24
|
+
const DEFAULT_AREA_COLOR = 1;
|
|
25
|
+
/**
|
|
26
|
+
* `yDomain` value {@link Chart.Area} falls back to closing a series' filled
|
|
27
|
+
* region down (or up) to when `baseline` is omitted.
|
|
28
|
+
*/
|
|
29
|
+
const DEFAULT_AREA_BASELINE = 0;
|
|
30
|
+
/**
|
|
31
|
+
* Approximate marker count {@link Chart.Line} and {@link Chart.Area} fall
|
|
32
|
+
* back to for `markerCount`, giving keyboard and screen-reader users a
|
|
33
|
+
* representative spread of stops instead of one per raw sample.
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_MARKER_COUNT = 6;
|
|
36
|
+
/**
|
|
37
|
+
* `aria-hidden="true"` applied to {@link Chart.Line}'s and {@link Chart.Area}'s
|
|
38
|
+
* plotted `<path>` through {@link attrs} — a series' accessible name and
|
|
39
|
+
* hover tooltip live on its point markers instead.
|
|
40
|
+
*/
|
|
41
|
+
const DEFAULT_PATH_ARIA_HIDDEN = "true";
|
|
42
|
+
/**
|
|
43
|
+
* Pixel distance from center to every wedge's inner edge {@link Chart.Pie}
|
|
44
|
+
* falls back to when `innerRadius` is omitted — a solid pie reaching the
|
|
45
|
+
* center, with no donut hole.
|
|
46
|
+
*/
|
|
47
|
+
const DEFAULT_PIE_INNER_RADIUS = 0;
|
|
48
|
+
/**
|
|
49
|
+
* {@link Chart.Color} {@link Chart.Tooltip.Swatch} falls back to when
|
|
50
|
+
* `color` is omitted, matching {@link DEFAULT_LINE_COLOR}'s own default.
|
|
51
|
+
*/
|
|
52
|
+
const DEFAULT_SWATCH_COLOR = 1;
|
|
53
|
+
/**
|
|
54
|
+
* `aria-hidden` value applied to {@link Chart.Tooltip} through
|
|
55
|
+
* {@link attrs} unless overridden — the surface only restates the label,
|
|
56
|
+
* value, and color a hovered point's native `<title>` already carries.
|
|
57
|
+
*/
|
|
58
|
+
const DEFAULT_TOOLTIP_ARIA_HIDDEN = "true";
|
|
59
|
+
/** Approximate gridline count {@link Chart.Bar} falls back to when `tickCount` is omitted. */
|
|
60
|
+
const DEFAULT_BAR_TICK_COUNT = 5;
|
|
61
|
+
/** Fraction of each category band reserved as a gap from its neighbors, {@link Chart.Bar} falls back to when `categoryGap` is omitted. */
|
|
62
|
+
const DEFAULT_CATEGORY_GAP = 0.2;
|
|
63
|
+
/**
|
|
64
|
+
* Fraction of a category's own band reserved as a gap between its series'
|
|
65
|
+
* bars, {@link Chart.Bar} falls back to when `seriesGap` is omitted —
|
|
66
|
+
* packing bars edge to edge, since most rows plot a single series.
|
|
67
|
+
*/
|
|
68
|
+
const DEFAULT_SERIES_GAP = 0;
|
|
69
|
+
/**
|
|
70
|
+
* `role="group"` applied to {@link Chart.Legend}'s host through
|
|
71
|
+
* {@link attrs} unless a consumer supplies its own `role`, announcing the
|
|
72
|
+
* series switcher as a related set of controls to assistive technology.
|
|
73
|
+
*/
|
|
74
|
+
const DEFAULT_LEGEND_ROLE = "group";
|
|
75
|
+
/**
|
|
76
|
+
* `defaultChecked` {@link Chart.LegendItemProps} falls back to when
|
|
77
|
+
* omitted, so a series renders visible until a reader explicitly hides it.
|
|
78
|
+
*/
|
|
79
|
+
const DEFAULT_LEGEND_ITEM_CHECKED = true;
|
|
80
|
+
/**
|
|
81
|
+
* Renders the series switcher's host: a `role="group"` `<div>` laying its
|
|
82
|
+
* {@link Chart.Legend.Item} children in a wrapping row. Must render as a
|
|
83
|
+
* later sibling of the chart root, with items in that chart's series order.
|
|
84
|
+
*
|
|
85
|
+
* @param handle Runtime handle carrying the host `<div>`'s props.
|
|
86
|
+
* @returns The render function producing the legend's markup.
|
|
87
|
+
* @example
|
|
88
|
+
* <Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t("chart.revenue.label")}>
|
|
89
|
+
* <Chart.Line points={points} color={1} />
|
|
90
|
+
* </Chart>
|
|
91
|
+
* <Chart.Legend aria-label={t("chart.legend")}>
|
|
92
|
+
* <Chart.Legend.Item color={1}>{t("chart.series.revenue")}</Chart.Legend.Item>
|
|
93
|
+
* </Chart.Legend>
|
|
94
|
+
*/
|
|
95
|
+
function ChartLegend(handle) {
|
|
96
|
+
return () => {
|
|
97
|
+
let { mix, ...rest } = handle.props;
|
|
98
|
+
warnIfNoAccessibleLabel(handle.props, 'Chart.Legend: needs an "aria-label" or "aria-labelledby" identifying this legend for assistive technology.');
|
|
99
|
+
return (_jsx("div", { "data-slot": "legend", ...rest, mix: [
|
|
100
|
+
attrs({ role: DEFAULT_LEGEND_ROLE }),
|
|
101
|
+
flex(),
|
|
102
|
+
flexWrap(),
|
|
103
|
+
items("center"),
|
|
104
|
+
gap(4),
|
|
105
|
+
mix,
|
|
106
|
+
] }));
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Renders one series' entry: a native `<label>` wrapping a visually hidden,
|
|
111
|
+
* `defaultChecked` checkbox, a `data-color` swatch matching its series, and
|
|
112
|
+
* its name — unchecking hides the series via the paired chart root's `css()`.
|
|
113
|
+
*
|
|
114
|
+
* @param handle Runtime handle carrying the host `<label>`'s props, plus
|
|
115
|
+
* the underlying `<input>`'s own attributes and per-part `swatch` styling.
|
|
116
|
+
* @returns The render function producing the item's markup.
|
|
117
|
+
* @example
|
|
118
|
+
* <Chart.Legend.Item color={1}>{t("chart.series.revenue")}</Chart.Legend.Item>
|
|
119
|
+
* @example
|
|
120
|
+
* <Chart.Legend.Item color={3} defaultChecked={false}>
|
|
121
|
+
* {t("chart.series.archived")}
|
|
122
|
+
* </Chart.Legend.Item>
|
|
123
|
+
*/
|
|
124
|
+
function ChartLegendItem(handle) {
|
|
125
|
+
return () => {
|
|
126
|
+
let { color, defaultChecked, children, parts, mix, ...rest } = handle.props;
|
|
127
|
+
let resolvedChecked = defaultChecked ?? DEFAULT_LEGEND_ITEM_CHECKED;
|
|
128
|
+
return (_jsxs("label", { "data-slot": "legend-item", mix: [
|
|
129
|
+
relative(),
|
|
130
|
+
inlineFlex(),
|
|
131
|
+
items("center"),
|
|
132
|
+
fg("neutral"),
|
|
133
|
+
when("&:has(input:focus-visible)", outline({ color: "brand.ring", offset: 2 })),
|
|
134
|
+
gap(2),
|
|
135
|
+
cursor("default"),
|
|
136
|
+
transition("opacity, color"),
|
|
137
|
+
userSelect(),
|
|
138
|
+
fontSize("sm"),
|
|
139
|
+
leading(1.25),
|
|
140
|
+
when("&:has(input:not(:checked))", [opacity(50), textDecoration("line-through")]),
|
|
141
|
+
], children: [_jsx("span", { "aria-hidden": "true", "data-slot": "swatch", "data-color": String(color), mix: [
|
|
142
|
+
chartPalette("color"),
|
|
143
|
+
inlineBlock(),
|
|
144
|
+
is(2.5),
|
|
145
|
+
bs(2.5),
|
|
146
|
+
rounded("full"),
|
|
147
|
+
shrink(),
|
|
148
|
+
bg("currentColor"),
|
|
149
|
+
parts?.swatch,
|
|
150
|
+
] }), _jsx("input", { type: "checkbox", defaultChecked: resolvedChecked, ...rest, mix: [visuallyHidden(), mix] }), children] }));
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
ChartLegend.Item = ChartLegendItem;
|
|
154
|
+
/**
|
|
155
|
+
* Renders a chart's coordinate space: a responsive `<svg>` whose `viewBox`
|
|
156
|
+
* comes from `width`/`height`, shared via context so nested series share one
|
|
157
|
+
* scale. A paired {@link Chart.Legend} must render as this root's later sibling.
|
|
158
|
+
*
|
|
159
|
+
* @param handle Runtime handle carrying the host `<svg>`'s props and providing {@link Chart.Context}.
|
|
160
|
+
* @returns The render function producing the chart's coordinate space.
|
|
161
|
+
* @example
|
|
162
|
+
* <Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t("chart.revenue.label")}>
|
|
163
|
+
* <Chart.Line
|
|
164
|
+
* points={months.map((month) => ({
|
|
165
|
+
* x: month.index,
|
|
166
|
+
* y: month.revenue,
|
|
167
|
+
* label: t("chart.revenue.point", { month: month.name, amount: month.revenue }),
|
|
168
|
+
* }))}
|
|
169
|
+
* />
|
|
170
|
+
* </Chart>
|
|
171
|
+
* <Chart.Legend aria-label={t("chart.legend")}>
|
|
172
|
+
* <Chart.Legend.Item color={1}>{t("chart.series.revenue")}</Chart.Legend.Item>
|
|
173
|
+
* </Chart.Legend>
|
|
174
|
+
*/
|
|
175
|
+
export function Chart(handle) {
|
|
176
|
+
return () => {
|
|
177
|
+
let { width, height, xDomain, yDomain, mix, ...rest } = handle.props;
|
|
178
|
+
handle.context.set({ width, height, xDomain, yDomain });
|
|
179
|
+
return (_jsx("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "xMidYMid meet", ...rest, mix: [legendToggle(), block(), is("full"), bs("auto"), mix] }));
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
Chart.Legend = ChartLegend;
|
|
183
|
+
/**
|
|
184
|
+
* Renders one series' representative point markers: a small focusable
|
|
185
|
+
* `<circle>` at each of `markerIndices`' scaled positions, nested with a
|
|
186
|
+
* `<title>` carrying that point's own `label`.
|
|
187
|
+
*
|
|
188
|
+
* @param points The series' original data points, read for each marker's label.
|
|
189
|
+
* @param scaledPoints Each point's already-scaled pixel position, in the same order as `points`.
|
|
190
|
+
* @param markerIndices Which of `points`' indices to render a marker for.
|
|
191
|
+
* @param markerMix Additional mixin(s) layered after each marker's own built-in styling.
|
|
192
|
+
* @returns The rendered `<circle>` markers.
|
|
193
|
+
*/
|
|
194
|
+
function renderChartMarkers(points, scaledPoints, markerIndices, markerMix) {
|
|
195
|
+
return markerIndices.map((index) => {
|
|
196
|
+
let point = points[index];
|
|
197
|
+
let position = scaledPoints[index];
|
|
198
|
+
if (point === undefined || position === undefined)
|
|
199
|
+
return null;
|
|
200
|
+
return (_jsx("circle", { cx: position.x, cy: position.y, tabIndex: 0, role: "img", mix: [
|
|
201
|
+
focusVisible(outline({ color: "brand.ring", offset: 2 })),
|
|
202
|
+
cursor("default"),
|
|
203
|
+
fill("currentColor"),
|
|
204
|
+
raw({ r: "var(--ui-chart-point-radius, 0.1875rem)" }),
|
|
205
|
+
markerMix,
|
|
206
|
+
], children: _jsx("title", { children: point.label }) }, index));
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Renders a line series: a stroked, `aria-hidden` `<path>` connecting
|
|
211
|
+
* `points` via {@link linearScale} and {@link linePath}, plus a focusable
|
|
212
|
+
* marker with a `<title>`, sampled via {@link ticks} for manageable density.
|
|
213
|
+
*
|
|
214
|
+
* @param handle Runtime handle carrying the host `<g>`'s props.
|
|
215
|
+
* @returns The render function producing the series' markup.
|
|
216
|
+
* @example
|
|
217
|
+
* <Chart.Line
|
|
218
|
+
* color={2}
|
|
219
|
+
* points={[
|
|
220
|
+
* { x: 0, y: 12, label: t("chart.point", { x: 0, y: 12 }) },
|
|
221
|
+
* { x: 1, y: 18, label: t("chart.point", { x: 1, y: 18 }) },
|
|
222
|
+
* { x: 2, y: 9, label: t("chart.point", { x: 2, y: 9 }) },
|
|
223
|
+
* ]}
|
|
224
|
+
* />
|
|
225
|
+
* @example
|
|
226
|
+
* <Chart.Line points={points} markerCount={3} parts={{ path: css({ strokeDasharray: "4 4" }) }} />
|
|
227
|
+
*/
|
|
228
|
+
Chart.Line = function ChartLine(handle) {
|
|
229
|
+
return () => {
|
|
230
|
+
let { points, color, markerCount, parts, mix, ...rest } = handle.props;
|
|
231
|
+
let context = handle.context.get(Chart);
|
|
232
|
+
let resolvedColor = color ?? DEFAULT_LINE_COLOR;
|
|
233
|
+
let resolvedMarkerCount = markerCount ?? DEFAULT_MARKER_COUNT;
|
|
234
|
+
let x = linearScale(context.xDomain, [0, context.width]);
|
|
235
|
+
let y = linearScale(context.yDomain, [context.height, 0]);
|
|
236
|
+
let scaledPoints = points.map((point) => ({ x: x(point.x), y: y(point.y) }));
|
|
237
|
+
let d = linePath(scaledPoints);
|
|
238
|
+
let markerIndices = computeMarkerIndices(points, context.xDomain, resolvedMarkerCount);
|
|
239
|
+
return (_jsxs("g", { "data-color": String(resolvedColor), ...rest, mix: [chartPalette("color"), mix], children: [_jsx("path", { d: d, mix: [
|
|
240
|
+
attrs({ "aria-hidden": DEFAULT_PATH_ARIA_HIDDEN }),
|
|
241
|
+
fill("none"),
|
|
242
|
+
stroke("currentColor"),
|
|
243
|
+
strokeWidth("var(--ui-chart-line-width, 2px)"),
|
|
244
|
+
strokeLinejoin("round"),
|
|
245
|
+
strokeLinecap("round"),
|
|
246
|
+
parts?.path,
|
|
247
|
+
] }), renderChartMarkers(points, scaledPoints, markerIndices, parts?.marker)] }));
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Renders the tooltip's floating host: an absolutely positioned `<div>`
|
|
252
|
+
* reading position and `data-open` state a `chartTooltip()` mixin writes
|
|
253
|
+
* onto it. Visibility requires pairing that mixin with the chart root.
|
|
254
|
+
*
|
|
255
|
+
* @param handle Runtime handle carrying the host `<div>`'s props.
|
|
256
|
+
* @returns The render function producing the surface's markup.
|
|
257
|
+
* @example
|
|
258
|
+
* <div style={{ position: "relative" }} mix={chartTooltip()}>
|
|
259
|
+
* <Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t("chart.revenue.label")}>
|
|
260
|
+
* <Chart.Line points={points} />
|
|
261
|
+
* </Chart>
|
|
262
|
+
* <Chart.Tooltip>
|
|
263
|
+
* <Chart.Tooltip.Swatch color={2} />
|
|
264
|
+
* <Chart.Tooltip.Label>{t("chart.months.march")}</Chart.Tooltip.Label>
|
|
265
|
+
* <Chart.Tooltip.Value>42</Chart.Tooltip.Value>
|
|
266
|
+
* </Chart.Tooltip>
|
|
267
|
+
* </div>
|
|
268
|
+
*/
|
|
269
|
+
function ChartTooltip(handle) {
|
|
270
|
+
return () => {
|
|
271
|
+
let { mix, ...rest } = handle.props;
|
|
272
|
+
return (_jsx("div", { "data-slot": "tooltip", ...rest, mix: [
|
|
273
|
+
attrs({ "aria-hidden": DEFAULT_TOOLTIP_ARIA_HIDDEN }),
|
|
274
|
+
absolute(),
|
|
275
|
+
flex(),
|
|
276
|
+
items("center"),
|
|
277
|
+
rounded("md"),
|
|
278
|
+
pi(2),
|
|
279
|
+
fg("neutral.onSolid"),
|
|
280
|
+
bg("neutral.solid"),
|
|
281
|
+
shadow("md"),
|
|
282
|
+
z(10),
|
|
283
|
+
gap(1.5),
|
|
284
|
+
pb(1.5),
|
|
285
|
+
nowrap(),
|
|
286
|
+
opacity(0),
|
|
287
|
+
transition("opacity, scale", { duration: durations.fast, easing: easings.standard }),
|
|
288
|
+
when("&[data-open]", [opacity(100), scaleProperty(1)]),
|
|
289
|
+
media("(prefers-reduced-motion: reduce)", [
|
|
290
|
+
scaleProperty("none"),
|
|
291
|
+
raw({ transitionProperty: "opacity" }),
|
|
292
|
+
]),
|
|
293
|
+
raw({
|
|
294
|
+
left: "var(--ui-chart-tooltip-x, 0px)",
|
|
295
|
+
top: "var(--ui-chart-tooltip-y, 0px)",
|
|
296
|
+
fontSize: "0.8125rem",
|
|
297
|
+
}),
|
|
298
|
+
translateProperty("-50% calc(-100% - var(--ui-chart-tooltip-gap, 0.5rem))"),
|
|
299
|
+
leading(1.2),
|
|
300
|
+
pointerEvents(),
|
|
301
|
+
scaleProperty(0.95),
|
|
302
|
+
mix,
|
|
303
|
+
] }));
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Renders a small circular color chip identifying the tooltip's current
|
|
308
|
+
* point or wedge: a native `<span>` colored through the `data-color`
|
|
309
|
+
* attribute, on the same eight-slot palette every series already renders with.
|
|
310
|
+
*
|
|
311
|
+
* @param handle Runtime handle carrying the host `<span>`'s props.
|
|
312
|
+
* @returns The render function producing the swatch's markup.
|
|
313
|
+
* @example
|
|
314
|
+
* <Chart.Tooltip.Swatch color={2} />
|
|
315
|
+
*/
|
|
316
|
+
ChartTooltip.Swatch = function ChartTooltipSwatch(handle) {
|
|
317
|
+
return () => {
|
|
318
|
+
let { color, mix, ...rest } = handle.props;
|
|
319
|
+
let resolvedColor = color ?? DEFAULT_SWATCH_COLOR;
|
|
320
|
+
return (_jsx("span", { ...rest, "data-slot": "swatch", "data-color": String(resolvedColor), mix: [
|
|
321
|
+
chartPalette("backgroundColor"),
|
|
322
|
+
inlineBlock(),
|
|
323
|
+
is(2),
|
|
324
|
+
bs(2),
|
|
325
|
+
rounded("full"),
|
|
326
|
+
shrink(),
|
|
327
|
+
mix,
|
|
328
|
+
] }));
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Renders the tooltip's label slot: a native `<span>` showing the hovered
|
|
333
|
+
* point or wedge's own label — the same string rendered into its native
|
|
334
|
+
* `<title>` — muted to read as secondary against {@link Chart.Tooltip.Value}.
|
|
335
|
+
*
|
|
336
|
+
* @param handle Runtime handle carrying the host `<span>`'s props.
|
|
337
|
+
* @returns The render function producing the label's markup.
|
|
338
|
+
* @example
|
|
339
|
+
* <Chart.Tooltip.Label>{t("chart.months.march")}</Chart.Tooltip.Label>
|
|
340
|
+
*/
|
|
341
|
+
ChartTooltip.Label = function ChartTooltipLabel(handle) {
|
|
342
|
+
return () => {
|
|
343
|
+
let { mix, ...rest } = handle.props;
|
|
344
|
+
return _jsx("span", { ...rest, "data-slot": "label", mix: [opacity(75), mix] });
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Renders the tooltip's value slot: a native `<span>` showing the hovered
|
|
349
|
+
* point or wedge's own value, weighted to read as the surface's most
|
|
350
|
+
* prominent figure against {@link Chart.Tooltip.Label}.
|
|
351
|
+
*
|
|
352
|
+
* @param handle Runtime handle carrying the host `<span>`'s props.
|
|
353
|
+
* @returns The render function producing the value's markup.
|
|
354
|
+
* @example
|
|
355
|
+
* <Chart.Tooltip.Value>42</Chart.Tooltip.Value>
|
|
356
|
+
*/
|
|
357
|
+
ChartTooltip.Value = function ChartTooltipValue(handle) {
|
|
358
|
+
return () => {
|
|
359
|
+
let { mix, ...rest } = handle.props;
|
|
360
|
+
return _jsx("span", { ...rest, "data-slot": "value", mix: [weight("semibold"), mix] });
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
// @ts-ignore
|
|
364
|
+
Chart.Tooltip = ChartTooltip;
|
|
365
|
+
/**
|
|
366
|
+
* Renders an area series: a filled, `aria-hidden` `<path>` tracing `points`
|
|
367
|
+
* and closing down to `baseline`, mapped through {@link linearScale} and
|
|
368
|
+
* {@link areaPath}, plus a focusable marker sampled via {@link ticks}.
|
|
369
|
+
*
|
|
370
|
+
* @param handle Runtime handle carrying the host `<g>`'s props.
|
|
371
|
+
* @returns The render function producing the series' markup.
|
|
372
|
+
* @example
|
|
373
|
+
* <Chart.Area
|
|
374
|
+
* color={3}
|
|
375
|
+
* points={[
|
|
376
|
+
* { x: 0, y: 12, label: t("chart.point", { x: 0, y: 12 }) },
|
|
377
|
+
* { x: 1, y: 18, label: t("chart.point", { x: 1, y: 18 }) },
|
|
378
|
+
* { x: 2, y: 9, label: t("chart.point", { x: 2, y: 9 }) },
|
|
379
|
+
* ]}
|
|
380
|
+
* />
|
|
381
|
+
* @example
|
|
382
|
+
* <Chart.Area
|
|
383
|
+
* points={points}
|
|
384
|
+
* baseline={20}
|
|
385
|
+
* markerCount={3}
|
|
386
|
+
* parts={{ path: css({ fillOpacity: 0.4 }) }}
|
|
387
|
+
* />
|
|
388
|
+
*/
|
|
389
|
+
Chart.Area = function ChartArea(handle) {
|
|
390
|
+
return () => {
|
|
391
|
+
let { points, color, baseline, markerCount, parts, mix, ...rest } = handle.props;
|
|
392
|
+
let context = handle.context.get(Chart);
|
|
393
|
+
let resolvedColor = color ?? DEFAULT_AREA_COLOR;
|
|
394
|
+
let resolvedBaseline = baseline ?? DEFAULT_AREA_BASELINE;
|
|
395
|
+
let resolvedMarkerCount = markerCount ?? DEFAULT_MARKER_COUNT;
|
|
396
|
+
let x = linearScale(context.xDomain, [0, context.width]);
|
|
397
|
+
let y = linearScale(context.yDomain, [context.height, 0]);
|
|
398
|
+
let scaledPoints = points.map((point) => ({ x: x(point.x), y: y(point.y) }));
|
|
399
|
+
let d = areaPath(scaledPoints, y(resolvedBaseline));
|
|
400
|
+
let markerIndices = computeMarkerIndices(points, context.xDomain, resolvedMarkerCount);
|
|
401
|
+
return (_jsxs("g", { "data-color": String(resolvedColor), ...rest, mix: [chartPalette("color"), mix], children: [_jsx("path", { d: d, mix: [
|
|
402
|
+
attrs({ "aria-hidden": DEFAULT_PATH_ARIA_HIDDEN }),
|
|
403
|
+
fill("currentColor"),
|
|
404
|
+
fillOpacity("var(--ui-chart-area-fill-opacity, 0.25)"),
|
|
405
|
+
stroke("currentColor"),
|
|
406
|
+
strokeWidth("var(--ui-chart-area-width, 2px)"),
|
|
407
|
+
strokeLinejoin("round"),
|
|
408
|
+
strokeLinecap("round"),
|
|
409
|
+
parts?.path,
|
|
410
|
+
] }), renderChartMarkers(points, scaledPoints, markerIndices, parts?.marker)] }));
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Renders a pie or donut chart: an independent `<svg>` root, since a
|
|
415
|
+
* circular layout shares no domain with a Cartesian {@link Chart}. A paired
|
|
416
|
+
* {@link Chart.Legend} must render as this root's later sibling.
|
|
417
|
+
*
|
|
418
|
+
* @param handle Runtime handle carrying the host `<svg>`'s props.
|
|
419
|
+
* @returns The render function producing the chart's markup.
|
|
420
|
+
* @example
|
|
421
|
+
* <Chart.Pie
|
|
422
|
+
* width={200}
|
|
423
|
+
* height={200}
|
|
424
|
+
* aria-label={t("chart.revenueByRegion")}
|
|
425
|
+
* data={[
|
|
426
|
+
* { value: 45, label: t("region.americas", { percent: 45 }) },
|
|
427
|
+
* { value: 30, label: t("region.emea", { percent: 30 }) },
|
|
428
|
+
* { value: 25, label: t("region.apac", { percent: 25 }) },
|
|
429
|
+
* ]}
|
|
430
|
+
* />
|
|
431
|
+
* @example
|
|
432
|
+
* <Chart.Pie
|
|
433
|
+
* width={200}
|
|
434
|
+
* height={200}
|
|
435
|
+
* innerRadius={60}
|
|
436
|
+
* aria-label={t("chart.storageByType")}
|
|
437
|
+
* data={rows.map((row) => ({ value: row.bytes, label: row.name }))}
|
|
438
|
+
* />
|
|
439
|
+
*/
|
|
440
|
+
Chart.Pie = function ChartPie(handle) {
|
|
441
|
+
return () => {
|
|
442
|
+
let { data, width, height, innerRadius, startAngle, endAngle, padAngle, parts, mix, ...rest } = handle.props;
|
|
443
|
+
let resolvedInnerRadius = innerRadius ?? DEFAULT_PIE_INNER_RADIUS;
|
|
444
|
+
let cx = width / 2;
|
|
445
|
+
let cy = height / 2;
|
|
446
|
+
let outerRadius = Math.min(width, height) / 2;
|
|
447
|
+
let slices = pieAngles(data.map((datum) => datum.value), { startAngle, endAngle, padAngle });
|
|
448
|
+
return (_jsx("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "xMidYMid meet", ...rest, mix: [chartPalette("fill", " "), legendToggle(), block(), is("full"), bs("auto"), mix], children: slices.map((slice, index) => {
|
|
449
|
+
let datum = data[index];
|
|
450
|
+
if (datum === undefined)
|
|
451
|
+
return null;
|
|
452
|
+
let d = arcPath({
|
|
453
|
+
cx,
|
|
454
|
+
cy,
|
|
455
|
+
innerRadius: resolvedInnerRadius,
|
|
456
|
+
outerRadius,
|
|
457
|
+
startAngle: slice.startAngle,
|
|
458
|
+
endAngle: slice.endAngle,
|
|
459
|
+
});
|
|
460
|
+
if (d === "")
|
|
461
|
+
return null;
|
|
462
|
+
let resolvedColor = datum.color ?? ((index % CHART_COLOR_SLOT_COUNT) + 1);
|
|
463
|
+
return (_jsx("path", { d: d, "data-color": String(resolvedColor), tabIndex: 0, role: "img", mix: [
|
|
464
|
+
focusVisible(outline({ color: "brand.ring", offset: 2 })),
|
|
465
|
+
cursor("default"),
|
|
466
|
+
parts?.segment,
|
|
467
|
+
], children: _jsx("title", { children: datum.label }) }, index));
|
|
468
|
+
}) }));
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Renders a categorical bar chart: an independent `<svg>` root, since a
|
|
473
|
+
* band axis shares no continuous domain with a Cartesian {@link Chart}. A
|
|
474
|
+
* paired {@link Chart.Legend} must render as this root's later sibling.
|
|
475
|
+
*
|
|
476
|
+
* @param handle Runtime handle carrying the host `<svg>`'s props.
|
|
477
|
+
* @returns The render function producing the chart's markup.
|
|
478
|
+
* @example
|
|
479
|
+
* <Chart.Bar
|
|
480
|
+
* width={480}
|
|
481
|
+
* height={240}
|
|
482
|
+
* domain={[0, 5000]}
|
|
483
|
+
* aria-label={t("chart.revenue.label")}
|
|
484
|
+
* data={[
|
|
485
|
+
* {
|
|
486
|
+
* category: "Jan",
|
|
487
|
+
* values: { revenue: { value: 4000, label: t("chart.revenuePoint", { month: "Jan", value: 4000 }) } },
|
|
488
|
+
* },
|
|
489
|
+
* {
|
|
490
|
+
* category: "Feb",
|
|
491
|
+
* values: { revenue: { value: 3000, label: t("chart.revenuePoint", { month: "Feb", value: 3000 }) } },
|
|
492
|
+
* },
|
|
493
|
+
* ]}
|
|
494
|
+
* series={["revenue"]}
|
|
495
|
+
* />
|
|
496
|
+
* @example
|
|
497
|
+
* <Chart.Bar
|
|
498
|
+
* width={480}
|
|
499
|
+
* height={240}
|
|
500
|
+
* domain={[0, 5000]}
|
|
501
|
+
* aria-label={t("chart.revenue.label")}
|
|
502
|
+
* data={quarters.map((quarter) => ({
|
|
503
|
+
* category: quarter.name,
|
|
504
|
+
* values: {
|
|
505
|
+
* revenue: {
|
|
506
|
+
* value: quarter.revenue,
|
|
507
|
+
* label: t("chart.revenuePoint", { quarter: quarter.name, value: quarter.revenue }),
|
|
508
|
+
* },
|
|
509
|
+
* refunds: {
|
|
510
|
+
* value: quarter.refunds,
|
|
511
|
+
* label: t("chart.refundsPoint", { quarter: quarter.name, value: quarter.refunds }),
|
|
512
|
+
* },
|
|
513
|
+
* },
|
|
514
|
+
* }))}
|
|
515
|
+
* series={["revenue", "refunds"]}
|
|
516
|
+
* seriesGap={0.15}
|
|
517
|
+
* />
|
|
518
|
+
*/
|
|
519
|
+
Chart.Bar = function ChartBar(handle) {
|
|
520
|
+
return () => {
|
|
521
|
+
let { data, series, width, height, domain, tickCount, categoryGap, seriesGap, parts, mix, ...rest } = handle.props;
|
|
522
|
+
let resolvedTickCount = tickCount ?? DEFAULT_BAR_TICK_COUNT;
|
|
523
|
+
let resolvedCategoryGap = categoryGap ?? DEFAULT_CATEGORY_GAP;
|
|
524
|
+
let resolvedSeriesGap = seriesGap ?? DEFAULT_SERIES_GAP;
|
|
525
|
+
let categories = data.map((row) => row.category);
|
|
526
|
+
let outer = bandScale(categories, [0, width], {
|
|
527
|
+
paddingInner: resolvedCategoryGap,
|
|
528
|
+
paddingOuter: resolvedCategoryGap / 2,
|
|
529
|
+
});
|
|
530
|
+
let inner = bandScale(series, [0, outer.bandwidth], { paddingInner: resolvedSeriesGap });
|
|
531
|
+
let y = linearScale(domain, [height, 0]);
|
|
532
|
+
let baselineY = y(0);
|
|
533
|
+
let gridlineValues = ticks(domain, resolvedTickCount);
|
|
534
|
+
return (_jsxs("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "xMidYMid meet", ...rest, mix: [chartPalette("fill", " "), legendToggle(), block(), is("full"), bs("auto"), mix], children: [_jsx("g", { mix: [attrs({ "aria-hidden": DEFAULT_PATH_ARIA_HIDDEN })], children: gridlineValues.map((value) => (_jsx("line", { x1: 0, x2: width, y1: y(value), y2: y(value), mix: [
|
|
535
|
+
stroke("var(--ui-neutral-border)"),
|
|
536
|
+
strokeWidth("1"),
|
|
537
|
+
vectorEffect("non-scaling-stroke"),
|
|
538
|
+
parts?.gridline,
|
|
539
|
+
] }, value))) }), data.map((row) => {
|
|
540
|
+
let categoryX = outer.position(row.category);
|
|
541
|
+
if (categoryX === undefined)
|
|
542
|
+
return null;
|
|
543
|
+
return series.map((key, index) => {
|
|
544
|
+
let entry = row.values[key];
|
|
545
|
+
if (entry === undefined)
|
|
546
|
+
return null;
|
|
547
|
+
let barX = categoryX + (inner.position(key) ?? 0);
|
|
548
|
+
let barValueY = y(entry.value);
|
|
549
|
+
let rectY = Math.min(baselineY, barValueY);
|
|
550
|
+
let rectHeight = Math.abs(barValueY - baselineY);
|
|
551
|
+
let resolvedColor = ((index % CHART_COLOR_SLOT_COUNT) + 1);
|
|
552
|
+
return (_jsx("rect", { x: barX, y: rectY, width: inner.bandwidth, height: rectHeight, "data-color": String(resolvedColor), "data-series-index": String(index), tabIndex: 0, role: "img", mix: [
|
|
553
|
+
hover(opacity(85)),
|
|
554
|
+
focusVisible(outline({ color: "brand.ring", offset: 2 })),
|
|
555
|
+
cursor("default"),
|
|
556
|
+
transition("opacity"),
|
|
557
|
+
media("(prefers-reduced-motion: reduce)", transitionDuration("0s")),
|
|
558
|
+
parts?.bar,
|
|
559
|
+
], children: _jsx("title", { children: entry.label }) }, `${row.category}:${key}`));
|
|
560
|
+
});
|
|
561
|
+
})] }));
|
|
562
|
+
};
|
|
563
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A landmark grouping independently toggled checkbox controls into one
|
|
3
|
+
* related set: a `role="group"` host laying children out in a column, or a
|
|
4
|
+
* row when `orientation` is `"horizontal"`. Each nested checkbox keeps its
|
|
5
|
+
* own checked state, `name`, and `value`; the host contributes the shared
|
|
6
|
+
* grouping, the layout, and an invalid-state color for composed text.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { Handle, Props as TagProps } from "remix/ui";
|
|
12
|
+
/**
|
|
13
|
+
* Prop types for {@link CheckboxGroup}.
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace CheckboxGroup {
|
|
16
|
+
/**
|
|
17
|
+
* Axis a group's checkboxes lay out along: a single column, or a single
|
|
18
|
+
* row.
|
|
19
|
+
*/
|
|
20
|
+
type Orientation = "horizontal" | "vertical";
|
|
21
|
+
/**
|
|
22
|
+
* Props accepted by {@link CheckboxGroup}. Native `<div>` attributes and
|
|
23
|
+
* `mix` pass through to the grouping host, so `aria-label`,
|
|
24
|
+
* `aria-labelledby`, `aria-describedby`, and `aria-invalid` behave natively.
|
|
25
|
+
*/
|
|
26
|
+
interface Props extends TagProps<"div"> {
|
|
27
|
+
/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */
|
|
28
|
+
orientation?: Orientation;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lays checkbox children out in a column, or a row when `orientation` is
|
|
33
|
+
* `"horizontal"`; each nested checkbox keeps its own checked state, `name`,
|
|
34
|
+
* and `value`. `aria-invalid="true"` recolors plain text composed alongside.
|
|
35
|
+
*
|
|
36
|
+
* @param handle Runtime handle carrying the host `<div>`'s props.
|
|
37
|
+
* @returns The render function producing the group's markup.
|
|
38
|
+
* @example
|
|
39
|
+
* <CheckboxGroup aria-labelledby="fruits-label">
|
|
40
|
+
* <Label id="fruits-label">{t("fruits.label")}</Label>
|
|
41
|
+
* <Checkbox name="fruits" value="apple">{t("fruits.apple")}</Checkbox>
|
|
42
|
+
* <Checkbox name="fruits" value="banana">{t("fruits.banana")}</Checkbox>
|
|
43
|
+
* <Checkbox name="fruits" value="orange">{t("fruits.orange")}</Checkbox>
|
|
44
|
+
* </CheckboxGroup>
|
|
45
|
+
* @example
|
|
46
|
+
* <CheckboxGroup aria-label={t("notifications.label")} orientation="horizontal">
|
|
47
|
+
* <Checkbox name="notify" value="email">{t("notifications.email")}</Checkbox>
|
|
48
|
+
* <Checkbox name="notify" value="sms">{t("notifications.sms")}</Checkbox>
|
|
49
|
+
* <Checkbox name="notify" value="push">{t("notifications.push")}</Checkbox>
|
|
50
|
+
* </CheckboxGroup>
|
|
51
|
+
* @example
|
|
52
|
+
* <CheckboxGroup aria-labelledby="terms-label" aria-invalid="true" aria-describedby="terms-error">
|
|
53
|
+
* <Label id="terms-label">{t("terms.label")}</Label>
|
|
54
|
+
* <Checkbox name="terms" value="accepted" required>{t("terms.accept")}</Checkbox>
|
|
55
|
+
* <FieldError id="terms-error">{t("terms.required")}</FieldError>
|
|
56
|
+
* </CheckboxGroup>
|
|
57
|
+
*/
|
|
58
|
+
export declare function CheckboxGroup(handle: Handle<CheckboxGroup.Props>): () => import("remix/ui").RemixElement;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "remix/ui/jsx-runtime";
|
|
2
|
+
import { fg } from "@sdxc/u/color";
|
|
3
|
+
import { flexRow, gap, vstack } from "@sdxc/u/layout";
|
|
4
|
+
import { when } from "@sdxc/u/state";
|
|
5
|
+
import { attrs } from "remix/ui";
|
|
6
|
+
import { warnIfNoAccessibleLabel } from "../utils/warn-if-no-accessible-name.js";
|
|
7
|
+
/**
|
|
8
|
+
* Announces the host as a related set of controls to assistive technology;
|
|
9
|
+
* {@link attrs} lets a consumer's own `role` win.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_ROLE = "group";
|
|
12
|
+
const DEFAULT_ORIENTATION = "vertical";
|
|
13
|
+
/**
|
|
14
|
+
* Lays checkbox children out in a column, or a row when `orientation` is
|
|
15
|
+
* `"horizontal"`; each nested checkbox keeps its own checked state, `name`,
|
|
16
|
+
* and `value`. `aria-invalid="true"` recolors plain text composed alongside.
|
|
17
|
+
*
|
|
18
|
+
* @param handle Runtime handle carrying the host `<div>`'s props.
|
|
19
|
+
* @returns The render function producing the group's markup.
|
|
20
|
+
* @example
|
|
21
|
+
* <CheckboxGroup aria-labelledby="fruits-label">
|
|
22
|
+
* <Label id="fruits-label">{t("fruits.label")}</Label>
|
|
23
|
+
* <Checkbox name="fruits" value="apple">{t("fruits.apple")}</Checkbox>
|
|
24
|
+
* <Checkbox name="fruits" value="banana">{t("fruits.banana")}</Checkbox>
|
|
25
|
+
* <Checkbox name="fruits" value="orange">{t("fruits.orange")}</Checkbox>
|
|
26
|
+
* </CheckboxGroup>
|
|
27
|
+
* @example
|
|
28
|
+
* <CheckboxGroup aria-label={t("notifications.label")} orientation="horizontal">
|
|
29
|
+
* <Checkbox name="notify" value="email">{t("notifications.email")}</Checkbox>
|
|
30
|
+
* <Checkbox name="notify" value="sms">{t("notifications.sms")}</Checkbox>
|
|
31
|
+
* <Checkbox name="notify" value="push">{t("notifications.push")}</Checkbox>
|
|
32
|
+
* </CheckboxGroup>
|
|
33
|
+
* @example
|
|
34
|
+
* <CheckboxGroup aria-labelledby="terms-label" aria-invalid="true" aria-describedby="terms-error">
|
|
35
|
+
* <Label id="terms-label">{t("terms.label")}</Label>
|
|
36
|
+
* <Checkbox name="terms" value="accepted" required>{t("terms.accept")}</Checkbox>
|
|
37
|
+
* <FieldError id="terms-error">{t("terms.required")}</FieldError>
|
|
38
|
+
* </CheckboxGroup>
|
|
39
|
+
*/
|
|
40
|
+
export function CheckboxGroup(handle) {
|
|
41
|
+
return () => {
|
|
42
|
+
let { orientation, mix, ...rest } = handle.props;
|
|
43
|
+
let resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;
|
|
44
|
+
warnIfNoAccessibleLabel(handle.props, "CheckboxGroup: a group with no `aria-label` or `aria-labelledby` needs one describing the set — assistive technology has no accessible name to announce otherwise.");
|
|
45
|
+
return (_jsx("div", { "data-orientation": resolvedOrientation, ...rest, mix: [
|
|
46
|
+
attrs({ role: DEFAULT_ROLE }),
|
|
47
|
+
vstack({ gap: 2 }),
|
|
48
|
+
when('&[data-orientation="horizontal"]', [flexRow(), gap(4)]),
|
|
49
|
+
when('&[aria-invalid="true"]', fg("danger")),
|
|
50
|
+
mix,
|
|
51
|
+
] }));
|
|
52
|
+
};
|
|
53
|
+
}
|