shelving 1.312.0 → 1.312.2

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.
@@ -19511,7 +19511,7 @@ The components below are listed in the index following this page; this is the sh
19511
19511
  - [Title](ui/Title.md): Page title — renders an <h1>.
19512
19512
  - [Video](ui/Video.md): Video container element.
19513
19513
  - [Button](ui/Button.md): Render either a <button> or an <a href=""> styled as a button, based on whether an onClick or href prop is provided.
19514
- - [Clickable](ui/Clickable.md): Render either a <button>, an <a href="">, or a plain <span> based on whether an onClick or href prop is provided.
19514
+ - [Clickable](ui/Clickable.md): Render an <a href="">, a <button>, or a plain <span>, from the href, onClick and disabled props.
19515
19515
  - [FullscreenButton](ui/FullscreenButton.md): Button to toggle the surrounding <figure> element or <body> element in/out of fullscreen mode.
19516
19516
  - [RetryButton](ui/RetryButton.md): Button that retries the nearest <Catcher> error boundary when clicked.
19517
19517
  - [Dialog](ui/Dialog.md): Modal <dialog> element that opens on mount and includes a close button.
@@ -19546,7 +19546,7 @@ The components below are listed in the index following this page; this is the sh
19546
19546
  - [Deleted](ui/Deleted.md): Deleted text — renders a <del> element to mark content removed from a document.
19547
19547
  - [Emphasis](ui/Emphasis.md): Emphasised text — renders an <em> element for stress emphasis (typically italic).
19548
19548
  - [Inserted](ui/Inserted.md): Inserted text — renders an <ins> element to mark content added to a document.
19549
- - [Link](ui/Link.md): Inline link — delegates to <Clickable>, rendering an <a> (when href is set) or <button> (when onClick is set).
19549
+ - [Link](ui/Link.md): Inline link — delegates to <Clickable>, rendering an <a> (when href is set), a <button> (when onClick or disabled is set), or a <span>.
19550
19550
  - [Mark](ui/Mark.md): Highlighted text — renders a <mark> element to call attention to a run of text.
19551
19551
  - [Small](ui/Small.md): Small print — renders a <small> element for side comments and fine print.
19552
19552
  - [Span](ui/Span.md): Styled inline text — renders a <span> carrying only the colour and typography variant classes, with no styling of its own.
@@ -19633,7 +19633,7 @@ The components below are listed in the index following this page; this is the sh
19633
19633
  - [getButtonClass()](ui/getButtonClass.md): Get the full combined className string for a button from its styling variants.
19634
19634
  - [LinkClickable()](ui/LinkClickable.md): Render an <a href=""> element, resolving its href against the current page URL and marking it active when it matches.
19635
19635
  - [ButtonClickable()](ui/ButtonClickable.md): Render a <button> element that runs its onClick handler through a BusyStore and shows a loading spinner while busy.
