@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.
Files changed (131) hide show
  1. package/package.json +5 -2
  2. package/scripts/build-tokens.cjs +79 -5
  3. package/src/app/preview/components/page.tsx +4474 -208
  4. package/src/app/shell.tsx +18 -6
  5. package/src/components/customize/brand-mark-section.tsx +1 -1
  6. package/src/components/customize-tab.tsx +2 -2
  7. package/src/components/home-tab.tsx +2 -2
  8. package/src/components/ui/action-bar.tsx +142 -0
  9. package/src/components/ui/affix.tsx +109 -0
  10. package/src/components/ui/alert.tsx +37 -3
  11. package/src/components/ui/anchor.tsx +136 -0
  12. package/src/components/ui/angle-slider.tsx +265 -0
  13. package/src/components/ui/autocomplete.tsx +223 -0
  14. package/src/components/ui/avatar.tsx +8 -2
  15. package/src/components/ui/blockquote.tsx +112 -0
  16. package/src/components/ui/bottom-navigation.tsx +144 -0
  17. package/src/components/ui/burger.tsx +117 -0
  18. package/src/components/ui/button.tsx +101 -3
  19. package/src/components/ui/calendar.tsx +1 -1
  20. package/src/components/ui/card.tsx +43 -5
  21. package/src/components/ui/carousel.tsx +10 -5
  22. package/src/components/ui/cascader.tsx +253 -0
  23. package/src/components/ui/checkbox-card.tsx +176 -0
  24. package/src/components/ui/checkbox-group.tsx +231 -0
  25. package/src/components/ui/checkbox.tsx +14 -3
  26. package/src/components/ui/chip.tsx +143 -0
  27. package/src/components/ui/circular-progress.tsx +2 -2
  28. package/src/components/ui/color-swatch.tsx +73 -0
  29. package/src/components/ui/copy-button.tsx +21 -4
  30. package/src/components/ui/date-picker.tsx +6 -3
  31. package/src/components/ui/date-range-picker.tsx +6 -3
  32. package/src/components/ui/float-label.tsx +114 -0
  33. package/src/components/ui/floating-panel.tsx +129 -0
  34. package/src/components/ui/format-number.tsx +122 -0
  35. package/src/components/ui/highlight.tsx +85 -0
  36. package/src/components/ui/image.tsx +195 -0
  37. package/src/components/ui/index.ts +50 -0
  38. package/src/components/ui/indicator.tsx +2 -2
  39. package/src/components/ui/input.tsx +48 -4
  40. package/src/components/ui/kbd.tsx +1 -1
  41. package/src/components/ui/link.tsx +158 -0
  42. package/src/components/ui/listbox.tsx +426 -0
  43. package/src/components/ui/loading-overlay.tsx +80 -0
  44. package/src/components/ui/marquee.tsx +193 -0
  45. package/src/components/ui/masonry.tsx +164 -0
  46. package/src/components/ui/meter.tsx +186 -0
  47. package/src/components/ui/motion-toggle.tsx +170 -0
  48. package/src/components/ui/notification.tsx +175 -0
  49. package/src/components/ui/overlay.tsx +63 -0
  50. package/src/components/ui/progress.tsx +95 -4
  51. package/src/components/ui/rating-group.tsx +1 -0
  52. package/src/components/ui/separator.tsx +57 -1
  53. package/src/components/ui/sidebar.tsx +1 -1
  54. package/src/components/ui/signature-pad.tsx +381 -0
  55. package/src/components/ui/skeleton.tsx +59 -2
  56. package/src/components/ui/skip-link.tsx +117 -0
  57. package/src/components/ui/slider.tsx +86 -1
  58. package/src/components/ui/spoiler.tsx +131 -0
  59. package/src/components/ui/tabs.tsx +1 -1
  60. package/src/components/ui/text.tsx +135 -0
  61. package/src/components/ui/textarea.tsx +66 -2
  62. package/src/components/ui/timeline.tsx +71 -14
  63. package/src/components/ui/timer.tsx +183 -0
  64. package/src/components/ui/tour.tsx +332 -0
  65. package/src/components/ui/transfer-list.tsx +308 -0
  66. package/src/components/ui/visually-hidden.tsx +42 -0
  67. package/src/components/ui/watermark.tsx +0 -0
  68. package/src/data/docs-index.ts +9 -2
  69. package/src/stories/ActionBar.stories.tsx +201 -0
  70. package/src/stories/Affix.stories.tsx +165 -0
  71. package/src/stories/Alert.stories.tsx +58 -0
  72. package/src/stories/Anchor.stories.tsx +236 -0
  73. package/src/stories/AngleSlider.stories.tsx +128 -0
  74. package/src/stories/Autocomplete.stories.tsx +216 -0
  75. package/src/stories/Avatar.stories.tsx +73 -1
  76. package/src/stories/Blockquote.stories.tsx +148 -0
  77. package/src/stories/BottomNavigation.stories.tsx +195 -0
  78. package/src/stories/Burger.stories.tsx +79 -0
  79. package/src/stories/Button.stories.tsx +103 -2
  80. package/src/stories/Calendar.stories.tsx +4 -0
  81. package/src/stories/Card.stories.tsx +30 -0
  82. package/src/stories/Carousel.stories.tsx +2 -1
  83. package/src/stories/Cascader.stories.tsx +285 -0
  84. package/src/stories/Checkbox.stories.tsx +13 -0
  85. package/src/stories/CheckboxCard.stories.tsx +210 -0
  86. package/src/stories/CheckboxGroup.stories.tsx +186 -0
  87. package/src/stories/Chip.stories.tsx +173 -0
  88. package/src/stories/CircularProgress.stories.tsx +3 -0
  89. package/src/stories/ColorSwatch.stories.tsx +81 -0
  90. package/src/stories/CopyButton.stories.tsx +3 -3
  91. package/src/stories/DatePicker.stories.tsx +3 -0
  92. package/src/stories/DateRangePicker.stories.tsx +3 -0
  93. package/src/stories/Editable.stories.tsx +14 -0
  94. package/src/stories/FloatLabel.stories.tsx +148 -0
  95. package/src/stories/FloatingPanel.stories.tsx +176 -0
  96. package/src/stories/FormatNumber.stories.tsx +308 -0
  97. package/src/stories/Highlight.stories.tsx +140 -0
  98. package/src/stories/Image.stories.tsx +141 -0
  99. package/src/stories/Indicator.stories.tsx +3 -0
  100. package/src/stories/Input.stories.tsx +33 -0
  101. package/src/stories/Kbd.stories.tsx +3 -0
  102. package/src/stories/Link.stories.tsx +198 -0
  103. package/src/stories/Listbox.stories.tsx +240 -0
  104. package/src/stories/LoadingOverlay.stories.tsx +148 -0
  105. package/src/stories/Marquee.stories.tsx +170 -0
  106. package/src/stories/Masonry.stories.tsx +227 -0
  107. package/src/stories/Meter.stories.tsx +143 -0
  108. package/src/stories/MotionToggle.stories.tsx +85 -0
  109. package/src/stories/Notification.stories.tsx +264 -0
  110. package/src/stories/Overlay.stories.tsx +169 -0
  111. package/src/stories/PasswordInput.stories.tsx +4 -0
  112. package/src/stories/Progress.stories.tsx +70 -27
  113. package/src/stories/RatingGroup.stories.tsx +5 -0
  114. package/src/stories/Separator.stories.tsx +41 -5
  115. package/src/stories/Sidebar.stories.tsx +2 -1
  116. package/src/stories/SignaturePad.stories.tsx +112 -0
  117. package/src/stories/Skeleton.stories.tsx +23 -4
  118. package/src/stories/SkipLink.stories.tsx +137 -0
  119. package/src/stories/Slider.stories.tsx +28 -0
  120. package/src/stories/Spoiler.stories.tsx +122 -0
  121. package/src/stories/Tabs.stories.tsx +2 -1
  122. package/src/stories/Text.stories.tsx +191 -0
  123. package/src/stories/Textarea.stories.tsx +58 -6
  124. package/src/stories/Timeline.stories.tsx +82 -0
  125. package/src/stories/Timer.stories.tsx +160 -0
  126. package/src/stories/Tour.stories.tsx +191 -0
  127. package/src/stories/TransferList.stories.tsx +169 -0
  128. package/src/stories/VisuallyHidden.stories.tsx +105 -0
  129. package/src/stories/Watermark.stories.tsx +212 -0
  130. package/src/styles.css +80 -6
  131. package/src/tokens.json +2 -2
