shelving 1.299.0 → 1.301.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.
Files changed (42) hide show
  1. package/package.json +1 -1
  2. package/ui/input/ArrayCheckboxInputs.d.ts +26 -0
  3. package/ui/input/ArrayCheckboxInputs.js +23 -0
  4. package/ui/input/ArrayCheckboxInputs.tsx +59 -0
  5. package/ui/input/ImageInput.d.ts +27 -0
  6. package/ui/input/ImageInput.js +49 -0
  7. package/ui/input/ImageInput.md +48 -0
  8. package/ui/input/ImageInput.module.css +79 -0
  9. package/ui/input/ImageInput.tsx +100 -0
  10. package/ui/input/Input.module.css +10 -1
  11. package/ui/input/Input.test.tsx +33 -1
  12. package/ui/input/QueryCheckboxesInput.d.ts +24 -0
  13. package/ui/input/QueryCheckboxesInput.js +20 -0
  14. package/ui/input/QueryCheckboxesInput.md +38 -0
  15. package/ui/input/QueryCheckboxesInput.test.tsx +42 -0
  16. package/ui/input/QueryCheckboxesInput.tsx +50 -0
  17. package/ui/input/QueryInputBase.d.ts +48 -0
  18. package/ui/input/QueryInputBase.js +48 -0
  19. package/ui/input/QueryInputBase.tsx +126 -0
  20. package/ui/input/QueryRadiosInput.d.ts +22 -0
  21. package/ui/input/QueryRadiosInput.js +23 -0
  22. package/ui/input/QueryRadiosInput.md +42 -0
  23. package/ui/input/{QueryInput.test.tsx → QueryRadiosInput.test.tsx} +12 -4
  24. package/ui/input/QueryRadiosInput.tsx +53 -0
  25. package/ui/input/TextInput.js +1 -1
  26. package/ui/input/TextInput.tsx +2 -1
  27. package/ui/input/index.d.ts +5 -1
  28. package/ui/input/index.js +5 -1
  29. package/ui/input/index.ts +5 -1
  30. package/ui/notice/Empty.d.ts +24 -0
  31. package/ui/notice/Empty.js +20 -0
  32. package/ui/notice/Empty.md +35 -0
  33. package/ui/notice/Empty.test.tsx +18 -0
  34. package/ui/notice/Empty.tsx +34 -0
  35. package/ui/notice/index.d.ts +1 -0
  36. package/ui/notice/index.js +1 -0
  37. package/ui/notice/index.ts +1 -0
  38. package/ui/util/props.test.tsx +1 -1
  39. package/ui/input/QueryInput.d.ts +0 -44
  40. package/ui/input/QueryInput.js +0 -53
  41. package/ui/input/QueryInput.md +0 -38
  42. package/ui/input/QueryInput.tsx +0 -126
