@brightlocal/ui-components 3.0.0 → 3.2.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 (235) hide show
  1. package/README.md +7 -1
  2. package/component-meta.json +749 -53
  3. package/deprecations.json +114 -4
  4. package/dist/accordion.cjs +1 -1
  5. package/dist/accordion.d.ts +36 -0
  6. package/dist/accordion.d.ts.map +1 -1
  7. package/dist/accordion.js +74 -61
  8. package/dist/alert-dialog.cjs +1 -1
  9. package/dist/alert-dialog.d.ts +32 -3
  10. package/dist/alert-dialog.d.ts.map +1 -1
  11. package/dist/alert-dialog.js +61 -58
  12. package/dist/alert.cjs +1 -1
  13. package/dist/alert.d.ts.map +1 -1
  14. package/dist/alert.js +58 -57
  15. package/dist/badge.cjs +1 -1
  16. package/dist/badge.d.ts +9 -0
  17. package/dist/badge.d.ts.map +1 -1
  18. package/dist/badge.js +50 -30
  19. package/dist/banner.cjs +1 -0
  20. package/dist/banner.d.ts +81 -0
  21. package/dist/banner.d.ts.map +1 -0
  22. package/dist/banner.js +176 -0
  23. package/dist/blocks/empty-state.cjs +1 -1
  24. package/dist/blocks/empty-state.d.ts +4 -3
  25. package/dist/blocks/empty-state.d.ts.map +1 -1
  26. package/dist/blocks/empty-state.js +50 -57
  27. package/dist/blocks/progress-state.d.ts +2 -2
  28. package/dist/blocks/sidebar.cjs +1 -1
  29. package/dist/blocks/sidebar.d.ts +17 -0
  30. package/dist/blocks/sidebar.d.ts.map +1 -1
  31. package/dist/blocks/sidebar.js +8 -2
  32. package/dist/brand-illustration-motif.d.ts +1 -1
  33. package/dist/button-group.cjs +1 -0
  34. package/dist/button-group.d.ts +36 -0
  35. package/dist/button-group.d.ts.map +1 -0
  36. package/dist/button-group.js +47 -0
  37. package/dist/button.cjs +1 -1
  38. package/dist/button.js +1 -1
  39. package/dist/card.cjs +1 -1
  40. package/dist/card.d.ts +105 -7
  41. package/dist/card.d.ts.map +1 -1
  42. package/dist/card.js +198 -101
  43. package/dist/chart.cjs +3 -3
  44. package/dist/chart.d.ts +270 -24
  45. package/dist/chart.d.ts.map +1 -1
  46. package/dist/chart.js +497 -322
  47. package/dist/checkbox.cjs +1 -1
  48. package/dist/checkbox.d.ts +1 -1
  49. package/dist/checkbox.d.ts.map +1 -1
  50. package/dist/checkbox.js +2 -1
  51. package/dist/chip.cjs +1 -1
  52. package/dist/chip.d.ts +38 -4
  53. package/dist/chip.d.ts.map +1 -1
  54. package/dist/chip.js +95 -81
  55. package/dist/combobox.cjs +1 -1
  56. package/dist/combobox.js +2 -2
  57. package/dist/command.cjs +1 -1
  58. package/dist/command.d.ts +23 -1
  59. package/dist/command.d.ts.map +1 -1
  60. package/dist/command.js +251 -225
  61. package/dist/data-table.cjs +1 -1
  62. package/dist/data-table.d.ts +201 -23
  63. package/dist/data-table.d.ts.map +1 -1
  64. package/dist/data-table.js +712 -568
  65. package/dist/date-picker.cjs +1 -1
  66. package/dist/date-picker.d.ts +13 -5
  67. package/dist/date-picker.d.ts.map +1 -1
  68. package/dist/date-picker.js +54 -53
  69. package/dist/field.cjs +1 -1
  70. package/dist/field.d.ts +8 -1
  71. package/dist/field.d.ts.map +1 -1
  72. package/dist/field.js +79 -52
  73. package/dist/global-layout.cjs +1 -1
  74. package/dist/global-layout.d.ts +105 -13
  75. package/dist/global-layout.d.ts.map +1 -1
  76. package/dist/global-layout.js +146 -129
  77. package/dist/grid.d.ts +26 -3
  78. package/dist/grid.d.ts.map +1 -1
  79. package/dist/hooks/use-breakpoint.cjs +1 -1
  80. package/dist/hooks/use-breakpoint.d.ts +1 -1
  81. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  82. package/dist/hooks/use-breakpoint.js +1 -0
  83. package/dist/hooks/use-mobile.cjs +1 -0
  84. package/dist/hooks/use-mobile.js +8 -0
  85. package/dist/index.cjs +1 -1
  86. package/dist/index.d.ts +6 -0
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +594 -553
  89. package/dist/info-tooltip.cjs +1 -0
  90. package/dist/info-tooltip.d.ts +39 -0
  91. package/dist/info-tooltip.d.ts.map +1 -0
  92. package/dist/info-tooltip.js +41 -0
  93. package/dist/input-chip.cjs +1 -1
  94. package/dist/input-chip.js +1 -1
  95. package/dist/input-group.cjs +1 -1
  96. package/dist/input-group.d.ts +33 -2
  97. package/dist/input-group.d.ts.map +1 -1
  98. package/dist/input-group.js +167 -54
  99. package/dist/input-otp.cjs +1 -1
  100. package/dist/input-otp.js +9 -9
  101. package/dist/input-password.cjs +1 -1
  102. package/dist/input-password.d.ts +45 -15
  103. package/dist/input-password.d.ts.map +1 -1
  104. package/dist/input-password.js +31 -30
  105. package/dist/input.cjs +1 -1
  106. package/dist/input.js +10 -10
  107. package/dist/lib/block-illustration.cjs +1 -1
  108. package/dist/lib/block-illustration.d.ts +4 -1
  109. package/dist/lib/block-illustration.d.ts.map +1 -1
  110. package/dist/lib/block-illustration.js +12 -11
  111. package/dist/lib/empty-chip.cjs +1 -0
  112. package/dist/lib/empty-chip.d.ts +4 -0
  113. package/dist/lib/empty-chip.d.ts.map +1 -0
  114. package/dist/lib/empty-chip.js +13 -0
  115. package/dist/lib/utils.cjs +1 -1
  116. package/dist/lib/utils.d.ts.map +1 -1
  117. package/dist/lib/utils.js +4 -3
  118. package/dist/list.cjs +1 -1
  119. package/dist/list.js +1 -1
  120. package/dist/multi-select-filter.cjs +1 -0
  121. package/dist/multi-select-filter.d.ts +178 -0
  122. package/dist/multi-select-filter.d.ts.map +1 -0
  123. package/dist/multi-select-filter.js +463 -0
  124. package/dist/pagination.cjs +1 -1
  125. package/dist/pagination.d.ts +3 -0
  126. package/dist/pagination.d.ts.map +1 -1
  127. package/dist/pagination.js +57 -57
  128. package/dist/progress.cjs +1 -1
  129. package/dist/progress.d.ts +123 -16
  130. package/dist/progress.d.ts.map +1 -1
  131. package/dist/progress.js +89 -75
  132. package/dist/rating.cjs +1 -1
  133. package/dist/rating.js +18 -18
  134. package/dist/relative-date.cjs +1 -0
  135. package/dist/relative-date.d.ts +65 -0
  136. package/dist/relative-date.d.ts.map +1 -0
  137. package/dist/relative-date.js +128 -0
  138. package/dist/scroll-area.cjs +1 -1
  139. package/dist/scroll-area.d.ts +15 -6
  140. package/dist/scroll-area.d.ts.map +1 -1
  141. package/dist/scroll-area.js +38 -36
  142. package/dist/select.cjs +2 -2
  143. package/dist/select.d.ts +24 -3
  144. package/dist/select.d.ts.map +1 -1
  145. package/dist/select.js +130 -110
  146. package/dist/sheet.cjs +1 -1
  147. package/dist/sheet.d.ts +78 -2
  148. package/dist/sheet.d.ts.map +1 -1
  149. package/dist/sheet.js +192 -85
  150. package/dist/single-select-filter.cjs +1 -0
  151. package/dist/single-select-filter.d.ts +81 -0
  152. package/dist/single-select-filter.d.ts.map +1 -0
  153. package/dist/single-select-filter.js +226 -0
  154. package/dist/sonner.cjs +1 -1
  155. package/dist/sonner.d.ts.map +1 -1
  156. package/dist/sonner.js +22 -22
  157. package/dist/split-layout.cjs +1 -1
  158. package/dist/split-layout.d.ts +1 -1
  159. package/dist/split-layout.js +13 -13
  160. package/dist/table.cjs +1 -1
  161. package/dist/table.d.ts +45 -4
  162. package/dist/table.d.ts.map +1 -1
  163. package/dist/table.js +90 -73
  164. package/dist/tabs.cjs +1 -1
  165. package/dist/tabs.d.ts +12 -1
  166. package/dist/tabs.d.ts.map +1 -1
  167. package/dist/tabs.js +148 -126
  168. package/dist/textarea.cjs +1 -1
  169. package/dist/textarea.js +1 -1
  170. package/dist/tooltip.cjs +1 -1
  171. package/dist/tooltip.d.ts +38 -36
  172. package/dist/tooltip.d.ts.map +1 -1
  173. package/dist/tooltip.js +262 -73
  174. package/dist/typography-heading.cjs +1 -1
  175. package/dist/typography-heading.d.ts +13 -0
  176. package/dist/typography-heading.d.ts.map +1 -1
  177. package/dist/typography-heading.js +32 -21
  178. package/dist/typography-text.cjs +1 -1
  179. package/dist/typography-text.d.ts +15 -2
  180. package/dist/typography-text.d.ts.map +1 -1
  181. package/dist/typography-text.js +35 -24
  182. package/dist/typography.d.ts +1 -1
  183. package/package.json +5 -6
  184. package/src/blocks/empty-state.tsx +17 -24
  185. package/src/blocks/progress-state.tsx +2 -2
  186. package/src/blocks/sidebar.tsx +26 -2
  187. package/src/components/accordion.tsx +82 -27
  188. package/src/components/alert-dialog.tsx +50 -5
  189. package/src/components/alert.tsx +16 -8
  190. package/src/components/badge.tsx +40 -3
  191. package/src/components/banner.tsx +288 -0
  192. package/src/components/brand-illustration-motif.tsx +1 -1
  193. package/src/components/button-group.tsx +112 -0
  194. package/src/components/button.tsx +1 -1
  195. package/src/components/card.tsx +249 -27
  196. package/src/components/chart.tsx +586 -53
  197. package/src/components/checkbox.tsx +1 -1
  198. package/src/components/chip.tsx +83 -10
  199. package/src/components/combobox.tsx +2 -2
  200. package/src/components/command.tsx +56 -4
  201. package/src/components/data-table.tsx +842 -199
  202. package/src/components/date-picker.tsx +18 -7
  203. package/src/components/field.tsx +81 -12
  204. package/src/components/global-layout.tsx +176 -38
  205. package/src/components/grid.tsx +34 -3
  206. package/src/components/info-tooltip.tsx +94 -0
  207. package/src/components/input-chip.tsx +1 -1
  208. package/src/components/input-group.tsx +246 -11
  209. package/src/components/input-otp.tsx +1 -1
  210. package/src/components/input-password.tsx +56 -22
  211. package/src/components/input.tsx +1 -1
  212. package/src/components/list.tsx +1 -1
  213. package/src/components/multi-select-filter.tsx +912 -0
  214. package/src/components/pagination.tsx +10 -3
  215. package/src/components/progress.tsx +190 -31
  216. package/src/components/rating.tsx +1 -1
  217. package/src/components/relative-date.tsx +230 -0
  218. package/src/components/scroll-area.tsx +23 -10
  219. package/src/components/select.tsx +65 -11
  220. package/src/components/sheet.tsx +240 -4
  221. package/src/components/single-select-filter.tsx +443 -0
  222. package/src/components/sonner.tsx +16 -5
  223. package/src/components/split-layout.tsx +2 -2
  224. package/src/components/table.tsx +71 -11
  225. package/src/components/tabs.tsx +93 -46
  226. package/src/components/textarea.tsx +1 -1
  227. package/src/components/tooltip.tsx +440 -68
  228. package/src/components/typography-heading.tsx +24 -0
  229. package/src/components/typography-text.tsx +27 -3
  230. package/src/components/typography.tsx +1 -1
  231. package/src/hooks/use-breakpoint.ts +2 -1
  232. package/src/index.ts +6 -0
  233. package/src/lib/block-illustration.tsx +5 -1
  234. package/src/lib/empty-chip.ts +24 -0
  235. package/src/lib/utils.ts +1 -0
