@brightlocal/ui-components 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/component-meta.json +749 -53
- package/deprecations.json +114 -4
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +36 -0
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +74 -61
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +32 -3
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +61 -58
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +58 -57
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +9 -0
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +50 -30
- package/dist/banner.cjs +1 -0
- package/dist/banner.d.ts +81 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +176 -0
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +4 -3
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +50 -57
- package/dist/blocks/progress-state.d.ts +2 -2
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +17 -0
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +8 -2
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/button-group.cjs +1 -0
- package/dist/button-group.d.ts +36 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +47 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +105 -7
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +198 -101
- package/dist/chart.cjs +3 -3
- package/dist/chart.d.ts +270 -24
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +497 -322
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +1 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +2 -1
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +38 -4
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +95 -81
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.js +2 -2
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +251 -225
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +201 -23
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +712 -568
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +13 -5
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +54 -53
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +8 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +79 -52
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +105 -13
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +146 -129
- package/dist/grid.d.ts +26 -3
- package/dist/grid.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +1 -0
- package/dist/hooks/use-mobile.cjs +1 -0
- package/dist/hooks/use-mobile.js +8 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +594 -553
- package/dist/info-tooltip.cjs +1 -0
- package/dist/info-tooltip.d.ts +39 -0
- package/dist/info-tooltip.d.ts.map +1 -0
- package/dist/info-tooltip.js +41 -0
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.js +1 -1
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +33 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +167 -54
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +9 -9
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +45 -15
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +31 -30
- package/dist/input.cjs +1 -1
- package/dist/input.js +10 -10
- package/dist/lib/block-illustration.cjs +1 -1
- package/dist/lib/block-illustration.d.ts +4 -1
- package/dist/lib/block-illustration.d.ts.map +1 -1
- package/dist/lib/block-illustration.js +12 -11
- package/dist/lib/empty-chip.cjs +1 -0
- package/dist/lib/empty-chip.d.ts +4 -0
- package/dist/lib/empty-chip.d.ts.map +1 -0
- package/dist/lib/empty-chip.js +13 -0
- package/dist/lib/utils.cjs +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -3
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/multi-select-filter.cjs +1 -0
- package/dist/multi-select-filter.d.ts +178 -0
- package/dist/multi-select-filter.d.ts.map +1 -0
- package/dist/multi-select-filter.js +463 -0
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +3 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +57 -57
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +123 -16
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +89 -75
- package/dist/rating.cjs +1 -1
- package/dist/rating.js +18 -18
- package/dist/relative-date.cjs +1 -0
- package/dist/relative-date.d.ts +65 -0
- package/dist/relative-date.d.ts.map +1 -0
- package/dist/relative-date.js +128 -0
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +15 -6
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +38 -36
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +24 -3
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +130 -110
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +78 -2
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +192 -85
- package/dist/single-select-filter.cjs +1 -0
- package/dist/single-select-filter.d.ts +81 -0
- package/dist/single-select-filter.d.ts.map +1 -0
- package/dist/single-select-filter.js +226 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +22 -22
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +1 -1
- package/dist/split-layout.js +13 -13
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +45 -4
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +90 -73
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +12 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +148 -126
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +1 -1
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts +38 -36
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +262 -73
- package/dist/typography-heading.cjs +1 -1
- package/dist/typography-heading.d.ts +13 -0
- package/dist/typography-heading.d.ts.map +1 -1
- package/dist/typography-heading.js +32 -21
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +15 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +35 -24
- package/dist/typography.d.ts +1 -1
- package/package.json +5 -6
- package/src/blocks/empty-state.tsx +17 -24
- package/src/blocks/progress-state.tsx +2 -2
- package/src/blocks/sidebar.tsx +26 -2
- package/src/components/accordion.tsx +82 -27
- package/src/components/alert-dialog.tsx +50 -5
- package/src/components/alert.tsx +16 -8
- package/src/components/badge.tsx +40 -3
- package/src/components/banner.tsx +288 -0
- package/src/components/brand-illustration-motif.tsx +1 -1
- package/src/components/button-group.tsx +112 -0
- package/src/components/button.tsx +1 -1
- package/src/components/card.tsx +249 -27
- package/src/components/chart.tsx +586 -53
- package/src/components/checkbox.tsx +1 -1
- package/src/components/chip.tsx +83 -10
- package/src/components/combobox.tsx +2 -2
- package/src/components/command.tsx +56 -4
- package/src/components/data-table.tsx +842 -199
- package/src/components/date-picker.tsx +18 -7
- package/src/components/field.tsx +81 -12
- package/src/components/global-layout.tsx +176 -38
- package/src/components/grid.tsx +34 -3
- package/src/components/info-tooltip.tsx +94 -0
- package/src/components/input-chip.tsx +1 -1
- package/src/components/input-group.tsx +246 -11
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input-password.tsx +56 -22
- package/src/components/input.tsx +1 -1
- package/src/components/list.tsx +1 -1
- package/src/components/multi-select-filter.tsx +912 -0
- package/src/components/pagination.tsx +10 -3
- package/src/components/progress.tsx +190 -31
- package/src/components/rating.tsx +1 -1
- package/src/components/relative-date.tsx +230 -0
- package/src/components/scroll-area.tsx +23 -10
- package/src/components/select.tsx +65 -11
- package/src/components/sheet.tsx +240 -4
- package/src/components/single-select-filter.tsx +443 -0
- package/src/components/sonner.tsx +16 -5
- package/src/components/split-layout.tsx +2 -2
- package/src/components/table.tsx +71 -11
- package/src/components/tabs.tsx +93 -46
- package/src/components/textarea.tsx +1 -1
- package/src/components/tooltip.tsx +440 -68
- package/src/components/typography-heading.tsx +24 -0
- package/src/components/typography-text.tsx +27 -3
- package/src/components/typography.tsx +1 -1
- package/src/hooks/use-breakpoint.ts +2 -1
- package/src/index.ts +6 -0
- package/src/lib/block-illustration.tsx +5 -1
- package/src/lib/empty-chip.ts +24 -0
- package/src/lib/utils.ts +1 -0
package/src/components/alert.tsx
CHANGED
|
@@ -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(
|
|
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=
|
|
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(
|
|
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=
|
|
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(
|
|
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=
|
|
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(
|
|
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=
|
|
256
|
+
{action && <div className={ALERT_ACTION_LAYOUT}>{action}</div>}
|
|
249
257
|
</Alert>
|
|
250
258
|
);
|
|
251
259
|
}
|
package/src/components/badge.tsx
CHANGED
|
@@ -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(
|
|
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
|
-
{
|
|
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
|
|
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;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
|
+
|
|
6
|
+
/* The group owns only the joining: it zeroes the radii on the shared edges,
|
|
7
|
+
collapses the doubled border between bordered neighbours, and raises the
|
|
8
|
+
focused/open child above its siblings so the focus shadow paints over the
|
|
9
|
+
joined edge. Children keep their own outer-edge shape — a Button end stays
|
|
10
|
+
a pill, a SelectTrigger end stays rounded-sm — because the child's variant,
|
|
11
|
+
not the group, owns its identity.
|
|
12
|
+
|
|
13
|
+
A joined SelectTrigger keeps BOTH its side borders and the neighbour
|
|
14
|
+
touching it gives up its own: Button borders are border (neutral-200) while
|
|
15
|
+
the trigger's are input (neutral-300), so letting each seam fall to "the
|
|
16
|
+
child on the left" would draw the trigger's two seams in different colours.
|
|
17
|
+
|
|
18
|
+
Base order: layout, the corner/border joins, the z-raise that lets a
|
|
19
|
+
focused/open child paint its shadow over the joined neighbour's edge, then
|
|
20
|
+
the SelectTrigger width fix: a joined trigger hugs its value instead of
|
|
21
|
+
stretching. The `.w-full` guard is the discriminator — SelectTrigger runs
|
|
22
|
+
className through twMerge, so its default `w-full` survives only when the
|
|
23
|
+
consumer set no width; an explicit width (e.g. `w-44`) replaces it and
|
|
24
|
+
this rule stops matching. */
|
|
25
|
+
const buttonGroupVariants = cva([
|
|
26
|
+
"flex w-fit items-stretch",
|
|
27
|
+
"[&>*:not(:first-child)]:rounded-l-none",
|
|
28
|
+
"[&>*:not(:last-child)]:rounded-r-none",
|
|
29
|
+
"[&>*:not(:first-child):not([data-slot=select-trigger])]:border-l-0",
|
|
30
|
+
"[&>*:has(+[data-slot=select-trigger])]:border-r-0",
|
|
31
|
+
"[&>*]:focus-visible:relative [&>*]:focus-visible:z-10",
|
|
32
|
+
"[&>*]:data-[state=open]:relative [&>*]:data-[state=open]:z-10",
|
|
33
|
+
"[&>[data-slot=select-trigger].w-full]:w-fit",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Props for the ButtonGroup component.
|
|
38
|
+
* Joins Buttons and a Select trigger into one attached row with merged
|
|
39
|
+
* borders. Children must be direct children of the group.
|
|
40
|
+
*/
|
|
41
|
+
interface ButtonGroupProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
42
|
+
/**
|
|
43
|
+
* Data hook for automated testing (REQUIRED)
|
|
44
|
+
* @example "run-navigator"
|
|
45
|
+
*/
|
|
46
|
+
dataHook: string;
|
|
47
|
+
/**
|
|
48
|
+
* Tracking element identifier for analytics
|
|
49
|
+
*/
|
|
50
|
+
trackingEl?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Tracking label for analytics context
|
|
53
|
+
*/
|
|
54
|
+
trackingLabel?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
58
|
+
({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
ref={ref}
|
|
62
|
+
className={cn(buttonGroupVariants(), className)}
|
|
63
|
+
data-hook={dataHook}
|
|
64
|
+
data-slot="button-group"
|
|
65
|
+
data-tracking-el={trackingEl || "button-group"}
|
|
66
|
+
data-tracking-label={trackingLabel}
|
|
67
|
+
role="group"
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
ButtonGroup.displayName = "ButtonGroup";
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Props for the ButtonGroupSeparator component.
|
|
78
|
+
*/
|
|
79
|
+
interface ButtonGroupSeparatorProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
80
|
+
/**
|
|
81
|
+
* Data hook for automated testing
|
|
82
|
+
*/
|
|
83
|
+
dataHook?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* A black scrim darkens whatever fill it sits on, so one default works on a
|
|
87
|
+
primary green split, a destructive red one, and an outline group alike —
|
|
88
|
+
no per-variant separator colour and nothing to redefine in dark mode.
|
|
89
|
+
-ml-px pulls the line over the previous segment's edge (net width 0), so it
|
|
90
|
+
reads as a darker shade of the fill, not a gap showing the page behind. */
|
|
91
|
+
const ButtonGroupSeparator = React.forwardRef<
|
|
92
|
+
HTMLDivElement,
|
|
93
|
+
ButtonGroupSeparatorProps
|
|
94
|
+
>(({ className, dataHook, ...props }, ref) => {
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
ref={ref}
|
|
98
|
+
aria-orientation="vertical"
|
|
99
|
+
className={cn("-ml-px w-px shrink-0 self-stretch bg-black/15", className)}
|
|
100
|
+
data-hook={dataHook}
|
|
101
|
+
data-slot="button-group-separator"
|
|
102
|
+
role="separator"
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
ButtonGroupSeparator.displayName = "ButtonGroupSeparator";
|
|
109
|
+
|
|
110
|
+
export { ButtonGroup, ButtonGroupSeparator, buttonGroupVariants };
|
|
111
|
+
|
|
112
|
+
export type { ButtonGroupProps, ButtonGroupSeparatorProps };
|