@brightlocal/ui-components 3.1.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 (176) hide show
  1. package/README.md +6 -1
  2. package/component-meta.json +663 -38
  3. package/deprecations.json +1 -1
  4. package/dist/alert-dialog.cjs +1 -1
  5. package/dist/alert-dialog.d.ts +32 -3
  6. package/dist/alert-dialog.d.ts.map +1 -1
  7. package/dist/alert-dialog.js +61 -58
  8. package/dist/alert.cjs +1 -1
  9. package/dist/alert.d.ts.map +1 -1
  10. package/dist/alert.js +58 -57
  11. package/dist/badge.cjs +1 -1
  12. package/dist/badge.d.ts +9 -0
  13. package/dist/badge.d.ts.map +1 -1
  14. package/dist/badge.js +50 -30
  15. package/dist/banner.cjs +1 -0
  16. package/dist/banner.d.ts +81 -0
  17. package/dist/banner.d.ts.map +1 -0
  18. package/dist/banner.js +176 -0
  19. package/dist/blocks/empty-state.cjs +1 -1
  20. package/dist/blocks/empty-state.d.ts +4 -3
  21. package/dist/blocks/empty-state.d.ts.map +1 -1
  22. package/dist/blocks/empty-state.js +21 -20
  23. package/dist/blocks/progress-state.d.ts +2 -2
  24. package/dist/blocks/sidebar.cjs +1 -1
  25. package/dist/blocks/sidebar.d.ts +17 -0
  26. package/dist/blocks/sidebar.d.ts.map +1 -1
  27. package/dist/blocks/sidebar.js +8 -2
  28. package/dist/brand-illustration-motif.d.ts +1 -1
  29. package/dist/card.cjs +1 -1
  30. package/dist/card.d.ts +86 -6
  31. package/dist/card.d.ts.map +1 -1
  32. package/dist/card.js +185 -96
  33. package/dist/chart.cjs +3 -3
  34. package/dist/chart.d.ts +231 -13
  35. package/dist/chart.d.ts.map +1 -1
  36. package/dist/chart.js +466 -306
  37. package/dist/checkbox.cjs +1 -1
  38. package/dist/checkbox.d.ts +1 -1
  39. package/dist/checkbox.d.ts.map +1 -1
  40. package/dist/checkbox.js +2 -1
  41. package/dist/combobox.cjs +1 -1
  42. package/dist/combobox.js +2 -2
  43. package/dist/command.cjs +1 -1
  44. package/dist/command.js +1 -1
  45. package/dist/data-table.cjs +1 -1
  46. package/dist/data-table.d.ts +169 -22
  47. package/dist/data-table.d.ts.map +1 -1
  48. package/dist/data-table.js +695 -561
  49. package/dist/grid.d.ts +24 -1
  50. package/dist/grid.d.ts.map +1 -1
  51. package/dist/hooks/use-breakpoint.cjs +1 -1
  52. package/dist/hooks/use-breakpoint.d.ts +1 -1
  53. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  54. package/dist/hooks/use-breakpoint.js +1 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.d.ts +5 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +593 -561
  59. package/dist/info-tooltip.cjs +1 -0
  60. package/dist/info-tooltip.d.ts +39 -0
  61. package/dist/info-tooltip.d.ts.map +1 -0
  62. package/dist/info-tooltip.js +41 -0
  63. package/dist/input-chip.cjs +1 -1
  64. package/dist/input-chip.js +1 -1
  65. package/dist/input-group.cjs +1 -1
  66. package/dist/input-group.d.ts +33 -2
  67. package/dist/input-group.d.ts.map +1 -1
  68. package/dist/input-group.js +167 -54
  69. package/dist/input-otp.cjs +1 -1
  70. package/dist/input-otp.js +9 -9
  71. package/dist/input-password.cjs +1 -1
  72. package/dist/input-password.d.ts +28 -6
  73. package/dist/input-password.d.ts.map +1 -1
  74. package/dist/input-password.js +5 -5
  75. package/dist/input.cjs +1 -1
  76. package/dist/input.js +10 -10
  77. package/dist/lib/block-illustration.cjs +1 -1
  78. package/dist/lib/block-illustration.d.ts +4 -1
  79. package/dist/lib/block-illustration.d.ts.map +1 -1
  80. package/dist/lib/block-illustration.js +12 -11
  81. package/dist/lib/utils.cjs +1 -1
  82. package/dist/lib/utils.d.ts.map +1 -1
  83. package/dist/lib/utils.js +4 -3
  84. package/dist/list.cjs +1 -1
  85. package/dist/list.js +1 -1
  86. package/dist/multi-select-filter.cjs +1 -0
  87. package/dist/multi-select-filter.d.ts +178 -0
  88. package/dist/multi-select-filter.d.ts.map +1 -0
  89. package/dist/multi-select-filter.js +463 -0
  90. package/dist/progress.cjs +1 -1
  91. package/dist/progress.d.ts +123 -16
  92. package/dist/progress.d.ts.map +1 -1
  93. package/dist/progress.js +89 -75
  94. package/dist/rating.cjs +1 -1
  95. package/dist/rating.js +18 -18
  96. package/dist/relative-date.cjs +1 -0
  97. package/dist/relative-date.d.ts +65 -0
  98. package/dist/relative-date.d.ts.map +1 -0
  99. package/dist/relative-date.js +128 -0
  100. package/dist/select.cjs +2 -2
  101. package/dist/select.d.ts +11 -1
  102. package/dist/select.d.ts.map +1 -1
  103. package/dist/select.js +97 -81
  104. package/dist/sheet.cjs +1 -1
  105. package/dist/sheet.d.ts +78 -2
  106. package/dist/sheet.d.ts.map +1 -1
  107. package/dist/sheet.js +192 -85
  108. package/dist/single-select-filter.cjs +1 -0
  109. package/dist/single-select-filter.d.ts +81 -0
  110. package/dist/single-select-filter.d.ts.map +1 -0
  111. package/dist/single-select-filter.js +226 -0
  112. package/dist/sonner.cjs +1 -1
  113. package/dist/sonner.d.ts.map +1 -1
  114. package/dist/sonner.js +22 -22
  115. package/dist/split-layout.cjs +1 -1
  116. package/dist/split-layout.d.ts +1 -1
  117. package/dist/split-layout.js +13 -13
  118. package/dist/table.cjs +1 -1
  119. package/dist/table.d.ts +45 -4
  120. package/dist/table.d.ts.map +1 -1
  121. package/dist/table.js +90 -73
  122. package/dist/tabs.cjs +1 -1
  123. package/dist/tabs.d.ts +12 -1
  124. package/dist/tabs.d.ts.map +1 -1
  125. package/dist/tabs.js +148 -126
  126. package/dist/textarea.cjs +1 -1
  127. package/dist/textarea.js +1 -1
  128. package/dist/tooltip.cjs +1 -1
  129. package/dist/tooltip.d.ts +38 -36
  130. package/dist/tooltip.d.ts.map +1 -1
  131. package/dist/tooltip.js +262 -73
  132. package/dist/typography-text.d.ts +1 -2
  133. package/dist/typography-text.d.ts.map +1 -1
  134. package/dist/typography.d.ts +1 -1
  135. package/package.json +5 -6
  136. package/src/blocks/empty-state.tsx +8 -3
  137. package/src/blocks/progress-state.tsx +2 -2
  138. package/src/blocks/sidebar.tsx +26 -2
  139. package/src/components/alert-dialog.tsx +50 -5
  140. package/src/components/alert.tsx +16 -8
  141. package/src/components/badge.tsx +40 -3
  142. package/src/components/banner.tsx +288 -0
  143. package/src/components/brand-illustration-motif.tsx +1 -1
  144. package/src/components/card.tsx +211 -24
  145. package/src/components/chart.tsx +523 -35
  146. package/src/components/checkbox.tsx +1 -1
  147. package/src/components/combobox.tsx +2 -2
  148. package/src/components/command.tsx +1 -1
  149. package/src/components/data-table.tsx +778 -195
  150. package/src/components/grid.tsx +32 -1
  151. package/src/components/info-tooltip.tsx +94 -0
  152. package/src/components/input-chip.tsx +1 -1
  153. package/src/components/input-group.tsx +246 -11
  154. package/src/components/input-otp.tsx +1 -1
  155. package/src/components/input-password.tsx +33 -11
  156. package/src/components/input.tsx +1 -1
  157. package/src/components/list.tsx +1 -1
  158. package/src/components/multi-select-filter.tsx +912 -0
  159. package/src/components/progress.tsx +190 -31
  160. package/src/components/rating.tsx +1 -1
  161. package/src/components/relative-date.tsx +230 -0
  162. package/src/components/select.tsx +35 -5
  163. package/src/components/sheet.tsx +240 -4
  164. package/src/components/single-select-filter.tsx +443 -0
  165. package/src/components/sonner.tsx +16 -5
  166. package/src/components/split-layout.tsx +2 -2
  167. package/src/components/table.tsx +71 -11
  168. package/src/components/tabs.tsx +93 -46
  169. package/src/components/textarea.tsx +1 -1
  170. package/src/components/tooltip.tsx +440 -68
  171. package/src/components/typography-text.tsx +1 -2
  172. package/src/components/typography.tsx +1 -1
  173. package/src/hooks/use-breakpoint.ts +2 -1
  174. package/src/index.ts +5 -0
  175. package/src/lib/block-illustration.tsx +5 -1
  176. package/src/lib/utils.ts +1 -0