@@ -0,0 +1,85 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ /**
8
+ * Escape regex-special characters so raw user input (search queries,
9
+ * filter terms) can never break — or worse, alter — the match pattern.
10
+ * `.` `*` `+` `?` `^` `$` `{` `}` `(` `)` `|` `[` `]` `\` are all literalized.
11
+ */
12
+ function escapeRegExp(value: string): string {
13
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
14
+ }
15
+
16
+ export interface HighlightProps
17
+ extends Omit<React.ComponentProps<"span">, "children"> {
18
+ /**
19
+ * Substring(s) to mark inside `children`. Matching is case-insensitive
20
+ * and safe against regex-special characters. Empty / whitespace-only
21
+ * terms are ignored — an empty query renders the text unchanged.
22
+ */
23
+ highlight: string | string[]
24
+ /**
25
+ * The full text to search. A plain string (not ReactNode) so matching
26
+ * semantics are a compile-time guarantee.
27
+ */
28
+ children: string
29
+ /** Extra classes merged onto every `<mark>` (e.g. a subtler fork tint). */
30
+ markClassName?: string
31
+ }
32
+
33
+ /**
34
+ * Wraps every case-insensitive occurrence of `highlight` inside `children`
35
+ * in a semantic `<mark>` styled with the audited `primary` /
36
+ * `primary-foreground` token pair (15.79:1, AAA in both modes).
37
+ *
38
+ * Display-only: `<mark>` carries no focus, keyboard, or target-size
39
+ * contract, and most screen readers do not announce it — never make the
40
+ * highlight the sole carrier of "this matched"; pair it with a result
41
+ * count or a filtered list.
42
+ */
43
+ function Highlight({
44
+ highlight,
45
+ children,
46
+ markClassName,
47
+ className,
48
+ ...props
49
+ }: HighlightProps) {
50
+ const terms = (Array.isArray(highlight) ? highlight : [highlight]).filter(
51
+ (term) => term.trim().length > 0
52
+ )
53
+
54
+ let content: React.ReactNode = children
55
+ if (terms.length > 0) {
56
+ // One capture group around the whole alternation: String.split keeps
57
+ // the captured matches in the result at odd indices — no RegExp
58
+ // lastIndex statefulness, no re-testing of chunks.
59
+ const pattern = new RegExp(`(${terms.map(escapeRegExp).join("|")})`, "gi")
60
+ content = children.split(pattern).map((chunk, index) =>
61
+ index % 2 === 1 ? (
62
+ <mark
63
+ key={index}
64
+ data-slot="highlight-mark"
65
+ className={cn(
66
+ "rounded-sm bg-primary px-0.5 text-primary-foreground",
67
+ markClassName
68
+ )}
69
+ >
70
+ {chunk}
71
+ </mark>
72
+ ) : (
73
+ chunk
74
+ )
75
+ )
76
+ }
77
+
78
+ return (
79
+ <span data-slot="highlight" className={className} {...props}>
80
+ {content}
81
+ </span>
82
+ )
83
+ }
84
+
85
+ export { Highlight }
@@ -0,0 +1,195 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { ImageOff } from "lucide-react"
5
+
6
+ import { cn } from "../../lib/utils"
7
+ import { Skeleton } from "./skeleton"
8
+
9
+ /**
10
+ * Image — image display primitive with fallback, aspect ratio, and lazy
11
+ * loading.
12
+ *
13
+ * Wraps a native img element with the three behaviors every product surface
14
+ * re-rolls by hand: a Skeleton while the image loads, a token-styled fallback
15
+ * when the src is broken (the accessible name survives via `role="img"` +
16
+ * `aria-label`), and an optional CSS `aspect-ratio` frame so layouts don't
17
+ * shift when the image arrives. Loads lazily by default.
18
+ *
19
+ * Display-only: no focus, keyboard, or target-size contract (like Text). The
20
+ * only motion is a token-driven opacity fade-in on load (pattern c), which
21
+ * the base layer collapses under prefers-reduced-motion.
22
+ *
23
+ * NOT a lightbox (zoom/preview is a separate concern) and NOT a `next/image`
24
+ * substitute — there's no optimization pipeline here; pass an already-sized
25
+ * URL as `src`.
26
+ */
27
+
28
+ type ImageProps = Omit<React.ComponentProps<"img">, "alt"> & {
29
+ /**
30
+ * Alternative text. Required at the type level — pass `""` explicitly for
31
+ * a purely decorative image.
32
+ */
33
+ alt: string
34
+ /** Fixed aspect ratio for the frame, e.g. `"16/9"`, `"4/3"`, `"1/1"` or a number. */
35
+ ratio?: number | `${number}/${number}`
36
+ /** How the image fills the frame. Default `"cover"`. */
37
+ fit?: "cover" | "contain" | "fill"
38
+ /** Token radius on the frame. Default `"md"`. */
39
+ radius?: "none" | "sm" | "md" | "lg" | "full"
40
+ /**
41
+ * Rendered when the image fails to load. A string renders as styled text;
42
+ * a node renders as-is (own its semantics). Default: a muted ImageOff
43
+ * glyph, with the accessible name kept via `role="img"` + `aria-label`.
44
+ */
45
+ fallback?: React.ReactNode
46
+ /** Native lazy loading. Default `true`. */
47
+ lazy?: boolean
48
+ /** Caption below the image. Promotes the root to a semantic `<figure>`. */
49
+ caption?: React.ReactNode
50
+ }
51
+
52
+ const fitClasses = {
53
+ cover: "object-cover",
54
+ contain: "object-contain",
55
+ fill: "object-fill",
56
+ } as const
57
+
58
+ const radiusClasses = {
59
+ none: "rounded-none",
60
+ sm: "rounded-sm",
61
+ md: "rounded-md",
62
+ lg: "rounded-lg",
63
+ full: "rounded-full",
64
+ } as const
65
+
66
+ type LoadStatus = "loading" | "loaded" | "error"
67
+
68
+ function Image({
69
+ className,
70
+ alt,
71
+ ratio,
72
+ fit = "cover",
73
+ radius = "md",
74
+ fallback,
75
+ lazy = true,
76
+ caption,
77
+ src,
78
+ onLoad,
79
+ onError,
80
+ ...props
81
+ }: ImageProps) {
82
+ const [status, setStatus] = React.useState<LoadStatus>(src ? "loading" : "error")
83
+ const imgRef = React.useRef<HTMLImageElement | null>(null)
84
+
85
+ // Reset the state machine when the src changes.
86
+ React.useEffect(() => {
87
+ setStatus(src ? "loading" : "error")
88
+ }, [src])
89
+
90
+ // Cached images can complete before hydration, so the load event never
91
+ // reaches React — check completeness on mount or the skeleton sticks.
92
+ React.useEffect(() => {
93
+ const el = imgRef.current
94
+ if (el && el.complete) {
95
+ setStatus(el.naturalWidth > 0 ? "loaded" : "error")
96
+ }
97
+ }, [src])
98
+
99
+ const aspectRatio =
100
+ typeof ratio === "number" ? String(ratio) : ratio ? ratio.replace("/", " / ") : undefined
101
+
102
+ const showFallback = status === "error"
103
+ const fallbackIsNode = fallback != null && typeof fallback !== "string"
104
+
105
+ const frame = (
106
+ <div
107
+ data-slot="image-frame"
108
+ className={cn(
109
+ "relative w-full overflow-hidden bg-muted",
110
+ radiusClasses[radius],
111
+ // No ratio + still loading/error: give the frame a body so the
112
+ // skeleton/fallback isn't a zero-height sliver.
113
+ !aspectRatio && status !== "loaded" && "min-h-24"
114
+ )}
115
+ style={aspectRatio ? { aspectRatio } : undefined}
116
+ >
117
+ {status === "loading" && (
118
+ <Skeleton
119
+ data-slot="image-skeleton"
120
+ className="absolute inset-0 h-full w-full rounded-none"
121
+ />
122
+ )}
123
+ {!showFallback && (
124
+ <img
125
+ ref={imgRef}
126
+ data-slot="image"
127
+ data-state={status}
128
+ alt={alt}
129
+ src={src}
130
+ loading={lazy ? "lazy" : undefined}
131
+ onLoad={(event) => {
132
+ setStatus("loaded")
133
+ onLoad?.(event)
134
+ }}
135
+ onError={(event) => {
136
+ setStatus("error")
137
+ onError?.(event)
138
+ }}
139
+ className={cn(
140
+ "w-full transition-opacity",
141
+ aspectRatio ? "h-full" : "h-auto",
142
+ fitClasses[fit],
143
+ status === "loaded" ? "opacity-100" : "opacity-0"
144
+ )}
145
+ style={{
146
+ transitionDuration: "var(--duration-base)",
147
+ transitionTimingFunction: "var(--ease-out)",
148
+ }}
149
+ {...props}
150
+ />
151
+ )}
152
+ {showFallback &&
153
+ (fallbackIsNode ? (
154
+ <div data-slot="image-fallback" className={cn(aspectRatio && "absolute inset-0")}>
155
+ {fallback}
156
+ </div>
157
+ ) : (
158
+ <div
159
+ data-slot="image-fallback"
160
+ role="img"
161
+ aria-label={alt || undefined}
162
+ className={cn(
163
+ "flex flex-col items-center justify-center gap-2 p-4 text-muted-foreground",
164
+ aspectRatio ? "absolute inset-0" : "min-h-24"
165
+ )}
166
+ >
167
+ <ImageOff strokeWidth={1.5} className="size-5 shrink-0" aria-hidden="true" />
168
+ {typeof fallback === "string" && (
169
+ <span className="max-w-full truncate text-xs">{fallback}</span>
170
+ )}
171
+ </div>
172
+ ))}
173
+ </div>
174
+ )
175
+
176
+ if (caption != null) {
177
+ return (
178
+ <figure data-slot="image-root" className={cn("m-0 flex w-full flex-col gap-2", className)}>
179
+ {frame}
180
+ <figcaption data-slot="image-caption" className="text-xs text-muted-foreground">
181
+ {caption}
182
+ </figcaption>
183
+ </figure>
184
+ )
185
+ }
186
+
187
+ return (
188
+ <div data-slot="image-root" className={cn("w-full", className)}>
189
+ {frame}
190
+ </div>
191
+ )
192
+ }
193
+
194
+ export { Image }
195
+ export type { ImageProps }
@@ -3,11 +3,14 @@
3
3
  // import paths so optional peer deps stay optional.
