@behavioral-agentic-design-system/core 0.24.0 → 0.27.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 +87 -5
- package/src/app/preview/components/page.tsx +4745 -244
- 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-action-button.tsx +179 -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 +51 -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 +343 -0
- package/src/components/ui/typing-indicator.tsx +96 -0
- package/src/components/ui/visually-hidden.tsx +42 -0
- package/src/components/ui/watermark.tsx +0 -0
- package/src/components/ui/word-rotate.tsx +82 -0
- package/src/data/docs-index.ts +10 -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/FloatingActionButton.stories.tsx +215 -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 +150 -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 +190 -0
- package/src/stories/TypingIndicator.stories.tsx +139 -0
- package/src/stories/VisuallyHidden.stories.tsx +105 -0
- package/src/stories/Watermark.stories.tsx +212 -0
- package/src/stories/WordRotate.stories.tsx +101 -0
- package/src/styles.css +88 -6
- package/src/tokens.json +3 -3
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Button } from "./button"
|
|
7
|
+
|
|
8
|
+
export interface SpoilerProps extends React.ComponentProps<"div"> {
|
|
9
|
+
/**
|
|
10
|
+
* Pixel height the content is clamped to while collapsed. The toggle
|
|
11
|
+
* renders ONLY when the measured content is taller than this.
|
|
12
|
+
* Default 96px — roughly four lines of `text-sm` body copy.
|
|
13
|
+
*/
|
|
14
|
+
maxHeight?: number
|
|
15
|
+
/** Toggle label while collapsed. */
|
|
16
|
+
showLabel?: React.ReactNode
|
|
17
|
+
/** Toggle label while expanded. */
|
|
18
|
+
hideLabel?: React.ReactNode
|
|
19
|
+
/** Controlled expanded state. Leave undefined for uncontrolled. */
|
|
20
|
+
expanded?: boolean
|
|
21
|
+
/** Uncontrolled initial state. */
|
|
22
|
+
defaultExpanded?: boolean
|
|
23
|
+
/** Fires with the next state whenever the toggle is activated. */
|
|
24
|
+
onExpandedChange?: (expanded: boolean) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* "Show more / show less" text expander. Content always renders up to
|
|
29
|
+
* `maxHeight`; a ResizeObserver measures the real content height, and the
|
|
30
|
+
* toggle appears ONLY when the content actually overflows the clamp — short
|
|
31
|
+
* content renders plain, with no dead control. (This measured, conditional
|
|
32
|
+
* control is what distinguishes Spoiler from Collapsible, which is binary
|
|
33
|
+
* hidden↔shown with an always-present trigger.)
|
|
34
|
+
*
|
|
35
|
+
* Server render + first client paint are clamped with no toggle (content
|
|
36
|
+
* height is unknowable until mount), so long bodies never flash at full
|
|
37
|
+
* height before collapsing.
|
|
38
|
+
*
|
|
39
|
+
* Accessibility notes:
|
|
40
|
+
* - The clipped overflow stays in the accessibility tree — screen readers
|
|
41
|
+
* read the full text in both states. The toggle is a visual affordance;
|
|
42
|
+
* no information is withheld from AT users.
|
|
43
|
+
* - For text / non-interactive content only. Interactive elements inside
|
|
44
|
+
* the clipped overflow would remain keyboard-focusable while invisible
|
|
45
|
+
* (an invisible focus trap). Put links or buttons outside the Spoiler.
|
|
46
|
+
*/
|
|
47
|
+
function Spoiler({
|
|
48
|
+
maxHeight = 96,
|
|
49
|
+
showLabel = "Show more",
|
|
50
|
+
hideLabel = "Show less",
|
|
51
|
+
expanded: expandedProp,
|
|
52
|
+
defaultExpanded = false,
|
|
53
|
+
onExpandedChange,
|
|
54
|
+
className,
|
|
55
|
+
children,
|
|
56
|
+
...props
|
|
57
|
+
}: SpoilerProps) {
|
|
58
|
+
const contentId = React.useId()
|
|
59
|
+
const innerRef = React.useRef<HTMLDivElement>(null)
|
|
60
|
+
const [contentHeight, setContentHeight] = React.useState<number | null>(null)
|
|
61
|
+
|
|
62
|
+
const isControlled = expandedProp !== undefined
|
|
63
|
+
const [uncontrolledExpanded, setUncontrolledExpanded] =
|
|
64
|
+
React.useState(defaultExpanded)
|
|
65
|
+
const expanded = isControlled ? expandedProp : uncontrolledExpanded
|
|
66
|
+
|
|
67
|
+
const setExpanded = (next: boolean) => {
|
|
68
|
+
if (!isControlled) setUncontrolledExpanded(next)
|
|
69
|
+
onExpandedChange?.(next)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
React.useLayoutEffect(() => {
|
|
73
|
+
const el = innerRef.current
|
|
74
|
+
if (!el) return
|
|
75
|
+
const measure = () => setContentHeight(el.scrollHeight)
|
|
76
|
+
measure()
|
|
77
|
+
const observer = new ResizeObserver(measure)
|
|
78
|
+
observer.observe(el)
|
|
79
|
+
return () => observer.disconnect()
|
|
80
|
+
}, [])
|
|
81
|
+
|
|
82
|
+
const measured = contentHeight !== null
|
|
83
|
+
const hasOverflow = measured && contentHeight > maxHeight
|
|
84
|
+
// Clamp until the content is proven to fit: pre-measurement (SSR + first
|
|
85
|
+
// client paint) renders clamped so a long body never flashes open.
|
|
86
|
+
const clamped = !expanded && (!measured || hasOverflow)
|
|
87
|
+
const state = expanded ? "expanded" : "collapsed"
|
|
88
|
+
|
|
89
|
+
// Animate max-height between two measured px values (never to `auto`,
|
|
90
|
+
// which isn't animatable) — spec §4 pattern (c): inline style driven by
|
|
91
|
+
// the motion tokens, resolved at runtime against :root.
|
|
92
|
+
const clampStyle: React.CSSProperties = {
|
|
93
|
+
maxHeight: clamped ? maxHeight : hasOverflow ? contentHeight! : undefined,
|
|
94
|
+
transitionProperty: "max-height",
|
|
95
|
+
transitionDuration: "var(--duration-base)",
|
|
96
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
data-slot="spoiler"
|
|
102
|
+
data-state={state}
|
|
103
|
+
className={cn("flex w-full flex-col items-start gap-1", className)}
|
|
104
|
+
{...props}
|
|
105
|
+
>
|
|
106
|
+
<div
|
|
107
|
+
id={contentId}
|
|
108
|
+
data-slot="spoiler-content"
|
|
109
|
+
data-state={state}
|
|
110
|
+
className="w-full overflow-hidden"
|
|
111
|
+
style={clampStyle}
|
|
112
|
+
>
|
|
113
|
+
<div ref={innerRef}>{children}</div>
|
|
114
|
+
</div>
|
|
115
|
+
{hasOverflow && (
|
|
116
|
+
<Button
|
|
117
|
+
type="button"
|
|
118
|
+
variant="link"
|
|
119
|
+
className="min-h-11 px-0"
|
|
120
|
+
aria-expanded={expanded}
|
|
121
|
+
aria-controls={contentId}
|
|
122
|
+
onClick={() => setExpanded(!expanded)}
|
|
123
|
+
>
|
|
124
|
+
{expanded ? hideLabel : showLabel}
|
|
125
|
+
</Button>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { Spoiler }
|
|
@@ -125,7 +125,7 @@ function TabsTrigger({
|
|
|
125
125
|
// Active state uses --primary / --primary-foreground so the selected tab
|
|
126
126
|
// always reflects the fork's brand color. bg-accent broke forks where
|
|
127
127
|
// --accent is a dark brand color (e.g. plum), rendering the pill illegibly dark.
|
|
128
|
-
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-
|
|
128
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-xs",
|
|
129
129
|
className
|
|
130
130
|
)}
|
|
131
131
|
{...props}
|
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Typography display primitives. `Text` and `Heading` deliver the semantic
|
|
10
|
+
* text styles defined in tokens.json (`textStyles.heading-xl/lg/md/sm`,
|
|
11
|
+
* `body`, `body-sm`, `caption`) as a component API, so screens stop
|
|
12
|
+
* re-deriving type by hand — the recurring failure this primitive exists to
|
|
13
|
+
* end is picking `text-Xxl` by feel across BADS' non-monotonic scale
|
|
14
|
+
* (`text-3xl` = 49px is BIGGER than `text-4xl` = 36px; see DESIGN.md →
|
|
15
|
+
* Type scale).
|
|
16
|
+
*
|
|
17
|
+
* <Heading as="h1" size="xl">Customize your tokens</Heading>
|
|
18
|
+
* <Text>BADS ships with tokens, components, and accessibility baked in.</Text>
|
|
19
|
+
* <Text variant="body-sm" tone="muted">Last token change was 3 days ago.</Text>
|
|
20
|
+
*
|
|
21
|
+
* Element and style are deliberately decoupled (the Mantine Title /
|
|
22
|
+
* Chakra Heading shape): `as` sets ONLY the document-outline level or text
|
|
23
|
+
* element; `size` / `variant` set ONLY the visual style. Never pick a
|
|
24
|
+
* heading level for its looks (SC 1.3.1) — set `as` for the outline, then
|
|
25
|
+
* size it independently.
|
|
26
|
+
*
|
|
27
|
+
* The marketing display tier (`text-4xl`–`text-8xl`) is intentionally NOT
|
|
28
|
+
* exposed here: no tokens.json textStyle defines it, and keeping it out of
|
|
29
|
+
* the primitive is the guard against reaching into the reset marketing
|
|
30
|
+
* scale from product UI. Landing-surface display type remains a deliberate,
|
|
31
|
+
* hand-written choice per DESIGN.md.
|
|
32
|
+
*
|
|
33
|
+
* Display-only: no interaction, no focus, no motion. Body copy is
|
|
34
|
+
* font-medium (500), not 400 — tokens.json textStyles.body: regular renders
|
|
35
|
+
* too thin at small sizes and on high-DPI screens for low-vision users.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const textVariants = cva(
|
|
39
|
+
// min-w-0 + overflow-wrap:anywhere — long-label overflow contract
|
|
40
|
+
// (corrections.md #001): arbitrary runtime strings (names, emails, URLs)
|
|
41
|
+
// wrap instead of bleeding out of flex/grid parents.
|
|
42
|
+
"min-w-0 [overflow-wrap:anywhere]",
|
|
43
|
+
{
|
|
44
|
+
variants: {
|
|
45
|
+
// 1:1 with tokens.json textStyles — do not invent sizes here.
|
|
46
|
+
variant: {
|
|
47
|
+
// body — text-base (20px) 500 leading-relaxed
|
|
48
|
+
body: "text-base font-medium leading-relaxed",
|
|
49
|
+
// body-sm — text-sm (16px) 500 leading-normal
|
|
50
|
+
"body-sm": "text-sm font-medium leading-normal",
|
|
51
|
+
// caption — text-xs (14px, the AAA floor) 500 leading-normal
|
|
52
|
+
caption: "text-xs font-medium leading-normal",
|
|
53
|
+
},
|
|
54
|
+
// Color is orthogonal to size so a tone change can never smuggle in a
|
|
55
|
+
// scale change. Both pairs are wcag:audit-enforced AAA.
|
|
56
|
+
tone: {
|
|
57
|
+
default: "text-foreground",
|
|
58
|
+
muted: "text-muted-foreground",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
variant: "body",
|
|
63
|
+
tone: "default",
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export interface TextProps
|
|
69
|
+
extends React.HTMLAttributes<HTMLElement>,
|
|
70
|
+
VariantProps<typeof textVariants> {
|
|
71
|
+
/**
|
|
72
|
+
* The rendered element — semantics only, never styling. `p` for
|
|
73
|
+
* paragraphs (default), `span` for inline runs, `div` for blocks that
|
|
74
|
+
* will contain flow content a <p> can't legally hold.
|
|
75
|
+
*/
|
|
76
|
+
as?: "p" | "span" | "div";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function Text({ className, as: Comp = "p", variant, tone, ...props }: TextProps) {
|
|
80
|
+
return (
|
|
81
|
+
<Comp
|
|
82
|
+
data-slot="text"
|
|
83
|
+
className={cn(textVariants({ variant, tone }), className)}
|
|
84
|
+
{...props}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const headingVariants = cva(
|
|
90
|
+
"min-w-0 [overflow-wrap:anywhere] text-foreground",
|
|
91
|
+
{
|
|
92
|
+
variants: {
|
|
93
|
+
// 1:1 with tokens.json textStyles.heading-* — the names ARE the
|
|
94
|
+
// token names, so "which size is a page title" is answered by the
|
|
95
|
+
// token layer, not by memory of pixel values.
|
|
96
|
+
size: {
|
|
97
|
+
// heading-sm — text-lg (25px) 500: drawer titles, sub-heads
|
|
98
|
+
sm: "text-lg font-medium leading-normal",
|
|
99
|
+
// heading-md — text-xl (31px) 700: card titles, sub-section heads
|
|
100
|
+
md: "text-xl font-bold leading-snug",
|
|
101
|
+
// heading-lg — text-2xl (39px) 700: page titles
|
|
102
|
+
lg: "text-2xl font-bold leading-snug",
|
|
103
|
+
// heading-xl — text-3xl (49px) 700: hero subheads (top of the
|
|
104
|
+
// body scale — the next Tailwind step, text-4xl, is SMALLER)
|
|
105
|
+
xl: "text-3xl font-bold leading-tight",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
defaultVariants: {
|
|
109
|
+
size: "md",
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export interface HeadingProps
|
|
115
|
+
extends React.HTMLAttributes<HTMLHeadingElement>,
|
|
116
|
+
VariantProps<typeof headingVariants> {
|
|
117
|
+
/**
|
|
118
|
+
* The document-outline level — semantics only. Pick it from the page
|
|
119
|
+
* structure (one h1, nested sections step down one level), then set the
|
|
120
|
+
* visual `size` independently.
|
|
121
|
+
*/
|
|
122
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function Heading({ className, as: Comp = "h2", size, ...props }: HeadingProps) {
|
|
126
|
+
return (
|
|
127
|
+
<Comp
|
|
128
|
+
data-slot="heading"
|
|
129
|
+
className={cn(headingVariants({ size }), className)}
|
|
130
|
+
{...props}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { Text, Heading, textVariants, headingVariants };
|
|
@@ -2,17 +2,81 @@ import * as React from "react"
|
|
|
2
2
|
|
|
3
3
|
import { cn } from "../../lib/utils"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
interface TextareaProps extends React.ComponentProps<"textarea"> {
|
|
6
|
+
/** Show a character count below the textarea. Default false. */
|
|
7
|
+
showCount?: boolean
|
|
8
|
+
/**
|
|
9
|
+
* Maximum character length. When provided with `showCount`, the counter
|
|
10
|
+
* reads "n / max" and the textarea receives `maxLength` natively.
|
|
11
|
+
* When provided without `showCount`, acts as a standard `maxLength` attribute.
|
|
12
|
+
*/
|
|
13
|
+
maxLength?: number
|
|
14
|
+
/** Label id for the character count `<output>` element. Auto-derived when omitted. */
|
|
15
|
+
countId?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function Textarea({
|
|
19
|
+
className,
|
|
20
|
+
showCount = false,
|
|
21
|
+
maxLength,
|
|
22
|
+
countId,
|
|
23
|
+
onChange,
|
|
24
|
+
defaultValue,
|
|
25
|
+
value,
|
|
26
|
+
...props
|
|
27
|
+
}: TextareaProps) {
|
|
28
|
+
const autoCountId = React.useId()
|
|
29
|
+
const resolvedCountId = countId ?? autoCountId
|
|
30
|
+
|
|
31
|
+
// Track character length only when showCount is active (avoid unnecessary renders).
|
|
32
|
+
const [length, setLength] = React.useState<number>(() => {
|
|
33
|
+
if (!showCount) return 0
|
|
34
|
+
const initial = value ?? defaultValue ?? ""
|
|
35
|
+
return String(initial).length
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
function handleChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
|
|
39
|
+
if (showCount) setLength(e.target.value.length)
|
|
40
|
+
onChange?.(e)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const textarea = (
|
|
7
44
|
<textarea
|
|
8
45
|
data-slot="textarea"
|
|
46
|
+
maxLength={maxLength}
|
|
47
|
+
aria-describedby={showCount ? resolvedCountId : undefined}
|
|
9
48
|
className={cn(
|
|
10
49
|
"flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
|
|
11
50
|
className
|
|
12
51
|
)}
|
|
52
|
+
value={value}
|
|
53
|
+
defaultValue={defaultValue}
|
|
54
|
+
onChange={handleChange}
|
|
13
55
|
{...props}
|
|
14
56
|
/>
|
|
15
57
|
)
|
|
58
|
+
|
|
59
|
+
if (!showCount) return textarea
|
|
60
|
+
|
|
61
|
+
const atLimit = maxLength != null && length >= maxLength
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div data-slot="textarea-wrapper" className="flex flex-col gap-1">
|
|
65
|
+
{textarea}
|
|
66
|
+
<output
|
|
67
|
+
id={resolvedCountId}
|
|
68
|
+
aria-live="polite"
|
|
69
|
+
aria-atomic="true"
|
|
70
|
+
className={cn(
|
|
71
|
+
"self-end text-xs text-muted-foreground tabular-nums",
|
|
72
|
+
atLimit && "text-destructive"
|
|
73
|
+
)}
|
|
74
|
+
>
|
|
75
|
+
{maxLength != null ? `${length} / ${maxLength}` : length}
|
|
76
|
+
</output>
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
16
79
|
}
|
|
17
80
|
|
|
18
81
|
export { Textarea }
|
|
82
|
+
export type { TextareaProps }
|
|
@@ -9,6 +9,16 @@ import { cn } from "../../lib/utils";
|
|
|
9
9
|
|
|
10
10
|
export type TimelineStatus = "default" | "complete" | "active" | "pending";
|
|
11
11
|
|
|
12
|
+
export type TimelineOrientation = "vertical" | "alternate";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Orientation flows from the Timeline root to each TimelineItem via context so
|
|
16
|
+
* the item API stays unchanged. Defaults to "vertical" — an item rendered
|
|
17
|
+
* outside a Timeline behaves exactly as before.
|
|
18
|
+
*/
|
|
19
|
+
const TimelineOrientationContext =
|
|
20
|
+
React.createContext<TimelineOrientation>("vertical");
|
|
21
|
+
|
|
12
22
|
// ─── Variants ─────────────────────────────────────────────────────────────────
|
|
13
23
|
|
|
14
24
|
const dotVariants = cva(
|
|
@@ -31,17 +41,40 @@ const dotVariants = cva(
|
|
|
31
41
|
|
|
32
42
|
// ─── Root ─────────────────────────────────────────────────────────────────────
|
|
33
43
|
|
|
34
|
-
export interface TimelineProps extends React.HTMLAttributes<HTMLOListElement> {
|
|
44
|
+
export interface TimelineProps extends React.HTMLAttributes<HTMLOListElement> {
|
|
45
|
+
/**
|
|
46
|
+
* Layout orientation.
|
|
47
|
+
*
|
|
48
|
+
* - `"vertical"` (default) — the classic left-rail layout: dots on the left,
|
|
49
|
+
* one content column. Unchanged from previous releases.
|
|
50
|
+
* - `"alternate"` — a centered vertical spine with consecutive items
|
|
51
|
+
* alternating left/right of it (cf. MUI `position="alternate"`, Ant Design
|
|
52
|
+
* `mode="alternate"`). Applies at the `md` breakpoint and up; on narrower
|
|
53
|
+
* viewports it gracefully falls back to the vertical layout, since
|
|
54
|
+
* alternating columns don't fit. Alternation is CSS-only — the `<ol>`/`<li>`
|
|
55
|
+
* DOM and reading order stay top-to-bottom for screen readers and keyboard
|
|
56
|
+
* users regardless of orientation.
|
|
57
|
+
*/
|
|
58
|
+
orientation?: TimelineOrientation;
|
|
59
|
+
}
|
|
35
60
|
|
|
36
|
-
export function Timeline({
|
|
61
|
+
export function Timeline({
|
|
62
|
+
className,
|
|
63
|
+
children,
|
|
64
|
+
orientation = "vertical",
|
|
65
|
+
...props
|
|
66
|
+
}: TimelineProps) {
|
|
37
67
|
return (
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
<TimelineOrientationContext.Provider value={orientation}>
|
|
69
|
+
<ol
|
|
70
|
+
data-slot="timeline"
|
|
71
|
+
data-orientation={orientation === "alternate" ? "alternate" : undefined}
|
|
72
|
+
className={cn("relative space-y-0", className)}
|
|
73
|
+
{...props}
|
|
74
|
+
>
|
|
75
|
+
{children}
|
|
76
|
+
</ol>
|
|
77
|
+
</TimelineOrientationContext.Provider>
|
|
45
78
|
);
|
|
46
79
|
}
|
|
47
80
|
|
|
@@ -88,11 +121,23 @@ export function TimelineItem({
|
|
|
88
121
|
? <CheckIcon className="size-3" strokeWidth={1.5} aria-hidden />
|
|
89
122
|
: null;
|
|
90
123
|
|
|
124
|
+
// "alternate" repositions dot/connector onto a centered spine and flips the
|
|
125
|
+
// content column per :nth-child odd/even — CSS-only, gated on md:+ so narrow
|
|
126
|
+
// viewports keep the vertical layout. When "vertical" (the default), every
|
|
127
|
+
// conditional below is false and the rendered output is identical to
|
|
128
|
+
// previous releases.
|
|
129
|
+
const orientation = React.useContext(TimelineOrientationContext);
|
|
130
|
+
const alternate = orientation === "alternate";
|
|
131
|
+
|
|
91
132
|
return (
|
|
92
133
|
<li
|
|
93
134
|
data-slot="timeline-item"
|
|
94
135
|
data-status={status}
|
|
95
|
-
className={cn(
|
|
136
|
+
className={cn(
|
|
137
|
+
"group relative pb-6 pl-8 last:pb-0",
|
|
138
|
+
alternate && "md:pl-0",
|
|
139
|
+
className
|
|
140
|
+
)}
|
|
96
141
|
{...props}
|
|
97
142
|
>
|
|
98
143
|
{/* Connector line: runs from below the dot to the bottom of the item.
|
|
@@ -103,7 +148,8 @@ export function TimelineItem({
|
|
|
103
148
|
className={cn(
|
|
104
149
|
"absolute left-[9px] top-5 bottom-0 w-px",
|
|
105
150
|
"group-last:hidden",
|
|
106
|
-
status === "pending" ? "bg-border/30" : "bg-border"
|
|
151
|
+
status === "pending" ? "bg-border/30" : "bg-border",
|
|
152
|
+
alternate && "md:left-1/2 md:-translate-x-1/2"
|
|
107
153
|
)}
|
|
108
154
|
style={{
|
|
109
155
|
transitionProperty: "background-color",
|
|
@@ -116,7 +162,10 @@ export function TimelineItem({
|
|
|
116
162
|
<span
|
|
117
163
|
aria-hidden
|
|
118
164
|
data-slot="timeline-dot"
|
|
119
|
-
className={cn(
|
|
165
|
+
className={cn(
|
|
166
|
+
dotVariants({ status }),
|
|
167
|
+
alternate && "md:left-1/2 md:-translate-x-1/2"
|
|
168
|
+
)}
|
|
120
169
|
style={{
|
|
121
170
|
transitionProperty: "background-color, border-color",
|
|
122
171
|
transitionDuration: "var(--duration-fast)",
|
|
@@ -126,8 +175,16 @@ export function TimelineItem({
|
|
|
126
175
|
{resolvedIcon}
|
|
127
176
|
</span>
|
|
128
177
|
|
|
129
|
-
{/* Content
|
|
130
|
-
|
|
178
|
+
{/* Content — in alternate mode, odd items take the left half (text
|
|
179
|
+
aligned toward the spine), even items the right half. */}
|
|
180
|
+
<div
|
|
181
|
+
data-slot="timeline-content"
|
|
182
|
+
className={cn(
|
|
183
|
+
"min-w-0 pt-0.5",
|
|
184
|
+
alternate &&
|
|
185
|
+
"md:w-1/2 md:group-odd:pr-8 md:group-odd:text-right md:group-even:ml-auto md:group-even:pl-8"
|
|
186
|
+
)}
|
|
187
|
+
>
|
|
131
188
|
{title && (
|
|
132
189
|
<p
|
|
133
190
|
data-slot="timeline-title"
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Timer — a live countdown or count-up display that ticks on a configurable
|
|
9
|
+
* interval (the Ark UI Timer / Ant Design Statistic-countdown shape).
|
|
10
|
+
* Distinct from Stat (static value), Progress (visual fill), and
|
|
11
|
+
* FormatNumber (formatting without ticking).
|
|
12
|
+
*
|
|
13
|
+
* Drift-free ticking: each run anchors a `Date.now()` timestamp and derives
|
|
14
|
+
* the displayed value from wall-clock elapsed time, so a throttled or busy
|
|
15
|
+
* tab can delay a repaint but never accumulate error. Pausing freezes the
|
|
16
|
+
* current value; resuming re-anchors from it.
|
|
17
|
+
*
|
|
18
|
+
* Accessibility: the ticking digits are `aria-live="off"` — announcing
|
|
19
|
+
* every second is unusable noise for screen-reader users. Completion is the
|
|
20
|
+
* one event worth announcing: a visually hidden `role="status"` region
|
|
21
|
+
* (polite) appears when a countdown reaches zero. Digits render
|
|
22
|
+
* `tabular-nums` so the display doesn't jitter as values change.
|
|
23
|
+
*
|
|
24
|
+
* State surface: `data-state="running" | "paused" | "completed"` for CSS
|
|
25
|
+
* and test targeting. Paused dims to `text-muted-foreground` via a
|
|
26
|
+
* token-driven color transition — the visible state change is animated, the
|
|
27
|
+
* per-second digit swap deliberately is not (a transition on every tick
|
|
28
|
+
* would smear the digits).
|
|
29
|
+
*
|
|
30
|
+
* Ethics note (registry `ethicsContract`, darkPatternRisk medium):
|
|
31
|
+
* countdowns are the classic fake-scarcity surface. Only bind a Timer to a
|
|
32
|
+
* REAL deadline (session expiry, meeting start, rate-limit window). A
|
|
33
|
+
* countdown that resets on reload, or that pressures a purchase with an
|
|
34
|
+
* invented deadline, is a dark pattern — the ethics floor refuses it.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export type TimerFormat = "HH:MM:SS" | "MM:SS" | "SS" | ((ms: number) => string)
|
|
38
|
+
|
|
39
|
+
export interface TimerProps
|
|
40
|
+
extends Omit<React.ComponentProps<"span">, "children" | "onComplete"> {
|
|
41
|
+
/** "countdown" ticks toward zero and completes; "countup" ticks upward forever. Default "countdown". */
|
|
42
|
+
mode?: "countdown" | "countup"
|
|
43
|
+
/**
|
|
44
|
+
* Starting value in milliseconds — the time remaining for a countdown, or
|
|
45
|
+
* the already-elapsed offset for a count-up (usually 0). Default 0.
|
|
46
|
+
*/
|
|
47
|
+
startMs?: number
|
|
48
|
+
/** Tick interval in milliseconds. Default 1000. */
|
|
49
|
+
intervalMs?: number
|
|
50
|
+
/**
|
|
51
|
+
* Start ticking on mount (default true). With `autoStart={false}` the
|
|
52
|
+
* timer holds at `startMs` until a `paused={false}` prop starts it.
|
|
53
|
+
*/
|
|
54
|
+
autoStart?: boolean
|
|
55
|
+
/** Pause/resume control. When provided it wins over `autoStart`. */
|
|
56
|
+
paused?: boolean
|
|
57
|
+
/** Fires every tick with the current value (remaining ms for countdown, elapsed ms for count-up). */
|
|
58
|
+
onTick?: (ms: number) => void
|
|
59
|
+
/** Fires once when a countdown reaches zero. Never fires in count-up mode. */
|
|
60
|
+
onComplete?: () => void
|
|
61
|
+
/** Display format. A preset string or a custom `(ms) => string`. Default "MM:SS". */
|
|
62
|
+
format?: TimerFormat
|
|
63
|
+
/** Screen-reader announcement when a countdown completes. Default "Time is up". */
|
|
64
|
+
completeAnnouncement?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function pad(value: number): string {
|
|
68
|
+
return String(value).padStart(2, "0")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function formatMs(ms: number, format: TimerFormat): string {
|
|
72
|
+
if (typeof format === "function") return format(ms)
|
|
73
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1000))
|
|
74
|
+
switch (format) {
|
|
75
|
+
case "HH:MM:SS": {
|
|
76
|
+
const hours = Math.floor(totalSeconds / 3600)
|
|
77
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
78
|
+
const seconds = totalSeconds % 60
|
|
79
|
+
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`
|
|
80
|
+
}
|
|
81
|
+
case "SS":
|
|
82
|
+
return String(totalSeconds)
|
|
83
|
+
case "MM:SS":
|
|
84
|
+
default: {
|
|
85
|
+
const minutes = Math.floor(totalSeconds / 60)
|
|
86
|
+
const seconds = totalSeconds % 60
|
|
87
|
+
return `${pad(minutes)}:${pad(seconds)}`
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function Timer({
|
|
93
|
+
mode = "countdown",
|
|
94
|
+
startMs = 0,
|
|
95
|
+
intervalMs = 1000,
|
|
96
|
+
autoStart = true,
|
|
97
|
+
paused,
|
|
98
|
+
onTick,
|
|
99
|
+
onComplete,
|
|
100
|
+
format = "MM:SS",
|
|
101
|
+
completeAnnouncement = "Time is up",
|
|
102
|
+
className,
|
|
103
|
+
style,
|
|
104
|
+
...props
|
|
105
|
+
}: TimerProps) {
|
|
106
|
+
const [displayMs, setDisplayMs] = React.useState(startMs)
|
|
107
|
+
const [completed, setCompleted] = React.useState(
|
|
108
|
+
mode === "countdown" && startMs <= 0
|
|
109
|
+
)
|
|
110
|
+
// Latest value lives in a ref so a resume can re-anchor from it without
|
|
111
|
+
// the effect depending on displayMs (which would reset the interval every
|
|
112
|
+
// tick).
|
|
113
|
+
const msRef = React.useRef(startMs)
|
|
114
|
+
const onTickRef = React.useRef(onTick)
|
|
115
|
+
const onCompleteRef = React.useRef(onComplete)
|
|
116
|
+
onTickRef.current = onTick
|
|
117
|
+
onCompleteRef.current = onComplete
|
|
118
|
+
|
|
119
|
+
// `paused` prop wins when provided; otherwise autoStart decides.
|
|
120
|
+
const isPaused = paused ?? !autoStart
|
|
121
|
+
const running = !completed && !isPaused
|
|
122
|
+
|
|
123
|
+
React.useEffect(() => {
|
|
124
|
+
if (!running) return
|
|
125
|
+
// Anchor wall-clock time at (re)start — drift-free regardless of how
|
|
126
|
+
// late the interval callbacks actually fire.
|
|
127
|
+
const anchor = Date.now()
|
|
128
|
+
const baseMs = msRef.current
|
|
129
|
+
const tick = () => {
|
|
130
|
+
const elapsed = Date.now() - anchor
|
|
131
|
+
const next =
|
|
132
|
+
mode === "countdown"
|
|
133
|
+
? Math.max(0, baseMs - elapsed)
|
|
134
|
+
: baseMs + elapsed
|
|
135
|
+
msRef.current = next
|
|
136
|
+
setDisplayMs(next)
|
|
137
|
+
onTickRef.current?.(next)
|
|
138
|
+
if (mode === "countdown" && next <= 0) {
|
|
139
|
+
setCompleted(true)
|
|
140
|
+
onCompleteRef.current?.()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const id = window.setInterval(tick, intervalMs)
|
|
144
|
+
return () => window.clearInterval(id)
|
|
145
|
+
}, [running, intervalMs, mode])
|
|
146
|
+
|
|
147
|
+
const state = completed ? "completed" : isPaused ? "paused" : "running"
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<span
|
|
151
|
+
data-slot="timer"
|
|
152
|
+
data-state={state}
|
|
153
|
+
className={cn(
|
|
154
|
+
// State-change (running ⇄ paused ⇄ completed) animates via a
|
|
155
|
+
// token-driven color transition; the per-tick digit swap does not.
|
|
156
|
+
"inline-flex items-center font-medium tabular-nums transition-colors",
|
|
157
|
+
"text-foreground data-[state=paused]:text-muted-foreground",
|
|
158
|
+
className
|
|
159
|
+
)}
|
|
160
|
+
style={{
|
|
161
|
+
transitionDuration: "var(--duration-base)",
|
|
162
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
163
|
+
...style,
|
|
164
|
+
}}
|
|
165
|
+
{...props}
|
|
166
|
+
>
|
|
167
|
+
{/* aria-live="off": per-second announcements are unusable noise. The
|
|
168
|
+
value stays readable on demand in the a11y tree. */}
|
|
169
|
+
<span data-slot="timer-value" aria-live="off">
|
|
170
|
+
{formatMs(displayMs, format)}
|
|
171
|
+
</span>
|
|
172
|
+
{/* Entering the DOM on completion triggers exactly one polite
|
|
173
|
+
announcement — the only tick worth interrupting for. */}
|
|
174
|
+
{completed && (
|
|
175
|
+
<span data-slot="timer-announcement" role="status" className="sr-only">
|
|
176
|
+
{completeAnnouncement}
|
|
177
|
+
</span>
|
|
178
|
+
)}
|
|
179
|
+
</span>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { Timer }
|