@seekalfred/primitives 0.6.0 → 0.7.3
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/README.md +214 -15
- package/dist/activity-heatmap/activity-heatmap.d.ts +92 -0
- package/dist/activity-heatmap/activity-heatmap.js +699 -0
- package/dist/activity-heatmap/activity-heatmap.js.map +1 -0
- package/dist/activity-heatmap/index.d.ts +2 -0
- package/dist/activity-heatmap/index.js +2 -0
- package/dist/alert/alert.d.ts +53 -4
- package/dist/alert/alert.js +100 -11
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +58 -18
- package/dist/alert-dialog/alert-dialog.js +152 -9
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/alert-dialog/index.d.ts +2 -2
- package/dist/alert-dialog/index.js +2 -2
- package/dist/animated-counter/animated-counter.d.ts +38 -0
- package/dist/animated-counter/animated-counter.js +230 -0
- package/dist/animated-counter/animated-counter.js.map +1 -0
- package/dist/animated-counter/index.d.ts +2 -0
- package/dist/animated-counter/index.js +2 -0
- package/dist/announcement-bar/announcement-bar.d.ts +67 -0
- package/dist/announcement-bar/announcement-bar.js +364 -0
- package/dist/announcement-bar/announcement-bar.js.map +1 -0
- package/dist/announcement-bar/index.d.ts +2 -0
- package/dist/announcement-bar/index.js +2 -0
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart.d.ts +51 -0
- package/dist/bar-chart/bar-chart.js +565 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/index.d.ts +2 -0
- package/dist/bar-chart/index.js +2 -0
- package/dist/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/breadcrumb/breadcrumb.js +12 -3
- package/dist/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/brush-chart/brush-chart.d.ts +64 -0
- package/dist/brush-chart/brush-chart.js +1056 -0
- package/dist/brush-chart/brush-chart.js.map +1 -0
- package/dist/brush-chart/index.d.ts +2 -0
- package/dist/brush-chart/index.js +2 -0
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button.js +31 -21
- package/dist/button/button.js.map +1 -1
- package/dist/button-group/button-group.js +3 -4
- package/dist/button-group/button-group.js.map +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/card-stack/card-stack.d.ts +54 -0
- package/dist/card-stack/card-stack.js +492 -0
- package/dist/card-stack/card-stack.js.map +1 -0
- package/dist/card-stack/index.d.ts +2 -0
- package/dist/card-stack/index.js +2 -0
- package/dist/carousel/carousel.d.ts +77 -0
- package/dist/carousel/carousel.js +415 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/carousel/index.d.ts +2 -0
- package/dist/carousel/index.js +2 -0
- package/dist/checkbox/checkbox.js +4 -4
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +37 -0
- package/dist/chip-group/chip-group.js +148 -0
- package/dist/chip-group/chip-group.js.map +1 -0
- package/dist/chip-group/index.d.ts +2 -0
- package/dist/chip-group/index.js +2 -0
- package/dist/copy-button/copy-button.d.ts +18 -2
- package/dist/copy-button/copy-button.js +29 -8
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/countdown/countdown.d.ts +45 -0
- package/dist/countdown/countdown.js +298 -0
- package/dist/countdown/countdown.js.map +1 -0
- package/dist/countdown/index.d.ts +2 -0
- package/dist/countdown/index.js +2 -0
- package/dist/date-picker/picker-parts.js +1 -1
- package/dist/date-picker/picker-parts.js.map +1 -1
- package/dist/dialog/dialog.js +1 -1
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +86 -0
- package/dist/donut-chart/donut-chart.js +593 -0
- package/dist/donut-chart/donut-chart.js.map +1 -0
- package/dist/donut-chart/index.d.ts +2 -0
- package/dist/donut-chart/index.js +2 -0
- package/dist/empty-state/empty-state.d.ts +42 -10
- package/dist/empty-state/empty-state.js +44 -26
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.js +1 -1
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +50 -26
- package/dist/filter-bar/filter-bar.js +317 -157
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +45 -0
- package/dist/gauge/gauge.js +219 -0
- package/dist/gauge/gauge.js.map +1 -0
- package/dist/gauge/index.d.ts +2 -0
- package/dist/gauge/index.js +2 -0
- package/dist/in-view-title/in-view-title.d.ts +33 -0
- package/dist/in-view-title/in-view-title.js +119 -0
- package/dist/in-view-title/in-view-title.js.map +1 -0
- package/dist/in-view-title/index.d.ts +2 -0
- package/dist/in-view-title/index.js +2 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.js +52 -12
- package/dist/input/input.js +4 -4
- package/dist/input/input.js.map +1 -1
- package/dist/lib/cn.js +11 -1
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/field-message.js +28 -10
- package/dist/lib/field-message.js.map +1 -1
- package/dist/lib/field-shell.js +10 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +31 -9
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/flag-emoji.js +50 -0
- package/dist/lib/flag-emoji.js.map +1 -0
- package/dist/lib/flip.js +11 -3
- package/dist/lib/flip.js.map +1 -1
- package/dist/lib/menu-highlight.js +64 -0
- package/dist/lib/menu-highlight.js.map +1 -0
- package/dist/lib/motion.js +9 -2
- package/dist/lib/motion.js.map +1 -1
- package/dist/lib/rolling-value.js +1 -1
- package/dist/lib/rolling-value.js.map +1 -1
- package/dist/lib/spring-tween.js +500 -0
- package/dist/lib/spring-tween.js.map +1 -0
- package/dist/lib/swap-text.js +3 -1
- package/dist/lib/swap-text.js.map +1 -1
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -0
- package/dist/line-chart/index.js +2 -0
- package/dist/line-chart/line-chart.d.ts +116 -0
- package/dist/line-chart/line-chart.js +740 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/mention-input/index.d.ts +2 -0
- package/dist/mention-input/index.js +2 -0
- package/dist/mention-input/mention-input.d.ts +98 -0
- package/dist/mention-input/mention-input.js +576 -0
- package/dist/mention-input/mention-input.js.map +1 -0
- package/dist/menu/menu.d.ts +2 -0
- package/dist/menu/menu.js +23 -12
- package/dist/menu/menu.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -0
- package/dist/money-input/index.js +2 -0
- package/dist/money-input/money-input.d.ts +86 -0
- package/dist/money-input/money-input.js +613 -0
- package/dist/money-input/money-input.js.map +1 -0
- package/dist/morph-select/index.d.ts +2 -0
- package/dist/morph-select/index.js +2 -0
- package/dist/morph-select/morph-select.d.ts +89 -0
- package/dist/morph-select/morph-select.js +712 -0
- package/dist/morph-select/morph-select.js.map +1 -0
- package/dist/multi-select/index.d.ts +2 -0
- package/dist/multi-select/index.js +2 -0
- package/dist/multi-select/multi-select.d.ts +77 -0
- package/dist/multi-select/multi-select.js +209 -0
- package/dist/multi-select/multi-select.js.map +1 -0
- package/dist/number-field/index.d.ts +2 -0
- package/dist/number-field/index.js +2 -0
- package/dist/number-field/number-field.d.ts +42 -0
- package/dist/number-field/number-field.js +199 -0
- package/dist/number-field/number-field.js.map +1 -0
- package/dist/onboarding-checklist/index.d.ts +2 -0
- package/dist/onboarding-checklist/index.js +2 -0
- package/dist/onboarding-checklist/onboarding-checklist.d.ts +55 -0
- package/dist/onboarding-checklist/onboarding-checklist.js +577 -0
- package/dist/onboarding-checklist/onboarding-checklist.js.map +1 -0
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +39 -10
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/phone-input/index.d.ts +3 -0
- package/dist/phone-input/index.js +3 -0
- package/dist/phone-input/phone-countries.d.ts +29 -0
- package/dist/phone-input/phone-countries.js +170 -0
- package/dist/phone-input/phone-countries.js.map +1 -0
- package/dist/phone-input/phone-input.d.ts +66 -0
- package/dist/phone-input/phone-input.js +440 -0
- package/dist/phone-input/phone-input.js.map +1 -0
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +51 -2
- package/dist/popover/popover.js +59 -8
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/progress.d.ts +16 -2
- package/dist/progress/progress.js +16 -9
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +110 -10
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/reactions/index.d.ts +2 -0
- package/dist/reactions/index.js +2 -0
- package/dist/reactions/reactions.d.ts +50 -0
- package/dist/reactions/reactions.js +315 -0
- package/dist/reactions/reactions.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +3 -0
- package/dist/rich-text-editor/index.js +2 -0
- package/dist/rich-text-editor/rich-text-editor.d.ts +70 -0
- package/dist/rich-text-editor/rich-text-editor.js +909 -0
- package/dist/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/rich-text-editor/rich-text-engine.d.ts +16 -0
- package/dist/rich-text-editor/rich-text-engine.js +366 -0
- package/dist/rich-text-editor/rich-text-engine.js.map +1 -0
- package/dist/rich-text-editor/rich-text-html.js +174 -0
- package/dist/rich-text-editor/rich-text-html.js.map +1 -0
- package/dist/rich-text-editor/rich-text-icons.js +43 -0
- package/dist/rich-text-editor/rich-text-icons.js.map +1 -0
- package/dist/ridgeline/index.d.ts +2 -0
- package/dist/ridgeline/index.js +2 -0
- package/dist/ridgeline/ridgeline.d.ts +55 -0
- package/dist/ridgeline/ridgeline.js +701 -0
- package/dist/ridgeline/ridgeline.js.map +1 -0
- package/dist/scroll-area/index.d.ts +2 -2
- package/dist/scroll-area/index.js +2 -2
- package/dist/scroll-area/scroll-area.d.ts +68 -31
- package/dist/scroll-area/scroll-area.js +212 -62
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/evaluate.d.ts +14 -0
- package/dist/scrub-input/evaluate.js +72 -0
- package/dist/scrub-input/evaluate.js.map +1 -0
- package/dist/scrub-input/index.d.ts +3 -0
- package/dist/scrub-input/index.js +3 -0
- package/dist/scrub-input/scrub-input.d.ts +74 -0
- package/dist/scrub-input/scrub-input.js +486 -0
- package/dist/scrub-input/scrub-input.js.map +1 -0
- package/dist/search-field/search-field.d.ts +24 -2
- package/dist/search-field/search-field.js +24 -9
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +3 -1
- package/dist/select/select.js +28 -14
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +22 -10
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sheet/sheet.js +2 -1
- package/dist/sheet/sheet.js.map +1 -1
- package/dist/shortcut-recorder/index.d.ts +3 -0
- package/dist/shortcut-recorder/index.js +3 -0
- package/dist/shortcut-recorder/shortcut-model.d.ts +27 -0
- package/dist/shortcut-recorder/shortcut-model.js +206 -0
- package/dist/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/shortcut-recorder/shortcut-recorder.d.ts +93 -0
- package/dist/shortcut-recorder/shortcut-recorder.js +489 -0
- package/dist/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/slider/index.d.ts +2 -2
- package/dist/slider/slider.d.ts +46 -14
- package/dist/slider/slider.js +151 -67
- package/dist/slider/slider.js.map +1 -1
- package/dist/slope-chart/index.d.ts +2 -0
- package/dist/slope-chart/index.js +2 -0
- package/dist/slope-chart/slope-chart.d.ts +54 -0
- package/dist/slope-chart/slope-chart.js +568 -0
- package/dist/slope-chart/slope-chart.js.map +1 -0
- package/dist/sparkline/index.d.ts +2 -0
- package/dist/sparkline/index.js +2 -0
- package/dist/sparkline/sparkline.d.ts +46 -0
- package/dist/sparkline/sparkline.js +390 -0
- package/dist/sparkline/sparkline.js.map +1 -0
- package/dist/split-bar/index.d.ts +2 -0
- package/dist/split-bar/index.js +2 -0
- package/dist/split-bar/split-bar.d.ts +62 -0
- package/dist/split-bar/split-bar.js +513 -0
- package/dist/split-bar/split-bar.js.map +1 -0
- package/dist/split-button/split-button.d.ts +1 -1
- package/dist/split-button/split-button.js +12 -11
- package/dist/split-button/split-button.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +58 -5
- package/dist/stat-card/stat-card.js +144 -17
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/stepper/index.d.ts +2 -0
- package/dist/stepper/index.js +2 -0
- package/dist/stepper/stepper.d.ts +51 -0
- package/dist/stepper/stepper.js +215 -0
- package/dist/stepper/stepper.js.map +1 -0
- package/dist/streamgraph/index.d.ts +2 -0
- package/dist/streamgraph/index.js +2 -0
- package/dist/streamgraph/streamgraph.d.ts +70 -0
- package/dist/streamgraph/streamgraph.js +613 -0
- package/dist/streamgraph/streamgraph.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/swipe-actions/index.d.ts +2 -0
- package/dist/swipe-actions/index.js +2 -0
- package/dist/swipe-actions/swipe-actions.d.ts +67 -0
- package/dist/swipe-actions/swipe-actions.js +552 -0
- package/dist/swipe-actions/swipe-actions.js.map +1 -0
- package/dist/switch/switch.js +2 -2
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +55 -3
- package/dist/table/table.js +340 -165
- package/dist/table/table.js.map +1 -1
- package/dist/tabs/tabs.js +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tag-input/index.d.ts +2 -0
- package/dist/tag-input/index.js +2 -0
- package/dist/tag-input/tag-input.d.ts +40 -0
- package/dist/tag-input/tag-input.js +269 -0
- package/dist/tag-input/tag-input.js.map +1 -0
- package/dist/text-morph/index.d.ts +2 -0
- package/dist/text-morph/index.js +2 -0
- package/dist/text-morph/text-morph.d.ts +23 -0
- package/dist/text-morph/text-morph.js +21 -0
- package/dist/text-morph/text-morph.js.map +1 -0
- package/dist/text-reveal/index.d.ts +2 -0
- package/dist/text-reveal/index.js +2 -0
- package/dist/text-reveal/text-reveal.d.ts +27 -0
- package/dist/text-reveal/text-reveal.js +51 -0
- package/dist/text-reveal/text-reveal.js.map +1 -0
- package/dist/text-shimmer/index.d.ts +2 -0
- package/dist/text-shimmer/index.js +2 -0
- package/dist/text-shimmer/text-shimmer.d.ts +29 -0
- package/dist/text-shimmer/text-shimmer.js +29 -0
- package/dist/text-shimmer/text-shimmer.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +35 -7
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/index.d.ts +2 -2
- package/dist/toast/index.js +2 -2
- package/dist/toast/toast.d.ts +7 -1
- package/dist/toast/toast.js +82 -40
- package/dist/toast/toast.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +9 -2
- package/dist/tooltip/tooltip.js +7 -7
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/treemap/index.d.ts +2 -0
- package/dist/treemap/index.js +2 -0
- package/dist/treemap/treemap.d.ts +53 -0
- package/dist/treemap/treemap.js +699 -0
- package/dist/treemap/treemap.js.map +1 -0
- package/dist/usage-meter/index.d.ts +2 -0
- package/dist/usage-meter/index.js +2 -0
- package/dist/usage-meter/usage-meter.d.ts +80 -0
- package/dist/usage-meter/usage-meter.js +458 -0
- package/dist/usage-meter/usage-meter.js.map +1 -0
- package/dist/waffle-chart/index.d.ts +2 -0
- package/dist/waffle-chart/index.js +2 -0
- package/dist/waffle-chart/waffle-chart.d.ts +57 -0
- package/dist/waffle-chart/waffle-chart.js +426 -0
- package/dist/waffle-chart/waffle-chart.js.map +1 -0
- package/package.json +165 -3
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { cn } from "../lib/cn.js";
|
|
3
3
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
4
4
|
import { prefersReducedMotion, useExitBackstop, useIsomorphicLayoutEffect } from "../lib/motion.js";
|
|
5
|
-
import { fieldSurfaceVariants } from "../lib/field-surface.js";
|
|
5
|
+
import { fieldBoxSize, fieldSurfaceVariants, fieldTextSize } from "../lib/field-surface.js";
|
|
6
6
|
import { FieldShell, useFieldWiring } from "../lib/field-shell.js";
|
|
7
|
+
import { cva } from "class-variance-authority";
|
|
7
8
|
import { forwardRef, useCallback, useMemo, useRef, useState } from "react";
|
|
8
9
|
import { Button, Group, Input } from "react-aria-components";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -13,10 +14,22 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
13
14
|
* PasswordField for why a Group, and why `data-focus-within` darkens the border
|
|
14
15
|
* as well). `group/shell` lets the glass read the box's focus and filled state.
|
|
15
16
|
*/
|
|
16
|
-
const
|
|
17
|
+
const shellVariants = cva("group/shell flex items-center gap-(--density-control-gap) [&:where([data-focus-within])]:border-border-strong", {
|
|
18
|
+
variants: {
|
|
19
|
+
/**
|
|
20
|
+
* Height and inline padding from the control scale, the same three rungs
|
|
21
|
+
* and tokens as Input, Select and Button, so a toolbar search sits level
|
|
22
|
+
* with the buttons beside it.
|
|
23
|
+
*/
|
|
24
|
+
size: fieldBoxSize },
|
|
25
|
+
defaultVariants: { size: "md" }
|
|
26
|
+
});
|
|
17
27
|
/** Borderless, fill-less input; the browser's own clear button and search decoration are hidden because the field has its own. */
|
|
18
|
-
const
|
|
19
|
-
|
|
28
|
+
const inputVariants = cva("min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden", {
|
|
29
|
+
variants: { size: fieldTextSize },
|
|
30
|
+
defaultVariants: { size: "md" }
|
|
31
|
+
});
|
|
32
|
+
const clearClass = "motion-safe:button-motion grid size-6 cursor-pointer place-items-center rounded-control border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground motion-safe:data-[pressed]:scale-96 data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed";
|
|
20
33
|
/** The glass wakes up with the field: muted at rest, full contrast while the field has focus or a value. */
|
|
21
34
|
function SearchGlyph() {
|
|
22
35
|
return /* @__PURE__ */ jsxs("svg", {
|
|
@@ -93,8 +106,9 @@ function ClearButton({ show, label, disabled, onClear }) {
|
|
|
93
106
|
*
|
|
94
107
|
* @example
|
|
95
108
|
* <SearchField label="Search contacts" value={query} onValueChange={setQuery} />
|
|
109
|
+
* <SearchField label="Search tickets" labelHidden size="sm" value={query} onValueChange={setQuery} />
|
|
96
110
|
*/
|
|
97
|
-
const SearchField = forwardRef(function SearchField({ label, value, onValueChange, clearLabel = "Clear search", className, ...props }, ref) {
|
|
111
|
+
const SearchField$1 = forwardRef(function SearchField({ label, labelHidden = false, size = "md", value, onValueChange, clearLabel = "Clear search", className, ...props }, ref) {
|
|
98
112
|
const inputRef = useRef(null);
|
|
99
113
|
const refs = useMemo(() => mergeRefs(ref, inputRef), [ref]);
|
|
100
114
|
const field = useFieldWiring({
|
|
@@ -111,18 +125,19 @@ const SearchField = forwardRef(function SearchField({ label, value, onValueChang
|
|
|
111
125
|
isDisabled: disabled,
|
|
112
126
|
"data-filled": value ? "true" : void 0,
|
|
113
127
|
"data-slot": "search-field-shell",
|
|
114
|
-
className:
|
|
128
|
+
className: cn(fieldSurfaceVariants(), shellVariants({ size })),
|
|
115
129
|
children: [
|
|
116
130
|
/* @__PURE__ */ jsx(SearchGlyph, {}),
|
|
117
131
|
/* @__PURE__ */ jsx(Input, {
|
|
118
132
|
ref: refs,
|
|
133
|
+
"aria-label": labelHidden ? label : void 0,
|
|
119
134
|
...props,
|
|
120
135
|
...field.controlProps,
|
|
121
136
|
type: "search",
|
|
122
137
|
value,
|
|
123
138
|
onChange: (event) => onValueChange(event.target.value),
|
|
124
139
|
"data-slot": "search-field",
|
|
125
|
-
className: cn(
|
|
140
|
+
className: cn(inputVariants({ size }), className)
|
|
126
141
|
}),
|
|
127
142
|
/* @__PURE__ */ jsx("span", {
|
|
128
143
|
className: "grid size-6 flex-none place-items-center",
|
|
@@ -140,7 +155,7 @@ const SearchField = forwardRef(function SearchField({ label, value, onValueChang
|
|
|
140
155
|
});
|
|
141
156
|
if (!field.active) return control;
|
|
142
157
|
return /* @__PURE__ */ jsx(FieldShell, {
|
|
143
|
-
label,
|
|
158
|
+
label: labelHidden ? null : label,
|
|
144
159
|
controlId: field.controlId,
|
|
145
160
|
description: void 0,
|
|
146
161
|
hintId: void 0,
|
|
@@ -150,6 +165,6 @@ const SearchField = forwardRef(function SearchField({ label, value, onValueChang
|
|
|
150
165
|
});
|
|
151
166
|
});
|
|
152
167
|
//#endregion
|
|
153
|
-
export { SearchField };
|
|
168
|
+
export { SearchField$1 as SearchField };
|
|
154
169
|
|
|
155
170
|
//# sourceMappingURL=search-field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-field.js","names":["AriaButton","AriaGroup","AriaInput"],"sources":["../../src/search-field/search-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useCallback, useMemo, useRef, useState } from \"react\";\nimport {\n Button as AriaButton,\n Group as AriaGroup,\n Input as AriaInput,\n type InputProps as AriaInputProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\nimport { FieldShell, useFieldWiring } from \"../lib/field-shell.js\";\nimport { fieldSurfaceVariants } from \"../lib/field-surface.js\";\nimport { mergeRefs } from \"../lib/merge-refs.js\";\nimport { prefersReducedMotion, useExitBackstop, useIsomorphicLayoutEffect } from \"../lib/motion.js\";\n\n/**\n * The field's box: a React Aria `Group` carrying the shared field surface (see\n * PasswordField for why a Group, and why `data-focus-within` darkens the border\n * as well). `group/shell` lets the glass read the box's focus and filled state.\n */\nconst shellClass = cn(\n fieldSurfaceVariants(),\n \"group/shell flex items-center gap-(--density-control-gap) h-(--density-control-h-md) px-(--density-control-pad-md) [&:where([data-focus-within])]:border-foreground\",\n);\n\n/** Borderless, fill-less input; the browser's own clear button and search decoration are hidden because the field has its own. */\nconst inputClass =\n \"min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-base text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden\";\n\nconst clearClass =\n \"motion-safe:button-motion grid size-6 cursor-pointer place-items-center rounded-md border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground motion-safe:data-[pressed]:scale-96 data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed\";\n\n/** The glass wakes up with the field: muted at rest, full contrast while the field has focus or a value. */\nfunction SearchGlyph() {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className=\"size-4.5 flex-none text-muted-foreground motion-safe:transition-colors motion-safe:duration-(--duration-quick) motion-safe:ease-settle group-data-[filled]/shell:text-foreground group-data-[focus-within]/shell:text-foreground\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n <path d=\"m21 21-4.34-4.34\" />\n </svg>\n );\n}\n\n/**\n * The clear button, in a box that is always there so the field never changes\n * width. It scales in on the snappy spring while it fades and unblurs, and\n * leaves a little smaller. Nothing animates if it is there on first mount, and\n * while it leaves it is inert so it cannot be pressed or focused.\n */\nfunction ClearButton({\n show,\n label,\n disabled,\n onClear,\n}: {\n show: boolean;\n label: string;\n disabled: boolean;\n onClear: () => void;\n}) {\n const [initial] = useState(show);\n const [rendered, setRendered] = useState(show);\n const [animated, setAnimated] = useState(false);\n const leaving = rendered && !show;\n if (show && !rendered) setRendered(true);\n if (!animated && show !== initial) setAnimated(true);\n const unmount = useCallback(() => setRendered(false), []);\n useExitBackstop(leaving, unmount);\n // Reduced motion removes it at once: an animation that is switched off never ends.\n useIsomorphicLayoutEffect(() => {\n if (leaving && prefersReducedMotion()) unmount();\n }, [leaving, unmount]);\n if (!rendered) return null;\n return (\n <span\n ref={(node) => {\n if (!node) return;\n if (leaving) node.setAttribute(\"inert\", \"\");\n else node.removeAttribute(\"inert\");\n }}\n aria-hidden={leaving || undefined}\n onAnimationEnd={(event) => {\n if (\n leaving &&\n event.target === event.currentTarget &&\n event.animationName === \"field-clear-out\"\n )\n unmount();\n }}\n className={cn(\n \"grid size-6 place-items-center\",\n leaving\n ? \"pointer-events-none motion-safe:animate-field-clear-out\"\n : animated && \"motion-safe:animate-field-clear-in motion-reduce:animate-fade-in\",\n )}\n >\n <AriaButton\n type=\"button\"\n isDisabled={disabled}\n aria-label={label}\n onPress={onClear}\n className={clearClass}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className=\"size-4\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n </AriaButton>\n </span>\n );\n}\n\nexport interface SearchFieldProps extends Omit<\n AriaInputProps,\n \"className\" | \"style\" | \"size\" | \"type\" | \"value\" | \"defaultValue\" | \"onChange\"\n> {\n /** Extra classes for the input. Merged last, so they win conflicts with ours. */\n className?: string;\n /** The visible label, tied to the input with `htmlFor`. */\n label: string;\n /** The current text. Controlled: the field has no state of its own. */\n value: string;\n /** Called with the new text on every edit, and with `\"\"` when the clear button is pressed. */\n onValueChange: (value: string) => void;\n /** The clear button's accessible name. @default \"Clear search\" */\n clearLabel?: string;\n}\n\n/**\n * A search input with a clear button. The button has a reserved box, so the\n * field never changes width as it comes and goes; pressing it clears the text\n * and returns focus to the input. `onChange` is not accepted: use `onValueChange`.\n * Native input props apply to the input, and `disabled` also disables the button.\n *\n * @example\n * <SearchField label=\"Search contacts\" value={query} onValueChange={setQuery} />\n */\nexport const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(function SearchField(\n { label, value, onValueChange, clearLabel = \"Clear search\", className, ...props },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement | null>(null);\n const refs = useMemo(() => mergeRefs(ref, inputRef), [ref]);\n const field = useFieldWiring({\n enabled: true,\n id: props.id,\n describedBy: props[\"aria-describedby\"],\n invalid: props[\"aria-invalid\"],\n description: undefined,\n error: undefined,\n });\n const disabled = Boolean(props.disabled);\n\n const control = (\n <AriaGroup\n role=\"presentation\"\n isDisabled={disabled}\n data-filled={value ? \"true\" : undefined}\n data-slot=\"search-field-shell\"\n className={shellClass}\n >\n <SearchGlyph />\n <AriaInput\n ref={refs}\n {...props}\n {...field.controlProps}\n type=\"search\"\n value={value}\n onChange={(event) => onValueChange(event.target.value)}\n data-slot=\"search-field\"\n className={cn(inputClass, className)}\n />\n {/* A clear button's box is reserved, so the field never changes width when it appears or leaves. */}\n <span className=\"grid size-6 flex-none place-items-center\">\n <ClearButton\n show={value !== \"\"}\n label={clearLabel}\n disabled={disabled}\n onClear={() => {\n onValueChange(\"\");\n inputRef.current?.focus();\n }}\n />\n </span>\n </AriaGroup>\n );\n\n if (!field.active) return control;\n return (\n <FieldShell\n label={label}\n controlId={field.controlId}\n description={undefined}\n hintId={undefined}\n error={undefined}\n errorId={undefined}\n >\n {control}\n </FieldShell>\n );\n});\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"search-field.js","names":["AriaButton","SearchField","AriaGroup","AriaInput"],"sources":["../../src/search-field/search-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef, useCallback, useMemo, useRef, useState } from \"react\";\nimport {\n Button as AriaButton,\n Group as AriaGroup,\n Input as AriaInput,\n type InputProps as AriaInputProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\nimport { FieldShell, useFieldWiring } from \"../lib/field-shell.js\";\nimport { fieldBoxSize, fieldSurfaceVariants, fieldTextSize } from \"../lib/field-surface.js\";\nimport { mergeRefs } from \"../lib/merge-refs.js\";\nimport { prefersReducedMotion, useExitBackstop, useIsomorphicLayoutEffect } from \"../lib/motion.js\";\n\n/**\n * The field's box: a React Aria `Group` carrying the shared field surface (see\n * PasswordField for why a Group, and why `data-focus-within` darkens the border\n * as well). `group/shell` lets the glass read the box's focus and filled state.\n */\nconst shellVariants = cva(\n \"group/shell flex items-center gap-(--density-control-gap) [&:where([data-focus-within])]:border-border-strong\",\n {\n variants: {\n /**\n * Height and inline padding from the control scale, the same three rungs\n * and tokens as Input, Select and Button, so a toolbar search sits level\n * with the buttons beside it.\n */\n size: fieldBoxSize,\n },\n defaultVariants: { size: \"md\" },\n },\n);\n\n/** Borderless, fill-less input; the browser's own clear button and search decoration are hidden because the field has its own. */\nconst inputVariants = cva(\n \"min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden\",\n {\n variants: {\n // Input's type rule: `sm` is 14px, except on a coarse pointer, where iOS would zoom a focused field under 16px.\n size: fieldTextSize,\n },\n defaultVariants: { size: \"md\" },\n },\n);\n\nconst clearClass =\n \"motion-safe:button-motion grid size-6 cursor-pointer place-items-center rounded-control border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground motion-safe:data-[pressed]:scale-96 data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed\";\n\n/** The glass wakes up with the field: muted at rest, full contrast while the field has focus or a value. */\nfunction SearchGlyph() {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className=\"size-4.5 flex-none text-muted-foreground motion-safe:transition-colors motion-safe:duration-(--duration-quick) motion-safe:ease-settle group-data-[filled]/shell:text-foreground group-data-[focus-within]/shell:text-foreground\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n <path d=\"m21 21-4.34-4.34\" />\n </svg>\n );\n}\n\n/**\n * The clear button, in a box that is always there so the field never changes\n * width. It scales in on the snappy spring while it fades and unblurs, and\n * leaves a little smaller. Nothing animates if it is there on first mount, and\n * while it leaves it is inert so it cannot be pressed or focused.\n */\nfunction ClearButton({\n show,\n label,\n disabled,\n onClear,\n}: {\n show: boolean;\n label: string;\n disabled: boolean;\n onClear: () => void;\n}) {\n const [initial] = useState(show);\n const [rendered, setRendered] = useState(show);\n const [animated, setAnimated] = useState(false);\n const leaving = rendered && !show;\n if (show && !rendered) setRendered(true);\n if (!animated && show !== initial) setAnimated(true);\n const unmount = useCallback(() => setRendered(false), []);\n useExitBackstop(leaving, unmount);\n // Reduced motion removes it at once: an animation that is switched off never ends.\n useIsomorphicLayoutEffect(() => {\n if (leaving && prefersReducedMotion()) unmount();\n }, [leaving, unmount]);\n if (!rendered) return null;\n return (\n <span\n ref={(node) => {\n if (!node) return;\n if (leaving) node.setAttribute(\"inert\", \"\");\n else node.removeAttribute(\"inert\");\n }}\n aria-hidden={leaving || undefined}\n onAnimationEnd={(event) => {\n if (\n leaving &&\n event.target === event.currentTarget &&\n event.animationName === \"field-clear-out\"\n )\n unmount();\n }}\n className={cn(\n \"grid size-6 place-items-center\",\n leaving\n ? \"pointer-events-none motion-safe:animate-field-clear-out\"\n : animated && \"motion-safe:animate-field-clear-in motion-reduce:animate-fade-in\",\n )}\n >\n <AriaButton\n type=\"button\"\n isDisabled={disabled}\n aria-label={label}\n onPress={onClear}\n className={clearClass}\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className=\"size-4\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n </AriaButton>\n </span>\n );\n}\n\nexport interface SearchFieldProps extends Omit<\n AriaInputProps,\n \"className\" | \"style\" | \"size\" | \"type\" | \"value\" | \"defaultValue\" | \"onChange\"\n> {\n /** Extra classes for the input. Merged last, so they win conflicts with ours. */\n className?: string;\n /**\n * What the field searches, and its accessible name. Visible above the box,\n * tied to the input with `htmlFor`, unless `labelHidden` is set.\n */\n label: string;\n /**\n * Hide the label and keep it as the input's accessible name (`aria-label`),\n * for a toolbar search whose purpose the surrounding UI already shows.\n * @default false\n */\n labelHidden?: boolean;\n /**\n * Control scale of the box. Height and inline padding come from the same\n * `--density-control-*` tokens as Input, Select and Button; `sm` also\n * takes Input's 14px text (16px on a touch screen).\n *\n * This REPLACES the native `size` attribute, which sets a width in\n * characters that the flex layout ignores.\n *\n * @default \"md\"\n */\n size?: \"sm\" | \"md\" | \"lg\";\n /** The current text. Controlled: the field has no state of its own. */\n value: string;\n /** Called with the new text on every edit, and with `\"\"` when the clear button is pressed. */\n onValueChange: (value: string) => void;\n /** The clear button's accessible name. @default \"Clear search\" */\n clearLabel?: string;\n}\n\n/**\n * A search input with a clear button. The button has a reserved box, so the\n * field never changes width as it comes and goes; pressing it clears the text\n * and returns focus to the input. `onChange` is not accepted: use `onValueChange`.\n * Native input props apply to the input, and `disabled` also disables the button.\n *\n * @example\n * <SearchField label=\"Search contacts\" value={query} onValueChange={setQuery} />\n * <SearchField label=\"Search tickets\" labelHidden size=\"sm\" value={query} onValueChange={setQuery} />\n */\nexport const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(function SearchField(\n {\n label,\n labelHidden = false,\n size = \"md\",\n value,\n onValueChange,\n clearLabel = \"Clear search\",\n className,\n ...props\n },\n ref,\n) {\n const inputRef = useRef<HTMLInputElement | null>(null);\n const refs = useMemo(() => mergeRefs(ref, inputRef), [ref]);\n const field = useFieldWiring({\n enabled: true,\n id: props.id,\n describedBy: props[\"aria-describedby\"],\n invalid: props[\"aria-invalid\"],\n description: undefined,\n error: undefined,\n });\n const disabled = Boolean(props.disabled);\n\n const control = (\n <AriaGroup\n role=\"presentation\"\n isDisabled={disabled}\n data-filled={value ? \"true\" : undefined}\n data-slot=\"search-field-shell\"\n className={cn(fieldSurfaceVariants(), shellVariants({ size }))}\n >\n <SearchGlyph />\n <AriaInput\n ref={refs}\n // A hidden label is still the name, inside a TextField too (one with no Label child has no other name).\n // Before the spread, so an explicit aria-label wins as it does over a visible one.\n aria-label={labelHidden ? label : undefined}\n {...props}\n {...field.controlProps}\n type=\"search\"\n value={value}\n onChange={(event) => onValueChange(event.target.value)}\n data-slot=\"search-field\"\n className={cn(inputVariants({ size }), className)}\n />\n {/* A clear button's box is reserved, so the field never changes width when it appears or leaves. */}\n <span className=\"grid size-6 flex-none place-items-center\">\n <ClearButton\n show={value !== \"\"}\n label={clearLabel}\n disabled={disabled}\n onClear={() => {\n onValueChange(\"\");\n inputRef.current?.focus();\n }}\n />\n </span>\n </AriaGroup>\n );\n\n if (!field.active) return control;\n return (\n <FieldShell\n label={labelHidden ? null : label}\n controlId={field.controlId}\n description={undefined}\n hintId={undefined}\n error={undefined}\n errorId={undefined}\n >\n {control}\n </FieldShell>\n );\n});\n"],"mappings":"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"}
|
package/dist/select/select.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export declare const selectVariants: (props?: import("class-variance-authority/t
|
|
|
29
29
|
export declare const selectTriggerVariants: (props?: ({
|
|
30
30
|
size?: "sm" | "md" | "lg" | null | undefined;
|
|
31
31
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
32
|
-
export declare const selectPopoverVariants: (props?:
|
|
32
|
+
export declare const selectPopoverVariants: (props?: ({
|
|
33
|
+
reveal?: "fade" | "grow" | null | undefined;
|
|
34
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
33
35
|
export declare const selectItemVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
34
36
|
/**
|
|
35
37
|
* A single-choice picker.
|
package/dist/select/select.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn, cnAll } from "../lib/cn.js";
|
|
3
3
|
import { useIsomorphicLayoutEffect } from "../lib/motion.js";
|
|
4
|
-
import { fieldSurfaceVariants } from "../lib/field-surface.js";
|
|
4
|
+
import { fieldBoxSize, fieldSurfaceVariants, fieldTextSize } from "../lib/field-surface.js";
|
|
5
5
|
import { labelVariants } from "../label/label.js";
|
|
6
6
|
import { RollingValue } from "../lib/rolling-value.js";
|
|
7
7
|
import { cva } from "class-variance-authority";
|
|
@@ -34,10 +34,12 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
34
34
|
* not `accent`, for the same reason.
|
|
35
35
|
*/
|
|
36
36
|
const selectVariants = cva(["group flex w-full flex-col gap-1.5 box-border font-sans"]);
|
|
37
|
+
/** The error line under a Select-based control (Select, TimePicker): one class, so they cannot drift. */
|
|
38
|
+
const selectErrorClass = "text-sm leading-(--leading-normal) text-destructive-strong";
|
|
37
39
|
const selectTriggerVariants = cva([
|
|
38
40
|
"group-data-[invalid]:border-destructive-strong",
|
|
39
41
|
fieldSurfaceVariants(),
|
|
40
|
-
"[&:where([data-pressed])]:border-
|
|
42
|
+
"[&:where([data-pressed])]:border-border-strong",
|
|
41
43
|
"data-[hovered]:not-data-[disabled]:bg-muted",
|
|
42
44
|
"data-[pressed]:bg-muted",
|
|
43
45
|
"group/trigger",
|
|
@@ -61,28 +63,40 @@ const selectTriggerVariants = cva([
|
|
|
61
63
|
* equal to the field beside it.
|
|
62
64
|
*/
|
|
63
65
|
size: {
|
|
64
|
-
sm:
|
|
65
|
-
md:
|
|
66
|
-
lg:
|
|
66
|
+
sm: [fieldBoxSize.sm, fieldTextSize.sm],
|
|
67
|
+
md: [fieldBoxSize.md, fieldTextSize.md],
|
|
68
|
+
lg: [fieldBoxSize.lg, fieldTextSize.lg]
|
|
67
69
|
} },
|
|
68
70
|
defaultVariants: { size: "md" }
|
|
69
71
|
});
|
|
70
72
|
const selectPopoverVariants = cva([
|
|
71
73
|
"w-(--trigger-width) min-w-32 overflow-y-auto",
|
|
72
74
|
"[--menu-x:0px] [--menu-y:-6px] origin-top",
|
|
73
|
-
"
|
|
75
|
+
"[--menu-from:var(--density-control-h-md)] [--menu-flip:0]",
|
|
76
|
+
"data-[placement=top]:[--menu-y:6px] data-[placement=top]:origin-bottom data-[placement=top]:[--menu-flip:1]",
|
|
74
77
|
"data-[placement=left]:[--menu-x:6px] data-[placement=left]:[--menu-y:0px] data-[placement=left]:origin-right",
|
|
75
78
|
"data-[placement=right]:[--menu-x:-6px] data-[placement=right]:[--menu-y:0px] data-[placement=right]:origin-left",
|
|
76
|
-
"motion-
|
|
79
|
+
"motion-reduce:data-[entering]:animate-select-fade-in",
|
|
77
80
|
"motion-safe:data-[exiting]:animate-select-popover-out motion-reduce:data-[exiting]:animate-select-fade-out",
|
|
78
81
|
"data-[exiting]:pointer-events-none",
|
|
79
|
-
"rounded-
|
|
82
|
+
"rounded-panel border-(length:--border-width) border-border p-1",
|
|
80
83
|
"bg-card text-card-foreground shadow-floating",
|
|
81
84
|
"box-border font-sans text-sm leading-(--leading-normal)"
|
|
82
|
-
]
|
|
85
|
+
], {
|
|
86
|
+
variants: {
|
|
87
|
+
/**
|
|
88
|
+
* `grow` opens the panel from the trigger's height on the smooth spring (about 700ms). `fade` is the quick 240ms
|
|
89
|
+
* settle for a list whose first row is a search field: a clipped panel would hide it while it grows.
|
|
90
|
+
*/
|
|
91
|
+
reveal: {
|
|
92
|
+
grow: "motion-safe:data-[entering]:animate-select-popover-reveal",
|
|
93
|
+
fade: "motion-safe:data-[entering]:animate-select-popover-in"
|
|
94
|
+
} },
|
|
95
|
+
defaultVariants: { reveal: "grow" }
|
|
96
|
+
});
|
|
83
97
|
const selectItemVariants = cva([
|
|
84
98
|
"relative flex cursor-pointer select-none items-center gap-2",
|
|
85
|
-
"rounded-
|
|
99
|
+
"rounded-control py-1.5 pe-8 ps-2",
|
|
86
100
|
"box-border text-sm leading-(--leading-normal) text-card-foreground",
|
|
87
101
|
"outline-none data-[focused]:bg-muted",
|
|
88
102
|
"motion-safe:transition-colors motion-safe:duration-(--duration-instant) motion-safe:ease-settle",
|
|
@@ -168,12 +182,12 @@ const Select$1 = forwardRef(function Select$2({ children, label, labelHidden, pl
|
|
|
168
182
|
}),
|
|
169
183
|
errorMessage == null ? null : /* @__PURE__ */ jsx(FieldError, {
|
|
170
184
|
"data-slot": "select-error",
|
|
171
|
-
className:
|
|
185
|
+
className: selectErrorClass,
|
|
172
186
|
children: errorMessage
|
|
173
187
|
}),
|
|
174
188
|
/* @__PURE__ */ jsx(Popover, {
|
|
175
189
|
"data-slot": "select-popover",
|
|
176
|
-
className: selectPopoverVariants(),
|
|
190
|
+
className: cn(selectPopoverVariants(), "border-0"),
|
|
177
191
|
children: /* @__PURE__ */ jsx(ListBox, {
|
|
178
192
|
"data-slot": "select-list",
|
|
179
193
|
className: "outline-none",
|
|
@@ -199,12 +213,12 @@ const SelectItem = forwardRef(function SelectItem({ className, children, textVal
|
|
|
199
213
|
strokeWidth: "2",
|
|
200
214
|
strokeLinecap: "round",
|
|
201
215
|
strokeLinejoin: "round",
|
|
202
|
-
className: "absolute
|
|
216
|
+
className: "absolute end-2 size-3.5 motion-safe:animate-select-check-in",
|
|
203
217
|
children: /* @__PURE__ */ jsx("path", { d: "m3.5 8.5 3 3 6-6" })
|
|
204
218
|
}) : null, children] })
|
|
205
219
|
});
|
|
206
220
|
});
|
|
207
221
|
//#endregion
|
|
208
|
-
export { Select$1 as Select, SelectItem, selectItemVariants, selectPopoverVariants, selectTriggerVariants, selectVariants };
|
|
222
|
+
export { Select$1 as Select, SelectItem, selectErrorClass, selectItemVariants, selectPopoverVariants, selectTriggerVariants, selectVariants };
|
|
209
223
|
|
|
210
224
|
//# sourceMappingURL=select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":["AriaSelectValue","Select","AriaSelect","AriaLabel","AriaButton","AriaFieldError","AriaPopover","AriaListBox","AriaListBoxItem"],"sources":["../../src/select/select.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef, useContext, useState, type ReactNode } from \"react\";\nimport {\n Button as AriaButton,\n FieldError as AriaFieldError,\n Label as AriaLabel,\n ListBox as AriaListBox,\n ListBoxItem as AriaListBoxItem,\n Popover as AriaPopover,\n Select as AriaSelect,\n SelectStateContext,\n SelectValue as AriaSelectValue,\n type ListBoxItemProps as AriaListBoxItemProps,\n type SelectProps as AriaSelectProps,\n} from \"react-aria-components\";\n\nimport { labelVariants } from \"../label/label.js\";\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { fieldSurfaceVariants } from \"../lib/field-surface.js\";\nimport { useIsomorphicLayoutEffect } from \"../lib/motion.js\";\nimport { RollingValue } from \"../lib/rolling-value.js\";\n\n/**\n * Select, ported from the legacy shadcn/Radix component.\n *\n * FOUR PARTS COLLAPSE INTO ONE. The census reads `SelectItem` 35 and\n * `Select`, `SelectTrigger`, `SelectValue`, `SelectContent` 15 each --\n * those four always appear together in the same shape, exactly like\n * Dialog's header trio, so they are one component and a prop.\n * `SelectGroup`, `SelectLabel`, `SelectSeparator`, `SelectScrollUpButton`\n * and `SelectScrollDownButton` have ZERO call sites and are not ported.\n *\n * `label` IS REQUIRED. The legacy exports a `SelectLabel` that nobody\n * renders and passes no `aria-label` anywhere, so all 15 selects are\n * unnamed comboboxes -- the same finding as Progress, Slider and\n * ScrollArea. Pass `labelHidden` when the surrounding UI already says it.\n *\n * The trigger reuses `fieldSurfaceVariants`, shared with Input and\n * Textarea. A select and a text field sit in the same form row and must\n * be the same box; the legacy styled them separately and drifted --\n * `h-10` here against Input's `h-9`, for no stated reason.\n *\n * The popover is `card`, not a `popover` role: `--popover` is\n * byte-identical to `--card` in the legacy theme. Item hover is `muted`,\n * not `accent`, for the same reason.\n */\n/*\n * `group` is load-bearing, not decoration. React Aria puts `data-invalid` on\n * THIS element, never on the trigger -- so the trigger's own\n * `data-[invalid]:` rule, inherited from the shared field surface, can never\n * match and `isInvalid` painted nothing at all. The trigger reads the state\n * from here instead.\n */\nexport const selectVariants = cva([\"group flex w-full flex-col gap-1.5 box-border font-sans\"]);\n\nexport const selectTriggerVariants = cva(\n [\n // See selectVariants: the invalid state lives on the ROOT, so this reads it\n // from the group rather than from itself.\n \"group-data-[invalid]:border-destructive-strong\",\n fieldSurfaceVariants(),\n // While the menu is open the trigger is pressed and focus has moved into the\n // list, so the border keeps the darkness it had instead of falling back.\n \"[&:where([data-pressed])]:border-foreground\",\n // The fill follows the border: hovered, pressed and open all read as one\n // state. Ordinary variants, not :where(): the base background is a plain\n // class, so a zero-specificity rule would lose to it. Nothing else paints\n // the background, and a disabled trigger is never hovered or pressed.\n \"data-[hovered]:not-data-[disabled]:bg-muted\",\n \"data-[pressed]:bg-muted\",\n \"group/trigger\",\n \"flex items-center justify-between gap-2 text-start\",\n \"leading-(--leading-normal) cursor-pointer\",\n \"[&_svg]:pointer-events-none [&_svg]:shrink-0\",\n \"[&_svg:not([class*='size-'])]:size-(--icon-sm)\",\n ],\n {\n variants: {\n /**\n * The same rungs and the same tokens as Input and Button. 14 of the\n * product's 32 `SelectTrigger` call sites override the height by hand,\n * and a Select sits in the same form row as a field -- giving Input the\n * axis without giving it here would be exactly the drift\n * `fieldSurfaceVariants` exists to prevent.\n *\n * Type matches Input's at every rung: 14px on `sm` (16px on a touch\n * screen), 16px on `md` and `lg`. A row whose two controls disagree\n * about type size reads as a mistake. The trigger is a button, so iOS\n * would not zoom on it; the coarse-pointer rule is there to keep it\n * equal to the field beside it.\n */\n size: {\n sm: \"h-(--density-control-h-sm) px-(--density-control-pad-sm) text-sm pointer-coarse:text-base\",\n md: \"h-(--density-control-h-md) px-(--density-control-pad-md) text-base\",\n lg: \"h-(--density-control-h-lg) px-(--density-control-pad-lg) text-base\",\n },\n },\n defaultVariants: { size: \"md\" },\n },\n);\n\nexport const selectPopoverVariants = cva([\n // --trigger-width is set inline by React Aria, so the list matches the\n // control it came from rather than guessing a width.\n \"w-(--trigger-width) min-w-32 overflow-y-auto\",\n // Grows from the trigger edge: offset toward it and a little small, 240ms in,\n // 120ms out. React Aria marks the first frame data-entering and the leaving\n // one data-exiting and keeps the list mounted until the animation ends.\n \"[--menu-x:0px] [--menu-y:-6px] origin-top\",\n \"data-[placement=top]:[--menu-y:6px] data-[placement=top]:origin-bottom\",\n \"data-[placement=left]:[--menu-x:6px] data-[placement=left]:[--menu-y:0px] data-[placement=left]:origin-right\",\n \"data-[placement=right]:[--menu-x:-6px] data-[placement=right]:[--menu-y:0px] data-[placement=right]:origin-left\",\n \"motion-safe:data-[entering]:animate-select-popover-in motion-reduce:data-[entering]:animate-select-fade-in\",\n \"motion-safe:data-[exiting]:animate-select-popover-out motion-reduce:data-[exiting]:animate-select-fade-out\",\n \"data-[exiting]:pointer-events-none\",\n \"rounded-md border-(length:--border-width) border-border p-1\",\n \"bg-card text-card-foreground shadow-floating\",\n \"box-border font-sans text-sm leading-(--leading-normal)\",\n]);\n\nexport const selectItemVariants = cva([\n \"relative flex cursor-pointer select-none items-center gap-2\",\n \"rounded-2xs py-1.5 pe-2 ps-8\",\n \"box-border text-sm leading-(--leading-normal) text-card-foreground\",\n // data-focused, not :hover. React Aria drives one highlight from both\n // pointer and keyboard, so the row under the mouse and the row the\n // arrows reached are the same row.\n \"outline-none data-[focused]:bg-muted\",\n \"motion-safe:transition-colors motion-safe:duration-(--duration-instant) motion-safe:ease-settle\",\n \"data-[focus-visible]:outline-solid\",\n \"data-[focus-visible]:outline-(length:--focus-ring-width)\",\n \"data-[focus-visible]:outline-offset-(--focus-ring-offset)\",\n \"data-[focus-visible]:outline-(--color-ring)\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-(--opacity-disabled)\",\n]);\n\n/**\n * A single-choice picker.\n *\n * @example\n * <Select label=\"Country\" placeholder=\"Pick one\"\n * selectedKey={code} onSelectionChange={setCode}>\n * <SelectItem id=\"gb\">United Kingdom</SelectItem>\n * <SelectItem id=\"us\">United States</SelectItem>\n * </Select>\n */\nexport interface SelectProps extends Omit<\n AriaSelectProps<object>,\n \"className\" | \"style\" | \"children\" | \"items\"\n> {\n /** `SelectItem` children. */\n children?: ReactNode;\n /**\n * What is being chosen, and the control's accessible name.\n *\n * **Required.** All 15 legacy selects are unnamed: the legacy exports a\n * `SelectLabel` that nobody renders and passes no `aria-label`.\n */\n label: ReactNode;\n /** Render the label for screen readers only. */\n labelHidden?: boolean;\n /** Shown while nothing is selected. */\n placeholder?: string;\n /**\n * Why the selection is wrong. Rendered under the control, and it is what\n * makes `isInvalid` reach a screen reader.\n *\n * React Aria marks the ROOT `data-invalid` and leaves the button untouched,\n * and an `aria-invalid` handed to that button is dropped by\n * `filterDOMProps`, whose allowlist stops at the labelling attributes -- the\n * same silent loss as `aria-current` on a pagination button. So without a\n * message, an invalid select is invalid only in colour, which is WCAG 1.4.1\n * on its own. React Aria wires this into `aria-describedby` for us.\n */\n errorMessage?: ReactNode;\n /**\n * Control scale of the trigger. Height and inline padding come from the\n * same `--density-control-*` tokens as Input and Button, so a Select, a\n * field and a button on one rung are the same height.\n *\n * Type does not scale with it, matching Input.\n *\n * @default \"md\"\n */\n size?: \"sm\" | \"md\" | \"lg\";\n /** Extra classes for the wrapper. Merged last. */\n className?: string;\n}\n\n/**\n * The shown value. React Aria's own `SelectValue` stays, visually hidden, as the\n * text a screen reader reads; the copy the eye sees rolls when the selection\n * changes: a later option rises from below, an earlier one drops from above. The\n * direction is read from the option's place in the list. A pre-selected value\n * does not animate on first mount.\n */\nfunction ValueRoll({ placeholder }: { placeholder?: string }) {\n const state = useContext(SelectStateContext);\n const key = state?.selectedKey ?? null;\n let index = -1;\n if (state && key != null) {\n let n = 0;\n for (const item of state.collection) {\n if (item.type !== \"item\") continue;\n if (item.key === key) index = n;\n n += 1;\n }\n }\n const [previous, setPrevious] = useState(index);\n const [dir, setDir] = useState(1);\n if (previous !== index) {\n setPrevious(index);\n setDir(index > previous ? 1 : -1);\n }\n const text = state?.selectedItem?.textValue ?? \"\";\n // React Aria resolves a default selection after the first render, so the key\n // starts as null and then settles. Until the collection is built nothing is\n // shown, and the swap remounts once it is, so that settling is not a change.\n const built = (state?.collection.size ?? 0) > 0 || state?.selectedKey != null;\n const [mounted, setMounted] = useState(false);\n useIsomorphicLayoutEffect(() => setMounted(true), []);\n const settled = built || mounted;\n const swapKey = key == null ? \"placeholder\" : `value-${String(key)}`;\n return (\n <RollingValue\n srValue={\n <AriaSelectValue data-slot=\"select-value\" className=\"sr-only\">\n {({ isPlaceholder, selectedText }) => (isPlaceholder ? placeholder : selectedText)}\n </AriaSelectValue>\n }\n swapKey={swapKey}\n dir={dir}\n instanceKey={settled ? \"live\" : \"boot\"}\n >\n {key == null ? (\n <span data-slot=\"select-placeholder\" className=\"text-muted-foreground\">\n {placeholder}\n </span>\n ) : (\n text\n )}\n </RollingValue>\n );\n}\n\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n { children, label, labelHidden, placeholder, errorMessage, size = \"md\", className, ...props },\n ref,\n) {\n return (\n <AriaSelect {...props} data-slot=\"select\" className={cn(selectVariants(), className)}>\n {/*\n The Label's own classes, so a Select's label and the Label over an\n Input in the same form are one style (same size, weight, colour and\n line height). The select-label slot stays for consumers that target it.\n */}\n <AriaLabel\n data-slot=\"select-label\"\n className={cnAll(labelVariants(), labelHidden && \"sr-only\")}\n >\n {label}\n </AriaLabel>\n\n {/*\n The ref goes on the TRIGGER, not the AriaSelect root above. The root\n is a field-level wrapper div; the trigger is the always-visible\n interactive surface a caller actually wants to focus or click,\n the same reasoning that puts Input's ref on the real control.\n */}\n <AriaButton ref={ref} data-slot=\"select-trigger\" className={selectTriggerVariants({ size })}>\n <ValueRoll placeholder={placeholder} />\n {/*\n aria-hidden: the chevron is decoration. The button already\n announces itself as a combobox, and a second name source only\n makes it announce twice.\n */}\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180\"\n >\n <path d=\"m4 6 4 4 4-4\" />\n </svg>\n </AriaButton>\n\n {errorMessage == null ? null : (\n // Not conditional on isInvalid: React Aria renders FieldError only\n // while the field IS invalid, so gating it here as well would just be\n // two sources of truth for one state.\n <AriaFieldError\n data-slot=\"select-error\"\n className=\"text-sm leading-(--leading-normal) text-destructive-strong\"\n >\n {errorMessage}\n </AriaFieldError>\n )}\n\n <AriaPopover data-slot=\"select-popover\" className={selectPopoverVariants()}>\n <AriaListBox data-slot=\"select-list\" className=\"outline-none\">\n {children}\n </AriaListBox>\n </AriaPopover>\n </AriaSelect>\n );\n});\n\n/**\n * One option. Its `id` is the value.\n *\n * @example\n * <SelectItem id=\"gb\">United Kingdom</SelectItem>\n */\nexport interface SelectItemProps extends Omit<\n AriaListBoxItemProps,\n \"className\" | \"style\" | \"children\"\n> {\n children?: ReactNode;\n /**\n * The option's text, for the trigger and for typeahead.\n *\n * Derived from `children` when they are a string. Pass it explicitly\n * when the option renders anything richer than text.\n */\n textValue?: string;\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\nexport const SelectItem = forwardRef<HTMLDivElement, SelectItemProps>(function SelectItem(\n { className, children, textValue, ...props },\n ref,\n) {\n return (\n <AriaListBoxItem\n ref={ref}\n {...props}\n /*\n textValue, derived from string children.\n React Aria infers an item's text from its children -- but ONLY\n when they are a string. This item uses FUNCTION children so the\n tick can be rendered in JS, which defeats that inference: the\n trigger showed an empty value after selecting, and typeahead had\n nothing to match on. Neither is visible in the type system.\n */\n textValue={textValue ?? (typeof children === \"string\" ? children : undefined)}\n data-slot=\"select-item\"\n className={cn(selectItemVariants(), className)}\n >\n {({ isSelected }) => (\n <>\n {/*\n The tick is rendered in JS rather than toggled with CSS, so\n the precedence is explicit and a test can read it from the\n DOM. ps-8 above reserves the gutter, so selecting an option\n does not shift its label.\n */}\n {isSelected ? (\n <svg\n data-slot=\"select-item-check\"\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"absolute start-2 size-3.5 motion-safe:animate-select-check-in\"\n >\n <path d=\"m3.5 8.5 3 3 6-6\" />\n </svg>\n ) : null}\n {children}\n </>\n )}\n </AriaListBoxItem>\n );\n});\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"select.js","names":["AriaSelectValue","Select","AriaSelect","AriaLabel","AriaButton","AriaFieldError","AriaPopover","AriaListBox","AriaListBoxItem"],"sources":["../../src/select/select.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef, useContext, useState, type ReactNode } from \"react\";\nimport {\n Button as AriaButton,\n FieldError as AriaFieldError,\n Label as AriaLabel,\n ListBox as AriaListBox,\n ListBoxItem as AriaListBoxItem,\n Popover as AriaPopover,\n Select as AriaSelect,\n SelectStateContext,\n SelectValue as AriaSelectValue,\n type ListBoxItemProps as AriaListBoxItemProps,\n type SelectProps as AriaSelectProps,\n} from \"react-aria-components\";\n\nimport { labelVariants } from \"../label/label.js\";\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { fieldBoxSize, fieldSurfaceVariants, fieldTextSize } from \"../lib/field-surface.js\";\nimport { useIsomorphicLayoutEffect } from \"../lib/motion.js\";\nimport { RollingValue } from \"../lib/rolling-value.js\";\n\n/**\n * Select, ported from the legacy shadcn/Radix component.\n *\n * FOUR PARTS COLLAPSE INTO ONE. The census reads `SelectItem` 35 and\n * `Select`, `SelectTrigger`, `SelectValue`, `SelectContent` 15 each --\n * those four always appear together in the same shape, exactly like\n * Dialog's header trio, so they are one component and a prop.\n * `SelectGroup`, `SelectLabel`, `SelectSeparator`, `SelectScrollUpButton`\n * and `SelectScrollDownButton` have ZERO call sites and are not ported.\n *\n * `label` IS REQUIRED. The legacy exports a `SelectLabel` that nobody\n * renders and passes no `aria-label` anywhere, so all 15 selects are\n * unnamed comboboxes -- the same finding as Progress, Slider and\n * ScrollArea. Pass `labelHidden` when the surrounding UI already says it.\n *\n * The trigger reuses `fieldSurfaceVariants`, shared with Input and\n * Textarea. A select and a text field sit in the same form row and must\n * be the same box; the legacy styled them separately and drifted --\n * `h-10` here against Input's `h-9`, for no stated reason.\n *\n * The popover is `card`, not a `popover` role: `--popover` is\n * byte-identical to `--card` in the legacy theme. Item hover is `muted`,\n * not `accent`, for the same reason.\n */\n/*\n * `group` is load-bearing, not decoration. React Aria puts `data-invalid` on\n * THIS element, never on the trigger -- so the trigger's own\n * `data-[invalid]:` rule, inherited from the shared field surface, can never\n * match and `isInvalid` painted nothing at all. The trigger reads the state\n * from here instead.\n */\nexport const selectVariants = cva([\"group flex w-full flex-col gap-1.5 box-border font-sans\"]);\n\n/** The error line under a Select-based control (Select, TimePicker): one class, so they cannot drift. */\nexport const selectErrorClass = \"text-sm leading-(--leading-normal) text-destructive-strong\";\n\nexport const selectTriggerVariants = cva(\n [\n // See selectVariants: the invalid state lives on the ROOT, so this reads it\n // from the group rather than from itself.\n \"group-data-[invalid]:border-destructive-strong\",\n fieldSurfaceVariants(),\n // While the menu is open the trigger is pressed and focus has moved into the\n // list, so the border keeps the darkness it had instead of falling back.\n \"[&:where([data-pressed])]:border-border-strong\",\n // The fill follows the border: hovered, pressed and open all read as one\n // state. Ordinary variants, not :where(): the base background is a plain\n // class, so a zero-specificity rule would lose to it. Nothing else paints\n // the background, and a disabled trigger is never hovered or pressed.\n \"data-[hovered]:not-data-[disabled]:bg-muted\",\n \"data-[pressed]:bg-muted\",\n \"group/trigger\",\n \"flex items-center justify-between gap-2 text-start\",\n \"leading-(--leading-normal) cursor-pointer\",\n \"[&_svg]:pointer-events-none [&_svg]:shrink-0\",\n \"[&_svg:not([class*='size-'])]:size-(--icon-sm)\",\n ],\n {\n variants: {\n /**\n * The same rungs and the same tokens as Input and Button. 14 of the\n * product's 32 `SelectTrigger` call sites override the height by hand,\n * and a Select sits in the same form row as a field -- giving Input the\n * axis without giving it here would be exactly the drift\n * `fieldSurfaceVariants` exists to prevent.\n *\n * Type matches Input's at every rung: 14px on `sm` (16px on a touch\n * screen), 16px on `md` and `lg`. A row whose two controls disagree\n * about type size reads as a mistake. The trigger is a button, so iOS\n * would not zoom on it; the coarse-pointer rule is there to keep it\n * equal to the field beside it.\n */\n size: {\n sm: [fieldBoxSize.sm, fieldTextSize.sm],\n md: [fieldBoxSize.md, fieldTextSize.md],\n lg: [fieldBoxSize.lg, fieldTextSize.lg],\n },\n },\n defaultVariants: { size: \"md\" },\n },\n);\n\nexport const selectPopoverVariants = cva(\n [\n // --trigger-width is set inline by React Aria, so the list matches the\n // control it came from rather than guessing a width.\n \"w-(--trigger-width) min-w-32 overflow-y-auto\",\n // Grows from the trigger edge: offset toward it, a little small and clipped to\n // the trigger's height, then opening to full height; 120ms out. React Aria\n // marks the first frame data-entering and the leaving one data-exiting and\n // keeps the list mounted until the animation ends.\n \"[--menu-x:0px] [--menu-y:-6px] origin-top\",\n // The panel also GROWS from the trigger's height: --menu-from is where the clip\n // starts, --menu-flip 1 grows it from the bottom edge when it opens upward.\n \"[--menu-from:var(--density-control-h-md)] [--menu-flip:0]\",\n \"data-[placement=top]:[--menu-y:6px] data-[placement=top]:origin-bottom data-[placement=top]:[--menu-flip:1]\",\n \"data-[placement=left]:[--menu-x:6px] data-[placement=left]:[--menu-y:0px] data-[placement=left]:origin-right\",\n \"data-[placement=right]:[--menu-x:-6px] data-[placement=right]:[--menu-y:0px] data-[placement=right]:origin-left\",\n \"motion-reduce:data-[entering]:animate-select-fade-in\",\n \"motion-safe:data-[exiting]:animate-select-popover-out motion-reduce:data-[exiting]:animate-select-fade-out\",\n \"data-[exiting]:pointer-events-none\",\n \"rounded-panel border-(length:--border-width) border-border p-1\",\n \"bg-card text-card-foreground shadow-floating\",\n \"box-border font-sans text-sm leading-(--leading-normal)\",\n ],\n {\n variants: {\n /**\n * `grow` opens the panel from the trigger's height on the smooth spring (about 700ms). `fade` is the quick 240ms\n * settle for a list whose first row is a search field: a clipped panel would hide it while it grows.\n */\n reveal: {\n grow: \"motion-safe:data-[entering]:animate-select-popover-reveal\",\n fade: \"motion-safe:data-[entering]:animate-select-popover-in\",\n },\n },\n defaultVariants: { reveal: \"grow\" },\n },\n);\n\nexport const selectItemVariants = cva([\n \"relative flex cursor-pointer select-none items-center gap-2\",\n // The same 18px as a Menu row: the hover fill is a soft pill inside the panel.\n \"rounded-control py-1.5 pe-8 ps-2\",\n \"box-border text-sm leading-(--leading-normal) text-card-foreground\",\n // data-focused, not :hover. React Aria drives one highlight from both\n // pointer and keyboard, so the row under the mouse and the row the\n // arrows reached are the same row.\n \"outline-none data-[focused]:bg-muted\",\n \"motion-safe:transition-colors motion-safe:duration-(--duration-instant) motion-safe:ease-settle\",\n \"data-[focus-visible]:outline-solid\",\n \"data-[focus-visible]:outline-(length:--focus-ring-width)\",\n \"data-[focus-visible]:outline-offset-(--focus-ring-offset)\",\n \"data-[focus-visible]:outline-(--color-ring)\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-(--opacity-disabled)\",\n]);\n\n/**\n * A single-choice picker.\n *\n * @example\n * <Select label=\"Country\" placeholder=\"Pick one\"\n * selectedKey={code} onSelectionChange={setCode}>\n * <SelectItem id=\"gb\">United Kingdom</SelectItem>\n * <SelectItem id=\"us\">United States</SelectItem>\n * </Select>\n */\nexport interface SelectProps extends Omit<\n AriaSelectProps<object>,\n \"className\" | \"style\" | \"children\" | \"items\"\n> {\n /** `SelectItem` children. */\n children?: ReactNode;\n /**\n * What is being chosen, and the control's accessible name.\n *\n * **Required.** All 15 legacy selects are unnamed: the legacy exports a\n * `SelectLabel` that nobody renders and passes no `aria-label`.\n */\n label: ReactNode;\n /** Render the label for screen readers only. */\n labelHidden?: boolean;\n /** Shown while nothing is selected. */\n placeholder?: string;\n /**\n * Why the selection is wrong. Rendered under the control, and it is what\n * makes `isInvalid` reach a screen reader.\n *\n * React Aria marks the ROOT `data-invalid` and leaves the button untouched,\n * and an `aria-invalid` handed to that button is dropped by\n * `filterDOMProps`, whose allowlist stops at the labelling attributes -- the\n * same silent loss as `aria-current` on a pagination button. So without a\n * message, an invalid select is invalid only in colour, which is WCAG 1.4.1\n * on its own. React Aria wires this into `aria-describedby` for us.\n */\n errorMessage?: ReactNode;\n /**\n * Control scale of the trigger. Height and inline padding come from the\n * same `--density-control-*` tokens as Input and Button, so a Select, a\n * field and a button on one rung are the same height.\n *\n * Type does not scale with it, matching Input.\n *\n * @default \"md\"\n */\n size?: \"sm\" | \"md\" | \"lg\";\n /** Extra classes for the wrapper. Merged last. */\n className?: string;\n}\n\n/**\n * The shown value. React Aria's own `SelectValue` stays, visually hidden, as the\n * text a screen reader reads; the copy the eye sees rolls when the selection\n * changes: a later option rises from below, an earlier one drops from above. The\n * direction is read from the option's place in the list. A pre-selected value\n * does not animate on first mount.\n */\nfunction ValueRoll({ placeholder }: { placeholder?: string }) {\n const state = useContext(SelectStateContext);\n const key = state?.selectedKey ?? null;\n let index = -1;\n if (state && key != null) {\n let n = 0;\n for (const item of state.collection) {\n if (item.type !== \"item\") continue;\n if (item.key === key) index = n;\n n += 1;\n }\n }\n const [previous, setPrevious] = useState(index);\n const [dir, setDir] = useState(1);\n if (previous !== index) {\n setPrevious(index);\n setDir(index > previous ? 1 : -1);\n }\n const text = state?.selectedItem?.textValue ?? \"\";\n // React Aria resolves a default selection after the first render, so the key\n // starts as null and then settles. Until the collection is built nothing is\n // shown, and the swap remounts once it is, so that settling is not a change.\n const built = (state?.collection.size ?? 0) > 0 || state?.selectedKey != null;\n const [mounted, setMounted] = useState(false);\n useIsomorphicLayoutEffect(() => setMounted(true), []);\n const settled = built || mounted;\n const swapKey = key == null ? \"placeholder\" : `value-${String(key)}`;\n return (\n <RollingValue\n srValue={\n <AriaSelectValue data-slot=\"select-value\" className=\"sr-only\">\n {({ isPlaceholder, selectedText }) => (isPlaceholder ? placeholder : selectedText)}\n </AriaSelectValue>\n }\n swapKey={swapKey}\n dir={dir}\n instanceKey={settled ? \"live\" : \"boot\"}\n >\n {key == null ? (\n <span data-slot=\"select-placeholder\" className=\"text-muted-foreground\">\n {placeholder}\n </span>\n ) : (\n text\n )}\n </RollingValue>\n );\n}\n\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n { children, label, labelHidden, placeholder, errorMessage, size = \"md\", className, ...props },\n ref,\n) {\n return (\n <AriaSelect {...props} data-slot=\"select\" className={cn(selectVariants(), className)}>\n {/*\n The Label's own classes, so a Select's label and the Label over an\n Input in the same form are one style (same size, weight, colour and\n line height). The select-label slot stays for consumers that target it.\n */}\n <AriaLabel\n data-slot=\"select-label\"\n className={cnAll(labelVariants(), labelHidden && \"sr-only\")}\n >\n {label}\n </AriaLabel>\n\n {/*\n The ref goes on the TRIGGER, not the AriaSelect root above. The root\n is a field-level wrapper div; the trigger is the always-visible\n interactive surface a caller actually wants to focus or click,\n the same reasoning that puts Input's ref on the real control.\n */}\n <AriaButton ref={ref} data-slot=\"select-trigger\" className={selectTriggerVariants({ size })}>\n <ValueRoll placeholder={placeholder} />\n {/*\n aria-hidden: the chevron is decoration. The button already\n announces itself as a combobox, and a second name source only\n makes it announce twice.\n */}\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180\"\n >\n <path d=\"m4 6 4 4 4-4\" />\n </svg>\n </AriaButton>\n\n {errorMessage == null ? null : (\n // Not conditional on isInvalid: React Aria renders FieldError only\n // while the field IS invalid, so gating it here as well would just be\n // two sources of truth for one state.\n <AriaFieldError data-slot=\"select-error\" className={selectErrorClass}>\n {errorMessage}\n </AriaFieldError>\n )}\n\n {/* No border colour on the list: it is lifted by its shadow alone. */}\n <AriaPopover\n data-slot=\"select-popover\"\n className={cn(selectPopoverVariants(), \"border-0\")}\n >\n <AriaListBox data-slot=\"select-list\" className=\"outline-none\">\n {children}\n </AriaListBox>\n </AriaPopover>\n </AriaSelect>\n );\n});\n\n/**\n * One option. Its `id` is the value.\n *\n * @example\n * <SelectItem id=\"gb\">United Kingdom</SelectItem>\n */\nexport interface SelectItemProps extends Omit<\n AriaListBoxItemProps,\n \"className\" | \"style\" | \"children\"\n> {\n children?: ReactNode;\n /**\n * The option's text, for the trigger and for typeahead.\n *\n * Derived from `children` when they are a string. Pass it explicitly\n * when the option renders anything richer than text.\n */\n textValue?: string;\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\nexport const SelectItem = forwardRef<HTMLDivElement, SelectItemProps>(function SelectItem(\n { className, children, textValue, ...props },\n ref,\n) {\n return (\n <AriaListBoxItem\n ref={ref}\n {...props}\n /*\n textValue, derived from string children.\n React Aria infers an item's text from its children -- but ONLY\n when they are a string. This item uses FUNCTION children so the\n tick can be rendered in JS, which defeats that inference: the\n trigger showed an empty value after selecting, and typeahead had\n nothing to match on. Neither is visible in the type system.\n */\n textValue={textValue ?? (typeof children === \"string\" ? children : undefined)}\n data-slot=\"select-item\"\n className={cn(selectItemVariants(), className)}\n >\n {({ isSelected }) => (\n <>\n {/*\n The tick is rendered in JS rather than toggled with CSS, so\n the precedence is explicit and a test can read it from the\n DOM. ps-8 above reserves the gutter, so selecting an option\n does not shift its label.\n */}\n {isSelected ? (\n <svg\n data-slot=\"select-item-check\"\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"absolute end-2 size-3.5 motion-safe:animate-select-check-in\"\n >\n <path d=\"m3.5 8.5 3 3 6-6\" />\n </svg>\n ) : null}\n {children}\n </>\n )}\n </AriaListBoxItem>\n );\n});\n"],"mappings":"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"}
|
|
@@ -6,22 +6,25 @@ import { SeparatorProps } from "react-aria-components";
|
|
|
6
6
|
* Census: 7 files, 6 uses, one of them `orientation="vertical"`. No other
|
|
7
7
|
* prop is ever passed.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
9
|
+
* The legacy defaulted to `decorative: true` and therefore rendered
|
|
10
|
+
* `role="none"`, so every divider in the app was invisible to assistive
|
|
11
|
+
* technology. Here the default is the opposite, which is worth saying out
|
|
12
|
+
* loud rather than burying: React Aria renders an `<hr>` for a horizontal
|
|
13
|
+
* separator, whose implicit role IS separator. A visible line between two
|
|
14
|
+
* groups of content is a separator; announcing it is the correct behaviour.
|
|
15
|
+
*
|
|
16
|
+
* `decorative` is the opt-in for the other case: a rule between inline
|
|
17
|
+
* metadata ("12 posts | 3 drafts") that only spaces items, where announcing
|
|
18
|
+
* "separator" between every pair is noise. React Aria has no equivalent and
|
|
19
|
+
* its Separator always carries a separator role, so a decorative one is a
|
|
20
|
+
* plain `aria-hidden` div drawn with the same classes.
|
|
18
21
|
*
|
|
19
22
|
* Every string in the cva blocks below is a STATIC literal. Tailwind scans
|
|
20
23
|
* source text, so a class assembled at runtime is invisible to it and would
|
|
21
24
|
* simply never be emitted.
|
|
22
25
|
*/
|
|
23
26
|
export declare const separatorVariants: (props?: ({
|
|
24
|
-
orientation?: "
|
|
27
|
+
orientation?: "vertical" | "horizontal" | null | undefined;
|
|
25
28
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
26
29
|
/**
|
|
27
30
|
* A visual divider between two groups of content.
|
|
@@ -33,6 +36,15 @@ export declare const separatorVariants: (props?: ({
|
|
|
33
36
|
interface SeparatorProps$1 extends Omit<SeparatorProps, "className" | "style"> {
|
|
34
37
|
/** @default "horizontal" */
|
|
35
38
|
orientation?: "horizontal" | "vertical";
|
|
39
|
+
/**
|
|
40
|
+
* Draw the line without announcing it: a plain `div` with
|
|
41
|
+
* `aria-hidden="true"` instead of a separator. For a rule that only spaces
|
|
42
|
+
* inline items (metadata, breadcrumbs-like rows), where a screen reader
|
|
43
|
+
* saying "separator" between each pair is noise. Leave it off for a line
|
|
44
|
+
* between two groups of content.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
decorative?: boolean;
|
|
36
48
|
/** Extra classes. Merged last, so they win conflicts with ours. */
|
|
37
49
|
className?: string;
|
|
38
50
|
}
|
|
@@ -11,22 +11,25 @@ import { jsx } from "react/jsx-runtime";
|
|
|
11
11
|
* Census: 7 files, 6 uses, one of them `orientation="vertical"`. No other
|
|
12
12
|
* prop is ever passed.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
14
|
+
* The legacy defaulted to `decorative: true` and therefore rendered
|
|
15
|
+
* `role="none"`, so every divider in the app was invisible to assistive
|
|
16
|
+
* technology. Here the default is the opposite, which is worth saying out
|
|
17
|
+
* loud rather than burying: React Aria renders an `<hr>` for a horizontal
|
|
18
|
+
* separator, whose implicit role IS separator. A visible line between two
|
|
19
|
+
* groups of content is a separator; announcing it is the correct behaviour.
|
|
20
|
+
*
|
|
21
|
+
* `decorative` is the opt-in for the other case: a rule between inline
|
|
22
|
+
* metadata ("12 posts | 3 drafts") that only spaces items, where announcing
|
|
23
|
+
* "separator" between every pair is noise. React Aria has no equivalent and
|
|
24
|
+
* its Separator always carries a separator role, so a decorative one is a
|
|
25
|
+
* plain `aria-hidden` div drawn with the same classes.
|
|
23
26
|
*
|
|
24
27
|
* Every string in the cva blocks below is a STATIC literal. Tailwind scans
|
|
25
28
|
* source text, so a class assembled at runtime is invisible to it and would
|
|
26
29
|
* simply never be emitted.
|
|
27
30
|
*/
|
|
28
31
|
const separatorVariants = cva([
|
|
29
|
-
"shrink-0 bg-
|
|
32
|
+
"shrink-0 bg-separator border-none",
|
|
30
33
|
"m-0",
|
|
31
34
|
"box-border"
|
|
32
35
|
], {
|
|
@@ -36,7 +39,26 @@ const separatorVariants = cva([
|
|
|
36
39
|
} },
|
|
37
40
|
defaultVariants: { orientation: "horizontal" }
|
|
38
41
|
});
|
|
39
|
-
|
|
42
|
+
/** Props a decorative separator does not forward to its div (see below). */
|
|
43
|
+
const DECORATIVE_DROPPED = [
|
|
44
|
+
"elementType",
|
|
45
|
+
"slot",
|
|
46
|
+
"render",
|
|
47
|
+
"aria-label",
|
|
48
|
+
"aria-labelledby"
|
|
49
|
+
];
|
|
50
|
+
const Separator$1 = forwardRef(function Separator$2({ className, orientation = "horizontal", decorative = false, ...props }, ref) {
|
|
51
|
+
if (decorative) {
|
|
52
|
+
const rest = { ...props };
|
|
53
|
+
for (const key of DECORATIVE_DROPPED) delete rest[key];
|
|
54
|
+
return /* @__PURE__ */ jsx("div", {
|
|
55
|
+
ref,
|
|
56
|
+
...rest,
|
|
57
|
+
"aria-hidden": "true",
|
|
58
|
+
"data-slot": "separator",
|
|
59
|
+
className: cn(separatorVariants({ orientation }), className)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
40
62
|
return /* @__PURE__ */ jsx(Separator, {
|
|
41
63
|
ref,
|
|
42
64
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"separator.js","names":["Separator","AriaSeparator"],"sources":["../../src/separator/separator.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef } from \"react\";\nimport {\n Separator as AriaSeparator,\n type SeparatorProps as AriaSeparatorProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\n\n/**\n * Separator, ported from the legacy component onto React Aria's Separator.\n *\n * Census: 7 files, 6 uses, one of them `orientation=\"vertical\"`. No other\n * prop is ever passed.\n *\n *
|
|
1
|
+
{"version":3,"file":"separator.js","names":["Separator","AriaSeparator"],"sources":["../../src/separator/separator.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef, type Ref } from \"react\";\nimport {\n Separator as AriaSeparator,\n type SeparatorProps as AriaSeparatorProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\n\n/**\n * Separator, ported from the legacy component onto React Aria's Separator.\n *\n * Census: 7 files, 6 uses, one of them `orientation=\"vertical\"`. No other\n * prop is ever passed.\n *\n * The legacy defaulted to `decorative: true` and therefore rendered\n * `role=\"none\"`, so every divider in the app was invisible to assistive\n * technology. Here the default is the opposite, which is worth saying out\n * loud rather than burying: React Aria renders an `<hr>` for a horizontal\n * separator, whose implicit role IS separator. A visible line between two\n * groups of content is a separator; announcing it is the correct behaviour.\n *\n * `decorative` is the opt-in for the other case: a rule between inline\n * metadata (\"12 posts | 3 drafts\") that only spaces items, where announcing\n * \"separator\" between every pair is noise. React Aria has no equivalent and\n * its Separator always carries a separator role, so a decorative one is a\n * plain `aria-hidden` div drawn with the same classes.\n *\n * Every string in the cva blocks below is a STATIC literal. Tailwind scans\n * source text, so a class assembled at runtime is invisible to it and would\n * simply never be emitted.\n */\nexport const separatorVariants = cva(\n [\n // border-none, not border-0. `border-0` sets the WIDTH to zero but leaves\n // border-style at solid, so the computed style still claims a border that\n // simply measures nothing -- the same bookkeeping the Checkbox parity run\n // turned up on the legacy input. `border-none` says what is true.\n // The separator role, not `border`: `border` is the outline of a card or\n // field, `separator` the hairline between rows and groups inside one.\n \"shrink-0 bg-separator border-none\",\n // The user-agent <hr> ships a block margin and a 1px inset border, and\n // React Aria renders an <hr> for the horizontal case. The reset in\n // @seekalfred/styles is OPT-IN, so a consumer may load none -- unreset,\n // every divider is a grooved double line with space around it.\n \"m-0\",\n \"box-border\",\n ],\n {\n variants: {\n orientation: {\n // h-px / w-px, not the legacy h-[1px] / w-[1px]. Those are bracket\n // values that check:hardcoding rejects, and `px` is a first-class\n // Tailwind step rather than an arbitrary one.\n horizontal: \"h-px w-full\",\n vertical: \"h-full w-px\",\n },\n },\n defaultVariants: { orientation: \"horizontal\" },\n },\n);\n\n/**\n * A visual divider between two groups of content.\n *\n * @example\n * <Separator />\n * <Separator orientation=\"vertical\" />\n */\nexport interface SeparatorProps extends Omit<AriaSeparatorProps, \"className\" | \"style\"> {\n /** @default \"horizontal\" */\n orientation?: \"horizontal\" | \"vertical\";\n /**\n * Draw the line without announcing it: a plain `div` with\n * `aria-hidden=\"true\"` instead of a separator. For a rule that only spaces\n * inline items (metadata, breadcrumbs-like rows), where a screen reader\n * saying \"separator\" between each pair is noise. Leave it off for a line\n * between two groups of content.\n * @default false\n */\n decorative?: boolean;\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\n/** Props a decorative separator does not forward to its div (see below). */\nconst DECORATIVE_DROPPED = [\n \"elementType\",\n \"slot\",\n \"render\",\n \"aria-label\",\n \"aria-labelledby\",\n] as const;\n\nexport const Separator = forwardRef<HTMLElement, SeparatorProps>(function Separator(\n { className, orientation = \"horizontal\", decorative = false, ...props },\n ref,\n) {\n if (decorative) {\n // Everything else the caller passed (id, data-*, handlers, dir...) reaches\n // the div, as it reaches React Aria's Separator below. Dropped: the props\n // that only mean something to React Aria (`elementType`, `slot`, `render`)\n // and a name, which an aria-hidden line has no use for.\n const rest = { ...props };\n for (const key of DECORATIVE_DROPPED) delete rest[key];\n return (\n <div\n ref={ref as Ref<HTMLDivElement>}\n {...(rest as Omit<typeof rest, (typeof DECORATIVE_DROPPED)[number]>)}\n aria-hidden=\"true\"\n data-slot=\"separator\"\n className={cn(separatorVariants({ orientation }), className)}\n />\n );\n }\n return (\n <AriaSeparator\n ref={ref}\n {...props}\n orientation={orientation}\n data-slot=\"separator\"\n className={cn(separatorVariants({ orientation }), className)}\n />\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,oBAAoB,IAC/B;CAOE;CAKA;CACA;AACF,GACA;CACE,UAAU,EACR,aAAa;EAIX,YAAY;EACZ,UAAU;CACZ,EACF;CACA,iBAAiB,EAAE,aAAa,aAAa;AAC/C,CACF;;AA0BA,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;AACF;AAEA,MAAaA,cAAY,WAAwC,SAASA,YACxE,EAAE,WAAW,cAAc,cAAc,aAAa,OAAO,GAAG,SAChE,KACA;CACA,IAAI,YAAY;EAKd,MAAM,OAAO,EAAE,GAAG,MAAM;EACxB,KAAK,MAAM,OAAO,oBAAoB,OAAO,KAAK;EAClD,OACE,oBAAC,OAAD;GACO;GACL,GAAK;GACL,eAAY;GACZ,aAAU;GACV,WAAW,GAAG,kBAAkB,EAAE,YAAY,CAAC,GAAG,SAAS;EAC5D,CAAA;CAEL;CACA,OACE,oBAACC,WAAD;EACO;EACL,GAAI;EACS;EACb,aAAU;EACV,WAAW,GAAG,kBAAkB,EAAE,YAAY,CAAC,GAAG,SAAS;CAC5D,CAAA;AAEL,CAAC"}
|
package/dist/sheet/sheet.js
CHANGED
|
@@ -91,7 +91,8 @@ const Sheet = forwardRef(function Sheet({ side = "right", className, onBack, bac
|
|
|
91
91
|
children: /* @__PURE__ */ jsx(ScrollArea, {
|
|
92
92
|
scrollResetKey,
|
|
93
93
|
label: bodyLabel ?? (typeof title === "string" ? title : ""),
|
|
94
|
-
className:
|
|
94
|
+
className: "min-h-0 flex-1",
|
|
95
|
+
viewportClassName: bodyClassName,
|
|
95
96
|
children
|
|
96
97
|
})
|
|
97
98
|
});
|
package/dist/sheet/sheet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sheet.js","names":[],"sources":["../../src/sheet/sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef } from \"react\";\n\nimport { Button } from \"../button/button.js\";\nimport { cn } from \"../lib/cn.js\";\nimport { Dialog, type DialogProps } from \"../dialog/dialog.js\";\nimport { ScrollArea } from \"../scroll-area/scroll-area.js\";\n\n/**\n * Sheet: a dialog that arrives from an edge.\n *\n * A PRESET over `Dialog`, like `AlertDialog`. The legacy `sheet.tsx` is\n * `@radix-ui/react-dialog` again -- the same import, the same parts, the\n * same close button -- with one prop changing where it sits. Keeping a\n * second copy is how the legacy `dialog.tsx` and `alert-dialog.tsx`\n * drifted, and this is the same file for the third time.\n *\n * Census: 2 files, 3 uses. `side=\"right\"` twice, `side=\"left\"` once, and\n * `className` four times. `SheetHeader`, `SheetFooter`, `SheetTitle`,\n * `SheetDescription` and `SheetClose` are exported by the legacy and used\n * by NOBODY -- so all three sheets in the app render a `role=\"dialog\"`\n * with no title at all. Radix even warns about it in the console.\n *\n * `title` is required here, inherited from Dialog, so that is no longer\n * expressible.\n *\n * `side` is `\"left\" | \"right\"` only. The legacy also offers `\"top\"` and\n * `\"bottom\"`; both have zero call sites, and each is two lines to add the\n * day something needs one.\n *\n * A REAL BUG THE PORT FIXES: the legacy panel is `w-3/4 sm:max-w-sm`, and\n * `sm:max-w-sm` names `--container-sm`, which this repo does not define --\n * so in Alfred it would compile to NOTHING and the sheet would be 75% of\n * the viewport at every width, on a phone and on a 4K monitor alike. The\n * width here is a spacing-scale step that actually resolves.\n *\n * NOT PORTED: the slide-in animation. It comes from tailwindcss-animate,\n * which this repo does not ship. React Aria exposes `data-entering` and\n * `data-exiting`, and `--animate-*` tokens now exist, so it is a small\n * follow-up rather than a blocker.\n */\nexport const sheetOverlayVariants = cva(\"p-0\", {\n variants: {\n // The overlay is a flex box centring the panel. A sheet replaces that\n // centring with an edge alignment rather than positioning the panel\n // absolutely, so the scrim and the panel stay one layout.\n side: {\n left: \"justify-start items-stretch\",\n right: \"justify-end items-stretch\",\n },\n },\n defaultVariants: { side: \"right\" },\n});\n\nexport const sheetPanelVariants = cva(\n [\n // max-w-96 is 384px and RESOLVES. See the note above on sm:max-w-sm.\n \"h-full w-full max-w-96\",\n // Square against the edge it is attached to: a rounded corner flush\n // with the viewport edge reads as a rendering fault.\n \"rounded-none\",\n \"max-h-full overflow-y-auto\",\n ],\n {\n variants: {\n side: {\n left: \"border-y-0 border-s-0\",\n right: \"border-y-0 border-e-0\",\n },\n },\n defaultVariants: { side: \"right\" },\n },\n);\n\n/**\n * A panel that arrives from the side.\n *\n * @example\n * <Sheet isOpen={open} onOpenChange={setOpen} title=\"Filters\">\n * ...\n * </Sheet>\n */\nexport interface SheetProps extends Omit<DialogProps, \"overlayClassName\"> {\n /**\n * Which edge it is attached to.\n *\n * `\"top\"` and `\"bottom\"` exist in the legacy and have zero call sites.\n *\n * @default \"right\"\n */\n side?: \"left\" | \"right\";\n /**\n * Show a back control, and what it does.\n *\n * A side panel that goes a level deeper REPLACES its own contents rather\n * than stacking a second modal on top, so the browser's back affordance and\n * the escape key both do the wrong thing -- they close the whole panel\n * instead of returning one level. The product's own note calls this the\n * thing that \"makes items 119 and 120 one change rather than two\".\n */\n onBack?: () => void;\n /** Accessible name and label for the back control. @default \"Back\" */\n backLabel?: string;\n /**\n * Change this when the panel's contents change, and the body scrolls back\n * to the top.\n *\n * Going a level deeper and landing halfway down the new view is\n * disorienting, and it is the kind of thing every call site forgets --\n * which is why it belongs here rather than in each of them.\n */\n scrollResetKey?: string | number;\n /** Extra classes for the scrolling body region. */\n bodyClassName?: string;\n /**\n * Names the scrolling body region. Defaults to `title` when that is a\n * string, which it is at every call site in the product.\n *\n * The body is a `ScrollArea`, so it is focusable -- a scrollable region that\n * is not reachable by keyboard is WCAG 2.1.1, and axe caught exactly that\n * when this was a plain div. The product's own `SidePanelBody` still is one.\n * A focusable element needs a role and a role needs a name, so this is the\n * only combination that is actually correct.\n */\n bodyLabel?: string;\n}\n\nfunction BackArrowGlyph() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n // Logical, so it points the right way once the panel mirrors in RTL.\n className=\"size-(--icon-sm) rtl:-scale-x-100\"\n >\n <path d=\"M10 3 5 8l5 5\" />\n </svg>\n );\n}\n\nexport const Sheet = forwardRef<HTMLElement, SheetProps>(function Sheet(\n {\n side = \"right\",\n className,\n onBack,\n backLabel = \"Back\",\n scrollResetKey,\n bodyClassName,\n bodyLabel,\n title,\n children,\n ...props\n },\n ref,\n) {\n return (\n /*\n No data-slot here. Dialog spreads its props onto the ModalOverlay and\n writes data-slot=\"dialog-overlay\" AFTER the spread, so a data-slot\n passed from here is overwritten before it reaches the DOM -- it read as\n working while rendering nothing. A sheet is identified by its side\n variant and its panel classes instead.\n */\n <Dialog\n entrance=\"none\"\n {...props}\n ref={ref}\n title={title}\n beforeTitle={\n onBack ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n data-slot=\"sheet-back\"\n className=\"-ms-2 w-fit\"\n startIcon={<BackArrowGlyph />}\n onPress={onBack}\n >\n {backLabel}\n </Button>\n ) : undefined\n }\n overlayClassName={sheetOverlayVariants({ side })}\n className={cn(sheetPanelVariants({ side }), className)}\n >\n {/*\n The scrolling region is its own element so the title and the back\n control stay put while the content moves. A panel that scrolled as one\n block would take its own heading off screen.\n */}\n {/*\n No data-slot=\"sheet-body\" here, for the same reason the overlay has\n none: ScrollArea spreads its props and writes data-slot=\"scroll-area\"\n AFTER the spread, so one passed from here is overwritten before it\n reaches the DOM. It read as wired while selecting nothing.\n */}\n <ScrollArea\n scrollResetKey={scrollResetKey}\n label={bodyLabel ?? (typeof title === \"string\" ? title : \"\")}\n className
|
|
1
|
+
{"version":3,"file":"sheet.js","names":[],"sources":["../../src/sheet/sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef } from \"react\";\n\nimport { Button } from \"../button/button.js\";\nimport { cn } from \"../lib/cn.js\";\nimport { Dialog, type DialogProps } from \"../dialog/dialog.js\";\nimport { ScrollArea } from \"../scroll-area/scroll-area.js\";\n\n/**\n * Sheet: a dialog that arrives from an edge.\n *\n * A PRESET over `Dialog`, like `AlertDialog`. The legacy `sheet.tsx` is\n * `@radix-ui/react-dialog` again -- the same import, the same parts, the\n * same close button -- with one prop changing where it sits. Keeping a\n * second copy is how the legacy `dialog.tsx` and `alert-dialog.tsx`\n * drifted, and this is the same file for the third time.\n *\n * Census: 2 files, 3 uses. `side=\"right\"` twice, `side=\"left\"` once, and\n * `className` four times. `SheetHeader`, `SheetFooter`, `SheetTitle`,\n * `SheetDescription` and `SheetClose` are exported by the legacy and used\n * by NOBODY -- so all three sheets in the app render a `role=\"dialog\"`\n * with no title at all. Radix even warns about it in the console.\n *\n * `title` is required here, inherited from Dialog, so that is no longer\n * expressible.\n *\n * `side` is `\"left\" | \"right\"` only. The legacy also offers `\"top\"` and\n * `\"bottom\"`; both have zero call sites, and each is two lines to add the\n * day something needs one.\n *\n * A REAL BUG THE PORT FIXES: the legacy panel is `w-3/4 sm:max-w-sm`, and\n * `sm:max-w-sm` names `--container-sm`, which this repo does not define --\n * so in Alfred it would compile to NOTHING and the sheet would be 75% of\n * the viewport at every width, on a phone and on a 4K monitor alike. The\n * width here is a spacing-scale step that actually resolves.\n *\n * NOT PORTED: the slide-in animation. It comes from tailwindcss-animate,\n * which this repo does not ship. React Aria exposes `data-entering` and\n * `data-exiting`, and `--animate-*` tokens now exist, so it is a small\n * follow-up rather than a blocker.\n */\nexport const sheetOverlayVariants = cva(\"p-0\", {\n variants: {\n // The overlay is a flex box centring the panel. A sheet replaces that\n // centring with an edge alignment rather than positioning the panel\n // absolutely, so the scrim and the panel stay one layout.\n side: {\n left: \"justify-start items-stretch\",\n right: \"justify-end items-stretch\",\n },\n },\n defaultVariants: { side: \"right\" },\n});\n\nexport const sheetPanelVariants = cva(\n [\n // max-w-96 is 384px and RESOLVES. See the note above on sm:max-w-sm.\n \"h-full w-full max-w-96\",\n // Square against the edge it is attached to: a rounded corner flush\n // with the viewport edge reads as a rendering fault.\n \"rounded-none\",\n \"max-h-full overflow-y-auto\",\n ],\n {\n variants: {\n side: {\n left: \"border-y-0 border-s-0\",\n right: \"border-y-0 border-e-0\",\n },\n },\n defaultVariants: { side: \"right\" },\n },\n);\n\n/**\n * A panel that arrives from the side.\n *\n * @example\n * <Sheet isOpen={open} onOpenChange={setOpen} title=\"Filters\">\n * ...\n * </Sheet>\n */\nexport interface SheetProps extends Omit<DialogProps, \"overlayClassName\"> {\n /**\n * Which edge it is attached to.\n *\n * `\"top\"` and `\"bottom\"` exist in the legacy and have zero call sites.\n *\n * @default \"right\"\n */\n side?: \"left\" | \"right\";\n /**\n * Show a back control, and what it does.\n *\n * A side panel that goes a level deeper REPLACES its own contents rather\n * than stacking a second modal on top, so the browser's back affordance and\n * the escape key both do the wrong thing -- they close the whole panel\n * instead of returning one level. The product's own note calls this the\n * thing that \"makes items 119 and 120 one change rather than two\".\n */\n onBack?: () => void;\n /** Accessible name and label for the back control. @default \"Back\" */\n backLabel?: string;\n /**\n * Change this when the panel's contents change, and the body scrolls back\n * to the top.\n *\n * Going a level deeper and landing halfway down the new view is\n * disorienting, and it is the kind of thing every call site forgets --\n * which is why it belongs here rather than in each of them.\n */\n scrollResetKey?: string | number;\n /** Extra classes for the scrolling body region. */\n bodyClassName?: string;\n /**\n * Names the scrolling body region. Defaults to `title` when that is a\n * string, which it is at every call site in the product.\n *\n * The body is a `ScrollArea`, so it is focusable -- a scrollable region that\n * is not reachable by keyboard is WCAG 2.1.1, and axe caught exactly that\n * when this was a plain div. The product's own `SidePanelBody` still is one.\n * A focusable element needs a role and a role needs a name, so this is the\n * only combination that is actually correct.\n */\n bodyLabel?: string;\n}\n\nfunction BackArrowGlyph() {\n return (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n // Logical, so it points the right way once the panel mirrors in RTL.\n className=\"size-(--icon-sm) rtl:-scale-x-100\"\n >\n <path d=\"M10 3 5 8l5 5\" />\n </svg>\n );\n}\n\nexport const Sheet = forwardRef<HTMLElement, SheetProps>(function Sheet(\n {\n side = \"right\",\n className,\n onBack,\n backLabel = \"Back\",\n scrollResetKey,\n bodyClassName,\n bodyLabel,\n title,\n children,\n ...props\n },\n ref,\n) {\n return (\n /*\n No data-slot here. Dialog spreads its props onto the ModalOverlay and\n writes data-slot=\"dialog-overlay\" AFTER the spread, so a data-slot\n passed from here is overwritten before it reaches the DOM -- it read as\n working while rendering nothing. A sheet is identified by its side\n variant and its panel classes instead.\n */\n <Dialog\n entrance=\"none\"\n {...props}\n ref={ref}\n title={title}\n beforeTitle={\n onBack ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n data-slot=\"sheet-back\"\n className=\"-ms-2 w-fit\"\n startIcon={<BackArrowGlyph />}\n onPress={onBack}\n >\n {backLabel}\n </Button>\n ) : undefined\n }\n overlayClassName={sheetOverlayVariants({ side })}\n className={cn(sheetPanelVariants({ side }), className)}\n >\n {/*\n The scrolling region is its own element so the title and the back\n control stay put while the content moves. A panel that scrolled as one\n block would take its own heading off screen.\n */}\n {/*\n No data-slot=\"sheet-body\" here, for the same reason the overlay has\n none: ScrollArea spreads its props and writes data-slot=\"scroll-area\"\n AFTER the spread, so one passed from here is overwritten before it\n reaches the DOM. It read as wired while selecting nothing.\n */}\n <ScrollArea\n scrollResetKey={scrollResetKey}\n label={bodyLabel ?? (typeof title === \"string\" ? title : \"\")}\n className=\"min-h-0 flex-1\"\n viewportClassName={bodyClassName}\n >\n {children}\n </ScrollArea>\n </Dialog>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,uBAAuB,IAAI,OAAO;CAC7C,UAAU,EAIR,MAAM;EACJ,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EAAE,MAAM,QAAQ;AACnC,CAAC;AAED,MAAa,qBAAqB,IAChC;CAEE;CAGA;CACA;AACF,GACA;CACE,UAAU,EACR,MAAM;EACJ,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EAAE,MAAM,QAAQ;AACnC,CACF;AAuDA,SAAS,iBAAiB;CACxB,OACE,oBAAC,OAAD;EACE,eAAY;EACZ,SAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAY;EACZ,eAAc;EACd,gBAAe;EAEf,WAAU;EAEV,UAAA,oBAAC,QAAD,EAAM,GAAE,gBAAiB,CAAA;CACtB,CAAA;AAET;AAEA,MAAa,QAAQ,WAAoC,SAAS,MAChE,EACE,OAAO,SACP,WACA,QACA,YAAY,QACZ,gBACA,eACA,WACA,OACA,UACA,GAAG,SAEL,KACA;CACA,OAQE,oBAAC,QAAD;EACE,UAAS;EACT,GAAI;EACC;EACE;EACP,aACE,SACE,oBAAC,QAAD;GACE,SAAQ;GACR,MAAK;GACL,aAAU;GACV,WAAU;GACV,WAAW,oBAAC,gBAAD,CAAiB,CAAA;GAC5B,SAAS;GAER,UAAA;EACK,CAAA,IACN,KAAA;EAEN,kBAAkB,qBAAqB,EAAE,KAAK,CAAC;EAC/C,WAAW,GAAG,mBAAmB,EAAE,KAAK,CAAC,GAAG,SAAS;EAarD,UAAA,oBAAC,YAAD;GACkB;GAChB,OAAO,cAAc,OAAO,UAAU,WAAW,QAAQ;GACzD,WAAU;GACV,mBAAmB;GAElB;EACS,CAAA;CACN,CAAA;AAEZ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Platform, ShortcutToken, formatShortcut, matchesShortcut, normalizeShortcut, shortcutFromEvent, shortcutTokens } from "./shortcut-model.js";
|
|
2
|
+
import { ShortcutBinding, ShortcutKbd, ShortcutKbdProps, ShortcutKeys, ShortcutKeysProps, ShortcutRecorder, ShortcutRecorderProps, usePlatform, usePressedKeys } from "./shortcut-recorder.js";
|
|
3
|
+
export { type Platform, type ShortcutBinding, ShortcutKbd, type ShortcutKbdProps, ShortcutKeys, type ShortcutKeysProps, ShortcutRecorder, type ShortcutRecorderProps, type ShortcutToken, formatShortcut, matchesShortcut, normalizeShortcut, shortcutFromEvent, shortcutTokens, usePlatform, usePressedKeys };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { formatShortcut, matchesShortcut, normalizeShortcut, shortcutFromEvent, shortcutTokens } from "./shortcut-model.js";
|
|
2
|
+
import { ShortcutKbd, ShortcutKeys, ShortcutRecorder, usePlatform, usePressedKeys } from "./shortcut-recorder.js";
|
|
3
|
+
export { ShortcutKbd, ShortcutKeys, ShortcutRecorder, formatShortcut, matchesShortcut, normalizeShortcut, shortcutFromEvent, shortcutTokens, usePlatform, usePressedKeys };
|