@behavioral-agentic-design-system/core 0.39.1 → 0.42.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 +2 -0
- package/package.json +26 -5
- package/scripts/a11y-lint.cjs +88 -8
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +133 -12
- package/scripts/check-stories.mjs +1 -1
- package/scripts/health-report.mjs +16 -2
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/size-audit.cjs +79 -0
- package/scripts/source-of-truth.cjs +58 -0
- package/scripts/ux-smoke.mjs +438 -0
- package/scripts/wcag-audit.cjs +121 -6
- package/src/api/layers/file.ts +1 -0
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/components/page.tsx +2237 -2
- package/src/app/shell.tsx +17 -16
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +17 -2
- package/src/components/customize/discipline-section.tsx +3 -6
- package/src/components/customize/font-pickers.tsx +1 -1
- package/src/components/customize/letter-spacing.tsx +1 -1
- package/src/components/customize/save-bar.tsx +2 -2
- package/src/components/customize/theme-io.tsx +7 -7
- package/src/components/customize/type-scale.tsx +1 -1
- package/src/components/customize-tab.tsx +7 -4
- package/src/components/home-tab.tsx +3 -0
- package/src/components/studio/studio.tsx +153 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +5 -14
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +2 -2
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/gauge-chart.tsx +238 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +17 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +1 -4
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/portal.tsx +111 -0
- package/src/components/ui/presence.tsx +172 -0
- package/src/components/ui/progress-stack.tsx +258 -0
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/select.tsx +89 -4
- package/src/components/ui/separator.tsx +1 -0
- package/src/components/ui/slider.tsx +83 -3
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/sparkline.tsx +2 -14
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/textarea.tsx +28 -1
- package/src/components/ui/tour.tsx +1 -3
- package/src/data/docs-index.ts +25 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/lib/clamp.ts +2 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Badge.stories.tsx +3 -0
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +219 -0
- package/src/stories/Chart.stories.tsx +8 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +24 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/GaugeChart.stories.tsx +163 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +1 -0
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +191 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/Select.stories.tsx +25 -0
- package/src/stories/Separator.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +54 -5
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Sparkline.stories.tsx +3 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/story-groups.json +26 -6
- package/src/styles.css +133 -12
- package/LICENSE +0 -21
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
+
import * as React from "react"
|
|
3
|
+
import { ScrollProgress } from "@behavioral-agentic-design-system/core/components/ui/scroll-progress"
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof ScrollProgress> = {
|
|
6
|
+
title: "Components/Feedback/ScrollProgress",
|
|
7
|
+
component: ScrollProgress,
|
|
8
|
+
parameters: { layout: "fullscreen" },
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
}
|
|
11
|
+
export default meta
|
|
12
|
+
type Story = StoryObj<typeof ScrollProgress>
|
|
13
|
+
|
|
14
|
+
/** Inline bar inside a fixed-height scroll container (most testable in Storybook). */
|
|
15
|
+
export const Default: Story = {
|
|
16
|
+
parameters: { controls: { disable: true } },
|
|
17
|
+
render: () => {
|
|
18
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
19
|
+
return (
|
|
20
|
+
<div ref={ref} className="relative max-h-[360px] overflow-y-auto border rounded-lg">
|
|
21
|
+
<ScrollProgress containerRef={ref} position="sticky" />
|
|
22
|
+
<div className="space-y-6 p-6">
|
|
23
|
+
{Array.from({ length: 16 }, (_, i) => (
|
|
24
|
+
<p key={i} className="text-sm text-muted-foreground">
|
|
25
|
+
Paragraph {i + 1}: Scroll down to see the progress bar advance.
|
|
26
|
+
This simulates a long article or settings panel.
|
|
27
|
+
</p>
|
|
28
|
+
))}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Custom color and height. */
|
|
36
|
+
export const CustomStyle: Story = {
|
|
37
|
+
parameters: { controls: { disable: true } },
|
|
38
|
+
render: () => {
|
|
39
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
40
|
+
return (
|
|
41
|
+
<div ref={ref} className="relative max-h-[320px] overflow-y-auto border rounded-lg">
|
|
42
|
+
<ScrollProgress
|
|
43
|
+
containerRef={ref}
|
|
44
|
+
position="sticky"
|
|
45
|
+
height="4px"
|
|
46
|
+
color="var(--destructive)"
|
|
47
|
+
trackColor="transparent"
|
|
48
|
+
/>
|
|
49
|
+
<div className="space-y-6 p-6">
|
|
50
|
+
{Array.from({ length: 14 }, (_, i) => (
|
|
51
|
+
<p key={i} className="text-sm text-muted-foreground">
|
|
52
|
+
Item {i + 1}: Custom bar — 4px height, destructive color, no track.
|
|
53
|
+
</p>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Inline position — placed in flow inside a layout. */
|
|
62
|
+
export const Inline: Story = {
|
|
63
|
+
parameters: { controls: { disable: true } },
|
|
64
|
+
render: () => {
|
|
65
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
66
|
+
return (
|
|
67
|
+
<div className="max-w-lg mx-auto space-y-2">
|
|
68
|
+
<div ref={ref} className="relative max-h-[300px] overflow-y-auto rounded-lg border">
|
|
69
|
+
<ScrollProgress containerRef={ref} position="inline" className="mb-0" />
|
|
70
|
+
<div className="space-y-6 p-5">
|
|
71
|
+
{Array.from({ length: 12 }, (_, i) => (
|
|
72
|
+
<p key={i} className="text-sm text-muted-foreground">
|
|
73
|
+
Paragraph {i + 1}: Inline indicator, rendered in document flow above content.
|
|
74
|
+
</p>
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Realistic use: article reader with a sticky reading progress indicator. */
|
|
84
|
+
export const RealisticUse: Story = {
|
|
85
|
+
parameters: { controls: { disable: true } },
|
|
86
|
+
render: () => {
|
|
87
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
88
|
+
return (
|
|
89
|
+
<div ref={ref} className="relative max-h-[500px] overflow-y-auto">
|
|
90
|
+
<header className="sticky top-0 z-10 border-b bg-background/95 backdrop-blur-sm">
|
|
91
|
+
<ScrollProgress containerRef={ref} position="sticky" />
|
|
92
|
+
<div className="px-5 py-3">
|
|
93
|
+
<p className="text-sm font-medium">Understanding Design Systems</p>
|
|
94
|
+
</div>
|
|
95
|
+
</header>
|
|
96
|
+
<article className="space-y-6 px-5 py-8 max-w-xl">
|
|
97
|
+
<h1 className="text-2xl font-semibold">Understanding Design Systems</h1>
|
|
98
|
+
{[
|
|
99
|
+
"A design system is a collection of reusable components guided by clear standards that can be assembled to build any number of applications.",
|
|
100
|
+
"Great design systems prioritize accessibility as a core constraint — not an afterthought applied at the end of a sprint.",
|
|
101
|
+
"Token-driven systems separate intent from implementation. A semantic token like `--primary` means something; a literal hex value means nothing.",
|
|
102
|
+
"Components are only as good as the context they document. A component without examples of misuse is half a component.",
|
|
103
|
+
"Version discipline keeps a design system trustworthy. Breaking changes are fine; undocumented breaking changes are trust-breaking.",
|
|
104
|
+
"The best design system is the one your team actually uses. A perfect spec shipped to nobody beats an imperfect one adopted everywhere.",
|
|
105
|
+
"Testing a design system is different from testing a product — you are testing the primitives that other tests depend on.",
|
|
106
|
+
"Accessibility testing cannot be delegated entirely to automated tools. A green axe score is a floor, not a ceiling.",
|
|
107
|
+
].map((para, i) => (
|
|
108
|
+
<p key={i} className="text-sm leading-relaxed text-muted-foreground">
|
|
109
|
+
{para}
|
|
110
|
+
</p>
|
|
111
|
+
))}
|
|
112
|
+
</article>
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// the portal. See components/Sheet.stories.tsx → WithPortalTheme for the\
|
|
5
5
|
// canonical demonstration. Mechanism is identical here; no separate\
|
|
6
6
|
// story added because the demo would duplicate Sheet's.
|
|
7
|
+
import * as React from "react";
|
|
7
8
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
8
9
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@behavioral-agentic-design-system/core/components/ui/select";
|
|
9
10
|
|
|
@@ -132,3 +133,27 @@ export const RealisticUse: Story = {
|
|
|
132
133
|
</SelectContent>
|
|
133
134
|
</Select>),
|
|
134
135
|
};
|
|
136
|
+
|
|
137
|
+
export const Clearable: Story = {
|
|
138
|
+
// Controlled story uses React.useState — args panel can't drive it.
|
|
139
|
+
parameters: { controls: { disable: true } },
|
|
140
|
+
render: () => {
|
|
141
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
142
|
+
const [value, setValue] = React.useState("apple");
|
|
143
|
+
return (
|
|
144
|
+
<Select value={value} onValueChange={setValue} clearable>
|
|
145
|
+
<SelectTrigger className="w-[220px]" aria-label="Pick a fruit — clearable">
|
|
146
|
+
<SelectValue placeholder="Pick a fruit" />
|
|
147
|
+
</SelectTrigger>
|
|
148
|
+
<SelectContent>
|
|
149
|
+
<SelectGroup>
|
|
150
|
+
<SelectLabel>Fruits</SelectLabel>
|
|
151
|
+
<SelectItem value="apple">Apple</SelectItem>
|
|
152
|
+
<SelectItem value="banana">Banana</SelectItem>
|
|
153
|
+
<SelectItem value="cherry">Cherry</SelectItem>
|
|
154
|
+
</SelectGroup>
|
|
155
|
+
</SelectContent>
|
|
156
|
+
</Select>
|
|
157
|
+
);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { Separator } from "@behavioral-agentic-design-system/core/components/ui/separator";
|
|
3
3
|
|
|
4
|
+
// Separator always renders a <div> (see the recipe-note in separator.tsx) —
|
|
5
|
+
// never nest it inside a <p>; that's invalid HTML and throws React hydration
|
|
6
|
+
// error #418 at runtime even though `next build` reports success.
|
|
4
7
|
const meta: Meta<typeof Separator> = {
|
|
5
8
|
title: "Components/Layout/Separator",
|
|
6
9
|
component: Separator,
|
|
@@ -66,6 +66,48 @@ export const WithMarks: Story = {
|
|
|
66
66
|
),
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* `valueLabel="auto"` shows a thumb-anchored value bubble on hover, focus, and
|
|
71
|
+
* drag (Mantine `label`, MUI `valueLabelDisplay="auto"`, Ant `tooltip`). The
|
|
72
|
+
* bubble is `aria-hidden` — the thumb announces the value — and a string from
|
|
73
|
+
* `valueLabelFormat` is mirrored to `aria-valuetext`. Default `never` keeps
|
|
74
|
+
* the slider byte-identical to before.
|
|
75
|
+
*/
|
|
76
|
+
export const WithValueLabel: Story = {
|
|
77
|
+
args: {
|
|
78
|
+
defaultValue: [62],
|
|
79
|
+
min: 0,
|
|
80
|
+
max: 100,
|
|
81
|
+
step: 1,
|
|
82
|
+
"aria-label": "Volume",
|
|
83
|
+
valueLabel: "auto",
|
|
84
|
+
valueLabelFormat: (v: number) => `${v}%`,
|
|
85
|
+
},
|
|
86
|
+
render: (args) => (
|
|
87
|
+
<div className="w-72">
|
|
88
|
+
<Slider {...args} />
|
|
89
|
+
</div>
|
|
90
|
+
),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** `valueLabel="always"` keeps the bubble persistent and reserves room above the track for it. */
|
|
94
|
+
export const ValueLabelAlways: Story = {
|
|
95
|
+
args: {
|
|
96
|
+
defaultValue: [120, 375],
|
|
97
|
+
min: 0,
|
|
98
|
+
max: 500,
|
|
99
|
+
step: 5,
|
|
100
|
+
"aria-label": "Retainer range",
|
|
101
|
+
valueLabel: "always",
|
|
102
|
+
valueLabelFormat: (v: number) => `$${v}`,
|
|
103
|
+
},
|
|
104
|
+
render: (args) => (
|
|
105
|
+
<div className="w-72">
|
|
106
|
+
<Slider {...args} />
|
|
107
|
+
</div>
|
|
108
|
+
),
|
|
109
|
+
};
|
|
110
|
+
|
|
69
111
|
export const RealisticUse: Story = {
|
|
70
112
|
render: () => (
|
|
71
113
|
<div className="w-80 space-y-6">
|
|
@@ -84,11 +126,18 @@ export const RealisticUse: Story = {
|
|
|
84
126
|
<Slider defaultValue={[28]} min={0} max={100} step={1} aria-labelledby="slider-brightness" />
|
|
85
127
|
</div>
|
|
86
128
|
<div className="space-y-3">
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
129
|
+
<label id="slider-retainer" className="text-sm font-medium">
|
|
130
|
+
Monthly retainer range
|
|
131
|
+
</label>
|
|
132
|
+
<Slider
|
|
133
|
+
defaultValue={[120, 375]}
|
|
134
|
+
min={0}
|
|
135
|
+
max={500}
|
|
136
|
+
step={5}
|
|
137
|
+
aria-labelledby="slider-retainer"
|
|
138
|
+
valueLabel="always"
|
|
139
|
+
valueLabelFormat={(v) => `$${v}`}
|
|
140
|
+
/>
|
|
92
141
|
</div>
|
|
93
142
|
</div>
|
|
94
143
|
),
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
3
|
+
import { userEvent, within, expect } from "storybook/test"
|
|
4
|
+
import { Archive, CircleCheck, Link2, Send } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
SnackbarProvider,
|
|
8
|
+
useSnackbar,
|
|
9
|
+
SNACKBAR_ANCHORS,
|
|
10
|
+
type SnackbarOptions,
|
|
11
|
+
} from "@behavioral-agentic-design-system/core/components/ui/snackbar"
|
|
12
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button"
|
|
13
|
+
|
|
14
|
+
const meta: Meta<typeof SnackbarProvider> = {
|
|
15
|
+
title: "Components/Feedback/Snackbar",
|
|
16
|
+
component: SnackbarProvider,
|
|
17
|
+
// The outlet is position: fixed at the bottom of the viewport, so the
|
|
18
|
+
// story needs the whole canvas, not a centered box.
|
|
19
|
+
parameters: {
|
|
20
|
+
layout: "fullscreen",
|
|
21
|
+
docs: {
|
|
22
|
+
description: {
|
|
23
|
+
component:
|
|
24
|
+
"One transient feedback message at a time, anchored to the bottom of the screen, that auto-dismisses. Imperative API: `const { show, dismiss } = useSnackbar()` inside a `<SnackbarProvider>`. The next message queues behind the current one — nothing stacks. Use Sonner for a stacked queue of async events; use Snackbar for lightweight confirmations of something the user just did (copied, saved, moved · Undo). The timer pauses on hover and focus-within; a sticky message (`duration: Infinity`) is always dismissible; the live region is mounted before the first message so screen readers announce it.",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
tags: ["autodocs"],
|
|
29
|
+
argTypes: {
|
|
30
|
+
anchor: { control: "select", options: [...SNACKBAR_ANCHORS] },
|
|
31
|
+
duration: { control: { type: "number", min: 500, step: 500 } },
|
|
32
|
+
container: { control: false },
|
|
33
|
+
children: { control: false },
|
|
34
|
+
className: { control: false },
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default meta
|
|
39
|
+
type Story = StoryObj<typeof meta>
|
|
40
|
+
|
|
41
|
+
// Content from content/personas/bads.json → primary.names / orgs.
|
|
42
|
+
const PERSON = "Seo-yun Park"
|
|
43
|
+
const ORG = "Harborline Logistics"
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Shared harness: a Button inside the provider that calls `show()` with the
|
|
47
|
+
* story's options. `play` clicks it so the snackbar is on screen when the
|
|
48
|
+
* story (and Chromatic) first looks at it.
|
|
49
|
+
*/
|
|
50
|
+
function Trigger({
|
|
51
|
+
label,
|
|
52
|
+
options,
|
|
53
|
+
}: {
|
|
54
|
+
label: string
|
|
55
|
+
options: SnackbarOptions | string
|
|
56
|
+
}) {
|
|
57
|
+
const { show } = useSnackbar()
|
|
58
|
+
return (
|
|
59
|
+
<Button variant="outline" size="xl" onClick={() => show(options)}>
|
|
60
|
+
{label}
|
|
61
|
+
</Button>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Frame({ children }: { children: React.ReactNode }) {
|
|
66
|
+
return (
|
|
67
|
+
<div className="flex min-h-[360px] flex-wrap items-start gap-3 p-8">
|
|
68
|
+
{children}
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const clickThenExpect =
|
|
74
|
+
(buttonName: RegExp, text: string | RegExp) =>
|
|
75
|
+
async ({ canvasElement }: { canvasElement: HTMLElement }) => {
|
|
76
|
+
const canvas = within(canvasElement)
|
|
77
|
+
await userEvent.click(canvas.getByRole("button", { name: buttonName }))
|
|
78
|
+
// The snackbar portals to the story iframe's <body>, outside canvasElement.
|
|
79
|
+
const body = within(canvasElement.ownerDocument.body)
|
|
80
|
+
const status = await body.findByRole("status")
|
|
81
|
+
await expect(within(status).getByText(text)).toBeInTheDocument()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const Default: Story = {
|
|
85
|
+
args: { anchor: "bottom-center", duration: 4000 },
|
|
86
|
+
render: (args) => (
|
|
87
|
+
<SnackbarProvider {...args}>
|
|
88
|
+
<Frame>
|
|
89
|
+
<Trigger label="Save settings" options="Settings saved" />
|
|
90
|
+
</Frame>
|
|
91
|
+
</SnackbarProvider>
|
|
92
|
+
),
|
|
93
|
+
play: clickThenExpect(/save settings/i, "Settings saved"),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const WithAction: Story = {
|
|
97
|
+
parameters: { controls: { disable: true } },
|
|
98
|
+
render: () => (
|
|
99
|
+
<SnackbarProvider>
|
|
100
|
+
<Frame>
|
|
101
|
+
<Trigger
|
|
102
|
+
label="Archive component"
|
|
103
|
+
options={{
|
|
104
|
+
message: "Pill moved to Archive",
|
|
105
|
+
action: { label: "Undo", onClick: () => {} },
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
</Frame>
|
|
109
|
+
</SnackbarProvider>
|
|
110
|
+
),
|
|
111
|
+
play: clickThenExpect(/archive component/i, "Pill moved to Archive"),
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const WithIcon: Story = {
|
|
115
|
+
parameters: { controls: { disable: true } },
|
|
116
|
+
render: () => (
|
|
117
|
+
<SnackbarProvider>
|
|
118
|
+
<Frame>
|
|
119
|
+
<Trigger
|
|
120
|
+
label="Copy token name"
|
|
121
|
+
options={{
|
|
122
|
+
message: "Copied --primary to clipboard",
|
|
123
|
+
icon: <CircleCheck strokeWidth={1.5} className="text-icon-success" />,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
</Frame>
|
|
127
|
+
</SnackbarProvider>
|
|
128
|
+
),
|
|
129
|
+
play: clickThenExpect(/copy token name/i, "Copied --primary to clipboard"),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A long single-word identifier wraps with overflow-wrap:anywhere instead of pushing the controls out. */
|
|
133
|
+
export const LongMessage: Story = {
|
|
134
|
+
parameters: { controls: { disable: true } },
|
|
135
|
+
render: () => (
|
|
136
|
+
<SnackbarProvider>
|
|
137
|
+
<Frame>
|
|
138
|
+
<Trigger
|
|
139
|
+
label="Share link"
|
|
140
|
+
options={{
|
|
141
|
+
message:
|
|
142
|
+
"Share link copied: https://design.harborline-logistics.example/preview/components#snackbar-queue-and-pause-on-hover-behaviour",
|
|
143
|
+
icon: <Link2 strokeWidth={1.5} />,
|
|
144
|
+
action: { label: "Open", onClick: () => {} },
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
</Frame>
|
|
148
|
+
</SnackbarProvider>
|
|
149
|
+
),
|
|
150
|
+
play: clickThenExpect(/share link/i, /Share link copied/),
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 1.5 s — a quick confirmation that gets out of the way. */
|
|
154
|
+
export const CustomDuration: Story = {
|
|
155
|
+
parameters: { controls: { disable: true } },
|
|
156
|
+
render: () => (
|
|
157
|
+
<SnackbarProvider>
|
|
158
|
+
<Frame>
|
|
159
|
+
<Trigger
|
|
160
|
+
label="Save draft"
|
|
161
|
+
options={{ message: "Draft saved", duration: 1500 }}
|
|
162
|
+
/>
|
|
163
|
+
</Frame>
|
|
164
|
+
</SnackbarProvider>
|
|
165
|
+
),
|
|
166
|
+
play: clickThenExpect(/save draft/i, "Draft saved"),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const Anchor_BottomLeft: Story = {
|
|
170
|
+
parameters: { controls: { disable: true } },
|
|
171
|
+
render: () => (
|
|
172
|
+
<SnackbarProvider anchor="bottom-left">
|
|
173
|
+
<Frame>
|
|
174
|
+
<Trigger label="Save settings" options="Settings saved" />
|
|
175
|
+
</Frame>
|
|
176
|
+
</SnackbarProvider>
|
|
177
|
+
),
|
|
178
|
+
play: clickThenExpect(/save settings/i, "Settings saved"),
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const Anchor_BottomRight: Story = {
|
|
182
|
+
parameters: { controls: { disable: true } },
|
|
183
|
+
render: () => (
|
|
184
|
+
<SnackbarProvider anchor="bottom-right">
|
|
185
|
+
<Frame>
|
|
186
|
+
<Trigger label="Save settings" options="Settings saved" />
|
|
187
|
+
</Frame>
|
|
188
|
+
</SnackbarProvider>
|
|
189
|
+
),
|
|
190
|
+
play: clickThenExpect(/save settings/i, "Settings saved"),
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** `duration: Infinity` — stays until dismissed. The × shows by default so the message can never trap itself. */
|
|
194
|
+
export const Sticky: Story = {
|
|
195
|
+
parameters: { controls: { disable: true } },
|
|
196
|
+
render: () => (
|
|
197
|
+
<SnackbarProvider>
|
|
198
|
+
<Frame>
|
|
199
|
+
<Trigger
|
|
200
|
+
label="Go offline"
|
|
201
|
+
options={{
|
|
202
|
+
message: `You're offline. Changes to ${ORG} sync when you reconnect.`,
|
|
203
|
+
duration: Infinity,
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
</Frame>
|
|
207
|
+
</SnackbarProvider>
|
|
208
|
+
),
|
|
209
|
+
play: clickThenExpect(/go offline/i, /You're offline/),
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Three `show()` calls in a row — one visible, two waiting. The next mounts only after the current one has fully exited. */
|
|
213
|
+
export const Queue: Story = {
|
|
214
|
+
parameters: { controls: { disable: true } },
|
|
215
|
+
render: function QueueStory() {
|
|
216
|
+
function QueueTrigger() {
|
|
217
|
+
const { show, dismiss } = useSnackbar()
|
|
218
|
+
return (
|
|
219
|
+
<>
|
|
220
|
+
<Button
|
|
221
|
+
variant="outline"
|
|
222
|
+
size="xl"
|
|
223
|
+
onClick={() => {
|
|
224
|
+
show({ message: `Invitation sent to ${PERSON}`, duration: 2000 })
|
|
225
|
+
show({ message: "Role updated to Editor", duration: 2000 })
|
|
226
|
+
show({ message: "Workspace settings saved", duration: 2000 })
|
|
227
|
+
}}
|
|
228
|
+
>
|
|
229
|
+
Queue three messages
|
|
230
|
+
</Button>
|
|
231
|
+
<Button variant="ghost" size="xl" onClick={() => dismiss("all")}>
|
|
232
|
+
Clear queue
|
|
233
|
+
</Button>
|
|
234
|
+
</>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
return (
|
|
238
|
+
<SnackbarProvider>
|
|
239
|
+
<Frame>
|
|
240
|
+
<QueueTrigger />
|
|
241
|
+
</Frame>
|
|
242
|
+
</SnackbarProvider>
|
|
243
|
+
)
|
|
244
|
+
},
|
|
245
|
+
play: clickThenExpect(/queue three messages/i, `Invitation sent to ${PERSON}`),
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A team settings page: invite → confirmation with Undo, archive → confirmation with Undo. One snackbar, one message at a time. */
|
|
249
|
+
export const RealisticUse: Story = {
|
|
250
|
+
parameters: { controls: { disable: true } },
|
|
251
|
+
render: function RealisticUseStory() {
|
|
252
|
+
function TeamActions() {
|
|
253
|
+
const { show } = useSnackbar()
|
|
254
|
+
const [members, setMembers] = React.useState([PERSON, "Marcus Lindqvist", "Anika Patel"])
|
|
255
|
+
const [archived, setArchived] = React.useState<string[]>([])
|
|
256
|
+
return (
|
|
257
|
+
<div className="w-full max-w-md space-y-4">
|
|
258
|
+
<div>
|
|
259
|
+
<h3 className="text-lg font-semibold tracking-tight">{ORG} · Team</h3>
|
|
260
|
+
<p className="text-sm text-muted-foreground">
|
|
261
|
+
{members.length} members · {archived.length} archived
|
|
262
|
+
</p>
|
|
263
|
+
</div>
|
|
264
|
+
<ul className="divide-y rounded-lg border">
|
|
265
|
+
{members.map((name) => (
|
|
266
|
+
<li key={name} className="flex items-center justify-between gap-3 px-4 py-2">
|
|
267
|
+
<span className="min-w-0 truncate text-sm font-medium">{name}</span>
|
|
268
|
+
<Button
|
|
269
|
+
variant="ghost"
|
|
270
|
+
size="default"
|
|
271
|
+
className="min-h-11 shrink-0"
|
|
272
|
+
onClick={() => {
|
|
273
|
+
setMembers((m) => m.filter((n) => n !== name))
|
|
274
|
+
setArchived((a) => [...a, name])
|
|
275
|
+
show({
|
|
276
|
+
message: `${name} archived`,
|
|
277
|
+
icon: <Archive strokeWidth={1.5} />,
|
|
278
|
+
action: {
|
|
279
|
+
label: "Undo",
|
|
280
|
+
onClick: () => {
|
|
281
|
+
setArchived((a) => a.filter((n) => n !== name))
|
|
282
|
+
setMembers((m) => [...m, name])
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
}}
|
|
287
|
+
>
|
|
288
|
+
Archive
|
|
289
|
+
</Button>
|
|
290
|
+
</li>
|
|
291
|
+
))}
|
|
292
|
+
</ul>
|
|
293
|
+
<Button
|
|
294
|
+
size="xl"
|
|
295
|
+
onClick={() =>
|
|
296
|
+
show({
|
|
297
|
+
message: "Invitation sent to Tomás Herrera",
|
|
298
|
+
icon: <Send strokeWidth={1.5} />,
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
>
|
|
302
|
+
Invite Tomás Herrera
|
|
303
|
+
</Button>
|
|
304
|
+
</div>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
return (
|
|
308
|
+
<SnackbarProvider>
|
|
309
|
+
<Frame>
|
|
310
|
+
<TeamActions />
|
|
311
|
+
</Frame>
|
|
312
|
+
</SnackbarProvider>
|
|
313
|
+
)
|
|
314
|
+
},
|
|
315
|
+
}
|