@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.
Files changed (137) hide show
  1. package/package.json +5 -2
  2. package/scripts/build-tokens.cjs +87 -5
  3. package/src/app/preview/components/page.tsx +4745 -244
  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-action-button.tsx +179 -0
  34. package/src/components/ui/floating-panel.tsx +129 -0
  35. package/src/components/ui/format-number.tsx +122 -0
  36. package/src/components/ui/highlight.tsx +85 -0
  37. package/src/components/ui/image.tsx +195 -0
  38. package/src/components/ui/index.ts +51 -0
  39. package/src/components/ui/indicator.tsx +2 -2
  40. package/src/components/ui/input.tsx +48 -4
  41. package/src/components/ui/kbd.tsx +1 -1
  42. package/src/components/ui/link.tsx +158 -0
  43. package/src/components/ui/listbox.tsx +426 -0
  44. package/src/components/ui/loading-overlay.tsx +80 -0
  45. package/src/components/ui/marquee.tsx +193 -0
  46. package/src/components/ui/masonry.tsx +164 -0
  47. package/src/components/ui/meter.tsx +186 -0
  48. package/src/components/ui/motion-toggle.tsx +170 -0
  49. package/src/components/ui/notification.tsx +175 -0
  50. package/src/components/ui/overlay.tsx +63 -0
  51. package/src/components/ui/progress.tsx +95 -4
  52. package/src/components/ui/rating-group.tsx +1 -0
  53. package/src/components/ui/separator.tsx +57 -1
  54. package/src/components/ui/sidebar.tsx +1 -1
  55. package/src/components/ui/signature-pad.tsx +381 -0
  56. package/src/components/ui/skeleton.tsx +59 -2
  57. package/src/components/ui/skip-link.tsx +117 -0
  58. package/src/components/ui/slider.tsx +86 -1
  59. package/src/components/ui/spoiler.tsx +131 -0
  60. package/src/components/ui/tabs.tsx +1 -1
  61. package/src/components/ui/text.tsx +135 -0
  62. package/src/components/ui/textarea.tsx +66 -2
  63. package/src/components/ui/timeline.tsx +71 -14
  64. package/src/components/ui/timer.tsx +183 -0
  65. package/src/components/ui/tour.tsx +332 -0
  66. package/src/components/ui/transfer-list.tsx +343 -0
  67. package/src/components/ui/typing-indicator.tsx +96 -0
  68. package/src/components/ui/visually-hidden.tsx +42 -0
  69. package/src/components/ui/watermark.tsx +0 -0
  70. package/src/components/ui/word-rotate.tsx +82 -0
  71. package/src/data/docs-index.ts +10 -2
  72. package/src/stories/ActionBar.stories.tsx +201 -0
  73. package/src/stories/Affix.stories.tsx +165 -0
  74. package/src/stories/Alert.stories.tsx +58 -0
  75. package/src/stories/Anchor.stories.tsx +236 -0
  76. package/src/stories/AngleSlider.stories.tsx +128 -0
  77. package/src/stories/Autocomplete.stories.tsx +216 -0
  78. package/src/stories/Avatar.stories.tsx +73 -1
  79. package/src/stories/Blockquote.stories.tsx +148 -0
  80. package/src/stories/BottomNavigation.stories.tsx +195 -0
  81. package/src/stories/Burger.stories.tsx +79 -0
  82. package/src/stories/Button.stories.tsx +103 -2
  83. package/src/stories/Calendar.stories.tsx +4 -0
  84. package/src/stories/Card.stories.tsx +30 -0
  85. package/src/stories/Carousel.stories.tsx +2 -1
  86. package/src/stories/Cascader.stories.tsx +285 -0
  87. package/src/stories/Checkbox.stories.tsx +13 -0
  88. package/src/stories/CheckboxCard.stories.tsx +210 -0
  89. package/src/stories/CheckboxGroup.stories.tsx +186 -0
  90. package/src/stories/Chip.stories.tsx +173 -0
  91. package/src/stories/CircularProgress.stories.tsx +3 -0
  92. package/src/stories/ColorSwatch.stories.tsx +81 -0
  93. package/src/stories/CopyButton.stories.tsx +3 -3
  94. package/src/stories/DatePicker.stories.tsx +3 -0
  95. package/src/stories/DateRangePicker.stories.tsx +3 -0
  96. package/src/stories/Editable.stories.tsx +14 -0
  97. package/src/stories/FloatLabel.stories.tsx +148 -0
  98. package/src/stories/FloatingActionButton.stories.tsx +215 -0
  99. package/src/stories/FloatingPanel.stories.tsx +176 -0
  100. package/src/stories/FormatNumber.stories.tsx +308 -0
  101. package/src/stories/Highlight.stories.tsx +140 -0
  102. package/src/stories/Image.stories.tsx +141 -0
  103. package/src/stories/Indicator.stories.tsx +3 -0
  104. package/src/stories/Input.stories.tsx +33 -0
  105. package/src/stories/Kbd.stories.tsx +3 -0
  106. package/src/stories/Link.stories.tsx +198 -0
  107. package/src/stories/Listbox.stories.tsx +240 -0
  108. package/src/stories/LoadingOverlay.stories.tsx +148 -0
  109. package/src/stories/Marquee.stories.tsx +170 -0
  110. package/src/stories/Masonry.stories.tsx +227 -0
  111. package/src/stories/Meter.stories.tsx +150 -0
  112. package/src/stories/MotionToggle.stories.tsx +85 -0
  113. package/src/stories/Notification.stories.tsx +264 -0
  114. package/src/stories/Overlay.stories.tsx +169 -0
  115. package/src/stories/PasswordInput.stories.tsx +4 -0
  116. package/src/stories/Progress.stories.tsx +70 -27
  117. package/src/stories/RatingGroup.stories.tsx +5 -0
  118. package/src/stories/Separator.stories.tsx +41 -5
  119. package/src/stories/Sidebar.stories.tsx +2 -1
  120. package/src/stories/SignaturePad.stories.tsx +112 -0
  121. package/src/stories/Skeleton.stories.tsx +23 -4
  122. package/src/stories/SkipLink.stories.tsx +137 -0
  123. package/src/stories/Slider.stories.tsx +28 -0
  124. package/src/stories/Spoiler.stories.tsx +122 -0
  125. package/src/stories/Tabs.stories.tsx +2 -1
  126. package/src/stories/Text.stories.tsx +191 -0
  127. package/src/stories/Textarea.stories.tsx +58 -6
  128. package/src/stories/Timeline.stories.tsx +82 -0
  129. package/src/stories/Timer.stories.tsx +160 -0
  130. package/src/stories/Tour.stories.tsx +191 -0
  131. package/src/stories/TransferList.stories.tsx +190 -0
  132. package/src/stories/TypingIndicator.stories.tsx +139 -0
  133. package/src/stories/VisuallyHidden.stories.tsx +105 -0
  134. package/src/stories/Watermark.stories.tsx +212 -0
  135. package/src/stories/WordRotate.stories.tsx +101 -0
  136. package/src/styles.css +88 -6
  137. package/src/tokens.json +3 -3
