@gopherium/godmin 0.4.0 → 0.6.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
@@ -19,7 +19,7 @@ here duplicates something upstream ships.
19
19
 
20
20
  | Entry point | Contents |
21
21
  | --- | --- |
22
- | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LoadingScreen`, `LoadingRows`, `useLoadingGate`, `Toaster`, `useToaster`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
22
+ | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
23
23
  | `@gopherium/godmin/base.css` | cascade layer order, design tokens, host rules, frame and screen styles |
24
24
  | `@gopherium/godmin/router` | `useCanvas`, `useFrameLocation`, the `canvas` route static data |
25
25
  | `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR` |
@@ -145,17 +145,15 @@ label through a visually hidden status region, so give `label` the same
145
145
  sentence you would have rendered as text.
146
146
 
147
147
  ```tsx
148
- const ghost = useLoadingGate(reports.isPending)
149
-
150
- if (ghost) {
148
+ if (reports.isPending) {
151
149
  return <LoadingRows label="Loading reports." rows={8} />
152
150
  }
151
+ return <ReportTable className="godmin-arrival" />
153
152
  ```
154
153
 
155
- `useLoadingGate` owns the timing: a load that resolves quickly shows no
156
- ghost at all, and a ghost that does appear stays long enough to read as
157
- intentional. Gate the pending flag rather than using it directly, or a
158
- mid speed load flashes the ghost for a moment.
154
+ A ghost fades in after a short delay, so a fast load never shows one.
155
+ Give the content that replaces a ghost the `godmin-arrival` class and it
156
+ fades in too, so the swap reads as one motion rather than a snap.
159
157
 
160
158
  `base.css` also ships `godmin-empty`, `godmin-form`, `godmin-table` and
161
159
  `godmin-table-scroll`. The last two go together: a table wider than a phone
package/dist/base.css CHANGED
@@ -152,6 +152,36 @@ body {
152
152
  white-space: nowrap;
153
153
  }
154
154
 
155
+ .godmin-loading-screen,
156
+ .godmin-loading-rows {
157
+ opacity: 0;
158
+ animation: godmin-fade-in var(--wpds-motion-duration-md)
159
+ var(--wpds-motion-easing-balanced) 150ms forwards;
160
+ }
161
+
162
+ .godmin-arrival {
163
+ animation: godmin-fade-in var(--wpds-motion-duration-md)
164
+ var(--wpds-motion-easing-balanced);
165
+ }
166
+
167
+ @keyframes godmin-fade-in {
168
+ 0% {
169
+ opacity: 0;
170
+ }
171
+
172
+ 100% {
173
+ opacity: 1;
174
+ }
175
+ }
176
+
177
+ @media (prefers-reduced-motion: reduce) {
178
+ .godmin-loading-screen,
179
+ .godmin-loading-rows,
180
+ .godmin-arrival {
181
+ animation-duration: 1ms;
182
+ }
183
+ }
184
+
155
185
  .godmin-loading-screen {
156
186
  padding: var(--wpds-dimension-padding-xl);
157
187
  }
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ export { ErrorNotice, LoadMore, Page, PageTitle } from './page.js';
10
10
  export type { LoadMoreQuery, PageProps } from './page.js';
11
11
  export { Toaster, useToaster } from './toaster.js';
12
12
  export type { ToastAction, ToasterHandle, ToasterProps } from './toaster.js';
13
- export { useLoadingGate } from './use-loading-gate.js';
14
13
  export { useMediaQuery } from './use-media-query.js';
15
14
  export { useTokenDocument } from './use-token-document.js';
16
15
  /**
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ export { LoadingRows, LoadingScreen } from './loading.js';
6
6
  export { NavScreen } from './nav-screen.js';
7
7
  export { ErrorNotice, LoadMore, Page, PageTitle } from './page.js';
8
8
  export { Toaster, useToaster } from './toaster.js';
9
- export { useLoadingGate } from './use-loading-gate.js';
10
9
  export { useMediaQuery } from './use-media-query.js';
11
10
  export { useTokenDocument } from './use-token-document.js';
12
11
  /**
package/dist/toaster.d.ts CHANGED
@@ -14,10 +14,11 @@ export declare function useToaster(): ToasterHandle;
14
14
  export interface ToasterProps {
15
15
  children: ReactNode;
16
16
  dismissAfter?: number;
17
+ dismissLabel?: string;
17
18
  }
18
19
  /**
19
20
  * Renders the region holding raised messages around the given tree.
20
- * @param props - The tree the region wraps and how long a toast stays.
21
+ * @param props - The tree the region wraps, how long a toast stays, and the dismiss control name.
21
22
  * @returns The wrapped tree with its region.
22
23
  */
23
- export declare function Toaster({ children, dismissAfter }: ToasterProps): import("react").JSX.Element;
24
+ export declare function Toaster({ children, dismissAfter, dismissLabel, }: ToasterProps): import("react").JSX.Element;
package/dist/toaster.js CHANGED
@@ -7,6 +7,10 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use
7
7
  * How long a toast nobody touches stays on screen.
8
8
  */
9
9
  const DISMISS_AFTER = 10000;
10
+ /**
11
+ * The name of the control clearing a toast.
12
+ */
13
+ const DISMISS_LABEL = 'Dismiss';
10
14
  const ToasterContext = createContext(null);
11
15
  /**
12
16
  * Returns the handle raising messages in the toast region.
@@ -21,21 +25,21 @@ export function useToaster() {
21
25
  }
22
26
  /**
23
27
  * Renders one raised message with its optional action.
24
- * @param props - The toast and the handler clearing it.
28
+ * @param props - The toast, the handler clearing it, and the dismiss control name.
25
29
  * @returns The toast element.
26
30
  */
27
- function Toast({ toast, onClear }) {
31
+ function Toast({ toast, onClear, dismissLabel, }) {
28
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: () => {
29
33
  toast.action?.onAct();
30
34
  onClear(toast.id);
31
- }, children: toast.action.label })), _jsx(Notice.ActionButton, { onClick: () => onClear(toast.id), children: "Dismiss" })] })] }));
35
+ }, children: toast.action.label })), _jsx(Notice.ActionButton, { onClick: () => onClear(toast.id), children: dismissLabel })] })] }));
32
36
  }
33
37
  /**
34
38
  * Renders the region holding raised messages around the given tree.
35
- * @param props - The tree the region wraps and how long a toast stays.
39
+ * @param props - The tree the region wraps, how long a toast stays, and the dismiss control name.
36
40
  * @returns The wrapped tree with its region.
37
41
  */
38
- export function Toaster({ children, dismissAfter = DISMISS_AFTER }) {
42
+ export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, }) {
39
43
  const [toasts, setToasts] = useState([]);
40
44
  const nextId = useRef(0);
41
45
  const timers = useRef(new Set());
@@ -58,5 +62,5 @@ export function Toaster({ children, dismissAfter = DISMISS_AFTER }) {
58
62
  timers.current.add(setTimeout(() => clear(id), dismissAfter));
59
63
  }, [clear, dismissAfter]);
60
64
  const handle = useMemo(() => ({ show }), [show]);
61
- 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 }, toast.id))) })] }));
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))) })] }));
62
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.4.0",
3
+ "version": "0.6.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",
@@ -47,7 +47,7 @@
47
47
  "./package.json": "./package.json"
48
48
  },
49
49
  "scripts": {
50
- "build": "tsc -p tsconfig.build.json && cp src/base.css dist/base.css",
50
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && cp src/base.css dist/base.css",
51
51
  "cover": "vitest run --coverage",
52
52
  "lint": "oxlint",
53
53
  "lint:css": "stylelint 'src/**/*.css'",
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns whether a loading ghost should stand in for the pending work.
3
- * @param pending - Whether the work the ghost stands in for is still pending.
4
- * @returns Whether to render the ghost.
5
- */
6
- export declare function useLoadingGate(pending: boolean): boolean;
@@ -1,32 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- import { useEffect, useRef, useState } from 'react';
3
- const SHOW_AFTER = 200;
4
- const SHOW_FOR = 500;
5
- /**
6
- * Returns whether a loading ghost should stand in for the pending work.
7
- * @param pending - Whether the work the ghost stands in for is still pending.
8
- * @returns Whether to render the ghost.
9
- */
10
- export function useLoadingGate(pending) {
11
- const [showing, setShowing] = useState(false);
12
- const holdUntil = useRef(0);
13
- useEffect(() => {
14
- if (pending && !showing) {
15
- const delay = setTimeout(() => {
16
- holdUntil.current = Date.now() + SHOW_FOR;
17
- setShowing(true);
18
- }, SHOW_AFTER);
19
- return () => clearTimeout(delay);
20
- }
21
- if (!pending && showing) {
22
- const left = holdUntil.current - Date.now();
23
- if (left <= 0) {
24
- setShowing(false);
25
- return;
26
- }
27
- const hold = setTimeout(() => setShowing(false), left);
28
- return () => clearTimeout(hold);
29
- }
30
- }, [pending, showing]);
31
- return showing;
32
- }