@behavioral-agentic-design-system/core 0.24.0 → 0.26.0
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/package.json +5 -2
- package/scripts/build-tokens.cjs +79 -5
- package/src/app/preview/components/page.tsx +4474 -208
- package/src/app/shell.tsx +18 -6
- package/src/components/customize/brand-mark-section.tsx +1 -1
- package/src/components/customize-tab.tsx +2 -2
- package/src/components/home-tab.tsx +2 -2
- package/src/components/ui/action-bar.tsx +142 -0
- package/src/components/ui/affix.tsx +109 -0
- package/src/components/ui/alert.tsx +37 -3
- package/src/components/ui/anchor.tsx +136 -0
- package/src/components/ui/angle-slider.tsx +265 -0
- package/src/components/ui/autocomplete.tsx +223 -0
- package/src/components/ui/avatar.tsx +8 -2
- package/src/components/ui/blockquote.tsx +112 -0
- package/src/components/ui/bottom-navigation.tsx +144 -0
- package/src/components/ui/burger.tsx +117 -0
- package/src/components/ui/button.tsx +101 -3
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/card.tsx +43 -5
- package/src/components/ui/carousel.tsx +10 -5
- package/src/components/ui/cascader.tsx +253 -0
- package/src/components/ui/checkbox-card.tsx +176 -0
- package/src/components/ui/checkbox-group.tsx +231 -0
- package/src/components/ui/checkbox.tsx +14 -3
- package/src/components/ui/chip.tsx +143 -0
- package/src/components/ui/circular-progress.tsx +2 -2
- package/src/components/ui/color-swatch.tsx +73 -0
- package/src/components/ui/copy-button.tsx +21 -4
- package/src/components/ui/date-picker.tsx +6 -3
- package/src/components/ui/date-range-picker.tsx +6 -3
- package/src/components/ui/float-label.tsx +114 -0
- package/src/components/ui/floating-panel.tsx +129 -0
- package/src/components/ui/format-number.tsx +122 -0
- package/src/components/ui/highlight.tsx +85 -0
- package/src/components/ui/image.tsx +195 -0
- package/src/components/ui/index.ts +50 -0
- package/src/components/ui/indicator.tsx +2 -2
- package/src/components/ui/input.tsx +48 -4
- package/src/components/ui/kbd.tsx +1 -1
- package/src/components/ui/link.tsx +158 -0
- package/src/components/ui/listbox.tsx +426 -0
- package/src/components/ui/loading-overlay.tsx +80 -0
- package/src/components/ui/marquee.tsx +193 -0
- package/src/components/ui/masonry.tsx +164 -0
- package/src/components/ui/meter.tsx +186 -0
- package/src/components/ui/motion-toggle.tsx +170 -0
- package/src/components/ui/notification.tsx +175 -0
- package/src/components/ui/overlay.tsx +63 -0
- package/src/components/ui/progress.tsx +95 -4
- package/src/components/ui/rating-group.tsx +1 -0
- package/src/components/ui/separator.tsx +57 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/signature-pad.tsx +381 -0
- package/src/components/ui/skeleton.tsx +59 -2
- package/src/components/ui/skip-link.tsx +117 -0
- package/src/components/ui/slider.tsx +86 -1
- package/src/components/ui/spoiler.tsx +131 -0
- package/src/components/ui/tabs.tsx +1 -1
- package/src/components/ui/text.tsx +135 -0
- package/src/components/ui/textarea.tsx +66 -2
- package/src/components/ui/timeline.tsx +71 -14
- package/src/components/ui/timer.tsx +183 -0
- package/src/components/ui/tour.tsx +332 -0
- package/src/components/ui/transfer-list.tsx +308 -0
- package/src/components/ui/visually-hidden.tsx +42 -0
- package/src/components/ui/watermark.tsx +0 -0
- package/src/data/docs-index.ts +9 -2
- package/src/stories/ActionBar.stories.tsx +201 -0
- package/src/stories/Affix.stories.tsx +165 -0
- package/src/stories/Alert.stories.tsx +58 -0
- package/src/stories/Anchor.stories.tsx +236 -0
- package/src/stories/AngleSlider.stories.tsx +128 -0
- package/src/stories/Autocomplete.stories.tsx +216 -0
- package/src/stories/Avatar.stories.tsx +73 -1
- package/src/stories/Blockquote.stories.tsx +148 -0
- package/src/stories/BottomNavigation.stories.tsx +195 -0
- package/src/stories/Burger.stories.tsx +79 -0
- package/src/stories/Button.stories.tsx +103 -2
- package/src/stories/Calendar.stories.tsx +4 -0
- package/src/stories/Card.stories.tsx +30 -0
- package/src/stories/Carousel.stories.tsx +2 -1
- package/src/stories/Cascader.stories.tsx +285 -0
- package/src/stories/Checkbox.stories.tsx +13 -0
- package/src/stories/CheckboxCard.stories.tsx +210 -0
- package/src/stories/CheckboxGroup.stories.tsx +186 -0
- package/src/stories/Chip.stories.tsx +173 -0
- package/src/stories/CircularProgress.stories.tsx +3 -0
- package/src/stories/ColorSwatch.stories.tsx +81 -0
- package/src/stories/CopyButton.stories.tsx +3 -3
- package/src/stories/DatePicker.stories.tsx +3 -0
- package/src/stories/DateRangePicker.stories.tsx +3 -0
- package/src/stories/Editable.stories.tsx +14 -0
- package/src/stories/FloatLabel.stories.tsx +148 -0
- package/src/stories/FloatingPanel.stories.tsx +176 -0
- package/src/stories/FormatNumber.stories.tsx +308 -0
- package/src/stories/Highlight.stories.tsx +140 -0
- package/src/stories/Image.stories.tsx +141 -0
- package/src/stories/Indicator.stories.tsx +3 -0
- package/src/stories/Input.stories.tsx +33 -0
- package/src/stories/Kbd.stories.tsx +3 -0
- package/src/stories/Link.stories.tsx +198 -0
- package/src/stories/Listbox.stories.tsx +240 -0
- package/src/stories/LoadingOverlay.stories.tsx +148 -0
- package/src/stories/Marquee.stories.tsx +170 -0
- package/src/stories/Masonry.stories.tsx +227 -0
- package/src/stories/Meter.stories.tsx +143 -0
- package/src/stories/MotionToggle.stories.tsx +85 -0
- package/src/stories/Notification.stories.tsx +264 -0
- package/src/stories/Overlay.stories.tsx +169 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/Progress.stories.tsx +70 -27
- package/src/stories/RatingGroup.stories.tsx +5 -0
- package/src/stories/Separator.stories.tsx +41 -5
- package/src/stories/Sidebar.stories.tsx +2 -1
- package/src/stories/SignaturePad.stories.tsx +112 -0
- package/src/stories/Skeleton.stories.tsx +23 -4
- package/src/stories/SkipLink.stories.tsx +137 -0
- package/src/stories/Slider.stories.tsx +28 -0
- package/src/stories/Spoiler.stories.tsx +122 -0
- package/src/stories/Tabs.stories.tsx +2 -1
- package/src/stories/Text.stories.tsx +191 -0
- package/src/stories/Textarea.stories.tsx +58 -6
- package/src/stories/Timeline.stories.tsx +82 -0
- package/src/stories/Timer.stories.tsx +160 -0
- package/src/stories/Tour.stories.tsx +191 -0
- package/src/stories/TransferList.stories.tsx +169 -0
- package/src/stories/VisuallyHidden.stories.tsx +105 -0
- package/src/stories/Watermark.stories.tsx +212 -0
- package/src/styles.css +80 -6
- package/src/tokens.json +2 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
import { Check } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils";
|
|
8
|
+
|
|
9
|
+
// Chip — interactive filter/facet toggle pill (role="checkbox").
|
|
10
|
+
//
|
|
11
|
+
// Semantic sibling of Tag: Tag is a passive display label (a div, optionally
|
|
12
|
+
// dismissible); Chip is a stateful selector the user toggles on/off ("Filter
|
|
13
|
+
// by: design tokens | a11y contract"). Each chip is an independent toggle and
|
|
14
|
+
// its own tab stop — deliberately NOT a radiogroup, so arrow-key roving is
|
|
15
|
+
// not wired. Space (and Enter, via the native button) toggles.
|
|
16
|
+
//
|
|
17
|
+
// Motion is pattern (c): explicit transition property list + inline
|
|
18
|
+
// var(--duration-fast) / var(--ease-out). box-shadow is excluded from the
|
|
19
|
+
// list so the focus ring appears instantly (a11y floor).
|
|
20
|
+
|
|
21
|
+
const chipVariants = cva(
|
|
22
|
+
[
|
|
23
|
+
// Layout + long-label overflow contract: the button is the flex parent
|
|
24
|
+
// (max-w-full min-w-0 overflow-hidden); the label span truncates.
|
|
25
|
+
"inline-flex max-w-full min-w-0 cursor-pointer select-none items-center gap-1.5 overflow-hidden rounded-full border font-medium whitespace-nowrap",
|
|
26
|
+
"transition-[background-color,color,border-color]",
|
|
27
|
+
"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
28
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
29
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
30
|
+
],
|
|
31
|
+
{
|
|
32
|
+
variants: {
|
|
33
|
+
variant: {
|
|
34
|
+
default: [
|
|
35
|
+
"border-transparent bg-secondary text-secondary-foreground",
|
|
36
|
+
"hover:bg-secondary/80",
|
|
37
|
+
"aria-checked:bg-primary aria-checked:text-primary-foreground aria-checked:hover:bg-primary/90",
|
|
38
|
+
],
|
|
39
|
+
outline: [
|
|
40
|
+
"border-input bg-transparent text-muted-foreground",
|
|
41
|
+
"hover:bg-muted hover:text-foreground",
|
|
42
|
+
"aria-checked:border-primary aria-checked:bg-primary/10 aria-checked:text-foreground",
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
size: {
|
|
46
|
+
// sm is the documented dense-filter-chrome exception to the CTA size
|
|
47
|
+
// contract (min-h-9, mirroring Button's h-9 default — CLAUDE.md →
|
|
48
|
+
// Accessibility Floor, 2026-07 audit H5). When a chip is a
|
|
49
|
+
// flow-changing CTA, use size="default" or "lg" (min-h-11+).
|
|
50
|
+
sm: "min-h-9 px-3 text-sm",
|
|
51
|
+
default: "min-h-11 px-4 text-sm",
|
|
52
|
+
lg: "min-h-12 px-5 text-sm",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
variant: "default",
|
|
57
|
+
size: "default",
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
type ChipProps = Omit<React.ComponentProps<"button">, "children"> &
|
|
63
|
+
VariantProps<typeof chipVariants> & {
|
|
64
|
+
/** Controlled selected state. */
|
|
65
|
+
selected?: boolean;
|
|
66
|
+
/** Uncontrolled initial selected state. */
|
|
67
|
+
defaultSelected?: boolean;
|
|
68
|
+
/** Called with the next selected state on every toggle. */
|
|
69
|
+
onSelectedChange?: (selected: boolean) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Optional leading icon (16px, strokeWidth 1.5 enforced via CSS).
|
|
72
|
+
* Replaced by the check indicator while the chip is selected.
|
|
73
|
+
*/
|
|
74
|
+
icon?: React.ReactNode;
|
|
75
|
+
/** Visible label — the chip's accessible name. */
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function Chip({
|
|
80
|
+
className,
|
|
81
|
+
variant,
|
|
82
|
+
size,
|
|
83
|
+
selected,
|
|
84
|
+
defaultSelected = false,
|
|
85
|
+
onSelectedChange,
|
|
86
|
+
icon,
|
|
87
|
+
disabled,
|
|
88
|
+
onClick,
|
|
89
|
+
style,
|
|
90
|
+
children,
|
|
91
|
+
...props
|
|
92
|
+
}: ChipProps) {
|
|
93
|
+
const [uncontrolledSelected, setUncontrolledSelected] =
|
|
94
|
+
React.useState(defaultSelected);
|
|
95
|
+
const isControlled = selected !== undefined;
|
|
96
|
+
const isSelected = isControlled ? selected : uncontrolledSelected;
|
|
97
|
+
|
|
98
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
99
|
+
onClick?.(event);
|
|
100
|
+
if (event.defaultPrevented || disabled) return;
|
|
101
|
+
const next = !isSelected;
|
|
102
|
+
if (!isControlled) setUncontrolledSelected(next);
|
|
103
|
+
onSelectedChange?.(next);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
role="checkbox"
|
|
110
|
+
aria-checked={isSelected}
|
|
111
|
+
data-slot="chip"
|
|
112
|
+
data-selected={isSelected || undefined}
|
|
113
|
+
data-state={isSelected ? "checked" : "unchecked"}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
onClick={handleClick}
|
|
116
|
+
className={cn(chipVariants({ variant, size }), className)}
|
|
117
|
+
style={{
|
|
118
|
+
transitionDuration: "var(--duration-fast)",
|
|
119
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
120
|
+
...style,
|
|
121
|
+
}}
|
|
122
|
+
{...props}
|
|
123
|
+
>
|
|
124
|
+
{isSelected ? (
|
|
125
|
+
// Non-color selected indicator — state never reads by fill alone.
|
|
126
|
+
<Check strokeWidth={1.5} aria-hidden="true" className="size-4 shrink-0" />
|
|
127
|
+
) : (
|
|
128
|
+
icon != null && (
|
|
129
|
+
<span
|
|
130
|
+
aria-hidden="true"
|
|
131
|
+
className="shrink-0 [&>svg]:size-4 [&>svg]:stroke-[1.5]"
|
|
132
|
+
>
|
|
133
|
+
{icon}
|
|
134
|
+
</span>
|
|
135
|
+
)
|
|
136
|
+
)}
|
|
137
|
+
<span className="min-w-0 truncate">{children}</span>
|
|
138
|
+
</button>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { Chip, chipVariants };
|
|
143
|
+
export type { ChipProps };
|
|
@@ -19,8 +19,8 @@ const circularProgressVariants = cva(
|
|
|
19
19
|
variant: {
|
|
20
20
|
default: "text-primary",
|
|
21
21
|
muted: "text-muted-foreground",
|
|
22
|
-
success: "text-[
|
|
23
|
-
warning: "text-[
|
|
22
|
+
success: "text-[var(--success)]",
|
|
23
|
+
warning: "text-[var(--warning)]",
|
|
24
24
|
destructive: "text-destructive",
|
|
25
25
|
},
|
|
26
26
|
},
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
|
|
8
|
+
const colorSwatchVariants = cva(
|
|
9
|
+
// Inset ring gives the swatch a crisp edge on any canvas. `foreground/15`
|
|
10
|
+
// is token-driven: a dark hairline in light mode delineates pale swatches,
|
|
11
|
+
// a light hairline in dark mode delineates near-black swatches.
|
|
12
|
+
"inline-grid shrink-0 place-items-center ring-1 ring-inset ring-foreground/15",
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
size: {
|
|
16
|
+
sm: "size-4 [&_svg]:size-2.5",
|
|
17
|
+
default: "size-6 [&_svg]:size-3.5",
|
|
18
|
+
lg: "size-8 [&_svg]:size-4",
|
|
19
|
+
},
|
|
20
|
+
shape: {
|
|
21
|
+
rounded: "rounded-md",
|
|
22
|
+
circle: "rounded-full",
|
|
23
|
+
square: "rounded-none",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
size: "default",
|
|
28
|
+
shape: "rounded",
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
interface ColorSwatchProps
|
|
34
|
+
extends Omit<React.ComponentProps<"span">, "color">,
|
|
35
|
+
VariantProps<typeof colorSwatchVariants> {
|
|
36
|
+
/** Any CSS color — hex, rgb(), hsl(), or a CSS variable like `var(--chart-1)`. */
|
|
37
|
+
color: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Display-only color chip. Presentational by default (`aria-hidden`) since a
|
|
42
|
+
* swatch usually sits beside a text label that already names the color. Pass
|
|
43
|
+
* `aria-label` when the swatch stands alone and must announce its meaning —
|
|
44
|
+
* it then renders `role="img"`. Not interactive: wrap it in a Button (with a
|
|
45
|
+
* label) if a click should do something.
|
|
46
|
+
*/
|
|
47
|
+
function ColorSwatch({
|
|
48
|
+
className,
|
|
49
|
+
color,
|
|
50
|
+
size,
|
|
51
|
+
shape,
|
|
52
|
+
style,
|
|
53
|
+
children,
|
|
54
|
+
"aria-label": ariaLabel,
|
|
55
|
+
...props
|
|
56
|
+
}: ColorSwatchProps) {
|
|
57
|
+
return (
|
|
58
|
+
<span
|
|
59
|
+
data-slot="color-swatch"
|
|
60
|
+
role={ariaLabel ? "img" : undefined}
|
|
61
|
+
aria-label={ariaLabel}
|
|
62
|
+
aria-hidden={ariaLabel ? undefined : true}
|
|
63
|
+
className={cn(colorSwatchVariants({ size, shape }), className)}
|
|
64
|
+
style={{ backgroundColor: color, ...style }}
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</span>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { ColorSwatch, colorSwatchVariants }
|
|
73
|
+
export type { ColorSwatchProps }
|
|
@@ -58,6 +58,11 @@ function CopyButton({
|
|
|
58
58
|
}, [value, copied, copiedDuration, onCopy])
|
|
59
59
|
|
|
60
60
|
const iconOnly = children === undefined
|
|
61
|
+
// Compact labeled buttons drop the check icon in the copied state — at
|
|
62
|
+
// sm/xs padding the icon+text pair is wider than the resting label and
|
|
63
|
+
// clips against overflow-hidden. "Copied!" alone is confirmation enough
|
|
64
|
+
// there. Icon-only mode always keeps the check (it's the only feedback).
|
|
65
|
+
const showCheck = iconOnly || (size !== "sm" && size !== "xs")
|
|
61
66
|
|
|
62
67
|
return (
|
|
63
68
|
<>
|
|
@@ -66,7 +71,12 @@ function CopyButton({
|
|
|
66
71
|
data-copied={copied ? "true" : undefined}
|
|
67
72
|
variant={variant}
|
|
68
73
|
size={size}
|
|
69
|
-
disabled
|
|
74
|
+
// Not disabled during the copied window — the Button primitive's
|
|
75
|
+
// disabled:opacity-50 would dim the green confirmation to 50%. The
|
|
76
|
+
// re-copy guard lives in handleCopy (`if (copied) return`), so leaving
|
|
77
|
+
// the button enabled keeps "Copied!" at full opacity without allowing
|
|
78
|
+
// a double-copy.
|
|
79
|
+
disabled={disabled}
|
|
70
80
|
onClick={handleCopy}
|
|
71
81
|
aria-label={ariaLabel ?? (iconOnly ? (copied ? "Copied" : "Copy") : undefined)}
|
|
72
82
|
className={cn("relative overflow-hidden", className)}
|
|
@@ -75,7 +85,7 @@ function CopyButton({
|
|
|
75
85
|
{/* In labeled mode this span provides the button's accessible name — not aria-hidden */}
|
|
76
86
|
<span
|
|
77
87
|
className={cn(
|
|
78
|
-
"inline-flex items-center gap-1.5 transition-
|
|
88
|
+
"inline-flex items-center gap-1.5 transition-[opacity,transform]",
|
|
79
89
|
copied ? "opacity-0 scale-75" : "opacity-100 scale-100"
|
|
80
90
|
)}
|
|
81
91
|
style={{
|
|
@@ -90,7 +100,14 @@ function CopyButton({
|
|
|
90
100
|
{/* Always hidden — state announced by the aria-live region */}
|
|
91
101
|
<span
|
|
92
102
|
className={cn(
|
|
93
|
-
|
|
103
|
+
// Centered over the whole button face. An earlier right-aligned
|
|
104
|
+
// pr-4 treatment clipped the overlay's left edge on any size whose
|
|
105
|
+
// padding isn't px-4 (sm/xs) because the swap-in content is wider
|
|
106
|
+
// than the resting label and the button is overflow-hidden.
|
|
107
|
+
// No color override — inherits the button's own foreground so it
|
|
108
|
+
// reads on any variant. Green text on the dark default button fails
|
|
109
|
+
// AAA (~3.6:1); the check icon is sufficient confirmation.
|
|
110
|
+
"absolute inset-0 inline-flex items-center justify-center gap-1.5 transition-[opacity,transform]",
|
|
94
111
|
copied ? "opacity-100 scale-100" : "opacity-0 scale-75"
|
|
95
112
|
)}
|
|
96
113
|
style={{
|
|
@@ -99,7 +116,7 @@ function CopyButton({
|
|
|
99
116
|
}}
|
|
100
117
|
aria-hidden="true"
|
|
101
118
|
>
|
|
102
|
-
<CheckIcon strokeWidth={1.5} />
|
|
119
|
+
{showCheck && <CheckIcon strokeWidth={1.5} />}
|
|
103
120
|
{!iconOnly && "Copied!"}
|
|
104
121
|
</span>
|
|
105
122
|
</Button>
|
|
@@ -146,9 +146,12 @@ function DatePicker({
|
|
|
146
146
|
mode="single"
|
|
147
147
|
selected={selectedDate}
|
|
148
148
|
onSelect={handleSelect}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
startMonth={fromDate}
|
|
150
|
+
endMonth={toDate}
|
|
151
|
+
disabled={[
|
|
152
|
+
...(fromDate ? [{ before: fromDate }] : []),
|
|
153
|
+
...(toDate ? [{ after: toDate }] : []),
|
|
154
|
+
]}
|
|
152
155
|
/>
|
|
153
156
|
</PopoverContent>
|
|
154
157
|
</Popover>
|
|
@@ -161,10 +161,13 @@ function DateRangePicker({
|
|
|
161
161
|
mode="range"
|
|
162
162
|
selected={selectedRange as DateRange | undefined}
|
|
163
163
|
onSelect={handleSelect}
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
startMonth={fromDate}
|
|
165
|
+
endMonth={toDate}
|
|
166
|
+
disabled={[
|
|
167
|
+
...(fromDate ? [{ before: fromDate }] : []),
|
|
168
|
+
...(toDate ? [{ after: toDate }] : []),
|
|
169
|
+
]}
|
|
166
170
|
numberOfMonths={2}
|
|
167
|
-
initialFocus
|
|
168
171
|
/>
|
|
169
172
|
</PopoverContent>
|
|
170
173
|
</Popover>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
import { Input } from "./input";
|
|
8
|
+
|
|
9
|
+
// ─── Variants ─────────────────────────────────────────────────────────────────
|
|
10
|
+
//
|
|
11
|
+
// The label always carries px-1 (so the floated "notch" has breathing room over
|
|
12
|
+
// the top border) and left-* compensates per size so the RESTING label text
|
|
13
|
+
// aligns exactly with the input's own text (Input pads: sm px-2.5, default px-3,
|
|
14
|
+
// lg px-4).
|
|
15
|
+
//
|
|
16
|
+
// Float trigger is pure CSS — the wrapped <Input> is the `peer`, and the label
|
|
17
|
+
// reacts to :focus, :not(:placeholder-shown) (requires placeholder=" "), and
|
|
18
|
+
// :autofill (Chrome autofill doesn't always fire focus). No JS state.
|
|
19
|
+
|
|
20
|
+
const floatLabelVariants = cva(
|
|
21
|
+
[
|
|
22
|
+
// geometry + resting position (vertically centered in the field)
|
|
23
|
+
"pointer-events-none absolute top-1/2 -translate-y-1/2 select-none px-1",
|
|
24
|
+
"origin-left text-muted-foreground",
|
|
25
|
+
// float on focus
|
|
26
|
+
"peer-focus:top-0 peer-focus:text-xs peer-focus:bg-background peer-focus:text-foreground",
|
|
27
|
+
// stay floated while filled (placeholder=" " makes :placeholder-shown reliable)
|
|
28
|
+
"peer-[:not(:placeholder-shown)]:top-0 peer-[:not(:placeholder-shown)]:text-xs peer-[:not(:placeholder-shown)]:bg-background",
|
|
29
|
+
// browser autofill paints a value without necessarily focusing
|
|
30
|
+
"peer-autofill:top-0 peer-autofill:text-xs peer-autofill:bg-background",
|
|
31
|
+
// state mirrors
|
|
32
|
+
"peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
|
33
|
+
"peer-aria-invalid:text-destructive",
|
|
34
|
+
// motion: property list here; duration/easing via inline style tokens below
|
|
35
|
+
"transition-[top,transform,font-size,color,background-color]",
|
|
36
|
+
],
|
|
37
|
+
{
|
|
38
|
+
variants: {
|
|
39
|
+
size: {
|
|
40
|
+
sm: "left-1.5 text-sm",
|
|
41
|
+
default: "left-2 text-sm",
|
|
42
|
+
lg: "left-3 text-base",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
defaultVariants: {
|
|
46
|
+
size: "default",
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
type FloatLabelProps = Omit<
|
|
54
|
+
React.ComponentProps<typeof Input>,
|
|
55
|
+
"size" | "placeholder" | "clearable"
|
|
56
|
+
> &
|
|
57
|
+
VariantProps<typeof floatLabelVariants> & {
|
|
58
|
+
/** Visible label text. Required — this IS the field's accessible name. */
|
|
59
|
+
label: string;
|
|
60
|
+
/** Class applied to the outer relative wrapper (use for width control). */
|
|
61
|
+
containerClassName?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ─── FloatLabel ───────────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
function FloatLabel({
|
|
67
|
+
label,
|
|
68
|
+
size,
|
|
69
|
+
id,
|
|
70
|
+
required,
|
|
71
|
+
containerClassName,
|
|
72
|
+
className,
|
|
73
|
+
...props
|
|
74
|
+
}: FloatLabelProps) {
|
|
75
|
+
const generatedId = React.useId();
|
|
76
|
+
const inputId = id ?? generatedId;
|
|
77
|
+
const labelId = `${inputId}-label`;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
data-slot="float-label"
|
|
82
|
+
className={cn("relative", containerClassName)}
|
|
83
|
+
>
|
|
84
|
+
<Input
|
|
85
|
+
id={inputId}
|
|
86
|
+
size={size}
|
|
87
|
+
required={required}
|
|
88
|
+
aria-labelledby={labelId}
|
|
89
|
+
// A single space keeps :placeholder-shown reliable for empty-state
|
|
90
|
+
// detection without ever rendering visible placeholder text — the
|
|
91
|
+
// floating label is the field's one visible name.
|
|
92
|
+
placeholder=" "
|
|
93
|
+
className={cn("peer", className)}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
<label
|
|
97
|
+
id={labelId}
|
|
98
|
+
htmlFor={inputId}
|
|
99
|
+
data-slot="float-label-label"
|
|
100
|
+
className={cn(floatLabelVariants({ size }))}
|
|
101
|
+
style={{
|
|
102
|
+
transitionDuration: "var(--duration-fast)",
|
|
103
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
{label}
|
|
107
|
+
{required && <span aria-hidden="true"> *</span>}
|
|
108
|
+
</label>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { FloatLabel, floatLabelVariants };
|
|
114
|
+
export type { FloatLabelProps };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { XIcon } from "lucide-react"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
type FloatingPanelPosition =
|
|
8
|
+
| "bottom-right"
|
|
9
|
+
| "bottom-left"
|
|
10
|
+
| "top-right"
|
|
11
|
+
| "top-left"
|
|
12
|
+
|
|
13
|
+
const positionClasses: Record<FloatingPanelPosition, string> = {
|
|
14
|
+
"bottom-right": "bottom-4 right-4",
|
|
15
|
+
"bottom-left": "bottom-4 left-4",
|
|
16
|
+
"top-right": "top-4 right-4",
|
|
17
|
+
"top-left": "top-4 left-4",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type FloatingPanelProps = Omit<React.HTMLAttributes<HTMLElement>, "title"> & {
|
|
21
|
+
/** Viewport corner the panel anchors to. Default "bottom-right". */
|
|
22
|
+
defaultPosition?: FloatingPanelPosition
|
|
23
|
+
/**
|
|
24
|
+
* Optional header title. When it is a plain string the landmark's
|
|
25
|
+
* accessible name derives from it via aria-labelledby.
|
|
26
|
+
*/
|
|
27
|
+
title?: React.ReactNode
|
|
28
|
+
/**
|
|
29
|
+
* Visibility. Default true — FloatingPanel is a persistent companion
|
|
30
|
+
* surface, not a popup. When false the panel carries the `hidden`
|
|
31
|
+
* attribute so it leaves the tab order and the accessibility tree.
|
|
32
|
+
*/
|
|
33
|
+
open?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* When provided, a labelled close button renders in the header and
|
|
36
|
+
* fires onOpenChange(false) on click.
|
|
37
|
+
*/
|
|
38
|
+
onOpenChange?: (open: boolean) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Floating, always-rendered, non-modal companion panel anchored to a
|
|
43
|
+
* viewport corner. Floats over content without blocking it — contextual
|
|
44
|
+
* help that stays available while the user works, debug overlays,
|
|
45
|
+
* sticky-note panels.
|
|
46
|
+
*
|
|
47
|
+
* Not a Sheet (edge-anchored slide-in), not a Popover (trigger-anchored,
|
|
48
|
+
* dismissable), not a Dialog (modal, focus-trapped). Focus is deliberately
|
|
49
|
+
* NOT trapped: the panel is a `role="complementary"` landmark the user
|
|
50
|
+
* tabs into and out of like any other page region.
|
|
51
|
+
*
|
|
52
|
+
* Reduced motion: the base layer's `prefers-reduced-motion` rule collapses
|
|
53
|
+
* the open/close transition automatically; no component-level guard needed.
|
|
54
|
+
*/
|
|
55
|
+
function FloatingPanel({
|
|
56
|
+
defaultPosition = "bottom-right",
|
|
57
|
+
title,
|
|
58
|
+
open = true,
|
|
59
|
+
onOpenChange,
|
|
60
|
+
className,
|
|
61
|
+
children,
|
|
62
|
+
...props
|
|
63
|
+
}: FloatingPanelProps) {
|
|
64
|
+
const titleId = React.useId()
|
|
65
|
+
const hasStringTitle = typeof title === "string" && title.length > 0
|
|
66
|
+
const showHeader = title != null || onOpenChange != null
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
data-slot="floating-panel"
|
|
71
|
+
data-open={open}
|
|
72
|
+
role="complementary"
|
|
73
|
+
// Consumer aria-label / aria-labelledby in {...props} spreads AFTER
|
|
74
|
+
// these defaults, so an explicit name always wins.
|
|
75
|
+
aria-labelledby={hasStringTitle ? titleId : undefined}
|
|
76
|
+
aria-label={hasStringTitle ? undefined : "Floating panel"}
|
|
77
|
+
hidden={!open || undefined}
|
|
78
|
+
className={cn(
|
|
79
|
+
"fixed z-50 w-72 rounded-lg border border-border bg-background p-4 text-foreground shadow-lg",
|
|
80
|
+
positionClasses[defaultPosition],
|
|
81
|
+
open ? "opacity-100 scale-100" : "opacity-0 scale-95",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
style={{
|
|
85
|
+
transitionProperty: "opacity, transform",
|
|
86
|
+
transitionDuration: "var(--duration-base)",
|
|
87
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
88
|
+
}}
|
|
89
|
+
{...props}
|
|
90
|
+
>
|
|
91
|
+
{showHeader && (
|
|
92
|
+
<header
|
|
93
|
+
data-slot="floating-panel-header"
|
|
94
|
+
className="mb-2 flex items-start justify-between gap-2"
|
|
95
|
+
>
|
|
96
|
+
{title != null ? (
|
|
97
|
+
<p
|
|
98
|
+
id={hasStringTitle ? titleId : undefined}
|
|
99
|
+
data-slot="floating-panel-title"
|
|
100
|
+
className="min-w-0 truncate text-sm font-medium"
|
|
101
|
+
>
|
|
102
|
+
{title}
|
|
103
|
+
</p>
|
|
104
|
+
) : (
|
|
105
|
+
<span aria-hidden="true" />
|
|
106
|
+
)}
|
|
107
|
+
{onOpenChange != null && (
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
aria-label="Close panel"
|
|
111
|
+
onClick={() => onOpenChange(false)}
|
|
112
|
+
className="-mr-1 -mt-1 flex size-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
113
|
+
style={{
|
|
114
|
+
transitionProperty: "background-color, color",
|
|
115
|
+
transitionDuration: "var(--duration-fast)",
|
|
116
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<XIcon size={16} strokeWidth={1.5} aria-hidden="true" />
|
|
120
|
+
</button>
|
|
121
|
+
)}
|
|
122
|
+
</header>
|
|
123
|
+
)}
|
|
124
|
+
{children}
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { FloatingPanel, type FloatingPanelProps, type FloatingPanelPosition }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Explicit default locale. FormatNumber never reads the runtime locale
|
|
7
|
+
* (navigator.language): an implicit locale formats differently on the
|
|
8
|
+
* server and the client, which is the classic hydration-mismatch bug.
|
|
9
|
+
* Consumers localizing for real pass `locale` from their own i18n layer.
|
|
10
|
+
*/
|
|
11
|
+
const FORMAT_NUMBER_DEFAULT_LOCALE = "en-US"
|
|
12
|
+
|
|
13
|
+
export interface FormatNumberProps
|
|
14
|
+
extends Omit<React.ComponentProps<"span">, "style" | "children">,
|
|
15
|
+
Intl.NumberFormatOptions {
|
|
16
|
+
/** The number to format. */
|
|
17
|
+
value: number
|
|
18
|
+
/**
|
|
19
|
+
* BCP 47 locale tag. Defaults to "en-US" (explicit, SSR-safe) — pass your
|
|
20
|
+
* i18n layer's locale to localize.
|
|
21
|
+
*/
|
|
22
|
+
locale?: string
|
|
23
|
+
/**
|
|
24
|
+
* `font-variant-numeric: tabular-nums` so digits occupy equal widths.
|
|
25
|
+
*
|
|
26
|
+
* **Defaults to `true`.** Tabular figures are the right baseline for a
|
|
27
|
+
* number-*display* primitive: they align in columns and stat rows, and —
|
|
28
|
+
* load-bearing for BADS' default face — they sidestep a rendering collision
|
|
29
|
+
* in Hyperlegible Sans, whose *proportional* figures carry kern pairs that
|
|
30
|
+
* Chromium over-applies, cramping/overlapping decimals (e.g. `$182,450.00`).
|
|
31
|
+
* Tabular figures use fixed advances with no kerning, so numbers render
|
|
32
|
+
* cleanly in the brand font. Pass `tabular={false}` to opt back into
|
|
33
|
+
* proportional figures (fine for prose on a fork whose font renders them
|
|
34
|
+
* cleanly; may cramp on Hyperlegible).
|
|
35
|
+
*/
|
|
36
|
+
tabular?: boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Locale-aware number display primitive — a thin wrapper around
|
|
41
|
+
* `Intl.NumberFormat`. Handles decimal, currency, percent, unit, and
|
|
42
|
+
* compact notation. Display-only: for editable numbers use NumberInput.
|
|
43
|
+
*
|
|
44
|
+
* Note: `style` here is the Intl style ("decimal" | "currency" | "percent"
|
|
45
|
+
* | "unit"), matching Chakra/Ark — NOT the CSS style prop. Style the span
|
|
46
|
+
* via `className`.
|
|
47
|
+
*/
|
|
48
|
+
function FormatNumber({
|
|
49
|
+
value,
|
|
50
|
+
locale = FORMAT_NUMBER_DEFAULT_LOCALE,
|
|
51
|
+
tabular = true,
|
|
52
|
+
className,
|
|
53
|
+
title,
|
|
54
|
+
// Intl.NumberFormatOptions (ES2020 set) — passed to the formatter, kept
|
|
55
|
+
// out of the DOM spread so no unknown attributes leak onto the <span>.
|
|
56
|
+
localeMatcher,
|
|
57
|
+
numberingSystem,
|
|
58
|
+
style,
|
|
59
|
+
currency,
|
|
60
|
+
currencyDisplay,
|
|
61
|
+
currencySign,
|
|
62
|
+
unit,
|
|
63
|
+
unitDisplay,
|
|
64
|
+
useGrouping,
|
|
65
|
+
minimumIntegerDigits,
|
|
66
|
+
minimumFractionDigits,
|
|
67
|
+
maximumFractionDigits,
|
|
68
|
+
minimumSignificantDigits,
|
|
69
|
+
maximumSignificantDigits,
|
|
70
|
+
notation,
|
|
71
|
+
compactDisplay,
|
|
72
|
+
signDisplay,
|
|
73
|
+
...props
|
|
74
|
+
}: FormatNumberProps) {
|
|
75
|
+
const options: Intl.NumberFormatOptions = {
|
|
76
|
+
localeMatcher,
|
|
77
|
+
numberingSystem,
|
|
78
|
+
style,
|
|
79
|
+
currency,
|
|
80
|
+
currencyDisplay,
|
|
81
|
+
currencySign,
|
|
82
|
+
unit,
|
|
83
|
+
unitDisplay,
|
|
84
|
+
useGrouping,
|
|
85
|
+
minimumIntegerDigits,
|
|
86
|
+
minimumFractionDigits,
|
|
87
|
+
maximumFractionDigits,
|
|
88
|
+
minimumSignificantDigits,
|
|
89
|
+
maximumSignificantDigits,
|
|
90
|
+
notation,
|
|
91
|
+
compactDisplay,
|
|
92
|
+
signDisplay,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const formatted = new Intl.NumberFormat(locale, options).format(value)
|
|
96
|
+
|
|
97
|
+
// Compact notation abbreviates ("1.2M"). Screen readers announce the
|
|
98
|
+
// visible text as-is (no aria-label override — SC 2.5.3 hygiene); the
|
|
99
|
+
// full-precision value rides the native title attribute so it stays
|
|
100
|
+
// recoverable on hover / long-press. A consumer-supplied title wins.
|
|
101
|
+
const fullValue =
|
|
102
|
+
notation === "compact" && title === undefined
|
|
103
|
+
? new Intl.NumberFormat(locale, {
|
|
104
|
+
...options,
|
|
105
|
+
notation: "standard",
|
|
106
|
+
compactDisplay: undefined,
|
|
107
|
+
}).format(value)
|
|
108
|
+
: undefined
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<span
|
|
112
|
+
data-slot="format-number"
|
|
113
|
+
className={cn(tabular && "tabular-nums", className)}
|
|
114
|
+
title={title ?? fullValue}
|
|
115
|
+
{...props}
|
|
116
|
+
>
|
|
117
|
+
{formatted}
|
|
118
|
+
</span>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { FormatNumber, FORMAT_NUMBER_DEFAULT_LOCALE }
|