@@ -0,0 +1,143 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { Check } from "lucide-react";
6
+
7
+ import { cn } from "../../lib/utils";
8
+
9
+ // Chip — interactive filter/facet toggle pill (role="checkbox").
10
+ //
11
+ // Semantic sibling of Tag: Tag is a passive display label (a div, optionally
12
+ // dismissible); Chip is a stateful selector the user toggles on/off ("Filter
13
+ // by: design tokens | a11y contract"). Each chip is an independent toggle and
14
+ // its own tab stop — deliberately NOT a radiogroup, so arrow-key roving is
15
+ // not wired. Space (and Enter, via the native button) toggles.
16
+ //
17
+ // Motion is pattern (c): explicit transition property list + inline
18
+ // var(--duration-fast) / var(--ease-out). box-shadow is excluded from the
19
+ // list so the focus ring appears instantly (a11y floor).
20
+
21
+ const chipVariants = cva(
22
+ [
23
+ // Layout + long-label overflow contract: the button is the flex parent
24
+ // (max-w-full min-w-0 overflow-hidden); the label span truncates.
25
+ "inline-flex max-w-full min-w-0 cursor-pointer select-none items-center gap-1.5 overflow-hidden rounded-full border font-medium whitespace-nowrap",
26
+ "transition-[background-color,color,border-color]",
27
+ "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
28
+ "disabled:pointer-events-none disabled:opacity-50",
29
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
30
+ ],
31
+ {
32
+ variants: {
33
+ variant: {
34
+ default: [
35
+ "border-transparent bg-secondary text-secondary-foreground",
36
+ "hover:bg-secondary/80",
37
+ "aria-checked:bg-primary aria-checked:text-primary-foreground aria-checked:hover:bg-primary/90",
38
+ ],
39
+ outline: [
40
+ "border-input bg-transparent text-muted-foreground",
41
+ "hover:bg-muted hover:text-foreground",
42
+ "aria-checked:border-primary aria-checked:bg-primary/10 aria-checked:text-foreground",
43
+ ],
44
+ },
45
+ size: {
46
+ // sm is the documented dense-filter-chrome exception to the CTA size
47
+ // contract (min-h-9, mirroring Button's h-9 default — CLAUDE.md →
48
+ // Accessibility Floor, 2026-07 audit H5). When a chip is a
49
+ // flow-changing CTA, use size="default" or "lg" (min-h-11+).
50
+ sm: "min-h-9 px-3 text-sm",
51
+ default: "min-h-11 px-4 text-sm",
52
+ lg: "min-h-12 px-5 text-sm",
53
+ },
54
+ },
55
+ defaultVariants: {
56
+ variant: "default",
57
+ size: "default",
58
+ },
59
+ }
60
+ );
61
+
62
+ type ChipProps = Omit<React.ComponentProps<"button">, "children"> &
63
+ VariantProps<typeof chipVariants> & {
64
+ /** Controlled selected state. */
65
+ selected?: boolean;
66
+ /** Uncontrolled initial selected state. */
67
+ defaultSelected?: boolean;
68
+ /** Called with the next selected state on every toggle. */
69
+ onSelectedChange?: (selected: boolean) => void;
70
+ /**
71
+ * Optional leading icon (16px, strokeWidth 1.5 enforced via CSS).
72
+ * Replaced by the check indicator while the chip is selected.
73
+ */
74
+ icon?: React.ReactNode;
75
+ /** Visible label — the chip's accessible name. */
76
+ children: React.ReactNode;
77
+ };
78
+
79
+ function Chip({
80
+ className,
81
+ variant,
82
+ size,
83
+ selected,
84
+ defaultSelected = false,
85
+ onSelectedChange,
86
+ icon,
87
+ disabled,
88
+ onClick,
89
+ style,
90
+ children,
91
+ ...props
92
+ }: ChipProps) {
93
+ const [uncontrolledSelected, setUncontrolledSelected] =
94
+ React.useState(defaultSelected);
95
+ const isControlled = selected !== undefined;
96
+ const isSelected = isControlled ? selected : uncontrolledSelected;
97
+
98
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
99
+ onClick?.(event);
100
+ if (event.defaultPrevented || disabled) return;
101
+ const next = !isSelected;
102
+ if (!isControlled) setUncontrolledSelected(next);
103
+ onSelectedChange?.(next);
104
+ };
105
+
106
+ return (
107
+ <button
108
+ type="button"
109
+ role="checkbox"
110
+ aria-checked={isSelected}
111
+ data-slot="chip"
112
+ data-selected={isSelected || undefined}
113
+ data-state={isSelected ? "checked" : "unchecked"}
114
+ disabled={disabled}
115
+ onClick={handleClick}
116
+ className={cn(chipVariants({ variant, size }), className)}
117
+ style={{
118
+ transitionDuration: "var(--duration-fast)",
119
+ transitionTimingFunction: "var(--ease-out)",
120
+ ...style,
121
+ }}
122
+ {...props}
123
+ >
124
+ {isSelected ? (
125
+ // Non-color selected indicator — state never reads by fill alone.
126
+ <Check strokeWidth={1.5} aria-hidden="true" className="size-4 shrink-0" />
127
+ ) : (
128
+ icon != null && (
129
+ <span
130
+ aria-hidden="true"
131
+ className="shrink-0 [&>svg]:size-4 [&>svg]:stroke-[1.5]"
132
+ >
133
+ {icon}
134
+ </span>
135
+ )
136
+ )}
137
+ <span className="min-w-0 truncate">{children}</span>
138
+ </button>
139
+ );
140
+ }
141
+
142
+ export { Chip, chipVariants };
143
+ export type { ChipProps };
@@ -19,8 +19,8 @@ const circularProgressVariants = cva(
19
19
  variant: {
20
20
  default: "text-primary",
21
21
  muted: "text-muted-foreground",
22
- success: "text-[hsl(var(--success))]",
23
- warning: "text-[hsl(var(--warning))]",
22
+ success: "text-[var(--success)]",
23
+ warning: "text-[var(--warning)]",
24
24
  destructive: "text-destructive",
25
25
  },
26
26
  },
