@behavioral-agentic-design-system/core 0.12.2 → 0.14.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.
@@ -0,0 +1,158 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { CalendarIcon, XIcon } from "lucide-react"
5
+
6
+ import { cn } from "../../lib/utils"
7
+ import { Calendar } from "./calendar"
8
+ import {
9
+ Popover,
10
+ PopoverContent,
11
+ PopoverTrigger,
12
+ } from "./popover"
13
+
14
+ export interface DatePickerProps {
15
+ value?: Date
16
+ onValueChange?: (date: Date | undefined) => void
17
+ placeholder?: string
18
+ disabled?: boolean
19
+ clearable?: boolean
20
+ size?: "sm" | "default" | "lg"
21
+ className?: string
22
+ /** Forward to DayPicker: earliest selectable date */
23
+ fromDate?: Date
24
+ /** Forward to DayPicker: latest selectable date */
25
+ toDate?: Date
26
+ }
27
+
28
+ const sizeMap = {
29
+ sm: { height: "h-8", px: "px-2.5", text: "text-sm", gap: "gap-1.5", icon: 14 },
30
+ default: { height: "h-9", px: "px-3", text: "text-sm", gap: "gap-2", icon: 16 },
31
+ lg: { height: "h-10", px: "px-4", text: "text-base", gap: "gap-2", icon: 16 },
32
+ } as const
33
+
34
+ function formatDate(date: Date): string {
35
+ return date.toLocaleDateString("en-US", {
36
+ month: "short",
37
+ day: "numeric",
38
+ year: "numeric",
39
+ })
40
+ }
41
+
42
+ function DatePicker({
43
+ value,
44
+ onValueChange,
45
+ placeholder = "Pick a date",
46
+ disabled = false,
47
+ clearable = false,
48
+ size = "default",
49
+ className,
50
+ fromDate,
51
+ toDate,
52
+ }: DatePickerProps) {
53
+ const [open, setOpen] = React.useState(false)
54
+ const [internalDate, setInternalDate] = React.useState<Date | undefined>(
55
+ undefined
56
+ )
57
+
58
+ const isControlled = value !== undefined || onValueChange !== undefined
59
+ const selectedDate = isControlled ? value : internalDate
60
+
61
+ function handleSelect(date: Date | undefined) {
62
+ if (!isControlled) {
63
+ setInternalDate(date)
64
+ }
65
+ onValueChange?.(date)
66
+ if (date) setOpen(false)
67
+ }
68
+
69
+ function handleClear(e: React.MouseEvent) {
70
+ e.stopPropagation()
71
+ handleSelect(undefined)
72
+ }
73
+
74
+ const { height, px, text, gap, icon: iconSize } = sizeMap[size]
75
+
76
+ return (
77
+ <Popover open={open} onOpenChange={disabled ? undefined : setOpen}>
78
+ {/*
79
+ Outer div carries all visual chrome (border, rounded, bg, shadow).
80
+ focus-within shows the ring when either the trigger OR clear button is focused —
81
+ consistent with how compound inputs (e.g. search with clear) behave.
82
+ The clear button must be a sibling of the trigger, NOT nested inside it,
83
+ to satisfy the axe-core `nested-interactive` rule.
84
+ */}
85
+ <div
86
+ data-slot="date-picker-root"
87
+ data-size={size}
88
+ className={cn(
89
+ "inline-flex w-full min-w-0 items-center rounded-md border border-input bg-transparent shadow-xs",
90
+ "focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
91
+ disabled && "pointer-events-none cursor-not-allowed opacity-50",
92
+ height,
93
+ px,
94
+ gap,
95
+ className
96
+ )}
97
+ >
98
+ <PopoverTrigger asChild>
99
+ <button
100
+ type="button"
101
+ data-slot="date-picker-trigger"
102
+ disabled={disabled}
103
+ aria-haspopup="dialog"
104
+ aria-expanded={open}
105
+ aria-label={selectedDate ? formatDate(selectedDate) : placeholder}
106
+ style={{
107
+ transitionDuration: "var(--duration-fast)",
108
+ transitionTimingFunction: "var(--ease-out)",
109
+ }}
110
+ className={cn(
111
+ "inline-flex flex-1 min-w-0 h-full items-center text-left font-normal bg-transparent outline-none",
112
+ "transition-[color]",
113
+ gap,
114
+ text,
115
+ !selectedDate && "text-muted-foreground"
116
+ )}
117
+ >
118
+ <CalendarIcon
119
+ size={iconSize}
120
+ strokeWidth={1.5}
121
+ className="shrink-0 text-muted-foreground"
122
+ />
123
+ <span className="flex-1 truncate">
124
+ {selectedDate ? formatDate(selectedDate) : placeholder}
125
+ </span>
126
+ </button>
127
+ </PopoverTrigger>
128
+ {clearable && selectedDate ? (
129
+ <button
130
+ type="button"
131
+ aria-label="Clear date"
132
+ onClick={handleClear}
133
+ disabled={disabled}
134
+ style={{
135
+ transitionDuration: "var(--duration-fast)",
136
+ transitionTimingFunction: "var(--ease-out)",
137
+ }}
138
+ className="shrink-0 -mr-1 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
139
+ >
140
+ <XIcon size={iconSize - 2} strokeWidth={1.5} />
141
+ </button>
142
+ ) : null}
143
+ </div>
144
+ <PopoverContent className="w-auto p-0" align="start">
145
+ <Calendar
146
+ mode="single"
147
+ selected={selectedDate}
148
+ onSelect={handleSelect}
149
+ fromDate={fromDate}
150
+ toDate={toDate}
151
+ initialFocus
152
+ />
153
+ </PopoverContent>
154
+ </Popover>
155
+ )
156
+ }
157
+
158
+ export { DatePicker }
@@ -12,6 +12,7 @@ export * from "./breadcrumb";
12
12
  export * from "./button";