4
4
  export * from "./accordion";
5
5
  export * from "./alert";
6
+ export * from "./angle-slider";
6
7
  export * from "./aspect-ratio";
7
8
  export * from "./carousel";
8
9
  export * from "./alert-dialog";
9
10
  export * from "./avatar";
10
11
  export * from "./badge";
12
+ export * from "./blockquote";
13
+ export * from "./bottom-navigation";
11
14
  export * from "./breadcrumb";
12
15
  export * from "./button";
13
16
  export * from "./calendar";
@@ -17,6 +20,7 @@ export * from "./chart";
17
20
  export * from "./checkbox";
18
21
  export * from "./collapsible";
19
22
  export * from "./color-picker";
23
+ export * from "./color-swatch";
20
24
  export * from "./command";
21
25
  export * from "./context-menu";
22
26
  export * from "./data-list";
@@ -29,8 +33,11 @@ export * from "./input";
29
33
  export * from "./input-group";
30
34
  export * from "./kbd";
31
35
  export * from "./label";
36
+ export * from "./link";
32
37
  export * from "./menubar";
38
+ export * from "./motion-toggle";
33
39
  export * from "./navigation-menu";
40
+ export * from "./notification";
34
41
  export * from "./number-input";
35
42
  export * from "./pagination";
36
43
  export * from "./password-input";