@@ -0,0 +1,94 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Info, type LucideProps } from "@brightlocal/icons";
5
+ import {
6
+ Tooltip,
7
+ TooltipContent,
8
+ TooltipTrigger,
9
+ } from "@brightlocal/ui-components/tooltip";
10
+ import { cn } from "@brightlocal/ui-components/lib/utils";
11
+
12
+ /**
13
+ * Props for the InfoTooltip component.
14
+ * Extends native button attributes so consumers can pass `id`, `disabled`, `style`, etc.
15
+ */
16
+ interface InfoTooltipProps extends Omit<
17
+ React.ComponentPropsWithoutRef<"button">,
18
+ "content" | "children"
19
+ > {
20
+ /**
21
+ * Required test hook identifier.
22
+ * Applied to the trigger; the tooltip content receives `${dataHook}-content`.
23
+ * @example "credits-info"
24
+ */
25
+ dataHook: string;
26
+ /** Tooltip content — a short explanation shown on hover/tap. */
27
+ content: React.ReactNode;
28
+ /**
29
+ * Icon component rendered inside the trigger.
30
+ * @default Info
31
+ */
32
+ icon?: React.ComponentType<LucideProps>;
33
+ /**
34
+ * Icon size in pixels.
35
+ * @default 16
36
+ */
37
+ iconSize?: number;
38
+ /**
39
+ * Accessible label for the trigger button.
40
+ * @default "More info"
41
+ */
42
+ ariaLabel?: string;
43
+ /** Analytics element identifier. */
44
+ trackingEl?: string;
45
+ /** Analytics label. */
46
+ trackingLabel?: string;
47
+ }
48
+
49
+ const InfoTooltip = React.forwardRef<HTMLButtonElement, InfoTooltipProps>(
50
+ (
51
+ {
52
+ dataHook,
53
+ content,
54
+ icon: Icon = Info,
55
+ iconSize = 16,
56
+ ariaLabel,
57
+ trackingEl,
58
+ trackingLabel,
59
+ className,
60
+ ...props
61
+ },
62
+ ref
63
+ ) => {
64
+ // No TooltipProvider here on purpose: the app-level provider's
65
+ // delayDuration must reach this tooltip like any other.
66
+ return (
67
+ <Tooltip>
68
+ <TooltipTrigger
69
+ ref={ref}
70
+ aria-label={ariaLabel ?? "More info"}
71
+ className={cn(
72
+ "text-muted-foreground duration-fast hover:text-foreground focus-visible:text-foreground focus-visible:shadow-default relative inline-flex cursor-help rounded-sm transition-colors ease-out outline-none before:absolute before:-inset-1.5 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
73
+ className
74
+ )}
75
+ data-slot="info-tooltip"
76
+ dataHook={dataHook}
77
+ trackingEl={trackingEl ?? "info-tooltip"}
78
+ trackingLabel={trackingLabel}
79
+ {...props}
80
+ >
81
+ <Icon aria-hidden size={iconSize} />
82
+ </TooltipTrigger>
83
+ <TooltipContent dataHook={`${dataHook}-content`}>
84
+ {content}
85
+ </TooltipContent>
86
+ </Tooltip>
87
+ );
88
+ }
89
+ );
90
+
91
+ InfoTooltip.displayName = "InfoTooltip";
92
+
93
+ export { InfoTooltip };
94
+ export type { InfoTooltipProps };
@@ -276,7 +276,7 @@ const inputStyles = [
276
276
  "bg-transparent",
277
277
  "border-0 outline-none",
278
278
  // Typography
279
- "text-body",
279
+ "text-field",
280
280
  "text-foreground",
281
281
  // Placeholder
282
282
  "placeholder:text-muted-foreground",
@@ -3,10 +3,38 @@
3
3
  import * as React from "react";
4
4
  import { Slot } from "@radix-ui/react-slot";
5
5
  import { cva, type VariantProps } from "class-variance-authority";
6
+ import { X } from "@brightlocal/icons";
6
7
 
7
8
  import { cn } from "@brightlocal/ui-components/lib/utils";
8
9
  import { Input, type InputProps } from "./input";
9
10
 
11
+ interface InputGroupContextValue {
12
+ /** Snapshot of the composed input's DOM state, kept fresh by InputGroupInput. */
13
+ inputState: { hasValue: boolean; disabled: boolean };
14
+ /** Re-reads the composed input into `inputState`; cheap and safe to call often. */
15
+ syncInputState: () => void;
16
+ /**
17
+ * Registers the composed input element with the group. A callback rather
18
+ * than a ref write because context values are immutable to the compiler.
19
+ */
20
+ registerInput: (node: HTMLInputElement | null) => void;
21
+ /**
22
+ * Registers the input's clear routine (owned by InputGroupInput, which
23
+ * holds the consumer's `onChange`).
24
+ */
25
+ registerClearHandler: (
26
+ fn: ((event: React.SyntheticEvent) => void) | null
27
+ ) => void;
28
+ /** Clears the composed input through its React onChange and refocuses it. */
29
+ clearInput: (event: React.SyntheticEvent) => void;
30
+ /** The composed input element. */
31
+ inputRef: React.RefObject<HTMLInputElement | null>;
32
+ }
33
+
34
+ const InputGroupContext = React.createContext<InputGroupContextValue | null>(
35
+ null
36
+ );
37
+
10
38
  const inputGroupVariants = cva(
11
39
  "relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50",
12
40
  {
@@ -58,16 +86,70 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
58
86
  { className, size, error, dataHook, trackingEl, trackingLabel, ...props },
59
87
  ref
60
88
  ) => {
89
+ const [inputState, setInputState] = React.useState({
90
+ hasValue: false,
91
+ disabled: false,
92
+ });
93
+ const inputRef = React.useRef<HTMLInputElement | null>(null);
94
+ const syncInputState = React.useCallback(() => {
95
+ const input = inputRef.current;
96
+ // readOnly counts as disabled here: a field the user cannot edit must
97
+ // not offer a clear affordance either.
98
+ const next = {
99
+ hasValue: !!input && input.value.length > 0,
100
+ disabled: !!input && (input.disabled || input.readOnly),
101
+ };
102
+ setInputState((prev) =>
103
+ prev.hasValue === next.hasValue && prev.disabled === next.disabled
104
+ ? prev
105
+ : next
106
+ );
107
+ }, []);
108
+ const registerInput = React.useCallback((node: HTMLInputElement | null) => {
109
+ inputRef.current = node;
110
+ }, []);
111
+ const clearHandlerRef = React.useRef<
112
+ ((event: React.SyntheticEvent) => void) | null
113
+ >(null);
114
+ const registerClearHandler = React.useCallback(
115
+ (fn: ((event: React.SyntheticEvent) => void) | null) => {
116
+ clearHandlerRef.current = fn;
117
+ },
118
+ []
119
+ );
120
+ const clearInput = React.useCallback((event: React.SyntheticEvent) => {
121
+ clearHandlerRef.current?.(event);
122
+ }, []);
123
+ const contextValue = React.useMemo(
124
+ () => ({
125
+ inputState,
126
+ syncInputState,
127
+ registerInput,
128
+ registerClearHandler,
129
+ clearInput,
130
+ inputRef,
131
+ }),
132
+ [
133
+ inputState,
134
+ syncInputState,
135
+ registerInput,
136
+ registerClearHandler,
137
+ clearInput,
138
+ ]
139
+ );
140
+
61
141
  return (
62
- <div
63
- ref={ref}
64
- className={cn(inputGroupVariants({ size, error }), className)}
65
- data-hook={dataHook}
66
- data-slot="input-group"
67
- data-tracking-el={trackingEl}
68
- data-tracking-label={trackingLabel}
69
- {...props}
70
- />
142
+ <InputGroupContext.Provider value={contextValue}>
143
+ <div
144
+ ref={ref}
145
+ className={cn(inputGroupVariants({ size, error }), className)}
146
+ data-hook={dataHook}
147
+ data-slot="input-group"
148
+ data-tracking-el={trackingEl}
149
+ data-tracking-label={trackingLabel}
150
+ {...props}
151
+ />
152
+ </InputGroupContext.Provider>
71
153
  );
72
154
  }
73
155
  );
@@ -81,10 +163,73 @@ type InputGroupInputProps = Omit<
81
163
  const InputGroupInput = React.forwardRef<
82
164
  HTMLInputElement,
83
165
  InputGroupInputProps
84
- >(({ className, ...props }, ref) => {
166
+ >(({ className, onChange, ...props }, ref) => {
167
+ const context = React.useContext(InputGroupContext);
168
+ const localRef = React.useRef<HTMLInputElement | null>(null);
169
+
170
+ const registerInput = context?.registerInput;
171
+ const setRefs = React.useCallback(
172
+ (node: HTMLInputElement | null) => {
173
+ localRef.current = node;
174
+ registerInput?.(node);
175
+ if (typeof ref === "function") ref(node);
176
+ else if (ref) ref.current = node;
177
+ },
178
+ [registerInput, ref]
179
+ );
180
+
181
+ // Re-read the DOM after every render (no dep array): covers mount
182
+ // (defaultValue), controlled updates, disabled/readOnly toggles, and a
183
+ // controlled parent rejecting or transforming a change — React restores
184
+ // the DOM value on that render and this re-read follows it.
185
+ const syncInputState = context?.syncInputState;
186
+ React.useEffect(() => {
187
+ syncInputState?.();
188
+ });
189
+
190
+ // form.reset() restores defaultValue without firing input/change events;
191
+ // re-read once the reset steps have run.
192
+ React.useEffect(() => {
193
+ const form = localRef.current?.form;
194
+ if (!form || !syncInputState) return;
195
+ const handleReset = () => queueMicrotask(syncInputState);
196
+ form.addEventListener("reset", handleReset);
197
+ return () => form.removeEventListener("reset", handleReset);
198
+ }, [syncInputState]);
199
+
200
+ // The clear routine lives here because this component holds the consumer's
201
+ // onChange. Assigning through the element keeps React's value tracker in
202
+ // sync, and calling onChange directly with a retargeted event (instead of
203
+ // dispatching a DOM input event) keeps React's controlled-input restoration
204
+ // out of the picture — a dispatched event raced it and could resurrect the
205
+ // cleared value. Re-registered every render so the closure stays fresh.
206
+ const registerClearHandler = context?.registerClearHandler;
207
+ React.useEffect(() => {
208
+ registerClearHandler?.((event: React.SyntheticEvent) => {
209
+ const input = localRef.current;
210
+ if (!input) return;
211
+ input.value = "";
212
+ const changeEvent = Object.create(event, {
213
+ target: { value: input, enumerable: true },
214
+ currentTarget: { value: input, enumerable: true },
215
+ }) as React.ChangeEvent<HTMLInputElement>;
216
+ onChange?.(changeEvent);
217
+ syncInputState?.();
218
+ input.focus();
219
+ });
220
+ });
221
+ React.useEffect(() => {
222
+ return () => registerClearHandler?.(null);
223
+ }, [registerClearHandler]);
224
+
225
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
226
+ syncInputState?.();
227
+ onChange?.(event);
228
+ };
229
+
85
230
  return (
86
231
  <Input
87
- ref={ref}
232
+ ref={setRefs}
88
233
  className={cn(
89
234
  // Override border and focus styles since InputGroup handles them
90
235
  "border-0 focus-visible:border-0 focus-visible:shadow-[none]",
@@ -92,6 +237,7 @@ const InputGroupInput = React.forwardRef<
92
237
  className
93
238
  )}
94
239
  dataHook="input-group-input"
240
+ onChange={handleChange}
95
241
  {...props}
96
242
  />
97
243
  );
@@ -195,11 +341,99 @@ const InputGroupButton = React.forwardRef<
195
341
  });
196
342
  InputGroupButton.displayName = "InputGroupButton";
197
343
 
344
+ interface InputGroupClearProps extends Omit<
345
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
346
+ "onClick" | "children"
347
+ > {
348
+ /**
349
+ * Accessible label for the clear button.
350
+ * @default "Clear search"
351
+ */
352
+ clearSearchAriaLabel?: string;
353
+ /**
354
+ * Called after the input has been cleared.
355
+ */
356
+ onClear?: () => void;
357
+ /**
358
+ * Data hook for automated testing.
359
+ * @default "input-group-clear"
360
+ */
361
+ dataHook?: string;
362
+ /**
363
+ * Tracking element identifier for analytics
364
+ */
365
+ trackingEl?: string;
366
+ /**
367
+ * Tracking label for analytics context
368
+ */
369
+ trackingLabel?: string;
370
+ }
371
+
372
+ /**
373
+ * Opt-in clear button for InputGroup. Renders only while the composed
374
+ * `InputGroupInput` holds content and is editable (not disabled or
375
+ * read-only); clicking it clears the input (firing the input's `onChange`,
376
+ * so controlled and uncontrolled usage both work) and returns focus to it.
377
+ */
378
+ const InputGroupClear = React.forwardRef<
379
+ HTMLButtonElement,
380
+ InputGroupClearProps
381
+ >(
382
+ (
383
+ {
384
+ className,
385
+ clearSearchAriaLabel,
386
+ onClear,
387
+ dataHook,
388
+ trackingEl,
389
+ trackingLabel,
390
+ ...props
391
+ },
392
+ ref
393
+ ) => {
394
+ const context = React.useContext(InputGroupContext);
395
+ if (!context) {
396
+ throw new Error("InputGroupClear must be used within <InputGroup>");
397
+ }
398
+ const { inputState, clearInput } = context;
399
+ if (!inputState.hasValue || inputState.disabled) return null;
400
+
401
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
402
+ // Delegates to InputGroupInput's registered routine: it clears the
403
+ // element, fires the consumer's onChange, and refocuses the input.
404
+ clearInput(event);
405
+ onClear?.();
406
+ };
407
+
408
+ return (
409
+ <InputGroupButton
410
+ ref={ref}
411
+ aria-label={clearSearchAriaLabel ?? "Clear search"}
412
+ // The button is the rendered root: alignment lives here so the
413
+ // consumer's className, ref, and data attributes reach the real element.
414
+ // Fully rounded to match Button's icon shape.
415
+ className={cn("mr-1 ml-auto shrink-0 rounded-full", className)}
416
+ data-hook={dataHook ?? "input-group-clear"}
417
+ data-slot="input-group-clear"
418
+ data-tracking-el={trackingEl}
419
+ data-tracking-label={trackingLabel}
420
+ size="icon-xs"
421
+ onClick={handleClick}
422
+ {...props}
423
+ >
424
+ <X size={14} />
425
+ </InputGroupButton>
426
+ );
427
+ }
428
+ );
429
+ InputGroupClear.displayName = "InputGroupClear";
430
+
198
431
  export {
199
432
  InputGroup,
200
433
  InputGroupInput,
201
434
  InputGroupAddon,
202
435
  InputGroupButton,
436
+ InputGroupClear,
203
437
  inputGroupVariants,
204
438
  inputGroupButtonVariants,
205
439
  };
@@ -208,4 +442,5 @@ export type {
208
442
  InputGroupInputProps,
209
443
  InputGroupAddonProps,
210
444
  InputGroupButtonProps,
445
+ InputGroupClearProps,
211
446
  };
@@ -137,7 +137,7 @@ function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
137
137
  // Base styles
138
138
  "relative flex h-9 w-9 items-center justify-center",
139
139
  "border-input bg-background border-y border-r",
140
- "text-foreground duration-fast text-body transition-[border-color,box-shadow] ease-out outline-none",
140
+ "text-foreground duration-fast text-field transition-[border-color,box-shadow] ease-out outline-none",
141
141
  "first:rounded-l-md first:border-l last:rounded-r-md",
142
142
  // Focus state
143
143
  "data-[active=true]:border-ring data-[active=true]:z-10",
@@ -26,23 +26,45 @@ type DefaultPasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
26
26
  * Configuration for a single strength level
27
27
  */
28
28
  interface StrengthLevelConfig {
29
+ /** Text shown beside the bar for this level, e.g. `"Weak"` */
29
30
  label: string;
31
+ /** Bar fill as a percentage, 0–100 */
30
32
  value: number;
33
+ /**
34
+ * Background utility for the bar fill. Use the Progress bar palette
35
+ * (`bg-green-400`, `bg-brand-red`, `bg-brand-orange`, `bg-brand-yellow`,
36
+ * `bg-muted`) so custom levels stay consistent with Progress (DS-773).
37
+ */
31
38
  color: string;
32
39
  }
33
40
 
34
41
  /**
35
42
  * Default strength levels configuration
43
+ *
44
+ * DESIGN DECISION (DS-293, kept in DS-666): every level shares one fill. The
45
+ * bar's length and the label ("Weak" … "Great") carry the strength, so colour
46
+ * is never the only indicator of state. Per-level red/amber/green would also
47
+ * have to come from the alert-surface tokens (`success-background` is green-200
48
+ * in light, green-950 in dark) — tints tuned as a backdrop, which read as a
49
+ * washed-out or near-black 8px bar.
50
+ *
51
+ * The fill is `green-400` — the same fill the green Progress bar uses, a
52
+ * documented palette-step-by-choice with Figma parity (DS-773, see
53
+ * progress.tsx). The meter IS a Progress, so its green must match; the track
54
+ * beneath stays Progress's own `brand-primary-foreground/20`. The token-first
55
+ * alternative (`bg-brand-primary-foreground`) was tried in DS-666 and rejected
56
+ * in review: its dark value (#00851E) renders a dim bar that diverges from
57
+ * every other green Progress on the page.
36
58
  */
37
59
  const DEFAULT_STRENGTH_LEVELS: Record<
38
60
  DefaultPasswordStrength,
39
61
  StrengthLevelConfig
40
62
  > = {
41
- meter: { label: "Meter", value: 0, color: "bg-green-500" },
42
- weak: { label: "Weak", value: 25, color: "bg-green-500" },
43
- ok: { label: "Ok", value: 50, color: "bg-green-500" },
44
- good: { label: "Good", value: 75, color: "bg-green-500" },
45
- great: { label: "Great", value: 100, color: "bg-green-500" },
63
+ meter: { label: "Meter", value: 0, color: "bg-green-400" },
64
+ weak: { label: "Weak", value: 25, color: "bg-green-400" },
65
+ ok: { label: "Ok", value: 50, color: "bg-green-400" },
66
+ good: { label: "Good", value: 75, color: "bg-green-400" },
67
+ great: { label: "Great", value: 100, color: "bg-green-400" },
46
68
  };
47
69
 
48
70
  /**
@@ -114,17 +136,17 @@ function useInputPasswordContext() {
114
136
  const context = React.useContext(InputPasswordContext);
115
137
  if (!context) {
116
138
  throw new Error(
117
- "InputPassword compound components must be used within InputPasswordRoot"
139
+ "InputPassword compound components must be used within InputPassword"
118
140
  );
119
141
  }
120
142
  return context;
121
143
  }
122
144
 
123
145
  // ============================================================================
124
- // InputPasswordRoot
146
+ // InputPassword (root)
125
147
  // ============================================================================
126
148
 
127
- export interface InputPasswordRootProps<
149
+ export interface InputPasswordProps<
128
150
  T extends string = DefaultPasswordStrength,
129
151
  > {
130
152
  /**
@@ -161,9 +183,9 @@ export interface InputPasswordRootProps<
161
183
  * @example
162
184
  * strengthLevels={{
163
185
  * empty: { label: "Enter password", value: 0, color: "bg-muted" },
164
- * slow: { label: "Slow", value: 33, color: "bg-red-500" },
165
- * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
166
- * fast: { label: "Fast", value: 100, color: "bg-green-500" },
186
+ * slow: { label: "Slow", value: 33, color: "bg-brand-red" },
187
+ * medium: { label: "Medium", value: 66, color: "bg-brand-yellow" },
188
+ * fast: { label: "Fast", value: 100, color: "bg-green-400" },
167
189
  * }}
168
190
  */
169
191
  strengthLevels?: Record<T, StrengthLevelConfig>;
@@ -192,22 +214,22 @@ export interface InputPasswordRootProps<
192
214
  }
