@bwui/react 0.1.2 → 0.1.4

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 CHANGED
@@ -1,8 +1,9 @@
1
1
  # `@bwui/react`
2
2
 
3
- Typed React adapter for Brickwork. Components emit the same `bw-*` classes as
4
- the HTML gallery and `django-brickwork`. Peer CSS is `@bwui/css`; this package
5
- does not bundle the stylesheet.
3
+ **Early (0.1.x).** Typed React adapter for Brickwork: same `bw-*` contract as
4
+ Django and HTML, but not Django-level production proof. Components emit the
5
+ same `bw-*` classes as the HTML gallery and `django-brickwork`. Peer CSS is
6
+ `@bwui/css`; this package does not bundle the stylesheet.
6
7
 
7
8
  ```bash
8
9
  npm install @bwui/react @bwui/css
@@ -17,13 +18,20 @@ export function App() {
17
18
  }
18
19
  ```
19
20
 
21
+ ## Runnable example
22
+
23
+ One three-page site (Northline: `Homepage`, `Landing`, `ContactForm`) is the
24
+ runnable example. It is one file, `App.tsx`, and it is what the demo host
25
+ preview renders and the brickworkui.com React copy tab shows (monorepo path
26
+ `examples/react-vite`). Start there rather than from an isolated snippet.
27
+
20
28
  ## Four jobs
21
29
 
22
30
  | Job | Export |
23
31
  |---|---|
24
32
  | Homepage | `<Homepage>` |
25
33
  | Landing | `<Landing>` |
26
- | Forms | `<Form>`, `<Field>`, `<Input>`, `<Checkbox>`, `<Combobox>`, `<DatePicker>`, `<DateRangePicker>`, `<TimeInput>`, `<ContactForm>` |
34
+ | Forms | `<Form>`, `<Field>`, `<Input>`, `<Checkbox>`, `<Combobox>`, `<DatePicker>`, `<DateRangePicker>`, `<TimeInput>`, `<ContactForm>` (`cancelHref` sets where Cancel leads) |
27
35
  | Components | `<Button>`, `<Card>`, `<Modal>`, `<DataTable>`, `<CommandPalette>`, … |
28
36
 
29
37
  Copy Pro gallery HTML from brickworkui.com. `@bwui/gallery` is not an npm
package/dist/button.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import { cn } from './cn';
4
4
  function buttonClasses(variant, size, className) {
5
- return cn('bw-btn', `bw-btn--${variant}`, size !== 'md' && `bw-btn--${size}`, className);
5
+ return cn('bw-btn', `bw-btn--${variant}`, size !== 'md' && `bw-btn--size-${size}`, className);
6
6
  }
