@alulore/kumiko 0.19.0 → 0.20.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/dist/board/board-api.d.ts +2 -1
- package/dist/board/board-api.js +1 -1
- package/dist/board/board-motion.js +29 -1
- package/dist/board/board-slots.d.ts +14 -7
- package/dist/board/board-slots.js +5 -3
- package/dist/board/board.d.ts +20 -5
- package/dist/board/board.js +28 -5
- package/dist/board/keep-capture.d.ts +10 -5
- package/dist/board/keep-capture.js +48 -13
- package/dist/cooldown/cooldown-button.d.ts +30 -0
- package/dist/cooldown/cooldown-button.js +75 -0
- package/dist/cooldown/cooldown-labels.d.ts +8 -0
- package/dist/cooldown/cooldown-labels.js +4 -0
- package/dist/cooldown/cooldown-time.d.ts +8 -0
- package/dist/cooldown/cooldown-time.js +20 -0
- package/dist/cooldown/cooldown.css +21 -0
- package/dist/cooldown/index.d.ts +4 -0
- package/dist/cooldown/index.js +4 -0
- package/dist/cooldown/use-cooldown.d.ts +30 -0
- package/dist/cooldown/use-cooldown.js +63 -0
- package/dist/dialog/dialog-content.d.ts +5 -0
- package/dist/dialog/dialog-content.js +7 -0
- package/dist/dialog/overlay-host.d.ts +1 -1
- package/dist/dialog/overlay-host.js +10 -1
- package/dist/empty-state/empty-state-labels.d.ts +14 -0
- package/dist/empty-state/empty-state-labels.js +10 -0
- package/dist/empty-state/empty-state.css +134 -0
- package/dist/empty-state/empty-state.d.ts +34 -0
- package/dist/empty-state/empty-state.js +61 -0
- package/dist/empty-state/index.d.ts +2 -0
- package/dist/empty-state/index.js +2 -0
- package/dist/form/choice-fields.d.ts +34 -0
- package/dist/form/choice-fields.js +41 -0
- package/dist/form/error-line.d.ts +8 -0
- package/dist/form/error-line.js +47 -0
- package/dist/form/field-props.d.ts +12 -0
- package/dist/form/field-props.js +8 -0
- package/dist/form/field-shell.d.ts +18 -0
- package/dist/form/field-shell.js +51 -0
- package/dist/form/focus-invalid.d.ts +5 -0
- package/dist/form/focus-invalid.js +17 -0
- package/dist/form/form-context.d.ts +2 -0
- package/dist/form/form-context.js +3 -0
- package/dist/form/form-parts.d.ts +20 -0
- package/dist/form/form-parts.js +73 -0
- package/dist/form/form.css +128 -0
- package/dist/form/index.d.ts +10 -0
- package/dist/form/index.js +9 -0
- package/dist/form/shown-error.d.ts +12 -0
- package/dist/form/shown-error.js +27 -0
- package/dist/form/submit-errors.d.ts +36 -0
- package/dist/form/submit-errors.js +46 -0
- package/dist/form/text-fields.d.ts +18 -0
- package/dist/form/text-fields.js +21 -0
- package/dist/form/use-app-form.d.ts +1655 -0
- package/dist/form/use-app-form.js +94 -0
- package/dist/form/use-dialog-link.d.ts +5 -0
- package/dist/form/use-dialog-link.js +30 -0
- package/dist/form/value-fields.d.ts +16 -0
- package/dist/form/value-fields.js +15 -0
- package/dist/map/geo.d.ts +20 -0
- package/dist/map/geo.js +41 -0
- package/dist/map/index.d.ts +5 -0
- package/dist/map/index.js +4 -0
- package/dist/map/label-overlap.d.ts +13 -0
- package/dist/map/label-overlap.js +23 -0
- package/dist/map/load-map.d.ts +12 -0
- package/dist/map/load-map.js +22 -0
- package/dist/map/location-map.d.ts +39 -0
- package/dist/map/location-map.js +171 -0
- package/dist/map/map-frame.d.ts +18 -0
- package/dist/map/map-frame.js +6 -0
- package/dist/map/map-pin.d.ts +4 -0
- package/dist/map/map-pin.js +38 -0
- package/dist/map/map-popup.d.ts +17 -0
- package/dist/map/map-popup.js +101 -0
- package/dist/map/map-source.d.ts +52 -0
- package/dist/map/map-source.js +59 -0
- package/dist/map/map.css +311 -0
- package/dist/map/marker-pins.d.ts +29 -0
- package/dist/map/marker-pins.js +144 -0
- package/dist/map/markers-map.d.ts +57 -0
- package/dist/map/markers-map.js +154 -0
- package/dist/map/use-label-overlap.d.ts +9 -0
- package/dist/map/use-label-overlap.js +55 -0
- package/dist/map/use-map.d.ts +49 -0
- package/dist/map/use-map.js +201 -0
- package/dist/media/encoding.d.ts +32 -0
- package/dist/media/encoding.js +59 -0
- package/dist/media/errors.d.ts +33 -0
- package/dist/media/errors.js +26 -0
- package/dist/media/image.d.ts +9 -0
- package/dist/media/image.js +35 -0
- package/dist/media/index.d.ts +10 -0
- package/dist/media/index.js +10 -0
- package/dist/media/load-mediabunny.d.ts +7 -0
- package/dist/media/load-mediabunny.js +13 -0
- package/dist/media/media-upload.d.ts +40 -0
- package/dist/media/media-upload.js +132 -0
- package/dist/media/media.css +101 -0
- package/dist/media/probe.d.ts +19 -0
- package/dist/media/probe.js +49 -0
- package/dist/media/sizes.d.ts +28 -0
- package/dist/media/sizes.js +51 -0
- package/dist/media/slideshow.d.ts +43 -0
- package/dist/media/slideshow.js +174 -0
- package/dist/media/timeline.d.ts +59 -0
- package/dist/media/timeline.js +105 -0
- package/dist/media/transcode.d.ts +35 -0
- package/dist/media/transcode.js +132 -0
- package/dist/media/upload.d.ts +21 -0
- package/dist/media/upload.js +54 -0
- package/dist/media/use-media-job.d.ts +79 -0
- package/dist/media/use-media-job.js +143 -0
- package/dist/server-render.test.js +93 -0
- package/dist/smooth-caret/caret-controller.js +16 -3
- package/dist/table/table-labels.d.ts +2 -0
- package/dist/table/table-labels.js +1 -0
- package/dist/table/table-sections.js +10 -2
- package/dist/table/table.css +1 -0
- package/dist/theme/define-theme.d.ts +38 -0
- package/dist/theme/define-theme.js +56 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/theme-style.d.ts +6 -0
- package/dist/theme/theme-style.js +11 -0
- package/dist/theme/theme-types.d.ts +1 -0
- package/dist/theme/theme-types.js +26 -0
- package/dist/theme/tokens-1.generated.d.ts +1 -0
- package/dist/theme/tokens-1.generated.js +404 -0
- package/dist/theme/tokens-2.generated.d.ts +1 -0
- package/dist/theme/tokens-2.generated.js +404 -0
- package/dist/theme/tokens-3.generated.d.ts +1 -0
- package/dist/theme/tokens-3.generated.js +158 -0
- package/dist/theme/tokens.generated.d.ts +2 -0
- package/dist/theme/tokens.generated.js +6 -0
- package/dist/undo/undo-provider.js +24 -9
- package/package.json +78 -1
|
@@ -9,6 +9,13 @@ export function useDialogContent() {
|
|
|
9
9
|
}
|
|
10
10
|
return api;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Like `useDialogContent`, but null outside a dialog `openDialog()` opened instead of throwing. For parts, like a
|
|
14
|
+
* form, that work in a dialog or on a page. Kept out of the package entry on purpose.
|
|
15
|
+
*/
|
|
16
|
+
export function useOptionalDialogContent() {
|
|
17
|
+
return useContext(DialogContentContext);
|
|
18
|
+
}
|
|
12
19
|
/** The row of buttons at the end of a form in an opened dialog. */
|
|
13
20
|
export function DialogActions(props) {
|
|
14
21
|
return _jsx("div", { ...props, "data-kumiko-actions": "" });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DialogProps } from "@ui-sdk/react/dialog";
|
|
2
2
|
import { type OverlayHostProps as SdkOverlayHostProps } from "@ui-sdk/react/overlays";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
import type { DialogLabels } from "./dialog-labels";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertDialog as SdkAlertDialog } from "@ui-sdk/react/alert-dialog";
|
|
3
|
+
import { Dialog as SdkDialog } from "@ui-sdk/react/dialog";
|
|
2
4
|
import { OverlayHost as SdkOverlayHost } from "@ui-sdk/react/overlays";
|
|
3
5
|
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
6
|
import { useSettledClose } from "../motion/settle-close";
|
|
@@ -21,6 +23,13 @@ function useDialogsChange(open, onChange) {
|
|
|
21
23
|
}
|
|
22
24
|
}, [open]);
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A closed dialog and question that stay mounted, so ui-sdk writes their popover styles when the app loads.
|
|
28
|
+
* Written at the first open instead, the new stylesheet makes the browser restyle the whole page.
|
|
29
|
+
*/
|
|
30
|
+
function ReadyRoots() {
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx(SdkDialog, { open: false }), _jsx(SdkAlertDialog, { open: false })] }));
|
|
32
|
+
}
|
|
24
33
|
/**
|
|
25
34
|
* The opened dialogs, in a box of their own that is always there. Mounted straight into a big container,
|
|
26
35
|
* each open and close would make the browser recheck most of that container; inside this box, only the box.
|
|
@@ -29,7 +38,7 @@ function DialogHost({ token, modal, closeIcon, onDialogsChange }) {
|
|
|
29
38
|
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
30
39
|
const active = state.activeHost === token;
|
|
31
40
|
useDialogsChange(active && anyOpen(state), active ? onDialogsChange : undefined);
|
|
32
|
-
return (
|
|
41
|
+
return (_jsxs("div", { "data-slot": "dialog-host", style: { display: "contents" }, children: [_jsx(ReadyRoots, {}), active ? (_jsx(DialogModalContext.Provider, { value: modal, children: _jsx(DialogCloseIconContext.Provider, { value: closeIcon, children: _jsx(Stack, { parent: null, state: state }) }) })) : null] }));
|
|
33
42
|
}
|
|
34
43
|
/**
|
|
35
44
|
* The host for `toast()`, `confirm()`, `openDialog()` and `ask()`. Mount it once, near the root and inside
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Every word an empty state shows by default. An empty description shows no description. */
|
|
2
|
+
export interface EmptyStateLabels {
|
|
3
|
+
emptyTitle: string;
|
|
4
|
+
emptyDescription: string;
|
|
5
|
+
noResultsTitle: string;
|
|
6
|
+
noResultsDescription: string;
|
|
7
|
+
errorTitle: string;
|
|
8
|
+
errorDescription: string;
|
|
9
|
+
/** The no-results button. */
|
|
10
|
+
clear: string;
|
|
11
|
+
/** The error button. */
|
|
12
|
+
retry: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const emptyStateLabels: EmptyStateLabels;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const emptyStateLabels = {
|
|
2
|
+
emptyTitle: "Nothing here yet",
|
|
3
|
+
emptyDescription: "",
|
|
4
|
+
noResultsTitle: "No results",
|
|
5
|
+
noResultsDescription: "Try other words, or clear the filters.",
|
|
6
|
+
errorTitle: "Couldn't load this",
|
|
7
|
+
errorDescription: "Something went wrong. Try again in a moment.",
|
|
8
|
+
clear: "Clear filters",
|
|
9
|
+
retry: "Try again"
|
|
10
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
@import "../motion/motion.css";
|
|
2
|
+
|
|
3
|
+
@layer kumiko {
|
|
4
|
+
:where(:root) {
|
|
5
|
+
--kumiko-empty-state-gap: 0.875rem;
|
|
6
|
+
--kumiko-empty-state-text-gap: 0.375rem;
|
|
7
|
+
--kumiko-empty-state-measure: 28rem;
|
|
8
|
+
--kumiko-empty-state-padding-page: 2rem;
|
|
9
|
+
--kumiko-empty-state-padding-inline: 0.5rem;
|
|
10
|
+
--kumiko-empty-state-min-height: 24rem;
|
|
11
|
+
--kumiko-empty-state-title-size-page: 1.375rem;
|
|
12
|
+
--kumiko-empty-state-title-size-inline: 1rem;
|
|
13
|
+
--kumiko-empty-state-title-weight: 600;
|
|
14
|
+
--kumiko-empty-state-title-color: inherit;
|
|
15
|
+
--kumiko-empty-state-description-size: 0.9375rem;
|
|
16
|
+
--kumiko-empty-state-description-color: color-mix(in oklab, currentColor 68%, transparent);
|
|
17
|
+
--kumiko-empty-state-icon-size-page: 3.5rem;
|
|
18
|
+
--kumiko-empty-state-icon-size-inline: 2.5rem;
|
|
19
|
+
--kumiko-empty-state-icon-bg: color-mix(in oklab, currentColor 8%, transparent);
|
|
20
|
+
--kumiko-empty-state-icon-color: color-mix(in oklab, currentColor 72%, transparent);
|
|
21
|
+
--kumiko-empty-state-art-max-size: 14rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:where([data-slot="empty-state"]) {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: var(--kumiko-empty-state-gap);
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
inline-size: 100%;
|
|
32
|
+
margin-inline: auto;
|
|
33
|
+
padding: var(--kumiko-empty-state-padding-inline);
|
|
34
|
+
text-align: center;
|
|
35
|
+
opacity: 1;
|
|
36
|
+
transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@starting-style {
|
|
40
|
+
:where([data-slot="empty-state"]) {
|
|
41
|
+
opacity: 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:where([data-slot="empty-state"][data-size="page"]) {
|
|
46
|
+
min-block-size: var(--kumiko-empty-state-min-height);
|
|
47
|
+
padding: var(--kumiko-empty-state-padding-page);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
:where([data-slot="empty-state"] > *) {
|
|
51
|
+
max-inline-size: var(--kumiko-empty-state-measure);
|
|
52
|
+
margin-block: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:where([data-slot="empty-state-title"]) {
|
|
56
|
+
color: var(--kumiko-empty-state-title-color);
|
|
57
|
+
font-size: var(--kumiko-empty-state-title-size-inline);
|
|
58
|
+
font-weight: var(--kumiko-empty-state-title-weight);
|
|
59
|
+
line-height: 1.3;
|
|
60
|
+
text-wrap: balance;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
:where([data-slot="empty-state"][data-size="page"] [data-slot="empty-state-title"]) {
|
|
64
|
+
font-size: var(--kumiko-empty-state-title-size-page);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:where([data-slot="empty-state-description"]) {
|
|
68
|
+
margin-block-start: calc(
|
|
69
|
+
var(--kumiko-empty-state-text-gap) - var(--kumiko-empty-state-gap)
|
|
70
|
+
);
|
|
71
|
+
color: var(--kumiko-empty-state-description-color);
|
|
72
|
+
font-size: var(--kumiko-empty-state-description-size);
|
|
73
|
+
line-height: 1.5;
|
|
74
|
+
text-wrap: pretty;
|
|
75
|
+
overflow-wrap: anywhere;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:where([data-slot="empty-state-icon"]) {
|
|
79
|
+
display: grid;
|
|
80
|
+
flex: none;
|
|
81
|
+
place-items: center;
|
|
82
|
+
inline-size: var(--kumiko-empty-state-icon-size-inline);
|
|
83
|
+
block-size: var(--kumiko-empty-state-icon-size-inline);
|
|
84
|
+
border-radius: 999px;
|
|
85
|
+
background: var(--kumiko-empty-state-icon-bg);
|
|
86
|
+
color: var(--kumiko-empty-state-icon-color);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:where([data-slot="empty-state"][data-size="page"] [data-slot="empty-state-icon"]) {
|
|
90
|
+
inline-size: var(--kumiko-empty-state-icon-size-page);
|
|
91
|
+
block-size: var(--kumiko-empty-state-icon-size-page);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
:where([data-slot="empty-state-icon"] > svg) {
|
|
95
|
+
inline-size: 50%;
|
|
96
|
+
block-size: 50%;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:where([data-slot="empty-state-art"]) {
|
|
100
|
+
display: grid;
|
|
101
|
+
place-items: center;
|
|
102
|
+
inline-size: 100%;
|
|
103
|
+
max-inline-size: var(--kumiko-empty-state-art-max-size);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
:where([data-slot="empty-state-art"] > svg) {
|
|
107
|
+
inline-size: 100%;
|
|
108
|
+
block-size: auto;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
:where([data-slot="empty-state-action"]) {
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-wrap: wrap;
|
|
114
|
+
gap: 0.5rem;
|
|
115
|
+
align-items: center;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
:where([data-slot="empty-state-action"]:empty) {
|
|
120
|
+
display: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@media (forced-colors: active) {
|
|
124
|
+
:where([data-slot="empty-state-icon"]) {
|
|
125
|
+
border: 1px solid CanvasText;
|
|
126
|
+
background: Canvas;
|
|
127
|
+
color: CanvasText;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
:where([data-slot="empty-state-description"]) {
|
|
131
|
+
color: CanvasText;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type EmptyStateLabels } from "./empty-state-labels";
|
|
2
|
+
/** What the state says: nothing yet, a search that found nothing, or a failed load. */
|
|
3
|
+
export type EmptyStateKind = "empty" | "no-results" | "error";
|
|
4
|
+
/** How big it is: a whole page, or a table, card or panel. */
|
|
5
|
+
export type EmptyStateSize = "page" | "inline";
|
|
6
|
+
export interface EmptyStateProps extends Omit<React.ComponentPropsWithoutRef<"div">, "title"> {
|
|
7
|
+
/** It sets the default words and button. `data-kind` lets an app restyle each kind. @defaultValue "empty" */
|
|
8
|
+
kind?: EmptyStateKind;
|
|
9
|
+
/** Replaces the kind's title. `null` shows none. */
|
|
10
|
+
title?: React.ReactNode;
|
|
11
|
+
/** Replaces the kind's description. `null` shows none. */
|
|
12
|
+
description?: React.ReactNode;
|
|
13
|
+
/** Drawn in a small tinted circle. Hidden from screen readers. */
|
|
14
|
+
icon?: React.ReactNode;
|
|
15
|
+
/** The app's own drawing, shown as it is. Hidden from screen readers. */
|
|
16
|
+
art?: React.ReactNode;
|
|
17
|
+
/** Replaces the kind's button. Without `action`, `onClear` and `onRetry` give the default buttons. */
|
|
18
|
+
action?: React.ReactNode;
|
|
19
|
+
/** Gives the no-results kind its Clear button. */
|
|
20
|
+
onClear?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
21
|
+
/** Gives the error kind its Try again button. While a returned promise runs, the button shows loading and ignores presses. */
|
|
22
|
+
onRetry?: () => void | PromiseLike<unknown>;
|
|
23
|
+
/** @defaultValue "page" */
|
|
24
|
+
size?: EmptyStateSize;
|
|
25
|
+
/** The title's heading level, so it fits the page outline. @defaultValue 2 */
|
|
26
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
27
|
+
/** The words, over the English ones. */
|
|
28
|
+
labels?: Partial<EmptyStateLabels>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What a screen, table or panel shows when it has nothing to show: no data yet, a search that found nothing, or a failed load.
|
|
32
|
+
* The error kind is announced, and its Try again button shows loading while the promise `onRetry` returns runs.
|
|
33
|
+
*/
|
|
34
|
+
export declare function EmptyState({ kind, title, description, icon, art, action, onClear, onRetry, size, headingLevel, labels, ...rest }: EmptyStateProps): React.JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Button } from "../button";
|
|
4
|
+
import { emptyStateLabels } from "./empty-state-labels";
|
|
5
|
+
/** Runs `onRetry` once at a time. A failure goes back to idle, and the error stays on screen for the app to handle. */
|
|
6
|
+
function useRetry(onRetry) {
|
|
7
|
+
const [phase, setPhase] = useState("idle");
|
|
8
|
+
function retry() {
|
|
9
|
+
if (phase === "retrying" || !onRetry) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
setPhase("retrying");
|
|
13
|
+
const settle = () => setPhase("idle");
|
|
14
|
+
try {
|
|
15
|
+
const result = onRetry();
|
|
16
|
+
if (result) {
|
|
17
|
+
void result.then(settle, settle);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
settle();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
settle();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return { phase, retry };
|
|
28
|
+
}
|
|
29
|
+
function DefaultAction({ kind, words, onClear, onRetry }) {
|
|
30
|
+
const { phase, retry } = useRetry(onRetry);
|
|
31
|
+
if (kind === "no-results" && onClear) {
|
|
32
|
+
return (_jsx(Button, { variant: "outline", onClick: onClear, children: words.clear }));
|
|
33
|
+
}
|
|
34
|
+
if (kind === "error" && onRetry) {
|
|
35
|
+
return (_jsx(Button, { variant: "outline", feedback: false, status: phase === "retrying" ? "loading" : undefined, onClick: retry, children: words.retry }));
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function wordsOf(kind, words) {
|
|
40
|
+
switch (kind) {
|
|
41
|
+
case "empty":
|
|
42
|
+
return { title: words.emptyTitle, description: words.emptyDescription };
|
|
43
|
+
case "no-results":
|
|
44
|
+
return { title: words.noResultsTitle, description: words.noResultsDescription };
|
|
45
|
+
case "error":
|
|
46
|
+
return { title: words.errorTitle, description: words.errorDescription };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What a screen, table or panel shows when it has nothing to show: no data yet, a search that found nothing, or a failed load.
|
|
51
|
+
* The error kind is announced, and its Try again button shows loading while the promise `onRetry` returns runs.
|
|
52
|
+
*/
|
|
53
|
+
export function EmptyState({ kind = "empty", title, description, icon, art, action, onClear, onRetry, size = "page", headingLevel = 2, labels, ...rest }) {
|
|
54
|
+
const words = { ...emptyStateLabels, ...labels };
|
|
55
|
+
const fallback = wordsOf(kind, words);
|
|
56
|
+
const shownTitle = title === undefined ? fallback.title : title;
|
|
57
|
+
const shownDescription = description === undefined ? fallback.description : description;
|
|
58
|
+
const Heading = `h${headingLevel}`;
|
|
59
|
+
const buttons = action ?? (_jsx(DefaultAction, { kind: kind, words: words, onClear: onClear, onRetry: onRetry }));
|
|
60
|
+
return (_jsxs("div", { role: kind === "error" ? "alert" : undefined, ...rest, "data-slot": "empty-state", "data-kind": kind, "data-size": size, children: [art ? (_jsx("div", { "data-slot": "empty-state-art", "aria-hidden": "true", children: art })) : null, icon ? (_jsx("div", { "data-slot": "empty-state-icon", "aria-hidden": "true", children: icon })) : null, shownTitle ? _jsx(Heading, { "data-slot": "empty-state-title", children: shownTitle }) : null, shownDescription ? (_jsx("p", { "data-slot": "empty-state-description", children: shownDescription })) : null, _jsx("div", { "data-slot": "empty-state-action", children: buttons })] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CheckboxProps } from "../checkbox";
|
|
2
|
+
import { type SelectProps } from "../select";
|
|
3
|
+
import { type SwitchProps } from "../switch";
|
|
4
|
+
import { type FieldProps } from "./field-props";
|
|
5
|
+
export interface Option {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
type Controlled = "value" | "defaultValue" | "onValueChange" | "name" | "required" | "disabled";
|
|
11
|
+
type Own = Controlled | "checked" | "defaultChecked" | "onCheckedChange";
|
|
12
|
+
export type SelectFieldProps = FieldProps & Omit<SelectProps<string, boolean>, Controlled | "items" | "multiple" | "children"> & {
|
|
13
|
+
options: readonly Option[];
|
|
14
|
+
/** Takes several options: the field's value is then a `string[]`, else a `string`. @defaultValue false */
|
|
15
|
+
multiple?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A list to pick from, bound to a form field. One choice is a `string`, with `""` for none; with `multiple` the value
|
|
19
|
+
* is a `string[]`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function SelectField({ label, description, required, disabled, multiple, ...select }: SelectFieldProps): React.JSX.Element;
|
|
22
|
+
export type CheckboxFieldProps = FieldProps & Omit<CheckboxProps, Own>;
|
|
23
|
+
/** One tick box, bound to a form field whose value is a `boolean`. */
|
|
24
|
+
export declare function CheckboxField({ label, description, required, disabled, ...box }: CheckboxFieldProps): React.JSX.Element;
|
|
25
|
+
export interface CheckboxGroupFieldProps extends Omit<FieldProps, "required"> {
|
|
26
|
+
options: readonly Option[];
|
|
27
|
+
size?: CheckboxProps["size"];
|
|
28
|
+
}
|
|
29
|
+
/** A set of tick boxes, bound to a form field whose value is the `string[]` of the ticked values. */
|
|
30
|
+
export declare function CheckboxGroupField({ label, description, disabled, options, size }: CheckboxGroupFieldProps): React.JSX.Element;
|
|
31
|
+
export type SwitchFieldProps = FieldProps & Omit<SwitchProps, Own>;
|
|
32
|
+
/** An on and off switch, bound to a form field whose value is a `boolean`. */
|
|
33
|
+
export declare function SwitchField({ label, description, required, disabled, ...toggle }: SwitchFieldProps): React.JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Checkbox, CheckboxGroup } from "../checkbox";
|
|
3
|
+
import { Label } from "../label";
|
|
4
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select";
|
|
5
|
+
import { Switch } from "../switch";
|
|
6
|
+
import { useFieldValue } from "./field-props";
|
|
7
|
+
import { FieldShell } from "./field-shell";
|
|
8
|
+
function Options({ options }) {
|
|
9
|
+
return (_jsxs(_Fragment, { children: [_jsx(SelectTrigger, { children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: options.map((option) => (_jsx(SelectItem, { value: option.value, disabled: option.disabled, children: option.label }, option.value))) })] }));
|
|
10
|
+
}
|
|
11
|
+
function Several({ options, ...select }) {
|
|
12
|
+
const [value, setValue] = useFieldValue();
|
|
13
|
+
return (_jsx(Select, { ...select, multiple: true, value: value, onValueChange: setValue, children: _jsx(Options, { options: options }) }));
|
|
14
|
+
}
|
|
15
|
+
function One({ options, ...select }) {
|
|
16
|
+
const [value, setValue] = useFieldValue();
|
|
17
|
+
return (_jsx(Select, { ...select, value: value === "" ? null : value, onValueChange: (next) => setValue(next ?? ""), children: _jsx(Options, { options: options }) }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A list to pick from, bound to a form field. One choice is a `string`, with `""` for none; with `multiple` the value
|
|
21
|
+
* is a `string[]`.
|
|
22
|
+
*/
|
|
23
|
+
export function SelectField({ label, description, required, disabled, multiple = false, ...select }) {
|
|
24
|
+
const picker = { ...select, required, disabled };
|
|
25
|
+
return (_jsx(FieldShell, { label: label, description: description, disabled: disabled, children: multiple ? _jsx(Several, { ...picker }) : _jsx(One, { ...picker }) }));
|
|
26
|
+
}
|
|
27
|
+
/** One tick box, bound to a form field whose value is a `boolean`. */
|
|
28
|
+
export function CheckboxField({ label, description, required, disabled, ...box }) {
|
|
29
|
+
const [checked, setChecked] = useFieldValue();
|
|
30
|
+
return (_jsx(FieldShell, { label: label, description: description, disabled: disabled, inline: true, children: _jsx(Checkbox, { ...box, required: required, checked: checked, onCheckedChange: (next) => setChecked(next === true) }) }));
|
|
31
|
+
}
|
|
32
|
+
/** A set of tick boxes, bound to a form field whose value is the `string[]` of the ticked values. */
|
|
33
|
+
export function CheckboxGroupField({ label, description, disabled, options, size }) {
|
|
34
|
+
const [value, setValue] = useFieldValue();
|
|
35
|
+
return (_jsx(FieldShell, { label: label, description: description, disabled: disabled, children: _jsx(CheckboxGroup, { value: value, onValueChange: setValue, "data-kumiko-form-group": "", children: options.map((option) => (_jsxs(Label, { disabled: option.disabled, children: [_jsx(Checkbox, { size: size, value: option.value, disabled: option.disabled }), option.label] }, option.value))) }) }));
|
|
36
|
+
}
|
|
37
|
+
/** An on and off switch, bound to a form field whose value is a `boolean`. */
|
|
38
|
+
export function SwitchField({ label, description, required, disabled, ...toggle }) {
|
|
39
|
+
const [checked, setChecked] = useFieldValue();
|
|
40
|
+
return (_jsx(FieldShell, { label: label, description: description, disabled: disabled, inline: true, children: _jsx(Switch, { ...toggle, required: required, checked: checked, onCheckedChange: setChecked }) }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field's error line. It always keeps one line of room, so an error that comes and goes moves nothing; a
|
|
3
|
+
* longer error grows the line smoothly, and one that goes away fades out. The fading copy is hidden from screen
|
|
4
|
+
* readers: only the live error is tied to the control.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ErrorLine({ message }: {
|
|
7
|
+
message: string | undefined;
|
|
8
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { FieldError } from "../input";
|
|
4
|
+
function noFade(element) {
|
|
5
|
+
return getComputedStyle(element)
|
|
6
|
+
.transitionDuration.split(",")
|
|
7
|
+
.every((duration) => duration.trim() === "0s");
|
|
8
|
+
}
|
|
9
|
+
/** Keeps the error that just went away, so it can fade out instead of vanishing. */
|
|
10
|
+
function useLeaving(message) {
|
|
11
|
+
const [previous, setPrevious] = useState(message);
|
|
12
|
+
const [leaving, setLeaving] = useState();
|
|
13
|
+
if (previous !== message) {
|
|
14
|
+
setPrevious(message);
|
|
15
|
+
setLeaving(message === undefined ? previous : undefined);
|
|
16
|
+
}
|
|
17
|
+
return [leaving, () => setLeaving(undefined)];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The field's error line. It always keeps one line of room, so an error that comes and goes moves nothing; a
|
|
21
|
+
* longer error grows the line smoothly, and one that goes away fades out. The fading copy is hidden from screen
|
|
22
|
+
* readers: only the live error is tied to the control.
|
|
23
|
+
*/
|
|
24
|
+
export function ErrorLine({ message }) {
|
|
25
|
+
const [leaving, left] = useLeaving(message);
|
|
26
|
+
const line = useRef(null);
|
|
27
|
+
const content = useRef(null);
|
|
28
|
+
const fading = useRef(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const box = line.current;
|
|
31
|
+
const inner = content.current;
|
|
32
|
+
if (!box || !inner || typeof ResizeObserver === "undefined") {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const observer = new ResizeObserver(() => {
|
|
36
|
+
box.style.setProperty("--kumiko-form-error-height", `${inner.offsetHeight}px`);
|
|
37
|
+
});
|
|
38
|
+
observer.observe(inner);
|
|
39
|
+
return () => observer.disconnect();
|
|
40
|
+
}, []);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (fading.current && noFade(fading.current)) {
|
|
43
|
+
left();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return (_jsx("div", { ref: line, "data-kumiko-form-error-line": "", children: _jsxs("div", { ref: content, children: [message === undefined ? null : _jsx(FieldError, { match: true, children: message }), leaving === undefined ? null : (_jsx("p", { ref: fading, "aria-hidden": "true", "data-kumiko-form-error-leaving": "", onTransitionEnd: left, onTransitionCancel: left, children: leaving }))] }) }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What every bound field takes, besides its control's own props. */
|
|
2
|
+
export interface FieldProps {
|
|
3
|
+
/** Names the control. */
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
/** A line under the control that stays while an error shows too. */
|
|
6
|
+
description?: React.ReactNode;
|
|
7
|
+
/** Marks the label and the control as required. The form's validators still decide what is valid. */
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** The value of the field in context, and a way to change it. The field re-renders as the value changes. */
|
|
12
|
+
export declare function useFieldValue<Value>(): [Value, (value: Value) => void];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useSelector } from "@tanstack/react-form";
|
|
2
|
+
import { useFieldContext } from "./form-context";
|
|
3
|
+
/** The value of the field in context, and a way to change it. The field re-renders as the value changes. */
|
|
4
|
+
export function useFieldValue() {
|
|
5
|
+
const field = useFieldContext();
|
|
6
|
+
const value = useSelector(field.store, (state) => state.value);
|
|
7
|
+
return [value, (next) => field.handleChange(next)];
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The error the field in context shows now, by the one rule: once it has been left or a submit was tried. */
|
|
2
|
+
export declare function useShownError(): string | undefined;
|
|
3
|
+
export interface FieldShellProps {
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
/** A line under the control that stays while an error shows too. */
|
|
6
|
+
description?: React.ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** Puts the control before the label, in one row, as a checkbox or a switch sits. @defaultValue false */
|
|
9
|
+
inline?: boolean;
|
|
10
|
+
/** The control, bound to the field by the caller. */
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A label, description and error around any control, tied together by ui-sdk's `Field`. Inside a field of
|
|
15
|
+
* `form.AppField`, an app's own control binds through `useFieldContext()` and sits in this.
|
|
16
|
+
* The field shows as invalid, and its first error, by the shown-error rule.
|
|
17
|
+
*/
|
|
18
|
+
export declare function FieldShell({ label, description, disabled, inline, children }: FieldShellProps): React.JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useSelector } from "@tanstack/react-form";
|
|
3
|
+
import { Field, FieldDescription, FieldLabel } from "../input";
|
|
4
|
+
import { ErrorLine } from "./error-line";
|
|
5
|
+
import { useFieldContext } from "./form-context";
|
|
6
|
+
import { shownError } from "./shown-error";
|
|
7
|
+
/** The error the field in context shows now, by the one rule: once it has been left or a submit was tried. */
|
|
8
|
+
export function useShownError() {
|
|
9
|
+
const field = useFieldContext();
|
|
10
|
+
const blurred = useSelector(field.store, (state) => state.meta.isBlurred);
|
|
11
|
+
const errors = useSelector(field.store, (state) => state.meta.errors);
|
|
12
|
+
const attempts = useSelector(field.form.store, (state) => state.submissionAttempts);
|
|
13
|
+
return shownError({ isBlurred: blurred, errors }, attempts);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* True when focus is leaving the field for good. Moving within it, or onto a submit button, does not count: an
|
|
17
|
+
* error that appeared as the button was pressed would move the button away before the press finished, and the
|
|
18
|
+
* submit would be lost. The submit shows the errors anyway.
|
|
19
|
+
*/
|
|
20
|
+
function leavesField(event) {
|
|
21
|
+
const next = event.relatedTarget;
|
|
22
|
+
if (!(next instanceof Element)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const submitting = next instanceof HTMLButtonElement && next.type === "submit";
|
|
26
|
+
return !event.currentTarget.contains(next) && !submitting;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Marks the field as left, and runs its change validators once, so a field no one has typed in yet can still show
|
|
30
|
+
* what is missing. Validators that run on blur only would leave a stale error behind once the value is fixed, so
|
|
31
|
+
* apps should give `onChange` ones.
|
|
32
|
+
*/
|
|
33
|
+
function leave(field) {
|
|
34
|
+
field.handleBlur();
|
|
35
|
+
void field.validate("change");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A label, description and error around any control, tied together by ui-sdk's `Field`. Inside a field of
|
|
39
|
+
* `form.AppField`, an app's own control binds through `useFieldContext()` and sits in this.
|
|
40
|
+
* The field shows as invalid, and its first error, by the shown-error rule.
|
|
41
|
+
*/
|
|
42
|
+
export function FieldShell({ label, description, disabled, inline = false, children }) {
|
|
43
|
+
const field = useFieldContext();
|
|
44
|
+
const message = useShownError();
|
|
45
|
+
const labelPart = _jsx(FieldLabel, { children: label });
|
|
46
|
+
return (_jsxs(Field, { name: field.name, invalid: message !== undefined, disabled: disabled, "data-kumiko-form-field": "", "data-inline": inline ? "" : undefined, onBlur: (event) => {
|
|
47
|
+
if (leavesField(event)) {
|
|
48
|
+
leave(field);
|
|
49
|
+
}
|
|
50
|
+
}, children: [inline ? children : labelPart, inline ? labelPart : children, description === undefined ? null : _jsx(FieldDescription, { children: description }), _jsx(ErrorLine, { message: message })] }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves focus to the control of the first field in the form, in page order, that shows an error. The control is
|
|
3
|
+
* the one ui-sdk marks `aria-invalid`, or else the first thing in the field that takes focus.
|
|
4
|
+
*/
|
|
5
|
+
export declare function focusFirstInvalid(form: HTMLElement): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The controls a person can put the cursor in, but never ui-sdk's visually hidden native twins. */
|
|
2
|
+
const focusable = "input:not([aria-hidden='true']):not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex='-1'])";
|
|
3
|
+
/**
|
|
4
|
+
* Moves focus to the control of the first field in the form, in page order, that shows an error. The control is
|
|
5
|
+
* the one ui-sdk marks `aria-invalid`, or else the first thing in the field that takes focus.
|
|
6
|
+
*/
|
|
7
|
+
export function focusFirstInvalid(form) {
|
|
8
|
+
for (const field of form.querySelectorAll("[data-kumiko-form-field][data-invalid]")) {
|
|
9
|
+
const control = field.querySelector(`[aria-invalid='true']:is(${focusable})`) ??
|
|
10
|
+
field.querySelector(focusable);
|
|
11
|
+
if (control) {
|
|
12
|
+
control.focus();
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** The contexts the form's parts read: the field a part is inside, and the form around it. */
|
|
2
|
+
export declare const fieldContext: import("react").Context<import("@tanstack/react-form").AnyFieldApi>, formContext: import("react").Context<import("@tanstack/react-form").AnyFormApi>, useFieldContext: <TData>() => import("@tanstack/react-form").FieldApi<any, string, TData, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>, useFormContext: () => import("@tanstack/react-form").ReactFormExtendedApi<Record<string, never>, any, any, any, any, any, any, any, any, any, any, any>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ButtonProps } from "../button";
|
|
2
|
+
export interface FormProps extends Omit<React.ComponentProps<"form">, "noValidate" | "ref"> {
|
|
3
|
+
/**
|
|
4
|
+
* Links the form to the dialog it is in: the dialog can't be dismissed while the form submits, and asks before a
|
|
5
|
+
* dismiss while the form is edited. Does nothing outside a dialog.
|
|
6
|
+
* @defaultValue true
|
|
7
|
+
*/
|
|
8
|
+
dialog?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The `<form>`: it checks nothing itself, and a submit runs the form's own `handleSubmit()`. A submit that fails
|
|
12
|
+
* moves focus to the first field with an error. A press during a submit is ignored.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Form({ dialog, onSubmit, ...props }: FormProps): React.JSX.Element;
|
|
15
|
+
/** The form-level error, from the server or from a validator that names no field. Nothing shows without one. */
|
|
16
|
+
export declare function FormError(props: React.ComponentProps<"p">): React.JSX.Element | null;
|
|
17
|
+
/** The row of buttons at the end of a form. In an opened dialog it is the dialog's footer. */
|
|
18
|
+
export declare function Actions(props: React.ComponentProps<"div">): React.JSX.Element;
|
|
19
|
+
/** The submit button. It shows loading while the form submits, and is never disabled for invalid input. */
|
|
20
|
+
export declare function SubmitButton({ status, ...props }: ButtonProps): React.JSX.Element;
|