seam-react 0.12.2 → 0.12.3
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/CheckBox.d.ts +0 -6
- package/dist/FormComponent.d.ts +169 -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/package.json +1 -1
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,169 @@
|
|
|
1
|
+
import { type FormHTMLAttributes, type HTMLAttributes, type LabelHTMLAttributes, type ReactElement, type ReactNode } 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: import("react").ForwardRefExoticComponent<FormRootProps<Record<string, unknown>> & import("react").RefAttributes<FormRef<Record<string, unknown>>>>;
|
|
153
|
+
declare function FormField({ name, defaultValue, rules, transform, disabled, readOnly, hidden, preserveOnUnmount, dependencies, children, className, }: FormFieldProps): ReactElement | null;
|
|
154
|
+
declare const FormLabel: import("react").ForwardRefExoticComponent<FormLabelProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
155
|
+
declare function FormControl({ children }: FormControlProps): ReactElement;
|
|
156
|
+
declare const FormDescription: import("react").ForwardRefExoticComponent<FormDescriptionProps & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
157
|
+
declare const FormErrorMessage: import("react").ForwardRefExoticComponent<FormErrorMessageProps & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
158
|
+
declare const FormActions: import("react").ForwardRefExoticComponent<FormActionsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
159
|
+
export interface FormComponent {
|
|
160
|
+
Root: typeof FormRoot;
|
|
161
|
+
Field: typeof FormField;
|
|
162
|
+
Label: typeof FormLabel;
|
|
163
|
+
Control: typeof FormControl;
|
|
164
|
+
Description: typeof FormDescription;
|
|
165
|
+
ErrorMessage: typeof FormErrorMessage;
|
|
166
|
+
Actions: typeof FormActions;
|
|
167
|
+
}
|
|
168
|
+
export declare const Form: FormComponent;
|
|
169
|
+
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;
|