@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
@@ -1419,7 +1419,14 @@ const sidebarMenuSubVariants = cva(
1419
1419
  variants: {
1420
1420
  variant: {
1421
1421
  default: "px-10",
1422
- border: "border-l border-sidebar-border ml-10 pl-1 pr-10",
1422
+ // Figma SidebarMenuSub / Type=Border (DS-1029): rule 24px in, items
1423
+ // 20px right of it, 8px right inset — labels keep ≥190px at the
1424
+ // 288px sidebar width. The rule is a pseudo-element so it stops at
1425
+ // the list's vertical padding (Figma draws it 4px short at both
1426
+ // ends); the transparent border keeps its 1px in the box so `pl-5`
1427
+ // still lands items 21px from the rule's left edge.
1428
+ border:
1429
+ "relative ml-6 border-l border-transparent pl-5 pr-2 before:absolute before:inset-y-1 before:-left-px before:w-px before:bg-sidebar-border",
1423
1430
  indent: "px-10",
1424
1431
  },
1425
1432
  },
@@ -1524,7 +1531,7 @@ const SidebarMenuSubButton = React.forwardRef<
1524
1531
  <Comp
1525
1532
  ref={ref}
1526
1533
  className={cn(
1527
- "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-foreground text-label duration-fast flex h-7 min-w-0 items-center gap-2 overflow-hidden rounded-md px-2 transition-[color,background-color,box-shadow,opacity] ease-out outline-none disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:not([data-slot])]:truncate [&>svg]:shrink-0",
1534
+ "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-foreground text-label duration-fast flex h-8 min-w-0 items-center gap-2 overflow-hidden rounded-md px-3 transition-[color,background-color,box-shadow,opacity] ease-out outline-none disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:not([data-slot])]:truncate [&>svg]:shrink-0",
1528
1535
  SIDEBAR_FOCUS_RING,
1529
1536
  "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
1530
1537
  size === SidebarMenuSubButtonSize.SM && "text-label-sm",
@@ -1638,6 +1645,23 @@ SidebarMenuCollapsibleTrigger.displayName = "SidebarMenuCollapsibleTrigger";
1638
1645
  */
1639
1646
  type SidebarMenuCollapsibleContentProps = SidebarMenuSubProps;
1640
1647
 
1648
+ /**
1649
+ * Expandable body of a `SidebarMenuCollapsible`. It **is** the sub-menu list:
1650
+ * it renders a `SidebarMenuSub` (so it takes `variant` and the other
1651
+ * `SidebarMenuSub` props), so place `SidebarMenuSubItem`s directly inside it.
1652
+ * Do not nest another `SidebarMenuSub` in here — the two indents stack and
1653
+ * leave ~100px for labels at the default sidebar width (DS-1029).
1654
+ *
1655
+ * @example
1656
+ * <SidebarMenuCollapsible>
1657
+ * <SidebarMenuCollapsibleTrigger>Reviews</SidebarMenuCollapsibleTrigger>
1658
+ * <SidebarMenuCollapsibleContent>
1659
+ * <SidebarMenuSubItem>
1660
+ * <SidebarMenuSubButton>Review Tracker</SidebarMenuSubButton>
1661
+ * </SidebarMenuSubItem>
1662
+ * </SidebarMenuCollapsibleContent>
1663
+ * </SidebarMenuCollapsible>
1664
+ */
1641
1665
  const SidebarMenuCollapsibleContent = React.forwardRef<
1642
1666
  HTMLUListElement,
1643
1667
  SidebarMenuCollapsibleContentProps
@@ -6,6 +6,7 @@ import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
6
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
7
  import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
8
8
  import { ButtonVariants } from "@brightlocal/ui-components/button";
9
+ import type { ButtonVariant } from "@brightlocal/ui-components/button";
9
10
 
10
11
  interface AlertDialogProps extends React.ComponentProps<
11
12
  typeof AlertDialogPrimitive.Root
@@ -193,27 +194,68 @@ const AlertDialogDescription = React.forwardRef<
193
194
 
194
195
  AlertDialogDescription.displayName = "AlertDialogDescription";
195
196
 
197
+ /** Visual style variants for the AlertDialogAction confirm button. */
198
+ type AlertDialogActionVariant = Extract<
199
+ ButtonVariant,
200
+ "primary" | "destructive"
201
+ >;
202
+
203
+ /**
204
+ * Props for the AlertDialogAction component
205
+ */
206
+ interface AlertDialogActionProps extends React.ComponentProps<
207
+ typeof AlertDialogPrimitive.Action
208
+ > {
209
+ /**
210
+ * Visual style of the confirm button. Use `"destructive"` when confirming
211
+ * an irreversible action such as a delete.
212
+ * @default "primary"
213
+ */
214
+ variant?: AlertDialogActionVariant;
215
+ /**
216
+ * Data hook for automated testing
217
+ * @example "delete-location-confirm"
218
+ */
219
+ dataHook?: string;
220
+ }
221
+
196
222
  const AlertDialogAction = React.forwardRef<
197
223
  React.ComponentRef<typeof AlertDialogPrimitive.Action>,
198
- React.ComponentProps<typeof AlertDialogPrimitive.Action>
199
- >(({ className, ...props }, ref) => (
224
+ AlertDialogActionProps
225
+ >(({ className, variant = "primary", dataHook, ...props }, ref) => (
200
226
  <AlertDialogPrimitive.Action
201
227
  ref={ref}
202
- className={cn(ButtonVariants(), className)}
228
+ className={cn(ButtonVariants({ variant }), className)}
229
+ data-hook={dataHook}
203
230
  data-slot="alert-dialog-action"
231
+ data-variant={variant}
204
232
  {...props}
205
233
  />
206
234
  ));
207
235
 
208
236
  AlertDialogAction.displayName = "AlertDialogAction";
209
237
 
238
+ /**
239
+ * Props for the AlertDialogCancel component
240
+ */
241
+ interface AlertDialogCancelProps extends React.ComponentProps<
242
+ typeof AlertDialogPrimitive.Cancel
243
+ > {
244
+ /**
245
+ * Data hook for automated testing
246
+ * @example "delete-location-cancel"
247
+ */
248
+ dataHook?: string;
249
+ }
250
+
210
251
  const AlertDialogCancel = React.forwardRef<
211
252
  React.ComponentRef<typeof AlertDialogPrimitive.Cancel>,
212
- React.ComponentProps<typeof AlertDialogPrimitive.Cancel>
213
- >(({ className, ...props }, ref) => (
253
+ AlertDialogCancelProps
254
+ >(({ className, dataHook, ...props }, ref) => (
214
255
  <AlertDialogPrimitive.Cancel
215
256
  ref={ref}
216
257
  className={cn(ButtonVariants({ variant: "outline" }), className)}
258
+ data-hook={dataHook}
217
259
  data-slot="alert-dialog-cancel"
218
260
  {...props}
219
261
  />
@@ -236,6 +278,9 @@ export {
236
278
  };
237
279
 
238
280
  export type {
281
+ AlertDialogActionProps,
282
+ AlertDialogActionVariant,
283
+ AlertDialogCancelProps,
239
284
  AlertDialogDescriptionProps,
240
285
  AlertDialogProps,
241
286
  AlertDialogTitleProps,
@@ -126,6 +126,14 @@ type AlertContentProps = AlertContentBaseProps &
126
126
  }
127
127
  );
128
128
 
129
+ // DS-1031: below `md` the action drops under the text, left-aligned with
130
+ // it (pl-7 = 16px icon + 12px gap), so the copy keeps the full width on
131
+ // phones. From `md` up the action sits beside the text, vertically centered.
132
+ const ALERT_CONTENT_LAYOUT =
133
+ "max-md:flex-col max-md:items-stretch items-center";
134
+ const ALERT_ACTION_LAYOUT =
135
+ "shrink-0 self-center max-md:self-start max-md:pl-7";
136
+
129
137
  function AlertSuccess({
130
138
  title,
131
139
  description,
@@ -137,7 +145,7 @@ function AlertSuccess({
137
145
  }: AlertContentProps) {
138
146
  return (
139
147
  <Alert
140
- className={cn("items-center", className)}
148
+ className={cn(ALERT_CONTENT_LAYOUT, className)}
141
149
  data-hook={dataHook}
142
150
  data-tracking-el={trackingEl}
143
151
  data-tracking-label={trackingLabel}
@@ -152,7 +160,7 @@ function AlertSuccess({
152
160
  )}
153
161
  </div>
154
162
  </div>
155
- {action && <div className="shrink-0 self-center">{action}</div>}
163
+ {action && <div className={ALERT_ACTION_LAYOUT}>{action}</div>}
156
164
  </Alert>
157
165
  );
158
166
  }
@@ -168,7 +176,7 @@ function AlertInfo({
168
176
  }: AlertContentProps) {
169
177
  return (
170
178
  <Alert
171
- className={cn("items-center", className)}
179
+ className={cn(ALERT_CONTENT_LAYOUT, className)}
172
180
  data-hook={dataHook}
173
181
  data-tracking-el={trackingEl}
174
182
  data-tracking-label={trackingLabel}
@@ -183,7 +191,7 @@ function AlertInfo({
183
191
  )}
184
192
  </div>
185
193
  </div>
186
- {action && <div className="shrink-0 self-center">{action}</div>}
194
+ {action && <div className={ALERT_ACTION_LAYOUT}>{action}</div>}
187
195
  </Alert>
188
196
  );
189
197
  }
@@ -199,7 +207,7 @@ function AlertDestructive({
199
207
  }: AlertContentProps) {
200
208
  return (
201
209
  <Alert
202
- className={cn("items-center", className)}
210
+ className={cn(ALERT_CONTENT_LAYOUT, className)}
203
211
  data-hook={dataHook}
204
212
  data-tracking-el={trackingEl}
205
213
  data-tracking-label={trackingLabel}
@@ -214,7 +222,7 @@ function AlertDestructive({
214
222
  )}
215
223
  </div>
216
224
  </div>
217
- {action && <div className="shrink-0 self-center">{action}</div>}
225
+ {action && <div className={ALERT_ACTION_LAYOUT}>{action}</div>}
218
226
  </Alert>
219
227
  );
220
228
  }
@@ -230,7 +238,7 @@ function AlertWarning({
230
238
  }: AlertContentProps) {
231
239
  return (
232
240
  <Alert
233
- className={cn("items-center", className)}
241
+ className={cn(ALERT_CONTENT_LAYOUT, className)}
234
242
  data-hook={dataHook}
235
243
  data-tracking-el={trackingEl}
236
244
  data-tracking-label={trackingLabel}
@@ -245,7 +253,7 @@ function AlertWarning({
245
253
  )}
246
254
  </div>
247
255
  </div>
248
- {action && <div className="shrink-0 self-center">{action}</div>}
256
+ {action && <div className={ALERT_ACTION_LAYOUT}>{action}</div>}
249
257
  </Alert>
250
258
  );
251
259
  }
@@ -3,6 +3,7 @@ import { Slot } from "@radix-ui/react-slot";
3
3
  import { cva, type VariantProps } from "class-variance-authority";
4
4
 
5
5
  import { cn } from "@brightlocal/ui-components/lib/utils";
6
+ import { useDevWarning } from "@brightlocal/ui-components/lib/use-dev-warning";
6
7
 
7
8
  const badgeVariants = cva(
8
9
  [
@@ -16,8 +17,11 @@ const badgeVariants = cva(
16
17
  // Typography — type-scale role for badges (12/16 Figma 500; the weight
17
18
  // drop from the old semibold is intentional, DS-925)
18
19
  "text-label-sm whitespace-nowrap",
19
- // Icons
20
+ // Icons — direct children, plus the one `srLabel` wrapper (display:
21
+ // contents) so an icon inside it keeps its size without resizing any
22
+ // other nested SVG
20
23
  "[&>svg]:size-3 [&>svg]:pointer-events-none",
24
+ "[&>.contents>svg]:size-3 [&>.contents>svg]:pointer-events-none",
21
25
  // Transition
22
26
  "transition-[color,background-color,border-color,box-shadow] duration-fast ease-out",
23
27
  // Focus
@@ -67,6 +71,15 @@ interface BadgeProps
67
71
  * Tracking label for analytics context
68
72
  */
69
73
  trackingLabel?: string;
74
+ /**
75
+ * Screen-reader phrase that replaces the visible content. A bare numeral
76
+ * tells a screen-reader user nothing about what it counts, so a count
77
+ * badge passes the phrase here ("3 active", "2 selected") and the numeral
78
+ * stays visual only. Ignored with `asChild` — the Slot's single child is
79
+ * the consumer's element, so put the phrase inside it instead.
80
+ * @example srLabel="3 active"
81
+ */
82
+ srLabel?: string;
70
83
  }
71
84
 
72
85
  /**
@@ -82,12 +95,21 @@ const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
82
95
  dataHook,
83
96
  trackingEl,
84
97
  trackingLabel,
98
+ srLabel,
85
99
  children,
86
100
  ...props
87
101
  },
88
102
  ref
89
103
  ) => {
90
104
  const Comp = asChild ? Slot : "span";
105
+ const srLabelApplies = srLabel !== undefined && !asChild;
106
+
107
+ useDevWarning(
108
+ () => asChild && srLabel !== undefined,
109
+ "srLabel is set on a <Badge asChild>. Slot renders the child element as-is, " +
110
+ "so the phrase cannot be injected — add an sr-only span inside the child instead.",
111
+ [asChild, srLabel]
112
+ );
91
113
 
92
114
  // Check if children is a single digit number (0-9)
93
115
  const isNumberBadge =
@@ -96,7 +118,13 @@ const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
96
118
  return (
97
119
  <Comp
98
120
  ref={ref}
99
- className={cn(badgeVariants({ variant }), className)}
121
+ className={cn(
122
+ badgeVariants({ variant }),
123
+ /* sr-only is absolutely positioned: the badge is its positioning
124
+ context so the phrase never escapes a scroll viewport. */
125
+ srLabelApplies && "relative",
126
+ className
127
+ )}
100
128
  data-hook={dataHook}
101
129
  data-number={isNumberBadge}
102
130
  data-slot="badge"
@@ -104,7 +132,16 @@ const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
104
132
  data-tracking-label={trackingLabel}
105
133
  {...props}
106
134
  >
107
- {children}
135
+ {srLabelApplies ? (
136
+ <>
137
+ <span aria-hidden="true" className="contents">
138
+ {children}
139
+ </span>
140
+ <span className="sr-only">{srLabel}</span>
141
+ </>
142
+ ) : (
143
+ children
144
+ )}
108
145
  </Comp>
109
146
  );
110
147
  }
@@ -0,0 +1,288 @@
1
+ import * as React from "react";
2
+ import { cva } from "class-variance-authority";
3
+ import { X } from "@brightlocal/icons";
4
+
5
+ import { Button } from "@brightlocal/ui-components/button";
6
+ import { cn } from "@brightlocal/ui-components/lib/utils";
7
+
8
+ /** Highlight surface the banner sits on — one per `highlight-*` token role */
9
+ type BannerVariant = "sky" | "violet";
10
+
11
+ /** Document outline level for the banner title */
12
+ type BannerTitleLevel = 1 | 2 | 3 | 4 | 5 | 6;
13
+
14
+ // Compact on purpose: a banner is a note, not a hero. Below `md` the parts
15
+ // stack (illustration, content, actions); from `md` they sit in one row with
16
+ // the actions vertically centred on the right.
17
+ const bannerVariants = cva(
18
+ "relative flex w-full flex-col gap-3 rounded-xl p-4 md:flex-row md:items-center md:gap-5 md:pl-5",
19
+ {
20
+ variants: {
21
+ variant: {
22
+ sky: "bg-highlight-sky text-highlight-sky-foreground",
23
+ violet: "bg-highlight-violet text-highlight-violet-foreground",
24
+ },
25
+ dismissible: {
26
+ // Keep the content clear of the absolutely positioned close button.
27
+ true: "pr-12 md:pr-14",
28
+ false: "",
29
+ },
30
+ },
31
+ defaultVariants: {
32
+ variant: "sky",
33
+ dismissible: false,
34
+ },
35
+ }
36
+ );
37
+
38
+ const descriptionColorMap: Record<BannerVariant, string> = {
39
+ sky: "text-highlight-sky-muted-foreground",
40
+ violet: "text-highlight-violet-muted-foreground",
41
+ };
42
+
43
+ const dismissColorMap: Record<BannerVariant, string> = {
44
+ sky: "text-highlight-sky-foreground hover:bg-highlight-sky-foreground/10",
45
+ violet:
46
+ "text-highlight-violet-foreground hover:bg-highlight-violet-foreground/10",
47
+ };
48
+
49
+ // The parts read the surface from the root, so colours and the region's
50
+ // accessible name stay the component's job whatever the composition.
51
+ interface BannerContextValue {
52
+ variant: BannerVariant;
53
+ titleId: string;
54
+ registerTitle: () => () => void;
55
+ }
56
+
57
+ const BannerContext = React.createContext<BannerContextValue>({
58
+ variant: "sky",
59
+ titleId: "",
60
+ registerTitle: () => () => {},
61
+ });
62
+
63
+ /** Props for the Banner root */
64
+ interface BannerProps extends React.ComponentPropsWithoutRef<"section"> {
65
+ /** Required test hook identifier */
66
+ dataHook: string;
67
+ /**
68
+ * Highlight surface. Sky is the default; violet is the alternative when
69
+ * two banners must read as different invitations.
70
+ * @default "sky"
71
+ */
72
+ variant?: BannerVariant;
73
+ /**
74
+ * Called when the close button is pressed. The close button renders only
75
+ * when this is set; the consumer decides where the dismissal is remembered.
76
+ */
77
+ onDismiss?: () => void;
78
+ /**
79
+ * Accessible label for the close button.
80
+ * @default "Dismiss"
81
+ */
82
+ dismissLabel?: string;
83
+ /** Analytics element identifier */
84
+ trackingEl?: string;
85
+ /** Analytics label */
86
+ trackingLabel?: string;
87
+ }
88
+
89
+ /**
90
+ * Branded, dismissible banner that invites the user to do something optional
91
+ * — an invitation, not a fault. Use an Alert when something happened.
92
+ *
93
+ * Compose it from `BannerIllustration`, `BannerContent` (with `BannerTitle`
94
+ * and `BannerDescription`) and `BannerActions`. The root owns the surface,
95
+ * the layout and the close button.
96
+ */
97
+ const Banner = React.forwardRef<HTMLElement, BannerProps>(
98
+ (
99
+ {
100
+ className,
101
+ variant = "sky",
102
+ onDismiss,
103
+ dismissLabel,
104
+ dataHook,
105
+ trackingEl,
106
+ trackingLabel,
107
+ children,
108
+ ...props
109
+ },
110
+ ref
111
+ ) => {
112
+ const titleId = React.useId();
113
+ // Only point aria-labelledby at a title that is actually rendered.
114
+ const [titleCount, setTitleCount] = React.useState(0);
115
+ const registerTitle = React.useCallback(() => {
116
+ setTitleCount((count) => count + 1);
117
+ return () => setTitleCount((count) => count - 1);
118
+ }, []);
119
+ const context = React.useMemo(
120
+ () => ({ variant, titleId, registerTitle }),
121
+ [variant, titleId, registerTitle]
122
+ );
123
+ const dismissible = onDismiss != null;
124
+
125
+ return (
126
+ <BannerContext.Provider value={context}>
127
+ <section
128
+ ref={ref}
129
+ aria-labelledby={titleCount > 0 ? titleId : undefined}
130
+ className={cn(bannerVariants({ variant, dismissible }), className)}
131
+ data-hook={dataHook}
132
+ data-slot="banner"
133
+ data-tracking-el={trackingEl || `banner-${variant}`}
134
+ data-tracking-label={trackingLabel}
135
+ {...props}
136
+ >
137
+ {children}
138
+ {dismissible && (
139
+ <Button
140
+ iconOnly
141
+ className={cn("absolute top-2 right-2", dismissColorMap[variant])}
142
+ dataHook={`${dataHook}-dismiss`}
143
+ variant="ghost"
144
+ onClick={onDismiss}
145
+ >
146
+ <X />
147
+ <span className="sr-only">{dismissLabel ?? "Dismiss"}</span>
148
+ </Button>
149
+ )}
150
+ </section>
151
+ </BannerContext.Provider>
152
+ );
153
+ }
154
+ );
155
+ Banner.displayName = "Banner";
156
+
157
+ /** Shared props for the Banner parts */
158
+ interface BannerPartProps extends React.HTMLAttributes<HTMLDivElement> {
159
+ /** Test hook identifier */
160
+ dataHook?: string;
161
+ }
162
+
163
+ /**
164
+ * Decorative illustration from `@brightlocal/illustrations`, sized by the
165
+ * banner (56px, 64px from `md`). Hidden from assistive technologies. Leave
166
+ * the illustration's `variant` unset so it follows light/dark mode.
167
+ */
168
+ const BannerIllustration = React.forwardRef<HTMLDivElement, BannerPartProps>(
169
+ ({ className, dataHook, ...props }, ref) => (
170
+ <div
171
+ ref={ref}
172
+ aria-hidden="true"
173
+ className={cn(
174
+ "flex size-14 shrink-0 md:size-16 [&>svg]:size-full",
175
+ className
176
+ )}
177
+ data-hook={dataHook}
178
+ data-slot="banner-illustration"
179
+ {...props}
180
+ />
181
+ )
182
+ );
183
+ BannerIllustration.displayName = "BannerIllustration";
184
+
185
+ /**
186
+ * The text column — takes the remaining width. Holds `BannerTitle` and
187
+ * `BannerDescription`, plus anything else the composition needs.
188
+ */
189
+ const BannerContent = React.forwardRef<HTMLDivElement, BannerPartProps>(
190
+ ({ className, dataHook, ...props }, ref) => (
191
+ <div
192
+ ref={ref}
193
+ className={cn("flex min-w-0 flex-1 flex-col gap-1", className)}
194
+ data-hook={dataHook}
195
+ data-slot="banner-content"
196
+ {...props}
197
+ />
198
+ )
199
+ );
200
+ BannerContent.displayName = "BannerContent";
201
+
202
+ /** Props for BannerTitle */
203
+ interface BannerTitleProps extends Omit<BannerPartProps, "id"> {
204
+ /**
205
+ * Document outline level — renders the title as the corresponding heading
206
+ * element (`h1`–`h6`). With no `level` the title renders a `div`; it still
207
+ * names the banner region either way.
208
+ * @example <BannerTitle level={2}>Connect Facebook</BannerTitle>
209
+ */
210
+ level?: BannerTitleLevel;
211
+ }
212
+
213
+ /** Heading — what the user is being invited to do. Names the banner region. */
214
+ const BannerTitle = React.forwardRef<HTMLHeadingElement, BannerTitleProps>(
215
+ ({ className, level, dataHook, ...props }, ref) => {
216
+ const { titleId, registerTitle } = React.useContext(BannerContext);
217
+ React.useLayoutEffect(() => registerTitle(), [registerTitle]);
218
+ const Title = level ? (`h${level}` as const) : "div";
219
+
220
+ return (
221
+ <Title
222
+ ref={ref}
223
+ className={cn("text-heading-subsection break-words", className)}
224
+ data-hook={dataHook}
225
+ data-slot="banner-title"
226
+ id={titleId}
227
+ {...props}
228
+ />
229
+ );
230
+ }
231
+ );
232
+ BannerTitle.displayName = "BannerTitle";
233
+
234
+ /** One or two lines of supporting copy, in the surface's muted text role */
235
+ const BannerDescription = React.forwardRef<HTMLDivElement, BannerPartProps>(
236
+ ({ className, dataHook, ...props }, ref) => {
237
+ const { variant } = React.useContext(BannerContext);
238
+
239
+ return (
240
+ <div
241
+ ref={ref}
242
+ className={cn(
243
+ "text-body-sm break-words",
244
+ descriptionColorMap[variant],
245
+ className
246
+ )}
247
+ data-hook={dataHook}
248
+ data-slot="banner-description"
249
+ {...props}
250
+ />
251
+ );
252
+ }
253
+ );
254
+ BannerDescription.displayName = "BannerDescription";
255
+
256
+ /**
257
+ * The action(s) — usually one outline `sm` Button. Sits on the right from
258
+ * `md`, under the text on phones.
259
+ */
260
+ const BannerActions = React.forwardRef<HTMLDivElement, BannerPartProps>(
261
+ ({ className, dataHook, ...props }, ref) => (
262
+ <div
263
+ ref={ref}
264
+ className={cn("flex shrink-0 flex-wrap items-center gap-2", className)}
265
+ data-hook={dataHook}
266
+ data-slot="banner-actions"
267
+ {...props}
268
+ />
269
+ )
270
+ );
271
+ BannerActions.displayName = "BannerActions";
272
+
273
+ export {
274
+ Banner,
275
+ BannerIllustration,
276
+ BannerContent,
277
+ BannerTitle,
278
+ BannerDescription,
279
+ BannerActions,
280
+ bannerVariants,
281
+ };
282
+ export type {
283
+ BannerProps,
284
+ BannerPartProps,
285
+ BannerTitleProps,
286
+ BannerVariant,
287
+ BannerTitleLevel,
288
+ };
@@ -65,7 +65,7 @@ interface BrandIllustrationMotifProps
65
65
  size?: "sm" | "md" | "lg";
66
66
  /**
67
67
  * The illustration to render over the motif backdrop — typically a brand
68
- * illustration such as RobotAiA at 144px. Only rendered for the `lg`
68
+ * illustration such as Robot at 144px. Only rendered for the `lg`
69
69
  * size; `sm`/`md` show the motif mark alone.
70
70
  */
71
71
  children?: React.ReactNode;