@bwui/react 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/dist/alert.d.ts +8 -0
  4. package/dist/alert.js +11 -0
  5. package/dist/badge.d.ts +6 -0
  6. package/dist/badge.js +5 -0
  7. package/dist/button.d.ts +16 -0
  8. package/dist/button.js +12 -0
  9. package/dist/card.d.ts +9 -0
  10. package/dist/card.js +20 -0
  11. package/dist/chrome.d.ts +59 -0
  12. package/dist/chrome.js +75 -0
  13. package/dist/cn.d.ts +6 -0
  14. package/dist/cn.js +8 -0
  15. package/dist/combobox.d.ts +20 -0
  16. package/dist/combobox.js +70 -0
  17. package/dist/command.d.ts +16 -0
  18. package/dist/command.js +74 -0
  19. package/dist/data-table.d.ts +17 -0
  20. package/dist/data-table.js +17 -0
  21. package/dist/date-picker.d.ts +30 -0
  22. package/dist/date-picker.js +146 -0
  23. package/dist/form.d.ts +31 -0
  24. package/dist/form.js +55 -0
  25. package/dist/index.d.ts +28 -0
  26. package/dist/index.js +17 -0
  27. package/dist/kbd.d.ts +2 -0
  28. package/dist/kbd.js +5 -0
  29. package/dist/layout.d.ts +10 -0
  30. package/dist/layout.js +23 -0
  31. package/dist/modal.d.ts +11 -0
  32. package/dist/modal.js +18 -0
  33. package/dist/pages.d.ts +42 -0
  34. package/dist/pages.js +84 -0
  35. package/dist/toast.d.ts +18 -0
  36. package/dist/toast.js +24 -0
  37. package/package.json +43 -3
  38. package/src/alert.tsx +36 -0
  39. package/src/badge.tsx +24 -0
  40. package/src/button.tsx +66 -0
  41. package/src/card.tsx +34 -0
  42. package/src/chrome.tsx +263 -0
  43. package/src/cn.ts +8 -0
  44. package/src/combobox.tsx +162 -0
  45. package/src/command.tsx +145 -0
  46. package/src/data-table.tsx +114 -0
  47. package/src/date-picker.tsx +357 -0
  48. package/src/form.tsx +201 -0
  49. package/src/index.ts +90 -0
  50. package/src/kbd.tsx +9 -0
  51. package/src/layout.tsx +44 -0
  52. package/src/modal.tsx +70 -0
  53. package/src/pages.tsx +361 -0
  54. package/src/toast.tsx +84 -0