193
215
 
194
216
  /**
195
- * InputPasswordRoot - Root component that provides context for all InputPassword parts
217
+ * InputPassword - Root component that provides context for all InputPassword parts
196
218
  *
197
219
  * Generic type parameter T allows custom strength levels:
198
220
  * @example
199
221
  * // Using default levels
200
- * <InputPasswordRoot dataHook="password">...</InputPasswordRoot>
222
+ * <InputPassword dataHook="password">...</InputPassword>
201
223
  *
202
224
  * // Using custom levels
203
225
  * type MyStrength = "empty" | "slow" | "medium" | "fast";
204
- * <InputPasswordRoot<MyStrength>
226
+ * <InputPassword<MyStrength>
205
227
  * dataHook="password"
206
228
  * strengthLevels={{
207
229
  * empty: { label: "Enter password", value: 0, color: "bg-muted" },
208
- * slow: { label: "Slow", value: 33, color: "bg-red-500" },
209
- * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
210
- * fast: { label: "Fast", value: 100, color: "bg-green-500" },
230
+ * slow: { label: "Slow", value: 33, color: "bg-brand-red" },
231
+ * medium: { label: "Medium", value: 66, color: "bg-brand-yellow" },
232
+ * fast: { label: "Fast", value: 100, color: "bg-green-400" },
211
233
  * }}
212
234
  * calculateStrength={(password) => {
213
235
  * if (!password) return "empty";
@@ -217,9 +239,9 @@ export interface InputPasswordRootProps<
217
239
  * }}
218
240
  * >
219
241
  * ...
220
- * </InputPasswordRoot>
242
+ * </InputPassword>
221
243
  */