19636
- - [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when neither href nor onClick is provided.
19636
+ - [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when none of href, onClick or disabled is provided, e.g. a plain tag.
19637
19637
  - [SubmitButton()](ui/SubmitButton.md): Submit button for a form that disables itself and shows a spinner while the form is busy.
19638
19638
  - [requireDialogs()](ui/requireDialogs.md): Read the current DialogsStore from the nearest <DialogsContext>.
19639
19639
  - [DocumentationApp()](ui/DocumentationApp.md): Documentation app.
@@ -22527,8 +22527,9 @@ Props for a clickable that also accepts a `className` for styling.
22527
22527
  - Kind: component
22528
22528
  - Import: `import { Clickable } from "shelving/ui";`
22529
22529
 
22530
- Render either a `<button>`, an `<a href="">`, or a plain `<span>` based on whether an `onClick` or `href` prop is provided.
22531
- - `href` renders a `LinkClickable`; `onClick` renders a `ButtonClickable`; neither renders a `SpanClickable`.
22530
+ Render an `<a href="">`, a `<button>`, or a plain `<span>`, from the `href`, `onClick` and `disabled` props.
22531
+ - `href` renders a `LinkClickable`; `onClick` or `disabled` renders a `ButtonClickable`; neither renders a `SpanClickable`.
22532
+ - `disabled` with no `onClick` is a disabled `<button>`, e.g. a "Locked" button that can never be pressed.
22532
22533
  - Dispatches on defined values (not key presence) so wrappers can always spread `href={href}` through, even when it's `undefined`.
22533
22534
 
22534
22535
  ## Signatures
@@ -22655,7 +22656,7 @@ ButtonClickable({
22655
22656
  - Kind: function
22656
22657
  - Import: `import { SpanClickable } from "shelving/ui";`
22657
22658
 
22658
- Render a non-interactive `<span>` element, used as the fallback when neither `href` nor `onClick` is provided.
22659
+ Render a non-interactive `<span>` element, used as the fallback when none of `href`, `onClick` or `disabled` is provided, e.g. a plain tag.
22659
22660
 
22660
22661
  ## Signatures
22661
22662
 
@@ -25882,7 +25883,7 @@ Props for `Link` — `ClickableProps` (`href` for navigation or `onClick` for ac
25882
25883
  - Kind: component
25883
25884
  - Import: `import { Link } from "shelving/ui";`
25884
25885
 
25885
- Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
25886
+ Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set), a `<button>` (when `onClick` or `disabled` is set), or a `<span>`.
25886
25887
 
25887
25888
  An inline link or action. Delegates to `<Clickable>`, rendering an `<a>` when `href` is provided or a `<button>` when `onClick` is provided — so the same component covers both navigation and in-page actions. Prefer it over a raw `<a>` inside React components.
25888
25889
 
@@ -30485,7 +30486,7 @@ Props for `<Tag>` — `TagVariants` styling options plus `<Clickable>` props (`h
30485
30486
  - Import: `import { Tag } from "shelving/ui";`
30486
30487
 
30487
30488
  Small inline label used to annotate other content.
30488
- - Delegates to `getClickable()` — renders as `<a>` when `href` is set, otherwise `<button>`.
30489
+ - Delegates to `<Clickable>` — renders as `<a>` when `href` is set, `<button>` when `onClick` or `disabled` is set, otherwise `<span>`.
30489
30490
  - Accepts a status variant (`success`, `info`, `error`, etc.) _or_ a raw colour (`color="red"`, `color="purple"`, etc.).
30490
30491
 
30491
30492
  A small inline label used to annotate other content. Accepts a status variant or a raw colour, and can be static or interactive depending on whether `href` / `onClick` is set.
@@ -3,8 +3,9 @@
3
3
  - Kind: component
4
4
  - Import: `import { Clickable } from "shelving/ui";`
5
5
 
6
- Render either a `<button>`, an `<a href="">`, or a plain `<span>` based on whether an `onClick` or `href` prop is provided.
7
- - `href` renders a `LinkClickable`; `onClick` renders a `ButtonClickable`; neither renders a `SpanClickable`.
6
+ Render an `<a href="">`, a `<button>`, or a plain `<span>`, from the `href`, `onClick` and `disabled` props.
7
+ - `href` renders a `LinkClickable`; `onClick` or `disabled` renders a `ButtonClickable`; neither renders a `SpanClickable`.
8
+ - `disabled` with no `onClick` is a disabled `<button>`, e.g. a "Locked" button that can never be pressed.
8
9
  - Dispatches on defined values (not key presence) so wrappers can always spread `href={href}` through, even when it's `undefined`.
9
10
 
10
11
  ## Signatures
package/docs/ui/Link.md CHANGED
@@ -3,7 +3,7 @@
3
3
  - Kind: component
4
4
  - Import: `import { Link } from "shelving/ui";`
5
5
 
6
- Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
6
+ Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set), a `<button>` (when `onClick` or `disabled` is set), or a `<span>`.
7
7
 
8
8
  An inline link or action. Delegates to `<Clickable>`, rendering an `<a>` when `href` is provided or a `<button>` when `onClick` is provided — so the same component covers both navigation and in-page actions. Prefer it over a raw `<a>` inside React components.
9
9
 
@@ -3,7 +3,7 @@
3
3
  - Kind: function
4
4
  - Import: `import { SpanClickable } from "shelving/ui";`
5
5
 
6
- Render a non-interactive `<span>` element, used as the fallback when neither `href` nor `onClick` is provided.
6
+ Render a non-interactive `<span>` element, used as the fallback when none of `href`, `onClick` or `disabled` is provided, e.g. a plain tag.
7
7
 
8
8
  ## Signatures
9
9
 
package/docs/ui/Tag.md CHANGED
@@ -4,7 +4,7 @@
4
4
  - Import: `import { Tag } from "shelving/ui";`
5
5
 
6
6
  Small inline label used to annotate other content.
7
- - Delegates to `getClickable()` — renders as `<a>` when `href` is set, otherwise `<button>`.
7
+ - Delegates to `<Clickable>` — renders as `<a>` when `href` is set, `<button>` when `onClick` or `disabled` is set, otherwise `<span>`.
8
8
  - Accepts a status variant (`success`, `info`, `error`, etc.) _or_ a raw colour (`color="red"`, `color="purple"`, etc.).
9
9
 
10
10
  A small inline label used to annotate other content. Accepts a status variant or a raw colour, and can be static or interactive depending on whether `href` / `onClick` is set.
package/docs/ui.md CHANGED
@@ -100,7 +100,7 @@ The components below are listed in the index following this page; this is the sh
100
100
  - [Title](ui/Title.md): Page title — renders an <h1>.
101
101
  - [Video](ui/Video.md): Video container element.
102
102
  - [Button](ui/Button.md): Render either a <button> or an <a href=""> styled as a button, based on whether an onClick or href prop is provided.
103
- - [Clickable](ui/Clickable.md): Render either a <button>, an <a href="">, or a plain <span> based on whether an onClick or href prop is provided.
103
+ - [Clickable](ui/Clickable.md): Render an <a href="">, a <button>, or a plain <span>, from the href, onClick and disabled props.
104
104
  - [FullscreenButton](ui/FullscreenButton.md): Button to toggle the surrounding <figure> element or <body> element in/out of fullscreen mode.
105
105
  - [RetryButton](ui/RetryButton.md): Button that retries the nearest <Catcher> error boundary when clicked.
106
106
  - [Dialog](ui/Dialog.md): Modal <dialog> element that opens on mount and includes a close button.
@@ -135,7 +135,7 @@ The components below are listed in the index following this page; this is the sh
135
135
  - [Deleted](ui/Deleted.md): Deleted text — renders a <del> element to mark content removed from a document.
136
136
  - [Emphasis](ui/Emphasis.md): Emphasised text — renders an <em> element for stress emphasis (typically italic).
137
137
  - [Inserted](ui/Inserted.md): Inserted text — renders an <ins> element to mark content added to a document.
138
- - [Link](ui/Link.md): Inline link — delegates to <Clickable>, rendering an <a> (when href is set) or <button> (when onClick is set).
138
+ - [Link](ui/Link.md): Inline link — delegates to <Clickable>, rendering an <a> (when href is set), a <button> (when onClick or disabled is set), or a <span>.
139
139
  - [Mark](ui/Mark.md): Highlighted text — renders a <mark> element to call attention to a run of text.
140
140
  - [Small](ui/Small.md): Small print — renders a <small> element for side comments and fine print.
141
141
  - [Span](ui/Span.md): Styled inline text — renders a <span> carrying only the colour and typography variant classes, with no styling of its own.
@@ -222,7 +222,7 @@ The components below are listed in the index following this page; this is the sh
222
222
  - [getButtonClass()](ui/getButtonClass.md): Get the full combined className string for a button from its styling variants.
223
223
  - [LinkClickable()](ui/LinkClickable.md): Render an <a href=""> element, resolving its href against the current page URL and marking it active when it matches.
224
224
  - [ButtonClickable()](ui/ButtonClickable.md): Render a <button> element that runs its onClick handler through a BusyStore and shows a loading spinner while busy.
225
- - [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when neither href nor onClick is provided.
225
+ - [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when none of href, onClick or disabled is provided, e.g. a plain tag.
226
226
  - [SubmitButton()](ui/SubmitButton.md): Submit button for a form that disables itself and shows a spinner while the form is busy.
227
227
  - [requireDialogs()](ui/requireDialogs.md): Read the current DialogsStore from the nearest <DialogsContext>.
228
228
  - [DocumentationApp()](ui/DocumentationApp.md): Documentation app.
@@ -1,6 +1,6 @@
1
1
  import type { Collection } from "../db/collection/Collection.js";
2
2
  import { DBProvider } from "../db/provider/DBProvider.js";
3
- import type { ImmutableArray } from "../util/array.js";
3
+ import { type ImmutableArray } from "../util/array.js";
4
4
  import type { Data } from "../util/data.js";
5
5
  import type { AnyCaller } from "../util/function.js";
6
6
  import type { Item, Items, ItemsSequence, OptionalItem, OptionalItemSequence } from "../util/item.js";
@@ -1,18 +1,20 @@
1
1
  import { DBProvider } from "../db/provider/DBProvider.js";
2
2
  import { ResponseError } from "../error/ResponseError.js";
3
3
  import { UnsupportedError } from "../error/UnsupportedError.js";
4
+ import { isArray } from "../util/array.js";
4
5
  import { getDelay } from "../util/async.js";
5
6
  import { joinDataPath } from "../util/data.js";
6
7
  import { BLACKHOLE } from "../util/function.js";
7
8
  import { getItem } from "../util/item.js";
8
9
  import { isPlainObject } from "../util/object.js";
9
- import { getQueryFilters, getQueryLimit, getQueryOrders } from "../util/query.js";
10
+ import { getQueryFilters, getQueryLimit, getQueryOrders, limitQueryItems, sortQueryItems, } from "../util/query.js";
10
11
  import { getRandom, getRandomKey } from "../util/random.js";
11
12
  import { getUpdates } from "../util/update.js";
12
13
  import { toData, toFirestoreFields, toFirestoreValue } from "./value.js";
13
14
  // Constants.
14
15
  const WRITE_BATCH = 500;
15
16
  const TRANSACTION_ATTEMPTS = 5;
17
+ const IN_MAX = 30; // Firestore allows at most 30 values in an `IN` filter.
16
18
  // Map `Filter.types` to Firestore REST `FieldFilter` operators.
17
19
  const OPERATORS = {
18
20
  is: "EQUAL",
@@ -82,6 +84,28 @@ function _getStructuredQuery(root, collection, query, select, caller) {
82
84
  structured.select = { fields: [{ fieldPath: "__name__" }] };
83
85
  return structured;
84
86
  }
87
+ /**
88
+ * Split a query with an `in` filter of more than `IN_MAX` values into queries of `IN_MAX` values each.
89
+ * - Returns `undefined` when the query needs no split.
90
+ * - Each query keeps the order and the limit, so the caller must merge, sort and limit the results again.
91
+ */
92
+ function _splitQuery(query) {
93
+ if (!query)
94
+ return;
95
+ for (const [key, value] of Object.entries(query)) {
96
+ if (!isArray(value) || value.length <= IN_MAX || /^[!$]|\[\]$|[<>=]$/.test(key))
97
+ continue;
98
+ const queries = [];
99
+ for (let i = 0; i < value.length; i += IN_MAX)
100
+ queries.push({ ...query, [key]: value.slice(i, i + IN_MAX) });
101
+ return queries.flatMap(q => _splitQuery(q) ?? [q]);
102
+ }
103
+ }
104
+ /** Get the orders Firestore sorts a query by: its own orders, then the document id in the direction of the last order. */
105
+ function _getFirestoreOrders(query) {
106
+ const orders = getQueryOrders(query);
107
+ return [...orders, { key: ["id"], direction: orders[orders.length - 1]?.direction ?? "asc" }];
108
+ }
85
109
  /** Convert an `Updates` object to a Firestore REST `Write` against a document name. */
86
110
  function _getUpdateWrite(name, updates, caller) {
87
111
  const fields = {};
@@ -184,6 +208,13 @@ export class FirestoreProvider extends DBProvider {
184
208
  }
185
209
  /** Run a query returning only the matching document names. */
186
210
  async _getQueryNames(collection, query, caller) {
211
+ const queries = _splitQuery(query);
212
+ if (queries) {
213
+ // A limit needs the full documents to find the first items across the queries.
214
+ if (query && getQueryLimit(query) !== undefined)
215
+ return (await this.getQuery(collection, query)).map(({ id }) => this._getDocumentName(collection, id));
216
+ return (await Promise.all(queries.map(q => this._getQueryNames(collection, q, caller)))).flat();
217
+ }
187
218
  const structuredQuery = _getStructuredQuery(this._root, collection.name, query, true, caller);
188
219
  if (!structuredQuery)
189
220
  return [];
@@ -225,6 +256,12 @@ export class FirestoreProvider extends DBProvider {
225
256
  await this._write([{ delete: this._getDocumentName(collection, id) }]);
226
257
  }
227
258
  async countQuery(collection, query) {
259
+ const queries = _splitQuery(query);
260
+ if (queries) {
261
+ const total = (await Promise.all(queries.map(q => this.countQuery(collection, q)))).reduce((a, b) => a + b, 0);
262
+ const limit = query && getQueryLimit(query);
263
+ return typeof limit === "number" ? Math.min(total, limit) : total;
264
+ }
228
265
  const structuredQuery = _getStructuredQuery(this._root, collection.name, query, false, this.countQuery);
229
266
  if (!structuredQuery)
230
267
  return 0;
@@ -236,6 +273,11 @@ export class FirestoreProvider extends DBProvider {
236
273
  return count ? Number(toData({ count }, this.countQuery).count) : 0;
237
274
  }
238
275
  async getQuery(collection, query) {
276
+ const queries = _splitQuery(query);
277
+ if (queries && query) {
278
+ const items = (await Promise.all(queries.map(q => this.getQuery(collection, q)))).flat();
279
+ return Array.from(limitQueryItems(sortQueryItems(items, _getFirestoreOrders(query)), getQueryLimit(query)));
280
+ }
239
281
  const structuredQuery = _getStructuredQuery(this._root, collection.name, query, false, this.getQuery);
240
282
  if (!structuredQuery)
241
283
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.312.0",
3
+ "version": "1.312.2",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,8 +43,9 @@ export interface ClickableProps extends OptionalChildProps {
43
43
  export interface StylableClickableProps extends ClickableProps, ClassProps {
44
44
  }
45
45
  /**
46
- * Render either a `<button>`, an `<a href="">`, or a plain `<span>` based on whether an `onClick` or `href` prop is provided.
47
- * - `href` renders a `LinkClickable`; `onClick` renders a `ButtonClickable`; neither renders a `SpanClickable`.
46
+ * Render an `<a href="">`, a `<button>`, or a plain `<span>`, from the `href`, `onClick` and `disabled` props.
47
+ * - `href` renders a `LinkClickable`; `onClick` or `disabled` renders a `ButtonClickable`; neither renders a `SpanClickable`.
48
+ * - `disabled` with no `onClick` is a disabled `<button>`, e.g. a "Locked" button that can never be pressed.
48
49
  * - Dispatches on defined values (not key presence) so wrappers can always spread `href={href}` through, even when it's `undefined`.
49
50
  *
50
51
  * @kind component
@@ -72,7 +73,7 @@ export declare function LinkClickable({ href, disabled, target, download, title,
72
73
  */
73
74
  export declare function ButtonClickable({ onClick, disabled, title, selected, children, className, }: StylableClickableProps): ReactElement;
74
75
  /**
75
- * Render a non-interactive `<span>` element, used as the fallback when neither `href` nor `onClick` is provided.
76
+ * Render a non-interactive `<span>` element, used as the fallback when none of `href`, `onClick` or `disabled` is provided, e.g. a plain tag.
76
77
  *
77
78
  * @example <SpanClickable className="label">Static</SpanClickable>
78
79
  * @see https://shelving.cc/ui/SpanClickable
@@ -9,8 +9,9 @@ import { requireMeta } from "../misc/MetaContext.js";
9
9
  import { getClass } from "../util/css.js";
10
10
  import { callNotifiedElement } from "../util/notice.js";
11
11
  /**
12
- * Render either a `<button>`, an `<a href="">`, or a plain `<span>` based on whether an `onClick` or `href` prop is provided.
13
- * - `href` renders a `LinkClickable`; `onClick` renders a `ButtonClickable`; neither renders a `SpanClickable`.
12
+ * Render an `<a href="">`, a `<button>`, or a plain `<span>`, from the `href`, `onClick` and `disabled` props.
13
+ * - `href` renders a `LinkClickable`; `onClick` or `disabled` renders a `ButtonClickable`; neither renders a `SpanClickable`.
14
+ * - `disabled` with no `onClick` is a disabled `<button>`, e.g. a "Locked" button that can never be pressed.
14
15
  * - Dispatches on defined values (not key presence) so wrappers can always spread `href={href}` through, even when it's `undefined`.
15
16
  *
16
17
  * @kind component
@@ -19,7 +20,7 @@ import { callNotifiedElement } from "../util/notice.js";
19
20
  * @see https://shelving.cc/ui/Clickable
20
21
  */
21
22
  export function Clickable(props) {
22
- return props.href !== undefined ? (_jsx(LinkClickable, { ...props })) : props.onClick !== undefined ? (_jsx(ButtonClickable, { ...props })) : (_jsx(SpanClickable, { ...props }));
23
+ return props.href !== undefined ? (_jsx(LinkClickable, { ...props })) : props.onClick !== undefined || props.disabled ? (_jsx(ButtonClickable, { ...props })) : (_jsx(SpanClickable, { ...props }));
23
24
  }
24
25
  /**
25
26
  * Render an `<a href="">` element, resolving its `href` against the current page URL and marking it active when it matches.
@@ -60,7 +61,7 @@ export function ButtonClickable({ onClick, disabled = !onClick, title, selected,
60
61
  }, children: busy ? LOADING : children }));
61
62
  }
62
63
  /**
63
- * Render a non-interactive `<span>` element, used as the fallback when neither `href` nor `onClick` is provided.
64
+ * Render a non-interactive `<span>` element, used as the fallback when none of `href`, `onClick` or `disabled` is provided, e.g. a plain tag.
64
65
  *
65
66
  * @example <SpanClickable className="label">Static</SpanClickable>
66
67
  * @see https://shelving.cc/ui/SpanClickable
@@ -55,8 +55,9 @@ export interface ClickableProps extends OptionalChildProps {
55
55
  export interface StylableClickableProps extends ClickableProps, ClassProps {}
56
56
 
57
57
  /**
58
- * Render either a `<button>`, an `<a href="">`, or a plain `<span>` based on whether an `onClick` or `href` prop is provided.
59
- * - `href` renders a `LinkClickable`; `onClick` renders a `ButtonClickable`; neither renders a `SpanClickable`.
58
+ * Render an `<a href="">`, a `<button>`, or a plain `<span>`, from the `href`, `onClick` and `disabled` props.
59
+ * - `href` renders a `LinkClickable`; `onClick` or `disabled` renders a `ButtonClickable`; neither renders a `SpanClickable`.
60
+ * - `disabled` with no `onClick` is a disabled `<button>`, e.g. a "Locked" button that can never be pressed.
60
61
  * - Dispatches on defined values (not key presence) so wrappers can always spread `href={href}` through, even when it's `undefined`.
61
62
  *
62
63
  * @kind component
@@ -67,7 +68,7 @@ export interface StylableClickableProps extends ClickableProps, ClassProps {}
67
68
  export function Clickable(props: StylableClickableProps): ReactElement {
68
69
  return props.href !== undefined ? (
69
70
  <LinkClickable {...props} />
70
- ) : props.onClick !== undefined ? (
71
+ ) : props.onClick !== undefined || props.disabled ? (
71
72
  <ButtonClickable {...props} />
72
73
  ) : (
73
74
  <SpanClickable {...props} />
@@ -161,7 +162,7 @@ export function ButtonClickable({
161
162
  }
162
163
 
163
164
  /**
164
- * Render a non-interactive `<span>` element, used as the fallback when neither `href` nor `onClick` is provided.
165
+ * Render a non-interactive `<span>` element, used as the fallback when none of `href`, `onClick` or `disabled` is provided, e.g. a plain tag.
165
166
  *
166
167
  * @example <SpanClickable className="label">Static</SpanClickable>
167
168
  * @see https://shelving.cc/ui/SpanClickable
@@ -12,7 +12,7 @@ export interface LinkProps extends ClickableProps, TypographyVariants, ClassProp
12
12
  plain?: boolean | undefined;
13
13
  }
14
14
  /**
15
- * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
15
+ * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set), a `<button>` (when `onClick` or `disabled` is set), or a `<span>`.
16
16
  *
17
17
  * @kind component
18
18
  * @see https://shelving.cc/ui/Link
package/ui/inline/Link.js CHANGED
@@ -4,7 +4,7 @@ import { getTypographyClass } from "../style/Typography.js";
4
4
  import { getClass, getModuleClass } from "../util/css.js";
5
5
  import LINK_CSS from "./Link.module.css";
6
6
  /**
7
- * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
7
+ * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set), a `<button>` (when `onClick` or `disabled` is set), or a `<span>`.
8
8
  *
9
9
  * @kind component
10
10
  * @see https://shelving.cc/ui/Link
@@ -16,7 +16,7 @@ export interface LinkProps extends ClickableProps, TypographyVariants, ClassProp
16
16
  }
17
17
 
18
18
  /**
19
- * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set) or `<button>` (when `onClick` is set).
19
+ * Inline link — delegates to `<Clickable>`, rendering an `<a>` (when `href` is set), a `<button>` (when `onClick` or `disabled` is set), or a `<span>`.
20
20
  *
21
21
  * @kind component
22
22
  * @see https://shelving.cc/ui/Link
package/ui/misc/Tag.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface TagProps extends TagVariants, ClickableProps, ClassProps {
28
28
  }
29
29
  /**
30
30
  * Small inline label used to annotate other content.
31
- * - Delegates to `getClickable()` — renders as `<a>` when `href` is set, otherwise `<button>`.
31
+ * - Delegates to `<Clickable>` — renders as `<a>` when `href` is set, `<button>` when `onClick` or `disabled` is set, otherwise `<span>`.
32
32
  * - Accepts a status variant (`success`, `info`, `error`, etc.) _or_ a raw colour (`color="red"`, `color="purple"`, etc.).
33
33
  *
34
34
  * @kind component
package/ui/misc/Tag.js CHANGED
@@ -19,7 +19,7 @@ export function getTagClass(variants) {
19
19
  }
20
20
  /**
21
21
  * Small inline label used to annotate other content.
22
- * - Delegates to `getClickable()` — renders as `<a>` when `href` is set, otherwise `<button>`.
22
+ * - Delegates to `<Clickable>` — renders as `<a>` when `href` is set, `<button>` when `onClick` or `disabled` is set, otherwise `<span>`.
23
23
  * - Accepts a status variant (`success`, `info`, `error`, etc.) _or_ a raw colour (`color="red"`, `color="purple"`, etc.).
24
24
  *
25
25
  * @kind component
package/ui/misc/Tag.tsx CHANGED
@@ -40,7 +40,7 @@ export interface TagProps extends TagVariants, ClickableProps, ClassProps {}
40
40
 
41
41
  /**
42
42
  * Small inline label used to annotate other content.
43
- * - Delegates to `getClickable()` — renders as `<a>` when `href` is set, otherwise `<button>`.
43
+ * - Delegates to `<Clickable>` — renders as `<a>` when `href` is set, `<button>` when `onClick` or `disabled` is set, otherwise `<span>`.
44
44
  * - Accepts a status variant (`success`, `info`, `error`, etc.) _or_ a raw colour (`color="red"`, `color="purple"`, etc.).
45
45
  *
46
46
  * @kind component
@@ -48,6 +48,11 @@ describe("ClassProps", () => {
48
48
  expect(html).not.toContain("<a ");
49
49
  });
50
50
 
51
+ test("clickable wrapper renders a disabled `<button>` when only `disabled` is set, and a `<span>` with nothing", () => {
52
+ expect(render(<Button disabled>Locked</Button>)).toContain('<button type="button" disabled=""');
53
+ expect(render(<Tag>New</Tag>)).toStartWith("<span");
54
+ });
55
+
51
56
  test("`className` lands on the component's own root, not on its inner elements", () => {
52
57
  // `Card` renders the class on its `<article>`, not on the stretched overlay `<a>` it also renders.
53
58
  const html = render(
package/util/start.js CHANGED
@@ -60,7 +60,7 @@ export class Starter {
60
60
  throw new UnexpectedError("Unexpected error in stop callback", { cause: thrown, caller: this.stop });
61
61
  }
62
62
  finally {
63
- this._started = true;
63
+ this._started = false;
64
64
  this._stop = undefined;
65
65
  }
66
66
  }