@gopherium/godmin 0.31.0 → 0.32.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 +2 -3
- package/dist/base.css +9 -16
- package/dist/breakpoints.d.ts +1 -1
- package/dist/breakpoints.js +1 -1
- package/dist/bulk-run.d.ts +10 -0
- package/dist/bulk-run.js +59 -10
- package/dist/bulk.d.ts +3 -0
- package/dist/confirm-dialog.d.ts +14 -14
- package/dist/confirm-dialog.js +8 -28
- package/dist/dialog-open.d.ts +63 -0
- package/dist/dialog-open.js +110 -0
- package/dist/form-dialog.d.ts +14 -16
- package/dist/form-dialog.js +53 -13
- package/dist/index.d.ts +9 -11
- package/dist/index.js +4 -6
- package/dist/list-chrome/fr-FR.js +1 -0
- package/dist/list-run.js +25 -44
- package/dist/rename-dialog.d.ts +24 -0
- package/dist/rename-dialog.js +16 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/toaster.js +21 -2
- package/dist/unsaved-changes-dialog.d.ts +19 -0
- package/dist/unsaved-changes-dialog.js +33 -0
- package/docs/build-and-versioning.md +90 -7
- package/docs/design-system/accessibility.md +5 -3
- package/docs/design-system/dialogs.md +240 -0
- package/docs/design-system/layout.md +1 -1
- package/docs/design-system/lists.md +3 -1
- package/docs/design-system/motion.md +3 -2
- package/docs/design-system/overview.md +4 -1
- package/docs/design-system/record-pages.md +4 -2
- package/docs/design-system/toasts.md +11 -7
- package/docs/lists.md +311 -432
- package/docs/loading-and-feedback.md +11 -6
- package/docs/overview.md +2 -3
- package/docs/screens.md +10 -2
- package/docs/testing.md +11 -9
- package/package.json +1 -9
- package/dist/close-while-open.d.ts +0 -6
- package/dist/close-while-open.js +0 -21
- package/dist/confirm.d.ts +0 -21
- package/dist/confirm.js +0 -11
- package/dist/dialogs.d.ts +0 -4
- package/dist/dialogs.js +0 -3
- package/dist/form.d.ts +0 -28
- package/dist/form.js +0 -23
- package/dist/rename.d.ts +0 -20
- package/dist/rename.js +0 -14
- package/dist/run-confirm.d.ts +0 -22
- package/dist/run-confirm.js +0 -23
|
@@ -43,6 +43,8 @@ decides how it shows:
|
|
|
43
43
|
page, under the title, as on a WordPress screen.
|
|
44
44
|
- Inside a dialog, when nothing of the dialog body is known yet. It
|
|
45
45
|
shows at once there too.
|
|
46
|
+
[When to ask first](./design-system/dialogs.md#when-to-ask-first)
|
|
47
|
+
says when an action opens a dialog at all.
|
|
46
48
|
- Alone, when nothing of the screen is known yet, such as while the
|
|
47
49
|
session loads before the frame is drawn. It then waits a moment, so
|
|
48
50
|
a fast load shows nothing, and fades in, in the middle of the space
|
|
@@ -199,12 +201,15 @@ Name an item in straight double quotes and in full, like
|
|
|
199
201
|
snackbar, and godmin does not either.
|
|
200
202
|
[Size](./design-system/toasts.md#size) says how a long one wraps.
|
|
201
203
|
|
|
202
|
-
Use a toast for a write that failed too,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
Use a toast for a write that failed too, on a page or in a run over
|
|
205
|
+
list rows. WordPress shows those in its snackbar, never above the
|
|
206
|
+
list, and godmin's list runs do the same. A dialog that closes says
|
|
207
|
+
how its write went in a toast too. A dialog that stays open says why
|
|
208
|
+
inside, as [a failed write](./design-system/dialogs.md#a-failed-write)
|
|
209
|
+
says.
|
|
210
|
+
Say what failed, in the words your server sent when it sent some. A
|
|
211
|
+
server message about one field goes under that field.
|
|
212
|
+
[A failure from a dialog](./lists.md#a-failure-from-a-dialog)
|
|
208
213
|
shows how to raise one from a dialog.
|
|
209
214
|
[Running an action over the picked rows](./lists.md#running-an-action-over-the-picked-rows)
|
|
210
215
|
raises it for you after a run over a list.
|
package/docs/overview.md
CHANGED
|
@@ -29,11 +29,10 @@ duplicates something the packages above already ship.
|
|
|
29
29
|
|
|
30
30
|
| Entry point | Contents |
|
|
31
31
|
| --- | --- |
|
|
32
|
-
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `PageBreadcrumbs`, `PageBreadcrumb`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `
|
|
32
|
+
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `PageBreadcrumbs`, `PageBreadcrumb`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `ConfirmDialog`, `FormDialog`, `RenameDialog`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `useDialogRun`, `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` |
|
|
33
33
|
| `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
|
|
34
34
|
| `@gopherium/godmin/dates` | `startListDates`, `listDate`, the only entry that loads `@wordpress/date` |
|
|
35
|
-
| `@gopherium/godmin/
|
|
36
|
-
| `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, the `canvas`, `Sidebar` and `capability` route static data |
|
|
35
|
+
| `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, `UnsavedChangesDialog`, the `canvas`, `Sidebar` and `capability` route static data |
|
|
37
36
|
| `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport` and its `TestViewport` type, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses`, `stubLayout` |
|
|
38
37
|
| `@gopherium/godmin/vite` | `godminDedupe`, `godminSingleCopy`, `godminStylesheetFirst`, `duplicateCopies`, `hoistStylesheet` |
|
|
39
38
|
| `@gopherium/godmin/stylelint` | The design system stylelint rules |
|
package/docs/screens.md
CHANGED
|
@@ -160,7 +160,7 @@ way a WordPress record page names its list:
|
|
|
160
160
|
title="Maria Perez"
|
|
161
161
|
breadcrumbs={
|
|
162
162
|
<PageBreadcrumbs label="Breadcrumbs">
|
|
163
|
-
<PageBreadcrumb render={<Link to="/contacts" />}>Contacts</PageBreadcrumb>
|
|
163
|
+
<PageBreadcrumb render={<Link to="/contacts" activeOptions={{ exact: true }} />}>Contacts</PageBreadcrumb>
|
|
164
164
|
</PageBreadcrumbs>
|
|
165
165
|
}
|
|
166
166
|
aside={<ContactDetails />}
|
|
@@ -173,6 +173,13 @@ Each breadcrumb is a link. Pass your router's link element as
|
|
|
173
173
|
`render`, or a plain address as `href`, as with `PageTab`. Leave the
|
|
174
174
|
page on screen out of the list, since its title already names it.
|
|
175
175
|
|
|
176
|
+
No breadcrumb is the current page, yet a router link can mark itself
|
|
177
|
+
as one for screen readers. TanStack Router counts a link to
|
|
178
|
+
`/contacts` as active on `/contacts/42` too, so without
|
|
179
|
+
`activeOptions={{ exact: true }}` a screen reader would hear the
|
|
180
|
+
breadcrumb as the page on screen. Pass it on every breadcrumb link, as
|
|
181
|
+
the example does.
|
|
182
|
+
|
|
176
183
|
`label` names the links for assistive technology. They are a
|
|
177
184
|
navigation region, and a screen reader lists it beside the sidebar and
|
|
178
185
|
any tabs, so the name tells them apart. Translate it.
|
|
@@ -258,7 +265,8 @@ message to screen readers. Use it wherever you would otherwise
|
|
|
258
265
|
render a bare error string, such as a screen that failed to load. A
|
|
259
266
|
write that fails goes in a toast instead, as
|
|
260
267
|
[what goes in a toast](./loading-and-feedback.md#what-goes-in-a-toast)
|
|
261
|
-
explains.
|
|
268
|
+
explains. A dialog that stays open draws its own notice, as
|
|
269
|
+
[a failed write](./design-system/dialogs.md#a-failed-write) says.
|
|
262
270
|
|
|
263
271
|
## LoadMore
|
|
264
272
|
|
package/docs/testing.md
CHANGED
|
@@ -135,20 +135,22 @@ setViewport(PHONE)
|
|
|
135
135
|
## Giving elements a layout box
|
|
136
136
|
|
|
137
137
|
jsdom lays nothing out, so no element has a size or a place on the
|
|
138
|
-
screen. The
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
screen. The `Modal` of `@wordpress/components`, such as one your app
|
|
139
|
+
draws itself or one DataViews opens for an action with a
|
|
140
|
+
`RenderModal`, looks for the first element it can focus among those
|
|
141
|
+
on screen, finds none, and leaves the focus where it was.
|
|
142
|
+
A test that checks such a modal put the cursor in its first field
|
|
143
|
+
then fails, though a browser moves the focus there. godmin's own
|
|
144
|
+
dialogs need no box for that. `stubLayout` gives every element one
|
|
145
|
+
small box, as a browser does for an element on screen:
|
|
144
146
|
|
|
145
147
|
```ts
|
|
146
148
|
import { stubLayout } from '@gopherium/godmin/testing'
|
|
147
149
|
|
|
148
|
-
test('
|
|
150
|
+
test('puts the cursor in the note field when the export modal opens', async () => {
|
|
149
151
|
stubLayout()
|
|
150
|
-
await user.click(screen.getByRole('button', { name: '
|
|
151
|
-
await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('
|
|
152
|
+
await user.click(screen.getByRole('button', { name: 'Export' }))
|
|
153
|
+
await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'Note' })))
|
|
152
154
|
})
|
|
153
155
|
```
|
|
154
156
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopherium/godmin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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",
|
|
@@ -31,10 +31,6 @@
|
|
|
31
31
|
"types": "./dist/dates.d.ts",
|
|
32
32
|
"default": "./dist/dates.js"
|
|
33
33
|
},
|
|
34
|
-
"./dialogs": {
|
|
35
|
-
"types": "./dist/dialogs.d.ts",
|
|
36
|
-
"default": "./dist/dialogs.js"
|
|
37
|
-
},
|
|
38
34
|
"./router": {
|
|
39
35
|
"types": "./dist/router.d.ts",
|
|
40
36
|
"default": "./dist/router.js"
|
|
@@ -71,7 +67,6 @@
|
|
|
71
67
|
"@tanstack/react-router": "^1.170.44",
|
|
72
68
|
"@testing-library/react": "^16.3.2",
|
|
73
69
|
"@wordpress/a11y": ">=5.0.0 <6.0.0",
|
|
74
|
-
"@wordpress/components": ">=43.0.0 <44.0.0",
|
|
75
70
|
"@wordpress/dataviews": ">=21.0.0 <22.0.0",
|
|
76
71
|
"@wordpress/date": ">=6.0.0 <7.0.0",
|
|
77
72
|
"@wordpress/i18n": ">=7.0.0 <8.0.0",
|
|
@@ -90,9 +85,6 @@
|
|
|
90
85
|
"@testing-library/react": {
|
|
91
86
|
"optional": true
|
|
92
87
|
},
|
|
93
|
-
"@wordpress/components": {
|
|
94
|
-
"optional": true
|
|
95
|
-
},
|
|
96
88
|
"@wordpress/dataviews": {
|
|
97
89
|
"optional": true
|
|
98
90
|
},
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the close of a dialog body that acts only while that body is on screen, never on a dialog opened since.
|
|
3
|
-
* @param close - Closes the dialog, none for a body drawn outside a dialog.
|
|
4
|
-
* @returns The close, which does nothing once the body left the screen.
|
|
5
|
-
*/
|
|
6
|
-
export declare function useCloseWhileOpen(close: (() => void) | undefined): () => void;
|
package/dist/close-while-open.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Returns the close of a dialog body that acts only while that body is on screen, never on a dialog opened since.
|
|
5
|
-
* @param close - Closes the dialog, none for a body drawn outside a dialog.
|
|
6
|
-
* @returns The close, which does nothing once the body left the screen.
|
|
7
|
-
*/
|
|
8
|
-
export function useCloseWhileOpen(close) {
|
|
9
|
-
const open = useRef(true);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
open.current = true;
|
|
12
|
-
return () => {
|
|
13
|
-
open.current = false;
|
|
14
|
-
};
|
|
15
|
-
}, []);
|
|
16
|
-
return () => {
|
|
17
|
-
if (open.current) {
|
|
18
|
-
close?.();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
package/dist/confirm.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
export interface ConfirmBodyProps {
|
|
3
|
-
/** The question the modal asks. */
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
/** The label of the button that carries the action out. */
|
|
6
|
-
confirmLabel: string;
|
|
7
|
-
/** The label of the button that closes the modal. */
|
|
8
|
-
cancelLabel: string;
|
|
9
|
-
/** Whether the action is running, the confirm button then busy and Cancel greyed out. */
|
|
10
|
-
busy?: boolean;
|
|
11
|
-
/** Carries the action out. */
|
|
12
|
-
onConfirm: () => void;
|
|
13
|
-
/** Closes the modal. */
|
|
14
|
-
onCancel?: () => void;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
|
|
18
|
-
* @param props - The question, the labels, the busy flag and the handlers.
|
|
19
|
-
* @returns The confirmation body.
|
|
20
|
-
*/
|
|
21
|
-
export declare function ConfirmBody({ children, confirmLabel, cancelLabel, busy, onConfirm, onCancel, }: ConfirmBodyProps): import("react").JSX.Element;
|
package/dist/confirm.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { Button, Stack, Text } from '@wordpress/ui';
|
|
4
|
-
/**
|
|
5
|
-
* Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
|
|
6
|
-
* @param props - The question, the labels, the busy flag and the handlers.
|
|
7
|
-
* @returns The confirmation body.
|
|
8
|
-
*/
|
|
9
|
-
export function ConfirmBody({ children, confirmLabel, cancelLabel, busy = false, onConfirm, onCancel, }) {
|
|
10
|
-
return (_jsxs("div", { className: "godmin-modal-body", children: [_jsx(Text, { className: "godmin-modal-body__question", children: children }), _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", disabled: busy, onClick: onCancel, children: cancelLabel }), _jsx(Button, { loading: busy, onClick: onConfirm, children: confirmLabel })] })] }));
|
|
11
|
-
}
|
package/dist/dialogs.d.ts
DELETED
package/dist/dialogs.js
DELETED
package/dist/form.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
/** What a form does, which sets the space above its buttons as WordPress spaces it. */
|
|
3
|
-
export type FormKind = 'edit' | 'copy' | 'create';
|
|
4
|
-
/** The props of the body of a form modal. */
|
|
5
|
-
export interface FormBodyProps {
|
|
6
|
-
/** The fields, and any help sentence before them, in the order the reader meets them. */
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
/** The label of the button that sends the form. */
|
|
9
|
-
submitLabel: string;
|
|
10
|
-
/** The label of the button that closes the modal. */
|
|
11
|
-
cancelLabel: string;
|
|
12
|
-
/** Whether the form may be sent now, false while a needed field is empty, true when left out. */
|
|
13
|
-
canSubmit?: boolean;
|
|
14
|
-
/** Whether the write runs, the submit button then busy and a second send ignored. */
|
|
15
|
-
busy?: boolean;
|
|
16
|
-
/** What the form does: 20px above the buttons for an edit, the default, 12px for a copy, 16px for a create. */
|
|
17
|
-
kind?: FormKind;
|
|
18
|
-
/** Sends the form, from the submit button or Enter in a field. */
|
|
19
|
-
onSubmit: () => void;
|
|
20
|
-
/** Closes the modal. */
|
|
21
|
-
onCancel?: () => void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
|
|
25
|
-
* @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
|
|
26
|
-
* @returns The form.
|
|
27
|
-
*/
|
|
28
|
-
export declare function FormBody({ children, submitLabel, cancelLabel, canSubmit, busy, kind, onSubmit, onCancel, }: FormBodyProps): import("react").JSX.Element;
|
package/dist/form.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { Button, Stack } from '@wordpress/ui';
|
|
4
|
-
/** The classes of a form body of each kind. */
|
|
5
|
-
const KIND_CLASSES = {
|
|
6
|
-
edit: 'godmin-modal-body',
|
|
7
|
-
copy: 'godmin-modal-body godmin-modal-body--copy',
|
|
8
|
-
create: 'godmin-modal-body godmin-modal-body--create',
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
|
|
12
|
-
* @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
|
|
13
|
-
* @returns The form.
|
|
14
|
-
*/
|
|
15
|
-
export function FormBody({ children, submitLabel, cancelLabel, canSubmit = true, busy = false, kind = 'edit', onSubmit, onCancel, }) {
|
|
16
|
-
const sendable = canSubmit && !busy;
|
|
17
|
-
return (_jsxs("form", { className: KIND_CLASSES[kind], onSubmit: (event) => {
|
|
18
|
-
event.preventDefault();
|
|
19
|
-
if (sendable) {
|
|
20
|
-
onSubmit();
|
|
21
|
-
}
|
|
22
|
-
}, children: [children, _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", onClick: onCancel, children: cancelLabel }), _jsx(Button, { type: "submit", loading: busy, disabled: !sendable, children: submitLabel })] })] }));
|
|
23
|
-
}
|
package/dist/rename.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface RenameBodyProps {
|
|
2
|
-
/** The text the field starts with: the name the item carries, or the name a failed write turned away. */
|
|
3
|
-
name: string;
|
|
4
|
-
/** The label of the name field. */
|
|
5
|
-
fieldLabel: string;
|
|
6
|
-
/** The label of the button that writes the new name. */
|
|
7
|
-
submitLabel: string;
|
|
8
|
-
/** The label of the button that closes the modal. */
|
|
9
|
-
cancelLabel: string;
|
|
10
|
-
/** Writes the name as typed, the one the item already has included. */
|
|
11
|
-
onSubmit: (name: string) => void;
|
|
12
|
-
/** Closes the modal. */
|
|
13
|
-
onCancel?: () => void;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
|
|
17
|
-
* @param props - The first name, the labels and the handlers.
|
|
18
|
-
* @returns The rename form.
|
|
19
|
-
*/
|
|
20
|
-
export declare function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }: RenameBodyProps): import("react").JSX.Element;
|
package/dist/rename.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { InputControl } from '@wordpress/ui';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { FormBody } from './form.js';
|
|
6
|
-
/**
|
|
7
|
-
* Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
|
|
8
|
-
* @param props - The first name, the labels and the handlers.
|
|
9
|
-
* @returns The rename form.
|
|
10
|
-
*/
|
|
11
|
-
export function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }) {
|
|
12
|
-
const [value, setValue] = useState(name);
|
|
13
|
-
return (_jsx(FormBody, { submitLabel: submitLabel, cancelLabel: cancelLabel, canSubmit: value.trim() !== '', onSubmit: () => onSubmit(value), onCancel: onCancel, children: _jsx(InputControl, { label: fieldLabel, value: value, onChange: (event) => setValue(event.target.value) }) }));
|
|
14
|
-
}
|
package/dist/run-confirm.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
/** The props of a run confirm, the first two as a DataViews modal hands them. */
|
|
3
|
-
export interface RunConfirmProps<Item> {
|
|
4
|
-
/** The items the action runs over. */
|
|
5
|
-
items: Item[];
|
|
6
|
-
/** Closes the modal. */
|
|
7
|
-
closeModal?: () => void;
|
|
8
|
-
/** The question the modal asks. */
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
/** The label of the button that starts the run. */
|
|
11
|
-
confirmLabel: string;
|
|
12
|
-
/** The label of the button that closes the modal. */
|
|
13
|
-
cancelLabel: string;
|
|
14
|
-
/** Runs the action over the items, settling once the list shows how it went. */
|
|
15
|
-
run: (items: Item[]) => Promise<unknown>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Renders a confirmation that runs the action, keeps Cancel inert while it runs and closes only itself once it settles.
|
|
19
|
-
* @param props - The items, the close handler, the question, the labels and the run.
|
|
20
|
-
* @returns The confirmation body.
|
|
21
|
-
*/
|
|
22
|
-
export declare function RunConfirm<Item>({ items, closeModal, children, confirmLabel, cancelLabel, run, }: RunConfirmProps<Item>): import("react").JSX.Element;
|
package/dist/run-confirm.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { useCloseWhileOpen } from './close-while-open.js';
|
|
5
|
-
import { ConfirmBody } from './confirm.js';
|
|
6
|
-
/**
|
|
7
|
-
* Renders a confirmation that runs the action, keeps Cancel inert while it runs and closes only itself once it settles.
|
|
8
|
-
* @param props - The items, the close handler, the question, the labels and the run.
|
|
9
|
-
* @returns The confirmation body.
|
|
10
|
-
*/
|
|
11
|
-
export function RunConfirm({ items, closeModal, children, confirmLabel, cancelLabel, run, }) {
|
|
12
|
-
const [busy, setBusy] = useState(false);
|
|
13
|
-
const close = useCloseWhileOpen(closeModal);
|
|
14
|
-
return (_jsx(ConfirmBody, { confirmLabel: confirmLabel, cancelLabel: cancelLabel, busy: busy, onCancel: closeModal, onConfirm: () => {
|
|
15
|
-
setBusy(true);
|
|
16
|
-
void Promise.resolve()
|
|
17
|
-
.then(() => run(items))
|
|
18
|
-
.finally(() => {
|
|
19
|
-
setBusy(false);
|
|
20
|
-
close();
|
|
21
|
-
});
|
|
22
|
-
}, children: children }));
|
|
23
|
-
}
|