@@ -48,11 +55,13 @@ export * from "./skeleton";
48
55
  export * from "./slider";
49
56
  export * from "./sonner";
50
57
  export * from "./spinner";
58
+ export * from "./spoiler";
51
59
  export * from "./stepper";
52
60
  export * from "./switch";
53
61
  export * from "./table";
54
62
  export * from "./tabs";
55
63
  export * from "./tag";
64
+ export * from "./text";
56
65
  export * from "./segmented-control";
57
66
  export * from "./tags-input";
58
67
  export * from "./timeline";
@@ -64,3 +73,44 @@ export * from "./tooltip";
64
73
  export * from "./tree-view";
65
74
  export * from "./editable";
66
75
  export * from "./qr-code";
76
+ export * from "./highlight";
77
+ export * from "./format-number";
78
+ export * from "./autocomplete";
79
+ export * from "./button-group";
80
+ export * from "./checkbox-group";
81
+ export * from "./circular-progress";
82
+ export * from "./code";
83
+ export * from "./combobox";
84
+ export * from "./copy-button";
85
+ export * from "./date-range-picker";
86
+ export * from "./empty-state";
87
+ export * from "./field";
88
+ export * from "./indicator";
89
+ export * from "./list";
90
+ export * from "./marquee";
91
+ export * from "./multi-select";
92
+ export * from "./native-select";
93
+ export * from "./pin-input";
94
+ export * from "./time-picker";
95
+ export * from "./visually-hidden";
96
+ export * from "./meter";
97
+ export * from "./chip";
98
+ export * from "./transfer-list";
99
+ export * from "./burger";
100
+ export * from "./action-bar";
101
+ export * from "./checkbox-card";
102
+ export * from "./watermark";
103
+ export * from "./loading-overlay";
104
+ export * from "./float-label";
105
+ export * from "./tour";
106
+ export * from "./image";
107
+ export * from "./masonry";
108
+ export * from "./listbox";
109
+ export * from "./floating-panel";
110
+ export * from "./anchor";
111
+ export * from "./overlay";
112
+ export * from "./cascader";
113
+ export * from "./affix";
114
+ export * from "./skip-link";
115
+ export * from "./timer";
116
+ export * from "./signature-pad";
@@ -21,8 +21,8 @@ const indicatorDotVariants = cva(
21
21
  default: "bg-primary text-primary-foreground",
22
22
  secondary: "bg-secondary text-secondary-foreground",
23
23
  destructive: "bg-destructive text-white",
24
- success: "bg-[hsl(var(--success))] text-white",
25
- warning: "bg-[hsl(var(--warning))] text-white",
24
+ success: "bg-[var(--success)] text-white",
25
+ warning: "bg-[var(--warning)] text-white",
26
26
  },
