@brightlocal/ui-components 2.27.0 → 3.1.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 (289) hide show
  1. package/README.md +7 -1
  2. package/component-meta.json +568 -143
  3. package/deprecations.json +298 -1
  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.js +18 -18
  10. package/dist/alert.cjs +1 -1
  11. package/dist/alert.d.ts +11 -1
  12. package/dist/alert.d.ts.map +1 -1
  13. package/dist/alert.js +31 -28
  14. package/dist/avatar.cjs +1 -1
  15. package/dist/avatar.js +4 -4
  16. package/dist/badge.cjs +1 -1
  17. package/dist/badge.d.ts.map +1 -1
  18. package/dist/badge.js +15 -11
  19. package/dist/blocks/empty-state.cjs +1 -0
  20. package/dist/blocks/empty-state.d.ts +172 -0
  21. package/dist/blocks/empty-state.d.ts.map +1 -0
  22. package/dist/blocks/empty-state.js +147 -0
  23. package/dist/blocks/input-list.cjs +2 -2
  24. package/dist/blocks/input-list.d.ts.map +1 -1
  25. package/dist/blocks/input-list.js +124 -108
  26. package/dist/blocks/progress-state.cjs +1 -0
  27. package/dist/blocks/{progress-screen.d.ts → progress-state.d.ts} +30 -18
  28. package/dist/blocks/progress-state.d.ts.map +1 -0
  29. package/dist/blocks/{progress-screen.js → progress-state.js} +100 -71
  30. package/dist/blocks/sidebar.cjs +1 -1
  31. package/dist/blocks/sidebar.d.ts.map +1 -1
  32. package/dist/blocks/sidebar.js +160 -161
  33. package/dist/breadcrumb.cjs +1 -1
  34. package/dist/breadcrumb.js +1 -1
  35. package/dist/button-group.cjs +1 -0
  36. package/dist/button-group.d.ts +36 -0
  37. package/dist/button-group.d.ts.map +1 -0
  38. package/dist/button-group.js +47 -0
  39. package/dist/button.cjs +1 -1
  40. package/dist/button.js +12 -12
  41. package/dist/calendar.cjs +1 -1
  42. package/dist/calendar.d.ts.map +1 -1
  43. package/dist/calendar.js +37 -38
  44. package/dist/callout.cjs +1 -1
  45. package/dist/callout.d.ts +24 -2
  46. package/dist/callout.d.ts.map +1 -1
  47. package/dist/callout.js +57 -55
  48. package/dist/card.cjs +1 -1
  49. package/dist/card.d.ts +42 -3
  50. package/dist/card.d.ts.map +1 -1
  51. package/dist/card.js +102 -91
  52. package/dist/chart-empty.cjs +1 -0
  53. package/dist/chart-empty.d.ts +59 -0
  54. package/dist/chart-empty.d.ts.map +1 -0
  55. package/dist/chart-empty.js +29 -0
  56. package/dist/chart.cjs +6 -6
  57. package/dist/chart.d.ts +46 -13
  58. package/dist/chart.d.ts.map +1 -1
  59. package/dist/chart.js +172 -157
  60. package/dist/chip.cjs +1 -1
  61. package/dist/chip.d.ts +38 -4
  62. package/dist/chip.d.ts.map +1 -1
  63. package/dist/chip.js +100 -84
  64. package/dist/combobox.cjs +2 -2
  65. package/dist/combobox.d.ts.map +1 -1
  66. package/dist/combobox.js +81 -79
  67. package/dist/command.cjs +1 -1
  68. package/dist/command.d.ts +23 -1
  69. package/dist/command.d.ts.map +1 -1
  70. package/dist/command.js +248 -225
  71. package/dist/context-menu.cjs +1 -1
  72. package/dist/context-menu.d.ts.map +1 -1
  73. package/dist/context-menu.js +26 -29
  74. package/dist/data-table.cjs +1 -1
  75. package/dist/data-table.d.ts +75 -10
  76. package/dist/data-table.d.ts.map +1 -1
  77. package/dist/data-table.js +346 -334
  78. package/dist/date-picker.cjs +1 -1
  79. package/dist/date-picker.d.ts +13 -5
  80. package/dist/date-picker.d.ts.map +1 -1
  81. package/dist/date-picker.js +54 -53
  82. package/dist/description.cjs +1 -1
  83. package/dist/description.js +5 -5
  84. package/dist/dialog.cjs +1 -1
  85. package/dist/dialog.js +20 -20
  86. package/dist/drawer.cjs +1 -1
  87. package/dist/drawer.d.ts.map +1 -1
  88. package/dist/drawer.js +8 -11
  89. package/dist/dropdown-menu.cjs +1 -1
  90. package/dist/dropdown-menu.d.ts.map +1 -1
  91. package/dist/dropdown-menu.js +17 -20
  92. package/dist/field.cjs +1 -1
  93. package/dist/field.d.ts +8 -1
  94. package/dist/field.d.ts.map +1 -1
  95. package/dist/field.js +96 -65
  96. package/dist/global-layout.cjs +1 -1
  97. package/dist/global-layout.d.ts +130 -12
  98. package/dist/global-layout.d.ts.map +1 -1
  99. package/dist/global-layout.js +146 -127
  100. package/dist/grid.cjs +1 -0
  101. package/dist/grid.d.ts +56 -0
  102. package/dist/grid.d.ts.map +1 -0
  103. package/dist/grid.js +32 -0
  104. package/dist/header.d.ts +13 -0
  105. package/dist/header.d.ts.map +1 -1
  106. package/dist/hooks/use-delayed-pending.cjs +1 -0
  107. package/dist/hooks/use-delayed-pending.d.ts +34 -0
  108. package/dist/hooks/use-delayed-pending.d.ts.map +1 -0
  109. package/dist/hooks/use-delayed-pending.js +17 -0
  110. package/dist/hooks/use-mobile.cjs +1 -0
  111. package/dist/hooks/use-mobile.js +8 -0
  112. package/dist/hover-card.cjs +1 -1
  113. package/dist/hover-card.js +13 -13
  114. package/dist/index.cjs +1 -1
  115. package/dist/index.d.ts +9 -1
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +554 -527
  118. package/dist/input-chip.cjs +1 -1
  119. package/dist/input-chip.js +25 -25
  120. package/dist/input-group.cjs +1 -1
  121. package/dist/input-group.js +9 -9
  122. package/dist/input-otp.cjs +1 -1
  123. package/dist/input-otp.js +9 -9
  124. package/dist/input-password.cjs +1 -1
  125. package/dist/input-password.d.ts +17 -9
  126. package/dist/input-password.d.ts.map +1 -1
  127. package/dist/input-password.js +73 -72
  128. package/dist/input.cjs +1 -1
  129. package/dist/input.js +9 -9
  130. package/dist/label.cjs +1 -1
  131. package/dist/label.d.ts.map +1 -1
  132. package/dist/label.js +25 -28
  133. package/dist/lib/block-illustration.cjs +1 -0
  134. package/dist/lib/block-illustration.d.ts +28 -0
  135. package/dist/lib/block-illustration.d.ts.map +1 -0
  136. package/dist/lib/block-illustration.js +21 -0
  137. package/dist/lib/empty-canvas.cjs +1 -0
  138. package/dist/lib/empty-canvas.d.ts +27 -0
  139. package/dist/lib/empty-canvas.d.ts.map +1 -0
  140. package/dist/lib/empty-canvas.js +62 -0
  141. package/dist/lib/empty-chip.cjs +1 -0
  142. package/dist/lib/empty-chip.d.ts +4 -0
  143. package/dist/lib/empty-chip.d.ts.map +1 -0
  144. package/dist/lib/empty-chip.js +13 -0
  145. package/dist/lib/optical-center.cjs +1 -0
  146. package/dist/lib/optical-center.d.ts +12 -0
  147. package/dist/lib/optical-center.d.ts.map +1 -0
  148. package/dist/lib/optical-center.js +11 -0
  149. package/dist/lib/utils.cjs +1 -1
  150. package/dist/lib/utils.d.ts.map +1 -1
  151. package/dist/lib/utils.js +28 -5
  152. package/dist/list.cjs +1 -1
  153. package/dist/list.d.ts.map +1 -1
  154. package/dist/list.js +62 -58
  155. package/dist/map.cjs +1 -1
  156. package/dist/map.d.ts +60 -2
  157. package/dist/map.d.ts.map +1 -1
  158. package/dist/map.js +187 -164
  159. package/dist/media-empty.cjs +1 -0
  160. package/dist/media-empty.d.ts +72 -0
  161. package/dist/media-empty.d.ts.map +1 -0
  162. package/dist/media-empty.js +45 -0
  163. package/dist/menubar.cjs +1 -1
  164. package/dist/menubar.d.ts.map +1 -1
  165. package/dist/menubar.js +17 -20
  166. package/dist/navigation-menu.cjs +1 -1
  167. package/dist/navigation-menu.js +7 -7
  168. package/dist/pagination.cjs +1 -1
  169. package/dist/pagination.d.ts +130 -1
  170. package/dist/pagination.d.ts.map +1 -1
  171. package/dist/pagination.js +193 -102
  172. package/dist/progress.cjs +1 -1
  173. package/dist/progress.d.ts +2 -26
  174. package/dist/progress.d.ts.map +1 -1
  175. package/dist/progress.js +79 -118
  176. package/dist/scroll-area.cjs +1 -1
  177. package/dist/scroll-area.d.ts +15 -6
  178. package/dist/scroll-area.d.ts.map +1 -1
  179. package/dist/scroll-area.js +38 -36
  180. package/dist/select.cjs +2 -2
  181. package/dist/select.d.ts +13 -2
  182. package/dist/select.d.ts.map +1 -1
  183. package/dist/select.js +92 -87
  184. package/dist/separator.cjs +1 -1
  185. package/dist/separator.js +8 -8
  186. package/dist/sheet.cjs +1 -1
  187. package/dist/sheet.js +2 -2
  188. package/dist/skeleton.cjs +1 -1
  189. package/dist/skeleton.d.ts +38 -3
  190. package/dist/skeleton.d.ts.map +1 -1
  191. package/dist/skeleton.js +43 -20
  192. package/dist/sonner.cjs +1 -1
  193. package/dist/sonner.js +26 -26
  194. package/dist/stepper.cjs +1 -1
  195. package/dist/stepper.js +40 -40
  196. package/dist/table.cjs +1 -1
  197. package/dist/table.d.ts.map +1 -1
  198. package/dist/table.js +31 -28
  199. package/dist/tabs.cjs +1 -1
  200. package/dist/tabs.js +1 -1
  201. package/dist/text-reveal-motion.d.ts +10 -0
  202. package/dist/text-reveal-motion.d.ts.map +1 -1
  203. package/dist/textarea.cjs +1 -1
  204. package/dist/textarea.js +11 -11
  205. package/dist/toggle.cjs +1 -1
  206. package/dist/toggle.js +8 -8
  207. package/dist/tooltip.cjs +1 -1
  208. package/dist/tooltip.js +8 -8
  209. package/dist/typography-heading.cjs +1 -0
  210. package/dist/typography-heading.d.ts +129 -0
  211. package/dist/typography-heading.d.ts.map +1 -0
  212. package/dist/typography-heading.js +95 -0
  213. package/dist/typography-text.cjs +1 -0
  214. package/dist/typography-text.d.ts +127 -0
  215. package/dist/typography-text.d.ts.map +1 -0
  216. package/dist/typography-text.js +92 -0
  217. package/dist/typography.d.ts +13 -0
  218. package/dist/typography.d.ts.map +1 -1
  219. package/package.json +35 -7
  220. package/src/blocks/empty-state.tsx +412 -0
  221. package/src/blocks/input-list.tsx +66 -36
  222. package/src/blocks/{progress-screen.tsx → progress-state.tsx} +154 -93
  223. package/src/blocks/sidebar.tsx +25 -26
  224. package/src/components/accordion.tsx +82 -27
  225. package/src/components/alert-dialog.tsx +2 -2
  226. package/src/components/alert.tsx +27 -13
  227. package/src/components/avatar.tsx +1 -1
  228. package/src/components/badge.tsx +8 -4
  229. package/src/components/breadcrumb.tsx +1 -1
  230. package/src/components/button-group.tsx +112 -0
  231. package/src/components/button.tsx +4 -4
  232. package/src/components/calendar.tsx +5 -6
  233. package/src/components/callout.tsx +48 -15
  234. package/src/components/card.tsx +89 -19
  235. package/src/components/chart-empty.tsx +116 -0
  236. package/src/components/chart.tsx +103 -32
  237. package/src/components/chip.tsx +88 -13
  238. package/src/components/combobox.tsx +12 -10
  239. package/src/components/command.tsx +64 -13
  240. package/src/components/context-menu.tsx +6 -9
  241. package/src/components/data-table.tsx +135 -20
  242. package/src/components/date-picker.tsx +18 -7
  243. package/src/components/description.tsx +1 -1
  244. package/src/components/dialog.tsx +2 -2
  245. package/src/components/drawer.tsx +2 -5
  246. package/src/components/dropdown-menu.tsx +8 -11
  247. package/src/components/field.tsx +89 -16
  248. package/src/components/global-layout.tsx +210 -39
  249. package/src/components/grid.tsx +130 -0
  250. package/src/components/header.tsx +13 -0
  251. package/src/components/hover-card.tsx +1 -1
  252. package/src/components/input-chip.tsx +1 -1
  253. package/src/components/input-group.tsx +1 -1
  254. package/src/components/input-otp.tsx +1 -1
  255. package/src/components/input-password.tsx +24 -12
  256. package/src/components/input.tsx +1 -1
  257. package/src/components/label.tsx +10 -13
  258. package/src/components/list.tsx +13 -9
  259. package/src/components/map.tsx +101 -5
  260. package/src/components/media-empty.tsx +156 -0
  261. package/src/components/menubar.tsx +7 -10
  262. package/src/components/navigation-menu.tsx +1 -1
  263. package/src/components/pagination.tsx +286 -1
  264. package/src/components/progress.tsx +35 -113
  265. package/src/components/scroll-area.tsx +23 -10
  266. package/src/components/select.tsx +35 -10
  267. package/src/components/separator.tsx +1 -1
  268. package/src/components/sheet.tsx +2 -2
  269. package/src/components/skeleton.tsx +78 -7
  270. package/src/components/sonner.tsx +2 -2
  271. package/src/components/stepper.tsx +3 -3
  272. package/src/components/table.tsx +6 -3
  273. package/src/components/tabs.tsx +1 -1
  274. package/src/components/text-reveal-motion.tsx +10 -0
  275. package/src/components/textarea.tsx +1 -1
  276. package/src/components/toggle.tsx +1 -1
  277. package/src/components/tooltip.tsx +1 -1
  278. package/src/components/typography-heading.tsx +253 -0
  279. package/src/components/typography-text.tsx +250 -0
  280. package/src/components/typography.tsx +13 -0
  281. package/src/hooks/use-delayed-pending.ts +60 -0
  282. package/src/index.ts +11 -1
  283. package/src/lib/block-illustration.tsx +88 -0
  284. package/src/lib/empty-canvas.tsx +128 -0
  285. package/src/lib/empty-chip.ts +24 -0
  286. package/src/lib/optical-center.tsx +45 -0
  287. package/src/lib/utils.ts +26 -0
  288. package/dist/blocks/progress-screen.cjs +0 -1
  289. package/dist/blocks/progress-screen.d.ts.map +0 -1