@@ -31,6 +31,14 @@ import { OpticalCenter } from "../lib/optical-center";
31
31
  * padding) for pages outside the app shell — auth, invites. Grid owns nothing
32
32
  * but the position inside whatever box it is given.
33
33
  *
34
+ * The flex chain (DS-1058): `centered` stretches with `flex-1`, and `flex-1`
35
+ * only means something inside a flex column that itself has height. Every box
36
+ * between the page body and the Grid must continue that chain (`flex flex-1
37
+ * flex-col`). A plain `<div>` in between breaks it silently: the Grid shrinks to
38
+ * its content, both spacers collapse to zero, and the message is centred
39
+ * horizontally only — it hugs the top of the body. The fix is the chain, never
40
+ * a top margin on the call site.
41
+ *
34
42
  * The single-message blocks are deliberately NOT wired to this internally:
35
43
  * `EmptyState size="lg"` is a pure visual block, and the page recipe is the
36
44
  * composition `<Grid variant="centered"><EmptyState size="lg" /></Grid>` — so
@@ -64,6 +72,10 @@ interface GridBaseProps extends React.ComponentPropsWithoutRef<"div"> {
64
72
  /**
65
73
  * One message at the page body's optical centre (38/62). Give it a page body
66
74
  * to fill — it stretches with `flex-1` — and one message to hold.
75
+ *
76
+ * Requires an unbroken flex chain: the Grid's parent, and every wrapper up to
77
+ * the page body, must be a `flex flex-1 flex-col` box. Behind a non-flex
78
+ * wrapper it centres horizontally only — fix the wrapper, do not add a margin.
67
79
  */
68
80
  interface GridCenteredProps extends GridBaseProps {
69
81
  variant: "centered";
@@ -85,13 +97,32 @@ export type GridProps = GridCenteredProps;
85
97
  * <Grid dataHook="locations-empty-center" variant="centered">
86
98
  * <EmptyState
87
99
  * dataHook="locations-empty"
88
- * illustration={<BusinessLocation aria-hidden />}
100
+ * illustration={<SmallBusiness aria-hidden />}
89
101
  * size="lg"
90
102
  * title={t("locations.empty.title")}
91
103
  * />
92
104
  * </Grid>
93
105
  * </GlobalLayoutBody>
94
106
  * ```
107
+ *
108
+ * @example
109
+ * Wrappers between the page body and the Grid must continue the flex chain:
110
+ * ```tsx
111
+ * // Broken — the plain <div> has no height to give, so the Grid collapses to
112
+ * // its content and the message hugs the top (horizontal centring only).
113
+ * <GlobalLayoutBody dataHook="search-body">
114
+ * <div>
115
+ * <Grid dataHook="search-empty-center" variant="centered">…</Grid>
116
+ * </div>
117
+ * </GlobalLayoutBody>
118
+ *
119
+ * // Fixed — the wrapper passes the height down.
120
+ * <GlobalLayoutBody dataHook="search-body">
121
+ * <div className="flex flex-1 flex-col">
122
+ * <Grid dataHook="search-empty-center" variant="centered">…</Grid>
123
+ * </div>
124
+ * </GlobalLayoutBody>
125
+ * ```
95
126
  */
96
127
  const Grid = React.forwardRef<HTMLDivElement, GridProps>(
97
128
  (
@@ -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
  /**
@@ -161,9 +183,9 @@ export interface InputPasswordProps<
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>;
@@ -205,9 +227,9 @@ export interface InputPasswordProps<
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";
@@ -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
  },