@brightlocal/ui-components 2.26.0 → 3.0.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 +9 -2
- package/component-meta.json +4010 -255
- package/deprecations.json +189 -2
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.js +2 -2
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.js +18 -18
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts +11 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +31 -28
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.js +4 -4
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +15 -11
- package/dist/blocks/empty-state.cjs +1 -0
- package/dist/blocks/empty-state.d.ts +172 -0
- package/dist/blocks/empty-state.d.ts.map +1 -0
- package/dist/blocks/empty-state.js +155 -0
- package/dist/blocks/input-list.cjs +2 -2
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +124 -108
- package/dist/blocks/progress-state.cjs +1 -0
- package/dist/blocks/progress-state.d.ts +121 -0
- package/dist/blocks/progress-state.d.ts.map +1 -0
- package/dist/blocks/progress-state.js +368 -0
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +297 -296
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +44 -40
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +23 -23
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +37 -38
- package/dist/callout.cjs +1 -1
- package/dist/callout.d.ts +24 -2
- package/dist/callout.d.ts.map +1 -1
- package/dist/callout.js +57 -55
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +23 -2
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +94 -91
- package/dist/chart-empty.cjs +1 -0
- package/dist/chart-empty.d.ts +59 -0
- package/dist/chart-empty.d.ts.map +1 -0
- package/dist/chart-empty.js +29 -0
- package/dist/chart.cjs +6 -6
- package/dist/chart.d.ts +6 -1
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +183 -183
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +1 -1
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +47 -44
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +4 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +143 -141
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +74 -77
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +26 -29
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +182 -13
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +462 -314
- package/dist/description.cjs +1 -1
- package/dist/description.js +5 -5
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +20 -20
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +8 -11
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +17 -20
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +29 -25
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +58 -6
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +278 -194
- package/dist/grid.cjs +1 -0
- package/dist/grid.d.ts +56 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +32 -0
- package/dist/header.d.ts +13 -0
- package/dist/header.d.ts.map +1 -1
- package/dist/hooks/use-delayed-pending.cjs +1 -0
- package/dist/hooks/use-delayed-pending.d.ts +34 -0
- package/dist/hooks/use-delayed-pending.d.ts.map +1 -0
- package/dist/hooks/use-delayed-pending.js +17 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.js +13 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +523 -494
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.js +25 -25
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.js +9 -9
- 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.js +51 -51
- package/dist/input.cjs +1 -1
- package/dist/input.js +9 -9
- package/dist/label.cjs +1 -1
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +25 -28
- package/dist/lib/block-illustration.cjs +1 -0
- package/dist/lib/block-illustration.d.ts +28 -0
- package/dist/lib/block-illustration.d.ts.map +1 -0
- package/dist/lib/block-illustration.js +21 -0
- package/dist/lib/empty-canvas.cjs +1 -0
- package/dist/lib/empty-canvas.d.ts +27 -0
- package/dist/lib/empty-canvas.d.ts.map +1 -0
- package/dist/lib/empty-canvas.js +62 -0
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.js +10 -8
- package/dist/lib/optical-center.cjs +1 -0
- package/dist/lib/optical-center.d.ts +12 -0
- package/dist/lib/optical-center.d.ts.map +1 -0
- package/dist/lib/optical-center.js +11 -0
- package/dist/lib/utils.cjs +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +28 -5
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +8 -6
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +52 -20
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +87 -81
- package/dist/map.cjs +1 -1
- package/dist/map.d.ts +60 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +187 -164
- package/dist/media-empty.cjs +1 -0
- package/dist/media-empty.d.ts +72 -0
- package/dist/media-empty.d.ts.map +1 -0
- package/dist/media-empty.js +45 -0
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +17 -20
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.js +7 -7
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +127 -1
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +189 -98
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +37 -3
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +102 -64
- package/dist/route-progress.cjs +1 -0
- package/dist/route-progress.d.ts +103 -0
- package/dist/route-progress.d.ts.map +1 -0
- package/dist/route-progress.js +106 -0
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +19 -18
- package/dist/separator.cjs +1 -1
- package/dist/separator.js +8 -8
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +35 -2
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +103 -66
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.d.ts +38 -3
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js +43 -20
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +32 -36
- package/dist/spinner.cjs +1 -0
- package/dist/spinner.d.ts +57 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/spinner.js +35 -0
- package/dist/stepper.cjs +1 -1
- package/dist/stepper.d.ts.map +1 -1
- package/dist/stepper.js +23 -22
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +36 -29
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/text-reveal-motion.d.ts +10 -0
- package/dist/text-reveal-motion.d.ts.map +1 -1
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +11 -11
- package/dist/toggle.cjs +1 -1
- package/dist/toggle.js +8 -8
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.js +8 -8
- package/dist/typography-heading.cjs +1 -0
- package/dist/typography-heading.d.ts +116 -0
- package/dist/typography-heading.d.ts.map +1 -0
- package/dist/typography-heading.js +84 -0
- package/dist/typography-text.cjs +1 -0
- package/dist/typography-text.d.ts +113 -0
- package/dist/typography-text.d.ts.map +1 -0
- package/dist/typography-text.js +81 -0
- package/dist/typography.d.ts +13 -0
- package/dist/typography.d.ts.map +1 -1
- package/package.json +42 -2
- package/src/blocks/empty-state.tsx +424 -0
- package/src/blocks/input-list.tsx +66 -36
- package/src/blocks/progress-state.tsx +542 -0
- package/src/blocks/sidebar.tsx +46 -40
- package/src/components/accordion.tsx +2 -2
- package/src/components/alert-dialog.tsx +2 -2
- package/src/components/alert.tsx +27 -13
- package/src/components/avatar.tsx +1 -1
- package/src/components/badge.tsx +8 -4
- package/src/components/breadcrumb.tsx +9 -4
- package/src/components/button.tsx +5 -8
- package/src/components/calendar.tsx +5 -6
- package/src/components/callout.tsx +48 -15
- package/src/components/card.tsx +52 -17
- package/src/components/chart-empty.tsx +116 -0
- package/src/components/chart.tsx +43 -17
- package/src/components/chip.tsx +9 -6
- package/src/components/combobox.tsx +21 -12
- package/src/components/command.tsx +9 -10
- package/src/components/context-menu.tsx +6 -9
- package/src/components/data-table.tsx +405 -31
- package/src/components/description.tsx +1 -1
- package/src/components/dialog.tsx +2 -2
- package/src/components/drawer.tsx +2 -5
- package/src/components/dropdown-menu.tsx +8 -11
- package/src/components/field.tsx +8 -4
- package/src/components/global-layout.tsx +264 -65
- package/src/components/grid.tsx +130 -0
- package/src/components/header.tsx +13 -0
- package/src/components/hover-card.tsx +1 -1
- package/src/components/input-chip.tsx +1 -1
- package/src/components/input-group.tsx +1 -1
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input-password.tsx +1 -1
- package/src/components/input.tsx +1 -1
- package/src/components/label.tsx +10 -13
- package/src/components/link.tsx +39 -5
- package/src/components/list.tsx +18 -14
- package/src/components/map.tsx +101 -5
- package/src/components/media-empty.tsx +156 -0
- package/src/components/menubar.tsx +7 -10
- package/src/components/navigation-menu.tsx +1 -1
- package/src/components/pagination.tsx +279 -1
- package/src/components/progress.tsx +120 -11
- package/src/components/route-progress.tsx +354 -0
- package/src/components/select.tsx +5 -4
- package/src/components/separator.tsx +1 -1
- package/src/components/sheet.tsx +89 -7
- package/src/components/skeleton.tsx +78 -7
- package/src/components/sonner.tsx +5 -14
- package/src/components/spinner.tsx +94 -0
- package/src/components/stepper.tsx +6 -7
- package/src/components/table.tsx +11 -4
- package/src/components/tabs.tsx +1 -1
- package/src/components/text-reveal-motion.tsx +10 -0
- package/src/components/textarea.tsx +1 -1
- package/src/components/toggle.tsx +1 -1
- package/src/components/tooltip.tsx +1 -1
- package/src/components/typography-heading.tsx +229 -0
- package/src/components/typography-text.tsx +225 -0
- package/src/components/typography.tsx +13 -0
- package/src/hooks/use-delayed-pending.ts +60 -0
- package/src/index.ts +12 -0
- package/src/lib/block-illustration.tsx +88 -0
- package/src/lib/empty-canvas.tsx +128 -0
- package/src/lib/optical-center.tsx +45 -0
- package/src/lib/utils.ts +26 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
|
+
import {
|
|
6
|
+
TypographyHeading,
|
|
7
|
+
type TypographyHeadingLevel,
|
|
8
|
+
} from "../components/typography-heading";
|
|
9
|
+
import { TypographyText } from "../components/typography-text";
|
|
10
|
+
import {
|
|
11
|
+
BLOCK_ILLUSTRATION_SIZE,
|
|
12
|
+
BlockIllustration,
|
|
13
|
+
} from "../lib/block-illustration";
|
|
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 20/28 title.
|
|
30
|
+
* lg — for the moment the whole page has nothing to show: a full
|
|
31
|
+
* illustration at 130 and a 24/32 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 20/28, or Poppins 24/32. */
|
|
72
|
+
const SIZE_HEADING_VARIANT = {
|
|
73
|
+
md: "section",
|
|
74
|
+
lg: "page",
|
|
75
|
+
} as const;
|
|
76
|
+
|
|
77
|
+
/** The outline level each size defaults to, if the consumer names none. */
|
|
78
|
+
const SIZE_TITLE_LEVEL: Record<EmptyStateSize, TypographyHeadingLevel> = {
|
|
79
|
+
// An lg block is the page's message, under the layout's own page header,
|
|
80
|
+
// which owns h1.
|
|
81
|
+
lg: 2,
|
|
82
|
+
md: 3,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The visual's chip: 40px of `bg-muted` around a 16px glyph. A canvas drops it
|
|
87
|
+
* — but a canvas is a different component, so there is no variant for that here.
|
|
88
|
+
*/
|
|
89
|
+
const chipStyles = cva(
|
|
90
|
+
"bg-muted text-muted-foreground flex size-10 items-center justify-center rounded-full",
|
|
91
|
+
{
|
|
92
|
+
variants: {
|
|
93
|
+
align: { center: "", left: "shrink-0" },
|
|
94
|
+
},
|
|
95
|
+
defaultVariants: { align: "center" },
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The parts every empty state has, at either size.
|
|
101
|
+
*/
|
|
102
|
+
interface EmptyStateBaseProps extends Omit<
|
|
103
|
+
React.ComponentPropsWithoutRef<"div">,
|
|
104
|
+
"title"
|
|
105
|
+
> {
|
|
106
|
+
/**
|
|
107
|
+
* Required data-hook attribute for automated testing. The parts derive
|
|
108
|
+
* theirs from it: `-icon`, `-title`, `-message`.
|
|
109
|
+
* @example "locations-empty"
|
|
110
|
+
*/
|
|
111
|
+
dataHook: string;
|
|
112
|
+
/**
|
|
113
|
+
* What is missing, as a real heading. Name the thing, not the condition:
|
|
114
|
+
* "No locations yet", never "Empty".
|
|
115
|
+
*/
|
|
116
|
+
title: React.ReactNode;
|
|
117
|
+
/**
|
|
118
|
+
* One line under the title: what would put something here, or why there is
|
|
119
|
+
* nothing. May carry an inline link that reads as part of the sentence.
|
|
120
|
+
*/
|
|
121
|
+
description?: React.ReactNode;
|
|
122
|
+
/**
|
|
123
|
+
* The actions row. Source order is the rendered order and the primary action
|
|
124
|
+
* goes last, so the CTA lands rightmost; a quiet
|
|
125
|
+
* `<Link variant="ghost" external>` comes before it. Never a second bordered
|
|
126
|
+
* button — two buttons of equal weight ask the reader to choose twice.
|
|
127
|
+
*
|
|
128
|
+
* Omit it entirely on a gated screen: the reader cannot act, and a button
|
|
129
|
+
* they are not allowed to press is worse than no button.
|
|
130
|
+
*/
|
|
131
|
+
children?: React.ReactNode;
|
|
132
|
+
/**
|
|
133
|
+
* Document outline level for the title. Pick it as if CSS did not exist —
|
|
134
|
+
* the text's size comes from `size`, never from this.
|
|
135
|
+
* @default 3 at size md, 2 at size lg
|
|
136
|
+
*/
|
|
137
|
+
titleLevel?: TypographyHeadingLevel;
|
|
138
|
+
/**
|
|
139
|
+
* Tracking element identifier for analytics.
|
|
140
|
+
*/
|
|
141
|
+
trackingEl?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Tracking label for analytics context.
|
|
144
|
+
*/
|
|
145
|
+
trackingLabel?: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The block at md: filling one region of a working page.
|
|
150
|
+
*/
|
|
151
|
+
interface EmptyStateMdProps extends EmptyStateBaseProps {
|
|
152
|
+
/**
|
|
153
|
+
* @default "md"
|
|
154
|
+
*/
|
|
155
|
+
size?: "md";
|
|
156
|
+
/**
|
|
157
|
+
* Content alignment relative to the chip.
|
|
158
|
+
* @default "center"
|
|
159
|
+
*/
|
|
160
|
+
align?: EmptyStateAlign;
|
|
161
|
+
/**
|
|
162
|
+
* The glyph in the muted chip, at its default 16px. Decorative: the wrapper
|
|
163
|
+
* is `aria-hidden`, so pass the glyph and nothing else.
|
|
164
|
+
* @example <MapPin />
|
|
165
|
+
*/
|
|
166
|
+
icon?: React.ReactNode;
|
|
167
|
+
/**
|
|
168
|
+
* Not available at md — a 130px drawing inside a card outweighs the page
|
|
169
|
+
* around it. Use `size="lg"`, or pass an `icon`.
|
|
170
|
+
*/
|
|
171
|
+
illustration?: never;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The block at lg: the whole page has nothing to show.
|
|
176
|
+
*/
|
|
177
|
+
interface EmptyStateLgProps extends EmptyStateBaseProps {
|
|
178
|
+
size: "lg";
|
|
179
|
+
/**
|
|
180
|
+
* The screen's illustration. Decorative — mark it `aria-hidden`; the title
|
|
181
|
+
* and description carry the state on their own.
|
|
182
|
+
*
|
|
183
|
+
* Pass the illustration itself and do NOT set a size: the block renders it at
|
|
184
|
+
* the size the design specifies, whatever the element carries, so there is no
|
|
185
|
+
* number to get wrong per call site.
|
|
186
|
+
* @example <BusinessLocation aria-hidden />
|
|
187
|
+
*/
|
|
188
|
+
illustration?: React.ReactNode;
|
|
189
|
+
/**
|
|
190
|
+
* A glyph in the muted chip, for a page with no illustration of its own.
|
|
191
|
+
* Ignored when `illustration` is set — a screen gets one visual, not two.
|
|
192
|
+
*/
|
|
193
|
+
icon?: React.ReactNode;
|
|
194
|
+
/**
|
|
195
|
+
* Not available at lg: a page message is centred, full stop.
|
|
196
|
+
*/
|
|
197
|
+
align?: never;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Props for the EmptyState block. `size` discriminates the two shapes.
|
|
202
|
+
*/
|
|
203
|
+
export type EmptyStateProps = EmptyStateMdProps | EmptyStateLgProps;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The empty block: a visual, a title, one supporting line, and up to two
|
|
207
|
+
* actions. Pure content — compose the position around it: `size="lg"` inside
|
|
208
|
+
* `<Grid variant="centered">` for an empty page, `size="md"` inside the card, panel or
|
|
209
|
+
* table frame it speaks for.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```tsx
|
|
213
|
+
* // A zero-row collection, inside the table's own frame.
|
|
214
|
+
* <EmptyState
|
|
215
|
+
* dataHook="locations-empty"
|
|
216
|
+
* description="Add a location to start tracking visibility."
|
|
217
|
+
* icon={<MapPin />}
|
|
218
|
+
* title={t("locations.empty.title")}
|
|
219
|
+
* >
|
|
220
|
+
* <Button dataHook="locations-add" variant="secondary">
|
|
221
|
+
* <Plus aria-hidden="true" />
|
|
222
|
+
* Add location
|
|
223
|
+
* </Button>
|
|
224
|
+
* </EmptyState>
|
|
225
|
+
*
|
|
226
|
+
* // In a card's reading flow, with a quiet secondary action before the CTA.
|
|
227
|
+
* <EmptyState
|
|
228
|
+
* align="left"
|
|
229
|
+
* dataHook="reviews-empty"
|
|
230
|
+
* description={t("reviews.empty.description")}
|
|
231
|
+
* icon={<MessageSquareText />}
|
|
232
|
+
* title="No reviews yet"
|
|
233
|
+
* >
|
|
234
|
+
* <Link dataHook="reviews-docs" external href="/help/reviews" variant="ghost">
|
|
235
|
+
* How review sync works
|
|
236
|
+
* </Link>
|
|
237
|
+
* <Button dataHook="reviews-connect" variant="secondary">Connect profile</Button>
|
|
238
|
+
* </EmptyState>
|
|
239
|
+
*
|
|
240
|
+
* // The whole page is empty: lg, held at the page body's optical centre.
|
|
241
|
+
* <Grid dataHook="locations-empty-center" variant="centered">
|
|
242
|
+
* <EmptyState
|
|
243
|
+
* dataHook="locations-empty-page"
|
|
244
|
+
* description={t("locations.empty.description")}
|
|
245
|
+
* illustration={<BusinessLocation aria-hidden />}
|
|
246
|
+
* size="lg"
|
|
247
|
+
* title={t("locations.empty.title")}
|
|
248
|
+
* >
|
|
249
|
+
* <Button dataHook="locations-add">
|
|
250
|
+
* <Plus aria-hidden="true" />
|
|
251
|
+
* Add location
|
|
252
|
+
* </Button>
|
|
253
|
+
* </EmptyState>
|
|
254
|
+
* </Grid>
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(
|
|
258
|
+
(props, ref) => {
|
|
259
|
+
const {
|
|
260
|
+
className,
|
|
261
|
+
dataHook,
|
|
262
|
+
title,
|
|
263
|
+
description,
|
|
264
|
+
children,
|
|
265
|
+
titleLevel,
|
|
266
|
+
trackingEl,
|
|
267
|
+
trackingLabel,
|
|
268
|
+
size = "md",
|
|
269
|
+
...rest
|
|
270
|
+
} = props;
|
|
271
|
+
/* Read the two size-exclusive props off the union by hand: destructuring
|
|
272
|
+
them above would make TypeScript resolve them against both members. */
|
|
273
|
+
const icon = (props as EmptyStateMdProps).icon;
|
|
274
|
+
const illustration = (props as EmptyStateLgProps).illustration;
|
|
275
|
+
const align: EmptyStateAlign =
|
|
276
|
+
size === "lg"
|
|
277
|
+
? "center"
|
|
278
|
+
: ((props as EmptyStateMdProps).align ?? "center");
|
|
279
|
+
const domProps = rest as React.ComponentPropsWithoutRef<"div">;
|
|
280
|
+
delete (domProps as { icon?: unknown }).icon;
|
|
281
|
+
delete (domProps as { illustration?: unknown }).illustration;
|
|
282
|
+
delete (domProps as { align?: unknown }).align;
|
|
283
|
+
|
|
284
|
+
/* `children ? …` is not enough to decide whether there is an actions row.
|
|
285
|
+
Call sites write `{canAdd && <Button/>}`, and two conditionals make
|
|
286
|
+
`children` the array `[false, false]` — truthy, so the row would render
|
|
287
|
+
empty and leave a stray 8px above nothing. `Children.toArray` drops
|
|
288
|
+
null, undefined and booleans, which is exactly the question being asked.
|
|
289
|
+
|
|
290
|
+
It does NOT look inside a fragment, though, and a call site that wraps
|
|
291
|
+
its conditionals in one (`<>{a}{b}</>`) would count as a single child
|
|
292
|
+
however empty it is. So unwrap one level before counting. */
|
|
293
|
+
const hasActions =
|
|
294
|
+
React.Children.toArray(children).flatMap((child) =>
|
|
295
|
+
React.isValidElement(child) && child.type === React.Fragment
|
|
296
|
+
? React.Children.toArray(
|
|
297
|
+
(child.props as { children?: React.ReactNode }).children
|
|
298
|
+
)
|
|
299
|
+
: [child]
|
|
300
|
+
).length > 0;
|
|
301
|
+
|
|
302
|
+
/* lg gets the illustration; md gets the chip. The chip is the fallback on
|
|
303
|
+
a page with no artwork of its own. */
|
|
304
|
+
const visual =
|
|
305
|
+
size === "lg" && illustration ? (
|
|
306
|
+
<BlockIllustration
|
|
307
|
+
size={BLOCK_ILLUSTRATION_SIZE}
|
|
308
|
+
slot="empty-state-illustration"
|
|
309
|
+
>
|
|
310
|
+
{illustration}
|
|
311
|
+
</BlockIllustration>
|
|
312
|
+
) : icon ? (
|
|
313
|
+
<span
|
|
314
|
+
aria-hidden="true"
|
|
315
|
+
className={cn(
|
|
316
|
+
chipStyles({ align }),
|
|
317
|
+
/* The chip's 4px of extra breathing room belongs to the title
|
|
318
|
+
under it — the lg column sets its own 16px rhythm instead. */
|
|
319
|
+
size === "md" && align === "center" && "mb-1"
|
|
320
|
+
)}
|
|
321
|
+
data-hook={`${dataHook}-icon`}
|
|
322
|
+
data-slot="empty-state-icon"
|
|
323
|
+
>
|
|
324
|
+
{icon}
|
|
325
|
+
</span>
|
|
326
|
+
) : null;
|
|
327
|
+
|
|
328
|
+
/* One column for every size and alignment, so the parts and their spacing
|
|
329
|
+
are written once. */
|
|
330
|
+
const content = (
|
|
331
|
+
<div
|
|
332
|
+
className={cn(
|
|
333
|
+
"flex flex-col gap-2",
|
|
334
|
+
align === "center" && "w-full items-center"
|
|
335
|
+
)}
|
|
336
|
+
data-slot="empty-state-content"
|
|
337
|
+
>
|
|
338
|
+
<TypographyHeading
|
|
339
|
+
align={align === "center" ? "center" : "left"}
|
|
340
|
+
data-slot="empty-state-title"
|
|
341
|
+
dataHook={`${dataHook}-title`}
|
|
342
|
+
level={titleLevel ?? SIZE_TITLE_LEVEL[size]}
|
|
343
|
+
variant={SIZE_HEADING_VARIANT[size]}
|
|
344
|
+
>
|
|
345
|
+
{title}
|
|
346
|
+
</TypographyHeading>
|
|
347
|
+
{description ? (
|
|
348
|
+
/* Capped at 28rem: a single line of support reads as one thought
|
|
349
|
+
only while it stays a couple of lines long. */
|
|
350
|
+
<TypographyText
|
|
351
|
+
align={align === "center" ? "center" : "left"}
|
|
352
|
+
className="max-w-md"
|
|
353
|
+
color="muted"
|
|
354
|
+
data-slot="empty-state-description"
|
|
355
|
+
dataHook={`${dataHook}-message`}
|
|
356
|
+
variant="body-sm"
|
|
357
|
+
>
|
|
358
|
+
{description}
|
|
359
|
+
</TypographyText>
|
|
360
|
+
) : null}
|
|
361
|
+
{hasActions ? (
|
|
362
|
+
<div
|
|
363
|
+
className={cn(
|
|
364
|
+
"mt-2 flex items-center gap-4",
|
|
365
|
+
align === "center" && "justify-center"
|
|
366
|
+
)}
|
|
367
|
+
data-slot="empty-state-actions"
|
|
368
|
+
>
|
|
369
|
+
{children}
|
|
370
|
+
</div>
|
|
371
|
+
) : null}
|
|
372
|
+
</div>
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
if (size === "lg") {
|
|
376
|
+
return (
|
|
377
|
+
<div
|
|
378
|
+
ref={ref}
|
|
379
|
+
/* 24px between the illustration and the text — the artwork needs
|
|
380
|
+
more air than the chip does (spacing/6 in Figma). No page layout
|
|
381
|
+
here: the block is the message, and `Grid variant="centered"`
|
|
382
|
+
(or whatever box the consumer chooses) is the position. */
|
|
383
|
+
className={cn("flex w-full flex-col items-center gap-6", className)}
|
|
384
|
+
data-hook={dataHook}
|
|
385
|
+
data-size="lg"
|
|
386
|
+
data-slot="empty-state"
|
|
387
|
+
data-tracking-el={trackingEl ?? "empty-state"}
|
|
388
|
+
data-tracking-label={trackingLabel}
|
|
389
|
+
{...domProps}
|
|
390
|
+
>
|
|
391
|
+
{visual}
|
|
392
|
+
{content}
|
|
393
|
+
</div>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<div
|
|
399
|
+
ref={ref}
|
|
400
|
+
className={cn(
|
|
401
|
+
align === "left"
|
|
402
|
+
? "flex items-start gap-4 text-left"
|
|
403
|
+
: "flex flex-col items-center gap-2 text-center",
|
|
404
|
+
className
|
|
405
|
+
)}
|
|
406
|
+
data-hook={dataHook}
|
|
407
|
+
data-size="md"
|
|
408
|
+
data-slot="empty-state"
|
|
409
|
+
data-tracking-el={trackingEl ?? "empty-state"}
|
|
410
|
+
data-tracking-label={trackingLabel}
|
|
411
|
+
{...domProps}
|
|
412
|
+
>
|
|
413
|
+
{visual}
|
|
414
|
+
{content}
|
|
415
|
+
</div>
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
EmptyState.displayName = "EmptyState";
|
|
421
|
+
|
|
422
|
+
export { EmptyState };
|
|
423
|
+
|
|
424
|
+
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
const [
|
|
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
|
-
//
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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]
|