seam-react 0.12.2 → 0.12.4
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 +2 -1
- package/dist/CheckBox.d.ts +0 -6
- package/dist/FormComponent.d.ts +171 -0
- package/dist/Select.d.ts +2 -2
- package/dist/Switch.d.ts +0 -6
- package/dist/control-contract.d.ts +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8664 -7976
- package/dist/index.js.map +1 -1
- package/dist/styles.cjs +114 -0
- package/dist/styles.cjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.js +114 -0
- package/dist/styles.js.map +1 -1
- package/dist/valibot.cjs +2 -0
- package/dist/valibot.cjs.map +1 -0
- package/dist/valibot.d.ts +13 -0
- package/dist/valibot.js +19 -0
- package/dist/valibot.js.map +1 -0
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -35,13 +35,14 @@ export function Root() {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
组件包含:Button、Input、Switch、Tabs、Dialog、Toast、Tooltip、Sidebar。
|
|
38
|
+
组件包含:Button、Input、Form、Switch、Tabs、Dialog、Toast、Tooltip、Sidebar。
|
|
39
39
|
|
|
40
40
|
- Tabs 支持方向键切换、ARIA 关联与 fluid 指示器。
|
|
41
41
|
- Switch 支持点击、键盘和拖拽 spring。
|
|
42
42
|
- Dialog 提供 Root / Trigger / Content 与语义化内容层,自带 Motion 进出场、焦点陷阱、Esc 关闭与滚动锁定。
|
|
43
43
|
- Toast 提供 `useToast` 状态队列与 `ToastStack` 呈现层,支持六向定位、自动关闭、状态图标、操作和拖拽关闭。
|
|
44
44
|
- Tooltip 提供延迟显示、键盘与触屏访问、视口翻转/避让,以及可让相邻触发器共享并连续移动表面的 Group / Item 组合。
|
|
45
|
+
- Form 提供组合式字段、同步/异步规则、服务端错误和失败聚焦;安装 `valibot` 后可通过 `seam-react/valibot` 接入 schema 校验。
|
|
45
46
|
- Sidebar 提供可折叠 Group、可配置分组间距,以及互斥的轨道与背景 hover 模式。
|
|
46
47
|
|
|
47
48
|
完整文档:[chenhaojie9527.github.io/ui-kit](https://chenhaojie9527.github.io/ui-kit/)
|
package/dist/CheckBox.d.ts
CHANGED
|
@@ -9,10 +9,4 @@ export interface CheckBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement
|
|
|
9
9
|
/** 显示在复选框右侧的标签文本。 */
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* 复选框。
|
|
14
|
-
*
|
|
15
|
-
* 保留原生 checkbox 的表单、键盘和读屏语义;方框内的对勾用 SVG 描边
|
|
16
|
-
* 展示状态转换,按压时的轻微缩放提供即时的触觉反馈。
|
|
17
|
-
*/
|
|
18
12
|
export declare const CheckBox: ForwardRefExoticComponent<CheckBoxProps & RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type FormHTMLAttributes, type HTMLAttributes, type LabelHTMLAttributes, type ReactElement, type ReactNode, type Ref } from "react";
|
|
2
|
+
export type FormErrors<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
3
|
+
[K in keyof T]?: string;
|
|
4
|
+
} & Record<string, string | undefined>;
|
|
5
|
+
export type FieldRule<T = unknown> = {
|
|
6
|
+
required: boolean;
|
|
7
|
+
message?: string;
|
|
8
|
+
} | {
|
|
9
|
+
minLength: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
} | {
|
|
12
|
+
maxLength: number;
|
|
13
|
+
message?: string;
|
|
14
|
+
} | {
|
|
15
|
+
pattern: RegExp;
|
|
16
|
+
message?: string;
|
|
17
|
+
} | {
|
|
18
|
+
min: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
} | {
|
|
21
|
+
max: number;
|
|
22
|
+
message?: string;
|
|
23
|
+
} | {
|
|
24
|
+
enum: T[];
|
|
25
|
+
message?: string;
|
|
26
|
+
} | {
|
|
27
|
+
validator: (value: T, values: Record<string, unknown>) => string | null | Promise<string | null>;
|
|
28
|
+
};
|
|
29
|
+
export interface FieldState {
|
|
30
|
+
value: unknown;
|
|
31
|
+
initialValue: unknown;
|
|
32
|
+
dirty: boolean;
|
|
33
|
+
touched: boolean;
|
|
34
|
+
focused: boolean;
|
|
35
|
+
validating: boolean;
|
|
36
|
+
invalid: boolean;
|
|
37
|
+
valid: boolean;
|
|
38
|
+
required: boolean;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
readOnly: boolean;
|
|
41
|
+
hidden: boolean;
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface FormState {
|
|
45
|
+
submitting: boolean;
|
|
46
|
+
submitted: boolean;
|
|
47
|
+
submitSucceeded: boolean;
|
|
48
|
+
submitFailed: boolean;
|
|
49
|
+
dirty: boolean;
|
|
50
|
+
validating: boolean;
|
|
51
|
+
errors: Record<string, string>;
|
|
52
|
+
formError: string | null;
|
|
53
|
+
}
|
|
54
|
+
export interface FormRef<T = Record<string, unknown>> {
|
|
55
|
+
getValues: () => T;
|
|
56
|
+
getValue: (name: string) => unknown;
|
|
57
|
+
setValue: (name: string, value: unknown, options?: {
|
|
58
|
+
validate?: boolean;
|
|
59
|
+
touch?: boolean;
|
|
60
|
+
}) => void;
|
|
61
|
+
setValues: (values: Partial<T>, options?: {
|
|
62
|
+
validate?: boolean;
|
|
63
|
+
}) => void;
|
|
64
|
+
reset: (values?: Partial<T>) => void;
|
|
65
|
+
clear: () => void;
|
|
66
|
+
validate: (fields?: string[]) => Promise<boolean>;
|
|
67
|
+
setError: (name: string, error: string) => void;
|
|
68
|
+
setFormError: (error: string | null) => void;
|
|
69
|
+
clearErrors: (fields?: string[]) => void;
|
|
70
|
+
focusFirstError: () => void;
|
|
71
|
+
}
|
|
72
|
+
export interface FormContextValue<T = Record<string, unknown>> {
|
|
73
|
+
values: T;
|
|
74
|
+
state: FormState;
|
|
75
|
+
getFieldState: (name: string) => FieldState;
|
|
76
|
+
setValue: (name: string, value: unknown, options?: {
|
|
77
|
+
validate?: boolean;
|
|
78
|
+
touch?: boolean;
|
|
79
|
+
}) => void;
|
|
80
|
+
setFieldTouched: (name: string, touched: boolean) => void;
|
|
81
|
+
setFieldFocused: (name: string, focused: boolean) => void;
|
|
82
|
+
registerField: (name: string, config: FieldConfig) => void;
|
|
83
|
+
unregisterField: (name: string) => void;
|
|
84
|
+
validateField: (name: string) => Promise<boolean>;
|
|
85
|
+
validateForm: () => Promise<boolean>;
|
|
86
|
+
submit: () => Promise<void>;
|
|
87
|
+
reset: (values?: Partial<T>) => void;
|
|
88
|
+
clear: () => void;
|
|
89
|
+
setError: (name: string, error: string) => void;
|
|
90
|
+
setFormError: (error: string | null) => void;
|
|
91
|
+
clearErrors: (fields?: string[]) => void;
|
|
92
|
+
focusFirstError: () => void;
|
|
93
|
+
validateOn: "submit" | "blur" | "change";
|
|
94
|
+
revalidateOn: "change" | "blur";
|
|
95
|
+
validateDebounce: number;
|
|
96
|
+
}
|
|
97
|
+
interface FieldConfig {
|
|
98
|
+
rules?: FieldRule[];
|
|
99
|
+
transform?: (value: unknown) => unknown;
|
|
100
|
+
dependencies?: string[];
|
|
101
|
+
preserveOnUnmount?: boolean;
|
|
102
|
+
defaultValue?: unknown;
|
|
103
|
+
disabled?: boolean;
|
|
104
|
+
readOnly?: boolean;
|
|
105
|
+
hidden?: boolean;
|
|
106
|
+
}
|
|
107
|
+
export interface FormRootProps<T extends Record<string, unknown> = Record<string, unknown>> extends Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "onChange"> {
|
|
108
|
+
values?: T;
|
|
109
|
+
defaultValues?: Partial<T>;
|
|
110
|
+
onValuesChange?: (values: T, changedField?: keyof T) => void;
|
|
111
|
+
onSubmit?: (values: T) => void | Promise<void>;
|
|
112
|
+
onSubmitFailed?: (errors: FormErrors<T>) => void;
|
|
113
|
+
validateOn?: "submit" | "blur" | "change";
|
|
114
|
+
revalidateOn?: "change" | "blur";
|
|
115
|
+
validateDebounce?: number;
|
|
116
|
+
noValidate?: boolean;
|
|
117
|
+
validate?: (values: T) => FormErrors<T> | Promise<FormErrors<T>>;
|
|
118
|
+
children: ReactNode;
|
|
119
|
+
}
|
|
120
|
+
export interface FormFieldProps<T = unknown> {
|
|
121
|
+
name: string;
|
|
122
|
+
defaultValue?: T;
|
|
123
|
+
rules?: FieldRule<T>[];
|
|
124
|
+
transform?: (value: T) => T;
|
|
125
|
+
disabled?: boolean;
|
|
126
|
+
readOnly?: boolean;
|
|
127
|
+
hidden?: boolean;
|
|
128
|
+
preserveOnUnmount?: boolean;
|
|
129
|
+
dependencies?: string[];
|
|
130
|
+
children: ReactNode;
|
|
131
|
+
className?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface FormLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
134
|
+
required?: boolean;
|
|
135
|
+
children: ReactNode;
|
|
136
|
+
}
|
|
137
|
+
export interface FormControlProps {
|
|
138
|
+
children: ReactElement;
|
|
139
|
+
}
|
|
140
|
+
export interface FormDescriptionProps extends HTMLAttributes<HTMLParagraphElement> {
|
|
141
|
+
children: ReactNode;
|
|
142
|
+
}
|
|
143
|
+
export interface FormErrorMessageProps extends Omit<HTMLAttributes<HTMLParagraphElement>, "children"> {
|
|
144
|
+
children?: (error: string) => ReactNode;
|
|
145
|
+
}
|
|
146
|
+
export interface FormActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
147
|
+
children: ReactNode;
|
|
148
|
+
}
|
|
149
|
+
export declare function useFormContext<T = Record<string, unknown>>(): FormContextValue<T>;
|
|
150
|
+
export declare function useFieldState(name: string): FieldState;
|
|
151
|
+
export declare function useWatch<T = unknown>(name: string | string[]): T;
|
|
152
|
+
declare const FormRoot: <T extends Record<string, unknown> = Record<string, unknown>>(props: FormRootProps<T> & {
|
|
153
|
+
ref?: Ref<FormRef>;
|
|
154
|
+
}) => ReactElement | null;
|
|
155
|
+
declare function FormField({ name, defaultValue, rules, transform, disabled, readOnly, hidden, preserveOnUnmount, dependencies, children, className, }: FormFieldProps): ReactElement | null;
|
|
156
|
+
declare const FormLabel: import("react").ForwardRefExoticComponent<FormLabelProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
157
|
+
declare function FormControl({ children }: FormControlProps): ReactElement;
|
|
158
|
+
declare const FormDescription: import("react").ForwardRefExoticComponent<FormDescriptionProps & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
159
|
+
declare const FormErrorMessage: import("react").ForwardRefExoticComponent<FormErrorMessageProps & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
160
|
+
declare const FormActions: import("react").ForwardRefExoticComponent<FormActionsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
161
|
+
export interface FormComponent {
|
|
162
|
+
Root: typeof FormRoot;
|
|
163
|
+
Field: typeof FormField;
|
|
164
|
+
Label: typeof FormLabel;
|
|
165
|
+
Control: typeof FormControl;
|
|
166
|
+
Description: typeof FormDescription;
|
|
167
|
+
ErrorMessage: typeof FormErrorMessage;
|
|
168
|
+
Actions: typeof FormActions;
|
|
169
|
+
}
|
|
170
|
+
export declare const Form: FormComponent;
|
|
171
|
+
export {};
|
package/dist/Select.d.ts
CHANGED
|
@@ -53,8 +53,8 @@ export type SelectProps<Multiple extends boolean = false> = SelectBaseProps & (M
|
|
|
53
53
|
defaultValue?: string | null;
|
|
54
54
|
onValueChange?: (value: string) => void;
|
|
55
55
|
});
|
|
56
|
-
declare const Select: {
|
|
56
|
+
export declare const Select: {
|
|
57
57
|
(props: SelectSingleProps & RefAttributes<HTMLDivElement>): ReactElement | null;
|
|
58
58
|
(props: SelectMultipleProps & RefAttributes<HTMLDivElement>): ReactElement | null;
|
|
59
59
|
};
|
|
60
|
-
export {
|
|
60
|
+
export {};
|
package/dist/Switch.d.ts
CHANGED
|
@@ -9,10 +9,4 @@ export interface SwitchProps extends Omit<InputHTMLAttributes<HTMLInputElement>,
|
|
|
9
9
|
/** 显示在开关右侧的标签文本。 */
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* 开关。
|
|
14
|
-
*
|
|
15
|
-
* 底层是原生 checkbox(role="switch"),所以表单提交、键盘操作和
|
|
16
|
-
* 屏幕阅读器语义都是免费的;视觉部分由 track / thumb 两个 span 承担。
|
|
17
|
-
*/
|
|
18
12
|
export declare const Switch: ForwardRefExoticComponent<SwitchProps & RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const CONTROL_KIND: "__seamControlKind";
|
|
2
|
+
export type ControlKind = "boolean" | "value";
|
|
3
|
+
export declare function markControl<T extends object>(component: T, kind: ControlKind): T;
|
|
4
|
+
export declare function getControlKind(component: unknown): ControlKind | undefined;
|