@gopherium/godmin 0.10.0 → 0.12.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`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
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` |
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` |
package/dist/base.css CHANGED
@@ -126,14 +126,12 @@ body {
126
126
  }
127
127
 
128
128
  .godmin-page__main {
129
- flex: 999 1 0;
130
- min-inline-size: min(50%, var(--wpds-dimension-surface-width-xl));
131
- max-inline-size: var(--wpds-dimension-surface-width-xl);
129
+ flex: 1 1 var(--wpds-dimension-surface-width-lg);
132
130
  }
133
131
 
134
132
  .godmin-page__aside {
135
- flex: 0 1 var(--wpds-dimension-surface-width-sm);
136
- min-inline-size: 0;
133
+ flex: 999 1 0;
134
+ min-inline-size: min(100%, var(--wpds-dimension-surface-width-xs));
137
135
  overflow-wrap: anywhere;
138
136
  }
139
137
 
@@ -145,7 +143,36 @@ body {
145
143
  display: flex;
146
144
  flex-direction: column;
147
145
  gap: var(--wpds-dimension-gap-md);
148
- max-width: var(--wpds-dimension-surface-width-sm);
146
+ max-width: var(--wpds-dimension-surface-width-lg);
147
+ }
148
+
149
+ .godmin-form--inline {
150
+ max-width: none;
151
+ }
152
+
153
+ .godmin-form > button {
154
+ align-self: flex-start;
155
+ }
156
+
157
+ .godmin-form__row {
158
+ display: flex;
159
+ flex-wrap: wrap;
160
+ align-items: flex-end;
161
+ gap: var(--wpds-dimension-gap-md);
162
+ }
163
+
164
+ .godmin-form__row > * {
165
+ flex: 1 1 calc(var(--wpds-dimension-surface-width-xs) * 2 / 3);
166
+ min-inline-size: 0;
167
+ }
168
+
169
+ .godmin-form__row > .godmin-form__grow {
170
+ flex-grow: 3;
171
+ }
172
+
173
+ .godmin-form__row > button {
174
+ flex: none;
175
+ margin-inline-start: auto;
149
176
  }
150
177
 
151
178
  .godmin-empty {
@@ -248,6 +275,78 @@ body {
248
275
  outline-offset: 2px;
249
276
  }
250
277
 
278
+ .godmin-rows__line {
279
+ display: flex;
280
+ flex-wrap: wrap;
281
+ align-items: flex-end;
282
+ gap: var(--wpds-dimension-gap-md);
283
+ }
284
+
285
+ .godmin-rows__inputs {
286
+ flex: 1 1 var(--wpds-dimension-surface-width-sm);
287
+ min-inline-size: 0;
288
+ }
289
+
290
+ .godmin-rows__controls {
291
+ flex: none;
292
+ margin-inline-start: auto;
293
+ }
294
+
295
+ .godmin-log-list {
296
+ margin: 0;
297
+ padding: 0;
298
+ list-style: none;
299
+ overflow-wrap: anywhere;
300
+ background: var(--wpds-color-background-surface-neutral-strong);
301
+ border: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral);
302
+ border-radius: var(--wpds-border-radius-lg);
303
+ }
304
+
305
+ .godmin-log-list:empty {
306
+ display: none;
307
+ }
308
+
309
+ .godmin-log-list__item {
310
+ display: flex;
311
+ flex-direction: column;
312
+ gap: var(--wpds-dimension-gap-xs);
313
+ padding: var(--wpds-dimension-padding-sm) var(--wpds-dimension-padding-md);
314
+ }
315
+
316
+ .godmin-log-list__item + .godmin-log-list__item {
317
+ border-block-start: var(--wpds-border-width-xs) solid
318
+ var(--wpds-color-stroke-surface-neutral-weak);
319
+ }
320
+
321
+ .godmin-log-list__header {
322
+ display: flex;
323
+ flex-wrap: wrap;
324
+ align-items: center;
325
+ gap: var(--wpds-dimension-gap-xs) var(--wpds-dimension-gap-sm);
326
+ }
327
+
328
+ .godmin-log-list__label {
329
+ flex: 1 1 auto;
330
+ min-inline-size: 0;
331
+ }
332
+
333
+ .godmin-log-list__actions {
334
+ display: flex;
335
+ flex-wrap: wrap;
336
+ align-items: center;
337
+ justify-content: flex-end;
338
+ gap: var(--wpds-dimension-gap-xs);
339
+ margin-inline-start: auto;
340
+ }
341
+
342
+ .godmin-log-list__body {
343
+ white-space: pre-line;
344
+ }
345
+
346
+ .godmin-log-list__time {
347
+ color: var(--wpds-color-foreground-content-neutral-weak);
348
+ }
349
+
251
350
  /* Small viewport overrides live together at the end of the sheet, so they
252
351
  always win over the rules above them without extra specificity. */
253
352
  @media (max-width: 639px) {
package/dist/index.d.ts CHANGED
@@ -6,9 +6,11 @@ export type { CanvasMode, FrameCanvasProps, FrameRailProps, FrameRootProps, } fr
6
6
  export { keyFromLabel } from './keys.js';
7
7
  export type { KeyOptions, KeyStyle } from './keys.js';
8
8
  export { LoadingRows, LoadingScreen } from './loading.js';
9
+ export { LogItem, LogList, LogTime } from './log-list.js';
10
+ export type { LogItemProps, LogListProps, LogTimeProps } from './log-list.js';
9
11
  export { NavScreen } from './nav-screen.js';
10
12
  export type { NavScreenProps } from './nav-screen.js';
11
- export { ErrorNotice, LoadMore, Page, PageTitle } from './page.js';
13
+ export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
12
14
  export type { LoadMoreQuery, PageProps } from './page.js';
13
15
  export { useRowKeys } from './row-keys.js';
14
16
  export type { RowBounds, RowKeys } from './row-keys.js';
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ export { DENSE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints
4
4
  export { Frame } from './frame.js';
5
5
  export { keyFromLabel } from './keys.js';
6
6
  export { LoadingRows, LoadingScreen } from './loading.js';
7
+ export { LogItem, LogList, LogTime } from './log-list.js';
7
8
  export { NavScreen } from './nav-screen.js';
8
- export { ErrorNotice, LoadMore, Page, PageTitle } from './page.js';
9
+ export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
9
10
  export { useRowKeys } from './row-keys.js';
10
11
  export { RepeatRows, RowControls } from './rows.js';
11
12
  export { Toaster, useToaster } from './toaster.js';
@@ -0,0 +1,46 @@
1
+ import type { ReactNode } from 'react';
2
+ /** What a log list needs. */
3
+ export interface LogListProps {
4
+ /** The items, each a LogItem the caller keys by its own id, in the order they read. */
5
+ children: ReactNode;
6
+ /** The id of the visible heading that names the list. */
7
+ 'aria-labelledby'?: string;
8
+ }
9
+ /** What one item of a log list needs. */
10
+ export interface LogItemProps {
11
+ /** The start of the header line, such as a LogTime. */
12
+ label?: ReactNode;
13
+ /** The controls at the end of the header line. */
14
+ actions?: ReactNode;
15
+ /** The item's text, shown with its line breaks kept. */
16
+ body?: string;
17
+ /** Any other content, shown under the body. */
18
+ children?: ReactNode;
19
+ /** The name the item is announced by. */
20
+ 'aria-label'?: string;
21
+ }
22
+ /** What a log time needs. */
23
+ export interface LogTimeProps {
24
+ /** The date or time in machine readable form, such as 2026-01-01. */
25
+ dateTime: string;
26
+ /** The date or time as the reader sees it. */
27
+ children: ReactNode;
28
+ }
29
+ /**
30
+ * Renders items one under the other in the order given.
31
+ * @param props - The items and the id of the heading that names the list.
32
+ * @returns The log list element.
33
+ */
34
+ export declare function LogList({ children, 'aria-labelledby': labelledBy }: LogListProps): import("react").JSX.Element;
35
+ /**
36
+ * Renders one log item, its header line over its text and any other content.
37
+ * @param props - The label, the actions, the text, the other content and the item's name.
38
+ * @returns The log item element.
39
+ */
40
+ export declare function LogItem({ label, actions, body, children, 'aria-label': name }: LogItemProps): import("react").JSX.Element;
41
+ /**
42
+ * Renders a date or time as small muted text inside a time element.
43
+ * @param props - The machine readable value and the text the reader sees.
44
+ * @returns The time element.
45
+ */
46
+ export declare function LogTime({ dateTime, children }: LogTimeProps): import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Text } from '@wordpress/ui';
4
+ /**
5
+ * Renders items one under the other in the order given.
6
+ * @param props - The items and the id of the heading that names the list.
7
+ * @returns The log list element.
8
+ */
9
+ export function LogList({ children, 'aria-labelledby': labelledBy }) {
10
+ return (_jsx("ul", { role: "list", className: "godmin-log-list", "aria-labelledby": labelledBy, children: children }));
11
+ }
12
+ /**
13
+ * Renders one log item, its header line over its text and any other content.
14
+ * @param props - The label, the actions, the text, the other content and the item's name.
15
+ * @returns The log item element.
16
+ */
17
+ export function LogItem({ label, actions, body, children, 'aria-label': name }) {
18
+ return (_jsxs("li", { className: "godmin-log-list__item", "aria-label": name, children: [_jsx(LogHeader, { label: label, actions: actions }), body !== undefined && (_jsx(Text, { render: _jsx("p", {}), className: "godmin-log-list__body", children: body })), children] }));
19
+ }
20
+ /**
21
+ * Renders the header line of a log item, or nothing without a label or actions.
22
+ * @param props - The label and the actions.
23
+ * @returns The header line element, or null.
24
+ */
25
+ function LogHeader({ label, actions }) {
26
+ const labelled = rendersSomething(label);
27
+ const acting = rendersSomething(actions);
28
+ if (!labelled && !acting) {
29
+ return null;
30
+ }
31
+ return (_jsxs("div", { className: "godmin-log-list__header", children: [labelled && _jsx("div", { className: "godmin-log-list__label", children: label }), acting && _jsx("div", { className: "godmin-log-list__actions", children: actions })] }));
32
+ }
33
+ /**
34
+ * Reports whether React renders anything for a node.
35
+ * @param node - The node to check.
36
+ * @returns False for undefined, null, booleans, an empty string and a list of those, true otherwise.
37
+ */
38
+ function rendersSomething(node) {
39
+ if (Array.isArray(node)) {
40
+ return node.some(rendersSomething);
41
+ }
42
+ return node !== undefined && node !== null && node !== '' && typeof node !== 'boolean';
43
+ }
44
+ /**
45
+ * Renders a date or time as small muted text inside a time element.
46
+ * @param props - The machine readable value and the text the reader sees.
47
+ * @returns The time element.
48
+ */
49
+ export function LogTime({ dateTime, children }) {
50
+ return (_jsx(Text, { variant: "body-sm", render: _jsx("time", { dateTime: dateTime }), className: "godmin-log-list__time", children: children }));
51
+ }
package/dist/page.d.ts CHANGED
@@ -10,6 +10,17 @@ export declare function PageTitle({ children, variant, }: {
10
10
  children: ReactNode;
11
11
  variant?: TextVariant;
12
12
  }): import("react").JSX.Element;
13
+ /**
14
+ * Renders a section heading one size step above the field labels.
15
+ * @param props - The heading text, its level, and the id and tab index a screen moves focus with.
16
+ * @returns The section heading element.
17
+ */
18
+ export declare function SectionTitle({ children, level, id, tabIndex, }: {
19
+ children: ReactNode;
20
+ level?: 2 | 3;
21
+ id?: string;
22
+ tabIndex?: number;
23
+ }): import("react").JSX.Element;
13
24
  export interface PageProps {
14
25
  title: string;
15
26
  subtitle?: string;
package/dist/page.js CHANGED
@@ -10,6 +10,15 @@ import { Button, Notice, Stack, Text } from '@wordpress/ui';
10
10
  export function PageTitle({ children, variant = 'heading-xl', }) {
11
11
  return (_jsx(Text, { variant: variant, render: _jsx("h1", {}), children: children }));
12
12
  }
13
+ /**
14
+ * Renders a section heading one size step above the field labels.
15
+ * @param props - The heading text, its level, and the id and tab index a screen moves focus with.
16
+ * @returns The section heading element.
17
+ */
18
+ export function SectionTitle({ children, level = 2, id, tabIndex, }) {
19
+ const second = level === 2;
20
+ return (_jsx(Text, { variant: second ? 'heading-lg' : 'heading-md', render: second ? _jsx("h2", {}) : _jsx("h3", {}), id: id, tabIndex: tabIndex, children: children }));
21
+ }
13
22
  /**
14
23
  * Renders a screen: its title top left, an optional subtitle under it,
15
24
  * optional actions top right, and the content below, beside an optional aside.
package/dist/rows.js CHANGED
@@ -5,13 +5,14 @@ import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
5
5
  import { useRowKeys } from './row-keys.js';
6
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
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" }) }));
8
9
  /**
9
10
  * Renders the buttons that move a row among its siblings and take it away.
10
11
  * @param props - The row's place, the list's length, the words and what to call on a change.
11
12
  * @returns The controls element.
12
13
  */
13
14
  export function RowControls({ at, count, removable = true, labels, onMove, onRemove }) {
14
- return (_jsxs(Stack, { direction: "row", gap: "xs", align: "center", children: [_jsx(IconButton, { icon: upIcon, label: labels.moveUp, size: "compact", variant: "minimal", tone: "neutral", disabled: at === 0, onClick: () => onMove(-1) }), _jsx(IconButton, { icon: downIcon, label: labels.moveDown, size: "compact", variant: "minimal", tone: "neutral", disabled: at === count - 1, onClick: () => onMove(1) }), _jsx(Button, { variant: "outline", size: "compact", disabled: !removable, onClick: onRemove, children: labels.remove })] }));
15
+ return (_jsxs(Stack, { direction: "row", gap: "xs", align: "center", className: "godmin-rows__controls", children: [_jsx(IconButton, { icon: upIcon, label: labels.moveUp, size: "compact", variant: "minimal", tone: "neutral", disabled: at === 0, onClick: () => onMove(-1) }), _jsx(IconButton, { icon: downIcon, label: labels.moveDown, size: "compact", variant: "minimal", tone: "neutral", disabled: at === count - 1, onClick: () => onMove(1) }), _jsx(IconButton, { icon: removeIcon, label: labels.remove, size: "compact", variant: "minimal", tone: "neutral", disabled: !removable, onClick: onRemove })] }));
15
16
  }
16
17
  /**
17
18
  * Returns where focus goes after the rows shown change.
@@ -120,7 +121,7 @@ function useRowFocus(keys) {
120
121
  function RowGroup({ rowKey, row, at, count, removable, labels, renderRow, rowLabel, update, move, remove, register, entered, }) {
121
122
  const changed = useCallback((next) => update(rowKey, next), [update, rowKey]);
122
123
  const ref = useCallback((element) => register(rowKey, element), [register, rowKey]);
123
- return (_jsx("div", { ref: ref, role: "group", "aria-label": rowLabel(at), tabIndex: -1, className: "godmin-rows__row", onFocus: (event) => entered(rowKey, event.target), children: _jsxs(Stack, { direction: "column", gap: "xs", children: [renderRow(row, changed, at), _jsx(RowControls, { at: at, count: count, removable: removable, labels: labels, onMove: (offset) => move(rowKey, offset), onRemove: () => remove(rowKey) })] }) }));
124
+ return (_jsx("div", { ref: ref, role: "group", "aria-label": rowLabel(at), tabIndex: -1, className: "godmin-rows__row", onFocus: (event) => entered(rowKey, event.target), children: _jsxs("div", { className: "godmin-rows__line", children: [_jsx("div", { className: "godmin-rows__inputs", children: renderRow(row, changed, at) }), _jsx(RowControls, { at: at, count: count, removable: removable, labels: labels, onMove: (offset) => move(rowKey, offset), onRemove: () => remove(rowKey) })] }) }));
124
125
  }
125
126
  /** The group of one row, rendered again only when its own props change. */
126
127
  const Row = memo(RowGroup);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.10.0",
3
+ "version": "0.12.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",