@gopherium/godmin 0.13.0 → 0.14.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
@@ -47,7 +47,7 @@ two lines do for you.
47
47
 
48
48
  | Entry point | Contents |
49
49
  | --- | --- |
50
- | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `SectionTitle`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
50
+ | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
51
51
  | `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
52
52
  | `@gopherium/godmin/router` | `useCanvas`, `useFrameLocation`, the `canvas` route static data |
53
53
  | `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR` |
@@ -0,0 +1,21 @@
1
+ /** A circle colour of the initials avatar and the colour its letter takes on it. */
2
+ export interface AvatarColor {
3
+ /** The circle colour as #rrggbb. */
4
+ background: string;
5
+ /** The letter colour as #rrggbb. */
6
+ letter: string;
7
+ }
8
+ /**
9
+ * The colours an initials avatar paints with, the WordPress blue, raspberry and purple first with their pale letters.
10
+ */
11
+ export declare const AVATAR_COLORS: readonly AvatarColor[];
12
+ export interface InitialsAvatarProps {
13
+ /** The name the avatar stands for, whose first letter it draws. */
14
+ name: string;
15
+ }
16
+ /**
17
+ * Renders a round avatar with the first letter of a name, in the letter colour of the circle colour the name picks.
18
+ * @param props - The name the avatar stands for.
19
+ * @returns The avatar element.
20
+ */
21
+ export declare function InitialsAvatar({ name }: InitialsAvatarProps): import("react").JSX.Element;
package/dist/avatar.js ADDED
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The colours an initials avatar paints with, the WordPress blue, raspberry and purple first with their pale letters.
4
+ */
5
+ export const AVATAR_COLORS = [
6
+ { background: '#3b59e4', letter: '#f7ecbd' },
7
+ { background: '#c6396e', letter: '#ecfaf4' },
8
+ { background: '#964c9a', letter: '#deefdd' },
9
+ { background: '#007017', letter: '#ffffff' },
10
+ { background: '#996800', letter: '#ffffff' },
11
+ { background: '#50575e', letter: '#ffffff' },
12
+ ];
13
+ /**
14
+ * Returns the palette colours a name always gets, whatever its case.
15
+ * @param name - The name the avatar stands for.
16
+ * @returns The circle and letter colours.
17
+ */
18
+ function colorFor(name) {
19
+ let hash = 0;
20
+ for (const letter of name.trim().toLocaleLowerCase()) {
21
+ hash = (hash * 31 + letter.codePointAt(0)) % 2147483647;
22
+ }
23
+ return AVATAR_COLORS[hash % AVATAR_COLORS.length];
24
+ }
25
+ /**
26
+ * Returns the first letter of a name in capitals, or nothing for an empty name.
27
+ * @param name - The name the avatar stands for.
28
+ * @returns The letter to draw.
29
+ */
30
+ function initialOf(name) {
31
+ const [first = ''] = Array.from(name.trim());
32
+ return first.toLocaleUpperCase();
33
+ }
34
+ /**
35
+ * Renders a round avatar with the first letter of a name, in the letter colour of the circle colour the name picks.
36
+ * @param props - The name the avatar stands for.
37
+ * @returns The avatar element.
38
+ */
39
+ export function InitialsAvatar({ name }) {
40
+ const { background, letter } = colorFor(name);
41
+ return (_jsx("span", { className: "godmin-avatar", "aria-hidden": "true", style: { backgroundColor: background, color: letter }, children: initialOf(name) }));
42
+ }
package/dist/base.css CHANGED
@@ -12,6 +12,75 @@ body {
12
12
  position: relative;
13
13
  }
14
14
 
15
+ /* Keeps the sticky DataViews toolbar and filters of a list page at the edge the list reaches. */
16
+ .godmin-page > .godmin-page__list :is(.dataviews__view-actions, .dataviews-filters__container) {
17
+ inset-inline-start: calc(-1 * var(--godmin-canvas-gutter, 0px));
18
+ }
19
+
20
+ /* Keeps the sticky DataViews footer of a list page on the canvas bottom the list reaches. */
21
+ .godmin-page > .godmin-page__list .dataviews-footer {
22
+ inset-block-end: calc(-1 * var(--godmin-canvas-gutter-block, 0px));
23
+ }
24
+
25
+ /* Draws a DataViews title link without an underline, as WordPress does. */
26
+ .dataviews-title-field--clickable {
27
+ text-decoration: none;
28
+ }
29
+
30
+ /* Draws a DataViews media link without an underline or the browser link colour. */
31
+ .dataviews-column-primary__media--clickable {
32
+ color: inherit;
33
+ text-decoration: none;
34
+ }
35
+
36
+ /* Sets the name 8px after an initials avatar in a DataViews table. */
37
+ .dataviews-column-primary__media:has(> .godmin-avatar) {
38
+ margin-inline-end: calc(var(--wpds-dimension-gap-sm) - var(--wpds-dimension-gap-md));
39
+ }
40
+
41
+ /* Fills the larger media box of the DataViews list with an initials avatar. */
42
+ .dataviews-view-list .dataviews-view-list__media-wrapper:has(> .godmin-avatar) {
43
+ container-type: size;
44
+ }
45
+
46
+ .dataviews-view-list .dataviews-view-list__media-wrapper > .godmin-avatar {
47
+ inline-size: 100%;
48
+ block-size: 100%;
49
+ font-size: 37.5cqi;
50
+ }
51
+
52
+ /* Rounds the DataViews media box around an initials avatar. */
53
+ .dataviews-column-primary__media:has(> .godmin-avatar),
54
+ .dataviews-view-list .dataviews-view-list__media-wrapper:has(> .godmin-avatar) {
55
+ border-radius: 50%;
56
+ }
57
+
58
+ /* Drops the dark DataViews media ring around an initials avatar. */
59
+ .dataviews-column-primary__media:has(> .godmin-avatar)::after,
60
+ .dataviews-view-list .dataviews-view-list__media-wrapper:has(> .godmin-avatar)::after {
61
+ box-shadow: none;
62
+ }
63
+
64
+ /* Centres the media of a list row on its title and description. */
65
+ .godmin-page__list .dataviews-view-table tbody .dataviews-column-primary__media {
66
+ align-self: center;
67
+ }
68
+
69
+ /* Sets a list title and its description as the WordPress list does, a 64px row for both. */
70
+ .godmin-page__list .dataviews-view-table tbody .dataviews-view-table__primary-column-content {
71
+ justify-content: center;
72
+ gap: var(--wpds-dimension-gap-xs);
73
+ min-block-size: var(--wpds-dimension-size-md);
74
+ font-size: var(--wpds-typography-font-size-sm);
75
+ line-height: var(--wpds-typography-line-height-xs);
76
+ }
77
+
78
+ .godmin-page__list .dataviews-view-table tbody .dataviews-view-table__primary-column-content > .dataviews-title-field {
79
+ min-block-size: 0;
80
+ font-weight: var(--wpds-typography-font-weight-default);
81
+ line-height: var(--wpds-typography-line-height-sm);
82
+ }
83
+
15
84
  @layer godmin {
16
85
  body {
17
86
  margin: 0;
@@ -22,6 +91,11 @@ body {
22
91
  }
23
92
 
24
93
  @layer godmin {
94
+ :root {
95
+ --godmin-rail-width: 300px;
96
+ --godmin-canvas-margin: 16px;
97
+ }
98
+
25
99
  .godmin-layout {
26
100
  display: flex;
27
101
  height: 100vh;
@@ -38,7 +112,7 @@ body {
38
112
  display: flex;
39
113
  flex-direction: column;
40
114
  flex-shrink: 0;
41
- width: 300px;
115
+ width: var(--godmin-rail-width);
42
116
  padding: 16px;
43
117
  box-sizing: border-box;
44
118
  overflow-y: auto;
@@ -49,7 +123,28 @@ body {
49
123
  flex-shrink: 0;
50
124
  align-items: center;
51
125
  gap: 8px;
52
- padding: 8px 16px;
126
+ block-size: 46px;
127
+ padding-inline-end: 16px;
128
+ }
129
+
130
+ .godmin-layout__menu {
131
+ display: flex;
132
+ flex: none;
133
+ padding: 0;
134
+ border: 0;
135
+ background: none;
136
+ color: color-mix(in srgb, var(--wpds-color-foreground-content-neutral) 60%, transparent);
137
+ cursor: var(--wpds-cursor-control);
138
+ }
139
+
140
+ .godmin-layout__menu:is(:hover, :focus-visible) {
141
+ background: var(--wpds-color-background-interactive-neutral-weak-active);
142
+ color: var(--wpds-color-foreground-interactive-brand);
143
+ }
144
+
145
+ .godmin-layout__menu:focus-visible {
146
+ outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus);
147
+ outline-offset: calc(-1 * var(--wpds-border-width-focus));
53
148
  }
54
149
 
55
150
  .godmin-layout__drawer {
@@ -61,15 +156,18 @@ body {
61
156
  }
62
157
 
63
158
  .godmin-layout__canvas {
159
+ --godmin-canvas-gutter: 24px;
160
+ --godmin-canvas-gutter-block: var(--wpds-dimension-padding-lg);
161
+ --wp-dataviews-color-background: var(--wpds-color-background-surface-neutral-strong);
64
162
  display: flex;
65
163
  flex-direction: column;
66
164
  flex: 1;
67
165
  min-width: 0;
68
- margin: 16px;
69
- padding: 24px;
166
+ margin: var(--godmin-canvas-margin);
167
+ padding: var(--godmin-canvas-gutter-block) var(--godmin-canvas-gutter);
70
168
  box-sizing: border-box;
71
169
  border-radius: var(--wpds-border-radius-xl);
72
- background: var(--wpds-color-background-surface-neutral);
170
+ background: var(--wpds-color-background-surface-neutral-strong);
73
171
  color: var(--wpds-color-foreground-content-neutral);
74
172
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
75
173
  overflow-x: hidden;
@@ -77,17 +175,116 @@ body {
77
175
  }
78
176
 
79
177
  .godmin-layout__canvas--bleed {
80
- padding: 0;
178
+ --godmin-canvas-gutter: 0px;
179
+ --godmin-canvas-gutter-block: 0px;
81
180
  overflow: hidden;
82
181
  }
83
182
 
183
+ .godmin-layout:has(> .godmin-layout__rail) .godmin-layout__canvas {
184
+ margin-inline-start: 0;
185
+ }
186
+
84
187
  .godmin-toasts {
85
188
  position: fixed;
86
- left: 16px;
87
- bottom: 16px;
189
+ inset-inline: 0;
190
+ bottom: 32px;
88
191
  z-index: 1;
89
- width: 360px;
90
- max-width: calc(100vw - 32px);
192
+ display: flex;
193
+ flex-direction: column;
194
+ align-items: center;
195
+ gap: var(--wpds-dimension-gap-sm);
196
+ padding-inline: 16px;
197
+ box-sizing: border-box;
198
+ pointer-events: none;
199
+ }
200
+
201
+ :root:has(.godmin-layout__rail) .godmin-toasts {
202
+ inset-inline-start: var(--godmin-rail-width);
203
+ inset-inline-end: var(--godmin-canvas-margin);
204
+ }
205
+
206
+ .godmin-toasts:focus {
207
+ outline: none;
208
+ }
209
+
210
+ .godmin-toast {
211
+ display: flex;
212
+ align-items: baseline;
213
+ justify-content: space-between;
214
+ width: fit-content;
215
+ max-width: var(--wpds-dimension-surface-width-lg);
216
+ box-sizing: border-box;
217
+ padding: var(--wpds-dimension-padding-md) var(--wpds-dimension-padding-xl);
218
+ border-radius: var(--wpds-border-radius-md);
219
+ background: rgb(0 0 0 / 0.85);
220
+ backdrop-filter: blur(16px) saturate(180%);
221
+ box-shadow:
222
+ 0 1px 2px rgb(0 0 0 / 0.05),
223
+ 0 2px 3px rgb(0 0 0 / 0.04),
224
+ 0 6px 6px rgb(0 0 0 / 0.03),
225
+ 0 8px 8px rgb(0 0 0 / 0.02);
226
+ color: #fff;
227
+ font-family: var(--wpds-typography-font-family-body);
228
+ font-size: var(--wpds-typography-font-size-md);
229
+ line-height: 1.4;
230
+ overflow-wrap: anywhere;
231
+ cursor: default;
232
+ pointer-events: auto;
233
+ animation: godmin-fade-in var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced);
234
+ }
235
+
236
+ .godmin-toast--leaving {
237
+ animation: godmin-fade-out var(--wpds-motion-duration-sm) var(--wpds-motion-easing-balanced) forwards;
238
+ }
239
+
240
+ .godmin-toast--plain {
241
+ margin: 0;
242
+ border: 0;
243
+ text-align: start;
244
+ cursor: var(--wpds-cursor-control);
245
+ }
246
+
247
+ .godmin-toast__action {
248
+ flex: none;
249
+ margin-inline-start: var(--wpds-dimension-gap-2xl);
250
+ padding: 0;
251
+ border: 0;
252
+ background: none;
253
+ color: inherit;
254
+ font: inherit;
255
+ line-height: normal;
256
+ text-decoration: underline;
257
+ text-underline-offset: 0.2em;
258
+ text-decoration-thickness: from-font;
259
+ cursor: var(--wpds-cursor-control);
260
+ }
261
+
262
+ .godmin-toast__action:hover {
263
+ text-decoration: none;
264
+ }
265
+
266
+ .godmin-toast__dismiss {
267
+ flex: none;
268
+ margin-inline-start: var(--wpds-dimension-gap-xl);
269
+ padding: 0;
270
+ border: 0;
271
+ background: none;
272
+ color: inherit;
273
+ font: inherit;
274
+ cursor: var(--wpds-cursor-control);
275
+ }
276
+
277
+ .godmin-toast--plain:focus-visible {
278
+ box-shadow:
279
+ inset 0 0 0 var(--wpds-border-width-xs) #fff,
280
+ 0 0 0 var(--wpds-border-width-focus) var(--wpds-color-stroke-focus);
281
+ }
282
+
283
+ .godmin-toast__action:focus-visible {
284
+ outline: var(--wpds-border-width-xs) dotted #fff;
285
+ outline-offset: 2px;
286
+ border-radius: var(--wpds-border-radius-sm);
287
+ text-decoration: none;
91
288
  }
92
289
 
93
290
  .godmin-nav-screen__title {
@@ -114,7 +311,12 @@ body {
114
311
  color: var(--wpds-color-foreground-content-neutral-weak);
115
312
  }
116
313
 
314
+ .godmin-page__head {
315
+ min-block-size: var(--wpds-dimension-size-lg);
316
+ }
317
+
117
318
  .godmin-page__subtitle {
319
+ padding-block-end: var(--wpds-dimension-padding-xs);
118
320
  color: var(--wpds-color-foreground-content-neutral-weak);
119
321
  }
120
322
 
@@ -139,6 +341,111 @@ body {
139
341
  display: none;
140
342
  }
141
343
 
344
+ .godmin-page:has(> .godmin-page__list) {
345
+ flex: 1 0 auto;
346
+ }
347
+
348
+ .godmin-page:has(> .godmin-page__list > .dataviews-wrapper) {
349
+ flex-shrink: 1;
350
+ min-block-size: 0;
351
+ }
352
+
353
+ .godmin-page > .godmin-page__list,
354
+ .godmin-page__main > .godmin-page__list {
355
+ display: flex;
356
+ flex-direction: column;
357
+ gap: var(--wpds-dimension-gap-lg);
358
+ }
359
+
360
+ .godmin-page > .godmin-page__list {
361
+ flex: 1 0 auto;
362
+ margin-inline: calc(-1 * var(--godmin-canvas-gutter, 0px));
363
+ margin-block-end: calc(-1 * var(--godmin-canvas-gutter-block, 0px));
364
+ }
365
+
366
+ .godmin-page > .godmin-page__list:has(> .dataviews-wrapper) {
367
+ flex-shrink: 1;
368
+ min-block-size: 0;
369
+ }
370
+
371
+ .godmin-list {
372
+ margin-inline: calc(-1 * min(var(--wpds-dimension-padding-2xl), var(--godmin-canvas-gutter, 0px)));
373
+ }
374
+
375
+ .godmin-page > .godmin-page__list > :not(.dataviews-wrapper, .godmin-table-scroll, .godmin-table) {
376
+ margin-inline: var(--wpds-dimension-padding-2xl);
377
+ }
378
+
379
+ .godmin-page__tabs {
380
+ margin-inline: calc(-1 * var(--godmin-canvas-gutter, 0px));
381
+ padding-inline: var(--godmin-canvas-gutter, 0px);
382
+ border-block-end: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak);
383
+ }
384
+
385
+ .godmin-page:has(> .godmin-page__list) > .godmin-page__tabs {
386
+ padding-inline: var(--wpds-dimension-padding-2xl);
387
+ }
388
+
389
+ .godmin-page > .godmin-page__tabs + .godmin-page__list:has(> .dataviews-wrapper:first-child) {
390
+ margin-block-start: calc(-1 * var(--wpds-dimension-gap-lg));
391
+ }
392
+
393
+ .godmin-page-tabs {
394
+ display: flex;
395
+ gap: var(--wpds-dimension-gap-lg);
396
+ overflow-x: auto;
397
+ }
398
+
399
+ .godmin-page-tabs__tab {
400
+ display: flex;
401
+ align-items: center;
402
+ position: relative;
403
+ block-size: 48px;
404
+ padding: 0;
405
+ color: var(--wpds-color-foreground-interactive-neutral);
406
+ font-family: var(--wpds-typography-font-family-body);
407
+ font-size: var(--wpds-typography-font-size-md);
408
+ font-weight: var(--wpds-typography-font-weight-default);
409
+ line-height: 1.2;
410
+ text-decoration: none;
411
+ white-space: nowrap;
412
+ }
413
+
414
+ .godmin-page-tabs__tab:is(:hover, :focus-visible) {
415
+ color: var(--wpds-color-foreground-interactive-neutral-active);
416
+ }
417
+
418
+ .godmin-page-tabs__tab:focus-visible {
419
+ outline: none;
420
+ }
421
+
422
+ .godmin-page-tabs__tab::before {
423
+ content: '';
424
+ position: absolute;
425
+ inset: var(--wpds-dimension-padding-md) var(--wpds-border-width-focus);
426
+ border-radius: var(--wpds-border-radius-sm);
427
+ outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus);
428
+ opacity: 0;
429
+ pointer-events: none;
430
+ }
431
+
432
+ .godmin-page-tabs__tab:focus-visible::before {
433
+ opacity: 1;
434
+ }
435
+
436
+ .godmin-page-tabs__tab--current::after {
437
+ content: '';
438
+ position: absolute;
439
+ inset-inline: 0;
440
+ inset-block-end: 0;
441
+ block-size: var(--wpds-border-width-focus);
442
+ background: var(--wpds-color-stroke-interactive-neutral-strong);
443
+ }
444
+
445
+ .godmin-page:has(> .godmin-page__list) > .godmin-page__header {
446
+ padding-inline: calc(var(--wpds-dimension-padding-2xl) - var(--godmin-canvas-gutter, 0px));
447
+ }
448
+
142
449
  .godmin-form {
143
450
  display: flex;
144
451
  flex-direction: column;
@@ -183,19 +490,62 @@ body {
183
490
  .godmin-table {
184
491
  width: 100%;
185
492
  border-collapse: collapse;
493
+ font-size: var(--wpds-typography-font-size-md);
494
+ line-height: var(--wpds-typography-line-height-sm);
186
495
  text-align: left;
187
496
  }
188
497
 
189
498
  .godmin-table th,
190
499
  .godmin-table td {
191
- padding: 8px 12px;
192
- border-bottom: 1px solid var(--wpds-color-stroke-surface-neutral);
500
+ padding: var(--wpds-dimension-padding-md);
193
501
  vertical-align: middle;
194
502
  }
195
503
 
196
- .godmin-table th {
197
- font-size: var(--wpds-typography-font-size-sm);
198
- color: var(--wpds-color-foreground-content-neutral-weak);
504
+ .godmin-table thead th {
505
+ padding-block: var(--wpds-dimension-padding-sm);
506
+ font-size: var(--wpds-typography-font-size-xs);
507
+ font-weight: var(--wpds-typography-font-weight-emphasis);
508
+ text-transform: uppercase;
509
+ color: var(--wpds-color-foreground-content-neutral);
510
+ }
511
+
512
+ .godmin-table tbody tr {
513
+ border-block-start: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak);
514
+ }
515
+
516
+ .godmin-table tbody td {
517
+ height: var(--wpds-dimension-size-md);
518
+ }
519
+
520
+ .godmin-page > .godmin-page__list .godmin-table tr > :first-child {
521
+ padding-inline-start: var(--wpds-dimension-padding-2xl);
522
+ }
523
+
524
+ .godmin-page > .godmin-page__list .godmin-table tr > :last-child {
525
+ padding-inline-end: var(--wpds-dimension-padding-2xl);
526
+ }
527
+
528
+ .godmin-table__title {
529
+ font-weight: var(--wpds-typography-font-weight-emphasis);
530
+ color: var(--wpds-color-foreground-content-neutral);
531
+ }
532
+
533
+ .godmin-page__list .godmin-table__title {
534
+ font-weight: var(--wpds-typography-font-weight-default);
535
+ }
536
+
537
+ .godmin-table__title a {
538
+ color: var(--wpds-color-foreground-interactive-neutral);
539
+ text-decoration: none;
540
+ }
541
+
542
+ .godmin-table__title a:hover {
543
+ color: var(--wpds-color-foreground-interactive-brand);
544
+ }
545
+
546
+ .godmin-table__title a:focus-visible {
547
+ outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus);
548
+ outline-offset: 2px;
199
549
  }
200
550
 
201
551
  .godmin-table__actions {
@@ -203,6 +553,22 @@ body {
203
553
  white-space: nowrap;
204
554
  }
205
555
 
556
+ .godmin-avatar {
557
+ display: inline-block;
558
+ text-align: center;
559
+ align-content: center;
560
+ flex: none;
561
+ inline-size: var(--wpds-dimension-size-md);
562
+ block-size: var(--wpds-dimension-size-md);
563
+ border-radius: 50%;
564
+ font-family: var(--wpds-typography-font-family-body);
565
+ font-size: var(--wpds-typography-font-size-sm);
566
+ font-weight: var(--wpds-typography-font-weight-emphasis);
567
+ line-height: 1;
568
+ text-box: trim-both cap alphabetic;
569
+ user-select: none;
570
+ }
571
+
206
572
  .godmin-table__actions * {
207
573
  white-space: nowrap;
208
574
  }
@@ -238,10 +604,21 @@ body {
238
604
  }
239
605
  }
240
606
 
607
+ @keyframes godmin-fade-out {
608
+ 0% {
609
+ opacity: 1;
610
+ }
611
+
612
+ 100% {
613
+ opacity: 0;
614
+ }
615
+ }
616
+
241
617
  @media (prefers-reduced-motion: reduce) {
242
618
  .godmin-loading-screen,
243
619
  .godmin-loading-rows,
244
- .godmin-arrival {
620
+ .godmin-arrival,
621
+ .godmin-toast {
245
622
  animation-duration: 1ms;
246
623
  }
247
624
  }
@@ -370,16 +747,21 @@ body {
370
747
 
371
748
  /* Small viewport overrides live together at the end of the sheet, so they
372
749
  always win over the rules above them without extra specificity. */
373
- @media (max-width: 639px) {
750
+ @media (max-width: 781px) {
374
751
  .godmin-layout__canvas {
375
752
  margin: 0;
376
- padding: 16px;
377
753
  border-radius: 0;
378
754
  box-shadow: none;
379
755
  }
756
+ }
757
+
758
+ @media (max-width: 639px) {
759
+ .godmin-layout__canvas {
760
+ --godmin-canvas-gutter: 16px;
761
+ }
380
762
 
381
763
  .godmin-layout__canvas--bleed {
382
- padding: 0;
764
+ --godmin-canvas-gutter: 0px;
383
765
  }
384
766
 
385
767
  /* The region needs a containing block, or absolutely positioned content
@@ -392,7 +774,7 @@ body {
392
774
  .godmin-table-scroll .godmin-table__actions {
393
775
  position: sticky;
394
776
  inset-inline-end: 0;
395
- background: var(--wpds-color-background-surface-neutral);
777
+ background: var(--wpds-color-background-surface-neutral-strong);
396
778
  box-shadow: inset var(--wpds-border-width-xs) 0 0 var(--wpds-color-stroke-surface-neutral);
397
779
  }
398
780
 
@@ -400,4 +782,10 @@ body {
400
782
  box-shadow: inset calc(-1 * var(--wpds-border-width-xs)) 0 0 var(--wpds-color-stroke-surface-neutral);
401
783
  }
402
784
  }
785
+
786
+ @media (max-width: 599px) {
787
+ .godmin-toast {
788
+ width: 100%;
789
+ }
790
+ }
403
791
  }
@@ -3,7 +3,11 @@
3
3
  */
4
4
  export declare const RAIL_BREAKPOINT = 1024;
5
5
  /**
6
- * The viewport width below which the canvas meets the screen edges.
6
+ * The viewport width below which the canvas meets the screen edges, the WordPress medium breakpoint.
7
+ */
8
+ export declare const EDGE_BREAKPOINT = 782;
9
+ /**
10
+ * The viewport width below which the canvas gutter narrows to 16px.
7
11
  */
8
12
  export declare const DENSE_BREAKPOINT = 640;
9
13
  /**
@@ -3,7 +3,11 @@
3
3
  */
4
4
  export const RAIL_BREAKPOINT = 1024;
5
5
  /**
6
- * The viewport width below which the canvas meets the screen edges.
6
+ * The viewport width below which the canvas meets the screen edges, the WordPress medium breakpoint.
7
+ */
8
+ export const EDGE_BREAKPOINT = 782;
9
+ /**
10
+ * The viewport width below which the canvas gutter narrows to 16px.
7
11
  */
8
12
  export const DENSE_BREAKPOINT = 640;
9
13
  /**
package/dist/frame.js CHANGED
@@ -2,14 +2,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /* oxlint-disable react/only-export-components -- a compound component is an
3
3
  object export standing beside the parts it is built from. */
4
4
  import { ThemeProvider } from '@wordpress/theme';
5
- import { Drawer, IconButton, VisuallyHidden } from '@wordpress/ui';
5
+ import { Drawer, VisuallyHidden } from '@wordpress/ui';
6
6
  import { createContext, useContext, useEffect, useState } from 'react';
7
7
  import { SMALL_VIEWPORT } from './breakpoints.js';
8
8
  import { useMediaQuery } from './use-media-query.js';
9
9
  /**
10
- * The glyph on the button that opens the rail drawer.
10
+ * The glyph on the button that opens the rail drawer, drawn where the admin bar menu toggle draws its bars.
11
11
  */
12
- const menuIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M5 5v1.5h14V5H5zm0 7.8h14v-1.5H5v1.5zM5 19h14v-1.5H5V19z" }) }));
12
+ const menuIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "52", height: "46", viewBox: "0 0 52 46", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M11 11h28v4H11zm0 10h28v4H11zm0 10h28v4H11z" }) }));
13
13
  const FrameContext = createContext({ small: false, location: undefined, layout: null });
14
14
  /**
15
15
  * Frames an admin application, folding its rail away on a narrow viewport.
@@ -48,7 +48,7 @@ function TopBar({ children, brand, menuLabel, }) {
48
48
  useEffect(() => {
49
49
  setOpen(false);
50
50
  }, [location]);
51
- return (_jsxs("div", { className: "godmin-layout__topbar", children: [_jsxs(Drawer.Root, { open: open, onOpenChange: setOpen, children: [_jsx(Drawer.Trigger, { render: _jsx(IconButton, { icon: menuIcon, label: menuLabel }) }), _jsxs(Drawer.Popup, { className: "godmin-layout__drawer", portal: _jsx(Drawer.Portal, { container: layout }), children: [_jsx(VisuallyHidden, { render: _jsx(Drawer.Title, {}), children: menuLabel }), children] })] }), brand] }));
51
+ return (_jsxs("div", { className: "godmin-layout__topbar", children: [_jsxs(Drawer.Root, { open: open, onOpenChange: setOpen, children: [_jsx(Drawer.Trigger, { render: _jsx("button", { type: "button", className: "godmin-layout__menu", "aria-label": menuLabel }), children: menuIcon }), _jsxs(Drawer.Popup, { className: "godmin-layout__drawer", portal: _jsx(Drawer.Portal, { container: layout }), children: [_jsx(VisuallyHidden, { render: _jsx(Drawer.Title, {}), children: menuLabel }), children] })] }), brand] }));
52
52
  }
53
53
  /**
54
54
  * Renders the region showing the active screen.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  export { AdminRoot } from './admin-root.js';
2
2
  export type { AdminRootProps } from './admin-root.js';
3
- export { DENSE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
3
+ export { InitialsAvatar } from './avatar.js';
4
+ export type { InitialsAvatarProps } from './avatar.js';
5
+ export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
4
6
  export { Frame } from './frame.js';
5
7
  export type { CanvasMode, FrameCanvasProps, FrameRailProps, FrameRootProps, } from './frame.js';
6
8
  export { keyFromLabel } from './keys.js';
7
9
  export type { KeyOptions, KeyStyle } from './keys.js';
10
+ export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
11
+ export type { ListChromeCatalog } from './list-chrome.js';
8
12
  export { LoadingRows, LoadingScreen } from './loading.js';
9
13
  export { LogItem, LogList, LogTime } from './log-list.js';
10
14
  export type { LogItemProps, LogListProps, LogTimeProps } from './log-list.js';
@@ -12,6 +16,8 @@ export { NavScreen } from './nav-screen.js';
12
16
  export type { NavScreenProps } from './nav-screen.js';
13
17
  export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
14
18
  export type { LoadMoreQuery, PageProps } from './page.js';
19
+ export { PageTab, PageTabs } from './page-tabs.js';
20
+ export type { PageTabProps, PageTabsProps } from './page-tabs.js';
15
21
  export { useRowKeys } from './row-keys.js';
16
22
  export type { RowBounds, RowKeys } from './row-keys.js';
17
23
  export { RepeatRows, RowControls } from './rows.js';
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  export { AdminRoot } from './admin-root.js';
3
- export { DENSE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
3
+ export { InitialsAvatar } from './avatar.js';
4
+ export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
4
5
  export { Frame } from './frame.js';
5
6
  export { keyFromLabel } from './keys.js';
7
+ export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
6
8
  export { LoadingRows, LoadingScreen } from './loading.js';
7
9
  export { LogItem, LogList, LogTime } from './log-list.js';
8
10
  export { NavScreen } from './nav-screen.js';
9
11
  export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
12
+ export { PageTab, PageTabs } from './page-tabs.js';
10
13
  export { useRowKeys } from './row-keys.js';
11
14
  export { RepeatRows, RowControls } from './rows.js';
12
15
  export { Toaster, useToaster } from './toaster.js';
@@ -0,0 +1,4 @@
1
+ import type { ListChromeCatalog } from '../list-chrome.js';
2
+ /** The Spanish list chrome, compiled from the es-ES.po source beside it. */
3
+ declare const catalog: ListChromeCatalog;
4
+ export default catalog;
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /** The Spanish list chrome, compiled from the es-ES.po source beside it. */
3
+ const catalog = {
4
+ '': { lang: 'es-ES', 'plural-forms': 'nplurals=2; plural=(n != 1);' },
5
+ '%1$d of %2$d Item': ['%1$d de %2$d elemento', '%1$d de %2$d elementos'],
6
+ '%1$s: %2$s': ['%1$s: %2$s'],
7
+ '%d Item': ['%d elemento', '%d elementos'],
8
+ '%d Item selected': ['%d elemento seleccionado', '%d elementos seleccionados'],
9
+ '%s: <groupName />': ['%s: <groupName />'],
10
+ '(no title)': ['(sin título)'],
11
+ '<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>': [
12
+ '<Name>%1$s entre (incl.): </Name><Value>%2$s y %3$s</Value>',
13
+ ],
14
+ '<Name>%1$s contains: </Name><Value>%2$s</Value>': [
15
+ '<Name>%1$s contiene: </Name><Value>%2$s</Value>',
16
+ ],
17
+ "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>": [
18
+ '<Name>%1$s no contiene: </Name><Value>%2$s</Value>',
19
+ ],
20
+ '<Name>%1$s includes all: </Name><Value>%2$s</Value>': [
21
+ '<Name>%1$s incluye todos: </Name><Value>%2$s</Value>',
22
+ ],
23
+ '<Name>%1$s includes: </Name><Value>%2$s</Value>': [
24
+ '<Name>%1$s incluye: </Name><Value>%2$s</Value>',
25
+ ],
26
+ '<Name>%1$s is after: </Name><Value>%2$s</Value>': [
27
+ '<Name>%1$s es posterior a: </Name><Value>%2$s</Value>',
28
+ ],
29
+ '<Name>%1$s is before: </Name><Value>%2$s</Value>': [
30
+ '<Name>%1$s es anterior a: </Name><Value>%2$s</Value>',
31
+ ],
32
+ '<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>': [
33
+ '<Name>%1$s es mayor o igual que: </Name><Value>%2$s</Value>',
34
+ ],
35
+ '<Name>%1$s is greater than: </Name><Value>%2$s</Value>': [
36
+ '<Name>%1$s es mayor que: </Name><Value>%2$s</Value>',
37
+ ],
38
+ '<Name>%1$s is in the past: </Name><Value>%2$s</Value>': [
39
+ '<Name>%1$s en los últimos: </Name><Value>%2$s</Value>',
40
+ ],
41
+ '<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>': [
42
+ '<Name>%1$s es menor o igual que: </Name><Value>%2$s</Value>',
43
+ ],
44
+ '<Name>%1$s is less than: </Name><Value>%2$s</Value>': [
45
+ '<Name>%1$s es menor que: </Name><Value>%2$s</Value>',
46
+ ],
47
+ '<Name>%1$s is none of: </Name><Value>%2$s</Value>': [
48
+ '<Name>%1$s no es ninguno de: </Name><Value>%2$s</Value>',
49
+ ],
50
+ '<Name>%1$s is not: </Name><Value>%2$s</Value>': [
51
+ '<Name>%1$s no es: </Name><Value>%2$s</Value>',
52
+ ],
53
+ '<Name>%1$s is on or after: </Name><Value>%2$s</Value>': [
54
+ '<Name>%1$s es igual o posterior a: </Name><Value>%2$s</Value>',
55
+ ],
56
+ '<Name>%1$s is on or before: </Name><Value>%2$s</Value>': [
57
+ '<Name>%1$s es igual o anterior a: </Name><Value>%2$s</Value>',
58
+ ],
59
+ '<Name>%1$s is over: </Name><Value>%2$s</Value>': [
60
+ '<Name>%1$s hace más de: </Name><Value>%2$s</Value>',
61
+ ],
62
+ '<Name>%1$s is: </Name><Value>%2$s</Value>': [
63
+ '<Name>%1$s es: </Name><Value>%2$s</Value>',
64
+ ],
65
+ '<Name>%1$s starts with: </Name><Value>%2$s</Value>': [
66
+ '<Name>%1$s empieza por: </Name><Value>%2$s</Value>',
67
+ ],
68
+ Actions: ['Acciones'],
69
+ Activity: ['Actividad'],
70
+ 'Add filter': ['Añadir filtro'],
71
+ After: ['Después de'],
72
+ 'After (inc)': ['Después de (incl.)'],
73
+ Appearance: ['Apariencia'],
74
+ 'Automatically load more content as you scroll, instead of showing pagination links.': [
75
+ 'Carga más contenido de forma automática al desplazarte, en lugar de mostrar enlaces de paginación.',
76
+ ],
77
+ Before: ['Antes de'],
78
+ 'Before (inc)': ['Antes de (incl.)'],
79
+ 'Between (inc)': ['Entre (incl.)'],
80
+ Cancel: ['Cancelar'],
81
+ Close: ['Cerrar'],
82
+ Conditions: ['Condiciones'],
83
+ Contains: ['Contiene'],
84
+ 'Current page': ['Página actual'],
85
+ Density: ['Densidad'],
86
+ 'Density option for DataView layout\u0004Balanced': ['Equilibrada'],
87
+ 'Density option for DataView layout\u0004Comfortable': ['Cómoda'],
88
+ 'Density option for DataView layout\u0004Compact': ['Compacta'],
89
+ 'Deselect all': ['Deseleccionar todo'],
90
+ "Doesn't contain": ['No contiene'],
91
+ 'Enable infinite scroll': ['Activar el desplazamiento infinito'],
92
+ False: ['Falso'],
93
+ 'Filter by: %1$s': ['Filtrar por: %1$s'],
94
+ 'Greater than': ['Mayor que'],
95
+ 'Greater than or equal': ['Mayor o igual que'],
96
+ Grid: ['Cuadrícula'],
97
+ 'Hide column': ['Ocultar columna'],
98
+ 'In the past': ['En los últimos'],
99
+ Includes: ['Incluye'],
100
+ 'Includes all': ['Incluye todos'],
101
+ 'Insert left': ['Insertar a la izquierda'],
102
+ 'Insert right': ['Insertar a la derecha'],
103
+ Is: ['Es'],
104
+ 'Is none of': ['No es ninguno de'],
105
+ 'Is not': ['No es'],
106
+ 'Items per page': ['Elementos por página'],
107
+ Layout: ['Diseño'],
108
+ 'Less than': ['Menor que'],
109
+ 'Less than or equal': ['Menor o igual que'],
110
+ List: ['Lista'],
111
+ 'List of: %1$s': ['Lista de: %1$s'],
112
+ 'Move left': ['Mover a la izquierda'],
113
+ 'Move right': ['Mover a la derecha'],
114
+ 'Navigate to item': ['Ir al elemento'],
115
+ 'Next page': ['Página siguiente'],
116
+ 'No elements found': ['No se han encontrado elementos'],
117
+ 'No results': ['Sin resultados'],
118
+ 'No results found': ['No se han encontrado resultados'],
119
+ 'Not on': ['No en la fecha'],
120
+ On: ['En la fecha'],
121
+ Order: ['Orden'],
122
+ 'Original aspect ratio': ['Proporción original'],
123
+ Over: ['Hace más de'],
124
+ 'Page %1$d of %2$d': ['Página %1$d de %2$d'],
125
+ 'Preview size': ['Tamaño de la vista previa'],
126
+ 'Previous page': ['Página anterior'],
127
+ Properties: ['Propiedades'],
128
+ Remove: ['Quitar'],
129
+ Reset: ['Restablecer'],
130
+ 'Reset search': ['Restablecer la búsqueda'],
131
+ 'Reset view': ['Restablecer la vista'],
132
+ 'Row %d': ['Fila %d'],
133
+ Search: ['Buscar'],
134
+ 'Search items': ['Buscar elementos'],
135
+ 'Select all': ['Seleccionar todo'],
136
+ 'Sort ascending': ['Orden ascendente'],
137
+ 'Sort by': ['Ordenar por'],
138
+ 'Sort descending': ['Orden descendente'],
139
+ 'Starts with': ['Empieza por'],
140
+ Table: ['Tabla'],
141
+ True: ['Verdadero'],
142
+ 'Unknown status for %1$s': ['Estado desconocido de %1$s'],
143
+ 'View is used as a noun\u0004View options': ['Opciones de vista'],
144
+ 'paging\u0004<div>Page</div>%1$s<div>of %2$d</div>': ['<div>Página</div>%1$s<div>de %2$d</div>'],
145
+ 'verb\u0004Filter': ['Filtrar'],
146
+ };
147
+ export default catalog;
@@ -0,0 +1,10 @@
1
+ /** A compiled catalogue as the i18n runtime reads it, the metadata entry first. */
2
+ export type ListChromeCatalog = Record<string, string[] | Record<string, string>>;
3
+ /** The text domain the WordPress list chrome reads its strings from. */
4
+ export declare const LIST_CHROME_DOMAIN = "default";
5
+ /**
6
+ * Returns the list chrome catalogue this package ships for a language.
7
+ * @param locale - The language the reader settled on.
8
+ * @returns The catalogue, or nothing when the package ships none for it.
9
+ */
10
+ export declare function listChromeCatalogFor(locale: string): Promise<ListChromeCatalog | undefined>;
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /** The text domain the WordPress list chrome reads its strings from. */
3
+ export const LIST_CHROME_DOMAIN = 'default';
4
+ /** The list chrome catalogue this package ships for each language it has one for. */
5
+ const SHIPPED = {
6
+ 'es-ES': () => import('./list-chrome/es-ES.js'),
7
+ };
8
+ /**
9
+ * Returns the list chrome catalogue this package ships for a language.
10
+ * @param locale - The language the reader settled on.
11
+ * @returns The catalogue, or nothing when the package ships none for it.
12
+ */
13
+ export async function listChromeCatalogFor(locale) {
14
+ return Object.hasOwn(SHIPPED, locale) ? (await SHIPPED[locale]()).default : undefined;
15
+ }
@@ -0,0 +1,31 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ export interface PageTabsProps {
3
+ /** The name of the tab navigation, read by assistive technology. */
4
+ label: string;
5
+ /** The tabs, one PageTab each. */
6
+ children: ReactNode;
7
+ }
8
+ /**
9
+ * Renders the tabs of a page as a navigation region of links.
10
+ * @param props - The navigation name and the tabs.
11
+ * @returns The tab navigation element.
12
+ */
13
+ export declare function PageTabs({ label, children }: PageTabsProps): import("react").JSX.Element;
14
+ export interface PageTabProps {
15
+ /** The address the tab leads to, when it renders as a plain link. */
16
+ href?: string;
17
+ /** The link element the tab renders through, such as a router link. */
18
+ render?: ReactElement<{
19
+ className?: string;
20
+ }>;
21
+ /** Whether the tab leads to the page on screen, which alone decides the underline. */
22
+ current?: boolean;
23
+ /** The tab label. */
24
+ children: ReactNode;
25
+ }
26
+ /**
27
+ * Renders one page tab as a link, marked and underlined as the current page when it leads to the page on screen.
28
+ * @param props - The address or the link element, whether it is current, and the label.
29
+ * @returns The tab link element.
30
+ */
31
+ export declare function PageTab({ href, render, current, children }: PageTabProps): import("react").JSX.Element;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cloneElement } from 'react';
3
+ /**
4
+ * Renders the tabs of a page as a navigation region of links.
5
+ * @param props - The navigation name and the tabs.
6
+ * @returns The tab navigation element.
7
+ */
8
+ export function PageTabs({ label, children }) {
9
+ return (_jsx("nav", { className: "godmin-page-tabs", "aria-label": label, children: children }));
10
+ }
11
+ /**
12
+ * The class every page tab carries.
13
+ */
14
+ const TAB_CLASS = 'godmin-page-tabs__tab';
15
+ /**
16
+ * The class that underlines the tab of the page on screen.
17
+ */
18
+ const CURRENT_CLASS = 'godmin-page-tabs__tab--current';
19
+ /**
20
+ * Renders one page tab as a link, marked and underlined as the current page when it leads to the page on screen.
21
+ * @param props - The address or the link element, whether it is current, and the label.
22
+ * @returns The tab link element.
23
+ */
24
+ export function PageTab({ href, render, current = false, children }) {
25
+ const ariaCurrent = current ? 'page' : undefined;
26
+ const tabClass = current ? `${TAB_CLASS} ${CURRENT_CLASS}` : TAB_CLASS;
27
+ if (render === undefined) {
28
+ return (_jsx("a", { href: href, className: tabClass, "aria-current": ariaCurrent, children: children }));
29
+ }
30
+ const own = render.props.className;
31
+ return cloneElement(render, {
32
+ className: own === undefined ? tabClass : `${own} ${tabClass}`,
33
+ 'aria-current': ariaCurrent,
34
+ children,
35
+ });
36
+ }
package/dist/page.d.ts CHANGED
@@ -25,17 +25,18 @@ export interface PageProps {
25
25
  title: string;
26
26
  subtitle?: string;
27
27
  actions?: ReactNode;
28
+ tabs?: ReactNode;
28
29
  aside?: ReactNode;
30
+ list?: boolean;
29
31
  className?: string;
30
32
  children: ReactNode;
31
33
  }
32
34
  /**
33
- * Renders a screen: its title top left, an optional subtitle under it,
34
- * optional actions top right, and the content below, beside an optional aside.
35
- * @param props - The title, subtitle, actions, aside, extra class and content.
35
+ * Renders a screen: a header with the title, actions and subtitle, then optional tabs and the content.
36
+ * @param props - The title, subtitle, actions, tabs, aside, list flag, extra class and content.
36
37
  * @returns The page element.
37
38
  */
38
- export declare function Page({ title, subtitle, actions, aside, className, children }: PageProps): import("react").JSX.Element;
39
+ export declare function Page({ title, subtitle, actions, tabs, aside, list, className, children }: PageProps): import("react").JSX.Element;
39
40
  /**
40
41
  * Renders a failure message that a screen reader announces.
41
42
  * @param props - The message to announce.
package/dist/page.js CHANGED
@@ -7,7 +7,7 @@ import { Button, Notice, Stack, Text } from '@wordpress/ui';
7
7
  * @param props - The title text and the type scale to render it at.
8
8
  * @returns The page title element.
9
9
  */
10
- export function PageTitle({ children, variant = 'heading-xl', }) {
10
+ export function PageTitle({ children, variant = 'heading-lg', }) {
11
11
  return (_jsx(Text, { variant: variant, render: _jsx("h1", {}), children: children }));
12
12
  }
13
13
  /**
@@ -20,14 +20,13 @@ export function SectionTitle({ children, level = 2, id, tabIndex, }) {
20
20
  return (_jsx(Text, { variant: second ? 'heading-lg' : 'heading-md', render: second ? _jsx("h2", {}) : _jsx("h3", {}), id: id, tabIndex: tabIndex, children: children }));
21
21
  }
22
22
  /**
23
- * Renders a screen: its title top left, an optional subtitle under it,
24
- * optional actions top right, and the content below, beside an optional aside.
25
- * @param props - The title, subtitle, actions, aside, extra class and content.
23
+ * Renders a screen: a header with the title, actions and subtitle, then optional tabs and the content.
24
+ * @param props - The title, subtitle, actions, tabs, aside, list flag, extra class and content.
26
25
  * @returns The page element.
27
26
  */
28
- export function Page({ title, subtitle, actions, aside, className, children }) {
27
+ export function Page({ title, subtitle, actions, tabs, aside, list = false, className, children }) {
29
28
  const classes = className === undefined ? 'godmin-page' : `godmin-page ${className}`;
30
- return (_jsxs(Stack, { direction: "column", gap: "lg", className: classes, children: [_jsxs(Stack, { direction: "row", gap: "md", align: "center", justify: "space-between", children: [_jsxs(Stack, { direction: "column", gap: "xs", children: [_jsx(PageTitle, { children: title }), subtitle !== undefined && (_jsx(Text, { variant: "body-sm", className: "godmin-page__subtitle", children: subtitle }))] }), actions !== undefined && (_jsx(Stack, { direction: "row", gap: "sm", align: "center", children: actions }))] }), _jsx(PageBody, { aside: aside, children: children })] }));
29
+ return (_jsxs(Stack, { direction: "column", gap: "lg", className: classes, children: [_jsxs(Stack, { direction: "column", render: _jsx("header", {}), className: "godmin-page__header", children: [_jsxs(Stack, { direction: "row", wrap: "wrap", gap: "md", align: "center", justify: "space-between", className: "godmin-page__head", children: [_jsx(PageTitle, { children: title }), actions !== undefined && (_jsx(Stack, { direction: "row", gap: "sm", align: "center", children: actions }))] }), subtitle !== undefined && (_jsx(Text, { variant: "body-md", render: _jsx("p", {}), className: "godmin-page__subtitle", children: subtitle }))] }), tabs !== undefined && _jsx("div", { className: "godmin-page__tabs", children: tabs }), _jsx(PageBody, { aside: aside, children: list ? _jsx("div", { className: "godmin-page__list", children: children }) : children })] }));
31
30
  }
32
31
  /**
33
32
  * Renders a page's content, beside its aside when it has one.
package/dist/toaster.d.ts CHANGED
@@ -12,13 +12,18 @@ export interface ToasterHandle {
12
12
  */
13
13
  export declare function useToaster(): ToasterHandle;
14
14
  export interface ToasterProps {
15
+ /** The tree the toast region wraps. */
15
16
  children: ReactNode;
17
+ /** How many milliseconds a toast nobody touches stays on screen. */
16
18
  dismissAfter?: number;
19
+ /** The name of the close button, also the hint screen readers hear that a click clears a plain toast. */
17
20
  dismissLabel?: string;
21
+ /** How many toasts stay on screen at once, the oldest leaving first. */
22
+ limit?: number;
18
23
  }
19
24
  /**
20
25
  * Renders the region holding raised messages around the given tree.
21
- * @param props - The tree the region wraps, how long a toast stays, and the dismiss control name.
26
+ * @param props - The tree the region wraps, how long a toast stays, the dismiss control name and how many stay.
22
27
  * @returns The wrapped tree with its region.
23
28
  */
24
- export declare function Toaster({ children, dismissAfter, dismissLabel, }: ToasterProps): import("react").JSX.Element;
29
+ export declare function Toaster({ children, dismissAfter, dismissLabel, limit, }: ToasterProps): import("react").JSX.Element;
package/dist/toaster.js CHANGED
@@ -1,16 +1,24 @@
1
1
  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
- import { Notice, Stack } from '@wordpress/ui';
5
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { speak } from '@wordpress/a11y';
5
+ import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
6
6
  /**
7
7
  * How long a toast nobody touches stays on screen.
8
8
  */
9
- const DISMISS_AFTER = 10000;
9
+ const DISMISS_AFTER = 6000;
10
10
  /**
11
11
  * The name of the control clearing a toast.
12
12
  */
13
13
  const DISMISS_LABEL = 'Dismiss';
14
+ /**
15
+ * The cross the WordPress snackbar draws in its close button.
16
+ */
17
+ const DISMISS_GLYPH = '✕';
18
+ /**
19
+ * How many toasts stay on screen at once.
20
+ */
21
+ const LIMIT = 3;
14
22
  const ToasterContext = createContext(null);
15
23
  /**
16
24
  * Returns the handle raising messages in the toast region.
@@ -24,43 +32,133 @@ export function useToaster() {
24
32
  return handle;
25
33
  }
26
34
  /**
27
- * Renders one raised message with its optional action.
28
- * @param props - The toast, the handler clearing it, and the dismiss control name.
35
+ * Returns the toasts with a new one at the bottom and the oldest past the limit leaving.
36
+ * @param held - The toasts on screen, oldest first.
37
+ * @param arriving - The toast to add.
38
+ * @param limit - How many toasts may stay on screen.
39
+ * @returns The toasts to show.
40
+ */
41
+ function admit(held, arriving, limit) {
42
+ const staying = held.filter((toast) => !toast.leaving);
43
+ const pushed = new Set(staying.slice(0, Math.max(staying.length + 1 - limit, 0)).map((toast) => toast.id));
44
+ return [...held.map((toast) => (pushed.has(toast.id) ? { ...toast, leaving: true } : toast)), arriving];
45
+ }
46
+ /**
47
+ * Returns the fades running on an element, none where the browser cannot report them.
48
+ * @param element - The element to ask.
49
+ * @returns The running animations.
50
+ */
51
+ function runningFades(element) {
52
+ return typeof element.getAnimations === 'function' ? element.getAnimations() : [];
53
+ }
54
+ /**
55
+ * Returns the ref of a toast element that gives up focus as the toast leaves and drops the toast once faded.
56
+ * @param toast - The toast the element draws.
57
+ * @param region - The toast region taking the focus a leaving toast held.
58
+ * @param onGone - The handler dropping a toast that finished leaving.
59
+ * @returns The ref to attach to the toast element.
60
+ */
61
+ function useDeparture(toast, region, onGone) {
62
+ const ref = useRef(null);
63
+ const { id, leaving } = toast;
64
+ useLayoutEffect(() => {
65
+ if (!leaving) {
66
+ return;
67
+ }
68
+ const element = ref.current;
69
+ const holder = region.current;
70
+ if (element.contains(document.activeElement)) {
71
+ holder.focus();
72
+ }
73
+ const fades = runningFades(element);
74
+ if (fades.length === 0) {
75
+ onGone(id);
76
+ return;
77
+ }
78
+ Promise.allSettled(fades.map((fade) => fade.finished)).then(() => onGone(id));
79
+ }, [id, leaving, region, onGone]);
80
+ return ref;
81
+ }
82
+ /**
83
+ * Runs the timer that sends a toast nobody touched away, cleared once the toast leaves or goes.
84
+ * @param toast - The toast the timer belongs to.
85
+ * @param dismissAfter - How many milliseconds the toast stays.
86
+ * @param onLeave - The handler sending a toast away.
87
+ */
88
+ function useExpiry(toast, dismissAfter, onLeave) {
89
+ const { id, leaving } = toast;
90
+ useEffect(() => {
91
+ if (leaving) {
92
+ return;
93
+ }
94
+ const timer = setTimeout(() => onLeave(id), dismissAfter);
95
+ return () => clearTimeout(timer);
96
+ }, [id, leaving, dismissAfter, onLeave]);
97
+ }
98
+ /**
99
+ * Returns the classes of a toast, with the leaving look while it fades out.
100
+ * @param base - The classes the toast always carries.
101
+ * @param leaving - Whether the toast is fading out.
102
+ * @returns The class list.
103
+ */
104
+ function toastClass(base, leaving) {
105
+ return leaving ? `${base} godmin-toast--leaving` : base;
106
+ }
107
+ /**
108
+ * Renders a toast with no action as one button that clears it, described by the dismiss hint.
109
+ * @param props - The toast, how long it stays, the id of the dismiss hint, the region and the handlers clearing it.
29
110
  * @returns The toast element.
30
111
  */
31
- function Toast({ toast, onClear, dismissLabel, }) {
32
- return (_jsxs(Notice.Root, { intent: "neutral", spokenMessage: toast.message, children: [_jsx(Notice.Description, { children: toast.message }), _jsxs(Notice.Actions, { children: [toast.action !== undefined && (_jsx(Notice.ActionButton, { onClick: () => {
33
- toast.action?.onAct();
34
- onClear(toast.id);
35
- }, children: toast.action.label })), _jsx(Notice.ActionButton, { onClick: () => onClear(toast.id), children: dismissLabel })] })] }));
112
+ function PlainToast({ toast, dismissAfter, hint, region, onLeave, onGone, }) {
113
+ useExpiry(toast, dismissAfter, onLeave);
114
+ const ref = useDeparture(toast, region, onGone);
115
+ 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 }));
116
+ }
117
+ /**
118
+ * Renders a toast with its action and a close button beside it.
119
+ * @param props - The toast, its action, its time, the close button name, the region and the handlers clearing it.
120
+ * @returns The toast element.
121
+ */
122
+ function ActionToast({ toast, action, dismissAfter, dismissLabel, region, onLeave, onGone, }) {
123
+ useExpiry(toast, dismissAfter, onLeave);
124
+ const ref = useDeparture(toast, region, onGone);
125
+ 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: () => {
126
+ action.onAct();
127
+ onLeave(toast.id);
128
+ }, children: action.label }), _jsx("button", { type: "button", className: "godmin-toast__dismiss", "aria-label": dismissLabel, onClick: () => onLeave(toast.id), children: DISMISS_GLYPH })] }));
36
129
  }
37
130
  /**
38
131
  * Renders the region holding raised messages around the given tree.
39
- * @param props - The tree the region wraps, how long a toast stays, and the dismiss control name.
132
+ * @param props - The tree the region wraps, how long a toast stays, the dismiss control name and how many stay.
40
133
  * @returns The wrapped tree with its region.
41
134
  */
42
- export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, }) {
135
+ export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, limit = LIMIT, }) {
43
136
  const [toasts, setToasts] = useState([]);
44
137
  const nextId = useRef(0);
45
- const timers = useRef(new Set());
46
- useEffect(() => {
47
- const held = timers.current;
138
+ const region = useRef(null);
139
+ const mounted = useRef(true);
140
+ useLayoutEffect(() => {
141
+ mounted.current = true;
48
142
  return () => {
49
- for (const timer of held) {
50
- clearTimeout(timer);
51
- }
52
- held.clear();
143
+ mounted.current = false;
53
144
  };
54
145
  }, []);
55
- const clear = useCallback((id) => {
146
+ const leave = useCallback((id) => {
147
+ setToasts((held) => held.map((toast) => (toast.id === id ? { ...toast, leaving: true } : toast)));
148
+ }, []);
149
+ const gone = useCallback((id) => {
56
150
  setToasts((held) => held.filter((toast) => toast.id !== id));
57
151
  }, []);
58
152
  const show = useCallback((message, action) => {
153
+ if (!mounted.current) {
154
+ return;
155
+ }
59
156
  nextId.current += 1;
60
157
  const id = nextId.current;
61
- setToasts((held) => [...held, { id, message, action }]);
62
- timers.current.add(setTimeout(() => clear(id), dismissAfter));
63
- }, [clear, dismissAfter]);
158
+ speak(message, 'polite');
159
+ setToasts((held) => admit(held, { id, message, action, leaving: false }, limit));
160
+ }, [limit]);
64
161
  const handle = useMemo(() => ({ show }), [show]);
65
- return (_jsxs(ToasterContext.Provider, { value: handle, children: [children, _jsx(Stack, { direction: "column", gap: "xs", className: "godmin-toasts", children: toasts.map((toast) => (_jsx(Toast, { toast: toast, onClear: clear, dismissLabel: dismissLabel }, toast.id))) })] }));
162
+ const hint = useId();
163
+ 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 })] }));
66
164
  }
package/dist/vite.js CHANGED
@@ -5,6 +5,7 @@
5
5
  export const godminDedupe = [
6
6
  'react',
7
7
  'react-dom',
8
+ '@wordpress/a11y',
8
9
  '@wordpress/element',
9
10
  '@wordpress/i18n',
10
11
  '@wordpress/theme',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "The admin kit for Gopherium projects: host layer for React admin applications on the WordPress Design System.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -58,6 +58,7 @@
58
58
  "peerDependencies": {
59
59
  "@tanstack/react-router": "^1.170.0",
60
60
  "@testing-library/react": "^16.3.2",
61
+ "@wordpress/a11y": ">=4.55.0 <5.0.0",
61
62
  "@wordpress/icons": ">=16.0.0 <17.0.0",
62
63
  "@wordpress/style-runtime": ">=0.11.0 <0.12.0",
63
64
  "@wordpress/theme": ">=2.1.0 <3.0.0",
@@ -88,6 +89,7 @@
88
89
  "@vitejs/plugin-react": "^6.0.3",
89
90
  "@vitest/coverage-v8": "^4.1.10",
90
91
  "@wordpress/a11y": "4.55.0",
92
+ "@wordpress/dataviews": "19.0.0",
91
93
  "@wordpress/element": "8.7.0",
92
94
  "@wordpress/icons": "16.0.0",
93
95
  "@wordpress/style-runtime": "0.11.0",