@gopherium/godmin 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,11 +26,6 @@ pnpm add @gopherium/godmin
26
26
  The design system packages are peer dependencies, so your application resolves
27
27
  and pins them. GodMin never redistributes them.
28
28
 
29
- ## Browsers
30
-
31
- GodMin needs `Intl.Segmenter`, which every browser WordPress supports has:
32
- Chrome and Edge 87, Safari 14.1 and Firefox 125 or newer.
33
-
34
29
  ## Setup
35
30
 
36
31
  Import the stylesheet once at your entry point, then mount `AdminRoot` around
@@ -54,7 +49,7 @@ those two lines do for you.
54
49
 
55
50
  | Entry point | Contents |
56
51
  | --- | --- |
57
- | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ConfirmBody`, `RenameBody`, `FormBody`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `RunConfirm`, `useCloseWhileOpen`, `focusInDialog`, `useFocusBack`, `focusedTrigger`, `openOnTap`, `useUnsavedText`, `markLatest`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `HUGE_BREAKPOINT`, `SIDEBAR_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
52
+ | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ConfirmBody`, `RenameBody`, `FormBody`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `RunConfirm`, `useCloseWhileOpen`, `focusInDialog`, `useFocusBack`, `focusedTrigger`, `openOnTap`, `useUnsavedText`, `markLatest`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `HUGE_BREAKPOINT`, `SIDEBAR_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
58
53
  | `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
59
54
  | `@gopherium/godmin/dates` | `startListDates`, `listDate`, the only entry that loads `@wordpress/date` |
60
55
  | `@gopherium/godmin/dialogs` | `ConfirmDialog`, `FormDialog`, the only entry that loads `@wordpress/components`. Load `@wordpress/components/build-style/style.css` once in your app, as DataViews asks |
@@ -97,6 +92,16 @@ render unthemed components with no error. Spread `godminDedupe` into
97
92
  [Build configuration](docs/build-and-versioning.md) covers both, and lists the
98
93
  design system versions each release supports.
99
94
 
95
+ ## Development
96
+
97
+ `pnpm run cover` runs the unit tests in jsdom with the coverage gate.
98
+ The stories in `stories/` show the components in Storybook, opened
99
+ with `pnpm run storybook:dev`. `pnpm run storybook:test` runs every
100
+ story in headless Chromium with its accessibility check, and
101
+ `pnpm run test:browser` runs the browser tests in `test/browser/`.
102
+ Both need Chromium once:
103
+ `pnpm exec playwright install --only-shell chromium`.
104
+
100
105
  ## Status
101
106
 
102
107
  Still 0.x, so minor releases may break. See the CHANGELOG for what each release
package/dist/base.css CHANGED
@@ -279,26 +279,50 @@ body {
279
279
  .godmin-toasts {
280
280
  position: fixed;
281
281
  inset-inline: 0;
282
- bottom: 32px;
282
+ bottom: var(--wpds-dimension-size-md);
283
283
  z-index: 1;
284
284
  display: flex;
285
285
  flex-direction: column;
286
- align-items: center;
287
- gap: var(--wpds-dimension-gap-sm);
288
286
  padding-inline: 16px;
289
287
  box-sizing: border-box;
290
288
  pointer-events: none;
291
289
  }
292
290
 
293
- :root:has(.godmin-layout__sidebar) .godmin-toasts {
294
- inset-inline-start: var(--godmin-nav-sidebar-width);
295
- inset-inline-end: var(--godmin-canvas-margin);
296
- }
297
-
298
291
  .godmin-toasts:focus {
299
292
  outline: none;
300
293
  }
301
294
 
295
+ .godmin-toasts__item {
296
+ display: grid;
297
+ grid-template-rows: 1fr;
298
+ animation: godmin-toast-grow var(--wpds-motion-duration-lg) cubic-bezier(0, 0, 0.2, 1);
299
+ }
300
+
301
+ .godmin-toasts__item--leaving {
302
+ animation:
303
+ godmin-toast-grow var(--wpds-motion-duration-lg) cubic-bezier(0, 0, 0.2, 1),
304
+ godmin-toast-shrink 450ms cubic-bezier(0.4, 0, 0.1, 1) var(--wpds-motion-duration-sm) forwards;
305
+ }
306
+
307
+ .godmin-toasts__item-inner {
308
+ display: flex;
309
+ flex-direction: column;
310
+ align-items: center;
311
+ min-height: 0;
312
+ }
313
+
314
+ @keyframes godmin-toast-grow {
315
+ 0% {
316
+ grid-template-rows: 0fr;
317
+ }
318
+ }
319
+
320
+ @keyframes godmin-toast-shrink {
321
+ 100% {
322
+ grid-template-rows: 0fr;
323
+ }
324
+ }
325
+
302
326
  .godmin-toast {
303
327
  display: flex;
304
328
  align-items: baseline;
@@ -320,20 +344,25 @@ body {
320
344
  font-size: var(--wpds-typography-font-size-md);
321
345
  line-height: 1.4;
322
346
  overflow-wrap: anywhere;
323
- cursor: default;
347
+ cursor: var(--wpds-cursor-control);
324
348
  pointer-events: auto;
325
- animation: godmin-fade-in var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced);
349
+ animation: godmin-fade-in 250ms cubic-bezier(0, 0, 0.2, 1) var(--wpds-motion-duration-xs) backwards;
326
350
  }
327
351
 
328
352
  .godmin-toast--leaving {
329
- animation: godmin-fade-out var(--wpds-motion-duration-sm) var(--wpds-motion-easing-balanced) forwards;
353
+ animation:
354
+ godmin-fade-in 250ms cubic-bezier(0, 0, 0.2, 1) var(--wpds-motion-duration-xs) backwards,
355
+ godmin-fade-out var(--wpds-motion-duration-sm) cubic-bezier(0, 0, 0.2, 1) forwards;
330
356
  }
331
357
 
332
358
  .godmin-toast--plain {
333
359
  margin: 0;
334
360
  border: 0;
335
361
  text-align: start;
336
- cursor: var(--wpds-cursor-control);
362
+ }
363
+
364
+ .godmin-toasts__item-inner > .godmin-toast {
365
+ margin-block-start: var(--wpds-dimension-gap-sm);
337
366
  }
338
367
 
339
368
  .godmin-toast__action {
@@ -355,17 +384,6 @@ body {
355
384
  text-decoration: none;
356
385
  }
357
386
 
358
- .godmin-toast__dismiss {
359
- flex: none;
360
- margin-inline-start: var(--wpds-dimension-gap-xl);
361
- padding: 0;
362
- border: 0;
363
- background: none;
364
- color: inherit;
365
- font: inherit;
366
- cursor: var(--wpds-cursor-control);
367
- }
368
-
369
387
  .godmin-toast--plain:focus-visible {
370
388
  box-shadow:
371
389
  inset 0 0 0 var(--wpds-border-width-xs) #fff,
@@ -373,8 +391,8 @@ body {
373
391
  }
374
392
 
375
393
  .godmin-toast__action:focus-visible {
376
- outline: var(--wpds-border-width-xs) dotted #fff;
377
- outline-offset: 2px;
394
+ outline: var(--wpds-border-width-focus) solid #fff;
395
+ outline-offset: var(--wpds-border-width-focus);
378
396
  border-radius: var(--wpds-border-radius-sm);
379
397
  text-decoration: none;
380
398
  }
@@ -959,16 +977,31 @@ body {
959
977
  outline-offset: 2px;
960
978
  }
961
979
 
962
- .godmin-loading-screen,
963
- .godmin-loading-rows {
980
+ .godmin-loading-screen {
981
+ display: flex;
982
+ flex: 1 0 auto;
983
+ align-items: center;
984
+ justify-content: center;
985
+ box-sizing: border-box;
986
+ min-block-size: 100vh;
987
+ padding: var(--wpds-dimension-padding-3xl);
964
988
  opacity: 0;
965
- animation: godmin-fade-in var(--wpds-motion-duration-md)
966
- var(--wpds-motion-easing-balanced) 150ms forwards;
989
+ animation: godmin-fade-in 500ms ease 200ms forwards;
990
+ }
991
+
992
+ .godmin-layout .godmin-loading-screen {
993
+ min-block-size: auto;
994
+ }
995
+
996
+ :is(.godmin-page, .godmin-navigation-screen, [role='dialog'], [role='alertdialog']) .godmin-loading-screen {
997
+ min-block-size: auto;
998
+ opacity: 1;
999
+ animation: none;
967
1000
  }
968
1001
 
969
- .godmin-arrival {
970
- animation: godmin-fade-in var(--wpds-motion-duration-md)
971
- var(--wpds-motion-easing-balanced);
1002
+ .godmin-page .godmin-loading-screen {
1003
+ flex: none;
1004
+ padding: 0;
972
1005
  }
973
1006
 
974
1007
  @keyframes godmin-fade-in {
@@ -982,21 +1015,20 @@ body {
982
1015
  }
983
1016
 
984
1017
  @keyframes godmin-fade-out {
985
- 0% {
986
- opacity: 1;
987
- }
988
-
989
1018
  100% {
990
1019
  opacity: 0;
991
1020
  }
992
1021
  }
993
1022
 
994
1023
  @media (prefers-reduced-motion: reduce) {
995
- .godmin-loading-screen,
996
- .godmin-loading-rows,
997
- .godmin-arrival,
1024
+ .godmin-loading-screen {
1025
+ animation-duration: 0s;
1026
+ }
1027
+
1028
+ .godmin-toasts__item,
998
1029
  .godmin-toast {
999
1030
  animation-duration: 1ms;
1031
+ animation-delay: 0s;
1000
1032
  }
1001
1033
 
1002
1034
  .godmin-navigation__screen-wrapper {
@@ -1004,43 +1036,6 @@ body {
1004
1036
  }
1005
1037
  }
1006
1038
 
1007
- .godmin-loading-screen {
1008
- padding: var(--wpds-dimension-padding-xl);
1009
- }
1010
-
1011
- .godmin-loading-screen__ghost {
1012
- display: flex;
1013
- flex-direction: column;
1014
- gap: var(--wpds-dimension-gap-lg);
1015
- max-width: var(--wpds-dimension-surface-width-sm);
1016
- }
1017
-
1018
- .godmin-loading-screen__title {
1019
- height: 32px;
1020
- width: 40%;
1021
- border-radius: var(--wpds-border-radius-sm);
1022
- }
1023
-
1024
- .godmin-loading-screen__stroke {
1025
- height: 14px;
1026
- border-radius: var(--wpds-border-radius-sm);
1027
- }
1028
-
1029
- .godmin-loading-screen__stroke:last-child {
1030
- width: 70%;
1031
- }
1032
-
1033
- .godmin-loading-rows__ghost {
1034
- display: flex;
1035
- flex-direction: column;
1036
- gap: var(--wpds-dimension-gap-sm);
1037
- }
1038
-
1039
- .godmin-loading-rows__row {
1040
- height: var(--wpds-dimension-size-lg);
1041
- border-radius: var(--wpds-border-radius-sm);
1042
- }
1043
-
1044
1039
  .godmin-rows__row:focus-visible {
1045
1040
  outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus);
1046
1041
  outline-offset: 2px;
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export type { ListEmptyProps } from './list-empty.js';
27
27
  export { focusInDialog, useListRun } from './list-run.js';
28
28
  export type { ListRun, ListRunState, RunSettled } from './list-run.js';
29
29
  export type { LayoutDefaults, ListDefaults, ListFilter, ListSearch, ListSortDirection, ListView, ListViewShape, } from './list-view.js';
30
- export { LoadingRows, LoadingScreen } from './loading.js';
30
+ export { LoadingScreen } from './loading.js';
31
31
  export { LogItem, LogList, LogTime } from './log-list.js';
32
32
  export type { LogItemProps, LogListProps, LogTimeProps } from './log-list.js';
33
33
  export { MenuCount } from './menu-count.js';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export { keyFromLabel } from './keys.js';
14
14
  export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
15
15
  export { ListEmpty } from './list-empty.js';
16
16
  export { focusInDialog, useListRun } from './list-run.js';
17
- export { LoadingRows, LoadingScreen } from './loading.js';
17
+ export { LoadingScreen } from './loading.js';
18
18
  export { LogItem, LogList, LogTime } from './log-list.js';
19
19
  export { MenuCount } from './menu-count.js';
20
20
  export { NavigationScreen } from './navigation-screen.js';
package/dist/loading.d.ts CHANGED
@@ -1,17 +1,8 @@
1
1
  /**
2
- * Renders a content-shaped ghost while a screen's data loads.
2
+ * Renders the design system spinner in place of a screen's content while it loads.
3
3
  * @param props - The label a screen reader announces.
4
4
  * @returns The loading screen element.
5
5
  */
6
6
  export declare function LoadingScreen({ label }: {
7
7
  label: string;
8
8
  }): import("react").JSX.Element;
9
- /**
10
- * Renders a stack of row-shaped ghosts while a list's data loads.
11
- * @param props - The label a screen reader announces and the row count.
12
- * @returns The loading rows element.
13
- */
14
- export declare function LoadingRows({ label, rows }: {
15
- label: string;
16
- rows?: number;
17
- }): import("react").JSX.Element;
package/dist/loading.js CHANGED
@@ -1,20 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Skeleton, VisuallyHidden } from '@wordpress/ui';
4
- const STROKES = 3;
3
+ import { Spinner, VisuallyHidden } from '@wordpress/ui';
5
4
  /**
6
- * Renders a content-shaped ghost while a screen's data loads.
5
+ * Renders the design system spinner in place of a screen's content while it loads.
7
6
  * @param props - The label a screen reader announces.
8
7
  * @returns The loading screen element.
9
8
  */
10
9
  export function LoadingScreen({ label }) {
11
- return (_jsxs("div", { className: "godmin-loading-screen", children: [_jsx(VisuallyHidden, { role: "status", children: label }), _jsxs("div", { className: "godmin-loading-screen__ghost", "aria-hidden": "true", children: [_jsx(Skeleton, { className: "godmin-loading-screen__title" }), Array.from({ length: STROKES }, (_, stroke) => (_jsx(Skeleton, { className: "godmin-loading-screen__stroke" }, stroke)))] })] }));
12
- }
13
- /**
14
- * Renders a stack of row-shaped ghosts while a list's data loads.
15
- * @param props - The label a screen reader announces and the row count.
16
- * @returns The loading rows element.
17
- */
18
- export function LoadingRows({ label, rows = 5 }) {
19
- return (_jsxs("div", { className: "godmin-loading-rows", children: [_jsx(VisuallyHidden, { role: "status", children: label }), _jsx("div", { className: "godmin-loading-rows__ghost", "aria-hidden": "true", children: Array.from({ length: rows }, (_, row) => (_jsx(Skeleton, { className: "godmin-loading-rows__row" }, row))) })] }));
10
+ return (_jsxs("div", { className: "godmin-loading-screen", children: [_jsx(VisuallyHidden, { role: "status", children: label }), _jsx(Spinner, {})] }));
20
11
  }
package/dist/toaster.d.ts CHANGED
@@ -5,8 +5,6 @@ export interface ToastAction {
5
5
  }
6
6
  export interface ToasterHandle {
7
7
  show: (message: string, action?: ToastAction) => void;
8
- /** The title cut to the toaster's name length, with an ellipsis when cut. */
9
- name: (title: string) => string;
10
8
  }
11
9
  /**
12
10
  * Returns the handle raising messages in the toast region.
@@ -16,18 +14,18 @@ export declare function useToaster(): ToasterHandle;
16
14
  export interface ToasterProps {
17
15
  /** The tree the toast region wraps. */
18
16
  children: ReactNode;
19
- /** How many milliseconds a toast nobody touches stays on screen. */
17
+ /** How many milliseconds a toast with no action stays on screen when nobody touches it. */
20
18
  dismissAfter?: number;
21
- /** The name of the close button, also the hint screen readers hear that a click clears a plain toast. */
19
+ /** How many milliseconds a toast with an action stays on screen when nobody touches it. */
20
+ actionDismissAfter?: number;
21
+ /** The hint screen readers hear after the message of a plain toast, that a click clears it. */
22
22
  dismissLabel?: string;
23
23
  /** How many toasts stay on screen at once, the oldest leaving first. */
24
24
  limit?: number;
25
- /** How many characters of a name a toast shows before the ellipsis. */
26
- nameLength?: number;
27
25
  }
28
26
  /**
29
- * Renders the region holding raised messages around the given tree.
30
- * @param props - The tree the region wraps, the toast time, the close button name, how many stay and the name length.
27
+ * Renders the region holding raised messages around the given tree, under the snackbar corners at every preset.
28
+ * @param props - The tree the region wraps, the time of each kind of toast, the plain toast hint and how many stay.
31
29
  * @returns The wrapped tree with its region.
32
30
  */
33
- export declare function Toaster({ children, dismissAfter, dismissLabel, limit, nameLength, }: ToasterProps): import("react").JSX.Element;
31
+ export declare function Toaster({ children, dismissAfter, actionDismissAfter, dismissLabel, limit, }: ToasterProps): import("react").JSX.Element;
package/dist/toaster.js CHANGED
@@ -2,45 +2,24 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /* oxlint-disable react/only-export-components -- the region ships beside the
3
3
  hook that reaches it. */
4
4
  import { speak } from '@wordpress/a11y';
5
+ import { ThemeProvider } from '@wordpress/theme';
5
6
  import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
6
7
  /**
7
- * How long a toast nobody touches stays on screen.
8
+ * How long a toast with no action stays on screen when nobody touches it.
8
9
  */
9
10
  const DISMISS_AFTER = 6000;
10
11
  /**
11
- * The name of the control clearing a toast.
12
+ * How long a toast with an action stays on screen when nobody touches it, time to read it and then act.
12
13
  */
13
- const DISMISS_LABEL = 'Dismiss';
14
+ const ACTION_DISMISS_AFTER = 10000;
14
15
  /**
15
- * The cross the WordPress snackbar draws in its close button.
16
+ * The hint telling a screen reader that a click clears a plain toast.
16
17
  */
17
- const DISMISS_GLYPH = '✕';
18
+ const DISMISS_LABEL = 'Dismiss this notice';
18
19
  /**
19
20
  * How many toasts stay on screen at once.
20
21
  */
21
22
  const LIMIT = 3;
22
- /**
23
- * How many characters of a name a toast shows before the ellipsis.
24
- */
25
- const NAME_LENGTH = 45;
26
- /**
27
- * The mark that ends a name a toast cut short.
28
- */
29
- const ELLIPSIS = '…';
30
- /**
31
- * Returns a title cut to the given number of characters, its trailing spaces trimmed and an ellipsis added.
32
- * @param title - The title to name.
33
- * @param length - How many characters to keep.
34
- * @returns The title whole when it fits, the cut title otherwise.
35
- */
36
- function cutName(title, length) {
37
- const characters = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
38
- const parts = Array.from(characters.segment(title), (part) => part.segment);
39
- if (parts.length <= length) {
40
- return title;
41
- }
42
- return `${parts.slice(0, length).join('').trimEnd()}${ELLIPSIS}`;
43
- }
44
23
  const ToasterContext = createContext(null);
45
24
  /**
46
25
  * Returns the handle raising messages in the toast region.
@@ -66,23 +45,25 @@ function admit(held, arriving, limit) {
66
45
  return [...held.map((toast) => (pushed.has(toast.id) ? { ...toast, leaving: true } : toast)), arriving];
67
46
  }
68
47
  /**
69
- * Returns the fades running on an element, none where the browser cannot report them.
48
+ * Returns the animations running on an element and inside it, none where the browser cannot report them.
70
49
  * @param element - The element to ask.
71
50
  * @returns The running animations.
72
51
  */
73
- function runningFades(element) {
74
- return typeof element.getAnimations === 'function' ? element.getAnimations() : [];
52
+ function runningMotion(element) {
53
+ return typeof element.getAnimations === 'function' ? element.getAnimations({ subtree: true }) : [];
75
54
  }
76
55
  /**
77
- * Returns the ref of a toast element that gives up focus as the toast leaves and drops the toast once faded.
78
- * @param toast - The toast the element draws.
56
+ * Returns the ref of a toast item that gives up focus as the toast leaves and drops the toast once its motion ends,
57
+ * or at once when the toast was already leaving as it first showed.
58
+ * @param toast - The toast the item holds.
79
59
  * @param region - The toast region taking the focus a leaving toast held.
80
60
  * @param onGone - The handler dropping a toast that finished leaving.
81
- * @returns The ref to attach to the toast element.
61
+ * @returns The ref to attach to the item element.
82
62
  */
83
63
  function useDeparture(toast, region, onGone) {
84
64
  const ref = useRef(null);
85
65
  const { id, leaving } = toast;
66
+ const leavingAtMount = useRef(leaving);
86
67
  useLayoutEffect(() => {
87
68
  if (!leaving) {
88
69
  return;
@@ -92,12 +73,12 @@ function useDeparture(toast, region, onGone) {
92
73
  if (element.contains(document.activeElement)) {
93
74
  holder.focus();
94
75
  }
95
- const fades = runningFades(element);
96
- if (fades.length === 0) {
76
+ const motion = leavingAtMount.current ? [] : runningMotion(element);
77
+ if (motion.length === 0) {
97
78
  onGone(id);
98
79
  return;
99
80
  }
100
- Promise.allSettled(fades.map((fade) => fade.finished)).then(() => onGone(id));
81
+ Promise.allSettled(motion.map((animation) => animation.finished)).then(() => onGone(id));
101
82
  }, [id, leaving, region, onGone]);
102
83
  return ref;
103
84
  }
@@ -126,35 +107,43 @@ function useExpiry(toast, dismissAfter, onLeave) {
126
107
  function toastClass(base, leaving) {
127
108
  return leaving ? `${base} godmin-toast--leaving` : base;
128
109
  }
110
+ /**
111
+ * Renders the item that holds a toast in the region, its space growing as the toast arrives and closing once it left.
112
+ * @param props - The toast, the region, the handler dropping a toast that finished leaving, and the toast element.
113
+ * @returns The item element.
114
+ */
115
+ function ToastItem({ toast, region, onGone, children }) {
116
+ const ref = useDeparture(toast, region, onGone);
117
+ const item = toast.leaving ? 'godmin-toasts__item godmin-toasts__item--leaving' : 'godmin-toasts__item';
118
+ return (_jsx("div", { ref: ref, className: item, children: _jsx("div", { className: "godmin-toasts__item-inner", children: children }) }));
119
+ }
129
120
  /**
130
121
  * Renders a toast with no action as one button that clears it, described by the dismiss hint.
131
- * @param props - The toast, how long it stays, the id of the dismiss hint, the region and the handlers clearing it.
122
+ * @param props - The toast, how long it stays, the id of the dismiss hint and the handler clearing it.
132
123
  * @returns The toast element.
133
124
  */
134
- function PlainToast({ toast, dismissAfter, hint, region, onLeave, onGone, }) {
125
+ function PlainToast({ toast, dismissAfter, hint, onLeave }) {
135
126
  useExpiry(toast, dismissAfter, onLeave);
136
- const ref = useDeparture(toast, region, onGone);
137
- return (_jsx("button", { ref: ref, type: "button", className: toastClass('godmin-toast godmin-toast--plain', toast.leaving), "aria-describedby": hint, inert: toast.leaving, onClick: () => onLeave(toast.id), children: toast.message }));
127
+ return (_jsx("button", { type: "button", className: toastClass('godmin-toast godmin-toast--plain', toast.leaving), "aria-describedby": hint, inert: toast.leaving, onClick: () => onLeave(toast.id), children: toast.message }));
138
128
  }
139
129
  /**
140
- * Renders a toast with its action and a close button beside it.
141
- * @param props - The toast, its action, its time, the close button name, the region and the handlers clearing it.
130
+ * Renders a toast with its action, cleared by a click anywhere on it, the action its only control.
131
+ * @param props - The toast, its action, its time and the handler clearing it.
142
132
  * @returns The toast element.
143
133
  */
144
- function ActionToast({ toast, action, dismissAfter, dismissLabel, region, onLeave, onGone, }) {
134
+ function ActionToast({ toast, action, dismissAfter, onLeave }) {
145
135
  useExpiry(toast, dismissAfter, onLeave);
146
- const ref = useDeparture(toast, region, onGone);
147
- return (_jsxs("div", { ref: ref, className: toastClass('godmin-toast', toast.leaving), inert: toast.leaving, children: [_jsx("span", { className: "godmin-toast__message", children: toast.message }), _jsx("button", { type: "button", className: "godmin-toast__action", onClick: () => {
148
- action.onAct();
136
+ return (_jsxs("div", { className: toastClass('godmin-toast', toast.leaving), inert: toast.leaving, onClick: () => onLeave(toast.id), children: [_jsx("span", { className: "godmin-toast__message", children: toast.message }), _jsx("button", { type: "button", className: "godmin-toast__action", onClick: () => {
149
137
  onLeave(toast.id);
150
- }, children: action.label }), _jsx("button", { type: "button", className: "godmin-toast__dismiss", "aria-label": dismissLabel, onClick: () => onLeave(toast.id), children: DISMISS_GLYPH })] }));
138
+ action.onAct();
139
+ }, children: action.label })] }));
151
140
  }
152
141
  /**
153
- * Renders the region holding raised messages around the given tree.
154
- * @param props - The tree the region wraps, the toast time, the close button name, how many stay and the name length.
142
+ * Renders the region holding raised messages around the given tree, under the snackbar corners at every preset.
143
+ * @param props - The tree the region wraps, the time of each kind of toast, the plain toast hint and how many stay.
155
144
  * @returns The wrapped tree with its region.
156
145
  */
157
- export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, limit = LIMIT, nameLength = NAME_LENGTH, }) {
146
+ export function Toaster({ children, dismissAfter = DISMISS_AFTER, actionDismissAfter = ACTION_DISMISS_AFTER, dismissLabel = DISMISS_LABEL, limit = LIMIT, }) {
158
147
  const [toasts, setToasts] = useState([]);
159
148
  const nextId = useRef(0);
160
149
  const region = useRef(null);
@@ -180,8 +169,7 @@ export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel =
180
169
  speak(message, 'polite');
181
170
  setToasts((held) => admit(held, { id, message, action, leaving: false }, limit));
182
171
  }, [limit]);
183
- const name = useCallback((title) => cutName(title, nameLength), [nameLength]);
184
- const handle = useMemo(() => ({ show, name }), [show, name]);
172
+ const handle = useMemo(() => ({ show }), [show]);
185
173
  const hint = useId();
186
- return (_jsxs(ToasterContext.Provider, { value: handle, children: [children, _jsx("div", { ref: region, className: "godmin-toasts", tabIndex: -1, children: toasts.map((toast) => toast.action === undefined ? (_jsx(PlainToast, { toast: toast, dismissAfter: dismissAfter, hint: hint, region: region, onLeave: leave, onGone: gone }, toast.id)) : (_jsx(ActionToast, { toast: toast, action: toast.action, dismissAfter: dismissAfter, dismissLabel: dismissLabel, region: region, onLeave: leave, onGone: gone }, toast.id))) }), _jsx("span", { id: hint, hidden: true, children: dismissLabel })] }));
174
+ return (_jsxs(ToasterContext.Provider, { value: handle, children: [children, _jsx(ThemeProvider, { cornerRadius: "subtle", children: _jsx("div", { ref: region, className: "godmin-toasts", tabIndex: -1, children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, region: region, onGone: gone, children: toast.action === undefined ? (_jsx(PlainToast, { toast: toast, dismissAfter: dismissAfter, hint: hint, onLeave: leave })) : (_jsx(ActionToast, { toast: toast, action: toast.action, dismissAfter: actionDismissAfter, onLeave: leave })) }, toast.id))) }) }), _jsx("span", { id: hint, hidden: true, children: dismissLabel })] }));
187
175
  }
@@ -100,6 +100,35 @@ the same peer ranges.
100
100
  follows the filter rules of that DataViews release. A list built on
101
101
  another release gets a peer warning when it installs godmin.
102
102
 
103
+ ## Upgrading from godmin 0.27.0
104
+
105
+ godmin 0.28.0 draws toasts as WordPress's new admin draws its
106
+ snackbars. Change your code in these places:
107
+
108
+ - `useToaster().name` and the `nameLength` prop of `Toaster` are gone.
109
+ Put the name in the message as it is. A long name wraps.
110
+ - `dismissAfter` now times only a toast with no action. Pass
111
+ `actionDismissAfter` to time a toast with an action. It stays 10
112
+ seconds when you pass nothing.
113
+ - A toast with an action has no close button. A click anywhere on it
114
+ clears it, so a test that pressed the close button clicks the toast
115
+ instead. A stylesheet that styles `.godmin-toast__dismiss` styles
116
+ nothing now.
117
+ - `dismissLabel` is now only the hint of a toast with no action, and
118
+ its default is `Dismiss this notice`, WordPress's words. A test that
119
+ reads the old hint, `Dismiss`, reads the new one.
120
+ - A toast now sits in a `.godmin-toasts__item` element inside
121
+ `.godmin-toasts`. A selector such as `.godmin-toasts > .godmin-toast`,
122
+ or code that reads the children of the region as toasts, reaches the
123
+ toast through that element.
124
+ - A toast now rises into place as it arrives, as
125
+ [Motion](./design-system/toasts.md#motion) shows. A browser test that
126
+ measures where a toast sits waits for that motion to end, or runs
127
+ with a reduced motion preference.
128
+
129
+ TypeScript points at each call to `name` and at `nameLength`. The rest
130
+ changes only what the reader sees.
131
+
103
132
  ## Upgrading from godmin 0.24.0
104
133
 
105
134
  godmin 0.25.0 gives the sidebar parts the names WordPress gives them.