27
27
  size: {
28
28
  // Dot-only base dimensions; labeled mode overrides height + min-width below
@@ -1,5 +1,6 @@
1
1
  import * as React from "react"
2
2
  import { cva, type VariantProps } from "class-variance-authority"
3
+ import { XIcon } from "lucide-react"
3
4
 
4
5
  import { cn } from "../../lib/utils"
5
6
 
@@ -21,22 +22,65 @@ const inputVariants = cva(
21
22
  }
22
23
  )
23
24
 
25
+ type InputProps = Omit<React.ComponentProps<"input">, "size"> &
26
+ VariantProps<typeof inputVariants> & {
27
+ /** When true, shows a dismiss (×) button on the right when the input has a value.
28
+ * Calls onChange with an empty string on click. Only meaningful for controlled inputs. */
29
+ clearable?: boolean
30
+ }
31
+
24
32
  function Input({
25
33
  className,
26
34
  type,
27
35
  size,
36
+ clearable,
37
+ value,
38
+ onChange,
39
+ disabled,
28
40
  ...props
29
- }: Omit<React.ComponentProps<"input">, "size"> &
30
- VariantProps<typeof inputVariants>) {
31
- return (
41
+ }: InputProps) {
42
+ const showClear = clearable && !disabled && value !== undefined && value !== ""
43
+
44
+ const inputEl = (
32
45
  <input
33
46
  type={type}
34
47
  data-slot="input"
35
48
  data-size={size ?? "default"}
36
- className={cn(inputVariants({ size, className }))}
49
+ className={cn(inputVariants({ size, className }), clearable && "pr-8")}
50
+ value={value}
51
+ onChange={onChange}
52
+ disabled={disabled}
37
53
  {...props}
38
54
  />
39
55
  )
56
+
57
+ if (!clearable) {
58
+ return inputEl
59
+ }
60
+
61
+ return (
62
+ <div className="relative">
63
+ {inputEl}
64
+ {showClear && (
65
+ <button
66
+ type="button"
67
+ aria-label="Clear input"
68
+ className="absolute right-1.5 top-1/2 -translate-y-1/2 inline-flex items-center justify-center size-6 rounded text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1"
69
+ style={{
70
+ transitionDuration: "var(--duration-fast)",
71
+ transitionTimingFunction: "var(--ease-out)",
72
+ }}
73
+ onClick={() => {
74
+ onChange?.({
75
+ target: { value: "" },
76
+ } as React.ChangeEvent<HTMLInputElement>)
77
+ }}
78
+ >
79
+ <XIcon size={14} strokeWidth={1.5} aria-hidden="true" />
80
+ </button>
81
+ )}
82
+ </div>
83
+ )
40
84
  }