@@ -0,0 +1,50 @@
1
+ import type { ReactElement } from "react";
2
+ import type { ImmutableArray } from "../../util/array.js";
3
+ import { formatValue } from "../../util/format.js";
4
+ import { ArrayCheckboxInputs } from "./ArrayCheckboxInputs.js";
5
+ import type { ValueInputProps } from "./Input.js";
6
+ import { QueryInputBase, type QueryInputBaseProps } from "./QueryInputBase.js";
7
+
8
+ /**
9
+ * Props for `QueryCheckboxesInput`, a combo box that queries items of type `O` from an input of type `I`, and picks any number of them.
10
+ *
11
+ * @see https://shelving.cc/ui/QueryCheckboxesInputProps
12
+ */
13
+ export interface QueryCheckboxesInputProps<I, O> extends QueryInputBaseProps<I, O>, ValueInputProps<ImmutableArray<O>> {}
14
+
15
+ /**
16
+ * Combo box that queries a list of items and lets the user pick any number of them, with checkboxes.
17
+ * - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
18
+ * - Shows a `<Popover>` with a checkbox list of returned items. The value is the array of checked items. The popover stays open while the user checks items.
19
+ * - With `popover={false}`, shows the checkbox list inline below the input instead.
20
+ * - Checked items stay checked when a new query does not return them. Items are compared with `===`, so `onQuery()` must return the same objects each time (or primitives).
21
+ * - Errors, loading, and empty states are handled automatically.
22
+ *
23
+ * @kind component
24
+ * @returns A combo box element wrapping the input and results popover (or the inline list).
25
+ * @see https://shelving.cc/ui/QueryCheckboxesInput
26
+ */
27
+ export function QueryCheckboxesInput<I, O>({
28
+ value,
29
+ onValue,
30
+ formatter = formatValue,
31
+ ...props
32
+ }: QueryCheckboxesInputProps<I, O>): ReactElement {
33
+ const { name, required, disabled } = props;
34
+ return (
35
+ <QueryInputBase<I, O>
36
+ {...props}
37
+ list={items => (
38
+ <ArrayCheckboxInputs
39
+ name={name}
40
+ required={required}
41
+ disabled={disabled}
42
+ items={items}
43
+ value={value}
44
+ formatter={formatter}
45
+ onValue={onValue}
46
+ />
47
+ )}
48
+ />
49
+ );
50
+ }
@@ -0,0 +1,48 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Schema } from "../../schema/Schema.js";
3
+ import { type PayloadFetchCallback } from "../../store/PayloadFetchStore.js";
4
+ import type { ImmutableArray } from "../../util/array.js";
5
+ import type { InputProps } from "./Input.js";
6
+ /**
7
+ * Props shared by `QueryRadiosInput` and `QueryCheckboxesInput`.
8
+ *
9
+ * @see https://shelving.cc/ui/QueryInputBaseProps
10
+ */
11
+ export interface QueryInputBaseProps<I, O> extends InputProps {
12
+ /** Schema for the text input. Its `one` and `many` name the items, e.g. `one: "user"` shows "No users". */
13
+ schema: Schema<I>;
14
+ /**
15
+ * Called with the current text value to return matching items whenever the text input changes.
16
+ * - Automatically debounced, so only called after a short delay.
17
+ * - Automatically shows a loading state while loading.
18
+ * - Returning `undefined` signals to close the popover (or, with `popover={false}`, to show no list).
19
+ */
20
+ onQuery: PayloadFetchCallback<I, ImmutableArray<O> | undefined>;
21
+ /** Format an item of type `O` for display in the list, for example as text or as an avatar. */
22
+ formatter?: ((value: O) => ReactNode) | undefined;
23
+ /**
24
+ * Show the results in a popover (the default), or set `false` to show them inline, as a list below the input.
25
+ * - Inline, the list shows at once: `onQuery()` is called with the schema's default value (e.g. `""`) on mount.
26
+ * - Inline, an empty input still queries.
27
+ */
28
+ popover?: boolean | undefined;
29
+ /**
30
+ * Message that shows in an `<Empty>` when the query returns `[]` (set to `""` to show no message).
31
+ * @default `No ${schema.many}`, e.g. "No users"
32
+ */
33
+ empty?: ReactNode | undefined;
34
+ }
35
+ /** Props for the internal `QueryInputBase`: the shared props, plus a function that renders the list of items. */
36
+ interface QueryInputBaseFrameProps<I, O> extends QueryInputBaseProps<I, O> {
37
+ /** Render the list for the items the query returned. `close()` closes the popover. */
38
+ list: (items: ImmutableArray<O>, close: () => void) => ReactNode;
39
+ }
40
+ /**
41
+ * Text input that queries a list of items, then shows the list in a popover or inline.
42
+ * - Shared by `QueryRadiosInput` and `QueryCheckboxesInput`, which each render their own list.
43
+ * - The text input is never required: the picked items are the value, not the text.
44
+ * - The store is kept when the parent renders again with a new `onQuery()`, so the list does not load again.
45
+ * - Errors show in an `<ErrorNotice>`. Loading and empty states show in an `<Empty>`.
46
+ */
47
+ export declare function QueryInputBase<I, O>({ schema, onQuery, popover, empty, list, className, ...props }: QueryInputBaseFrameProps<I, O>): ReactElement;
48
+ export {};
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { useInstance } from "../../react/useInstance.js";
4
+ import { useStore } from "../../react/useStore.js";
5
+ import { PayloadFetchStore } from "../../store/PayloadFetchStore.js";
6
+ import { NONE, SECOND } from "../../util/constants.js";
7
+ import { Column } from "../block/Column.js";
8
+ import { Paragraph } from "../block/Paragraph.js";
9
+ import { ErrorNotice } from "../misc/Catcher.js";
10
+ import { EMPTY_LOADING, Empty } from "../notice/Empty.js";
11
+ import { Popover } from "./Popover.js";
12
+ import { SchemaInput } from "./SchemaInput.js";
13
+ /**
14
+ * Text input that queries a list of items, then shows the list in a popover or inline.
15
+ * - Shared by `QueryRadiosInput` and `QueryCheckboxesInput`, which each render their own list.
16
+ * - The text input is never required: the picked items are the value, not the text.
17
+ * - The store is kept when the parent renders again with a new `onQuery()`, so the list does not load again.
18
+ * - Errors show in an `<ErrorNotice>`. Loading and empty states show in an `<Empty>`.
19
+ */
20
+ export function QueryInputBase({ schema, onQuery, popover = true, empty = `No ${schema.many}`, list, className, ...props }) {
21
+ // Keep one store while the component lives. `onQuery()` is often a new function on each render, so the store calls the latest one through a ref.
22
+ const latest = useRef(onQuery);
23
+ latest.current = onQuery;
24
+ const query = (useRef(undefined).current ??= (payload, signal) => latest.current(payload, signal));
25
+ const store = useStore(useInstance(PayloadFetchStore, NONE, undefined, query, SECOND));
26
+ const busy = useStore(store.busy).value;
27
+ // Inline, query the schema's default value at once, so the list shows before anything is typed.
28
+ useEffect(() => {
29
+ if (!popover)
30
+ store.payload.value = schema.value;
31
+ }, [popover, store, schema]);
32
+ // Is popover open?
33
+ const isOpen = busy || !!store.reason || !!store.value;
34
+ // Close the popover and clear the results.
35
+ const close = () => {
36
+ store.payload.value = NONE;
37
+ store.value = undefined;
38
+ };
39
+ const results = busy ? (EMPTY_LOADING) : store.reason ? (_jsx(ErrorNotice, { reason: store.reason })) : store.value?.length ? (list(store.value, close)) : empty && store.value ? (_jsx(Empty, { children: typeof empty === "string" ? _jsx(Paragraph, { children: empty }) : empty })) : null;
40
+ if (!popover)
41
+ return (_jsxs(Column, { children: [_jsx(SchemaInput, { ...props, required: false, schema: schema, className: className, onValue: v => void (store.payload.value = v) }), results] }));
42
+ return (_jsxs(Popover, { open: isOpen, onClose: close, children: [_jsx(SchemaInput, { ...props, required: false, schema: schema, className: className, onValue: v => {
43
+ if (v)
44
+ store.payload.value = v;
45
+ else
46
+ close();
47
+ } }), results] }));
48
+ }
@@ -0,0 +1,126 @@
1
+ import { type ReactElement, type ReactNode, useEffect, useRef } from "react";
2
+ import { useInstance } from "../../react/useInstance.js";
3
+ import { useStore } from "../../react/useStore.js";
4
+ import type { Schema } from "../../schema/Schema.js";
5
+ import { type PayloadFetchCallback, PayloadFetchStore } from "../../store/PayloadFetchStore.js";
6
+ import type { ImmutableArray } from "../../util/array.js";
7
+ import { NONE, SECOND } from "../../util/constants.js";
8
+ import { Column } from "../block/Column.js";
9
+ import { Paragraph } from "../block/Paragraph.js";
10
+ import { ErrorNotice } from "../misc/Catcher.js";
11
+ import { EMPTY_LOADING, Empty } from "../notice/Empty.js";
12
+ import type { InputProps } from "./Input.js";
13
+ import { Popover } from "./Popover.js";
14
+ import { SchemaInput } from "./SchemaInput.js";
15
+
16
+ /**
17
+ * Props shared by `QueryRadiosInput` and `QueryCheckboxesInput`.
18
+ *
19
+ * @see https://shelving.cc/ui/QueryInputBaseProps
20
+ */
21
+ export interface QueryInputBaseProps<I, O> extends InputProps {
22
+ /** Schema for the text input. Its `one` and `many` name the items, e.g. `one: "user"` shows "No users". */
23
+ schema: Schema<I>;
24
+
25
+ /**
26
+ * Called with the current text value to return matching items whenever the text input changes.
27
+ * - Automatically debounced, so only called after a short delay.
28
+ * - Automatically shows a loading state while loading.
29
+ * - Returning `undefined` signals to close the popover (or, with `popover={false}`, to show no list).
30
+ */
31
+ onQuery: PayloadFetchCallback<I, ImmutableArray<O> | undefined>;
32
+
33
+ /** Format an item of type `O` for display in the list, for example as text or as an avatar. */
34
+ formatter?: ((value: O) => ReactNode) | undefined;
35
+
36
+ /**
37
+ * Show the results in a popover (the default), or set `false` to show them inline, as a list below the input.
38
+ * - Inline, the list shows at once: `onQuery()` is called with the schema's default value (e.g. `""`) on mount.
39
+ * - Inline, an empty input still queries.
40
+ */
41
+ popover?: boolean | undefined;
42
+
43
+ /**
44
+ * Message that shows in an `<Empty>` when the query returns `[]` (set to `""` to show no message).
45
+ * @default `No ${schema.many}`, e.g. "No users"
46
+ */
47
+ empty?: ReactNode | undefined;
48
+ }
49
+
50
+ /** Props for the internal `QueryInputBase`: the shared props, plus a function that renders the list of items. */
51
+ interface QueryInputBaseFrameProps<I, O> extends QueryInputBaseProps<I, O> {
52
+ /** Render the list for the items the query returned. `close()` closes the popover. */
53
+ list: (items: ImmutableArray<O>, close: () => void) => ReactNode;
54
+ }
55
+
56
+ /**
57
+ * Text input that queries a list of items, then shows the list in a popover or inline.
58
+ * - Shared by `QueryRadiosInput` and `QueryCheckboxesInput`, which each render their own list.
59
+ * - The text input is never required: the picked items are the value, not the text.
60
+ * - The store is kept when the parent renders again with a new `onQuery()`, so the list does not load again.
61
+ * - Errors show in an `<ErrorNotice>`. Loading and empty states show in an `<Empty>`.
62
+ */
63
+ export function QueryInputBase<I, O>({
64
+ schema,
65
+ onQuery,
66
+ popover = true,
67
+ empty = `No ${schema.many}`,
68
+ list,
69
+ className,
70
+ ...props
71
+ }: QueryInputBaseFrameProps<I, O>): ReactElement {
72
+ // Keep one store while the component lives. `onQuery()` is often a new function on each render, so the store calls the latest one through a ref.
73
+ const latest = useRef(onQuery);
74
+ latest.current = onQuery;
75
+ const query = (useRef<typeof onQuery>(undefined).current ??= (payload, signal) => latest.current(payload, signal));
76
+ const store = useStore(useInstance(PayloadFetchStore, NONE, undefined, query, SECOND));
77
+ const busy = useStore(store.busy).value;
78
+
79
+ // Inline, query the schema's default value at once, so the list shows before anything is typed.
80
+ useEffect(() => {
81
+ if (!popover) store.payload.value = schema.value as I;
82
+ }, [popover, store, schema]);
83
+
84
+ // Is popover open?
85
+ const isOpen = busy || !!store.reason || !!store.value;
86
+
87
+ // Close the popover and clear the results.
88
+ const close = () => {
89
+ store.payload.value = NONE;
90
+ store.value = undefined;
91
+ };
92
+
93
+ const results = busy ? (
94
+ EMPTY_LOADING
95
+ ) : store.reason ? (
96
+ <ErrorNotice reason={store.reason} />
97
+ ) : store.value?.length ? (
98
+ list(store.value, close)
99
+ ) : empty && store.value ? (
100
+ <Empty>{typeof empty === "string" ? <Paragraph>{empty}</Paragraph> : empty}</Empty>
101
+ ) : null;
102
+
103
+ if (!popover)
104
+ return (
105
+ <Column>
106
+ <SchemaInput {...props} required={false} schema={schema} className={className} onValue={v => void (store.payload.value = v as I)} />
107
+ {results}
108
+ </Column>
109
+ );
110
+
111
+ return (
112
+ <Popover open={isOpen} onClose={close}>
113
+ <SchemaInput
114
+ {...props}
115
+ required={false}
116
+ schema={schema}
117
+ className={className}
118
+ onValue={v => {
119
+ if (v) store.payload.value = v;
120
+ else close();
121
+ }}
122
+ />
123
+ {results}
124
+ </Popover>
125
+ );
126
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactElement } from "react";
2
+ import type { ValueInputProps } from "./Input.js";
3
+ import { type QueryInputBaseProps } from "./QueryInputBase.js";
4
+ /**
5
+ * Props for `QueryRadiosInput`, a combo box that queries items of type `O` from an input of type `I`, and picks one.
6
+ *
7
+ * @see https://shelving.cc/ui/QueryRadiosInputProps
8
+ */
9
+ export interface QueryRadiosInputProps<I, O> extends QueryInputBaseProps<I, O>, ValueInputProps<O> {
10
+ }
11
+ /**
12
+ * Combo box that queries a list of items and lets the user pick one, with radios.
13
+ * - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
14
+ * - Shows a `<Popover>` with a radio list of returned items to pick a final value of type `O`. Picking an item closes the popover.
15
+ * - With `popover={false}`, shows the radio list inline below the input instead, like a `<select>` list box.
16
+ * - Errors, loading, and empty states are handled automatically.
17
+ *
18
+ * @kind component
19
+ * @returns A combo box element wrapping the input and results popover (or the inline list).
20
+ * @see https://shelving.cc/ui/QueryRadiosInput
21
+ */
22
+ export declare function QueryRadiosInput<I, O>({ value, onValue, formatter, popover, ...props }: QueryRadiosInputProps<I, O>): ReactElement;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { formatValue } from "../../util/format.js";
3
+ import { ArrayRadioInputs } from "./ArrayRadioInputs.js";
4
+ import { QueryInputBase } from "./QueryInputBase.js";
5
+ /**
6
+ * Combo box that queries a list of items and lets the user pick one, with radios.
7
+ * - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
8
+ * - Shows a `<Popover>` with a radio list of returned items to pick a final value of type `O`. Picking an item closes the popover.
9
+ * - With `popover={false}`, shows the radio list inline below the input instead, like a `<select>` list box.
10
+ * - Errors, loading, and empty states are handled automatically.
11
+ *
12
+ * @kind component
13
+ * @returns A combo box element wrapping the input and results popover (or the inline list).
14
+ * @see https://shelving.cc/ui/QueryRadiosInput
15
+ */
16
+ export function QueryRadiosInput({ value, onValue, formatter = formatValue, popover = true, ...props }) {
17
+ const { name, required, disabled } = props;
18
+ return (_jsx(QueryInputBase, { ...props, popover: popover, list: (items, close) => (_jsx(ArrayRadioInputs, { name: name, required: required, disabled: disabled, items: items, value: value, formatter: formatter, onValue: v => {
19
+ onValue(v);
20
+ if (popover)
21
+ close();
22
+ } })) }));
23
+ }
@@ -0,0 +1,42 @@
1
+ # QueryRadiosInput
2
+
3
+ Combo box that queries a list of items and lets the user pick one. The text in the input goes to `onQuery()`, and the items it returns show as a radio list.
4
+
5
+ **Things to know:**
6
+
7
+ - `onQuery()` is debounced (one second). Loading and empty states show in an `<Empty>`, and errors in an `<ErrorNotice>`.
8
+ - By default the list shows in a `<Popover>`, which closes when the user picks an item.
9
+ - With `popover={false}` the list shows inline, below the input, like a `<select>` list box. It queries the schema's default value on mount, so the list shows before the user types. Picking an item keeps the list.
10
+ - `formatter` can return any `ReactNode`, for example an avatar, not only a string.
11
+ - The empty message is "No" plus the schema's `many`. Set `one: "user"` on the schema to show "No users", or set `empty` (`""` shows no message).
12
+ - To pick more than one item, use `<QueryCheckboxesInput>`.
13
+
14
+ ## Usage
15
+
16
+ ### Popover
17
+
18
+ ```tsx
19
+ import { QueryRadiosInput } from "shelving/ui";
20
+ import { StringSchema } from "shelving/schema";
21
+
22
+ const SEARCH = new StringSchema({ title: "Search", one: "user" });
23
+
24
+ <QueryRadiosInput name="user" schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
25
+ ```
26
+
27
+ ### Inline list with avatars
28
+
29
+ ```tsx
30
+ <QueryRadiosInput
31
+ popover={false}
32
+ name="user"
33
+ schema={SEARCH}
34
+ onQuery={search}
35
+ formatter={user => <Avatar user={user} />}
36
+ onValue={setUser}
37
+ />
38
+ ```
39
+
40
+ ## Styling
41
+
42
+ `<QueryRadiosInput>` has no own hooks. The popover version uses the `<Popover>` styles. The inline version is a `<Column>` with the input and the `<ArrayRadioInputs>` list, so it uses their styles.
@@ -1,17 +1,25 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
3
  import { STRING } from "shelving/schema";