package/src/index.ts ADDED
@@ -0,0 +1,90 @@
1
+ export { Button, ButtonLink } from './button'
2
+ export type { ButtonProps, ButtonLinkProps, ButtonVariant, ButtonSize } from './button'
3
+
4
+ export { Badge } from './badge'
5
+ export type { BadgeProps, BadgeVariant } from './badge'
6
+
7
+ export {
8
+ Card,
9
+ CardHeader,
10
+ CardTitle,
11
+ CardDescription,
12
+ CardBody,
13
+ CardFooter,
14
+ } from './card'
15
+
16
+ export { Alert, AlertTitle, AlertBody } from './alert'
17
+ export type { AlertProps, AlertVariant } from './alert'
18
+
19
+ export {
20
+ Input,
21
+ Textarea,
22
+ Select,
23
+ Field,
24
+ Label,
25
+ Hint,
26
+ FieldError,
27
+ FormErrors,
28
+ Form,
29
+ FormActions,
30
+ Switch,
31
+ Checkbox,
32
+ Radio,
33
+ TimeInput,
34
+ DateTimeInput,
35
+ PasswordField,
36
+ } from './form'
37
+ export type { SwitchProps, PasswordFieldProps } from './form'
38
+
39
+ export { Combobox } from './combobox'
40
+ export type { ComboboxProps, ComboboxOption } from './combobox'
41
+
42
+ export { DatePicker, DateRangePicker } from './date-picker'
43
+ export type { DatePickerProps, DateRangePickerProps } from './date-picker'
44
+
45
+ export {
46
+ Stack,
47
+ Cluster,
48
+ Grid,
49
+ Container,
50
+ Centre,
51
+ Divider,
52
+ SkipLink,
53
+ } from './layout'
54
+
55
+ export {
56
+ Tabs,
57
+ TabList,
58
+ Tab,
59
+ TabPanel,
60
+ ThemeToggle,
61
+ EmptyState,
62
+ Spinner,
63
+ Progress,
64
+ Skeleton,
65
+ Avatar,
66
+ Chip,
67
+ Breadcrumbs,
68
+ Pagination,
69
+ } from './chrome'
70
+
71
+ export { ToastProvider, useToast } from './toast'
72
+ export type { ToastItem, ToastVariant } from './toast'
73
+
74
+ export { Homepage, Landing, ContactForm } from './pages'
75
+ export type { HomepageProps, LandingProps, ContactFormProps, NavLink } from './pages'
76
+
77
+ export { cn } from './cn'
78
+
79
+ export * as tokens from '@bwui/tokens'
80
+
81
+ export { Modal } from './modal'
82
+ export type { ModalProps } from './modal'
83
+
84
+ export { CommandPalette } from './command'
85
+ export type { CommandPaletteProps, CommandItem } from './command'
86
+
87
+ export { DataTable } from './data-table'
88
+ export type { DataTableProps, DataTableColumn } from './data-table'
89
+
90
+ export { Kbd } from './kbd'
package/src/kbd.tsx ADDED
@@ -0,0 +1,9 @@
1
+ import * as React from 'react'
2
+ import { cn } from './cn'
3
+
4
+ export function Kbd({
5
+ className,
6
+ ...props
7
+ }: React.HTMLAttributes<HTMLElement>) {
8
+ return <kbd className={cn('bw-kbd', className)} {...props} />
9
+ }
package/src/layout.tsx ADDED
@@ -0,0 +1,44 @@
1
+ import * as React from 'react'
2
+ import { cn } from './cn'
3
+
4
+ type DivProps = React.HTMLAttributes<HTMLDivElement>
5
+
6
+ export function Stack({ className, ...props }: DivProps) {
7
+ return <div className={cn('bw-stack', className)} {...props} />
8
+ }
9
+
10
+ export function Cluster({ className, ...props }: DivProps) {
11
+ return <div className={cn('bw-cluster', className)} {...props} />
12
+ }
13
+
14
+ export function Grid({ className, ...props }: DivProps) {
15
+ return <div className={cn('bw-grid', className)} {...props} />
16
+ }
17
+
18
+ export function Container({ className, ...props }: DivProps) {
19
+ return <div className={cn('bw-container', className)} {...props} />
20
+ }
21
+
22
+ export function Centre({ className, ...props }: DivProps) {
23
+ return <div className={cn('bw-centre', className)} {...props} />
24
+ }
25
+
26
+ export function Divider({
27
+ className,
28
+ ...props
29
+ }: React.HTMLAttributes<HTMLHRElement>) {
30
+ return <hr className={cn('bw-divider', className)} {...props} />
31
+ }
32
+
33
+ export function SkipLink({
34
+ href = '#main',
35
+ className,
36
+ children = 'Skip to content',
37
+ ...props
38
+ }: React.AnchorHTMLAttributes<HTMLAnchorElement>) {
39
+ return (
40
+ <a href={href} className={cn('bw-skip-link', className)} {...props}>
41
+ {children}
42
+ </a>
43
+ )
44
+ }
package/src/modal.tsx ADDED
@@ -0,0 +1,70 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { cn } from './cn'
5
+
6
+ export type ModalProps = {
7
+ open?: boolean
8
+ onOpenChange?: (open: boolean) => void
9
+ title: string
10
+ children: React.ReactNode
11
+ footer?: React.ReactNode
12
+ size?: 'sm' | 'md' | 'lg' | 'full'
13
+ className?: string
14
+ }
15
+
16
+ export function Modal({
17
+ open = false,
18
+ onOpenChange,
19
+ title,
20
+ children,
21
+ footer,
22
+ size = 'md',
23
+ className,
24
+ }: ModalProps) {
25
+ const titleId = React.useId()
26
+ React.useEffect(() => {
27
+ if (!open) return
28
+ const onKey = (e: KeyboardEvent) => {
29
+ if (e.key === 'Escape') onOpenChange?.(false)
30
+ }
31
+ document.addEventListener('keydown', onKey)
32
+ return () => document.removeEventListener('keydown', onKey)
33
+ }, [open, onOpenChange])
34
+
35
+ return (
36
+ <div
37
+ className={cn('bw-modal', `bw-modal--${size}`, open && 'bw-modal--open', className)}
38
+ {...(open ? { 'data-bw-open': '' } : {})}
39
+ role="presentation"
40
+ >
41
+ <div
42
+ className="bw-modal__scrim"
43
+ aria-hidden="true"
44
+ onClick={() => onOpenChange?.(false)}
45
+ />
46
+ <div
47
+ role="dialog"
48
+ aria-modal="true"
49
+ aria-labelledby={titleId}
50
+ className="bw-modal__panel"
51
+ >
52
+ <header className="bw-modal__header">
53
+ <h2 className="bw-modal__title" id={titleId}>
54
+ {title}
55
+ </h2>
56
+ <button
57
+ type="button"
58
+ className="bw-modal__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only"
59
+ aria-label="Close"
60
+ onClick={() => onOpenChange?.(false)}
61
+ >
62
+ x
63
+ </button>
64
+ </header>
65
+ <div className="bw-modal__body">{children}</div>
66
+ {footer ? <footer className="bw-modal__footer">{footer}</footer> : null}
67
+ </div>
68
+ </div>
69
+ )
70
+ }
package/src/pages.tsx ADDED
@@ -0,0 +1,361 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { Button, ButtonLink } from './button'
5
+ import { Card } from './card'
6
+ import { ThemeToggle } from './chrome'
7
+ import { Combobox } from './combobox'
8
+ import { DatePicker, DateRangePicker } from './date-picker'
9
+ import {
10
+ Checkbox,
11
+ Field,
12
+ Form,
13
+ FormActions,
14
+ Hint,
15
+ Input,
16
+ Label,
17
+ Textarea,
18
+ TimeInput,
19
+ } from './form'
20
+ import { Cluster, SkipLink, Stack } from './layout'
21
+
22
+ export type NavLink = { href: string; label: string }
23
+
24
+ export type HomepageProps = {
25
+ brand?: string
26
+ eyebrow?: string
27
+ title?: string
28
+ description?: string
29
+ primaryCta?: NavLink
30
+ secondaryCta?: NavLink
31
+ nav?: NavLink[]
32
+ features?: Array<{ title: string; body: string }>
33
+ closingTitle?: string
34
+ closingBody?: string
35
+ closingCta?: NavLink
36
+ footer?: string
37
+ }
38
+
39
+ const DEFAULT_FEATURES = [
40
+ {
41
+ title: 'Tokens',
42
+ body: 'One --bw-* source for colour, type, space, and dark mode.',
43
+ },
44
+ {
45
+ title: 'Components',
46
+ body: 'Library chrome with states, accessibility, and stack adapters.',
47
+ },
48
+ {
49
+ title: 'Gallery',
50
+ body: 'Copy-own pages for homepage, landing, forms, and app shells.',
51
+ },
52
+ ]
53
+
54
+ export function Homepage({
55
+ brand = 'Brickwork',
56
+ eyebrow = 'UI product gallery',
57
+ title = 'Beautiful interfaces, out of the box',
58
+ description = 'Install a Brickwork delivery, copy a gallery template, brand with tokens, ship.',
59
+ primaryCta = { href: '/gallery/forms', label: 'Get started' },
60
+ secondaryCta = { href: '/gallery/landing', label: 'See landing' },
61
+ nav,
62
+ features = DEFAULT_FEATURES,
63
+ closingTitle = 'Ready when you are',
64
+ closingBody = 'HTML, React, Vue, and Django consume the same bw-* contract.',
65
+ closingCta = { href: '/gallery/landing', label: 'View landing template' },
66
+ footer = 'Brickwork gallery. Copy and own.',
67
+ }: HomepageProps) {
68
+ const links = nav ?? [
69
+ { href: '#features', label: 'Features' },
70
+ { href: '/gallery/landing', label: 'Landing' },
71
+ { href: '/gallery/forms', label: 'Contact' },
72
+ ]
73
+ return (
74
+ <>
75
+ <SkipLink />
76
+ <header className="bw-shell-marketing__header">
77
+ <Cluster
78
+ style={{
79
+ justifyContent: 'space-between',
80
+ alignItems: 'center',
81
+ padding: 'var(--bw-space-4) var(--bw-space-6)',
82
+ }}
83
+ >
84
+ <strong className="bw-text-title-md">{brand}</strong>
85
+ <nav className="bw-cluster" aria-label="Primary" style={{ gap: 'var(--bw-space-4)' }}>
86
+ {links.map((item) => (
87
+ <ButtonLink
88
+ key={item.href}
89
+ href={item.href}
90
+ variant={item.href.includes('forms') ? 'primary' : 'ghost'}
91
+ >
92
+ {item.label}
93
+ </ButtonLink>
94
+ ))}
95
+ <ThemeToggle />
96
+ </nav>
97
+ </Cluster>
98
+ </header>
99
+ <main id="main">
100
+ <section className="bw-hero" style={{ padding: 'var(--bw-space-12) var(--bw-space-6)' }}>
101
+ <Stack style={{ maxWidth: '40rem', gap: 'var(--bw-space-4)' }}>
102
+ <p className="bw-text-label-md" style={{ color: 'var(--bw-color-fg-muted)' }}>
103
+ {eyebrow}
104
+ </p>
105
+ <h1 className="bw-text-display-md">{title}</h1>
106
+ <p className="bw-text-body-lg" style={{ color: 'var(--bw-color-fg-muted)' }}>
107
+ {description}
108
+ </p>
109
+ <Cluster style={{ gap: 'var(--bw-space-3)' }}>
110
+ <ButtonLink href={primaryCta.href} variant="primary" size="lg">
111
+ {primaryCta.label}
112
+ </ButtonLink>
113
+ <ButtonLink href={secondaryCta.href} variant="ghost" size="lg">
114
+ {secondaryCta.label}
115
+ </ButtonLink>
116
+ </Cluster>
117
+ </Stack>
118
+ </section>
119
+ <section
120
+ id="features"
121
+ style={{
122
+ padding: 'var(--bw-space-10) var(--bw-space-6)',
123
+ background: 'var(--bw-color-surface-2)',
124
+ }}
125
+ >
126
+ <div
127
+ className="bw-grid"
128
+ style={{
129
+ display: 'grid',
130
+ gap: 'var(--bw-space-6)',
131
+ gridTemplateColumns: 'repeat(auto-fit, minmax(14rem, 1fr))',
132
+ }}
133
+ >
134
+ {features.map((feature) => (
135
+ <article key={feature.title} className="bw-card">
136
+ <h2 className="bw-text-title-sm">{feature.title}</h2>
137
+ <p className="bw-text-body-md" style={{ color: 'var(--bw-color-fg-muted)' }}>
138
+ {feature.body}
139
+ </p>
140
+ </article>
141
+ ))}
142
+ </div>
143
+ </section>
144
+ <section style={{ padding: 'var(--bw-space-10) var(--bw-space-6)' }}>
145
+ <Card
146
+ style={{
147
+ display: 'flex',
148
+ flexWrap: 'wrap',
149
+ gap: 'var(--bw-space-4)',
150
+ alignItems: 'center',
151
+ justifyContent: 'space-between',
152
+ }}
153
+ >
154
+ <div>
155
+ <h2 className="bw-text-title-md">{closingTitle}</h2>
156
+ <p className="bw-text-body-md" style={{ color: 'var(--bw-color-fg-muted)' }}>
157
+ {closingBody}
158
+ </p>
159
+ </div>
160
+ <ButtonLink href={closingCta.href} variant="primary">
161
+ {closingCta.label}
162
+ </ButtonLink>
163
+ </Card>
164
+ </section>
165
+ </main>
166
+ <footer
167
+ style={{
168
+ padding: 'var(--bw-space-8) var(--bw-space-6)',
169
+ borderTop: '1px solid var(--bw-color-border)',
170
+ }}
171
+ >
172
+ <p className="bw-text-body-sm" style={{ color: 'var(--bw-color-fg-muted)' }}>
173
+ {footer}
174
+ </p>
175
+ </footer>
176
+ </>
177
+ )
178
+ }
179
+
180
+ export type LandingProps = {
181
+ brand?: string
182
+ title?: string
183
+ description?: string
184
+ primaryCta?: NavLink
185
+ secondaryCta?: NavLink
186
+ benefits?: string[]
187
+ }
188
+
189
+ export function Landing({
190
+ brand = 'Brickwork',
191
+ title = 'Ship your next interface this afternoon',
192
+ description = 'One primary offer. One CTA. Gallery landings stay focused on conversion.',
193
+ primaryCta = { href: '/gallery/forms', label: 'Start free' },
194
+ secondaryCta = { href: '/gallery/homepage', label: 'Back to homepage' },
195
+ benefits = [
196
+ 'Tokens and components share one visual contract.',
197
+ 'HTML, React, Vue, and Django consume the same bw-* chrome.',
198
+ 'L1 recolour brands the whole page without forks.',
199
+ ],
200
+ }: LandingProps) {
201
+ return (
202
+ <>
203
+ <SkipLink />
204
+ <header style={{ padding: 'var(--bw-space-4) var(--bw-space-6)' }}>
205
+ <Cluster style={{ justifyContent: 'space-between' }}>
206
+ <strong className="bw-text-title-md">{brand}</strong>
207
+ <ThemeToggle />
208
+ </Cluster>
209
+ </header>
210
+ <main id="main" style={{ padding: 'var(--bw-space-12) var(--bw-space-6)' }}>
211
+ <Stack
212
+ className="bw-centre"
213
+ style={{
214
+ maxWidth: '36rem',
215
+ marginInline: 'auto',
216
+ textAlign: 'center',
217
+ gap: 'var(--bw-space-5)',
218
+ }}
219
+ >
220
+ <h1 className="bw-text-display-sm">{title}</h1>
221
+ <p className="bw-text-body-lg" style={{ color: 'var(--bw-color-fg-muted)' }}>
222
+ {description}
223
+ </p>
224
+ <Cluster style={{ justifyContent: 'center', gap: 'var(--bw-space-3)' }}>
225
+ <ButtonLink href={primaryCta.href} variant="primary" size="lg">
226
+ {primaryCta.label}
227
+ </ButtonLink>
228
+ <ButtonLink href={secondaryCta.href} variant="ghost" size="lg">
229
+ {secondaryCta.label}
230
+ </ButtonLink>
231
+ </Cluster>
232
+ <ul
233
+ className="bw-stack"
234
+ style={{
235
+ textAlign: 'left',
236
+ gap: 'var(--bw-space-3)',
237
+ marginTop: 'var(--bw-space-6)',
238
+ }}
239
+ >
240
+ {benefits.map((item) => (
241
+ <li key={item} className="bw-card">
242
+ {item}
243
+ </li>
244
+ ))}
245
+ </ul>
246
+ </Stack>
247
+ </main>
248
+ </>
249
+ )
250
+ }
251
+
252
+ export type ContactFormProps = {
253
+ title?: string
254
+ description?: React.ReactNode
255
+ onSubmit?: React.FormEventHandler<HTMLFormElement>
256
+ topics?: Array<{ value: string; label: string }>
257
+ }
258
+
259
+ export function ContactForm({
260
+ title = 'Contact',
261
+ description = 'Gallery form recipe with searchable topic, dates, and kit chrome.',
262
+ onSubmit,
263
+ topics = [
264
+ { value: 'product', label: 'Product question' },
265
+ { value: 'partnership', label: 'Partnership' },
266
+ { value: 'support', label: 'Support' },
267
+ ],
268
+ }: ContactFormProps) {
269
+ return (
270
+ <>
271
+ <SkipLink />
272
+ <main
273
+ id="main"
274
+ style={{
275
+ padding: 'var(--bw-space-10) var(--bw-space-6)',
276
+ maxWidth: '32rem',
277
+ marginInline: 'auto',
278
+ }}
279
+ >
280
+ <Stack style={{ gap: 'var(--bw-space-6)' }}>
281
+ <Stack style={{ gap: 'var(--bw-space-2)' }}>
282
+ <h1 className="bw-text-title-lg">{title}</h1>
283
+ <p className="bw-text-body-md" style={{ color: 'var(--bw-color-fg-muted)' }}>
284
+ {description}
285
+ </p>
286
+ </Stack>
287
+ <Form
288
+ onSubmit={(e) => {
289
+ if (onSubmit) {
290
+ onSubmit(e)
291
+ return
292
+ }
293
+ e.preventDefault()
294
+ }}
295
+ style={{ gap: 'var(--bw-space-4)' }}
296
+ >
297
+ <Field>
298
+ <Label htmlFor="bw-contact-name">Name</Label>
299
+ <Input id="bw-contact-name" name="name" autoComplete="name" required />
300
+ </Field>
301
+ <Field>
302
+ <Label htmlFor="bw-contact-email">Email</Label>
303
+ <Input
304
+ id="bw-contact-email"
305
+ name="email"
306
+ type="email"
307
+ autoComplete="email"
308
+ required
309
+ />
310
+ <Hint>We only use this to reply.</Hint>
311
+ </Field>
312
+ <Field>
313
+ <Label htmlFor="bw-contact-topic">Topic</Label>
314
+ <Combobox
315
+ id="bw-contact-topic"
316
+ name="topic"
317
+ options={topics}
318
+ placeholder="Search topics"
319
+ />
320
+ </Field>
321
+ <Field>
322
+ <Label htmlFor="bw-contact-date">Preferred date</Label>
323
+ <DatePicker id="bw-contact-date" name="date" />
324
+ </Field>
325
+ <Field>
326
+ <Label htmlFor="bw-contact-from">Availability</Label>
327
+ <DateRangePicker
328
+ startId="bw-contact-from"
329
+ endId="bw-contact-to"
330
+ startName="from"
331
+ endName="to"
332
+ />
333
+ </Field>
334
+ <Field>
335
+ <Label htmlFor="bw-contact-time">Call time</Label>
336
+ <TimeInput id="bw-contact-time" name="time" />
337
+ </Field>
338
+ <Field>
339
+ <Label htmlFor="bw-contact-message">Message</Label>
340
+ <Textarea id="bw-contact-message" name="message" rows={5} required />
341
+ </Field>
342
+ <Field>
343
+ <Cluster>
344
+ <Checkbox id="bw-contact-copy" name="copy" />
345
+ <Label htmlFor="bw-contact-copy">Send me a copy</Label>
346
+ </Cluster>
347
+ </Field>
348
+ <FormActions>
349
+ <Button type="submit" variant="primary">
350
+ Send message
351
+ </Button>
352
+ <ButtonLink href="/gallery/homepage" variant="ghost">
353
+ Cancel
354
+ </ButtonLink>
355
+ </FormActions>
356
+ </Form>
357
+ </Stack>
358
+ </main>
359
+ </>
360
+ )
361
+ }
package/src/toast.tsx ADDED
@@ -0,0 +1,84 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { cn } from './cn'
5
+
6
+ export type ToastVariant = 'default' | 'success' | 'warning' | 'danger' | 'info'
7
+
8
+ export type ToastItem = {
9
+ id: string
10
+ message: string
11
+ variant?: ToastVariant
12
+ }
13
+
14
+ type ToastContextValue = {
15
+ toasts: ToastItem[]
16
+ push: (message: string, variant?: ToastVariant) => void
17
+ dismiss: (id: string) => void
18
+ }
19
+
20
+ const ToastContext = React.createContext<ToastContextValue | null>(null)
21
+
22
+ export function ToastProvider({
23
+ children,
24
+ placement = 'top-end',
25
+ }: {
26
+ children: React.ReactNode
27
+ placement?: 'top-end' | 'top-start' | 'bottom-end' | 'bottom-start'
28
+ }) {
29
+ const [toasts, setToasts] = React.useState<ToastItem[]>([])
30
+
31
+ const dismiss = React.useCallback((id: string) => {
32
+ setToasts((list) => list.filter((t) => t.id !== id))
33
+ }, [])
34
+
35
+ const push = React.useCallback(
36
+ (message: string, variant: ToastVariant = 'success') => {
37
+ const id = `toast-${Date.now()}-${Math.random().toString(16).slice(2)}`
38
+ setToasts((list) => [{ id, message, variant }, ...list])
39
+ window.setTimeout(() => dismiss(id), 4000)
40
+ },
41
+ [dismiss],
42
+ )
43
+
44
+ return (
45
+ <ToastContext.Provider value={{ toasts, push, dismiss }}>
46
+ {children}
47
+ <div
48
+ id="bw-toast-region"
49
+ className={cn('bw-toast-region', `bw-toast-region--${placement}`)}
50
+ aria-live="polite"
51
+ >
52
+ {toasts.map((toast) => (
53
+ <div
54
+ key={toast.id}
55
+ className={cn(
56
+ 'bw-toast',
57
+ toast.variant && toast.variant !== 'default' && `bw-toast--${toast.variant}`,
58
+ )}
59
+ data-bw-toast=""
60
+ data-bw-visible=""
61
+ >
62
+ <p className="bw-toast__message">{toast.message}</p>
63
+ <button
64
+ type="button"
65
+ className="bw-toast__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only"
66
+ aria-label="Dismiss"
67
+ onClick={() => dismiss(toast.id)}
68
+ >
69
+ x
70
+ </button>
71
+ </div>
72
+ ))}
73
+ </div>
74
+ </ToastContext.Provider>
75
+ )
76
+ }
77
+
78
+ export function useToast() {
79
+ const ctx = React.useContext(ToastContext)
80
+ if (!ctx) {
81
+ throw new Error('useToast must be used within ToastProvider')
82
+ }
83
+ return ctx
84
+ }