@lite-code/aui-react 0.0.1

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.
Files changed (83) hide show
  1. package/README.md +76 -0
  2. package/dist/alert/index.d.ts +14 -0
  3. package/dist/avatar/index.d.ts +28 -0
  4. package/dist/badge/index.d.ts +18 -0
  5. package/dist/breadcrumb/index.d.ts +18 -0
  6. package/dist/button/index.d.ts +11 -0
  7. package/dist/card/index.d.ts +25 -0
  8. package/dist/carousel/index.d.ts +17 -0
  9. package/dist/cascader/index.d.ts +25 -0
  10. package/dist/checkbox/index.d.ts +33 -0
  11. package/dist/collapse/index.d.ts +19 -0
  12. package/dist/datepicker/index.d.ts +26 -0
  13. package/dist/descriptions/index.d.ts +25 -0
  14. package/dist/drawer/index.d.ts +16 -0
  15. package/dist/dropdown/index.d.ts +29 -0
  16. package/dist/empty/index.d.ts +11 -0
  17. package/dist/form/context.d.ts +3 -0
  18. package/dist/form/index.d.ts +39 -0
  19. package/dist/form/item.d.ts +87 -0
  20. package/dist/form/list.d.ts +8 -0
  21. package/dist/form/store.d.ts +49 -0
  22. package/dist/form/types.d.ts +47 -0
  23. package/dist/grid/index.d.ts +35 -0
  24. package/dist/icon/index.d.ts +9 -0
  25. package/dist/image-compressor/engine.d.ts +55 -0
  26. package/dist/image-compressor/index.d.ts +5 -0
  27. package/dist/image-compressor/types.d.ts +44 -0
  28. package/dist/image-compressor/use-image-compressor.d.ts +21 -0
  29. package/dist/index.cjs.js +2 -0
  30. package/dist/index.cjs.js.map +1 -0
  31. package/dist/index.d.ts +93 -0
  32. package/dist/index.esm.js +2 -0
  33. package/dist/index.esm.js.map +1 -0
  34. package/dist/input/index.d.ts +12 -0
  35. package/dist/input-number/index.d.ts +23 -0
  36. package/dist/layer/index.d.ts +18 -0
  37. package/dist/menu/index.d.ts +24 -0
  38. package/dist/message/index.d.ts +18 -0
  39. package/dist/modal/index.d.ts +42 -0
  40. package/dist/pagination/index.d.ts +19 -0
  41. package/dist/popover/index.d.ts +18 -0
  42. package/dist/popover/util.d.ts +28 -0
  43. package/dist/progress/index.d.ts +17 -0
  44. package/dist/radio/index.d.ts +32 -0
  45. package/dist/rate/index.d.ts +20 -0
  46. package/dist/select/index.d.ts +23 -0
  47. package/dist/slider/index.d.ts +19 -0
  48. package/dist/space/index.d.ts +11 -0
  49. package/dist/spin/index.d.ts +12 -0
  50. package/dist/steps/index.d.ts +25 -0
  51. package/dist/switch/index.d.ts +18 -0
  52. package/dist/table/checkbox.d.ts +14 -0
  53. package/dist/table/empty.d.ts +5 -0
  54. package/dist/table/index.d.ts +2 -0
  55. package/dist/table/row-operation-cell.d.ts +9 -0
  56. package/dist/table/table.d.ts +3 -0
  57. package/dist/table/toolbar.d.ts +12 -0
  58. package/dist/table/types.d.ts +84 -0
  59. package/dist/table/utils.d.ts +19 -0
  60. package/dist/tabs/index.d.ts +22 -0
  61. package/dist/textarea/index.d.ts +10 -0
  62. package/dist/theme/theme-provider.d.ts +21 -0
  63. package/dist/timepicker/index.d.ts +12 -0
  64. package/dist/timepicker/scroll-column.d.ts +13 -0
  65. package/dist/timepicker/types.d.ts +43 -0
  66. package/dist/timepicker/utils.d.ts +13 -0
  67. package/dist/tooltip/index.d.ts +19 -0
  68. package/dist/tree/index.d.ts +29 -0
  69. package/dist/tree-select/index.d.ts +21 -0
  70. package/dist/upload/file-item.d.ts +10 -0
  71. package/dist/upload/index.d.ts +12 -0
  72. package/dist/upload/types.d.ts +58 -0
  73. package/dist/upload/use-upload.d.ts +6 -0
  74. package/dist/upload/utils.d.ts +5 -0
  75. package/dist/upload-manager/index.d.ts +10 -0
  76. package/dist/upload-manager/manager-item.d.ts +10 -0
  77. package/dist/upload-manager/preview-modal.d.ts +10 -0
  78. package/dist/upload-manager/types.d.ts +80 -0
  79. package/dist/upload-manager/use-upload-manager.d.ts +19 -0
  80. package/env.d.ts +2 -0
  81. package/package.json +47 -0
  82. package/rollup.config.js +36 -0
  83. package/tsconfig.tsbuildinfo +1 -0
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # 快速上手
2
+
3
+ ## 安装
4
+
5
+ ```bash
6
+ npm install @lite-code/aui-react
7
+ # 或
8
+ pnpm add @lite-code/aui-react
9
+ ```
10
+
11
+ ## 基础使用
12
+
13
+ > 样式已内置于组件中,无需额外引入 CSS 文件。
14
+
15
+ ```tsx
16
+ import { Button, Input } from '@lite-code/aui-react'
17
+
18
+ export default function App() {
19
+ return (
20
+ <div>
21
+ <Button variant="primary">点击我</Button>
22
+ <Input placeholder="请输入内容" />
23
+ </div>
24
+ )
25
+ }
26
+ ```
27
+
28
+ ## 主题切换
29
+
30
+ 使用 `ThemeProvider` 管理全局主题:
31
+
32
+ ```tsx
33
+ import { ThemeProvider } from '@lite-code/aui-react'
34
+
35
+ export default function App() {
36
+ return (
37
+ <ThemeProvider defaultTheme="dark" defaultAccentColor="#6366f1">
38
+ <YourApp />
39
+ </ThemeProvider>
40
+ )
41
+ }
42
+ ```
43
+
44
+ 在子组件中使用 `useTheme` Hook:
45
+
46
+ ```tsx
47
+ import { useTheme } from '@lite-code/aui-react'
48
+
49
+ function MyComponent() {
50
+ const { theme, setTheme, accentColor, setAccentColor } = useTheme()
51
+
52
+ return (
53
+ <button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
54
+ 切换为 {theme === 'dark' ? '亮色' : '暗色'} 主题
55
+ </button>
56
+ )
57
+ }
58
+ ```
59
+
60
+ ## 高亮色预设
61
+
62
+ ```tsx
63
+ import { ACCENT_PRESETS } from '@lite-code/aui-react'
64
+
65
+ // ACCENT_PRESETS 包含 Indigo / Violet / Sky / Emerald / Rose / Amber
66
+ ```
67
+
68
+ ## 自定义主题色
69
+
70
+ 通过修改 CSS 变量可全局覆盖主题色:
71
+
72
+ ```css
73
+ :root {
74
+ --aui-accent: #your-color;
75
+ }
76
+ ```
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import "./alert.css";
3
+ export type AlertType = "info" | "success" | "warning" | "danger";
4
+ export interface AlertProps {
5
+ type?: AlertType;
6
+ message: React.ReactNode;
7
+ description?: React.ReactNode;
8
+ closable?: boolean;
9
+ showIcon?: boolean;
10
+ onClose?: () => void;
11
+ className?: string;
12
+ style?: React.CSSProperties;
13
+ }
14
+ export declare function Alert({ type, message, description, closable, showIcon, onClose, className, style, }: AlertProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import "./avatar.css";
3
+ export type AvatarShape = "circle" | "square";
4
+ export type AvatarSize = "sm" | "md" | "lg" | number;
5
+ export interface AvatarProps {
6
+ src?: string;
7
+ alt?: string;
8
+ icon?: React.ReactNode;
9
+ children?: React.ReactNode;
10
+ shape?: AvatarShape;
11
+ size?: AvatarSize;
12
+ color?: string;
13
+ background?: string;
14
+ gap?: number;
15
+ className?: string;
16
+ style?: React.CSSProperties;
17
+ }
18
+ export interface AvatarGroupProps {
19
+ children: React.ReactNode;
20
+ max?: number;
21
+ renderMax?: (count: number) => React.ReactNode;
22
+ size?: AvatarSize;
23
+ shape?: AvatarShape;
24
+ className?: string;
25
+ style?: React.CSSProperties;
26
+ }
27
+ export declare function Avatar({ src, alt, icon, children, shape, size, color, background, gap, className, style, }: AvatarProps): import("react/jsx-runtime").JSX.Element;
28
+ export declare function AvatarGroup({ children, max, renderMax, size, shape, className, style, }: AvatarGroupProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import "./badge.css";
3
+ export type BadgeStatus = "default" | "processing" | "error" | "warning" | "success";
4
+ export type BadgeSize = "default" | "small";
5
+ export interface BadgeProps {
6
+ count?: number;
7
+ overflowCount?: number;
8
+ dot?: boolean;
9
+ status?: BadgeStatus;
10
+ text?: React.ReactNode;
11
+ size?: BadgeSize;
12
+ showZero?: boolean;
13
+ offset?: [number, number];
14
+ children?: React.ReactNode;
15
+ className?: string;
16
+ style?: React.CSSProperties;
17
+ }
18
+ export declare function Badge({ count, overflowCount, dot, status, text, size, showZero, offset, children, className, style, }: BadgeProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import type { DropdownItem } from "../dropdown";
3
+ import "./breadcrumb.css";
4
+ export interface BreadcrumbItem {
5
+ label: React.ReactNode;
6
+ href?: string;
7
+ onClick?: (e: React.MouseEvent) => void;
8
+ menu?: DropdownItem[];
9
+ }
10
+ export interface BreadcrumbProps {
11
+ items: BreadcrumbItem[];
12
+ separator?: React.ReactNode;
13
+ fontSize?: number | string;
14
+ max?: number;
15
+ className?: string;
16
+ style?: React.CSSProperties;
17
+ }
18
+ export declare function Breadcrumb({ items, separator, fontSize, max, className, style, }: BreadcrumbProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import "./button.css";
3
+ export type ButtonVariant = "primary" | "secondary" | "outline" | "ghost";
4
+ export type ButtonSize = "sm" | "md" | "lg";
5
+ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
6
+ variant?: ButtonVariant;
7
+ size?: ButtonSize;
8
+ loading?: boolean;
9
+ children?: React.ReactNode;
10
+ }
11
+ export declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import "./card.css";
3
+ export type CardSize = "sm" | "md" | "lg";
4
+ export type CardShadow = "always" | "hover" | "never";
5
+ export interface CardProps {
6
+ title?: React.ReactNode;
7
+ extra?: React.ReactNode;
8
+ cover?: React.ReactNode;
9
+ footer?: React.ReactNode;
10
+ children?: React.ReactNode;
11
+ collapsible?: boolean;
12
+ defaultCollapsed?: boolean;
13
+ collapsed?: boolean;
14
+ onCollapseChange?: (collapsed: boolean) => void;
15
+ bordered?: boolean;
16
+ shadow?: CardShadow;
17
+ loading?: boolean;
18
+ size?: CardSize;
19
+ /** 右侧流光彩线动画 */
20
+ shimmer?: boolean;
21
+ className?: string;
22
+ style?: React.CSSProperties;
23
+ bodyStyle?: React.CSSProperties;
24
+ }
25
+ export declare function Card({ title, extra, cover, footer, children, collapsible, defaultCollapsed, collapsed: collapsedProp, onCollapseChange, bordered, shadow, loading, size, shimmer, className, style, bodyStyle, }: CardProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import "./carousel.css";
3
+ export interface CarouselProps {
4
+ children: React.ReactNode;
5
+ autoplay?: boolean;
6
+ autoplayInterval?: number;
7
+ dots?: boolean;
8
+ arrows?: boolean;
9
+ loop?: boolean;
10
+ defaultIndex?: number;
11
+ index?: number;
12
+ effect?: "slide" | "fade";
13
+ onChange?: (index: number) => void;
14
+ className?: string;
15
+ style?: React.CSSProperties;
16
+ }
17
+ export declare function Carousel({ children, autoplay, autoplayInterval, dots, arrows, loop, defaultIndex, index: controlledIndex, effect, onChange, className, style, }: CarouselProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import "./cascader.css";
3
+ export interface CascaderOption {
4
+ label: string;
5
+ value: string | number;
6
+ children?: CascaderOption[];
7
+ disabled?: boolean;
8
+ }
9
+ export type CascaderValue = (string | number)[];
10
+ export interface CascaderProps {
11
+ options?: CascaderOption[];
12
+ /** 单选时为 CascaderValue,多选时为 CascaderValue[] */
13
+ value?: CascaderValue | CascaderValue[];
14
+ onChange?: (value: CascaderValue | CascaderValue[], selectedOptions: CascaderOption[] | CascaderOption[][]) => void;
15
+ multiple?: boolean;
16
+ maxTagCount?: number;
17
+ placeholder?: string;
18
+ disabled?: boolean;
19
+ size?: "sm" | "md" | "lg";
20
+ clearable?: boolean;
21
+ separator?: string;
22
+ style?: React.CSSProperties;
23
+ className?: string;
24
+ }
25
+ export declare function Cascader({ options, value, onChange, multiple, maxTagCount, placeholder, disabled, size, clearable, separator, style, className, }: CascaderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import "./checkbox.css";
3
+ export type CheckboxSize = "sm" | "md" | "lg";
4
+ export interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "onChange" | "checked" | "defaultChecked" | "value"> {
5
+ checked?: boolean;
6
+ defaultChecked?: boolean;
7
+ onChange?: (checked: boolean, e: React.ChangeEvent<HTMLInputElement>) => void;
8
+ indeterminate?: boolean;
9
+ size?: CheckboxSize;
10
+ children?: React.ReactNode;
11
+ value?: string | number;
12
+ }
13
+ export interface CheckboxOption {
14
+ label: React.ReactNode;
15
+ value: string | number;
16
+ disabled?: boolean;
17
+ }
18
+ export interface CheckboxGroupProps {
19
+ value?: (string | number)[];
20
+ defaultValue?: (string | number)[];
21
+ onChange?: (value: (string | number)[]) => void;
22
+ options?: CheckboxOption[];
23
+ disabled?: boolean;
24
+ children?: React.ReactNode;
25
+ className?: string;
26
+ }
27
+ declare function CheckboxGroup({ value, defaultValue, onChange, options, disabled, children, className, }: CheckboxGroupProps): import("react/jsx-runtime").JSX.Element;
28
+ export declare function Checkbox({ checked, defaultChecked, onChange, indeterminate, size, disabled, children, value, className, ...rest }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
29
+ export declare namespace Checkbox {
30
+ var Group: typeof CheckboxGroup;
31
+ var displayName: string;
32
+ }
33
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import "./collapse.css";
3
+ export interface CollapseItem {
4
+ key: string;
5
+ label: React.ReactNode;
6
+ children: React.ReactNode;
7
+ disabled?: boolean;
8
+ }
9
+ export interface CollapseProps {
10
+ items: CollapseItem[];
11
+ defaultActiveKeys?: string[];
12
+ activeKeys?: string[];
13
+ accordion?: boolean;
14
+ onChange?: (keys: string[]) => void;
15
+ bordered?: boolean;
16
+ className?: string;
17
+ style?: React.CSSProperties;
18
+ }
19
+ export declare function Collapse({ items, defaultActiveKeys, activeKeys: controlledKeys, accordion, onChange, bordered, className, style, }: CollapseProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import "./datepicker.css";
3
+ export type DatePickerSize = "sm" | "md" | "lg";
4
+ export type PickerType = "date" | "month" | "year";
5
+ export type SingleValue = Date | string | null;
6
+ export type RangeValue = [SingleValue, SingleValue];
7
+ export interface DatePickerProps {
8
+ value?: SingleValue | RangeValue;
9
+ defaultValue?: SingleValue | RangeValue;
10
+ onChange?: (value: Date | null | [Date | null, Date | null], str: string | [string, string]) => void;
11
+ picker?: PickerType;
12
+ range?: boolean;
13
+ disabled?: boolean;
14
+ clearable?: boolean;
15
+ size?: DatePickerSize;
16
+ placeholder?: string;
17
+ format?: string;
18
+ min?: SingleValue;
19
+ max?: SingleValue;
20
+ style?: React.CSSProperties;
21
+ className?: string;
22
+ }
23
+ export declare function DatePicker({ value, defaultValue, onChange, picker, range, disabled, clearable, size, placeholder, format, min, max, style, className, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
24
+ export declare namespace DatePicker {
25
+ var displayName: string;
26
+ }
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import "./descriptions.css";
3
+ export interface DescriptionItem {
4
+ label: string;
5
+ value: React.ReactNode;
6
+ /** 占据的列数,默认 1 */
7
+ span?: number;
8
+ }
9
+ export interface DescriptionsProps {
10
+ /** 标题 */
11
+ title?: React.ReactNode;
12
+ /** 数据项 */
13
+ items: DescriptionItem[];
14
+ /** 每行列数,默认 3 */
15
+ column?: number;
16
+ /** 冒号分隔符,默认 ':' */
17
+ colon?: string;
18
+ /** 是否显示边框(表格样式) */
19
+ bordered?: boolean;
20
+ labelStyle?: React.CSSProperties;
21
+ contentStyle?: React.CSSProperties;
22
+ style?: React.CSSProperties;
23
+ className?: string;
24
+ }
25
+ export declare function Descriptions({ title, items, column, colon, bordered, labelStyle, contentStyle, style, className, }: DescriptionsProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import "./drawer.css";
3
+ export type DrawerPlacement = "left" | "right" | "top" | "bottom";
4
+ export interface DrawerProps {
5
+ open: boolean;
6
+ onClose?: () => void;
7
+ title?: React.ReactNode;
8
+ children?: React.ReactNode;
9
+ footer?: React.ReactNode | null;
10
+ placement?: DrawerPlacement;
11
+ width?: number | string;
12
+ height?: number | string;
13
+ closable?: boolean;
14
+ bodyStyle?: React.CSSProperties;
15
+ }
16
+ export declare function Drawer({ open, onClose, title, children, footer, placement, width, height, closable, bodyStyle, }: DrawerProps): React.ReactPortal | null;
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import "./dropdown.css";
3
+ export type DropdownTrigger = "click" | "hover" | "contextMenu";
4
+ export interface DropdownMenuItem {
5
+ key: string | number;
6
+ label: React.ReactNode;
7
+ icon?: React.ReactNode;
8
+ disabled?: boolean;
9
+ danger?: boolean;
10
+ onClick?: () => void;
11
+ }
12
+ export interface DropdownDivider {
13
+ type: "divider";
14
+ key?: string | number;
15
+ }
16
+ export type DropdownItem = DropdownMenuItem | DropdownDivider;
17
+ export interface DropdownProps {
18
+ items: DropdownItem[];
19
+ trigger?: DropdownTrigger;
20
+ disabled?: boolean;
21
+ open?: boolean;
22
+ defaultOpen?: boolean;
23
+ onOpenChange?: (open: boolean) => void;
24
+ onSelect?: (key: string | number) => void;
25
+ children: React.ReactElement;
26
+ className?: string;
27
+ style?: React.CSSProperties;
28
+ }
29
+ export declare function Dropdown({ items, trigger, disabled, open: openProp, defaultOpen, onOpenChange, onSelect, children, className, style, }: DropdownProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import "./empty.css";
3
+ export interface EmptyProps {
4
+ image?: React.ReactNode | null;
5
+ imageStyle?: React.CSSProperties;
6
+ description?: React.ReactNode;
7
+ children?: React.ReactNode;
8
+ className?: string;
9
+ style?: React.CSSProperties;
10
+ }
11
+ export declare function Empty({ image, imageStyle, description, children, className, style, }: EmptyProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { FormContextValue } from "./types";
2
+ export declare const FormContext: import("react").Context<FormContextValue>;
3
+ export declare function useFormContext(): FormContextValue;
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import "./form.css";
3
+ import { FormItem } from "./item";
4
+ import type { FormItemProps } from "./item";
5
+ import { FormList } from "./list";
6
+ import type { FormInstance, FieldError, ColConfig } from "./types";
7
+ export { FormItem };
8
+ export type { FormItemProps, FormItemType, FormItemRenderProps, FormItemRenderFn, } from "./item";
9
+ export { FormList };
10
+ export type { FormListProps } from "./list";
11
+ export declare function useForm<Values = any>(): [FormInstance<Values>];
12
+ export interface FormProps<Values = any> {
13
+ form?: FormInstance<Values>;
14
+ onFinish?: (values: Values) => void;
15
+ onFinishFailed?: (info: {
16
+ values: Values;
17
+ errorFields: FieldError[];
18
+ }) => void;
19
+ initialValues?: Partial<Values>;
20
+ layout?: "horizontal" | "vertical" | "inline";
21
+ labelCol?: ColConfig;
22
+ wrapperCol?: ColConfig;
23
+ colon?: boolean;
24
+ requiredMark?: boolean;
25
+ validateTrigger?: string | string[];
26
+ onValuesChange?: (changed: Partial<Values>, all: Values) => void;
27
+ name?: string;
28
+ column?: number;
29
+ items?: FormItemProps[];
30
+ widget?: Record<string, React.ComponentType<any>>;
31
+ className?: string;
32
+ style?: React.CSSProperties;
33
+ }
34
+ export declare function Form<Values = any>({ form, onFinish, onFinishFailed, initialValues, layout, labelCol, wrapperCol, colon, requiredMark, validateTrigger, onValuesChange, name, column, items, widget, className, style, }: FormProps<Values>): import("react/jsx-runtime").JSX.Element;
35
+ export declare namespace Form {
36
+ var Item: typeof FormItem;
37
+ var List: typeof FormList;
38
+ var useForm: typeof import(".").useForm;
39
+ }
@@ -0,0 +1,87 @@
1
+ import React from "react";
2
+ import type { RuleItem, NamePath, ColConfig } from "./types";
3
+ import type { InputProps } from "../input";
4
+ import type { InputNumberProps } from "../input-number";
5
+ import type { TextareaProps } from "../textarea";
6
+ import type { SelectProps } from "../select";
7
+ import type { SwitchProps } from "../switch";
8
+ import type { CheckboxProps, CheckboxGroupProps } from "../checkbox";
9
+ import type { RadioGroupProps } from "../radio";
10
+ import type { SliderProps } from "../slider";
11
+ import type { RateProps } from "../rate";
12
+ import type { DatePickerProps } from "../datepicker";
13
+ import type { TimePickerProps, TimeRangePickerProps } from "../timepicker";
14
+ import type { UploadProps } from "../upload";
15
+ import type { TreeSelectProps } from "../tree-select";
16
+ import type { CascaderProps } from "../cascader";
17
+ import { FormListProps } from "./list";
18
+ export type FormItemType = "Input" | "InputNumber" | "Textarea" | "Select" | "Switch" | "Checkbox" | "CheckboxGroup" | "RadioGroup" | "Slider" | "Rate" | "DatePicker" | "TimePicker" | "TimeRangePicker" | "Upload" | "TreeSelect" | "Cascader" | "FormList";
19
+ type ComponentPropsMap = {
20
+ Input: InputProps;
21
+ InputNumber: InputNumberProps;
22
+ Textarea: TextareaProps;
23
+ Select: SelectProps;
24
+ Switch: SwitchProps;
25
+ Checkbox: CheckboxProps;
26
+ CheckboxGroup: CheckboxGroupProps;
27
+ RadioGroup: RadioGroupProps;
28
+ Slider: SliderProps;
29
+ Rate: RateProps;
30
+ DatePicker: DatePickerProps;
31
+ TimePicker: TimePickerProps;
32
+ TimeRangePicker: TimeRangePickerProps;
33
+ Upload: UploadProps;
34
+ TreeSelect: TreeSelectProps;
35
+ Cascader: CascaderProps;
36
+ FormList: FormListProps;
37
+ };
38
+ export interface FormItemRenderProps {
39
+ form: import("./types").FormInstance;
40
+ value?: any;
41
+ onChange?: (...args: any[]) => void;
42
+ onBlur?: () => void;
43
+ status?: "error" | "";
44
+ }
45
+ export type FormItemRenderFn = React.ComponentType<FormItemRenderProps & Record<string, any>>;
46
+ type TypedProps = {
47
+ [K in FormItemType]: {
48
+ type: K;
49
+ props?: Partial<ComponentPropsMap[K]>;
50
+ };
51
+ }[FormItemType] | {
52
+ type: FormItemRenderFn;
53
+ props?: Record<string, any>;
54
+ } | {
55
+ type: string;
56
+ props?: Record<string, any>;
57
+ } | {
58
+ type?: undefined;
59
+ props?: never;
60
+ };
61
+ interface FormItemBaseProps {
62
+ name?: NamePath;
63
+ label?: React.ReactNode;
64
+ rules?: RuleItem[];
65
+ required?: boolean;
66
+ colon?: boolean;
67
+ labelCol?: ColConfig;
68
+ wrapperCol?: ColConfig;
69
+ validateTrigger?: string | string[];
70
+ valuePropName?: string;
71
+ getValueFromEvent?: (...args: any[]) => any;
72
+ help?: React.ReactNode;
73
+ extra?: React.ReactNode;
74
+ noStyle?: boolean;
75
+ hideMessage?: boolean;
76
+ span?: number;
77
+ effect?: NamePath[];
78
+ visible?: (form: import("./types").FormInstance) => boolean;
79
+ mergeProps?: (form: import("./types").FormInstance) => Record<string, any>;
80
+ normalize?: (value: any, prevValue: any, prevValues: any) => any;
81
+ initialValue?: any;
82
+ className?: string;
83
+ style?: React.CSSProperties;
84
+ }
85
+ export type FormItemProps = FormItemBaseProps & TypedProps;
86
+ export declare function FormItem({ name, label, rules, required, colon: colonProp, labelCol: labelColProp, wrapperCol: wrapperColProp, validateTrigger: validateTriggerProp, valuePropName: valuePropNameProp, getValueFromEvent, help, extra, noStyle, hideMessage, span, effect, visible, normalize, initialValue, type, props: componentProps, mergeProps, className, style, }: FormItemProps): import("react/jsx-runtime").JSX.Element | null;
87
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { NamePath } from "./types";
2
+ import type { FormItemProps } from "./item";
3
+ export interface FormListProps {
4
+ name: NamePath;
5
+ items?: FormItemProps[];
6
+ addText?: string;
7
+ }
8
+ export declare function FormList({ name, items, addText }: FormListProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,49 @@
1
+ import type { RuleItem, FieldError, FormInstance } from "./types";
2
+ export declare function getFormStore<V>(instance: FormInstance<V>): FormStore<V> | undefined;
3
+ type Listener = () => void;
4
+ export declare class FormStore<Values = Record<string, any>> {
5
+ private values;
6
+ private publicInstance;
7
+ private initialValues;
8
+ private errors;
9
+ private meta;
10
+ private fieldListeners;
11
+ private listPrefixes;
12
+ private callbacks;
13
+ setCallbacks(cbs: typeof this.callbacks): void;
14
+ setInitialValues(vals: Partial<Values>, init: boolean): void;
15
+ private notify;
16
+ registerField(name: string, rules: RuleItem[], initialValue?: any): void;
17
+ unregisterField(name: string): void;
18
+ subscribeField(name: string, listener: Listener): () => boolean | undefined;
19
+ getFieldValue(name: string): any;
20
+ registerList(prefix: string): void;
21
+ unregisterList(prefix: string): void;
22
+ private unflatten;
23
+ getFieldsValue(names?: string[]): Values;
24
+ setFieldValue(name: string, value: any): void;
25
+ setFieldsValue(vals: Partial<Values>): void;
26
+ resetFields(names?: string[]): void;
27
+ getFieldError(name: string): string[];
28
+ getFieldsError(names?: string[]): FieldError[];
29
+ isFieldTouched(name: string): boolean;
30
+ validateField(name: string): Promise<string[]>;
31
+ validateFields(names?: string[]): Promise<Values>;
32
+ submit(): void;
33
+ listRemove(prefix: string, index: number): void;
34
+ listAdd(prefix: string, index: number, initialValue: Record<string, any>): void;
35
+ getPublicInstance(): FormInstance<Values>;
36
+ getInternalHooks(): {
37
+ registerField: (name: string, rules: RuleItem[], initialValue?: any) => void;
38
+ unregisterField: (name: string) => void;
39
+ subscribeField: (name: string, listener: Listener) => () => boolean | undefined;
40
+ setCallbacks: (cbs: typeof this.callbacks) => void;
41
+ setInitialValues: (vals: Partial<Values>, init: boolean) => void;
42
+ validateField: (name: string) => Promise<string[]>;
43
+ listRemove: (prefix: string, index: number) => void;
44
+ listAdd: (prefix: string, index: number, initialValue: Record<string, any>) => void;
45
+ registerList: (prefix: string) => void;
46
+ unregisterList: (prefix: string) => void;
47
+ };
48
+ }
49
+ export {};
@@ -0,0 +1,47 @@
1
+ import type React from "react";
2
+ export type NamePath = string | (string | number)[];
3
+ export interface Rule {
4
+ required?: boolean;
5
+ message?: string;
6
+ min?: number;
7
+ max?: number;
8
+ len?: number;
9
+ pattern?: RegExp;
10
+ whitespace?: boolean;
11
+ type?: "string" | "number" | "email" | "url" | "boolean" | "array" | "object";
12
+ validator?: (rule: Rule, value: any) => Promise<void> | void;
13
+ enum?: any[];
14
+ }
15
+ export type RuleItem = Rule | ((form: FormInstance) => Rule);
16
+ export interface FieldError {
17
+ name: NamePath;
18
+ errors: string[];
19
+ }
20
+ export interface FormInstance<Values = any> {
21
+ getFieldValue(name: NamePath): any;
22
+ getFieldsValue(nameList?: NamePath[]): Values;
23
+ setFieldValue(name: NamePath, value: any): void;
24
+ setFieldsValue(values: Partial<Values>): void;
25
+ resetFields(fields?: NamePath[]): void;
26
+ validateFields(nameList?: NamePath[]): Promise<Values>;
27
+ getFieldError(name: NamePath): string[];
28
+ getFieldsError(nameList?: NamePath[]): FieldError[];
29
+ isFieldTouched(name: NamePath): boolean;
30
+ submit(): void;
31
+ }
32
+ export interface ColConfig {
33
+ span?: number;
34
+ }
35
+ export interface FormContextValue {
36
+ store: any;
37
+ layout: "horizontal" | "vertical" | "inline";
38
+ labelCol: ColConfig;
39
+ wrapperCol: ColConfig;
40
+ colon: boolean;
41
+ requiredMark: boolean;
42
+ validateTrigger: string[];
43
+ name?: string;
44
+ column?: number;
45
+ widget?: Record<string, React.ComponentType<any>>;
46
+ }
47
+ export declare function normalizeName(name: NamePath): string;