@aaas-pro/library 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -2
- package/dist/components/address-picker.d.ts +18 -0
- package/dist/components/address-picker.js +46 -0
- package/dist/components/card-date-filter.d.ts +12 -0
- package/dist/components/card-date-filter.js +95 -0
- package/dist/components/date-time-picker.d.ts +12 -0
- package/dist/components/date-time-picker.js +96 -0
- package/dist/components/detail-dialog.d.ts +48 -0
- package/dist/components/detail-dialog.js +97 -0
- package/dist/components/document-links.d.ts +13 -0
- package/dist/components/document-links.js +19 -0
- package/dist/components/draft-row-actions.d.ts +14 -0
- package/dist/components/draft-row-actions.js +70 -0
- package/dist/components/error-boundary.d.ts +14 -0
- package/dist/components/error-boundary.js +35 -0
- package/dist/components/glow-card.d.ts +13 -0
- package/dist/components/glow-card.js +48 -0
- package/dist/components/org-picker.d.ts +17 -0
- package/dist/components/org-picker.js +56 -0
- package/dist/components/overflow-row-actions.d.ts +29 -0
- package/dist/components/overflow-row-actions.js +135 -0
- package/dist/components/page-header.d.ts +21 -0
- package/dist/components/page-header.js +21 -0
- package/dist/components/permission-button.d.ts +4 -0
- package/dist/components/permission-button.js +17 -0
- package/dist/components/permission-context.d.ts +12 -0
- package/dist/components/permission-context.js +17 -0
- package/dist/components/person-picker.d.ts +20 -0
- package/dist/components/person-picker.js +38 -0
- package/dist/components/process-flow-bar.d.ts +15 -0
- package/dist/components/process-flow-bar.js +19 -0
- package/dist/components/product-picker.d.ts +19 -0
- package/dist/components/product-picker.js +155 -0
- package/dist/components/ref-doc-picker.d.ts +24 -0
- package/dist/components/ref-doc-picker.js +139 -0
- package/dist/components/scroll-to-top.d.ts +1 -0
- package/dist/components/scroll-to-top.js +20 -0
- package/dist/components/state-view.d.ts +26 -0
- package/dist/components/state-view.js +75 -0
- package/dist/components/theme-switcher.d.ts +27 -0
- package/dist/components/theme-switcher.js +77 -0
- package/dist/components/time-filter.d.ts +7 -0
- package/dist/components/time-filter.js +65 -0
- package/dist/components/ui/accordion.d.ts +7 -0
- package/dist/components/ui/accordion.js +64 -0
- package/dist/components/ui/alert-dialog.d.ts +15 -0
- package/dist/components/ui/alert-dialog.js +160 -0
- package/dist/components/ui/alert.d.ts +12 -0
- package/dist/components/ui/alert.js +66 -0
- package/dist/components/ui/aspect-ratio.d.ts +3 -0
- package/dist/components/ui/aspect-ratio.js +10 -0
- package/dist/components/ui/avatar.d.ts +6 -0
- package/dist/components/ui/avatar.js +53 -0
- package/dist/components/ui/badge.d.ts +12 -0
- package/dist/components/ui/badge.js +44 -0
- package/dist/components/ui/breadcrumb.d.ts +11 -0
- package/dist/components/ui/breadcrumb.js +103 -0
- package/dist/components/ui/button-group.d.ts +14 -0
- package/dist/components/ui/button-group.js +76 -0
- package/dist/components/ui/button.d.ts +20 -0
- package/dist/components/ui/button.js +93 -0
- package/dist/components/ui/calendar.d.ts +73 -0
- package/dist/components/ui/calendar.js +103 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.js +90 -0
- package/dist/components/ui/carousel.d.ts +14 -0
- package/dist/components/ui/carousel.js +200 -0
- package/dist/components/ui/chart.d.ts +43 -0
- package/dist/components/ui/chart.js +252 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/checkbox.js +31 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/collapsible.js +34 -0
- package/dist/components/ui/command.d.ts +18 -0
- package/dist/components/ui/command.js +170 -0
- package/dist/components/ui/context-menu.d.ts +26 -0
- package/dist/components/ui/context-menu.js +237 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.js +139 -0
- package/dist/components/ui/drawer.d.ts +13 -0
- package/dist/components/ui/drawer.js +129 -0
- package/dist/components/ui/dropdown-menu.d.ts +26 -0
- package/dist/components/ui/dropdown-menu.js +245 -0
- package/dist/components/ui/empty.d.ts +14 -0
- package/dist/components/ui/empty.js +102 -0
- package/dist/components/ui/field.d.ts +27 -0
- package/dist/components/ui/field.js +229 -0
- package/dist/components/ui/form.d.ts +26 -0
- package/dist/components/ui/form.js +118 -0
- package/dist/components/ui/hover-card.d.ts +6 -0
- package/dist/components/ui/hover-card.js +39 -0
- package/dist/components/ui/input-group.d.ts +22 -0
- package/dist/components/ui/input-group.js +156 -0
- package/dist/components/ui/input-otp.d.ts +11 -0
- package/dist/components/ui/input-otp.js +66 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +21 -0
- package/dist/components/ui/item.d.ts +29 -0
- package/dist/components/ui/item.js +187 -0
- package/dist/components/ui/kbd.d.ts +3 -0
- package/dist/components/ui/kbd.js +31 -0
- package/dist/components/ui/label.d.ts +4 -0
- package/dist/components/ui/label.js +22 -0
- package/dist/components/ui/menubar.d.ts +26 -0
- package/dist/components/ui/menubar.js +252 -0
- package/dist/components/ui/navigation-menu.d.ts +17 -0
- package/dist/components/ui/navigation-menu.js +170 -0
- package/dist/components/ui/pagination.d.ts +13 -0
- package/dist/components/ui/pagination.js +118 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.js +47 -0
- package/dist/components/ui/progress.d.ts +4 -0
- package/dist/components/ui/progress.js +34 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +45 -0
- package/dist/components/ui/resizable.d.ts +7 -0
- package/dist/components/ui/resizable.js +49 -0
- package/dist/components/ui/scroll-area.d.ts +5 -0
- package/dist/components/ui/scroll-area.js +60 -0
- package/dist/components/ui/select.d.ts +17 -0
- package/dist/components/ui/select.js +215 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.js +26 -0
- package/dist/components/ui/sheet.d.ts +13 -0
- package/dist/components/ui/sheet.js +127 -0
- package/dist/components/ui/sidebar.d.ts +72 -0
- package/dist/components/ui/sidebar.js +656 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/skeleton.js +15 -0
- package/dist/components/ui/slider.d.ts +4 -0
- package/dist/components/ui/slider.js +63 -0
- package/dist/components/ui/sonner.d.ts +4 -0
- package/dist/components/ui/sonner.js +34 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/spinner.js +17 -0
- package/dist/components/ui/switch.d.ts +4 -0
- package/dist/components/ui/switch.js +31 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/table.js +114 -0
- package/dist/components/ui/tabs.d.ts +7 -0
- package/dist/components/ui/tabs.js +67 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.js +18 -0
- package/dist/components/ui/toggle-group.d.ts +9 -0
- package/dist/components/ui/toggle-group.js +68 -0
- package/dist/components/ui/toggle.d.ts +12 -0
- package/dist/components/ui/toggle.js +43 -0
- package/dist/components/ui/tooltip.d.ts +7 -0
- package/dist/components/ui/tooltip.js +56 -0
- package/dist/hooks/use-mobile.d.ts +1 -0
- package/dist/hooks/use-mobile.js +18 -0
- package/dist/icons/index.d.ts +57 -0
- package/dist/icons/index.js +115 -0
- package/dist/icons/paths.d.ts +556 -0
- package/dist/icons/paths.js +231 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +399 -0
- package/dist/internal/selection-base.d.ts +37 -0
- package/dist/internal/selection-base.js +40 -0
- package/dist/lib/class-names.d.ts +6 -0
- package/dist/lib/class-names.js +159 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +7 -0
- package/dist/lib/variants.d.ts +21 -0
- package/dist/lib/variants.js +21 -0
- package/dist/primitives/accordion.d.ts +29 -0
- package/dist/primitives/accordion.js +49 -0
- package/dist/primitives/alert-dialog.d.ts +10 -0
- package/dist/primitives/alert-dialog.js +22 -0
- package/dist/primitives/aspect-ratio.d.ts +4 -0
- package/dist/primitives/aspect-ratio.js +7 -0
- package/dist/primitives/avatar.d.ts +8 -0
- package/dist/primitives/avatar.js +45 -0
- package/dist/primitives/carousel.d.ts +22 -0
- package/dist/primitives/carousel.js +78 -0
- package/dist/primitives/chart.d.ts +71 -0
- package/dist/primitives/chart.js +125 -0
- package/dist/primitives/checkbox.d.ts +13 -0
- package/dist/primitives/checkbox.js +24 -0
- package/dist/primitives/collapsible.d.ts +14 -0
- package/dist/primitives/collapsible.js +29 -0
- package/dist/primitives/command.d.ts +43 -0
- package/dist/primitives/command.js +98 -0
- package/dist/primitives/context-menu.d.ts +24 -0
- package/dist/primitives/context-menu.js +19 -0
- package/dist/primitives/core.d.ts +25 -0
- package/dist/primitives/core.js +89 -0
- package/dist/primitives/dialog.d.ts +7 -0
- package/dist/primitives/dialog.js +15 -0
- package/dist/primitives/drawer.d.ts +30 -0
- package/dist/primitives/drawer.js +39 -0
- package/dist/primitives/dropdown-menu.d.ts +24 -0
- package/dist/primitives/dropdown-menu.js +19 -0
- package/dist/primitives/form.d.ts +154 -0
- package/dist/primitives/form.js +139 -0
- package/dist/primitives/hover-card.d.ts +4 -0
- package/dist/primitives/hover-card.js +8 -0
- package/dist/primitives/input-otp.d.ts +21 -0
- package/dist/primitives/input-otp.js +78 -0
- package/dist/primitives/label.d.ts +2 -0
- package/dist/primitives/label.js +7 -0
- package/dist/primitives/layer.d.ts +84 -0
- package/dist/primitives/layer.js +300 -0
- package/dist/primitives/menu.d.ts +56 -0
- package/dist/primitives/menu.js +126 -0
- package/dist/primitives/menubar.d.ts +91 -0
- package/dist/primitives/menubar.js +44 -0
- package/dist/primitives/navigation-menu.d.ts +32 -0
- package/dist/primitives/navigation-menu.js +121 -0
- package/dist/primitives/popover.d.ts +4 -0
- package/dist/primitives/popover.js +12 -0
- package/dist/primitives/progress.d.ts +7 -0
- package/dist/primitives/progress.js +13 -0
- package/dist/primitives/radio-group.d.ts +18 -0
- package/dist/primitives/radio-group.js +36 -0
- package/dist/primitives/resizable.d.ts +19 -0
- package/dist/primitives/resizable.js +91 -0
- package/dist/primitives/scroll-area.d.ts +12 -0
- package/dist/primitives/scroll-area.js +26 -0
- package/dist/primitives/select.d.ts +42 -0
- package/dist/primitives/select.js +167 -0
- package/dist/primitives/separator.d.ts +5 -0
- package/dist/primitives/separator.js +7 -0
- package/dist/primitives/slider.d.ts +25 -0
- package/dist/primitives/slider.js +98 -0
- package/dist/primitives/slot.d.ts +1 -0
- package/dist/primitives/slot.js +4 -0
- package/dist/primitives/switch.d.ts +11 -0
- package/dist/primitives/switch.js +22 -0
- package/dist/primitives/tabs.d.ts +23 -0
- package/dist/primitives/tabs.js +38 -0
- package/dist/primitives/toast.d.ts +55 -0
- package/dist/primitives/toast.js +86 -0
- package/dist/primitives/toggle-group.d.ts +24 -0
- package/dist/primitives/toggle-group.js +33 -0
- package/dist/primitives/toggle.d.ts +7 -0
- package/dist/primitives/toggle.js +13 -0
- package/dist/primitives/tooltip.d.ts +7 -0
- package/dist/primitives/tooltip.js +10 -0
- package/dist/style-entry.d.ts +1 -0
- package/dist/style-entry.js +1 -0
- package/dist/styles.css +7016 -0
- package/dist/styles.js +1 -0
- package/dist/theme/index.d.ts +110 -0
- package/dist/theme/index.js +199 -0
- package/licenses/Lucide.txt +15 -0
- package/package.json +67 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type DivProps } from './core';
|
|
3
|
+
type Filter = (value: string, search: string, keywords?: string[]) => number;
|
|
4
|
+
export interface CommandProps extends Omit<DivProps, 'defaultValue'> {
|
|
5
|
+
value?: string;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
shouldFilter?: boolean;
|
|
9
|
+
filter?: Filter;
|
|
10
|
+
loop?: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function textOf(children: React.ReactNode): string;
|
|
14
|
+
declare function Root({ value, defaultValue, onValueChange, shouldFilter, filter, loop, label, onKeyDown, ...props }: CommandProps): React.JSX.Element;
|
|
15
|
+
declare function Input({ value, onValueChange, onChange, ...props }: Omit<React.ComponentProps<'input'>, 'value'> & {
|
|
16
|
+
value?: string;
|
|
17
|
+
onValueChange?: (value: string) => void;
|
|
18
|
+
}): React.JSX.Element;
|
|
19
|
+
declare function List(props: DivProps): React.JSX.Element;
|
|
20
|
+
declare function Empty(props: DivProps): React.JSX.Element | null;
|
|
21
|
+
declare function Group({ heading, forceMount, children, ...props }: DivProps & {
|
|
22
|
+
heading?: React.ReactNode;
|
|
23
|
+
forceMount?: boolean;
|
|
24
|
+
}): React.JSX.Element;
|
|
25
|
+
declare function Item({ value, keywords, disabled, onSelect, children, forceMount, onClick, onPointerMove, ...props }: Omit<DivProps, 'onSelect'> & {
|
|
26
|
+
value?: string;
|
|
27
|
+
keywords?: string[];
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
onSelect?: (value: string) => void;
|
|
30
|
+
forceMount?: boolean;
|
|
31
|
+
}): React.JSX.Element;
|
|
32
|
+
declare function Separator({ alwaysRender: _always, ...props }: DivProps & {
|
|
33
|
+
alwaysRender?: boolean;
|
|
34
|
+
}): React.JSX.Element;
|
|
35
|
+
export declare const Command: typeof Root & {
|
|
36
|
+
Input: typeof Input;
|
|
37
|
+
List: typeof List;
|
|
38
|
+
Empty: typeof Empty;
|
|
39
|
+
Group: typeof Group;
|
|
40
|
+
Item: typeof Item;
|
|
41
|
+
Separator: typeof Separator;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useControllable, DivPart } from "./core.js";
|
|
4
|
+
const defaultFilter = (value, query, keywords = []) => `${value} ${keywords.join(" ")}`.toLocaleLowerCase().includes(query.toLocaleLowerCase().trim()) ? 1 : 0;
|
|
5
|
+
const Context = React.createContext({ query: "", setQuery: (_query) => {
|
|
6
|
+
}, value: "", setValue: (_value) => {
|
|
7
|
+
}, shouldFilter: true, filter: defaultFilter, items: /* @__PURE__ */ new Map(), register: (_item) => () => {
|
|
8
|
+
}, listId: "" });
|
|
9
|
+
const GroupContext = React.createContext("");
|
|
10
|
+
function textOf(children) {
|
|
11
|
+
return React.Children.toArray(children).map((child) => typeof child === "string" || typeof child === "number" ? String(child) : React.isValidElement(child) ? textOf(child.props.children) : "").join(" ");
|
|
12
|
+
}
|
|
13
|
+
function Root({ value, defaultValue = "", onValueChange, shouldFilter = true, filter = defaultFilter, loop = false, label = "命令", onKeyDown, ...props }) {
|
|
14
|
+
const [query, setQuery] = React.useState(""), [current, setValue] = useControllable(value, defaultValue, onValueChange), [items, setItems] = React.useState(/* @__PURE__ */ new Map());
|
|
15
|
+
const listId = React.useId();
|
|
16
|
+
const register = React.useCallback((item) => {
|
|
17
|
+
setItems((previous) => new Map(previous).set(item.id, item));
|
|
18
|
+
return () => setItems((previous) => {
|
|
19
|
+
const next = new Map(previous);
|
|
20
|
+
next.delete(item.id);
|
|
21
|
+
return next;
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: { query, setQuery, value: current, setValue, shouldFilter, filter, items, register, listId }, children: /* @__PURE__ */ jsx(DivPart, { ...props, "aria-label": label, "data-command-root": "", onKeyDown: (event) => {
|
|
25
|
+
onKeyDown?.(event);
|
|
26
|
+
if (event.defaultPrevented)
|
|
27
|
+
return;
|
|
28
|
+
const candidates = [...items.values()].filter((item) => !item.disabled && (!shouldFilter || filter(`${item.value} ${item.text}`, query, item.keywords) > 0));
|
|
29
|
+
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key) && candidates.length) {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
const index = candidates.findIndex((item) => item.value === current);
|
|
32
|
+
let next = event.key === "Home" ? 0 : event.key === "End" ? candidates.length - 1 : index + (event.key === "ArrowDown" ? 1 : -1);
|
|
33
|
+
next = loop ? (next + candidates.length) % candidates.length : Math.max(0, Math.min(candidates.length - 1, next));
|
|
34
|
+
setValue(candidates[next].value);
|
|
35
|
+
document.getElementById(candidates[next].id)?.scrollIntoView?.({ block: "nearest" });
|
|
36
|
+
} else if (event.key === "Enter") {
|
|
37
|
+
const item = candidates.find((item2) => item2.value === current) ?? candidates[0];
|
|
38
|
+
if (item) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
document.getElementById(item.id)?.click();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} }) });
|
|
44
|
+
}
|
|
45
|
+
function Input({ value, onValueChange, onChange, ...props }) {
|
|
46
|
+
const state = React.useContext(Context), current = value ?? state.query, active = [...state.items.values()].find((item) => item.value === state.value);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (value !== void 0)
|
|
49
|
+
state.setQuery(value);
|
|
50
|
+
}, [value]);
|
|
51
|
+
return /* @__PURE__ */ jsx("input", { ...props, "data-command-input": "", role: "combobox", "aria-expanded": "true", "aria-controls": state.listId, "aria-autocomplete": "list", "aria-activedescendant": active?.id, value: current, onChange: (event) => {
|
|
52
|
+
onChange?.(event);
|
|
53
|
+
if (!event.defaultPrevented) {
|
|
54
|
+
state.setQuery(event.target.value);
|
|
55
|
+
onValueChange?.(event.target.value);
|
|
56
|
+
}
|
|
57
|
+
} });
|
|
58
|
+
}
|
|
59
|
+
function List(props) {
|
|
60
|
+
const state = React.useContext(Context);
|
|
61
|
+
return /* @__PURE__ */ jsx(DivPart, { ...props, id: state.listId, "data-command-list": "", role: "listbox" });
|
|
62
|
+
}
|
|
63
|
+
function Empty(props) {
|
|
64
|
+
const state = React.useContext(Context);
|
|
65
|
+
return [...state.items.values()].some((item) => !state.shouldFilter || state.filter(`${item.value} ${item.text}`, state.query, item.keywords) > 0) ? null : /* @__PURE__ */ jsx(DivPart, { ...props, role: "status" });
|
|
66
|
+
}
|
|
67
|
+
function Group({ heading, forceMount, children, ...props }) {
|
|
68
|
+
const state = React.useContext(Context), id = React.useId();
|
|
69
|
+
const candidates = [...state.items.values()].filter((item) => item.group === id), empty = candidates.length > 0 && !candidates.some((item) => !state.shouldFilter || state.filter(`${item.value} ${item.text}`, state.query, item.keywords) > 0);
|
|
70
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, { value: id, children: /* @__PURE__ */ jsxs(DivPart, { ...props, "data-command-group": "", role: "group", "aria-labelledby": heading ? `${id}-heading` : void 0, hidden: !forceMount && empty, children: [
|
|
71
|
+
heading && /* @__PURE__ */ jsx("div", { id: `${id}-heading`, "data-command-group-heading": "", children: heading }),
|
|
72
|
+
children
|
|
73
|
+
] }) });
|
|
74
|
+
}
|
|
75
|
+
function Item({ value, keywords = [], disabled = false, onSelect, children, forceMount = false, onClick, onPointerMove, ...props }) {
|
|
76
|
+
const state = React.useContext(Context), group = React.useContext(GroupContext), id = React.useId(), text = textOf(children), key = value ?? text, keywordKey = keywords.join("\0");
|
|
77
|
+
React.useEffect(() => state.register({ id, value: key, text, keywords, disabled, group }), [id, key, text, keywordKey, disabled, group, state.register]);
|
|
78
|
+
const shown = forceMount || !state.shouldFilter || state.filter(`${key} ${text}`, state.query, keywords) > 0;
|
|
79
|
+
return /* @__PURE__ */ jsx(DivPart, { ...props, id, role: "option", tabIndex: -1, hidden: !shown, "data-command-item": "", "data-selected": state.value === key, "data-disabled": disabled, "aria-selected": state.value === key, "aria-disabled": disabled, onPointerMove: (event) => {
|
|
80
|
+
onPointerMove?.(event);
|
|
81
|
+
if (!disabled)
|
|
82
|
+
state.setValue(key);
|
|
83
|
+
}, onClick: (event) => {
|
|
84
|
+
onClick?.(event);
|
|
85
|
+
if (!event.defaultPrevented && !disabled) {
|
|
86
|
+
state.setValue(key);
|
|
87
|
+
onSelect?.(key);
|
|
88
|
+
}
|
|
89
|
+
}, children });
|
|
90
|
+
}
|
|
91
|
+
function Separator({ alwaysRender: _always, ...props }) {
|
|
92
|
+
return /* @__PURE__ */ jsx(DivPart, { ...props, role: "separator" });
|
|
93
|
+
}
|
|
94
|
+
const Command = Object.assign(Root, { Input, List, Empty, Group, Item, Separator });
|
|
95
|
+
export {
|
|
96
|
+
Command,
|
|
97
|
+
textOf
|
|
98
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const Root: (props: import("./layer").ModalRootProps) => React.ReactElement, Trigger: ({ onContextMenu, ref, disabled, ...props }: import("./core").ButtonProps) => import("react").JSX.Element, Portal: ({ children, container, forceMount }: import("./layer").PortalProps) => import("react").ReactPortal | null, Content: ({ onKeyDown, loop, ...props }: import("./layer").LayerContentProps & {
|
|
2
|
+
loop?: boolean;
|
|
3
|
+
}) => import("react").JSX.Element, Group: (props: import("./core").DivProps) => import("react").JSX.Element, Label: (props: import("./core").DivProps) => import("react").JSX.Element, Item: ({ onSelect, textValue: _text, onClick, onPointerMove, ...props }: Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
4
|
+
onSelect?: (event: Event) => void;
|
|
5
|
+
textValue?: string;
|
|
6
|
+
}) => import("react").JSX.Element, CheckboxItem: ({ checked, defaultChecked, onCheckedChange, children, onSelect, ...props }: (Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
7
|
+
onSelect?: (event: Event) => void;
|
|
8
|
+
textValue?: string;
|
|
9
|
+
}) & {
|
|
10
|
+
checked?: boolean | "indeterminate";
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
13
|
+
}) => import("react").JSX.Element, RadioGroup: ({ value, defaultValue, onValueChange, ...props }: Omit<import("./core").DivProps, "defaultValue"> & {
|
|
14
|
+
value?: string;
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
onValueChange?: (value: string) => void;
|
|
17
|
+
}) => import("react").JSX.Element, RadioItem: ({ value, children, onSelect, ...props }: (Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
18
|
+
onSelect?: (event: Event) => void;
|
|
19
|
+
textValue?: string;
|
|
20
|
+
}) & {
|
|
21
|
+
value: string;
|
|
22
|
+
}) => import("react").JSX.Element, Separator: (props: import("./core").DivProps) => import("react").JSX.Element, ItemIndicator: ({ forceMount, ...props }: React.ComponentProps<"span"> & {
|
|
23
|
+
forceMount?: true;
|
|
24
|
+
}) => import("react").JSX.Element | null, Sub: (props: import("./layer").ModalRootProps) => React.ReactElement, SubTrigger: ({ onClick, onPointerEnter, onKeyDown, ref, ...props }: import("./core").ButtonProps) => import("react").JSX.Element, SubContent: ({ onKeyDown, ...props }: import("./layer").LayerContentProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMenu } from "./menu.js";
|
|
2
|
+
const { Root, Trigger, Portal, Content, Group, Label, Item, CheckboxItem, RadioGroup, RadioItem, Separator, ItemIndicator, Sub, SubTrigger, SubContent } = createMenu(true);
|
|
3
|
+
export {
|
|
4
|
+
CheckboxItem,
|
|
5
|
+
Content,
|
|
6
|
+
Group,
|
|
7
|
+
Item,
|
|
8
|
+
ItemIndicator,
|
|
9
|
+
Label,
|
|
10
|
+
Portal,
|
|
11
|
+
RadioGroup,
|
|
12
|
+
RadioItem,
|
|
13
|
+
Root,
|
|
14
|
+
Separator,
|
|
15
|
+
Sub,
|
|
16
|
+
SubContent,
|
|
17
|
+
SubTrigger,
|
|
18
|
+
Trigger
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function setRef<T>(ref: React.Ref<T> | undefined, value: T | null): void;
|
|
3
|
+
export declare function useMergedRef<T>(...refs: (React.Ref<T> | undefined)[]): (value: T | null) => void;
|
|
4
|
+
export declare function useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (next: T) => void): readonly [T, (next: T | ((previous: T) => T)) => void];
|
|
5
|
+
/** Compose a single child without adding a DOM wrapper. Child handlers run first. */
|
|
6
|
+
export declare function Slot({ children, ref, ...props }: React.HTMLAttributes<HTMLElement> & {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
ref?: React.Ref<HTMLElement>;
|
|
9
|
+
}): React.ReactElement<Record<string, unknown>, string | React.JSXElementConstructor<any>>;
|
|
10
|
+
export type ButtonProps = React.ComponentProps<'button'> & {
|
|
11
|
+
asChild?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function ButtonPart({ asChild, ...props }: ButtonProps): React.JSX.Element;
|
|
14
|
+
export type DivProps = React.ComponentProps<'div'> & {
|
|
15
|
+
asChild?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function DivPart({ asChild, ...props }: DivProps): React.JSX.Element;
|
|
18
|
+
export declare function focusable(container: HTMLElement): HTMLElement[];
|
|
19
|
+
/** Roving keyboard navigation, disabled controls are skipped. */
|
|
20
|
+
export declare function moveFocus(event: React.KeyboardEvent<HTMLElement>, selector: string, { vertical, loop, select }?: {
|
|
21
|
+
vertical?: boolean;
|
|
22
|
+
loop?: boolean;
|
|
23
|
+
select?: boolean;
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function selectionEvent(callback?: (event: Event) => void): boolean;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
function setRef(ref, value) {
|
|
4
|
+
if (typeof ref === "function")
|
|
5
|
+
ref(value);
|
|
6
|
+
else if (ref)
|
|
7
|
+
ref.current = value;
|
|
8
|
+
}
|
|
9
|
+
function useMergedRef(...refs) {
|
|
10
|
+
return React.useMemo(() => (value) => refs.forEach((ref) => setRef(ref, value)), refs);
|
|
11
|
+
}
|
|
12
|
+
function useControllable(value, defaultValue, onChange) {
|
|
13
|
+
const [local, setLocal] = React.useState(defaultValue);
|
|
14
|
+
const current = value === void 0 ? local : value;
|
|
15
|
+
const latest = React.useRef({ current, value, onChange });
|
|
16
|
+
latest.current = { current, value, onChange };
|
|
17
|
+
const set = React.useCallback((next) => {
|
|
18
|
+
const previous = latest.current;
|
|
19
|
+
const resolved = typeof next === "function" ? next(previous.current) : next;
|
|
20
|
+
if (Object.is(resolved, previous.current))
|
|
21
|
+
return;
|
|
22
|
+
if (previous.value === void 0)
|
|
23
|
+
setLocal(resolved);
|
|
24
|
+
previous.onChange?.(resolved);
|
|
25
|
+
}, []);
|
|
26
|
+
return [current, set];
|
|
27
|
+
}
|
|
28
|
+
function Slot({ children, ref, ...props }) {
|
|
29
|
+
if (!React.isValidElement(children))
|
|
30
|
+
throw new Error("asChild requires one React element");
|
|
31
|
+
const child = children;
|
|
32
|
+
const merged = { ...props, ...child.props };
|
|
33
|
+
for (const [key, parent] of Object.entries(props)) {
|
|
34
|
+
const own = child.props[key];
|
|
35
|
+
if (/^on[A-Z]/.test(key) && typeof parent === "function") {
|
|
36
|
+
merged[key] = (...args) => {
|
|
37
|
+
if (typeof own === "function")
|
|
38
|
+
own(...args);
|
|
39
|
+
if (!args[0]?.defaultPrevented)
|
|
40
|
+
parent(...args);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
merged.className = [props.className, child.props.className].filter(Boolean).join(" ");
|
|
45
|
+
merged.style = { ...props.style, ...child.props.style };
|
|
46
|
+
const combined = useMergedRef(ref, child.props.ref);
|
|
47
|
+
return React.cloneElement(child, { ...merged, ref: combined });
|
|
48
|
+
}
|
|
49
|
+
function ButtonPart({ asChild, ...props }) {
|
|
50
|
+
return asChild ? /* @__PURE__ */ jsx(Slot, { ...props, ref: props.ref, children: props.children }) : /* @__PURE__ */ jsx("button", { type: "button", ...props });
|
|
51
|
+
}
|
|
52
|
+
function DivPart({ asChild, ...props }) {
|
|
53
|
+
return asChild ? /* @__PURE__ */ jsx(Slot, { ...props, children: props.children }) : /* @__PURE__ */ jsx("div", { ...props });
|
|
54
|
+
}
|
|
55
|
+
function focusable(container) {
|
|
56
|
+
return [...container.querySelectorAll('button:not(:disabled),a[href],input:not(:disabled),select:not(:disabled),textarea:not(:disabled),[tabindex]:not([tabindex="-1"])')].filter((node) => node.tabIndex >= 0 && !node.hidden && !node.closest('[hidden],[inert],[aria-hidden="true"]') && getComputedStyle(node).display !== "none");
|
|
57
|
+
}
|
|
58
|
+
function moveFocus(event, selector, { vertical = false, loop = true, select = false } = {}) {
|
|
59
|
+
const rtl = !vertical && (event.currentTarget.closest("[dir]")?.getAttribute("dir") === "rtl" || getComputedStyle(event.currentTarget).direction === "rtl");
|
|
60
|
+
const nextKey = vertical ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight", prevKey = vertical ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
61
|
+
if (![nextKey, prevKey, "Home", "End"].includes(event.key))
|
|
62
|
+
return;
|
|
63
|
+
const nodes = [...event.currentTarget.querySelectorAll(selector)].filter((n) => !n.matches(':disabled,[aria-disabled="true"]') && !n.closest("[hidden]"));
|
|
64
|
+
if (!nodes.length)
|
|
65
|
+
return;
|
|
66
|
+
const index = nodes.indexOf(document.activeElement);
|
|
67
|
+
let next = event.key === "Home" ? 0 : event.key === "End" ? nodes.length - 1 : index + (event.key === nextKey ? 1 : -1);
|
|
68
|
+
next = loop ? (next + nodes.length) % nodes.length : Math.max(0, Math.min(nodes.length - 1, next));
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
nodes[next].focus();
|
|
71
|
+
if (select)
|
|
72
|
+
nodes[next].click();
|
|
73
|
+
}
|
|
74
|
+
function selectionEvent(callback) {
|
|
75
|
+
const event = new Event("select", { cancelable: true });
|
|
76
|
+
callback?.(event);
|
|
77
|
+
return event.defaultPrevented;
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
ButtonPart,
|
|
81
|
+
DivPart,
|
|
82
|
+
Slot,
|
|
83
|
+
focusable,
|
|
84
|
+
moveFocus,
|
|
85
|
+
selectionEvent,
|
|
86
|
+
setRef,
|
|
87
|
+
useControllable,
|
|
88
|
+
useMergedRef
|
|
89
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type ModalRootProps, type ModalContentProps } from './layer';
|
|
3
|
+
export declare const Trigger: ({ onClick, onKeyDown, onPointerEnter, onPointerLeave, onFocus, onBlur, onContextMenu, ref, disabled, ...props }: import("./core").ButtonProps) => React.JSX.Element, Close: ({ onClick, ...props }: import("./core").ButtonProps) => React.JSX.Element, Portal: ({ children, container, forceMount }: import("./layer").PortalProps) => React.ReactPortal | null, Overlay: ({ forceMount, ...props }: import("./core").DivProps & {
|
|
4
|
+
forceMount?: true;
|
|
5
|
+
}) => React.JSX.Element | null, Title: (props: React.ComponentProps<"h2">) => React.JSX.Element, Description: (props: React.ComponentProps<"p">) => React.JSX.Element;
|
|
6
|
+
export declare const Root: (props: ModalRootProps) => React.ReactElement;
|
|
7
|
+
export declare const Content: (props: ModalContentProps) => React.ReactElement | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createLayer } from "./layer.js";
|
|
2
|
+
const family = createLayer({ modal: true, floating: false });
|
|
3
|
+
const { Trigger, Close, Portal, Overlay, Title, Description } = family;
|
|
4
|
+
const Root = family.Root;
|
|
5
|
+
const Content = family.Content;
|
|
6
|
+
export {
|
|
7
|
+
Close,
|
|
8
|
+
Content,
|
|
9
|
+
Description,
|
|
10
|
+
Overlay,
|
|
11
|
+
Portal,
|
|
12
|
+
Root,
|
|
13
|
+
Title,
|
|
14
|
+
Trigger
|
|
15
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type ModalRootProps, type ModalContentProps } from './layer';
|
|
3
|
+
type Direction = 'top' | 'right' | 'bottom' | 'left';
|
|
4
|
+
interface DrawerProps extends ModalRootProps {
|
|
5
|
+
direction?: Direction;
|
|
6
|
+
dismissible?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function Root({ direction, dismissible, children, ...props }: DrawerProps): React.JSX.Element;
|
|
9
|
+
declare function Content({ onPointerDown, onPointerUp, onPointerDownOutside, onEscapeKeyDown, ...props }: ModalContentProps): React.JSX.Element;
|
|
10
|
+
export declare const Drawer: {
|
|
11
|
+
Root: typeof Root;
|
|
12
|
+
Content: typeof Content;
|
|
13
|
+
Provider: ({ children, delayDuration }: {
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
delayDuration?: number;
|
|
16
|
+
}) => React.JSX.Element;
|
|
17
|
+
Trigger: ({ onClick, onKeyDown, onPointerEnter, onPointerLeave, onFocus, onBlur, onContextMenu, ref, disabled, ...props }: import("./core").ButtonProps) => React.JSX.Element;
|
|
18
|
+
Anchor: ({ ref, ...props }: import("./core").DivProps) => React.JSX.Element;
|
|
19
|
+
Close: ({ onClick, ...props }: import("./core").ButtonProps) => React.JSX.Element;
|
|
20
|
+
Portal: ({ children, container, forceMount }: import("./layer").PortalProps) => React.ReactPortal | null;
|
|
21
|
+
Overlay: ({ forceMount, ...props }: import("./core").DivProps & {
|
|
22
|
+
forceMount?: true;
|
|
23
|
+
}) => React.JSX.Element | null;
|
|
24
|
+
Title: (props: React.ComponentProps<"h2">) => React.JSX.Element;
|
|
25
|
+
Description: (props: React.ComponentProps<"p">) => React.JSX.Element;
|
|
26
|
+
Arrow: (props: React.ComponentProps<"span">) => React.JSX.Element;
|
|
27
|
+
Sub: (props: import("./layer").LayerRootProps) => React.JSX.Element;
|
|
28
|
+
useLayer: () => import("./layer").LayerState;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { createLayer } from "./layer.js";
|
|
4
|
+
const family = createLayer({ modal: true, floating: false });
|
|
5
|
+
const Context = React.createContext({ direction: "bottom", dismissible: true });
|
|
6
|
+
function Root({ direction = "bottom", dismissible = true, children, ...props }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(family.Root, { ...props, direction, children: /* @__PURE__ */ jsx(Context.Provider, { value: { direction, dismissible }, children }) });
|
|
8
|
+
}
|
|
9
|
+
function Content({ onPointerDown, onPointerUp, onPointerDownOutside, onEscapeKeyDown, ...props }) {
|
|
10
|
+
const { direction, dismissible } = React.useContext(Context), state = family.useLayer();
|
|
11
|
+
const start = React.useRef(null);
|
|
12
|
+
return /* @__PURE__ */ jsx(family.Content, { ...props, "data-drawer-direction": direction, onPointerDownOutside: (event) => {
|
|
13
|
+
onPointerDownOutside?.(event);
|
|
14
|
+
if (!dismissible)
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
}, onEscapeKeyDown: (event) => {
|
|
17
|
+
onEscapeKeyDown?.(event);
|
|
18
|
+
if (!dismissible)
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
}, onPointerDown: (event) => {
|
|
21
|
+
onPointerDown?.(event);
|
|
22
|
+
if (event.target.closest("[data-drawer-handle]")) {
|
|
23
|
+
start.current = { x: event.clientX, y: event.clientY };
|
|
24
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
25
|
+
}
|
|
26
|
+
}, onPointerUp: (event) => {
|
|
27
|
+
onPointerUp?.(event);
|
|
28
|
+
if (!start.current)
|
|
29
|
+
return;
|
|
30
|
+
const delta = direction === "bottom" ? event.clientY - start.current.y : direction === "top" ? start.current.y - event.clientY : direction === "right" ? event.clientX - start.current.x : start.current.x - event.clientX;
|
|
31
|
+
start.current = null;
|
|
32
|
+
if (dismissible && delta > 60)
|
|
33
|
+
state.setOpen(false);
|
|
34
|
+
} });
|
|
35
|
+
}
|
|
36
|
+
const Drawer = { ...family, Root, Content };
|
|
37
|
+
export {
|
|
38
|
+
Drawer
|
|
39
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const Root: (props: import("./layer").ModalRootProps) => React.ReactElement, Trigger: ({ onContextMenu, ref, disabled, ...props }: import("./core").ButtonProps) => import("react").JSX.Element, Portal: ({ children, container, forceMount }: import("./layer").PortalProps) => import("react").ReactPortal | null, Content: ({ onKeyDown, loop, ...props }: import("./layer").LayerContentProps & {
|
|
2
|
+
loop?: boolean;
|
|
3
|
+
}) => import("react").JSX.Element, Group: (props: import("./core").DivProps) => import("react").JSX.Element, Label: (props: import("./core").DivProps) => import("react").JSX.Element, Item: ({ onSelect, textValue: _text, onClick, onPointerMove, ...props }: Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
4
|
+
onSelect?: (event: Event) => void;
|
|
5
|
+
textValue?: string;
|
|
6
|
+
}) => import("react").JSX.Element, CheckboxItem: ({ checked, defaultChecked, onCheckedChange, children, onSelect, ...props }: (Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
7
|
+
onSelect?: (event: Event) => void;
|
|
8
|
+
textValue?: string;
|
|
9
|
+
}) & {
|
|
10
|
+
checked?: boolean | "indeterminate";
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
13
|
+
}) => import("react").JSX.Element, RadioGroup: ({ value, defaultValue, onValueChange, ...props }: Omit<import("./core").DivProps, "defaultValue"> & {
|
|
14
|
+
value?: string;
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
onValueChange?: (value: string) => void;
|
|
17
|
+
}) => import("react").JSX.Element, RadioItem: ({ value, children, onSelect, ...props }: (Omit<import("./core").ButtonProps, "onSelect"> & {
|
|
18
|
+
onSelect?: (event: Event) => void;
|
|
19
|
+
textValue?: string;
|
|
20
|
+
}) & {
|
|
21
|
+
value: string;
|
|
22
|
+
}) => import("react").JSX.Element, Separator: (props: import("./core").DivProps) => import("react").JSX.Element, ItemIndicator: ({ forceMount, ...props }: React.ComponentProps<"span"> & {
|
|
23
|
+
forceMount?: true;
|
|
24
|
+
}) => import("react").JSX.Element | null, Sub: (props: import("./layer").ModalRootProps) => React.ReactElement, SubTrigger: ({ onClick, onPointerEnter, onKeyDown, ref, ...props }: import("./core").ButtonProps) => import("react").JSX.Element, SubContent: ({ onKeyDown, ...props }: import("./layer").LayerContentProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMenu } from "./menu.js";
|
|
2
|
+
const { Root, Trigger, Portal, Content, Group, Label, Item, CheckboxItem, RadioGroup, RadioItem, Separator, ItemIndicator, Sub, SubTrigger, SubContent } = createMenu();
|
|
3
|
+
export {
|
|
4
|
+
CheckboxItem,
|
|
5
|
+
Content,
|
|
6
|
+
Group,
|
|
7
|
+
Item,
|
|
8
|
+
ItemIndicator,
|
|
9
|
+
Label,
|
|
10
|
+
Portal,
|
|
11
|
+
RadioGroup,
|
|
12
|
+
RadioItem,
|
|
13
|
+
Root,
|
|
14
|
+
Separator,
|
|
15
|
+
Sub,
|
|
16
|
+
SubContent,
|
|
17
|
+
SubTrigger,
|
|
18
|
+
Trigger
|
|
19
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type FieldValues = Record<string, any>;
|
|
3
|
+
export type FieldPath<T extends FieldValues> = Extract<keyof T, string>;
|
|
4
|
+
export interface FieldError {
|
|
5
|
+
type: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ValidationRules<V = unknown> {
|
|
9
|
+
required?: boolean | string;
|
|
10
|
+
min?: number | {
|
|
11
|
+
value: number;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
max?: number | {
|
|
15
|
+
value: number;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
minLength?: number | {
|
|
19
|
+
value: number;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
maxLength?: number | {
|
|
23
|
+
value: number;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
pattern?: RegExp | {
|
|
27
|
+
value: RegExp;
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
validate?: (value: V) => boolean | string | Promise<boolean | string>;
|
|
31
|
+
}
|
|
32
|
+
interface FormSnapshot<T> {
|
|
33
|
+
values: T;
|
|
34
|
+
errors: Partial<Record<keyof T, FieldError>>;
|
|
35
|
+
touchedFields: Partial<Record<keyof T, boolean>>;
|
|
36
|
+
dirtyFields: Partial<Record<keyof T, boolean>>;
|
|
37
|
+
isSubmitting: boolean;
|
|
38
|
+
isSubmitted: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface FormControl<T extends FieldValues> {
|
|
41
|
+
snapshot: FormSnapshot<T>;
|
|
42
|
+
subscribe: (callback: () => void) => () => void;
|
|
43
|
+
rules: Map<string, ValidationRules<any>>;
|
|
44
|
+
refs: Map<string, HTMLElement>;
|
|
45
|
+
setValue: <K extends FieldPath<T>>(name: K, value: T[K], options?: {
|
|
46
|
+
shouldValidate?: boolean;
|
|
47
|
+
shouldTouch?: boolean;
|
|
48
|
+
shouldDirty?: boolean;
|
|
49
|
+
}) => void;
|
|
50
|
+
touch: (name: FieldPath<T>) => void;
|
|
51
|
+
validate: (names?: FieldPath<T>[]) => Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
export interface UseFormOptions<T extends FieldValues> {
|
|
54
|
+
defaultValues?: Partial<T>;
|
|
55
|
+
mode?: 'onSubmit' | 'onChange' | 'onBlur';
|
|
56
|
+
}
|
|
57
|
+
export declare function useForm<T extends FieldValues = FieldValues>({ defaultValues, mode }?: UseFormOptions<T>): {
|
|
58
|
+
control: FormControl<T>;
|
|
59
|
+
formState: {
|
|
60
|
+
isDirty: boolean;
|
|
61
|
+
isValid: boolean;
|
|
62
|
+
values: T;
|
|
63
|
+
errors: Partial<Record<keyof T, FieldError>>;
|
|
64
|
+
touchedFields: Partial<Record<keyof T, boolean>>;
|
|
65
|
+
dirtyFields: Partial<Record<keyof T, boolean>>;
|
|
66
|
+
isSubmitting: boolean;
|
|
67
|
+
isSubmitted: boolean;
|
|
68
|
+
};
|
|
69
|
+
getFieldState: (name: FieldPath<T>, state?: FormSnapshot<T>) => {
|
|
70
|
+
error: Partial<Record<keyof T, FieldError>>[Extract<keyof T, string>];
|
|
71
|
+
invalid: boolean;
|
|
72
|
+
isTouched: boolean;
|
|
73
|
+
isDirty: boolean;
|
|
74
|
+
};
|
|
75
|
+
getValues: () => T;
|
|
76
|
+
setValue: <K extends Extract<keyof T, string>>(name: K, value: T[K], options?: {
|
|
77
|
+
shouldValidate?: boolean;
|
|
78
|
+
shouldTouch?: boolean;
|
|
79
|
+
shouldDirty?: boolean;
|
|
80
|
+
}) => void;
|
|
81
|
+
trigger: (name?: FieldPath<T>) => Promise<boolean>;
|
|
82
|
+
reset(values?: Partial<T>): void;
|
|
83
|
+
setFocus(name: FieldPath<T>): void;
|
|
84
|
+
handleSubmit(onValid: (values: T) => unknown | Promise<unknown>, onInvalid?: (errors: FormSnapshot<T>["errors"]) => unknown): (event?: React.FormEvent) => Promise<void>;
|
|
85
|
+
};
|
|
86
|
+
export type UseFormReturn<T extends FieldValues> = ReturnType<typeof useForm<T>>;
|
|
87
|
+
export declare function FormProvider<T extends FieldValues>({ children, ...form }: UseFormReturn<T> & {
|
|
88
|
+
children?: React.ReactNode;
|
|
89
|
+
}): React.JSX.Element;
|
|
90
|
+
export declare function useFormContext(): {
|
|
91
|
+
control: FormControl<FieldValues>;
|
|
92
|
+
formState: {
|
|
93
|
+
isDirty: boolean;
|
|
94
|
+
isValid: boolean;
|
|
95
|
+
values: FieldValues;
|
|
96
|
+
errors: Partial<Record<string, FieldError>>;
|
|
97
|
+
touchedFields: Partial<Record<string, boolean>>;
|
|
98
|
+
dirtyFields: Partial<Record<string, boolean>>;
|
|
99
|
+
isSubmitting: boolean;
|
|
100
|
+
isSubmitted: boolean;
|
|
101
|
+
};
|
|
102
|
+
getFieldState: (name: string, state?: FormSnapshot<FieldValues>) => {
|
|
103
|
+
error: FieldError | undefined;
|
|
104
|
+
invalid: boolean;
|
|
105
|
+
isTouched: boolean;
|
|
106
|
+
isDirty: boolean;
|
|
107
|
+
};
|
|
108
|
+
getValues: () => FieldValues;
|
|
109
|
+
setValue: <K extends string>(name: K, value: any, options?: {
|
|
110
|
+
shouldValidate?: boolean;
|
|
111
|
+
shouldTouch?: boolean;
|
|
112
|
+
shouldDirty?: boolean;
|
|
113
|
+
}) => void;
|
|
114
|
+
trigger: (name?: string | undefined) => Promise<boolean>;
|
|
115
|
+
reset(values?: Partial<FieldValues>): void;
|
|
116
|
+
setFocus(name: string): void;
|
|
117
|
+
handleSubmit(onValid: (values: FieldValues) => unknown | Promise<unknown>, onInvalid?: ((errors: Partial<Record<string, FieldError>>) => unknown) | undefined): (event?: React.FormEvent) => Promise<void>;
|
|
118
|
+
};
|
|
119
|
+
export declare function useFormState(_options?: {
|
|
120
|
+
name?: string;
|
|
121
|
+
}): {
|
|
122
|
+
isDirty: boolean;
|
|
123
|
+
isValid: boolean;
|
|
124
|
+
values: FieldValues;
|
|
125
|
+
errors: Partial<Record<string, FieldError>>;
|
|
126
|
+
touchedFields: Partial<Record<string, boolean>>;
|
|
127
|
+
dirtyFields: Partial<Record<string, boolean>>;
|
|
128
|
+
isSubmitting: boolean;
|
|
129
|
+
isSubmitted: boolean;
|
|
130
|
+
};
|
|
131
|
+
export interface ControllerProps<T extends FieldValues = FieldValues, K extends FieldPath<T> = FieldPath<T>> {
|
|
132
|
+
name: K;
|
|
133
|
+
control: FormControl<T>;
|
|
134
|
+
rules?: ValidationRules<T[K]>;
|
|
135
|
+
defaultValue?: T[K];
|
|
136
|
+
disabled?: boolean;
|
|
137
|
+
render: (props: {
|
|
138
|
+
field: {
|
|
139
|
+
name: K;
|
|
140
|
+
value: T[K];
|
|
141
|
+
onChange: (event: any) => void;
|
|
142
|
+
onBlur: () => void;
|
|
143
|
+
ref: (element: HTMLElement | null) => void;
|
|
144
|
+
disabled?: boolean;
|
|
145
|
+
};
|
|
146
|
+
fieldState: {
|
|
147
|
+
error?: FieldError;
|
|
148
|
+
invalid: boolean;
|
|
149
|
+
};
|
|
150
|
+
formState: FormSnapshot<T>;
|
|
151
|
+
}) => React.ReactElement;
|
|
152
|
+
}
|
|
153
|
+
export declare function Controller<T extends FieldValues, K extends FieldPath<T>>({ name, control, rules, defaultValue, disabled, render }: ControllerProps<T, K>): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
154
|
+
export {};
|