4
- import { QueryInput } from "shelving/ui";
4
+ import { QueryRadiosInput } from "shelving/ui";
5
5
  import { PASSTHROUGH } from "shelving/util/function";
6
6
 
7
- describe("QueryInput", () => {
7
+ describe("QueryRadiosInput", () => {
8
8
  test("shows the input with no popover when `popover={false}`", () => {
9
- const html = renderToStaticMarkup(<QueryInput popover={false} name="q" schema={STRING} onQuery={() => []} onValue={PASSTHROUGH} />);
9
+ const html = renderToStaticMarkup(
10
+ <QueryRadiosInput popover={false} name="q" schema={STRING} onQuery={() => []} onValue={PASSTHROUGH} />,
11
+ );
10
12
  expect(html).toContain('name="q"');
11
13
  });
12
14
  test("formatter can return a React element, not only a string", () => {
13
15
  const element = (
14
- <QueryInput<string, string> name="q" schema={STRING} onQuery={() => []} formatter={v => <strong>{v}</strong>} onValue={PASSTHROUGH} />
16
+ <QueryRadiosInput<string, string>
17
+ name="q"
18
+ schema={STRING}
19
+ onQuery={() => []}
20
+ formatter={v => <strong>{v}</strong>}
21
+ onValue={PASSTHROUGH}
22
+ />
15
23
  );
16
24
  expect(element).toBeTruthy();
17
25
  });
@@ -0,0 +1,53 @@
1
+ import type { ReactElement } from "react";
2
+ import { formatValue } from "../../util/format.js";
3
+ import { ArrayRadioInputs } from "./ArrayRadioInputs.js";
4
+ import type { ValueInputProps } from "./Input.js";
5
+ import { QueryInputBase, type QueryInputBaseProps } from "./QueryInputBase.js";
6
+
7
+ /**
8
+ * Props for `QueryRadiosInput`, a combo box that queries items of type `O` from an input of type `I`, and picks one.
9
+ *
10
+ * @see https://shelving.cc/ui/QueryRadiosInputProps
11
+ */
12
+ export interface QueryRadiosInputProps<I, O> extends QueryInputBaseProps<I, O>, ValueInputProps<O> {}
13
+
14
+ /**
15
+ * Combo box that queries a list of items and lets the user pick one, with radios.
16
+ * - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
17
+ * - Shows a `<Popover>` with a radio list of returned items to pick a final value of type `O`. Picking an item closes the popover.
18
+ * - With `popover={false}`, shows the radio list inline below the input instead, like a `<select>` list box.
19
+ * - Errors, loading, and empty states are handled automatically.
20
+ *
21
+ * @kind component
22
+ * @returns A combo box element wrapping the input and results popover (or the inline list).
23
+ * @see https://shelving.cc/ui/QueryRadiosInput
24
+ */
25
+ export function QueryRadiosInput<I, O>({
26
+ value,
27
+ onValue,
28
+ formatter = formatValue,
29
+ popover = true,
30
+ ...props
31
+ }: QueryRadiosInputProps<I, O>): ReactElement {
32
+ const { name, required, disabled } = props;
33
+ return (
34
+ <QueryInputBase<I, O>
35
+ {...props}
36
+ popover={popover}
37
+ list={(items, close) => (
38
+ <ArrayRadioInputs
39
+ name={name}
40
+ required={required}
41
+ disabled={disabled}
42
+ items={items}
43
+ value={value}
44
+ formatter={formatter}
45
+ onValue={v => {
46
+ onValue(v);
47
+ if (popover) close();
48
+ }}
49
+ />
50
+ )}
51
+ />
52
+ );
53
+ }
@@ -22,7 +22,7 @@ required = false, disabled = false, message = "", value, onValue, input = "text"
22
22
  onValue?.(e.currentTarget.value);
23
23
  _resize(e.currentTarget, rows);
24
24
  };
25
- return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
25
+ return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, style: { "--input-rows": rows }, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
26
26
  }
27
27
  const onChange = (e) => {
28
28
  onValue?.(e.currentTarget.value);
@@ -1,4 +1,4 @@
1
- import type { ReactElement, SyntheticEvent } from "react";
1
+ import type { CSSProperties, ReactElement, SyntheticEvent } from "react";
2
2
  import type { StringInputType } from "../../schema/StringSchema.js";
3
3
  import { PASSTHROUGH } from "../../util/function.js";
4
4
  import { getInputClass, type InputVariants, type ValueInputProps } from "../input/Input.js";
@@ -66,6 +66,7 @@ export function TextInput({
66
66
  minLength={Number.isFinite(min) ? min : 0}
67
67
  maxLength={Number.isFinite(max) ? max : undefined}
68
68
  rows={rows}
69
+ style={{ "--input-rows": rows } as CSSProperties}
69
70
  required={required && min > 0}
70
71
  disabled={disabled}
71
72
  placeholder={placeholder || " "}
@@ -1,3 +1,4 @@
1
+ export * from "./ArrayCheckboxInputs.js";
1
2
  export * from "./ArrayInput.js";
2
3
  export * from "./ArrayRadioInputs.js";
3
4
  export * from "./ButtonInput.js";
@@ -7,13 +8,16 @@ export * from "./DataInput.js";
7
8
  export * from "./DateInput.js";
8
9
  export * from "./DictionaryInput.js";
9
10
  export * from "./FileInput.js";
11
+ export * from "./ImageInput.js";
10
12
  export * from "./Input.js";
11
13
  export * from "./NumberInput.js";
12
14
  export * from "./OutputInput.js";
13
15
  export * from "./Popover.js";
14
16
  export * from "./PopoverButton.js";
15
17
  export * from "./PopoverButtonInput.js";
16
- export * from "./QueryInput.js";
18
+ export * from "./QueryCheckboxesInput.js";
19
+ export * from "./QueryInputBase.js";
20
+ export * from "./QueryRadiosInput.js";
17
21
  export * from "./RadioInput.js";
18
22
  export * from "./SchemaInput.js";
19
23
  export * from "./SelectInput.js";
package/ui/input/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./ArrayCheckboxInputs.js";
1
2
  export * from "./ArrayInput.js";
2
3
  export * from "./ArrayRadioInputs.js";
3
4
  export * from "./ButtonInput.js";
@@ -7,13 +8,16 @@ export * from "./DataInput.js";
7
8
  export * from "./DateInput.js";
8
9
  export * from "./DictionaryInput.js";
9
10
  export * from "./FileInput.js";
11
+ export * from "./ImageInput.js";
10
12
  export * from "./Input.js";
11
13
  export * from "./NumberInput.js";
12
14
  export * from "./OutputInput.js";
13
15
  export * from "./Popover.js";
14
16
  export * from "./PopoverButton.js";
15
17
  export * from "./PopoverButtonInput.js";
16
- export * from "./QueryInput.js";
18
+ export * from "./QueryCheckboxesInput.js";
19
+ export * from "./QueryInputBase.js";
20
+ export * from "./QueryRadiosInput.js";
17
21
  export * from "./RadioInput.js";
18
22
  export * from "./SchemaInput.js";
19
23
  export * from "./SelectInput.js";
package/ui/input/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./ArrayCheckboxInputs.js";
1
2
  export * from "./ArrayInput.js";
2
3
  export * from "./ArrayRadioInputs.js";
3
4
  export * from "./ButtonInput.js";
@@ -7,13 +8,16 @@ export * from "./DataInput.js";
7
8
  export * from "./DateInput.js";
8
9
  export * from "./DictionaryInput.js";
9
10
  export * from "./FileInput.js";
11
+ export * from "./ImageInput.js";
10
12
  export * from "./Input.js";
11
13
  export * from "./NumberInput.js";
12
14
  export * from "./OutputInput.js";
13
15
  export * from "./Popover.js";
14
16
  export * from "./PopoverButton.js";
15
17
  export * from "./PopoverButtonInput.js";
16
- export * from "./QueryInput.js";
18
+ export * from "./QueryCheckboxesInput.js";
19
+ export * from "./QueryInputBase.js";
20
+ export * from "./QueryRadiosInput.js";
17
21
  export * from "./RadioInput.js";
18
22
  export * from "./SchemaInput.js";
19
23
  export * from "./SelectInput.js";
@@ -0,0 +1,24 @@
1
+ import type { ReactElement } from "react";
2
+ import type { ChildProps, ClassProps } from "../util/props.js";
3
+ /**
4
+ * Props for `<Empty>` — the message content plus an optional `className`.
5
+ *
6
+ * @see https://shelving.cc/ui/EmptyProps
7
+ */
8
+ export interface EmptyProps extends ChildProps, ClassProps {
9
+ }
10
+ /**
11
+ * Message for a list with nothing in it: centred, grey content with space around it.
12
+ * - Use it for every empty list, so they all look the same.
13
+ * - Pass the text as `<Paragraph>` elements, plus any buttons. Each child keeps its own margins.
14
+ *
15
+ * @kind component
16
+ * @see https://shelving.cc/ui/Empty
17
+ */
18
+ export declare function Empty({ children, className }: EmptyProps): ReactElement;
19
+ /**
20
+ * Loading spinner in an `<Empty>`, for a list or form that is still loading. The empty message replaces it in the same place.
21
+ *
22
+ * @see https://shelving.cc/ui/EMPTY_LOADING
23
+ */
24
+ export declare const EMPTY_LOADING: import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Block } from "../block/Block.js";
3
+ import { LOADING } from "../misc/Loading.js";
4
+ /**
5
+ * Message for a list with nothing in it: centred, grey content with space around it.
6
+ * - Use it for every empty list, so they all look the same.
7
+ * - Pass the text as `<Paragraph>` elements, plus any buttons. Each child keeps its own margins.
8
+ *
9
+ * @kind component
10
+ * @see https://shelving.cc/ui/Empty
11
+ */
12
+ export function Empty({ children, className }) {
13
+ return (_jsx(Block, { center: true, tint: "50", space: "xlarge", className: className, children: children }));
14
+ }
15
+ /**
16
+ * Loading spinner in an `<Empty>`, for a list or form that is still loading. The empty message replaces it in the same place.
17
+ *
18
+ * @see https://shelving.cc/ui/EMPTY_LOADING
19
+ */
20
+ export const EMPTY_LOADING = _jsx(Empty, { children: LOADING }, "loading");
@@ -0,0 +1,35 @@
1
+ # Empty
2
+
3
+ Message for a list with nothing in it. `<Empty>` shows its content centred and grey, with space around it, so every empty list looks the same.
4
+
5
+ **Things to know:**
6
+
7
+ - Pass the text as `<Paragraph>` elements, plus any buttons. Each child keeps its own margins.
8
+ - `EMPTY_LOADING` is a loading spinner in an `<Empty>`. Use it as the `fallback` of a `<Loader>` for a list, so the empty message later shows in the same place.
9
+ - `<QueryRadiosInput>` and `<QueryCheckboxesInput>` use both for their loading and empty states.
10
+
11
+ ## Usage
12
+
13
+ ### Empty list
14
+
15
+ ```tsx
16
+ import { Empty, Paragraph } from "shelving/ui";
17
+
18
+ <Empty>
19
+ <Paragraph>No challenges yet.</Paragraph>
20
+ </Empty>
21
+ ```
22
+
23
+ ### Loading list
24
+
25
+ ```tsx
26
+ import { EMPTY_LOADING, Loader } from "shelving/ui";
27
+
28
+ <Loader fallback={EMPTY_LOADING}>
29
+ <LoadChallenges />
30
+ </Loader>
31
+ ```
32
+
33
+ ## Styling
34
+
35
+ `<Empty>` has no own hooks. It is a `<Block>` with `center`, `tint="50"` and `space="xlarge"`, so it reads the `--tint-50` ladder step and `--space-xlarge`.
@@ -0,0 +1,18 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+ import { EMPTY_LOADING, Empty, Paragraph } from "shelving/ui";
4
+
5
+ describe("Empty", () => {
6
+ test("renders its children in one block", () => {
7
+ const html = renderToStaticMarkup(
8
+ <Empty>
9
+ <Paragraph>No items yet.</Paragraph>
10
+ </Empty>,
11
+ );
12
+ expect(html).toMatch(/^<div[^>]*><p[^>]*>No items yet\.<\/p><\/div>$/);
13
+ });
14
+ test("EMPTY_LOADING renders a spinner in the same block", () => {
15
+ const html = renderToStaticMarkup(EMPTY_LOADING);
16
+ expect(html).toMatch(/^<div[^>]*><svg[^>]*>.*<\/svg><\/div>$/);
17
+ });
18
+ });