222
- function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
244
+ function InputPassword<T extends string = DefaultPasswordStrength>({
223
245
  children,
224
246
  dataHook,
225
247
  trackingEl,
@@ -233,7 +255,7 @@ function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
233
255
  error,
234
256
  id,
235
257
  className,
236
- }: InputPasswordRootProps<T>) {
258
+ }: InputPasswordProps<T>) {
237
259
  const [showPassword, setShowPassword] = React.useState(false);
238
260
  const [internalPassword, setInternalPassword] = React.useState("");
239
261
  const [strength, setStrength] = React.useState<string>("meter");
@@ -323,7 +345,18 @@ function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
323
345
  );
324
346
  }
325
347
 
326
- InputPasswordRoot.displayName = "InputPasswordRoot";
348
+ InputPassword.displayName = "InputPassword";
349
+
350
+ /**
351
+ * @deprecated Use `InputPassword` instead — family roots are bare names (DS-853).
352
+ */
353
+ const InputPasswordRoot = InputPassword;
354
+
355
+ /**
356
+ * @deprecated Use `InputPasswordProps` instead — family roots are bare names (DS-853).
357
+ */
358
+ export type InputPasswordRootProps<T extends string = DefaultPasswordStrength> =
359
+ InputPasswordProps<T>;
327
360
 