41
85
 
42
86
  export { Input, inputVariants }
@@ -14,7 +14,7 @@ const kbdVariants = cva(
14
14
  {
15
15
  variants: {
16
16
  variant: {
17
- default: "border-border bg-muted shadow-[0_1px_0_1px_hsl(var(--border))]",
17
+ default: "border-border bg-muted shadow-[0_1px_0_1px_var(--border)]",
18
18
  outline: "border-border bg-background",
19
19
  },
20
20
  size: {
@@ -0,0 +1,158 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Slot } from "@radix-ui/react-slot";
5
+ import { cva, type VariantProps } from "class-variance-authority";
6
+ import { ExternalLinkIcon } from "lucide-react";
7
+
8
+ import { cn } from "../../lib/utils";
9
+
10
+ /**
11
+ * Navigation anchor primitive — a semantic `<a href>` with BADS' link
12
+ * discipline built in. Sources: MUI Link (the underline axis), Chakra UI
13
+ * Link (the external affordance), Mantine Anchor (inherit-the-context
14
+ * sizing). Distinct from `Button variant="link"`, which is a `<button>`
15
+ * for ACTIONS styled as links — `Link` is for navigation, stays
16
+ * `display: inline` so it wraps mid-sentence in prose, and inherits its
17
+ * font size from the surrounding text.
18
+ *
19
+ * <Text>
20
+ * Read the <Link href="/docs/getting-started">getting started guide</Link>
21
+ * before customizing tokens.
22
+ * </Text>
23
+ *
24
+ * <Link href="https://design.bads.com" external>design.bads.com</Link>
25
+ *
26
+ * <Link asChild><NextLink href="/customize">Customize</NextLink></Link>
27
+ *
28
+ * AAA notes baked into the defaults:
29
+ * - `underline="always"` is the default because color alone cannot mark a
30
+ * link inside prose (SC 1.4.1). `hover`/`none` are for chrome where
31
+ * position identifies the link (nav lists, footers, breadcrumb-likes).
32
+ * - The underline renders at 40% strength and solidifies on hover — the
33
+ * hover state-change, animated via `transition-colors` (which covers
34
+ * `text-decoration-color`) on `--duration-fast` + `--ease-out`.
35
+ * - `external` appends an aria-hidden ExternalLink icon (strokeWidth 1.5)
36
+ * plus sr-only "(opens in new tab)" (SC 3.2.5 advance warning) and sets
37
+ * `target="_blank" rel="noopener noreferrer"`. With `asChild`, target/rel
38
+ * still forward through Slot but the icon/sr-only affordance is skipped
39
+ * (Slot requires exactly one child — same contract as Button's loading).
40
+ * - Inline links take the SC 2.5.8 inline target-size exception. A
41
+ * standalone flow-changing CTA styled as a link is still a CTA — use
42
+ * `Button` (min-h-11 CTA contract), not `Link`.
43
+ * - There is NO disabled state: links are removed or rendered as plain
44
+ * text, never disabled.
45
+ *
46
+ * `[overflow-wrap:anywhere]` ships in the base so a raw URL used as link
47
+ * text wraps instead of bleeding out of its container (corrections.md
48
+ * #001; `min-w-0` is omitted — meaningless on `display: inline`).
49
+ * Cursor pointer comes from the base layer's `a[href]` rule.
50
+ */
51
+
52
+ const linkVariants = cva(
53
+ // rounded-sm gives the focus ring a soft corner; ring appears instantly
54
+ // (only color properties are transitioned — never transition-all, so the
55
+ // focus indicator is not faded in; see CLAUDE.md → microanimation rule).
56
+ "rounded-sm underline-offset-4 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 [overflow-wrap:anywhere]",
57
+ {
58
+ variants: {
59
+ underline: {
60
+ always: "underline",
61
+ hover: "no-underline hover:underline",
62
+ none: "no-underline",
63
+ },
64
+ tone: {
65
+ // --link defaults to --primary (fork-overridable in tokens.json);
66
+ // decoration solidifies from 40% on hover.
67
+ default: "text-link decoration-link/40 hover:decoration-link",
68
+ foreground:
69
+ "text-foreground decoration-foreground/40 hover:decoration-foreground",
70
+ // muted lifts to foreground on hover — both pairs are
71
+ // wcag:audit-enforced AAA.
72
+ muted:
73
+ "text-muted-foreground decoration-muted-foreground/40 hover:text-foreground hover:decoration-foreground",
74
+ },
75
+ },
76
+ defaultVariants: {
77
+ underline: "always",
78
+ tone: "default",
79
+ },
80
+ }
81
+ );
82
+
83
+ export interface LinkProps
84
+ extends React.ComponentProps<"a">,
85
+ VariantProps<typeof linkVariants> {
86
+ /**
87
+ * Marks the destination as outside this product: sets
88
+ * `target="_blank" rel="noopener noreferrer"` (explicit `target`/`rel`
89
+ * props win) and appends the external-link icon + sr-only
90
+ * "(opens in new tab)". Icon/sr-only are skipped with `asChild`.
91
+ */
92
+ external?: boolean;
93
+ /**
94
+ * Radix Slot idiom (same as Button) — merge the link styles and props
95
+ * onto the single child element, e.g. a Next.js `<Link>`.
96
+ */
97
+ asChild?: boolean;
98
+ }
99
+
100
+ function Link({
101
+ className,
102
+ underline,
103
+ tone,
104
+ external = false,
105
+ asChild = false,
106
+ target,
107
+ rel,
108
+ style,
109
+ children,
110
+ ...props
111
+ }: LinkProps) {
112
+ const Comp = asChild ? Slot : "a";
113
+
114
+ return (
115
+ <Comp
116
+ data-slot="link"
117
+ data-underline={underline ?? "always"}
118
+ data-tone={tone ?? "default"}
119
+ target={external ? (target ?? "_blank") : target}
120
+ rel={external ? (rel ?? "noopener noreferrer") : rel}
121
+ className={cn(linkVariants({ underline, tone }), className)}
122
+ // Motion pattern (c): token-driven one-off transition — inline var()
123
+ // resolves at runtime against :root; never duration-* classes or
124
+ // literal ms values. Reduced-motion is handled by the base layer.
125
+ style={{
126
+ transitionDuration: "var(--duration-fast)",
127
+ transitionTimingFunction: "var(--ease-out)",
128
+ ...style,
129
+ }}
130
+ {...props}
131
+ >
132
+ {asChild ? (
133
+ // Slot calls React.Children.only — it must receive exactly ONE
134
+ // child, so the external icon/sr-only affordance cannot be injected
135
+ // here (documented no-op, mirroring Button's loading contract).
136
+ children
137
+ ) : (
138
+ <>
139
+ {children}
140
+ {external ? (
141
+ <>
142
+ {/* size-3.5 (14px) reads correctly against both text-sm and
143
+ text-base contexts; align tucks it onto the baseline. */}
144
+ <ExternalLinkIcon
145
+ strokeWidth={1.5}
146
+ aria-hidden="true"
147
+ className="ml-1 inline-block size-3.5 shrink-0 align-[-0.125em]"
148
+ />
149
+ <span className="sr-only"> (opens in new tab)</span>
150
+ </>
151
+ ) : null}
152
+ </>
153
+ )}
154
+ </Comp>
155
+ );
156
+ }
157
+
158
+ export { Link, linkVariants };