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.
- package/package.json +1 -1
- package/ui/input/ArrayCheckboxInputs.d.ts +26 -0
- package/ui/input/ArrayCheckboxInputs.js +23 -0
- package/ui/input/ArrayCheckboxInputs.tsx +59 -0
- package/ui/input/ImageInput.d.ts +27 -0
- package/ui/input/ImageInput.js +49 -0
- package/ui/input/ImageInput.md +48 -0
- package/ui/input/ImageInput.module.css +79 -0
- package/ui/input/ImageInput.tsx +100 -0
- package/ui/input/Input.module.css +10 -1
- package/ui/input/Input.test.tsx +33 -1
- package/ui/input/QueryCheckboxesInput.d.ts +24 -0
- package/ui/input/QueryCheckboxesInput.js +20 -0
- package/ui/input/QueryCheckboxesInput.md +38 -0
- package/ui/input/QueryCheckboxesInput.test.tsx +42 -0
- package/ui/input/QueryCheckboxesInput.tsx +50 -0
- package/ui/input/QueryInputBase.d.ts +48 -0
- package/ui/input/QueryInputBase.js +48 -0
- package/ui/input/QueryInputBase.tsx +126 -0
- package/ui/input/QueryRadiosInput.d.ts +22 -0
- package/ui/input/QueryRadiosInput.js +23 -0
- package/ui/input/QueryRadiosInput.md +42 -0
- package/ui/input/{QueryInput.test.tsx → QueryRadiosInput.test.tsx} +12 -4
- package/ui/input/QueryRadiosInput.tsx +53 -0
- package/ui/input/TextInput.js +1 -1
- package/ui/input/TextInput.tsx +2 -1
- package/ui/input/index.d.ts +5 -1
- package/ui/input/index.js +5 -1
- package/ui/input/index.ts +5 -1
- package/ui/notice/Empty.d.ts +24 -0
- package/ui/notice/Empty.js +20 -0
- package/ui/notice/Empty.md +35 -0
- package/ui/notice/Empty.test.tsx +18 -0
- package/ui/notice/Empty.tsx +34 -0
- package/ui/notice/index.d.ts +1 -0
- package/ui/notice/index.js +1 -0
- package/ui/notice/index.ts +1 -0
- package/ui/util/props.test.tsx +1 -1
- package/ui/input/QueryInput.d.ts +0 -44
- package/ui/input/QueryInput.js +0 -53
- package/ui/input/QueryInput.md +0 -38
- package/ui/input/QueryInput.tsx +0 -126
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { Block } from "../block/Block.js";
|
|
3
|
+
import { LOADING } from "../misc/Loading.js";
|
|
4
|
+
import type { ChildProps, ClassProps } from "../util/props.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Props for `<Empty>` — the message content plus an optional `className`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://shelving.cc/ui/EmptyProps
|
|
10
|
+
*/
|
|
11
|
+
export interface EmptyProps extends ChildProps, ClassProps {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Message for a list with nothing in it: centred, grey content with space around it.
|
|
15
|
+
* - Use it for every empty list, so they all look the same.
|
|
16
|
+
* - Pass the text as `<Paragraph>` elements, plus any buttons. Each child keeps its own margins.
|
|
17
|
+
*
|
|
18
|
+
* @kind component
|
|
19
|
+
* @see https://shelving.cc/ui/Empty
|
|
20
|
+
*/
|
|
21
|
+
export function Empty({ children, className }: EmptyProps): ReactElement {
|
|
22
|
+
return (
|
|
23
|
+
<Block center tint="50" space="xlarge" className={className}>
|
|
24
|
+
{children}
|
|
25
|
+
</Block>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Loading spinner in an `<Empty>`, for a list or form that is still loading. The empty message replaces it in the same place.
|
|
31
|
+
*
|
|
32
|
+
* @see https://shelving.cc/ui/EMPTY_LOADING
|
|
33
|
+
*/
|
|
34
|
+
export const EMPTY_LOADING = <Empty key="loading">{LOADING}</Empty>;
|
package/ui/notice/index.d.ts
CHANGED
package/ui/notice/index.js
CHANGED
package/ui/notice/index.ts
CHANGED
package/ui/util/props.test.tsx
CHANGED
|
@@ -74,7 +74,7 @@ describe("ClassProps", () => {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
test("popover wrapper components render their `className` on the trigger, not the floating panel", () => {
|
|
77
|
-
// `PopoverButtonInput` (and `PopoverButton`/`
|
|
77
|
+
// `PopoverButtonInput` (and `PopoverButton`/`QueryRadiosInput`) style their always-visible trigger — only a bare `<Popover>` styles the panel.
|
|
78
78
|
const html = render(
|
|
79
79
|
<PopoverButtonInput name="pick" className="spongy">
|
|
80
80
|
{["Pick", "Panel"]}
|
package/ui/input/QueryInput.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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 { ValueInputProps } from "./Input.js";
|
|
6
|
-
/**
|
|
7
|
-
* Props for `QueryInput`, a combo box that queries items of type `O` from an input of type `I`.
|
|
8
|
-
*
|
|
9
|
-
* @see https://shelving.cc/ui/QueryInputProps
|
|
10
|
-
*/
|
|
11
|
-
export interface QueryInputProps<I, O> extends ValueInputProps<O> {
|
|
12
|
-
/** Schema input */
|
|
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 picker, 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, and picking an item keeps the list.
|
|
27
|
-
*/
|
|
28
|
-
popover?: boolean | undefined;
|
|
29
|
-
/** Message that shows when query returns `[]` empty array (set to `""` empty string to show no message). */
|
|
30
|
-
empty?: ReactNode | undefined;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Combo box that queries a list of items and lets the user pick one from a popover.
|
|
34
|
-
* - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
|
|
35
|
-
* - Shows a `<Popover>` with a radio list of returned items to pick a final value of type `O`.
|
|
36
|
-
* - With `popover={false}`, shows the radio list inline below the input instead, like a `<select>` list box.
|
|
37
|
-
* - Errors, loading, and empty states are handled automatically.
|
|
38
|
-
*
|
|
39
|
-
* @returns A combo box element wrapping the input and results popover (or the inline list).
|
|
40
|
-
* @example <QueryInput schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
41
|
-
* @example <QueryInput popover={false} schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
42
|
-
* @see https://shelving.cc/ui/QueryInput
|
|
43
|
-
*/
|
|
44
|
-
export declare function QueryInput<I, O>({ empty, value, onValue, onQuery, formatter, popover, className, ...props }: QueryInputProps<I, O>): ReactElement;
|
package/ui/input/QueryInput.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } 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 { formatValue } from "../../util/format.js";
|
|
8
|
-
import { Column } from "../block/Column.js";
|
|
9
|
-
import { ErrorNotice } from "../misc/Catcher.js";
|
|
10
|
-
import { LOADING_NOTICE, Notice } from "../notice/Notice.js";
|
|
11
|
-
import { ArrayRadioInputs } from "./ArrayRadioInputs.js";
|
|
12
|
-
import { Popover } from "./Popover.js";
|
|
13
|
-
import { SchemaInput } from "./SchemaInput.js";
|
|
14
|
-
/**
|
|
15
|
-
* Combo box that queries a list of items and lets the user pick one from a popover.
|
|
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`.
|
|
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
|
-
* @returns A combo box element wrapping the input and results popover (or the inline list).
|
|
22
|
-
* @example <QueryInput schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
23
|
-
* @example <QueryInput popover={false} schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
24
|
-
* @see https://shelving.cc/ui/QueryInput
|
|
25
|
-
*/
|
|
26
|
-
export function QueryInput({ empty = "No results", value, onValue, onQuery, formatter = formatValue, popover = true, className, ...props }) {
|
|
27
|
-
const store = useStore(useInstance(PayloadFetchStore, NONE, undefined, onQuery, SECOND));
|
|
28
|
-
const busy = useStore(store.busy).value;
|
|
29
|
-
// Inline, query the schema's default value at once, so the list shows before anything is typed.
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (!popover)
|
|
32
|
-
store.payload.value = props.schema.value;
|
|
33
|
-
}, [popover, store, props.schema]);
|
|
34
|
-
// Is popover open?
|
|
35
|
-
const isOpen = busy || !!store.reason || !!store.value;
|
|
36
|
-
const close = () => {
|
|
37
|
-
store.payload.value = NONE;
|
|
38
|
-
store.value = undefined;
|
|
39
|
-
};
|
|
40
|
-
const results = busy ? (LOADING_NOTICE) : store.reason ? (_jsx(ErrorNotice, { reason: store.reason })) : store.value?.length ? (_jsx(ArrayRadioInputs, { items: store.value, onValue: v => {
|
|
41
|
-
onValue(v); // Set the value.
|
|
42
|
-
if (popover)
|
|
43
|
-
close();
|
|
44
|
-
}, formatter: formatter, ...props })) : empty && store.value ? (_jsx(Notice, { children: empty })) : null;
|
|
45
|
-
if (!popover)
|
|
46
|
-
return (_jsxs(Column, { children: [_jsx(SchemaInput, { ...props, className: className, value: value, onValue: v => void (store.payload.value = v) }), results] }));
|
|
47
|
-
return (_jsxs(Popover, { open: isOpen, onClose: close, children: [_jsx(SchemaInput, { ...props, className: className, value: value, onValue: v => {
|
|
48
|
-
if (v)
|
|
49
|
-
store.payload.value = v;
|
|
50
|
-
else
|
|
51
|
-
close();
|
|
52
|
-
} }), results] }));
|
|
53
|
-
}
|
package/ui/input/QueryInput.md
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# QueryInput
|
|
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), and loading, error and empty states show automatically.
|
|
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
|
-
- `empty` sets the message for no results (`""` shows no message).
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
### Popover
|
|
16
|
-
|
|
17
|
-
```tsx
|
|
18
|
-
import { QueryInput } from "shelving/ui";
|
|
19
|
-
|
|
20
|
-
<QueryInput name="user" schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Inline list with avatars
|
|
24
|
-
|
|
25
|
-
```tsx
|
|
26
|
-
<QueryInput
|
|
27
|
-
popover={false}
|
|
28
|
-
name="user"
|
|
29
|
-
schema={SEARCH}
|
|
30
|
-
onQuery={search}
|
|
31
|
-
formatter={user => <Avatar user={user} />}
|
|
32
|
-
onValue={setUser}
|
|
33
|
-
/>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Styling
|
|
37
|
-
|
|
38
|
-
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.
|
package/ui/input/QueryInput.tsx
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { type ReactElement, type ReactNode, useEffect } 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 { formatValue } from "../../util/format.js";
|
|
9
|
-
import { Column } from "../block/Column.js";
|
|
10
|
-
import { ErrorNotice } from "../misc/Catcher.js";
|
|
11
|
-
import { LOADING_NOTICE, Notice } from "../notice/Notice.js";
|
|
12
|
-
import { ArrayRadioInputs } from "./ArrayRadioInputs.js";
|
|
13
|
-
import type { ValueInputProps } from "./Input.js";
|
|
14
|
-
import { Popover } from "./Popover.js";
|
|
15
|
-
import { SchemaInput } from "./SchemaInput.js";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Props for `QueryInput`, a combo box that queries items of type `O` from an input of type `I`.
|
|
19
|
-
*
|
|
20
|
-
* @see https://shelving.cc/ui/QueryInputProps
|
|
21
|
-
*/
|
|
22
|
-
export interface QueryInputProps<I, O> extends ValueInputProps<O> {
|
|
23
|
-
/** Schema input */
|
|
24
|
-
schema: Schema<I>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Called with the current text value to return matching items whenever the text input changes.
|
|
28
|
-
* - Automatically debounced, so only called after a short delay.
|
|
29
|
-
* - Automatically shows a loading state while loading.
|
|
30
|
-
* - Returning `undefined` signals to close the popover (or, with `popover={false}`, to show no list).
|
|
31
|
-
*/
|
|
32
|
-
onQuery: PayloadFetchCallback<I, ImmutableArray<O> | undefined>;
|
|
33
|
-
|
|
34
|
-
/** Format an item of type `O` for display in the picker, for example as text or as an avatar. */
|
|
35
|
-
formatter?: ((value: O) => ReactNode) | undefined;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Show the results in a popover (the default), or set `false` to show them inline, as a list below the input.
|
|
39
|
-
* - Inline, the list shows at once: `onQuery()` is called with the schema's default value (e.g. `""`) on mount.
|
|
40
|
-
* - Inline, an empty input still queries, and picking an item keeps the list.
|
|
41
|
-
*/
|
|
42
|
-
popover?: boolean | undefined;
|
|
43
|
-
|
|
44
|
-
/** Message that shows when query returns `[]` empty array (set to `""` empty string to show no message). */
|
|
45
|
-
empty?: ReactNode | undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Combo box that queries a list of items and lets the user pick one from a popover.
|
|
50
|
-
* - Shows an input based on a `schema` of type `I`; its values are piped to the `onQuery()` callback.
|
|
51
|
-
* - Shows a `<Popover>` with a radio list of returned items to pick a final value of type `O`.
|
|
52
|
-
* - With `popover={false}`, shows the radio list inline below the input instead, like a `<select>` list box.
|
|
53
|
-
* - Errors, loading, and empty states are handled automatically.
|
|
54
|
-
*
|
|
55
|
-
* @returns A combo box element wrapping the input and results popover (or the inline list).
|
|
56
|
-
* @example <QueryInput schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
57
|
-
* @example <QueryInput popover={false} schema={SEARCH} onQuery={search} value={user} onValue={setUser} />
|
|
58
|
-
* @see https://shelving.cc/ui/QueryInput
|
|
59
|
-
*/
|
|
60
|
-
export function QueryInput<I, O>({
|
|
61
|
-
empty = "No results",
|
|
62
|
-
value,
|
|
63
|
-
onValue,
|
|
64
|
-
onQuery,
|
|
65
|
-
formatter = formatValue,
|
|
66
|
-
popover = true,
|
|
67
|
-
className,
|
|
68
|
-
...props
|
|
69
|
-
}: QueryInputProps<I, O>): ReactElement {
|
|
70
|
-
const store = useStore(useInstance(PayloadFetchStore, NONE, undefined, onQuery, SECOND));
|
|
71
|
-
const busy = useStore(store.busy).value;
|
|
72
|
-
|
|
73
|
-
// Inline, query the schema's default value at once, so the list shows before anything is typed.
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (!popover) store.payload.value = props.schema.value as I;
|
|
76
|
-
}, [popover, store, props.schema]);
|
|
77
|
-
|
|
78
|
-
// Is popover open?
|
|
79
|
-
const isOpen = busy || !!store.reason || !!store.value;
|
|
80
|
-
|
|
81
|
-
const close = () => {
|
|
82
|
-
store.payload.value = NONE;
|
|
83
|
-
store.value = undefined;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const results = busy ? (
|
|
87
|
-
LOADING_NOTICE
|
|
88
|
-
) : store.reason ? (
|
|
89
|
-
<ErrorNotice reason={store.reason} />
|
|
90
|
-
) : store.value?.length ? (
|
|
91
|
-
<ArrayRadioInputs
|
|
92
|
-
items={store.value}
|
|
93
|
-
onValue={v => {
|
|
94
|
-
onValue(v); // Set the value.
|
|
95
|
-
if (popover) close();
|
|
96
|
-
}}
|
|
97
|
-
formatter={formatter}
|
|
98
|
-
{...props}
|
|
99
|
-
/>
|
|
100
|
-
) : empty && store.value ? (
|
|
101
|
-
<Notice>{empty}</Notice>
|
|
102
|
-
) : null;
|
|
103
|
-
|
|
104
|
-
if (!popover)
|
|
105
|
-
return (
|
|
106
|
-
<Column>
|
|
107
|
-
<SchemaInput {...props} className={className} value={value as I} onValue={v => void (store.payload.value = v as I)} />
|
|
108
|
-
{results}
|
|
109
|
-
</Column>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<Popover open={isOpen} onClose={close}>
|
|
114
|
-
<SchemaInput
|
|
115
|
-
{...props}
|
|
116
|
-
className={className}
|
|
117
|
-
value={value as I}
|
|
118
|
-
onValue={v => {
|
|
119
|
-
if (v) store.payload.value = v;
|
|
120
|
-
else close();
|
|
121
|
-
}}
|
|
122
|
-
/>
|
|
123
|
-
{results}
|
|
124
|
-
</Popover>
|
|
125
|
-
);
|
|
126
|
-
}
|