@@ -0,0 +1,73 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { cva, type VariantProps } from "class-variance-authority"
5
+
6
+ import { cn } from "../../lib/utils"
7
+
8
+ const colorSwatchVariants = cva(
9
+ // Inset ring gives the swatch a crisp edge on any canvas. `foreground/15`
10
+ // is token-driven: a dark hairline in light mode delineates pale swatches,
11
+ // a light hairline in dark mode delineates near-black swatches.
12
+ "inline-grid shrink-0 place-items-center ring-1 ring-inset ring-foreground/15",
13
+ {
14
+ variants: {
15
+ size: {
16
+ sm: "size-4 [&_svg]:size-2.5",
17
+ default: "size-6 [&_svg]:size-3.5",
18
+ lg: "size-8 [&_svg]:size-4",
19
+ },
20
+ shape: {
21
+ rounded: "rounded-md",
22
+ circle: "rounded-full",
23
+ square: "rounded-none",
24
+ },
25
+ },
26
+ defaultVariants: {
27
+ size: "default",
28
+ shape: "rounded",
29
+ },
30
+ }
31
+ )
32
+
33
+ interface ColorSwatchProps
34
+ extends Omit<React.ComponentProps<"span">, "color">,
35
+ VariantProps<typeof colorSwatchVariants> {
36
+ /** Any CSS color — hex, rgb(), hsl(), or a CSS variable like `var(--chart-1)`. */
37
+ color: string
38
+ }
39
+
40
+ /**
41
+ * Display-only color chip. Presentational by default (`aria-hidden`) since a
42
+ * swatch usually sits beside a text label that already names the color. Pass
43
+ * `aria-label` when the swatch stands alone and must announce its meaning —
44
+ * it then renders `role="img"`. Not interactive: wrap it in a Button (with a
45
+ * label) if a click should do something.
46
+ */
47
+ function ColorSwatch({
48
+ className,
49
+ color,
50
+ size,
51
+ shape,
52
+ style,
53
+ children,
54
+ "aria-label": ariaLabel,
55
+ ...props
56
+ }: ColorSwatchProps) {
57
+ return (
58
+ <span
59
+ data-slot="color-swatch"
60
+ role={ariaLabel ? "img" : undefined}
61
+ aria-label={ariaLabel}
62
+ aria-hidden={ariaLabel ? undefined : true}
63
+ className={cn(colorSwatchVariants({ size, shape }), className)}
64
+ style={{ backgroundColor: color, ...style }}
65
+ {...props}
66
+ >
67
+ {children}
68
+ </span>
69
+ )
70
+ }
71
+
72
+ export { ColorSwatch, colorSwatchVariants }
73
+ export type { ColorSwatchProps }
@@ -58,6 +58,11 @@ function CopyButton({
58
58
  }, [value, copied, copiedDuration, onCopy])
