@bwui/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +36 -2
- package/dist/alert.d.ts +8 -0
- package/dist/alert.js +11 -0
- package/dist/badge.d.ts +6 -0
- package/dist/badge.js +5 -0
- package/dist/button.d.ts +16 -0
- package/dist/button.js +12 -0
- package/dist/card.d.ts +9 -0
- package/dist/card.js +20 -0
- package/dist/chrome.d.ts +59 -0
- package/dist/chrome.js +75 -0
- package/dist/cn.d.ts +6 -0
- package/dist/cn.js +8 -0
- package/dist/combobox.d.ts +20 -0
- package/dist/combobox.js +70 -0
- package/dist/command.d.ts +16 -0
- package/dist/command.js +74 -0
- package/dist/data-table.d.ts +17 -0
- package/dist/data-table.js +17 -0
- package/dist/date-picker.d.ts +30 -0
- package/dist/date-picker.js +146 -0
- package/dist/form.d.ts +31 -0
- package/dist/form.js +55 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +17 -0
- package/dist/kbd.d.ts +2 -0
- package/dist/kbd.js +5 -0
- package/dist/layout.d.ts +10 -0
- package/dist/layout.js +23 -0
- package/dist/modal.d.ts +11 -0
- package/dist/modal.js +18 -0
- package/dist/pages.d.ts +42 -0
- package/dist/pages.js +84 -0
- package/dist/toast.d.ts +18 -0
- package/dist/toast.js +24 -0
- package/package.json +43 -3
- package/src/alert.tsx +36 -0
- package/src/badge.tsx +24 -0
- package/src/button.tsx +66 -0
- package/src/card.tsx +34 -0
- package/src/chrome.tsx +263 -0
- package/src/cn.ts +8 -0
- package/src/combobox.tsx +162 -0
- package/src/command.tsx +145 -0
- package/src/data-table.tsx +114 -0
- package/src/date-picker.tsx +357 -0
- package/src/form.tsx +201 -0
- package/src/index.ts +90 -0
- package/src/kbd.tsx +9 -0
- package/src/layout.tsx +44 -0
- package/src/modal.tsx +70 -0
- package/src/pages.tsx +361 -0
- package/src/toast.tsx +84 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
import { Input } from './form';
|
|
6
|
+
const MONTHS = [
|
|
7
|
+
'January',
|
|
8
|
+
'February',
|
|
9
|
+
'March',
|
|
10
|
+
'April',
|
|
11
|
+
'May',
|
|
12
|
+
'June',
|
|
13
|
+
'July',
|
|
14
|
+
'August',
|
|
15
|
+
'September',
|
|
16
|
+
'October',
|
|
17
|
+
'November',
|
|
18
|
+
'December',
|
|
19
|
+
];
|
|
20
|
+
const DOW = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
|
|
21
|
+
function parseISO(s) {
|
|
22
|
+
if (!s)
|
|
23
|
+
return null;
|
|
24
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
25
|
+
if (!m)
|
|
26
|
+
return null;
|
|
27
|
+
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
28
|
+
}
|
|
29
|
+
function toISO(d) {
|
|
30
|
+
const y = d.getFullYear();
|
|
31
|
+
const m = String(d.getMonth() + 1).padStart(2, '0');
|
|
32
|
+
const day = String(d.getDate()).padStart(2, '0');
|
|
33
|
+
return `${y}-${m}-${day}`;
|
|
34
|
+
}
|
|
35
|
+
function sameDay(a, b) {
|
|
36
|
+
return Boolean(a &&
|
|
37
|
+
b &&
|
|
38
|
+
a.getFullYear() === b.getFullYear() &&
|
|
39
|
+
a.getMonth() === b.getMonth() &&
|
|
40
|
+
a.getDate() === b.getDate());
|
|
41
|
+
}
|
|
42
|
+
function daysFor(view) {
|
|
43
|
+
const first = new Date(view.getFullYear(), view.getMonth(), 1);
|
|
44
|
+
const startDow = (first.getDay() + 6) % 7;
|
|
45
|
+
const count = new Date(view.getFullYear(), view.getMonth() + 1, 0).getDate();
|
|
46
|
+
const cells = Array.from({ length: startDow }, () => null);
|
|
47
|
+
for (let day = 1; day <= count; day += 1) {
|
|
48
|
+
cells.push(new Date(view.getFullYear(), view.getMonth(), day));
|
|
49
|
+
}
|
|
50
|
+
return cells;
|
|
51
|
+
}
|
|
52
|
+
function Calendar({ view, onViewChange, selected, rangeStart, rangeEnd, onSelect, }) {
|
|
53
|
+
return (_jsxs("div", { className: "bw-calendar", children: [_jsxs("div", { className: "bw-calendar__nav", children: [_jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", "data-bw-cal-prev": "", "aria-label": "Previous month", onClick: () => onViewChange(new Date(view.getFullYear(), view.getMonth() - 1, 1)), children: "Prev" }), _jsxs("p", { className: "bw-calendar__title", children: [MONTHS[view.getMonth()], " ", view.getFullYear()] }), _jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", "data-bw-cal-next": "", "aria-label": "Next month", onClick: () => onViewChange(new Date(view.getFullYear(), view.getMonth() + 1, 1)), children: "Next" })] }), _jsxs("div", { className: "bw-calendar__grid", children: [DOW.map((d) => (_jsx("div", { className: "bw-calendar__dow", children: d }, d))), daysFor(view).map((date, i) => {
|
|
54
|
+
if (!date)
|
|
55
|
+
return _jsx("div", {}, `blank-${i}`);
|
|
56
|
+
const inRange = Boolean(rangeStart &&
|
|
57
|
+
rangeEnd &&
|
|
58
|
+
date > rangeStart &&
|
|
59
|
+
date < rangeEnd);
|
|
60
|
+
const isSelected = sameDay(date, selected) ||
|
|
61
|
+
sameDay(date, rangeStart ?? null) ||
|
|
62
|
+
sameDay(date, rangeEnd ?? null);
|
|
63
|
+
return (_jsx("button", { type: "button", className: "bw-calendar__day", "aria-label": toISO(date), "aria-selected": isSelected, ...(inRange ? { 'data-bw-in-range': '' } : {}), onClick: () => onSelect(date), children: date.getDate() }, toISO(date)));
|
|
64
|
+
})] })] }));
|
|
65
|
+
}
|
|
66
|
+
export function DatePicker({ id, name, value, defaultValue = '', onValueChange, placeholder = 'YYYY-MM-DD', disabled, required, className, }) {
|
|
67
|
+
const [open, setOpen] = React.useState(false);
|
|
68
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
|
|
69
|
+
const selected = value ?? uncontrolled;
|
|
70
|
+
const parsed = parseISO(selected) || new Date();
|
|
71
|
+
const [view, setView] = React.useState(new Date(parsed.getFullYear(), parsed.getMonth(), 1));
|
|
72
|
+
const rootRef = React.useRef(null);
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
function onPointer(e) {
|
|
75
|
+
if (!rootRef.current?.contains(e.target))
|
|
76
|
+
setOpen(false);
|
|
77
|
+
}
|
|
78
|
+
function onKey(e) {
|
|
79
|
+
if (e.key === 'Escape')
|
|
80
|
+
setOpen(false);
|
|
81
|
+
}
|
|
82
|
+
document.addEventListener('pointerdown', onPointer);
|
|
83
|
+
document.addEventListener('keydown', onKey);
|
|
84
|
+
return () => {
|
|
85
|
+
document.removeEventListener('pointerdown', onPointer);
|
|
86
|
+
document.removeEventListener('keydown', onKey);
|
|
87
|
+
};
|
|
88
|
+
}, []);
|
|
89
|
+
function commit(next) {
|
|
90
|
+
if (value === undefined)
|
|
91
|
+
setUncontrolled(next);
|
|
92
|
+
onValueChange?.(next);
|
|
93
|
+
}
|
|
94
|
+
return (_jsxs("div", { ref: rootRef, className: cn('bw-date-picker-chrome', className), children: [_jsxs("div", { className: "bw-date-picker-chrome__field", children: [_jsx(Input, { id: id, name: name, value: selected, required: required, disabled: disabled, placeholder: placeholder, autoComplete: "off", "data-bw-date-input": "", onChange: (e) => commit(e.target.value), onFocus: () => setOpen(true) }), _jsx("button", { type: "button", className: "bw-date-picker-chrome__trigger", "aria-label": "Open calendar", disabled: disabled, onClick: () => setOpen((v) => !v), children: "Cal" })] }), _jsx("div", { className: "bw-date-picker-chrome__panel", hidden: !open, children: _jsx(Calendar, { view: view, onViewChange: setView, selected: parseISO(selected), onSelect: (date) => {
|
|
95
|
+
commit(toISO(date));
|
|
96
|
+
setOpen(false);
|
|
97
|
+
} }) })] }));
|
|
98
|
+
}
|
|
99
|
+
export function DateRangePicker({ startId, endId, startName, endName, startValue, endValue, defaultStartValue = '', defaultEndValue = '', onValueChange, disabled, className, }) {
|
|
100
|
+
const [open, setOpen] = React.useState(false);
|
|
101
|
+
const [start, setStart] = React.useState(defaultStartValue);
|
|
102
|
+
const [end, setEnd] = React.useState(defaultEndValue);
|
|
103
|
+
const startSelected = startValue ?? start;
|
|
104
|
+
const endSelected = endValue ?? end;
|
|
105
|
+
const parsed = parseISO(startSelected) || new Date();
|
|
106
|
+
const [view, setView] = React.useState(new Date(parsed.getFullYear(), parsed.getMonth(), 1));
|
|
107
|
+
const rootRef = React.useRef(null);
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
function onPointer(e) {
|
|
110
|
+
if (!rootRef.current?.contains(e.target))
|
|
111
|
+
setOpen(false);
|
|
112
|
+
}
|
|
113
|
+
function onKey(e) {
|
|
114
|
+
if (e.key === 'Escape')
|
|
115
|
+
setOpen(false);
|
|
116
|
+
}
|
|
117
|
+
document.addEventListener('pointerdown', onPointer);
|
|
118
|
+
document.addEventListener('keydown', onKey);
|
|
119
|
+
return () => {
|
|
120
|
+
document.removeEventListener('pointerdown', onPointer);
|
|
121
|
+
document.removeEventListener('keydown', onKey);
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
124
|
+
function emit(nextStart, nextEnd) {
|
|
125
|
+
if (startValue === undefined)
|
|
126
|
+
setStart(nextStart);
|
|
127
|
+
if (endValue === undefined)
|
|
128
|
+
setEnd(nextEnd);
|
|
129
|
+
onValueChange?.({ start: nextStart, end: nextEnd });
|
|
130
|
+
}
|
|
131
|
+
return (_jsxs("div", { ref: rootRef, className: cn('bw-date-picker-chrome', className), "data-bw-range": "true", children: [_jsxs("div", { className: "bw-date-picker-chrome__range", children: [_jsx(Input, { id: startId, name: startName, value: startSelected, disabled: disabled, placeholder: "From", autoComplete: "off", "data-bw-date-input": "", onChange: (e) => emit(e.target.value, endSelected), onFocus: () => setOpen(true) }), _jsx("span", { className: "bw-date-picker-chrome__separator", children: "to" }), _jsx(Input, { id: endId, name: endName, value: endSelected, disabled: disabled, placeholder: "To", autoComplete: "off", "data-bw-date-end": "", onChange: (e) => emit(startSelected, e.target.value), onFocus: () => setOpen(true) }), _jsx("button", { type: "button", className: "bw-date-picker-chrome__trigger", "aria-label": "Open range calendar", disabled: disabled, onClick: () => setOpen((v) => !v), children: "Cal" })] }), _jsx("div", { className: "bw-date-picker-chrome__panel", hidden: !open, children: _jsx(Calendar, { view: view, onViewChange: setView, rangeStart: parseISO(startSelected), rangeEnd: parseISO(endSelected), onSelect: (date) => {
|
|
132
|
+
const currentStart = parseISO(startSelected);
|
|
133
|
+
const currentEnd = parseISO(endSelected);
|
|
134
|
+
if (!currentStart || currentEnd) {
|
|
135
|
+
emit(toISO(date), '');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (date < currentStart) {
|
|
139
|
+
emit(toISO(date), toISO(currentStart));
|
|
140
|
+
setOpen(false);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
emit(toISO(currentStart), toISO(date));
|
|
144
|
+
setOpen(false);
|
|
145
|
+
} }) })] }));
|
|
146
|
+
}
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
3
|
+
export declare const Textarea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
4
|
+
export declare const Select: React.ForwardRefExoticComponent<React.SelectHTMLAttributes<HTMLSelectElement> & React.RefAttributes<HTMLSelectElement>>;
|
|
5
|
+
export declare const Form: React.ForwardRefExoticComponent<React.FormHTMLAttributes<HTMLFormElement> & React.RefAttributes<HTMLFormElement>>;
|
|
6
|
+
export declare function Field({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
7
|
+
export declare function Label({ className, ...props }: React.LabelHTMLAttributes<HTMLLabelElement>): React.JSX.Element;
|
|
8
|
+
export declare function Hint({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>): React.JSX.Element;
|
|
9
|
+
export declare function FieldError({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>): React.JSX.Element;
|
|
10
|
+
export declare function FormErrors({ title, errors, className, }: {
|
|
11
|
+
title?: string;
|
|
12
|
+
errors: string[];
|
|
13
|
+
className?: string;
|
|
14
|
+
}): React.JSX.Element | null;
|
|
15
|
+
export declare function FormActions({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
16
|
+
export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLInputElement>>;
|
|
20
|
+
export declare const Checkbox: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
21
|
+
export declare const Radio: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
22
|
+
export declare const TimeInput: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
23
|
+
export declare const DateTimeInput: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
24
|
+
export type PasswordFieldProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> & {
|
|
25
|
+
revealLabel?: string;
|
|
26
|
+
hideLabel?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const PasswordField: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & {
|
|
29
|
+
revealLabel?: string;
|
|
30
|
+
hideLabel?: string;
|
|
31
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
package/dist/form.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
export const Input = React.forwardRef(function Input({ className, ...props }, ref) {
|
|
6
|
+
return _jsx("input", { ref: ref, className: cn('bw-input', className), ...props });
|
|
7
|
+
});
|
|
8
|
+
export const Textarea = React.forwardRef(function Textarea({ className, ...props }, ref) {
|
|
9
|
+
return (_jsx("textarea", { ref: ref, className: cn('bw-textarea', className), ...props }));
|
|
10
|
+
});
|
|
11
|
+
export const Select = React.forwardRef(function Select({ className, ...props }, ref) {
|
|
12
|
+
return _jsx("select", { ref: ref, className: cn('bw-select', className), ...props });
|
|
13
|
+
});
|
|
14
|
+
export const Form = React.forwardRef(function Form({ className, ...props }, ref) {
|
|
15
|
+
return _jsx("form", { ref: ref, className: cn('bw-form', 'bw-stack', className), ...props });
|
|
16
|
+
});
|
|
17
|
+
export function Field({ className, ...props }) {
|
|
18
|
+
return _jsx("div", { className: cn('bw-field', className), ...props });
|
|
19
|
+
}
|
|
20
|
+
export function Label({ className, ...props }) {
|
|
21
|
+
return _jsx("label", { className: cn('bw-field__label', className), ...props });
|
|
22
|
+
}
|
|
23
|
+
export function Hint({ className, ...props }) {
|
|
24
|
+
return _jsx("p", { className: cn('bw-field__hint', className), ...props });
|
|
25
|
+
}
|
|
26
|
+
export function FieldError({ className, ...props }) {
|
|
27
|
+
return _jsx("p", { className: cn('bw-field__error', className), ...props });
|
|
28
|
+
}
|
|
29
|
+
export function FormErrors({ title = 'Please fix the following', errors, className, }) {
|
|
30
|
+
if (errors.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
return (_jsxs("div", { className: cn('bw-form-errors', className), role: "alert", children: [_jsx("p", { className: "bw-form-errors__title", children: title }), _jsx("ul", { className: "bw-form-errors__list", children: errors.map((item) => (_jsx("li", { children: item }, item))) })] }));
|
|
33
|
+
}
|
|
34
|
+
export function FormActions({ className, ...props }) {
|
|
35
|
+
return _jsx("div", { className: cn('bw-form__actions', 'bw-cluster', className), ...props });
|
|
36
|
+
}
|
|
37
|
+
export const Switch = React.forwardRef(function Switch({ className, ...props }, ref) {
|
|
38
|
+
return (_jsxs("span", { className: cn('bw-switch', className), children: [_jsx("input", { ref: ref, type: "checkbox", ...props }), _jsx("span", { className: "bw-switch__track", "aria-hidden": "true" }), _jsx("span", { className: "bw-switch__thumb", "aria-hidden": "true" })] }));
|
|
39
|
+
});
|
|
40
|
+
export const Checkbox = React.forwardRef(function Checkbox({ className, ...props }, ref) {
|
|
41
|
+
return (_jsx("input", { ref: ref, type: "checkbox", className: cn('bw-checkbox', className), ...props }));
|
|
42
|
+
});
|
|
43
|
+
export const Radio = React.forwardRef(function Radio({ className, ...props }, ref) {
|
|
44
|
+
return (_jsx("input", { ref: ref, type: "radio", className: cn('bw-radio', className), ...props }));
|
|
45
|
+
});
|
|
46
|
+
export const TimeInput = React.forwardRef(function TimeInput({ className, ...props }, ref) {
|
|
47
|
+
return (_jsx("input", { ref: ref, type: "time", className: cn('bw-input', className), ...props }));
|
|
48
|
+
});
|
|
49
|
+
export const DateTimeInput = React.forwardRef(function DateTimeInput({ className, ...props }, ref) {
|
|
50
|
+
return (_jsx("input", { ref: ref, type: "datetime-local", className: cn('bw-input', className), ...props }));
|
|
51
|
+
});
|
|
52
|
+
export const PasswordField = React.forwardRef(function PasswordField({ className, revealLabel = 'Show', hideLabel = 'Hide', id, ...props }, ref) {
|
|
53
|
+
const [visible, setVisible] = React.useState(false);
|
|
54
|
+
return (_jsxs("div", { className: "bw-password", children: [_jsx("input", { ref: ref, id: id, type: visible ? 'text' : 'password', className: cn('bw-input', className), ...props }), _jsx("button", { type: "button", className: "bw-password__toggle", "aria-pressed": visible, onClick: () => setVisible((v) => !v), children: visible ? hideLabel : revealLabel })] }));
|
|
55
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Button, ButtonLink } from './button';
|
|
2
|
+
export type { ButtonProps, ButtonLinkProps, ButtonVariant, ButtonSize } from './button';
|
|
3
|
+
export { Badge } from './badge';
|
|
4
|
+
export type { BadgeProps, BadgeVariant } from './badge';
|
|
5
|
+
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter, } from './card';
|
|
6
|
+
export { Alert, AlertTitle, AlertBody } from './alert';
|
|
7
|
+
export type { AlertProps, AlertVariant } from './alert';
|
|
8
|
+
export { Input, Textarea, Select, Field, Label, Hint, FieldError, FormErrors, Form, FormActions, Switch, Checkbox, Radio, TimeInput, DateTimeInput, PasswordField, } from './form';
|
|
9
|
+
export type { SwitchProps, PasswordFieldProps } from './form';
|
|
10
|
+
export { Combobox } from './combobox';
|
|
11
|
+
export type { ComboboxProps, ComboboxOption } from './combobox';
|
|
12
|
+
export { DatePicker, DateRangePicker } from './date-picker';
|
|
13
|
+
export type { DatePickerProps, DateRangePickerProps } from './date-picker';
|
|
14
|
+
export { Stack, Cluster, Grid, Container, Centre, Divider, SkipLink, } from './layout';
|
|
15
|
+
export { Tabs, TabList, Tab, TabPanel, ThemeToggle, EmptyState, Spinner, Progress, Skeleton, Avatar, Chip, Breadcrumbs, Pagination, } from './chrome';
|
|
16
|
+
export { ToastProvider, useToast } from './toast';
|
|
17
|
+
export type { ToastItem, ToastVariant } from './toast';
|
|
18
|
+
export { Homepage, Landing, ContactForm } from './pages';
|
|
19
|
+
export type { HomepageProps, LandingProps, ContactFormProps, NavLink } from './pages';
|
|
20
|
+
export { cn } from './cn';
|
|
21
|
+
export * as tokens from '@bwui/tokens';
|
|
22
|
+
export { Modal } from './modal';
|
|
23
|
+
export type { ModalProps } from './modal';
|
|
24
|
+
export { CommandPalette } from './command';
|
|
25
|
+
export type { CommandPaletteProps, CommandItem } from './command';
|
|
26
|
+
export { DataTable } from './data-table';
|
|
27
|
+
export type { DataTableProps, DataTableColumn } from './data-table';
|
|
28
|
+
export { Kbd } from './kbd';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { Button, ButtonLink } from './button';
|
|
2
|
+
export { Badge } from './badge';
|
|
3
|
+
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter, } from './card';
|
|
4
|
+
export { Alert, AlertTitle, AlertBody } from './alert';
|
|
5
|
+
export { Input, Textarea, Select, Field, Label, Hint, FieldError, FormErrors, Form, FormActions, Switch, Checkbox, Radio, TimeInput, DateTimeInput, PasswordField, } from './form';
|
|
6
|
+
export { Combobox } from './combobox';
|
|
7
|
+
export { DatePicker, DateRangePicker } from './date-picker';
|
|
8
|
+
export { Stack, Cluster, Grid, Container, Centre, Divider, SkipLink, } from './layout';
|
|
9
|
+
export { Tabs, TabList, Tab, TabPanel, ThemeToggle, EmptyState, Spinner, Progress, Skeleton, Avatar, Chip, Breadcrumbs, Pagination, } from './chrome';
|
|
10
|
+
export { ToastProvider, useToast } from './toast';
|
|
11
|
+
export { Homepage, Landing, ContactForm } from './pages';
|
|
12
|
+
export { cn } from './cn';
|
|
13
|
+
export * as tokens from '@bwui/tokens';
|
|
14
|
+
export { Modal } from './modal';
|
|
15
|
+
export { CommandPalette } from './command';
|
|
16
|
+
export { DataTable } from './data-table';
|
|
17
|
+
export { Kbd } from './kbd';
|
package/dist/kbd.d.ts
ADDED
package/dist/kbd.js
ADDED
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export declare function Stack({ className, ...props }: DivProps): React.JSX.Element;
|
|
4
|
+
export declare function Cluster({ className, ...props }: DivProps): React.JSX.Element;
|
|
5
|
+
export declare function Grid({ className, ...props }: DivProps): React.JSX.Element;
|
|
6
|
+
export declare function Container({ className, ...props }: DivProps): React.JSX.Element;
|
|
7
|
+
export declare function Centre({ className, ...props }: DivProps): React.JSX.Element;
|
|
8
|
+
export declare function Divider({ className, ...props }: React.HTMLAttributes<HTMLHRElement>): React.JSX.Element;
|
|
9
|
+
export declare function SkipLink({ href, className, children, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement>): React.JSX.Element;
|
|
10
|
+
export {};
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
export function Stack({ className, ...props }) {
|
|
4
|
+
return _jsx("div", { className: cn('bw-stack', className), ...props });
|
|
5
|
+
}
|
|
6
|
+
export function Cluster({ className, ...props }) {
|
|
7
|
+
return _jsx("div", { className: cn('bw-cluster', className), ...props });
|
|
8
|
+
}
|
|
9
|
+
export function Grid({ className, ...props }) {
|
|
10
|
+
return _jsx("div", { className: cn('bw-grid', className), ...props });
|
|
11
|
+
}
|
|
12
|
+
export function Container({ className, ...props }) {
|
|
13
|
+
return _jsx("div", { className: cn('bw-container', className), ...props });
|
|
14
|
+
}
|
|
15
|
+
export function Centre({ className, ...props }) {
|
|
16
|
+
return _jsx("div", { className: cn('bw-centre', className), ...props });
|
|
17
|
+
}
|
|
18
|
+
export function Divider({ className, ...props }) {
|
|
19
|
+
return _jsx("hr", { className: cn('bw-divider', className), ...props });
|
|
20
|
+
}
|
|
21
|
+
export function SkipLink({ href = '#main', className, children = 'Skip to content', ...props }) {
|
|
22
|
+
return (_jsx("a", { href: href, className: cn('bw-skip-link', className), ...props, children: children }));
|
|
23
|
+
}
|
package/dist/modal.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ModalProps = {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
onOpenChange?: (open: boolean) => void;
|
|
5
|
+
title: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
footer?: React.ReactNode;
|
|
8
|
+
size?: 'sm' | 'md' | 'lg' | 'full';
|
|
9
|
+
className?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function Modal({ open, onOpenChange, title, children, footer, size, className, }: ModalProps): React.JSX.Element;
|
package/dist/modal.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
export function Modal({ open = false, onOpenChange, title, children, footer, size = 'md', className, }) {
|
|
6
|
+
const titleId = React.useId();
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
if (!open)
|
|
9
|
+
return;
|
|
10
|
+
const onKey = (e) => {
|
|
11
|
+
if (e.key === 'Escape')
|
|
12
|
+
onOpenChange?.(false);
|
|
13
|
+
};
|
|
14
|
+
document.addEventListener('keydown', onKey);
|
|
15
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
16
|
+
}, [open, onOpenChange]);
|
|
17
|
+
return (_jsxs("div", { className: cn('bw-modal', `bw-modal--${size}`, open && 'bw-modal--open', className), ...(open ? { 'data-bw-open': '' } : {}), role: "presentation", children: [_jsx("div", { className: "bw-modal__scrim", "aria-hidden": "true", onClick: () => onOpenChange?.(false) }), _jsxs("div", { role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, className: "bw-modal__panel", children: [_jsxs("header", { className: "bw-modal__header", children: [_jsx("h2", { className: "bw-modal__title", id: titleId, children: title }), _jsx("button", { type: "button", className: "bw-modal__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only", "aria-label": "Close", onClick: () => onOpenChange?.(false), children: "x" })] }), _jsx("div", { className: "bw-modal__body", children: children }), footer ? _jsx("footer", { className: "bw-modal__footer", children: footer }) : null] })] }));
|
|
18
|
+
}
|
package/dist/pages.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type NavLink = {
|
|
3
|
+
href: string;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type HomepageProps = {
|
|
7
|
+
brand?: string;
|
|
8
|
+
eyebrow?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
primaryCta?: NavLink;
|
|
12
|
+
secondaryCta?: NavLink;
|
|
13
|
+
nav?: NavLink[];
|
|
14
|
+
features?: Array<{
|
|
15
|
+
title: string;
|
|
16
|
+
body: string;
|
|
17
|
+
}>;
|
|
18
|
+
closingTitle?: string;
|
|
19
|
+
closingBody?: string;
|
|
20
|
+
closingCta?: NavLink;
|
|
21
|
+
footer?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function Homepage({ brand, eyebrow, title, description, primaryCta, secondaryCta, nav, features, closingTitle, closingBody, closingCta, footer, }: HomepageProps): React.JSX.Element;
|
|
24
|
+
export type LandingProps = {
|
|
25
|
+
brand?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
primaryCta?: NavLink;
|
|
29
|
+
secondaryCta?: NavLink;
|
|
30
|
+
benefits?: string[];
|
|
31
|
+
};
|
|
32
|
+
export declare function Landing({ brand, title, description, primaryCta, secondaryCta, benefits, }: LandingProps): React.JSX.Element;
|
|
33
|
+
export type ContactFormProps = {
|
|
34
|
+
title?: string;
|
|
35
|
+
description?: React.ReactNode;
|
|
36
|
+
onSubmit?: React.FormEventHandler<HTMLFormElement>;
|
|
37
|
+
topics?: Array<{
|
|
38
|
+
value: string;
|
|
39
|
+
label: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
export declare function ContactForm({ title, description, onSubmit, topics, }: ContactFormProps): React.JSX.Element;
|
package/dist/pages.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Button, ButtonLink } from './button';
|
|
4
|
+
import { Card } from './card';
|
|
5
|
+
import { ThemeToggle } from './chrome';
|
|
6
|
+
import { Combobox } from './combobox';
|
|
7
|
+
import { DatePicker, DateRangePicker } from './date-picker';
|
|
8
|
+
import { Checkbox, Field, Form, FormActions, Hint, Input, Label, Textarea, TimeInput, } from './form';
|
|
9
|
+
import { Cluster, SkipLink, Stack } from './layout';
|
|
10
|
+
const DEFAULT_FEATURES = [
|
|
11
|
+
{
|
|
12
|
+
title: 'Tokens',
|
|
13
|
+
body: 'One --bw-* source for colour, type, space, and dark mode.',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'Components',
|
|
17
|
+
body: 'Library chrome with states, accessibility, and stack adapters.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: 'Gallery',
|
|
21
|
+
body: 'Copy-own pages for homepage, landing, forms, and app shells.',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
export function Homepage({ brand = 'Brickwork', eyebrow = 'UI product gallery', title = 'Beautiful interfaces, out of the box', description = 'Install a Brickwork delivery, copy a gallery template, brand with tokens, ship.', primaryCta = { href: '/gallery/forms', label: 'Get started' }, secondaryCta = { href: '/gallery/landing', label: 'See landing' }, nav, features = DEFAULT_FEATURES, closingTitle = 'Ready when you are', closingBody = 'HTML, React, Vue, and Django consume the same bw-* contract.', closingCta = { href: '/gallery/landing', label: 'View landing template' }, footer = 'Brickwork gallery. Copy and own.', }) {
|
|
25
|
+
const links = nav ?? [
|
|
26
|
+
{ href: '#features', label: 'Features' },
|
|
27
|
+
{ href: '/gallery/landing', label: 'Landing' },
|
|
28
|
+
{ href: '/gallery/forms', label: 'Contact' },
|
|
29
|
+
];
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx(SkipLink, {}), _jsx("header", { className: "bw-shell-marketing__header", children: _jsxs(Cluster, { style: {
|
|
31
|
+
justifyContent: 'space-between',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
padding: 'var(--bw-space-4) var(--bw-space-6)',
|
|
34
|
+
}, children: [_jsx("strong", { className: "bw-text-title-md", children: brand }), _jsxs("nav", { className: "bw-cluster", "aria-label": "Primary", style: { gap: 'var(--bw-space-4)' }, children: [links.map((item) => (_jsx(ButtonLink, { href: item.href, variant: item.href.includes('forms') ? 'primary' : 'ghost', children: item.label }, item.href))), _jsx(ThemeToggle, {})] })] }) }), _jsxs("main", { id: "main", children: [_jsx("section", { className: "bw-hero", style: { padding: 'var(--bw-space-12) var(--bw-space-6)' }, children: _jsxs(Stack, { style: { maxWidth: '40rem', gap: 'var(--bw-space-4)' }, children: [_jsx("p", { className: "bw-text-label-md", style: { color: 'var(--bw-color-fg-muted)' }, children: eyebrow }), _jsx("h1", { className: "bw-text-display-md", children: title }), _jsx("p", { className: "bw-text-body-lg", style: { color: 'var(--bw-color-fg-muted)' }, children: description }), _jsxs(Cluster, { style: { gap: 'var(--bw-space-3)' }, children: [_jsx(ButtonLink, { href: primaryCta.href, variant: "primary", size: "lg", children: primaryCta.label }), _jsx(ButtonLink, { href: secondaryCta.href, variant: "ghost", size: "lg", children: secondaryCta.label })] })] }) }), _jsx("section", { id: "features", style: {
|
|
35
|
+
padding: 'var(--bw-space-10) var(--bw-space-6)',
|
|
36
|
+
background: 'var(--bw-color-surface-2)',
|
|
37
|
+
}, children: _jsx("div", { className: "bw-grid", style: {
|
|
38
|
+
display: 'grid',
|
|
39
|
+
gap: 'var(--bw-space-6)',
|
|
40
|
+
gridTemplateColumns: 'repeat(auto-fit, minmax(14rem, 1fr))',
|
|
41
|
+
}, children: features.map((feature) => (_jsxs("article", { className: "bw-card", children: [_jsx("h2", { className: "bw-text-title-sm", children: feature.title }), _jsx("p", { className: "bw-text-body-md", style: { color: 'var(--bw-color-fg-muted)' }, children: feature.body })] }, feature.title))) }) }), _jsx("section", { style: { padding: 'var(--bw-space-10) var(--bw-space-6)' }, children: _jsxs(Card, { style: {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexWrap: 'wrap',
|
|
44
|
+
gap: 'var(--bw-space-4)',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
justifyContent: 'space-between',
|
|
47
|
+
}, children: [_jsxs("div", { children: [_jsx("h2", { className: "bw-text-title-md", children: closingTitle }), _jsx("p", { className: "bw-text-body-md", style: { color: 'var(--bw-color-fg-muted)' }, children: closingBody })] }), _jsx(ButtonLink, { href: closingCta.href, variant: "primary", children: closingCta.label })] }) })] }), _jsx("footer", { style: {
|
|
48
|
+
padding: 'var(--bw-space-8) var(--bw-space-6)',
|
|
49
|
+
borderTop: '1px solid var(--bw-color-border)',
|
|
50
|
+
}, children: _jsx("p", { className: "bw-text-body-sm", style: { color: 'var(--bw-color-fg-muted)' }, children: footer }) })] }));
|
|
51
|
+
}
|
|
52
|
+
export function Landing({ brand = 'Brickwork', title = 'Ship your next interface this afternoon', description = 'One primary offer. One CTA. Gallery landings stay focused on conversion.', primaryCta = { href: '/gallery/forms', label: 'Start free' }, secondaryCta = { href: '/gallery/homepage', label: 'Back to homepage' }, benefits = [
|
|
53
|
+
'Tokens and components share one visual contract.',
|
|
54
|
+
'HTML, React, Vue, and Django consume the same bw-* chrome.',
|
|
55
|
+
'L1 recolour brands the whole page without forks.',
|
|
56
|
+
], }) {
|
|
57
|
+
return (_jsxs(_Fragment, { children: [_jsx(SkipLink, {}), _jsx("header", { style: { padding: 'var(--bw-space-4) var(--bw-space-6)' }, children: _jsxs(Cluster, { style: { justifyContent: 'space-between' }, children: [_jsx("strong", { className: "bw-text-title-md", children: brand }), _jsx(ThemeToggle, {})] }) }), _jsx("main", { id: "main", style: { padding: 'var(--bw-space-12) var(--bw-space-6)' }, children: _jsxs(Stack, { className: "bw-centre", style: {
|
|
58
|
+
maxWidth: '36rem',
|
|
59
|
+
marginInline: 'auto',
|
|
60
|
+
textAlign: 'center',
|
|
61
|
+
gap: 'var(--bw-space-5)',
|
|
62
|
+
}, children: [_jsx("h1", { className: "bw-text-display-sm", children: title }), _jsx("p", { className: "bw-text-body-lg", style: { color: 'var(--bw-color-fg-muted)' }, children: description }), _jsxs(Cluster, { style: { justifyContent: 'center', gap: 'var(--bw-space-3)' }, children: [_jsx(ButtonLink, { href: primaryCta.href, variant: "primary", size: "lg", children: primaryCta.label }), _jsx(ButtonLink, { href: secondaryCta.href, variant: "ghost", size: "lg", children: secondaryCta.label })] }), _jsx("ul", { className: "bw-stack", style: {
|
|
63
|
+
textAlign: 'left',
|
|
64
|
+
gap: 'var(--bw-space-3)',
|
|
65
|
+
marginTop: 'var(--bw-space-6)',
|
|
66
|
+
}, children: benefits.map((item) => (_jsx("li", { className: "bw-card", children: item }, item))) })] }) })] }));
|
|
67
|
+
}
|
|
68
|
+
export function ContactForm({ title = 'Contact', description = 'Gallery form recipe with searchable topic, dates, and kit chrome.', onSubmit, topics = [
|
|
69
|
+
{ value: 'product', label: 'Product question' },
|
|
70
|
+
{ value: 'partnership', label: 'Partnership' },
|
|
71
|
+
{ value: 'support', label: 'Support' },
|
|
72
|
+
], }) {
|
|
73
|
+
return (_jsxs(_Fragment, { children: [_jsx(SkipLink, {}), _jsx("main", { id: "main", style: {
|
|
74
|
+
padding: 'var(--bw-space-10) var(--bw-space-6)',
|
|
75
|
+
maxWidth: '32rem',
|
|
76
|
+
marginInline: 'auto',
|
|
77
|
+
}, children: _jsxs(Stack, { style: { gap: 'var(--bw-space-6)' }, children: [_jsxs(Stack, { style: { gap: 'var(--bw-space-2)' }, children: [_jsx("h1", { className: "bw-text-title-lg", children: title }), _jsx("p", { className: "bw-text-body-md", style: { color: 'var(--bw-color-fg-muted)' }, children: description })] }), _jsxs(Form, { onSubmit: (e) => {
|
|
78
|
+
if (onSubmit) {
|
|
79
|
+
onSubmit(e);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
}, style: { gap: 'var(--bw-space-4)' }, children: [_jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-name", children: "Name" }), _jsx(Input, { id: "bw-contact-name", name: "name", autoComplete: "name", required: true })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-email", children: "Email" }), _jsx(Input, { id: "bw-contact-email", name: "email", type: "email", autoComplete: "email", required: true }), _jsx(Hint, { children: "We only use this to reply." })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-topic", children: "Topic" }), _jsx(Combobox, { id: "bw-contact-topic", name: "topic", options: topics, placeholder: "Search topics" })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-date", children: "Preferred date" }), _jsx(DatePicker, { id: "bw-contact-date", name: "date" })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-from", children: "Availability" }), _jsx(DateRangePicker, { startId: "bw-contact-from", endId: "bw-contact-to", startName: "from", endName: "to" })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-time", children: "Call time" }), _jsx(TimeInput, { id: "bw-contact-time", name: "time" })] }), _jsxs(Field, { children: [_jsx(Label, { htmlFor: "bw-contact-message", children: "Message" }), _jsx(Textarea, { id: "bw-contact-message", name: "message", rows: 5, required: true })] }), _jsx(Field, { children: _jsxs(Cluster, { children: [_jsx(Checkbox, { id: "bw-contact-copy", name: "copy" }), _jsx(Label, { htmlFor: "bw-contact-copy", children: "Send me a copy" })] }) }), _jsxs(FormActions, { children: [_jsx(Button, { type: "submit", variant: "primary", children: "Send message" }), _jsx(ButtonLink, { href: "/gallery/homepage", variant: "ghost", children: "Cancel" })] })] })] }) })] }));
|
|
84
|
+
}
|
package/dist/toast.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ToastVariant = 'default' | 'success' | 'warning' | 'danger' | 'info';
|
|
3
|
+
export type ToastItem = {
|
|
4
|
+
id: string;
|
|
5
|
+
message: string;
|
|
6
|
+
variant?: ToastVariant;
|
|
7
|
+
};
|
|
8
|
+
type ToastContextValue = {
|
|
9
|
+
toasts: ToastItem[];
|
|
10
|
+
push: (message: string, variant?: ToastVariant) => void;
|
|
11
|
+
dismiss: (id: string) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function ToastProvider({ children, placement, }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
placement?: 'top-end' | 'top-start' | 'bottom-end' | 'bottom-start';
|
|
16
|
+
}): React.JSX.Element;
|
|
17
|
+
export declare function useToast(): ToastContextValue;
|
|
18
|
+
export {};
|
package/dist/toast.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
const ToastContext = React.createContext(null);
|
|
6
|
+
export function ToastProvider({ children, placement = 'top-end', }) {
|
|
7
|
+
const [toasts, setToasts] = React.useState([]);
|
|
8
|
+
const dismiss = React.useCallback((id) => {
|
|
9
|
+
setToasts((list) => list.filter((t) => t.id !== id));
|
|
10
|
+
}, []);
|
|
11
|
+
const push = React.useCallback((message, variant = 'success') => {
|
|
12
|
+
const id = `toast-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
13
|
+
setToasts((list) => [{ id, message, variant }, ...list]);
|
|
14
|
+
window.setTimeout(() => dismiss(id), 4000);
|
|
15
|
+
}, [dismiss]);
|
|
16
|
+
return (_jsxs(ToastContext.Provider, { value: { toasts, push, dismiss }, children: [children, _jsx("div", { id: "bw-toast-region", className: cn('bw-toast-region', `bw-toast-region--${placement}`), "aria-live": "polite", children: toasts.map((toast) => (_jsxs("div", { className: cn('bw-toast', toast.variant && toast.variant !== 'default' && `bw-toast--${toast.variant}`), "data-bw-toast": "", "data-bw-visible": "", children: [_jsx("p", { className: "bw-toast__message", children: toast.message }), _jsx("button", { type: "button", className: "bw-toast__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only", "aria-label": "Dismiss", onClick: () => dismiss(toast.id), children: "x" })] }, toast.id))) })] }));
|
|
17
|
+
}
|
|
18
|
+
export function useToast() {
|
|
19
|
+
const ctx = React.useContext(ToastContext);
|
|
20
|
+
if (!ctx) {
|
|
21
|
+
throw new Error('useToast must be used within ToastProvider');
|
|
22
|
+
}
|
|
23
|
+
return ctx;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bwui/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React adapter for Brickwork: typed components bound to the Brickwork token substrate and bw-* class contract.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18",
|
|
26
|
+
"react-dom": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@bwui/css": "0.1.0",
|
|
30
|
+
"@bwui/tokens": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "^18",
|
|
34
|
+
"typescript": "^5"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/icvoss/brickwork.git"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json"
|
|
45
|
+
}
|
|
6
46
|
}
|
package/src/alert.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { cn } from './cn'
|
|
3
|
+
|
|
4
|
+
export type AlertVariant = 'default' | 'success' | 'warning' | 'danger' | 'info'
|
|
5
|
+
|
|
6
|
+
export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
variant?: AlertVariant
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Alert({ className, variant = 'default', ...props }: AlertProps) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
role="alert"
|
|
14
|
+
className={cn(
|
|
15
|
+
'bw-alert',
|
|
16
|
+
variant !== 'default' && `bw-alert--${variant}`,
|
|
17
|
+
className,
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function AlertTitle({
|
|
25
|
+
className,
|
|
26
|
+
...props
|
|
27
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
28
|
+
return <div className={cn('bw-alert__title', className)} {...props} />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function AlertBody({
|
|
32
|
+
className,
|
|
33
|
+
...props
|
|
34
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
35
|
+
return <div className={cn('bw-alert__body', className)} {...props} />
|
|
36
|
+
}
|