@gopherium/godmin 0.12.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 +1 -1
- package/dist/avatar.d.ts +21 -0
- package/dist/avatar.js +42 -0
- package/dist/base.css +437 -22
- package/dist/breakpoints.d.ts +5 -1
- package/dist/breakpoints.js +5 -1
- package/dist/frame.js +4 -4
- package/dist/index.d.ts +7 -1
- package/dist/index.js +4 -1
- package/dist/list-chrome/es-ES.d.ts +4 -0
- package/dist/list-chrome/es-ES.js +147 -0
- package/dist/list-chrome.d.ts +10 -0
- package/dist/list-chrome.js +15 -0
- package/dist/page-tabs.d.ts +31 -0
- package/dist/page-tabs.js +36 -0
- package/dist/page.d.ts +5 -4
- package/dist/page.js +5 -6
- package/dist/rows.js +3 -5
- package/dist/toaster.d.ts +7 -2
- package/dist/toaster.js +122 -24
- package/dist/vite.js +1 -0
- package/package.json +5 -1
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,
|
|
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
|
|
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(
|
|
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 {
|
|
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 {
|
|
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,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:
|
|
34
|
-
*
|
|
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-
|
|
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:
|
|
24
|
-
*
|
|
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: "
|
|
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/rows.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { chevronDown, chevronUp, trash } from '@wordpress/icons';
|
|
4
|
+
import { Button, IconButton, Stack, Text, Tooltip } from '@wordpress/ui';
|
|
4
5
|
import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
5
6
|
import { useRowKeys } from './row-keys.js';
|
|
6
|
-
const upIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z" }) }));
|
|
7
|
-
const downIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z" }) }));
|
|
8
|
-
const removeIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z" }) }));
|
|
9
7
|
/**
|
|
10
8
|
* Renders the buttons that move a row among its siblings and take it away.
|
|
11
9
|
* @param props - The row's place, the list's length, the words and what to call on a change.
|
|
12
10
|
* @returns The controls element.
|
|
13
11
|
*/
|
|
14
12
|
export function RowControls({ at, count, removable = true, labels, onMove, onRemove }) {
|
|
15
|
-
return (_jsxs(Stack, { direction: "row", gap: "xs", align: "center", className: "godmin-rows__controls", children: [_jsx(IconButton, { icon:
|
|
13
|
+
return (_jsxs(Stack, { direction: "row", gap: "xs", align: "center", className: "godmin-rows__controls", children: [_jsx(IconButton, { icon: chevronUp, label: labels.moveUp, size: "compact", variant: "minimal", tone: "neutral", disabled: at === 0, onClick: () => onMove(-1) }), _jsx(IconButton, { icon: chevronDown, label: labels.moveDown, size: "compact", variant: "minimal", tone: "neutral", disabled: at === count - 1, onClick: () => onMove(1) }), _jsx(IconButton, { icon: trash, label: labels.remove, className: "godmin-rows__remove", positioner: _jsx(Tooltip.Positioner, { align: "end" }), size: "compact", variant: "minimal", tone: "neutral", disabled: !removable, onClick: onRemove })] }));
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Returns where focus goes after the rows shown change.
|
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,
|
|
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 {
|
|
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 =
|
|
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
|
-
*
|
|
28
|
-
* @param
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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,
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
138
|
+
const region = useRef(null);
|
|
139
|
+
const mounted = useRef(true);
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
mounted.current = true;
|
|
48
142
|
return () => {
|
|
49
|
-
|
|
50
|
-
clearTimeout(timer);
|
|
51
|
-
}
|
|
52
|
-
held.clear();
|
|
143
|
+
mounted.current = false;
|
|
53
144
|
};
|
|
54
145
|
}, []);
|
|
55
|
-
const
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
}, [
|
|
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
|
-
|
|
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
|
}
|