59
59
 
60
60
  const iconOnly = children === undefined
61
+ // Compact labeled buttons drop the check icon in the copied state — at
62
+ // sm/xs padding the icon+text pair is wider than the resting label and
63
+ // clips against overflow-hidden. "Copied!" alone is confirmation enough
64
+ // there. Icon-only mode always keeps the check (it's the only feedback).
65
+ const showCheck = iconOnly || (size !== "sm" && size !== "xs")
61
66
 
62
67
  return (
63
68
  <>
@@ -66,7 +71,12 @@ function CopyButton({
66
71
  data-copied={copied ? "true" : undefined}
67
72
  variant={variant}
68
73
  size={size}
69
- disabled={disabled || copied}
74
+ // Not disabled during the copied window — the Button primitive's
75
+ // disabled:opacity-50 would dim the green confirmation to 50%. The
76
+ // re-copy guard lives in handleCopy (`if (copied) return`), so leaving
77
+ // the button enabled keeps "Copied!" at full opacity without allowing
78
+ // a double-copy.
79
+ disabled={disabled}
70
80
  onClick={handleCopy}
71
81
  aria-label={ariaLabel ?? (iconOnly ? (copied ? "Copied" : "Copy") : undefined)}
72
82
  className={cn("relative overflow-hidden", className)}
@@ -75,7 +85,7 @@ function CopyButton({
75
85
  {/* In labeled mode this span provides the button's accessible name — not aria-hidden */}
76
86
  <span
77
87
  className={cn(
78
- "inline-flex items-center gap-1.5 transition-all",
88
+ "inline-flex items-center gap-1.5 transition-[opacity,transform]",
79
89
  copied ? "opacity-0 scale-75" : "opacity-100 scale-100"
80
90
  )}
81
91
  style={{
@@ -90,7 +100,14 @@ function CopyButton({
90
100
  {/* Always hidden — state announced by the aria-live region */}
91
101
  <span
92
102
  className={cn(
93
- "absolute inset-0 inline-flex items-center justify-center gap-1.5 text-[var(--success)] transition-all",
103
+ // Centered over the whole button face. An earlier right-aligned
104
+ // pr-4 treatment clipped the overlay's left edge on any size whose
105
+ // padding isn't px-4 (sm/xs) because the swap-in content is wider
106
+ // than the resting label and the button is overflow-hidden.
107
+ // No color override — inherits the button's own foreground so it
108
+ // reads on any variant. Green text on the dark default button fails
109
+ // AAA (~3.6:1); the check icon is sufficient confirmation.
110
+ "absolute inset-0 inline-flex items-center justify-center gap-1.5 transition-[opacity,transform]",
94
111
  copied ? "opacity-100 scale-100" : "opacity-0 scale-75"
95
112
  )}
96
113
  style={{
@@ -99,7 +116,7 @@ function CopyButton({
99
116
  }}
100
117
  aria-hidden="true"
101
118
  >
102
- <CheckIcon strokeWidth={1.5} />
119
+ {showCheck && <CheckIcon strokeWidth={1.5} />}
103
120
  {!iconOnly && "Copied!"}
104
121
  </span>
105
122
  </Button>
@@ -146,9 +146,12 @@ function DatePicker({
146
146
  mode="single"
147
147
  selected={selectedDate}
148
148
  onSelect={handleSelect}
149
- fromDate={fromDate}
150
- toDate={toDate}
151
- initialFocus
149
+ startMonth={fromDate}
150
+ endMonth={toDate}
151
+ disabled={[
152
+ ...(fromDate ? [{ before: fromDate }] : []),
153
+ ...(toDate ? [{ after: toDate }] : []),
154
+ ]}
152
155
  />
153
156
  </PopoverContent>
154
157
  </Popover>
@@ -161,10 +161,13 @@ function DateRangePicker({
161
161
  mode="range"
162
162
  selected={selectedRange as DateRange | undefined}
163
163
  onSelect={handleSelect}
164
- fromDate={fromDate}
165
- toDate={toDate}
164
+ startMonth={fromDate}
165
+ endMonth={toDate}
166
+ disabled={[
167
+ ...(fromDate ? [{ before: fromDate }] : []),
168
+ ...(toDate ? [{ after: toDate }] : []),
169
+ ]}
166
170
  numberOfMonths={2}
167
- initialFocus
168
171
  />
169
172
  </PopoverContent>
170
173
  </Popover>
@@ -0,0 +1,114 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+
6
+ import { cn } from "../../lib/utils";
7
+ import { Input } from "./input";
8
+
9
+ // ─── Variants ─────────────────────────────────────────────────────────────────
10
+ //
11
+ // The label always carries px-1 (so the floated "notch" has breathing room over
12
+ // the top border) and left-* compensates per size so the RESTING label text
13
+ // aligns exactly with the input's own text (Input pads: sm px-2.5, default px-3,
14
+ // lg px-4).
15
+ //
16
+ // Float trigger is pure CSS — the wrapped <Input> is the `peer`, and the label
17
+ // reacts to :focus, :not(:placeholder-shown) (requires placeholder=" "), and
18
+ // :autofill (Chrome autofill doesn't always fire focus). No JS state.
19
+
20
+ const floatLabelVariants = cva(
21
+ [
22
+ // geometry + resting position (vertically centered in the field)
23
+ "pointer-events-none absolute top-1/2 -translate-y-1/2 select-none px-1",
24
+ "origin-left text-muted-foreground",
25
+ // float on focus
26
+ "peer-focus:top-0 peer-focus:text-xs peer-focus:bg-background peer-focus:text-foreground",
27
+ // stay floated while filled (placeholder=" " makes :placeholder-shown reliable)
28
+ "peer-[:not(:placeholder-shown)]:top-0 peer-[:not(:placeholder-shown)]:text-xs peer-[:not(:placeholder-shown)]:bg-background",
29
+ // browser autofill paints a value without necessarily focusing
30
+ "peer-autofill:top-0 peer-autofill:text-xs peer-autofill:bg-background",
31
+ // state mirrors
32
+ "peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
33
+ "peer-aria-invalid:text-destructive",
34
+ // motion: property list here; duration/easing via inline style tokens below
35
+ "transition-[top,transform,font-size,color,background-color]",
36
+ ],
37
+ {
38
+ variants: {
39
+ size: {
40
+ sm: "left-1.5 text-sm",
41
+ default: "left-2 text-sm",
42
+ lg: "left-3 text-base",
43
+ },
44
+ },
45
+ defaultVariants: {
46
+ size: "default",
47
+ },
48
+ }
49
+ );
50
+
51
+ // ─── Types ────────────────────────────────────────────────────────────────────
52
+
53
+ type FloatLabelProps = Omit<
54
+ React.ComponentProps<typeof Input>,
55
+ "size" | "placeholder" | "clearable"
56
+ > &
57
+ VariantProps<typeof floatLabelVariants> & {
58
+ /** Visible label text. Required — this IS the field's accessible name. */
59
+ label: string;
60
+ /** Class applied to the outer relative wrapper (use for width control). */
61
+ containerClassName?: string;
62
+ };
63
+
64
+ // ─── FloatLabel ───────────────────────────────────────────────────────────────
65
+
66
+ function FloatLabel({
67
+ label,
68
+ size,
69
+ id,
70
+ required,
71
+ containerClassName,
72
+ className,
73
+ ...props
74
+ }: FloatLabelProps) {
75
+ const generatedId = React.useId();
76
+ const inputId = id ?? generatedId;
77
+ const labelId = `${inputId}-label`;
78
+
79
+ return (
80
+ <div
81
+ data-slot="float-label"
82
+ className={cn("relative", containerClassName)}
83
+ >
84
+ <Input
85
+ id={inputId}
86
+ size={size}
87
+ required={required}
88
+ aria-labelledby={labelId}
89
+ // A single space keeps :placeholder-shown reliable for empty-state
90
+ // detection without ever rendering visible placeholder text — the
91
+ // floating label is the field's one visible name.
92
+ placeholder=" "
93
+ className={cn("peer", className)}
94
+ {...props}
95
+ />
96
+ <label
97
+ id={labelId}
98
+ htmlFor={inputId}
99
+ data-slot="float-label-label"
100
+ className={cn(floatLabelVariants({ size }))}
101
+ style={{
102
+ transitionDuration: "var(--duration-fast)",
103
+ transitionTimingFunction: "var(--ease-out)",
104
+ }}
105
+ >
106
+ {label}
107
+ {required && <span aria-hidden="true"> *</span>}
108
+ </label>
109
+ </div>
110
+ );
111
+ }
112
+
113
+ export { FloatLabel, floatLabelVariants };
114
+ export type { FloatLabelProps };
@@ -0,0 +1,179 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+
6
+ import { cn } from "../../lib/utils";
7
+ import { Button } from "./button";
8
+
9
+ /**
10
+ * FloatingActionButton — fixed-position circular button that triggers a
11
+ * single primary action, pinned to a viewport corner. The single-action
12
+ * counterpart to SpeedDial (which opens a submenu of 2–5 quick actions).
13
+ * Cross-library Tier 1 pattern: MUI `Fab` + Ant Design `FloatButton`.
14
+ *
15
+ * Wraps the Button primitive, so focus ring, loading (spinner + aria-busy +
16
+ * disabled), and disabled affordances are inherited — this file only owns
17
+ * positioning, shape, size contract, and entrance motion.
18
+ *
19
+ * Accessible name is REQUIRED: either a visible `label` (extended/pill form)
20
+ * or `aria-label` when icon-only. A dev-mode warning fires when both are
21
+ * missing.
22
+ *
23
+ * Motion:
24
+ * - entrance: tw-animate-css `animate-in fade-in-0 zoom-in-75` (existing
25
+ * keyframe utility — spec §4 pattern (a), same family Dialog/Tooltip use)
26
+ * - hover/active: shadow elevation shift on `transition-shadow` with inline
27
+ * token vars (spec §4 pattern (c)); bg hover comes from Button's own
28
+ * `transition-colors` variant classes
29
+ * - reduced motion: base-layer prefers-reduced-motion kill-switch, no
30
+ * per-component guard needed
31
+ *
32
+ * Exit motion on unmount is deliberately out of scope — the element is
33
+ * removed before an exit keyframe could play; animated dismissal needs
34
+ * presence management (a future follow-up, same limitation as Ant
35
+ * FloatButton).
36
+ */
37
+ const fabVariants = cva(
38
+ // fixed + z-50 floats above page content; rounded-full is the FAB shape
39
+ // contract; shadow ladder (lg → xl on hover → md on active) is the lift
40
+ // affordance — never hover:scale (BADS-SLOP-3 anti-default). The explicit
41
+ // property list replaces Button's `transition-colors` (same tailwind-merge
42
+ // group) so bg hover AND elevation both animate — never `transition-all`.
43
+ "fixed z-50 rounded-full shadow-lg transition-[background-color,color,box-shadow] hover:shadow-xl active:shadow-md animate-in fade-in-0 zoom-in-75",
44
+ {
45
+ variants: {
46
+ size: {
47
+ // sm is 40px — BELOW the 44px SC 2.5.5 floor. Dense/desktop-secondary
48
+ // chrome only; never a primary CTA (registry antiPatterns).
49
+ sm: "min-h-10 min-w-10 [&_svg:not([class*='size-'])]:size-5",
50
+ // md 56px is the thumb-target convention both source systems default to.
51
+ md: "min-h-14 min-w-14 [&_svg:not([class*='size-'])]:size-6",
52
+ lg: "min-h-16 min-w-16 [&_svg:not([class*='size-'])]:size-6",
53
+ },
54
+ corner: {
55
+ "bottom-right": "bottom-6 right-6",
56
+ "bottom-left": "bottom-6 left-6",
57
+ "top-right": "top-6 right-6",
58
+ "top-left": "top-6 left-6",
59
+ },
60
+ // extended = visible label → pill form. Explicit h-* + px-* override
61
+ // Button's size classes via tailwind-merge; round form zeroes padding so
62
+ // min-h/min-w keep the button square.
63
+ extended: {
64
+ false: "px-0 py-0",
65
+ true: "gap-2 text-sm font-medium",
66
+ },
67
+ },
68
+ compoundVariants: [
69
+ { extended: false, size: "sm", class: "h-10 w-10" },
70
+ { extended: false, size: "md", class: "h-14 w-14" },
71
+ { extended: false, size: "lg", class: "h-16 w-16" },
72
+ { extended: true, size: "sm", class: "h-10 px-4" },
73
+ { extended: true, size: "md", class: "h-14 px-5" },
74
+ { extended: true, size: "lg", class: "h-16 px-6" },
75
+ ],
76
+ defaultVariants: {
77
+ size: "md",
78
+ corner: "bottom-right",
79
+ extended: false,
80
+ },
81
+ }
82
+ );
83
+
84
+ interface FloatingActionButtonProps
85
+ extends Omit<React.ComponentProps<"button">, "children">,
86
+ Omit<VariantProps<typeof fabVariants>, "extended"> {
87
+ /** Required — the icon rendered inside. Lucide at strokeWidth 1.5 by convention. */
88
+ icon: React.ReactNode;
89
+ /** Visible label beside the icon — switches to the extended (pill) FAB form. */
90
+ label?: string;
91
+ /** Maps to Button variants: primary → default, secondary → secondary. */
92
+ variant?: "primary" | "secondary";
93
+ /** Spinner replaces the icon; aria-busy + disabled via Button. Dimensions stay stable. */
94
+ loading?: boolean;
95
+ /**
96
+ * Render via Radix Slot (e.g. a Next.js Link). The composed icon + label
97
+ * are injected as the child's children; if the child already has its own
98
+ * children, those win (compose the icon yourself in that case). Button's
99
+ * asChild contract applies: `loading` is a no-op with asChild.
100
+ */
101
+ asChild?: boolean;
102
+ children?: React.ReactNode;
103
+ }
104
+
105
+ function FloatingActionButton({
106
+ icon,
107
+ label,
108
+ size = "md",
109
+ corner = "bottom-right",
110
+ variant = "primary",
111
+ loading = false,
112
+ asChild = false,
113
+ className,
114
+ style,
115
+ children,
116
+ ...props
117
+ }: FloatingActionButtonProps) {
118
+ if (process.env.NODE_ENV !== "production") {
119
+ if (
120
+ !label &&
121
+ !props["aria-label"] &&
122
+ !props["aria-labelledby"] &&
123
+ !asChild
124
+ ) {
125
+ console.warn(
126
+ "FloatingActionButton: icon-only FABs need an accessible name — pass `aria-label` (or a visible `label`)."
127
+ );
128
+ }
129
+ }
130
+
131
+ const content = (
132
+ <>
133
+ {/* Button renders its own aria-hidden spinner when loading; hide the
134
+ icon then so the round form stays a single centered glyph. */}
135
+ {loading && !asChild ? null : icon}
136
+ {label ? <span>{label}</span> : null}
137
+ </>
138
+ );
139
+
140
+ let inner: React.ReactNode = content;
141
+ if (asChild && React.isValidElement(children)) {
142
+ const child = children as React.ReactElement<{
143
+ children?: React.ReactNode;
144
+ }>;
145
+ // Slot needs exactly one child; inject the composed icon/label into it
146
+ // unless the consumer already hand-composed the child's content.
147
+ inner =
148
+ child.props.children != null
149
+ ? child
150
+ : React.cloneElement(child, undefined, content);
151
+ }
152
+
153
+ return (
154
+ <Button
155
+ asChild={asChild}
156
+ variant={variant === "secondary" ? "secondary" : "default"}
157
+ loading={loading}
158
+ data-slot="floating-action-button"
159
+ data-state="visible"
160
+ className={cn(fabVariants({ size, corner, extended: Boolean(label) }), className)}
161
+ // Elevation lift timing rides the motion tokens (spec §4 pattern (c));
162
+ // CSS vars resolve at runtime against :root, so tokens.json changes
163
+ // propagate without a rebuild of this file. Consumer style merges on
164
+ // top (but the motion tokens are listed first so an explicit consumer
165
+ // override still wins).
166
+ style={{
167
+ transitionDuration: "var(--duration-fast)",
168
+ transitionTimingFunction: "var(--ease-out)",
169
+ ...style,
170
+ }}
171
+ {...props}
172
+ >
173
+ {inner}
174
+ </Button>
175
+ );
176
+ }
177
+
178
+ export { FloatingActionButton, fabVariants };
179
+ export type { FloatingActionButtonProps };