@behavioral-agentic-design-system/core 0.8.4 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { ChevronDownIcon } from "lucide-react"
5
+ import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"
6
+
7
+ import { cn } from "../../lib/utils"
8
+
9
+ function NavigationMenu({
10
+ className,
11
+ children,
12
+ viewport = true,
13
+ ...props
14
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Root> & {
15
+ viewport?: boolean
16
+ }) {
17
+ return (
18
+ <NavigationMenuPrimitive.Root
19
+ data-slot="navigation-menu"
20
+ data-viewport={viewport}
21
+ className={cn(
22
+ "group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
23
+ className
24
+ )}
25
+ {...props}
26
+ >
27
+ {children}
28
+ {viewport && <NavigationMenuViewport />}
29
+ </NavigationMenuPrimitive.Root>
30
+ )
31
+ }
32
+
33
+ function NavigationMenuList({
34
+ className,
35
+ ...props
36
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
37
+ return (
38
+ <NavigationMenuPrimitive.List
39
+ data-slot="navigation-menu-list"
40
+ className={cn(
41
+ "group flex flex-1 list-none items-center justify-center gap-1",
42
+ className
43
+ )}
44
+ {...props}
45
+ />
46
+ )
47
+ }
48
+
49
+ function NavigationMenuItem({
50
+ ...props
51
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
52
+ return (
53
+ <NavigationMenuPrimitive.Item data-slot="navigation-menu-item" {...props} />
54
+ )
55
+ }
56
+
57
+ function NavigationMenuTrigger({
58
+ className,
59
+ children,
60
+ ...props
61
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>) {
62
+ return (
63
+ <NavigationMenuPrimitive.Trigger
64
+ data-slot="navigation-menu-trigger"
65
+ className={cn(
66
+ "group inline-flex h-9 w-max items-center justify-center gap-1 rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-hidden disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[state=open]:bg-accent/50",
67
+ className
68
+ )}
69
+ {...props}
70
+ >
71
+ {children}
72
+ <ChevronDownIcon
73
+ className="relative top-[1px] ml-1 size-3 transition-transform duration-200 group-data-[state=open]:rotate-180"
74
+ aria-hidden="true"
75
+ strokeWidth={1.5}
76
+ />
77
+ </NavigationMenuPrimitive.Trigger>
78
+ )
79
+ }
80
+
81
+ function NavigationMenuContent({
82
+ className,
83
+ ...props
84
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
85
+ return (
86
+ <NavigationMenuPrimitive.Content
87
+ data-slot="navigation-menu-content"
88
+ className={cn(
89
+ "left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto",
90
+ className
91
+ )}
92
+ {...props}
93
+ />
94
+ )
95
+ }
96
+
97
+ function NavigationMenuLink({
98
+ ...props
99
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
100
+ return (
101
+ <NavigationMenuPrimitive.Link data-slot="navigation-menu-link" {...props} />
102
+ )
103
+ }
104
+
105
+ function NavigationMenuViewport({
106
+ className,
107
+ ...props
108
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Viewport>) {
109
+ return (
110
+ <div
111
+ className={cn(
112
+ "absolute left-0 top-full flex justify-center"
113
+ )}
114
+ >
115
+ <NavigationMenuPrimitive.Viewport
116
+ data-slot="navigation-menu-viewport"
117
+ className={cn(
118
+ "origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 md:w-[var(--radix-navigation-menu-viewport-width)]",
119
+ className
120
+ )}
121
+ {...props}
122
+ />
123
+ </div>
124
+ )
125
+ }
126
+
127
+ function NavigationMenuIndicator({
128
+ className,
129
+ ...props
130
+ }: React.ComponentProps<typeof NavigationMenuPrimitive.Indicator>) {
131
+ return (
132
+ <NavigationMenuPrimitive.Indicator
133
+ data-slot="navigation-menu-indicator"
134
+ className={cn(
135
+ "top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:animate-in data-[state=visible]:fade-in",
136
+ className
137
+ )}
138
+ {...props}
139
+ >
140
+ <div className="relative top-[60%] size-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
141
+ </NavigationMenuPrimitive.Indicator>
142
+ )
143
+ }
144
+
145
+ export {
146
+ NavigationMenu,
147
+ NavigationMenuList,
148
+ NavigationMenuItem,
149
+ NavigationMenuTrigger,
150
+ NavigationMenuContent,
151
+ NavigationMenuLink,
152
+ NavigationMenuViewport,
153
+ NavigationMenuIndicator,
154
+ }
@@ -0,0 +1,229 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { Minus, Plus } from "lucide-react";
6
+
7
+ import { cn } from "../../lib/utils";
8
+
9
+ // ─── Variants ─────────────────────────────────────────────────────────────────
10
+
11
+ const numberInputVariants = cva(
12
+ [
13
+ "flex items-stretch overflow-hidden",
14
+ "rounded-md border border-input bg-transparent shadow-xs",
15
+ "transition-[color,box-shadow]",
16
+ "focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
17
+ ],
18
+ {
19
+ variants: {
20
+ size: {
21
+ sm: "h-9 text-sm",
22
+ default: "h-11 text-base",
23
+ lg: "h-14 text-xl",
24
+ },
25
+ },
26
+ defaultVariants: { size: "default" },
27
+ }
28
+ );
29
+
30
+ // ─── Types ────────────────────────────────────────────────────────────────────
31
+
32
+ export interface NumberInputProps
33
+ extends Omit<
34
+ React.InputHTMLAttributes<HTMLInputElement>,
35
+ "value" | "defaultValue" | "onChange" | "size" | "type"
36
+ >,
37
+ VariantProps<typeof numberInputVariants> {
38
+ /** Controlled value */
39
+ value?: number;
40
+ /** Uncontrolled default */
41
+ defaultValue?: number;
42
+ /** Fires with the new number after each committed change */
43
+ onChange?: (value: number) => void;
44
+ min?: number;
45
+ max?: number;
46
+ /** Amount to increment/decrement per step (default 1) */
47
+ step?: number;
48
+ disabled?: boolean;
49
+ className?: string;
50
+ }
51
+
52
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
53
+
54
+ function clamp(value: number, min: number, max: number) {
55
+ return Math.min(Math.max(value, min), max);
56
+ }
57
+
58
+ // ─── NumberInput ──────────────────────────────────────────────────────────────
59
+
60
+ function NumberInput({
61
+ value: valueProp,
62
+ defaultValue = 0,
63
+ onChange,
64
+ min = -Infinity,
65
+ max = Infinity,
66
+ step = 1,
67
+ disabled = false,
68
+ size,
69
+ className,
70
+ "aria-label": ariaLabel = "Number input",
71
+ "aria-labelledby": ariaLabelledBy,
72
+ ...rest
73
+ }: NumberInputProps) {
74
+ const isControlled = valueProp !== undefined;
75
+
76
+ const [localValue, setLocalValue] = React.useState<number>(
77
+ isControlled ? (valueProp ?? 0) : defaultValue
78
+ );
79
+ const value = isControlled ? (valueProp ?? 0) : localValue;
80
+
81
+ // Input display string (may diverge from value during typing)
82
+ const [inputStr, setInputStr] = React.useState(String(value));
83
+ const lastCommittedRef = React.useRef(value);
84
+
85
+ // Sync display string when external controlled value changes
86
+ React.useEffect(() => {
87
+ if (isControlled && valueProp !== lastCommittedRef.current) {
88
+ lastCommittedRef.current = valueProp ?? 0;
89
+ setInputStr(String(valueProp ?? 0));
90
+ }
91
+ }, [isControlled, valueProp]);
92
+
93
+ // ── commit a new value ─────────────────────────────────────────────────────
94
+
95
+ const commit = React.useCallback(
96
+ (next: number) => {
97
+ const clamped = clamp(next, min, max);
98
+ lastCommittedRef.current = clamped;
99
+ setInputStr(String(clamped));
100
+ if (!isControlled) setLocalValue(clamped);
101
+ onChange?.(clamped);
102
+ },
103
+ [min, max, isControlled, onChange]
104
+ );
105
+
106
+ const increment = () => commit(value + step);
107
+ const decrement = () => commit(value - step);
108
+
109
+ // ── keyboard handling ──────────────────────────────────────────────────────
110
+
111
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
112
+ if (e.key === "ArrowUp") {
113
+ e.preventDefault();
114
+ increment();
115
+ } else if (e.key === "ArrowDown") {
116
+ e.preventDefault();
117
+ decrement();
118
+ } else if (e.key === "PageUp") {
119
+ e.preventDefault();
120
+ commit(value + step * 10);
121
+ } else if (e.key === "PageDown") {
122
+ e.preventDefault();
123
+ commit(value - step * 10);
124
+ } else if (e.key === "Home" && Number.isFinite(min)) {
125
+ e.preventDefault();
126
+ commit(min);
127
+ } else if (e.key === "End" && Number.isFinite(max)) {
128
+ e.preventDefault();
129
+ commit(max);
130
+ }
131
+ };
132
+
133
+ // ── text change (during typing) ────────────────────────────────────────────
134
+
135
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
136
+ setInputStr(e.target.value);
137
+ };
138
+
139
+ // ── blur: commit typed value or reset ─────────────────────────────────────
140
+
141
+ const handleBlur = () => {
142
+ const parsed = parseFloat(inputStr);
143
+ if (Number.isFinite(parsed)) {
144
+ commit(parsed);
145
+ } else {
146
+ setInputStr(String(value));
147
+ }
148
+ };
149
+
150
+ const atMin = Number.isFinite(min) && value <= min;
151
+ const atMax = Number.isFinite(max) && value >= max;
152
+
153
+ const stepButtonClass = cn(
154
+ "flex shrink-0 items-center justify-center px-2.5",
155
+ "text-muted-foreground outline-none",
156
+ "hover:bg-accent hover:text-accent-foreground",
157
+ "focus-visible:bg-accent focus-visible:text-accent-foreground",
158
+ "disabled:pointer-events-none disabled:opacity-40",
159
+ "transition-colors"
160
+ );
161
+
162
+ return (
163
+ <div
164
+ data-slot="number-input"
165
+ className={cn(numberInputVariants({ size }), className)}
166
+ style={{
167
+ transitionDuration: "var(--duration-fast)",
168
+ transitionTimingFunction: "var(--ease-out)",
169
+ }}
170
+ >
171
+ <button
172
+ type="button"
173
+ data-slot="number-input-decrement"
174
+ aria-label="Decrement"
175
+ disabled={disabled || atMin}
176
+ onClick={decrement}
177
+ tabIndex={-1}
178
+ className={cn(stepButtonClass, "border-r border-input")}
179
+ style={{
180
+ transitionDuration: "var(--duration-fast)",
181
+ transitionTimingFunction: "var(--ease-out)",
182
+ }}
183
+ >
184
+ <Minus strokeWidth={1.5} className="size-4" />
185
+ </button>
186
+
187
+ <input
188
+ data-slot="number-input-field"
189
+ role="spinbutton"
190
+ type="text"
191
+ inputMode="decimal"
192
+ aria-valuenow={Number.isFinite(value) ? value : undefined}
193
+ aria-valuemin={Number.isFinite(min) ? min : undefined}
194
+ aria-valuemax={Number.isFinite(max) ? max : undefined}
195
+ aria-label={ariaLabelledBy ? undefined : ariaLabel}
196
+ aria-labelledby={ariaLabelledBy}
197
+ disabled={disabled}
198
+ value={inputStr}
199
+ onChange={handleChange}
200
+ onBlur={handleBlur}
201
+ onKeyDown={handleKeyDown}
202
+ className={cn(
203
+ "min-w-0 flex-1 bg-transparent text-center font-sans tabular-nums text-foreground",
204
+ "outline-none placeholder:text-muted-foreground",
205
+ "disabled:pointer-events-none disabled:opacity-50"
206
+ )}
207
+ {...rest}
208
+ />
209
+
210
+ <button
211
+ type="button"
212
+ data-slot="number-input-increment"
213
+ aria-label="Increment"
214
+ disabled={disabled || atMax}
215
+ onClick={increment}
216
+ tabIndex={-1}
217
+ className={cn(stepButtonClass, "border-l border-input")}
218
+ style={{
219
+ transitionDuration: "var(--duration-fast)",
220
+ transitionTimingFunction: "var(--ease-out)",
221
+ }}
222
+ >
223
+ <Plus strokeWidth={1.5} className="size-4" />
224
+ </button>
225
+ </div>
226
+ );
227
+ }
228
+
229
+ export { NumberInput, numberInputVariants };
@@ -0,0 +1,143 @@
1
+ import * as React from "react"
2
+ import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"
3
+
4
+ import { cn } from "../../lib/utils"
5
+ import { buttonVariants } from "./button"
6
+
7
+ function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
8
+ return (
9
+ <nav
10
+ role="navigation"
11
+ aria-label="pagination"
12
+ data-slot="pagination"
13
+ className={cn("mx-auto flex w-full justify-center", className)}
14
+ {...props}
15
+ />
16
+ )
17
+ }
18
+
19
+ function PaginationContent({
20
+ className,
21
+ ...props
22
+ }: React.ComponentProps<"ul">) {
23
+ return (
24
+ <ul
25
+ data-slot="pagination-content"
26
+ className={cn("flex flex-row items-center gap-1", className)}
27
+ {...props}
28
+ />
29
+ )
30
+ }
31
+
32
+ function PaginationItem({ className, ...props }: React.ComponentProps<"li">) {
33
+ return (
34
+ <li
35
+ data-slot="pagination-item"
36
+ className={cn("", className)}
37
+ {...props}
38
+ />
39
+ )
40
+ }
41
+
42
+ type PaginationLinkProps = {
43
+ isActive?: boolean
44
+ disabled?: boolean
45
+ } & React.ComponentProps<"a">
46
+
47
+ function PaginationLink({
48
+ className,
49
+ isActive,
50
+ disabled,
51
+ ...props
52
+ }: PaginationLinkProps) {
53
+ return (
54
+ <a
55
+ aria-current={isActive ? "page" : undefined}
56
+ aria-disabled={disabled || undefined}
57
+ data-slot="pagination-link"
58
+ data-active={isActive}
59
+ className={cn(
60
+ buttonVariants({
61
+ variant: isActive ? "default" : "ghost",
62
+ size: "icon",
63
+ }),
64
+ "min-h-11 min-w-11",
65
+ disabled && "pointer-events-none opacity-50",
66
+ className
67
+ )}
68
+ {...props}
69
+ />
70
+ )
71
+ }
72
+
73
+ function PaginationPrevious({
74
+ className,
75
+ disabled,
76
+ ...props
77
+ }: React.ComponentProps<typeof PaginationLink>) {
78
+ return (
79
+ <PaginationLink
80
+ aria-label="Previous page"
81
+ disabled={disabled}
82
+ className={cn(
83
+ "w-auto gap-1 px-4 text-sm font-medium min-h-11",
84
+ className
85
+ )}
86
+ {...props}
87
+ >
88
+ <ChevronLeft strokeWidth={1.5} className="size-4" />
89
+ <span>Previous</span>
90
+ </PaginationLink>
91
+ )
92
+ }
93
+
94
+ function PaginationNext({
95
+ className,
96
+ disabled,
97
+ ...props
98
+ }: React.ComponentProps<typeof PaginationLink>) {
99
+ return (
100
+ <PaginationLink
101
+ aria-label="Next page"
102
+ disabled={disabled}
103
+ className={cn(
104
+ "w-auto gap-1 px-4 text-sm font-medium min-h-11",
105
+ className
106
+ )}
107
+ {...props}
108
+ >
109
+ <span>Next</span>
110
+ <ChevronRight strokeWidth={1.5} className="size-4" />
111
+ </PaginationLink>
112
+ )
113
+ }
114
+
115
+ function PaginationEllipsis({
116
+ className,
117
+ ...props
118
+ }: React.ComponentProps<"span">) {
119
+ return (
120
+ <span
121
+ aria-hidden
122
+ data-slot="pagination-ellipsis"
123
+ className={cn(
124
+ "flex min-h-11 min-w-11 items-center justify-center text-muted-foreground",
125
+ className
126
+ )}
127
+ {...props}
128
+ >
129
+ <MoreHorizontal strokeWidth={1.5} className="size-4" />
130
+ <span className="sr-only">More pages</span>
131
+ </span>
132
+ )
133
+ }
134
+
135
+ export {
136
+ Pagination,
137
+ PaginationContent,
138
+ PaginationEllipsis,
139
+ PaginationItem,
140
+ PaginationLink,
141
+ PaginationNext,
142
+ PaginationPrevious,
143
+ }