@@ -0,0 +1,412 @@
1
+ import * as React from "react";
2
+
3
+ import { cn } from "@brightlocal/ui-components/lib/utils";
4
+ import {
5
+ TypographyHeading,
6
+ type TypographyHeadingLevel,
7
+ } from "../components/typography-heading";
8
+ import { TypographyText } from "../components/typography-text";
9
+ import {
10
+ BLOCK_ILLUSTRATION_SIZE,
11
+ BlockIllustration,
12
+ } from "../lib/block-illustration";
13
+ import { emptyChipStyles } from "../lib/empty-chip";
14
+
15
+ /* -------------------------------------------------------------------------------------------------
16
+ * EmptyState
17
+ *
18
+ * The empty block (Patterns/Empty States) — the shape every "nothing here"
19
+ * moment takes. Four parts in reading order: a visual, a real heading, one
20
+ * supporting line, and the actions row.
21
+ *
22
+ * One component, one size axis. `size` sets visual prominence — the title's
23
+ * role, the kind of visual, the rhythm — and nothing else. The block is pure
24
+ * content: it owns no page layout, so WHERE it sits is always the consumer's
25
+ * composition (`Grid variant="centered"` for a page body, a card or table frame
26
+ * for a section):
27
+ *
28
+ * md (default) — for the box a working page gives it: a card, a panel, a
29
+ * zero-row table. An icon in a muted chip, and a 16/24 title.
30
+ * lg — for the moment the whole page has nothing to show: a full
31
+ * illustration at 130 and a 20/28 title. Sits at the page
32
+ * body's optical centre via `<Grid variant="centered">`.
33
+ *
34
+ * (`sm` is reserved: a compact row-level tier is not designed yet, and until
35
+ * it is, the smallest empty vocabulary is the canvas primitives below.)
36
+ *
37
+ * The sizes are not interchangeable and the types say so: `illustration`
38
+ * exists only at lg, `align` only at md. A 130px drawing inside a card
39
+ * outweighs the page around it, and a left-aligned page message is not a
40
+ * thing — so neither combination compiles.
41
+ *
42
+ * Two things are deliberately NOT props:
43
+ * - The CTA order. `children` renders in source order, and the rule is that
44
+ * the primary action is last, so it lands rightmost. A prop per action slot
45
+ * would let a call site put the CTA first and still look correct.
46
+ * - The heading level's default only. `titleLevel` is the consumer's to set,
47
+ * because only the page knows where this block sits in its outline.
48
+ *
49
+ * A canvas — an empty chart, map or image slot — is NOT this component. It
50
+ * carries no title, no actions and no chip: those are `ChartEmpty`, `MapEmpty`
51
+ * and `MediaEmpty`, and they are primitives rather than blocks.
52
+ * -----------------------------------------------------------------------------------------------*/
53
+
54
+ /**
55
+ * Visual prominence of the block. It sets the title's role, the kind of
56
+ * visual, and the rhythm — never the layout, which stays the consumer's.
57
+ */
58
+ type EmptyStateSize = "md" | "lg";
59
+
60
+ /**
61
+ * Where an md block's content sits relative to its visual.
62
+ * - `center` — the column centres under the chip. For a standalone area the
63
+ * block fills: a zero-row table, a chart well, a panel.
64
+ * - `left` — the chip sits beside a left-aligned column, so the text joins the
65
+ * reading flow of the card it lives in rather than interrupting it.
66
+ *
67
+ * lg has no alignment: a page message is centred, full stop.
68
+ */
69
+ type EmptyStateAlign = "center" | "left";
70
+
71
+ /** The title's type role per size — Inter 16/24, or Inter 20/28. One step
72
+ * under the heading of the page or card the block sits inside, so the empty
73
+ * message never competes with it (DS-997). */
74
+ const SIZE_HEADING_VARIANT = {
75
+ md: "subsection",
76
+ lg: "section",
77
+ } as const;
78
+
79
+ /** The outline level each size defaults to, if the consumer names none. */
80
+ const SIZE_TITLE_LEVEL: Record<EmptyStateSize, TypographyHeadingLevel> = {
81
+ // An lg block is the page's message, under the layout's own page header,
82
+ // which owns h1.
83
+ lg: 2,
84
+ md: 3,
85
+ };
86
+
87
+ /**
88
+ * The parts every empty state has, at either size.
89
+ */
90
+ interface EmptyStateBaseProps extends Omit<
91
+ React.ComponentPropsWithoutRef<"div">,
92
+ "title"
93
+ > {
94
+ /**
95
+ * Required data-hook attribute for automated testing. The parts derive
96
+ * theirs from it: `-icon`, `-title`, `-message`.
97
+ * @example "locations-empty"
98
+ */
99
+ dataHook: string;
100
+ /**
101
+ * What is missing, as a real heading. Name the thing, not the condition:
102
+ * "No locations yet", never "Empty".
103
+ */
104
+ title: React.ReactNode;
105
+ /**
106
+ * One line under the title: what would put something here, or why there is
107
+ * nothing. May carry an inline link that reads as part of the sentence.
108
+ */
109
+ description?: React.ReactNode;
110
+ /**
111
+ * The actions row. Source order is the rendered order and the primary action
112
+ * goes last, so the CTA lands rightmost; a quiet
113
+ * `<Link variant="ghost" external>` comes before it. Never a second bordered
114
+ * button — two buttons of equal weight ask the reader to choose twice.
115
+ *
116
+ * Omit it entirely on a gated screen: the reader cannot act, and a button
117
+ * they are not allowed to press is worse than no button.
118
+ */
119
+ children?: React.ReactNode;
120
+ /**
121
+ * Document outline level for the title. Pick it as if CSS did not exist —
122
+ * the text's size comes from `size`, never from this.
123
+ * @default 3 at size md, 2 at size lg
124
+ */
125
+ titleLevel?: TypographyHeadingLevel;
126
+ /**
127
+ * Tracking element identifier for analytics.
128
+ */
129
+ trackingEl?: string;
130
+ /**
131
+ * Tracking label for analytics context.
132
+ */
133
+ trackingLabel?: string;
134
+ }
135
+
136
+ /**
137
+ * The block at md: filling one region of a working page.
138
+ */
139
+ interface EmptyStateMdProps extends EmptyStateBaseProps {
140
+ /**
141
+ * @default "md"
142
+ */
143
+ size?: "md";
144
+ /**
145
+ * Content alignment relative to the chip.
146
+ * @default "center"
147
+ */
148
+ align?: EmptyStateAlign;
149
+ /**
150
+ * The glyph in the muted chip, at its default 16px. Decorative: the wrapper
151
+ * is `aria-hidden`, so pass the glyph and nothing else.
152
+ * @example <MapPin />
153
+ */
154
+ icon?: React.ReactNode;
155
+ /**
156
+ * Not available at md — a 130px drawing inside a card outweighs the page
157
+ * around it. Use `size="lg"`, or pass an `icon`.
158
+ */
159
+ illustration?: never;
160
+ }
161
+
162
+ /**
163
+ * The block at lg: the whole page has nothing to show.
164
+ */
165
+ interface EmptyStateLgProps extends EmptyStateBaseProps {
166
+ size: "lg";
167
+ /**
168
+ * The screen's illustration. Decorative — mark it `aria-hidden`; the title
169
+ * and description carry the state on their own.
170
+ *
171
+ * Pass the illustration itself and do NOT set a size: the block renders it at
172
+ * the size the design specifies, whatever the element carries, so there is no
173
+ * number to get wrong per call site.
174
+ * @example <BusinessLocation aria-hidden />
175
+ */
176
+ illustration?: React.ReactNode;
177
+ /**
178
+ * A glyph in the muted chip, for a page with no illustration of its own.
179
+ * Ignored when `illustration` is set — a screen gets one visual, not two.
180
+ */
181
+ icon?: React.ReactNode;
182
+ /**
183
+ * Not available at lg: a page message is centred, full stop.
184
+ */
185
+ align?: never;
186
+ }
187
+
188
+ /**
189
+ * Props for the EmptyState block. `size` discriminates the two shapes.
190
+ */
191
+ export type EmptyStateProps = EmptyStateMdProps | EmptyStateLgProps;
192
+
193
+ /**
194
+ * The empty block: a visual, a title, one supporting line, and up to two
195
+ * actions. Pure content — compose the position around it: `size="lg"` inside
196
+ * `<Grid variant="centered">` for an empty page, `size="md"` inside the card, panel or
197
+ * table frame it speaks for.
198
+ *
199
+ * @example
200
+ * ```tsx
201
+ * // A zero-row collection, inside the table's own frame.
202
+ * <EmptyState
203
+ * dataHook="locations-empty"
204
+ * description="Add a location to start tracking visibility."
205
+ * icon={<MapPin />}
206
+ * title={t("locations.empty.title")}
207
+ * >
208
+ * <Button dataHook="locations-add" variant="secondary">
209
+ * <Plus aria-hidden="true" />
210
+ * Add location
211
+ * </Button>
212
+ * </EmptyState>
213
+ *
214
+ * // In a card's reading flow, with a quiet secondary action before the CTA.
215
+ * <EmptyState
216
+ * align="left"
217
+ * dataHook="reviews-empty"
218
+ * description={t("reviews.empty.description")}
219
+ * icon={<MessageSquareText />}
220
+ * title="No reviews yet"
221
+ * >
222
+ * <Link dataHook="reviews-docs" external href="/help/reviews" variant="ghost">
223
+ * How review sync works
224
+ * </Link>
225
+ * <Button dataHook="reviews-connect" variant="secondary">Connect profile</Button>
226
+ * </EmptyState>
227
+ *
228
+ * // The whole page is empty: lg, held at the page body's optical centre.
229
+ * <Grid dataHook="locations-empty-center" variant="centered">
230
+ * <EmptyState
231
+ * dataHook="locations-empty-page"
232
+ * description={t("locations.empty.description")}
233
+ * illustration={<BusinessLocation aria-hidden />}
234
+ * size="lg"
235
+ * title={t("locations.empty.title")}
236
+ * >
237
+ * <Button dataHook="locations-add">
238
+ * <Plus aria-hidden="true" />
239
+ * Add location
240
+ * </Button>
241
+ * </EmptyState>
242
+ * </Grid>
243
+ * ```
244
+ */
245
+ const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(
246
+ (props, ref) => {
247
+ const {
248
+ className,
249
+ dataHook,
250
+ title,
251
+ description,
252
+ children,
253
+ titleLevel,
254
+ trackingEl,
255
+ trackingLabel,
256
+ size = "md",
257
+ ...rest
258
+ } = props;
259
+ /* Read the two size-exclusive props off the union by hand: destructuring
260
+ them above would make TypeScript resolve them against both members. */
261
+ const icon = (props as EmptyStateMdProps).icon;
262
+ const illustration = (props as EmptyStateLgProps).illustration;
263
+ const align: EmptyStateAlign =
264
+ size === "lg"
265
+ ? "center"
266
+ : ((props as EmptyStateMdProps).align ?? "center");
267
+ const domProps = rest as React.ComponentPropsWithoutRef<"div">;
268
+ delete (domProps as { icon?: unknown }).icon;
269
+ delete (domProps as { illustration?: unknown }).illustration;
270
+ delete (domProps as { align?: unknown }).align;
271
+
272
+ /* `children ? …` is not enough to decide whether there is an actions row.
273
+ Call sites write `{canAdd && <Button/>}`, and two conditionals make
274
+ `children` the array `[false, false]` — truthy, so the row would render
275
+ empty and leave a stray 8px above nothing. `Children.toArray` drops
276
+ null, undefined and booleans, which is exactly the question being asked.
277
+
278
+ It does NOT look inside a fragment, though, and a call site that wraps
279
+ its conditionals in one (`<>{a}{b}</>`) would count as a single child
280
+ however empty it is. So unwrap one level before counting. */
281
+ const hasActions =
282
+ React.Children.toArray(children).flatMap((child) =>
283
+ React.isValidElement(child) && child.type === React.Fragment
284
+ ? React.Children.toArray(
285
+ (child.props as { children?: React.ReactNode }).children
286
+ )
287
+ : [child]
288
+ ).length > 0;
289
+
290
+ /* lg gets the illustration; md gets the chip. The chip is the fallback on
291
+ a page with no artwork of its own. */
292
+ const visual =
293
+ size === "lg" && illustration ? (
294
+ <BlockIllustration
295
+ size={BLOCK_ILLUSTRATION_SIZE}
296
+ slot="empty-state-illustration"
297
+ >
298
+ {illustration}
299
+ </BlockIllustration>
300
+ ) : icon ? (
301
+ <span
302
+ aria-hidden="true"
303
+ className={cn(
304
+ emptyChipStyles({ align }),
305
+ /* The chip's 4px of extra breathing room belongs to the title
306
+ under it — the lg column sets its own 16px rhythm instead. */
307
+ size === "md" && align === "center" && "mb-1"
308
+ )}
309
+ data-hook={`${dataHook}-icon`}
310
+ data-slot="empty-state-icon"
311
+ >
312
+ {icon}
313
+ </span>
314
+ ) : null;
315
+
316
+ /* One column for every size and alignment, so the parts and their spacing
317
+ are written once. */
318
+ const content = (
319
+ <div
320
+ className={cn(
321
+ "flex flex-col gap-2",
322
+ align === "center" && "w-full items-center"
323
+ )}
324
+ data-slot="empty-state-content"
325
+ >
326
+ <TypographyHeading
327
+ align={align === "center" ? "center" : "left"}
328
+ data-slot="empty-state-title"
329
+ dataHook={`${dataHook}-title`}
330
+ level={titleLevel ?? SIZE_TITLE_LEVEL[size]}
331
+ variant={SIZE_HEADING_VARIANT[size]}
332
+ >
333
+ {title}
334
+ </TypographyHeading>
335
+ {description ? (
336
+ /* Capped at 28rem: a single line of support reads as one thought
337
+ only while it stays a couple of lines long. */
338
+ <TypographyText
339
+ align={align === "center" ? "center" : "left"}
340
+ className="max-w-md"
341
+ color="muted"
342
+ data-slot="empty-state-description"
343
+ dataHook={`${dataHook}-message`}
344
+ variant="body-sm"
345
+ >
346
+ {description}
347
+ </TypographyText>
348
+ ) : null}
349
+ {hasActions ? (
350
+ <div
351
+ className={cn(
352
+ "mt-2 flex items-center gap-4",
353
+ align === "center" && "justify-center"
354
+ )}
355
+ data-slot="empty-state-actions"
356
+ >
357
+ {children}
358
+ </div>
359
+ ) : null}
360
+ </div>
361
+ );
362
+
363
+ if (size === "lg") {
364
+ return (
365
+ <div
366
+ ref={ref}
367
+ /* 24px between the illustration and the text — the artwork needs
368
+ more air than the chip does (spacing/6 in Figma). No page layout
369
+ here: the block is the message, and `Grid variant="centered"`
370
+ (or whatever box the consumer chooses) is the position. */
371
+ className={cn("flex w-full flex-col items-center gap-6", className)}
372
+ data-hook={dataHook}
373
+ data-size="lg"
374
+ data-slot="empty-state"
375
+ data-tracking-el={trackingEl ?? "empty-state"}
376
+ data-tracking-label={trackingLabel}
377
+ {...domProps}
378
+ >
379
+ {visual}
380
+ {content}
381
+ </div>
382
+ );
383
+ }
384
+
385
+ return (
386
+ <div
387
+ ref={ref}
388
+ className={cn(
389
+ align === "left"
390
+ ? "flex items-start gap-4 text-left"
391
+ : "flex flex-col items-center gap-2 text-center",
392
+ className
393
+ )}
394
+ data-hook={dataHook}
395
+ data-size="md"
396
+ data-slot="empty-state"
397
+ data-tracking-el={trackingEl ?? "empty-state"}
398
+ data-tracking-label={trackingLabel}
399
+ {...domProps}
400
+ >
401
+ {visual}
402
+ {content}
403
+ </div>
404
+ );
405
+ }
406
+ );
407
+
408
+ EmptyState.displayName = "EmptyState";
409
+
410
+ export { EmptyState };
411
+
412
+ export type { EmptyStateAlign, EmptyStateSize };
@@ -100,18 +100,66 @@ function InputList({
100
100
  const [inputValue, setInputValue] = React.useState("");
101
101
  const prevValueLengthRef = React.useRef(value.length);
102
102
 
103
- // Stable keys so AnimatePresence can track items across additions/removals
104
- const nextIdRef = React.useRef(value.length);
105
- const [stableKeys, setStableKeys] = React.useState<number[]>(() =>
106
- value.map((_, i) => i)
107
- );
108
-
109
- // Counter that triggers key sync even when the consumer rejects an add
110
- // (value stays the same but stableKeys grew eagerly).
111
- const [addAttempt, setAddAttempt] = React.useState(0);
103
+ // Stable keys so AnimatePresence can track items across additions/removals.
104
+ // Keys reconcile with `value` DURING render (React's "adjust state when props
105
+ // change" pattern), never one effect later: an effect-based sync renders one
106
+ // frame with keys out of step, and AnimatePresence then treats the re-keyed
107
+ // items as an exit+enter pair — a whole-value replacement from outside (a
108
+ // query response arriving) duplicated every previous item (DS-908). The
109
+ // counter lives in the same state so allocation is a pure function of state,
110
+ // safe for React to invoke twice.
111
+ const [keyState, setKeyState] = React.useState<{
112
+ keys: number[];
113
+ nextId: number;
114
+ // The index removeItem asked the consumer to drop. The key is only
115
+ // removed once `value` confirms the removal — a rejected removal
116
+ // (onValueChange left `value` unchanged) must leave every key in place,
117
+ // or the reconciliation below would append a fresh key and AnimatePresence
118
+ // would exit/re-enter items in an unchanged list.
119
+ pendingRemoval: number | null;
120
+ }>(() => ({
121
+ keys: value.map((_, i) => i),
122
+ nextId: value.length,
123
+ pendingRemoval: null,
124
+ }));
125
+
126
+ let stableKeys = keyState.keys;
127
+ if (stableKeys.length !== value.length) {
128
+ const next =
129
+ value.length > stableKeys.length
130
+ ? {
131
+ // Append: preserve existing keys, allocate new ones
132
+ keys: [
133
+ ...stableKeys,
134
+ ...Array.from(
135
+ { length: value.length - stableKeys.length },
136
+ (_, i) => keyState.nextId + i
137
+ ),
138
+ ],
139
+ nextId: keyState.nextId + (value.length - stableKeys.length),
140
+ pendingRemoval: null,
141
+ }
142
+ : {
143
+ // The prop confirmed a removal: drop the pending key so the
144
+ // remaining items keep theirs. Without a matching pending index
145
+ // (partial acceptance, external shrink) trim from the end.
146
+ keys:
147
+ keyState.pendingRemoval !== null &&
148
+ stableKeys.length - value.length === 1
149
+ ? stableKeys.filter((_, i) => i !== keyState.pendingRemoval)
150
+ : stableKeys.slice(0, value.length),
151
+ nextId: keyState.nextId,
152
+ pendingRemoval: null,
153
+ };
154
+ stableKeys = next.keys;
155
+ setKeyState(next);
156
+ } else if (keyState.pendingRemoval !== null) {
157
+ // Same length with a pending removal: the consumer rejected it — clear
158
+ // the marker, keys untouched.
159
+ setKeyState({ ...keyState, pendingRemoval: null });
160
+ }
112
161
 
113
- // Sync keys with value. Runs on value change OR rejected add (via addAttempt).
114
- // Clear input only when the consumer actually accepted the addition.
162
+ // Clear the input once the consumer accepts an addition (value grew).
115
163
  React.useEffect(() => {
116
164
  const prevLength = prevValueLengthRef.current;
117
165
  prevValueLengthRef.current = value.length;
@@ -119,44 +167,26 @@ function InputList({
119
167
  if (value.length > prevLength) {
120
168
  setInputValue("");
121
169
  }
122
-
123
- setStableKeys((prev) => {
124
- if (prev.length === value.length) return prev;
125
- if (value.length > prev.length) {
126
- // Append: preserve existing keys, generate new ones
127
- return [
128
- ...prev,
129
- ...Array.from(
130
- { length: value.length - prev.length },
131
- () => nextIdRef.current++
132
- ),
133
- ];
134
- }
135
- // Trim excess keys (rejected add, partial acceptance, or external shrink).
136
- // removeItem already eagerly filters keys, so removals hit the
137
- // prev.length === value.length check above and never reach here.
138
- return prev.slice(0, value.length);
139
- });
140
- }, [value, addAttempt]);
170
+ }, [value]);
141
171
 
142
172
  const addItems = React.useCallback(
143
173
  (items: string[]) => {
144
174
  const toAdd = items.map((s) => s.trim()).filter(Boolean);
145
175
  if (!toAdd.length) return;
146
176
 
147
- setStableKeys((prev) => [
148
- ...prev,
149
- ...toAdd.map(() => nextIdRef.current++),
150
- ]);
177
+ // Keys for the new entries are allocated by the render-time
178
+ // reconciliation once the consumer accepts the new value.
151
179
  onValueChange([...value, ...toAdd]);
152
- setAddAttempt((c) => c + 1);
153
180
  },
154
181
  [value, onValueChange]
155
182
  );
156
183
 
157
184
  const removeItem = React.useCallback(
158
185
  (index: number) => {
159
- setStableKeys((prev) => prev.filter((_, i) => i !== index));
186
+ // Record the index instead of filtering the key eagerly: the render-time
187
+ // reconciliation drops it only once the consumer's value confirms the
188
+ // removal, so a rejected removal leaves the keys (and the list) intact.
189
+ setKeyState((prev) => ({ ...prev, pendingRemoval: index }));
160
190
  onValueChange(value.filter((_, i) => i !== index));
161
191
  },
162
192
  [value, onValueChange]