7
7
  export const Button = React.forwardRef(function Button({ className, variant = 'primary', size = 'md', type = 'button', ...props }, ref) {
8
8
  return (_jsx("button", { ref: ref, type: type, className: buttonClasses(variant, size, className), ...props }));
package/dist/chrome.js CHANGED
@@ -71,5 +71,5 @@ export function Breadcrumbs({ items, className, }) {
71
71
  return (_jsx("nav", { className: cn('bw-breadcrumbs', className), "aria-label": "Breadcrumb", children: _jsx("ol", { children: items.map((item, i) => (_jsx("li", { children: item.href && i < items.length - 1 ? (_jsx("a", { href: item.href, children: item.label })) : (_jsx("span", { "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label })) }, item.label))) }) }));
72
72
  }
73
73
  export function Pagination({ page, pageCount, onPageChange, className, }) {
74
- return (_jsxs("nav", { className: cn('bw-pagination', className), "aria-label": "Pagination", children: [_jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: "Previous" }), _jsxs("span", { className: "bw-pagination__status", children: [page, " of ", pageCount] }), _jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: "Next" })] }));
74
+ return (_jsxs("nav", { className: cn('bw-pagination', className), "aria-label": "Pagination", children: [_jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--size-sm", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: "Previous" }), _jsxs("span", { className: "bw-pagination__status", children: [page, " of ", pageCount] }), _jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--size-sm", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: "Next" })] }));
75
75
  }
@@ -12,9 +12,34 @@ export type ComboboxProps = {
12
12
  defaultValue?: string;
13
13
  onValueChange?: (value: string) => void;
14
14
  placeholder?: string;
15
+ /**
16
+ * Text of the blank option on the hidden floor select (CMB-072). It is never
17
+ * shown to a user; it defaults to `placeholder` so no English originates in
18
+ * the component.
19
+ */
20
+ blankLabel?: string;
15
21
  disabled?: boolean;
22
+ /**
23
+ * Conveyed with `aria-required` on the input. The hidden floor select never
24
+ * carries a native `required` (CMB-062): a browser cannot show the message
25
+ * for a hidden control, so the server owns validation.
26
+ */
16
27
  required?: boolean;
17
28
  className?: string;
18
29
  emptyLabel?: string;
30
+ /**
31
+ * Accessible name for the input when there is no visible `<label>` (CMB-050).
32
+ * With a visible label whose `htmlFor` targets `id`, the input is named from
33
+ * that label automatically.
34
+ */
35
+ 'aria-label'?: string;
36
+ /** Space-separated ids that name the input; overrides the automatic label lookup. */
37
+ 'aria-labelledby'?: string;
38
+ /**
39
+ * Polite status text for the number of results after a filter (CMB-052). The
40
+ * zero case uses `emptyLabel`. Supply it to translate or reword the default
41
+ * English.
42
+ */
43
+ resultsLabel?: (count: number) => string;
19
44
  };
20
- export declare function Combobox({ id, name, options, value, defaultValue, onValueChange, placeholder, disabled, required, className, emptyLabel, }: ComboboxProps): React.JSX.Element;
45
+ export declare function Combobox({ id, name, options, value, defaultValue, onValueChange, placeholder, blankLabel, disabled, required, className, emptyLabel, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, resultsLabel, }: ComboboxProps): React.JSX.Element;
package/dist/combobox.js CHANGED
@@ -2,69 +2,197 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as React from 'react';
4
4
  import { cn } from './cn';
5
- export function Combobox({ id, name, options, value, defaultValue = '', onValueChange, placeholder = 'Search', disabled, required, className, emptyLabel = 'No matches', }) {
5
+ function defaultResultsLabel(count) {
6
+ return count === 1 ? '1 result available' : `${count} results available`;
7
+ }
8
+ export function Combobox({ id, name, options, value, defaultValue = '', onValueChange, placeholder = 'Search', blankLabel = placeholder, disabled, required, className, emptyLabel = 'No matches', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, resultsLabel = defaultResultsLabel, }) {
6
9
  const listboxId = React.useId();
7
10
  const [open, setOpen] = React.useState(false);
8
11
  const [query, setQuery] = React.useState('');
9
- const [active, setActive] = React.useState(0);
12
+ // The list filters only once the user has typed; opening by click or arrow
13
+ // shows every option (CMB-011, CMB-022).
14
+ const [typed, setTyped] = React.useState(false);
15
+ // -1 means no active option (CMB-010): the first ArrowDown selects one.
16
+ const [active, setActive] = React.useState(-1);
17
+ // Escape on an open list closes it and leaves the typed text (section 5.2);
18
+ // blur, Tab, an outside press or a commit restores the committed label
19
+ // (CMB-013).
20
+ const [held, setHeld] = React.useState(false);
10
21
  const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
22
+ const [status, setStatus] = React.useState('');
23
+ const [labelledBy, setLabelledBy] = React.useState(undefined);
11
24
  const rootRef = React.useRef(null);
25
+ const floorRef = React.useRef(null);
26
+ const pendingChange = React.useRef(null);
12
27
  const selected = value ?? uncontrolled;
13
28
  const selectedOption = options.find((o) => o.value === selected);
14
29
  const filtered = React.useMemo(() => {
15
- const q = query.trim().toLowerCase();
30
+ const entries = options.map((opt, index) => ({ opt, index }));
31
+ const q = typed ? query.trim().toLowerCase() : '';
16
32
  if (!q)
17
- return options;
18
- return options.filter((o) => o.label.toLowerCase().includes(q));
19
- }, [options, query]);
33
+ return entries;
34
+ return entries.filter(({ opt }) => opt.label.toLowerCase().includes(q));
35
+ }, [options, query, typed]);
36
+ const optionId = (index) => `${listboxId}-opt-${index}`;
37
+ const activeEntry = active >= 0 ? filtered[active] : undefined;
20
38
  React.useEffect(() => {
21
- if (open)
39
+ if (open || held)
22
40
  return;
23
41
  setQuery(selectedOption?.label ?? '');
24
- }, [open, selectedOption]);
42
+ }, [open, held, selectedOption]);
43
+ const hide = React.useCallback(() => {
44
+ setOpen(false);
45
+ setActive(-1);
46
+ setTyped(false);
47
+ setHeld(false);
48
+ }, []);
49
+ // The next enabled entry from `from` in direction `step`, wrapping at the
50
+ // ends and skipping disabled options (CMB-016); -1 when every entry is
51
+ // disabled.
52
+ function nextEnabled(from, step) {
53
+ const count = filtered.length;
54
+ let index = from;
55
+ for (let tried = 0; tried < count; tried += 1) {
56
+ index = (((index + step) % count) + count) % count;
57
+ if (!filtered[index].opt.disabled)
58
+ return index;
59
+ }
60
+ return -1;
61
+ }
25
62
  React.useEffect(() => {
26
63
  function onPointer(e) {
27
64
  if (!rootRef.current?.contains(e.target))
28
- setOpen(false);
65
+ hide();
29
66
  }
30
67
  document.addEventListener('pointerdown', onPointer);
31
68
  return () => document.removeEventListener('pointerdown', onPointer);
32
- }, []);
33
- function commit(next) {
69
+ }, [hide]);
70
+ // The label's `htmlFor` targets the hidden floor, so name the visible input
71
+ // from the floor's labels unless the consumer supplied a name (CMB-050). A
72
+ // label without an id gets a stable generated one.
73
+ React.useEffect(() => {
74
+ if (ariaLabel || ariaLabelledBy)
75
+ return;
76
+ const floor = floorRef.current;
77
+ if (!floor)
78
+ return;
79
+ const ids = Array.from(floor.labels ?? []).map((label, i) => {
80
+ if (!label.id)
81
+ label.id = `${floor.id || listboxId}-label-${i}`;
82
+ return label.id;
83
+ });
84
+ setLabelledBy(ids.length ? ids.join(' ') : undefined);
85
+ }, [ariaLabel, ariaLabelledBy, id, listboxId]);
86
+ function apply(next) {
34
87
  if (value === undefined)
35
88
  setUncontrolled(next);
36
89
  onValueChange?.(next);
90
+ }
91
+ function commit(next) {
92
+ if (next !== selected) {
93
+ pendingChange.current = next;
94
+ apply(next);
95
+ }
37
96
  const label = options.find((o) => o.value === next)?.label ?? next;
38
97
  setQuery(label);
39
- setOpen(false);
98
+ hide();
99
+ }
100
+ // A real selection change also fires a bubbling native `change` on the
101
+ // floor select (CMB-012), after React has written the new value to it, so
102
+ // htmx triggers, dependent fields and form listeners see the final value.
103
+ React.useEffect(() => {
104
+ const pending = pendingChange.current;
105
+ pendingChange.current = null;
106
+ if (pending !== null && pending === selected) {
107
+ floorRef.current?.dispatchEvent(new Event('change', { bubbles: true }));
108
+ }
109
+ });
110
+ function announce(nextQuery) {
111
+ const q = nextQuery.trim().toLowerCase();
112
+ const count = q
113
+ ? options.filter((o) => o.label.toLowerCase().includes(q)).length
114
+ : options.length;
115
+ setStatus(count === 0 ? emptyLabel : resultsLabel(count));
40
116
  }
41
- return (_jsxs("div", { ref: rootRef, className: cn('bw-combobox', className), "data-bw-combobox": "", ...(open ? { 'data-bw-open': '' } : {}), children: [_jsxs("select", { className: "bw-input bw-combobox__floor", id: id, name: name, value: selected, required: required, disabled: disabled, tabIndex: -1, "aria-hidden": "true", hidden: true, onChange: (e) => commit(e.target.value), children: [_jsx("option", { value: "", children: "Choose" }), options.map((opt) => (_jsx("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value)))] }), _jsxs("div", { className: "bw-combobox__field", children: [_jsx("input", { className: "bw-input bw-combobox__input", role: "combobox", "aria-expanded": open, "aria-controls": listboxId, "aria-autocomplete": "list", autoComplete: "off", disabled: disabled, placeholder: placeholder, value: open ? query : (selectedOption?.label ?? query), onChange: (e) => {
117
+ return (_jsxs("div", { ref: rootRef, className: cn('bw-combobox', className), "data-bw-combobox": "", ...(open ? { 'data-bw-open': '' } : {}), children: [_jsxs("select", { ref: floorRef, className: "bw-input bw-combobox__floor", id: id, name: name, value: selected, disabled: disabled, tabIndex: -1, "aria-hidden": "true", hidden: true, onChange: (e) => {
118
+ // The dispatch above lands here with the value already applied; only
119
+ // a genuinely different value (an external write) is applied.
120
+ if (e.target.value !== selected)
121
+ apply(e.target.value);
122
+ }, children: [_jsx("option", { value: "", children: blankLabel }), options.map((opt) => (_jsx("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value)))] }), _jsxs("div", { className: "bw-combobox__field", children: [_jsx("input", { className: "bw-input bw-combobox__input", role: "combobox", "aria-expanded": open, "aria-controls": listboxId, "aria-autocomplete": "list", "aria-activedescendant": open && activeEntry ? optionId(activeEntry.index) : undefined, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy ?? labelledBy, "aria-required": required || undefined, autoComplete: "off", disabled: disabled, placeholder: placeholder, value: open || held ? query : (selectedOption?.label ?? query), onClick: () => setOpen(true), onBlur: hide, onChange: (e) => {
42
123
  setQuery(e.target.value);
124
+ setTyped(true);
125
+ setHeld(false);
43
126
  setOpen(true);
44
- setActive(0);
45
- }, onFocus: () => setOpen(true), onKeyDown: (e) => {
127
+ setActive(-1);
128
+ announce(e.target.value);
129
+ }, onKeyDown: (e) => {
46
130
  if (e.key === 'ArrowDown') {
47
131
  e.preventDefault();
48
- setOpen(true);
49
- setActive((i) => Math.min(i + 1, Math.max(filtered.length - 1, 0)));
132
+ if (!open) {
133
+ setOpen(true);
134
+ // Alt+ArrowDown opens and leaves the active option unchanged.
135
+ if (e.altKey)
136
+ return;
137
+ const selectedAt = filtered.findIndex(({ opt }) => opt.value === selected);
138
+ setActive(selectedAt >= 0 && !filtered[selectedAt].opt.disabled
139
+ ? selectedAt
140
+ : nextEnabled(-1, 1));
141
+ }
142
+ else if (!e.altKey) {
143
+ const next = nextEnabled(active, 1);
144
+ if (next !== -1)
145
+ setActive(next);
146
+ }
50
147
  }
51
148
  else if (e.key === 'ArrowUp') {
52
149
  e.preventDefault();
53
- setActive((i) => Math.max(i - 1, 0));
150
+ if (!open) {
151
+ setOpen(true);
152
+ setActive(nextEnabled(0, -1));
153
+ }
154
+ else {
155
+ const next = nextEnabled(active === -1 ? 0 : active, -1);
156
+ if (next !== -1)
157
+ setActive(next);
158
+ }
54
159
  }
55
160
  else if (e.key === 'Enter') {
56
- e.preventDefault();
57
- const opt = filtered[active];
58
- if (opt && !opt.disabled)
59
- commit(opt.value);
161
+ // Enter acts only on an open list with an active option; otherwise
162
+ // the form submit proceeds.
163
+ if (open && activeEntry) {
164
+ e.preventDefault();
165
+ if (!activeEntry.opt.disabled)
166
+ commit(activeEntry.opt.value);
167
+ }
60
168
  }
61
169
  else if (e.key === 'Escape') {
62
- e.preventDefault();
63
- setOpen(false);
170
+ if (open) {
171
+ // Closes and leaves the text as typed.
172
+ e.preventDefault();
173
+ hide();
174
+ setHeld(true);
175
+ }
176
+ else if (held) {
177
+ // Closed with an uncommitted edit: revert it. An Escape with
178
+ // nothing to revert is left for the page (a modal still closes).
179
+ e.preventDefault();
180
+ setHeld(false);
181
+ }
182
+ }
183
+ else if (e.key === 'Tab') {
184
+ // Close without choosing; the default Tab continues the sequence.
185
+ hide();
64
186
  }
65
- } }), _jsxs("ul", { className: "bw-combobox__listbox", role: "listbox", id: listboxId, children: [filtered.map((opt, idx) => (_jsx("li", { className: "bw-combobox__option", role: "option", "data-bw-value": opt.value, "aria-selected": opt.value === selected, "aria-disabled": opt.disabled || undefined, ...(idx === active ? { 'data-bw-active': '' } : {}), onMouseMove: () => setActive(idx), onMouseDown: (e) => {
187
+ } }), _jsxs("ul", { className: "bw-combobox__listbox", role: "listbox", id: listboxId,
188
+ // A press inside the list (an option or its scrollbar) must not blur
189
+ // the input: focus stays there (CMB-010).
190
+ onMouseDown: (e) => e.preventDefault(), children: [filtered.map(({ opt, index }, idx) => (_jsx("li", { id: optionId(index), className: "bw-combobox__option", role: "option", "data-bw-value": opt.value, "aria-selected": opt.value === selected, "aria-disabled": opt.disabled || undefined, ...(idx === active ? { 'data-bw-active': '' } : {}), onMouseMove: () => {
191
+ if (!opt.disabled)
192
+ setActive(idx);
193
+ }, onMouseDown: (e) => {
66
194
  e.preventDefault();
67
195
  if (!opt.disabled)
68
196
  commit(opt.value);
69
- }, children: opt.label }, opt.value))), _jsx("li", { className: "bw-combobox__empty", hidden: filtered.length > 0, children: emptyLabel })] })] })] }));
197
+ }, children: opt.label }, opt.value))), _jsx("li", { className: "bw-combobox__empty", role: "option", "aria-disabled": "true", hidden: filtered.length > 0, children: emptyLabel })] }), _jsx("div", { className: "bw-combobox__status bw-visually-hidden", role: "status", "aria-live": "polite", "data-bw-combobox-status": "", children: status })] })] }));
70
198
  }
@@ -50,7 +50,7 @@ function daysFor(view) {
50
50
  return cells;
51
51
  }
52
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) => {
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--size-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--size-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
54
  if (!date)
55
55
  return _jsx("div", {}, `blank-${i}`);
56
56
  const inRange = Boolean(rangeStart &&
package/dist/modal.js CHANGED
@@ -14,5 +14,5 @@ export function Modal({ open = false, onOpenChange, title, children, footer, siz
14
14
  document.addEventListener('keydown', onKey);
15
15
  return () => document.removeEventListener('keydown', onKey);
16
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] })] }));
17
+ return (_jsxs("div", { className: cn('bw-modal', `bw-modal--size-${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--size-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
18
  }
package/dist/pages.d.ts CHANGED
@@ -38,5 +38,7 @@ export type ContactFormProps = {
38
38
  value: string;
39
39
  label: string;
40
40
  }>;
41
+ /** Where "Cancel" leads. Defaults to the gallery homepage route. */
42
+ cancelHref?: string;
41
43
  };
42
- export declare function ContactForm({ title, description, onSubmit, topics, }: ContactFormProps): React.JSX.Element;
44
+ export declare function ContactForm({ title, description, onSubmit, topics, cancelHref, }: ContactFormProps): React.JSX.Element;
package/dist/pages.js CHANGED
@@ -69,7 +69,7 @@ export function ContactForm({ title = 'Contact', description = 'Gallery form rec
69
69
  { value: 'product', label: 'Product question' },
70
70
  { value: 'partnership', label: 'Partnership' },
71
71
  { value: 'support', label: 'Support' },
72
- ], }) {
72
+ ], cancelHref = '/gallery/homepage', }) {
73
73
  return (_jsxs(_Fragment, { children: [_jsx(SkipLink, {}), _jsx("main", { id: "main", style: {
74
74
  padding: 'var(--bw-space-10) var(--bw-space-6)',
75
75
  maxWidth: '32rem',
@@ -80,5 +80,5 @@ export function ContactForm({ title = 'Contact', description = 'Gallery form rec
80
80
  return;
81
81
  }
82
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" })] })] })] }) })] }));
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: cancelHref, variant: "ghost", children: "Cancel" })] })] })] }) })] }));
84
84
  }
package/dist/toast.js CHANGED
@@ -13,7 +13,7 @@ export function ToastProvider({ children, placement = 'top-end', }) {
13
13
  setToasts((list) => [{ id, message, variant }, ...list]);
14
14
  window.setTimeout(() => dismiss(id), 4000);
15
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))) })] }));
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--size-sm bw-btn--icon-only", "aria-label": "Dismiss", onClick: () => dismiss(toast.id), children: "x" })] }, toast.id))) })] }));
17
17
  }
18
18
  export function useToast() {
19
19
  const ctx = React.useContext(ToastContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bwui/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "React adapter for Brickwork: typed components bound to the Brickwork token substrate and bw-* class contract.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "react-dom": ">=18"
27
27
  },
28
28
  "dependencies": {
29
- "@bwui/css": "0.1.2",
30
- "@bwui/tokens": "0.1.2"
29
+ "@bwui/css": "0.1.4",
30
+ "@bwui/tokens": "0.1.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^18",
package/src/button.tsx CHANGED
@@ -18,7 +18,7 @@ function buttonClasses(
18
18
  return cn(
19
19
  'bw-btn',
20
20
  `bw-btn--${variant}`,
21
- size !== 'md' && `bw-btn--${size}`,
21
+ size !== 'md' && `bw-btn--size-${size}`,
22
22
  className,
23
23
  )
24
24
  }
package/src/chrome.tsx CHANGED
@@ -241,7 +241,7 @@ export function Pagination({
241
241
  <nav className={cn('bw-pagination', className)} aria-label="Pagination">
242
242
  <button
243
243
  type="button"
244
- className="bw-btn bw-btn--ghost bw-btn--sm"
244
+ className="bw-btn bw-btn--ghost bw-btn--size-sm"
245
245
  disabled={page <= 1}
246
246
  onClick={() => onPageChange(page - 1)}
247
247
  >
@@ -252,7 +252,7 @@ export function Pagination({
252
252
  </span>
253
253
  <button
254
254
  type="button"
255
- className="bw-btn bw-btn--ghost bw-btn--sm"
255
+ className="bw-btn bw-btn--ghost bw-btn--size-sm"
256
256
  disabled={page >= pageCount}
257
257
  onClick={() => onPageChange(page + 1)}
258
258
  >
package/src/combobox.tsx CHANGED
@@ -17,10 +17,39 @@ export type ComboboxProps = {
17
17
  defaultValue?: string
18
18
  onValueChange?: (value: string) => void
19
19
  placeholder?: string
20
+ /**
21
+ * Text of the blank option on the hidden floor select (CMB-072). It is never
22
+ * shown to a user; it defaults to `placeholder` so no English originates in
23
+ * the component.
24
+ */
25
+ blankLabel?: string
20
26
  disabled?: boolean
27
+ /**
28
+ * Conveyed with `aria-required` on the input. The hidden floor select never
29
+ * carries a native `required` (CMB-062): a browser cannot show the message
30
+ * for a hidden control, so the server owns validation.
31
+ */
21
32
  required?: boolean
22
33
  className?: string
23
34
  emptyLabel?: string
35
+ /**
36
+ * Accessible name for the input when there is no visible `<label>` (CMB-050).
37
+ * With a visible label whose `htmlFor` targets `id`, the input is named from
38
+ * that label automatically.
39
+ */
40
+ 'aria-label'?: string
41
+ /** Space-separated ids that name the input; overrides the automatic label lookup. */
42
+ 'aria-labelledby'?: string
43
+ /**
44
+ * Polite status text for the number of results after a filter (CMB-052). The
45
+ * zero case uses `emptyLabel`. Supply it to translate or reword the default
46
+ * English.
47
+ */
48
+ resultsLabel?: (count: number) => string
49
+ }
50
+
51
+ function defaultResultsLabel(count: number): string {
52
+ return count === 1 ? '1 result available' : `${count} results available`
24
53
  }
25
54
 
26
55
  export function Combobox({
@@ -31,45 +60,125 @@ export function Combobox({
31
60
  defaultValue = '',
32
61
  onValueChange,
33
62
  placeholder = 'Search',
63
+ blankLabel = placeholder,
34
64
  disabled,
35
65
  required,
36
66
  className,
37
67
  emptyLabel = 'No matches',
68
+ 'aria-label': ariaLabel,
69
+ 'aria-labelledby': ariaLabelledBy,
70
+ resultsLabel = defaultResultsLabel,
38
71
  }: ComboboxProps) {
39
72
  const listboxId = React.useId()
40
73
  const [open, setOpen] = React.useState(false)
41
74
  const [query, setQuery] = React.useState('')
42
- const [active, setActive] = React.useState(0)
75
+ // The list filters only once the user has typed; opening by click or arrow
76
+ // shows every option (CMB-011, CMB-022).
77
+ const [typed, setTyped] = React.useState(false)
78
+ // -1 means no active option (CMB-010): the first ArrowDown selects one.
79
+ const [active, setActive] = React.useState(-1)
80
+ // Escape on an open list closes it and leaves the typed text (section 5.2);
81
+ // blur, Tab, an outside press or a commit restores the committed label
82
+ // (CMB-013).
83
+ const [held, setHeld] = React.useState(false)
43
84
  const [uncontrolled, setUncontrolled] = React.useState(defaultValue)
85
+ const [status, setStatus] = React.useState('')
86
+ const [labelledBy, setLabelledBy] = React.useState<string | undefined>(undefined)
44
87
  const rootRef = React.useRef<HTMLDivElement>(null)
88
+ const floorRef = React.useRef<HTMLSelectElement>(null)
89
+ const pendingChange = React.useRef<string | null>(null)
45
90
  const selected = value ?? uncontrolled
46
91
 
47
92
  const selectedOption = options.find((o) => o.value === selected)
48
93
  const filtered = React.useMemo(() => {
49
- const q = query.trim().toLowerCase()
50
- if (!q) return options
51
- return options.filter((o) => o.label.toLowerCase().includes(q))
52
- }, [options, query])
94
+ const entries = options.map((opt, index) => ({ opt, index }))
95
+ const q = typed ? query.trim().toLowerCase() : ''
96
+ if (!q) return entries
97
+ return entries.filter(({ opt }) => opt.label.toLowerCase().includes(q))
98
+ }, [options, query, typed])
99
+
100
+ const optionId = (index: number) => `${listboxId}-opt-${index}`
101
+ const activeEntry = active >= 0 ? filtered[active] : undefined
53
102
 
54
103
  React.useEffect(() => {
55
- if (open) return
104
+ if (open || held) return
56
105
  setQuery(selectedOption?.label ?? '')
57
- }, [open, selectedOption])
106
+ }, [open, held, selectedOption])
107
+
108
+ const hide = React.useCallback(() => {
109
+ setOpen(false)
110
+ setActive(-1)
111
+ setTyped(false)
112
+ setHeld(false)
113
+ }, [])
114
+
115
+ // The next enabled entry from `from` in direction `step`, wrapping at the
116
+ // ends and skipping disabled options (CMB-016); -1 when every entry is
117
+ // disabled.
118
+ function nextEnabled(from: number, step: 1 | -1): number {
119
+ const count = filtered.length
120
+ let index = from
121
+ for (let tried = 0; tried < count; tried += 1) {
122
+ index = (((index + step) % count) + count) % count
123
+ if (!filtered[index].opt.disabled) return index
124
+ }
125
+ return -1
126
+ }
58
127
 
59
128
  React.useEffect(() => {
60
129
  function onPointer(e: PointerEvent) {
61
- if (!rootRef.current?.contains(e.target as Node)) setOpen(false)
130
+ if (!rootRef.current?.contains(e.target as Node)) hide()
62
131
  }
63
132
  document.addEventListener('pointerdown', onPointer)
64
133
  return () => document.removeEventListener('pointerdown', onPointer)
65
- }, [])
134
+ }, [hide])
66
135
 
67
- function commit(next: string) {
136
+ // The label's `htmlFor` targets the hidden floor, so name the visible input
137
+ // from the floor's labels unless the consumer supplied a name (CMB-050). A
138
+ // label without an id gets a stable generated one.
139
+ React.useEffect(() => {
140
+ if (ariaLabel || ariaLabelledBy) return
141
+ const floor = floorRef.current
142
+ if (!floor) return
143
+ const ids = Array.from(floor.labels ?? []).map((label, i) => {
144
+ if (!label.id) label.id = `${floor.id || listboxId}-label-${i}`
145
+ return label.id
146
+ })
147
+ setLabelledBy(ids.length ? ids.join(' ') : undefined)
148
+ }, [ariaLabel, ariaLabelledBy, id, listboxId])
149
+
150
+ function apply(next: string) {
68
151
  if (value === undefined) setUncontrolled(next)
69
152
  onValueChange?.(next)
153
+ }
154
+
155
+ function commit(next: string) {
156
+ if (next !== selected) {
157
+ pendingChange.current = next
158
+ apply(next)
159
+ }
70
160
  const label = options.find((o) => o.value === next)?.label ?? next
71
161
  setQuery(label)
72
- setOpen(false)
162
+ hide()
163
+ }
164
+
165
+ // A real selection change also fires a bubbling native `change` on the
166
+ // floor select (CMB-012), after React has written the new value to it, so
167
+ // htmx triggers, dependent fields and form listeners see the final value.
168
+ React.useEffect(() => {
169
+ const pending = pendingChange.current
170
+ pendingChange.current = null
171
+ if (pending !== null && pending === selected) {
172
+ floorRef.current?.dispatchEvent(new Event('change', { bubbles: true }))
173
+ }
174
+ })
175
+
176
+ function announce(nextQuery: string) {
177
+ const q = nextQuery.trim().toLowerCase()
178
+ const count = q
179
+ ? options.filter((o) => o.label.toLowerCase().includes(q)).length
180
+ : options.length
181
+ setStatus(count === 0 ? emptyLabel : resultsLabel(count))
73
182
  }
74
183
 
75
184
  return (
@@ -80,18 +189,22 @@ export function Combobox({
80
189
  {...(open ? { 'data-bw-open': '' } : {})}
81
190
  >
82
191
  <select
192
+ ref={floorRef}
83
193
  className="bw-input bw-combobox__floor"
84
194
  id={id}
85
195
  name={name}
86
196
  value={selected}
87
- required={required}
88
197
  disabled={disabled}
89
198
  tabIndex={-1}
90
199
  aria-hidden="true"
91
200
  hidden
92
- onChange={(e) => commit(e.target.value)}
201
+ onChange={(e) => {
202
+ // The dispatch above lands here with the value already applied; only
203
+ // a genuinely different value (an external write) is applied.
204
+ if (e.target.value !== selected) apply(e.target.value)
205
+ }}
93
206
  >
94
- <option value="">Choose</option>
207
+ <option value="">{blankLabel}</option>
95
208
  {options.map((opt) => (
96
209
  <option key={opt.value} value={opt.value} disabled={opt.disabled}>
97
210
  {opt.label}
@@ -105,45 +218,96 @@ export function Combobox({
105
218
  aria-expanded={open}
106
219
  aria-controls={listboxId}
107
220
  aria-autocomplete="list"
221
+ aria-activedescendant={open && activeEntry ? optionId(activeEntry.index) : undefined}
222
+ aria-label={ariaLabel}
223
+ aria-labelledby={ariaLabelledBy ?? labelledBy}
224
+ aria-required={required || undefined}
108
225
  autoComplete="off"
109
226
  disabled={disabled}
110
227
  placeholder={placeholder}
111
- value={open ? query : (selectedOption?.label ?? query)}
228
+ value={open || held ? query : (selectedOption?.label ?? query)}
229
+ onClick={() => setOpen(true)}
230
+ onBlur={hide}
112
231
  onChange={(e) => {
113
232
  setQuery(e.target.value)
233
+ setTyped(true)
234
+ setHeld(false)
114
235
  setOpen(true)
115
- setActive(0)
236
+ setActive(-1)
237
+ announce(e.target.value)
116
238
  }}
117
- onFocus={() => setOpen(true)}
118
239
  onKeyDown={(e) => {
119
240
  if (e.key === 'ArrowDown') {
120
241
  e.preventDefault()
121
- setOpen(true)
122
- setActive((i) => Math.min(i + 1, Math.max(filtered.length - 1, 0)))
242
+ if (!open) {
243
+ setOpen(true)
244
+ // Alt+ArrowDown opens and leaves the active option unchanged.
245
+ if (e.altKey) return
246
+ const selectedAt = filtered.findIndex(({ opt }) => opt.value === selected)
247
+ setActive(
248
+ selectedAt >= 0 && !filtered[selectedAt].opt.disabled
249
+ ? selectedAt
250
+ : nextEnabled(-1, 1),
251
+ )
252
+ } else if (!e.altKey) {
253
+ const next = nextEnabled(active, 1)
254
+ if (next !== -1) setActive(next)
255
+ }
123
256
  } else if (e.key === 'ArrowUp') {
124
257
  e.preventDefault()
125
- setActive((i) => Math.max(i - 1, 0))
258
+ if (!open) {
259
+ setOpen(true)
260
+ setActive(nextEnabled(0, -1))
261
+ } else {
262
+ const next = nextEnabled(active === -1 ? 0 : active, -1)
263
+ if (next !== -1) setActive(next)
264
+ }
126
265
  } else if (e.key === 'Enter') {
127
- e.preventDefault()
128
- const opt = filtered[active]
129
- if (opt && !opt.disabled) commit(opt.value)
266
+ // Enter acts only on an open list with an active option; otherwise
267
+ // the form submit proceeds.
268
+ if (open && activeEntry) {
269
+ e.preventDefault()
270
+ if (!activeEntry.opt.disabled) commit(activeEntry.opt.value)
271
+ }
130
272
  } else if (e.key === 'Escape') {
131
- e.preventDefault()
132
- setOpen(false)
273
+ if (open) {
274
+ // Closes and leaves the text as typed.
275
+ e.preventDefault()
276
+ hide()
277
+ setHeld(true)
278
+ } else if (held) {
279
+ // Closed with an uncommitted edit: revert it. An Escape with
280
+ // nothing to revert is left for the page (a modal still closes).
281
+ e.preventDefault()
282
+ setHeld(false)
283
+ }
284
+ } else if (e.key === 'Tab') {
285
+ // Close without choosing; the default Tab continues the sequence.
286
+ hide()
133
287
  }
134
288
  }}
135
289
  />
136
- <ul className="bw-combobox__listbox" role="listbox" id={listboxId}>
137
- {filtered.map((opt, idx) => (
290
+ <ul
291
+ className="bw-combobox__listbox"
292
+ role="listbox"
293
+ id={listboxId}
294
+ // A press inside the list (an option or its scrollbar) must not blur
295
+ // the input: focus stays there (CMB-010).
296
+ onMouseDown={(e) => e.preventDefault()}
297
+ >
298
+ {filtered.map(({ opt, index }, idx) => (
138
299
  <li
139
300
  key={opt.value}
301
+ id={optionId(index)}
140
302
  className="bw-combobox__option"
141
303
  role="option"
142
304
  data-bw-value={opt.value}
143
305
  aria-selected={opt.value === selected}
144
306
  aria-disabled={opt.disabled || undefined}
145
307
  {...(idx === active ? { 'data-bw-active': '' } : {})}
146
- onMouseMove={() => setActive(idx)}
308
+ onMouseMove={() => {
309
+ if (!opt.disabled) setActive(idx)
310
+ }}
147
311
  onMouseDown={(e) => {
148
312
  e.preventDefault()
149
313
  if (!opt.disabled) commit(opt.value)
@@ -152,10 +316,23 @@ export function Combobox({
152
316
  {opt.label}
153
317
  </li>
154
318
  ))}
155
- <li className="bw-combobox__empty" hidden={filtered.length > 0}>
319
+ <li
320
+ className="bw-combobox__empty"
321
+ role="option"
322
+ aria-disabled="true"
323
+ hidden={filtered.length > 0}
324
+ >
156
325
  {emptyLabel}
157
326
  </li>
158
327
  </ul>
328
+ <div
329
+ className="bw-combobox__status bw-visually-hidden"
330
+ role="status"
331
+ aria-live="polite"
332
+ data-bw-combobox-status=""
333
+ >
334
+ {status}
335
+ </div>
159
336
  </div>
160
337
  </div>
161
338
  )
@@ -77,7 +77,7 @@ function Calendar({
77
77
  <div className="bw-calendar__nav">
78
78
  <button
79
79
  type="button"
80
- className="bw-btn bw-btn--ghost bw-btn--sm"
80
+ className="bw-btn bw-btn--ghost bw-btn--size-sm"
81
81
  data-bw-cal-prev=""
82
82
  aria-label="Previous month"
83
83
  onClick={() =>
@@ -91,7 +91,7 @@ function Calendar({
91
91
  </p>
92
92
  <button
93
93
  type="button"
94
- className="bw-btn bw-btn--ghost bw-btn--sm"
94
+ className="bw-btn bw-btn--ghost bw-btn--size-sm"
95
95
  data-bw-cal-next=""
96
96
  aria-label="Next month"
97
97
  onClick={() =>
package/src/modal.tsx CHANGED
@@ -34,7 +34,7 @@ export function Modal({
34
34
 
35
35
  return (
36
36
  <div
37
- className={cn('bw-modal', `bw-modal--${size}`, open && 'bw-modal--open', className)}
37
+ className={cn('bw-modal', `bw-modal--size-${size}`, open && 'bw-modal--open', className)}
38
38
  {...(open ? { 'data-bw-open': '' } : {})}
39
39
  role="presentation"
40
40
  >
@@ -55,7 +55,7 @@ export function Modal({
55
55
  </h2>
56
56
  <button
57
57
  type="button"
58
- className="bw-modal__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only"
58
+ className="bw-modal__close bw-btn bw-btn--ghost bw-btn--size-sm bw-btn--icon-only"
59
59
  aria-label="Close"
60
60
  onClick={() => onOpenChange?.(false)}
61
61
  >
package/src/pages.tsx CHANGED
@@ -254,6 +254,8 @@ export type ContactFormProps = {
254
254
  description?: React.ReactNode
255
255
  onSubmit?: React.FormEventHandler<HTMLFormElement>
256
256
  topics?: Array<{ value: string; label: string }>
257
+ /** Where "Cancel" leads. Defaults to the gallery homepage route. */
258
+ cancelHref?: string
257
259
  }
258
260
 
259
261
  export function ContactForm({
@@ -265,6 +267,7 @@ export function ContactForm({
265
267
  { value: 'partnership', label: 'Partnership' },
266
268
  { value: 'support', label: 'Support' },
267
269
  ],
270
+ cancelHref = '/gallery/homepage',
268
271
  }: ContactFormProps) {
269
272
  return (
270
273
  <>
@@ -349,7 +352,7 @@ export function ContactForm({
349
352
  <Button type="submit" variant="primary">
350
353
  Send message
351
354
  </Button>
352
- <ButtonLink href="/gallery/homepage" variant="ghost">
355
+ <ButtonLink href={cancelHref} variant="ghost">
353
356
  Cancel
354
357
  </ButtonLink>
355
358
  </FormActions>
package/src/toast.tsx CHANGED
@@ -62,7 +62,7 @@ export function ToastProvider({
62
62
  <p className="bw-toast__message">{toast.message}</p>
63
63
  <button
64
64
  type="button"
65
- className="bw-toast__close bw-btn bw-btn--ghost bw-btn--sm bw-btn--icon-only"
65
+ className="bw-toast__close bw-btn bw-btn--ghost bw-btn--size-sm bw-btn--icon-only"
66
66
  aria-label="Dismiss"
67
67
  onClick={() => dismiss(toast.id)}
68
68
  >