13
13
  export * from "./calendar";
14
14
  export * from "./card";
15
+ export * from "./date-picker";
15
16
  export * from "./chart";
16
17
  export * from "./checkbox";
17
18
  export * from "./collapsible";
@@ -31,6 +32,7 @@ export * from "./pagination";
31
32
  export * from "./popover";
32
33
  export * from "./progress";
33
34
  export * from "./radio-group";
35
+ export * from "./rating-group";
34
36
  export * from "./resizable";
35
37
  export * from "./scroll-area";
36
38
  export * from "./select";
@@ -47,6 +49,9 @@ export * from "./switch";
47
49
  export * from "./table";
48
50
  export * from "./tabs";
49
51
  export * from "./tag";
52
+ export * from "./segmented-control";
53
+ export * from "./tags-input";
54
+ export * from "./timeline";
50
55
  export * from "./textarea";
51
56
  export * from "./toggle";
52
57
  export * from "./toggle-group";
@@ -0,0 +1,126 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { StarIcon } from "lucide-react"
5
+
6
+ import { cn } from "../../lib/utils"
7
+
8
+ export interface RatingGroupProps {
9
+ value?: number
10
+ onValueChange?: (value: number) => void
11
+ max?: number
12
+ disabled?: boolean
13
+ readOnly?: boolean
14
+ size?: "sm" | "default" | "lg"
15
+ className?: string
16
+ /** Accessible label for the group */
17
+ label?: string
18
+ }
19
+
20
+ const sizeMap = {
21
+ sm: { icon: 16, gap: "gap-0.5" },
22
+ default: { icon: 20, gap: "gap-1" },
23
+ lg: { icon: 28, gap: "gap-1.5" },
24
+ } as const
25
+
26
+ function RatingGroup({
27
+ value,
28
+ onValueChange,
29
+ max = 5,
30
+ disabled = false,
31
+ readOnly = false,
32
+ size = "default",
33
+ className,
34
+ label = "Rating",
35
+ }: RatingGroupProps) {
36
+ const [internalValue, setInternalValue] = React.useState(0)
37
+ const [hoverValue, setHoverValue] = React.useState(0)
38
+
39
+ const isControlled = value !== undefined
40
+ const currentValue = isControlled ? (value ?? 0) : internalValue
41
+ const displayValue = hoverValue > 0 ? hoverValue : currentValue
42
+
43
+ const { icon: iconSize, gap } = sizeMap[size]
44
+
45
+ function handleSelect(star: number) {
46
+ if (disabled || readOnly) return
47
+ if (!isControlled) setInternalValue(star)
48
+ onValueChange?.(star)
49
+ }
50
+
51
+ function handleKeyDown(e: React.KeyboardEvent, star: number) {
52
+ if (disabled || readOnly) return
53
+ if (e.key === "ArrowRight" || e.key === "ArrowUp") {
54
+ e.preventDefault()
55
+ const next = Math.min(star + 1, max)
56
+ handleSelect(next)
57
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
58
+ e.preventDefault()
59
+ const prev = Math.max(star - 1, 1)
60
+ handleSelect(prev)
61
+ } else if (e.key === "Home") {
62
+ e.preventDefault()
63
+ handleSelect(1)
64
+ } else if (e.key === "End") {
65
+ e.preventDefault()
66
+ handleSelect(max)
67
+ }
68
+ }
69
+
70
+ return (
71
+ <div
72
+ role="radiogroup"
73
+ aria-label={label}
74
+ aria-disabled={disabled || undefined}
75
+ aria-readonly={readOnly || undefined}
76
+ data-slot="rating-group"
77
+ data-size={size}
78
+ className={cn("inline-flex items-center", gap, className)}
79
+ onMouseLeave={() => setHoverValue(0)}
80
+ >
81
+ {Array.from({ length: max }, (_, i) => {
82
+ const star = i + 1
83
+ const isFilled = star <= displayValue
84
+ const isSelected = star <= currentValue
85
+
86
+ return (
87
+ <button
88
+ key={star}
89
+ type="button"
90
+ role="radio"
91
+ aria-checked={isSelected}
92
+ aria-label={`${star} of ${max}`}
93
+ tabIndex={disabled || readOnly ? -1 : isSelected || (currentValue === 0 && star === 1) ? 0 : -1}
94
+ disabled={disabled}
95
+ data-slot="rating-item"
96
+ data-filled={isFilled || undefined}
97
+ style={{ transitionDuration: "var(--duration-fast)", transitionTimingFunction: "var(--ease-out)" }}
98
+ className={cn(
99
+ "min-h-[24px] min-w-[24px] flex items-center justify-center rounded-sm outline-none",
100
+ "transition-[color,transform]",
101
+ "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
102
+ disabled
103
+ ? "cursor-not-allowed opacity-40"
104
+ : readOnly
105
+ ? "cursor-default"
106
+ : "cursor-pointer hover:scale-110",
107
+ isFilled ? "text-primary" : "text-muted-foreground/40"
108
+ )}
109
+ onClick={() => handleSelect(star)}
110
+ onMouseEnter={() => !disabled && !readOnly && setHoverValue(star)}
111
+ onKeyDown={(e) => handleKeyDown(e, currentValue || 1)}
112
+ >
113
+ <StarIcon
114
+ size={iconSize}
115
+ strokeWidth={1.5}
116
+ fill={isFilled ? "currentColor" : "none"}
117
+ aria-hidden="true"
118
+ />
119
+ </button>
120
+ )
121
+ })}
122
+ </div>
123
+ )
124
+ }
125
+
126
+ export { RatingGroup }
@@ -0,0 +1,213 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { cn } from "../../lib/utils";
6
+
7
+ // ─── Context ──────────────────────────────────────────────────────────────────
8
+
9
+ interface SegmentedControlContextValue {
10
+ value: string;
11
+ onValueChange: (value: string) => void;
12
+ disabled: boolean;
13
+ size: "sm" | "default" | "lg";
14
+ }
15
+
16
+ const SegmentedControlContext = React.createContext<SegmentedControlContextValue>({
17
+ value: "",
18
+ onValueChange: () => {},
19
+ disabled: false,
20
+ size: "default",
21
+ });
22
+
23
+ // ─── Variants ─────────────────────────────────────────────────────────────────
24
+
25
+ const rootVariants = cva(
26
+ [
27
+ "relative inline-grid rounded-lg bg-muted p-1",
28
+ ],
29
+ {
30
+ variants: {
31
+ size: {
32
+ sm: "gap-0.5",
33
+ default: "gap-0.5",
34
+ lg: "gap-0.5",
35
+ },
36
+ },
37
+ defaultVariants: { size: "default" },
38
+ }
39
+ );
40
+
41
+ const itemVariants = cva(
42
+ [
43
+ "relative z-10 inline-flex cursor-pointer select-none items-center justify-center whitespace-nowrap rounded-md",
44
+ "font-medium text-muted-foreground",
45
+ "transition-colors",
46
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
47
+ "disabled:pointer-events-none disabled:opacity-50",
48
+ "aria-checked:text-foreground",
49
+ "hover:text-foreground",
50
+ ],
51
+ {
52
+ variants: {
53
+ size: {
54
+ sm: "px-2.5 min-h-8 text-xs",
55
+ default: "px-3 min-h-11 text-sm",
56
+ lg: "px-4 min-h-12 text-sm",
57
+ },
58
+ },
59
+ defaultVariants: { size: "default" },
60
+ }
61
+ );
62
+
63
+ // ─── Root ─────────────────────────────────────────────────────────────────────
64
+
65
+ export interface SegmentedControlProps
66
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
67
+ /** The currently selected value. */
68
+ value: string;
69
+ /** Callback fired when the selected value changes. */
70
+ onValueChange: (value: string) => void;
71
+ /** Visual + size variant. */
72
+ size?: "sm" | "default" | "lg";
73
+ /** Disables all items. */
74
+ disabled?: boolean;
75
+ /** Accessible label for the radio group. */
76
+ label?: string;
77
+ }
78
+
79
+ export function SegmentedControl({
80
+ value,
81
+ onValueChange,
82
+ size = "default",
83
+ disabled = false,
84
+ label,
85
+ className,
86
+ children,
87
+ ...props
88
+ }: SegmentedControlProps) {
89
+ // Count valid SegmentedControlItem children to calculate indicator geometry
90
+ const items = React.Children.toArray(children).filter(
91
+ (child): child is React.ReactElement<SegmentedControlItemProps> =>
92
+ React.isValidElement(child)
93
+ );
94
+ const count = items.length;
95
+ const selectedIndex = items.findIndex((item) => item.props.value === value);
96
+
97
+ // Roving tabindex: track focused item index so ArrowLeft/Right works across items
98
+ const rootRef = React.useRef<HTMLDivElement>(null);
99
+
100
+ const handleKeyDown = React.useCallback(
101
+ (e: React.KeyboardEvent<HTMLDivElement>) => {
102
+ if (!rootRef.current) return;
103
+ const buttons = Array.from(
104
+ rootRef.current.querySelectorAll<HTMLButtonElement>("[role=radio]:not([disabled])")
105
+ );
106
+ const focusedIdx = buttons.findIndex((b) => b === document.activeElement);
107
+ if (focusedIdx === -1) return;
108
+
109
+ let next = focusedIdx;
110
+ if (e.key === "ArrowRight" || e.key === "ArrowDown") {
111
+ next = (focusedIdx + 1) % buttons.length;
112
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
113
+ next = (focusedIdx - 1 + buttons.length) % buttons.length;
114
+ } else if (e.key === "Home") {
115
+ next = 0;
116
+ } else if (e.key === "End") {
117
+ next = buttons.length - 1;
118
+ } else {
119
+ return;
120
+ }
121
+ e.preventDefault();
122
+ buttons[next]?.focus();
123
+ const nextValue = items.find((_, i) => {
124
+ const enabledItems = items.filter((item) => !item.props.disabled);
125
+ return enabledItems[next] === items[i];
126
+ });
127
+ const targetItem = items.filter((item) => !item.props.disabled)[next];
128
+ if (targetItem) onValueChange(targetItem.props.value);
129
+ },
130
+ [items, onValueChange]
131
+ );
132
+
133
+ return (
134
+ <SegmentedControlContext.Provider value={{ value, onValueChange, disabled, size }}>
135
+ <div
136
+ ref={rootRef}
137
+ role="radiogroup"
138
+ aria-label={label}
139
+ data-slot="segmented-control"
140
+ data-disabled={disabled || undefined}
141
+ onKeyDown={handleKeyDown}
142
+ className={cn(rootVariants({ size }), className)}
143
+ style={{ gridTemplateColumns: `repeat(${count}, 1fr)` }}
144
+ {...props}
145
+ >
146
+ {/* Sliding indicator — absolutely positioned, moves via left transition */}
147
+ {selectedIndex >= 0 && count > 0 && (
148
+ <div
149
+ aria-hidden
150
+ data-slot="segmented-control-indicator"
151
+ className="absolute inset-y-1 rounded-md bg-background shadow-sm pointer-events-none"
152
+ style={{
153
+ // width = (containerWidth - 2*p-1 gap) / count
154
+ width: `calc((100% - 8px) / ${count})`,
155
+ // left = p-1(4px) + selectedIndex * (itemWidth + gap)
156
+ left: `calc(${selectedIndex} * (100% - 8px) / ${count} + 4px)`,
157
+ transitionProperty: "left",
158
+ transitionDuration: "var(--duration-fast)",
159
+ transitionTimingFunction: "var(--ease-out)",
160
+ }}
161
+ />
162
+ )}
163
+ {children}
164
+ </div>
165
+ </SegmentedControlContext.Provider>
166
+ );
167
+ }
168
+
169
+ // ─── Item ─────────────────────────────────────────────────────────────────────
170
+
171
+ export interface SegmentedControlItemProps
172
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
173
+ /** The value this item represents. */
174
+ value: string;
175
+ /** Icon to render before the label. Must be a Lucide icon with strokeWidth={1.5}. */
176
+ icon?: React.ReactNode;
177
+ }
178
+
179
+ export function SegmentedControlItem({
180
+ value,
181
+ icon,
182
+ className,
183
+ disabled,
184
+ children,
185
+ ...props
186
+ }: SegmentedControlItemProps) {
187
+ const { value: selectedValue, onValueChange, disabled: groupDisabled, size } =
188
+ React.useContext(SegmentedControlContext);
189
+ const isSelected = selectedValue === value;
190
+ const isDisabled = groupDisabled || disabled;
191
+
192
+ return (
193
+ <button
194
+ type="button"
195
+ role="radio"
196
+ aria-checked={isSelected}
197
+ data-slot="segmented-control-item"
198
+ data-state={isSelected ? "on" : "off"}
199
+ disabled={isDisabled}
200
+ tabIndex={isSelected ? 0 : -1}
201
+ onClick={() => {
202
+ if (!isDisabled) onValueChange(value);
203
+ }}
204
+ className={cn(itemVariants({ size }), className)}
205
+ {...props}
206
+ >
207
+ {icon && (
208
+ <span className="mr-1.5 shrink-0 [&>svg]:size-4 [&>svg]:stroke-[1.5]">{icon}</span>
209
+ )}
210
+ {children}
211
+ </button>
212
+ );
213
+ }
@@ -165,6 +165,12 @@ function StepperIndicator({
165
165
  ...(state === "active" && {
166
166
  borderColor: "var(--primary)",
167
167
  }),
168
+ // Error matches the active/completed pattern: inline so the
169
+ // destructive color resolves regardless of the @theme cascade
170
+ // (the `border-destructive` class alone falls back to gray).
171
+ ...(state === "error" && {
172
+ borderColor: "var(--destructive)",
173
+ }),
168
174
  }}
169
175
  {...props}
170
176
  >
@@ -193,9 +199,11 @@ function StepperTitle({
193
199
  data-state={state}
194
200
  className={cn(
195
201
  "text-sm font-medium leading-tight",
196
- state === "active" || state === "completed"
197
- ? "text-foreground"
198
- : "text-muted-foreground",
202
+ state === "error"
203
+ ? "text-destructive"
204
+ : state === "active" || state === "completed"
205
+ ? "text-foreground"
206
+ : "text-muted-foreground",
199
207
  className
200
208
  )}
201
209
  {...props}
@@ -106,7 +106,7 @@ function TabsList({
106
106
  className={cn(
107
107
  tabsListVariants({ variant }),
108
108
  scrollable &&
109
- "overflow-x-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden data-[overflowing]:[mask-image:linear-gradient(to_right,#000_calc(100%-2rem),transparent)]",
109
+ "overflow-x-auto scrollbar-none data-[overflowing]:[mask-image:linear-gradient(to_right,#000_calc(100%-2rem),transparent)]",
110
110
  className
111
111
  )}
112
112
  {...props}