328
361
  // ============================================================================
329
362
  // InputPasswordField
@@ -501,7 +534,7 @@ export interface InputPasswordStrengthProps {
501
534
  /**
502
535
  * InputPasswordStrength - Password strength indicator
503
536
  * Displays a progress bar and optional label showing password strength.
504
- * Automatically uses the strength levels configured on InputPasswordRoot.
537
+ * Automatically uses the strength levels configured on InputPassword.
505
538
  */
506
539
  function InputPasswordStrength({
507
540
  className,
@@ -546,6 +579,7 @@ InputPasswordStrength.displayName = "InputPasswordStrength";
546
579
  // ============================================================================
547
580
 
548
581
  export {
582
+ InputPassword,
549
583
  InputPasswordRoot,
550
584
  InputPasswordField,
551
585
  InputPasswordToggle,
@@ -16,7 +16,7 @@ export const inputVariants = cva(
16
16
  "border border-input bg-background rounded-sm",
17
17
  "outline-none transition-[border-color,box-shadow,background-color] duration-fast ease-out",
18
18
  // Typography
19
- "text-body",
19
+ "text-field",
20
20
  "text-foreground",
21
21
  "overflow-hidden text-ellipsis",
22
22
  // States - Focus
@@ -26,7 +26,7 @@ const itemVariants = cva(
26
26
  variants: {
27
27
  variant: {
28
28
  default: [],
29
- filled: ["bg-card"],
29
+ filled: ["bg-muted"],
30
30
  outline: ["bg-background", "border", "border-border"],
31
31
  loading: ["p-0"],
32
32
  },