@ldkj/web-ui 0.19.0 → 0.21.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 ldkj
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ldkj
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,2 +1 @@
1
1
  export * from "./input";
2
- export * from "./useInputValue";
@@ -1,14 +1,45 @@
1
1
  import * as React from "react";
2
2
  import { type SxProps } from "@/styling";
3
- export type InputProps = React.ComponentPropsWithoutRef<"input"> & {
3
+ export type InputSlotProps = {
4
+ children?: React.ReactNode;
5
+ };
6
+ export type InputAddonProps = InputSlotProps & {
7
+ position?: "before" | "after";
8
+ };
9
+ export type InputProps = Omit<React.ComponentPropsWithoutRef<"input">, "prefix"> & {
10
+ addonAfter?: React.ReactNode;
11
+ addonBefore?: React.ReactNode;
4
12
  class?: string;
13
+ prefix?: React.ReactNode;
14
+ suffix?: React.ReactNode;
5
15
  sx?: SxProps;
6
16
  };
7
- /**
8
- * Input 是基础文本输入框组件,支持原生 input 属性、`class` 别名与本库 `sx` 样式系统。
9
- */
10
- declare const Input: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
17
+ export declare const Input: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "prefix"> & {
18
+ addonAfter?: React.ReactNode;
19
+ addonBefore?: React.ReactNode;
11
20
  class?: string;
21
+ prefix?: React.ReactNode;
22
+ suffix?: React.ReactNode;
12
23
  sx?: SxProps;
13
- } & React.RefAttributes<HTMLInputElement>>;
14
- export { Input };
24
+ } & React.RefAttributes<HTMLInputElement>> & {
25
+ Addon: {
26
+ (props: InputAddonProps): import("react/jsx-runtime").JSX.Element;
27
+ displayName: string;
28
+ };
29
+ AddonAfter: {
30
+ (props: InputSlotProps): import("react/jsx-runtime").JSX.Element;
31
+ displayName: string;
32
+ };
33
+ AddonBefore: {
34
+ (props: InputSlotProps): import("react/jsx-runtime").JSX.Element;
35
+ displayName: string;
36
+ };
37
+ Prefix: {
38
+ (props: InputSlotProps): import("react/jsx-runtime").JSX.Element;
39
+ displayName: string;
40
+ };
41
+ Suffix: {
42
+ (props: InputSlotProps): import("react/jsx-runtime").JSX.Element;
43
+ displayName: string;
44
+ };
45
+ };
@@ -1,10 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { type InputProps } from "@/components/form/input";
3
- export type InputNumberValueChangeReason = "input" | "commit";
3
+ export type InputNumberValueChangeReason = "input" | "commit" | "set";
4
4
  export type InputNumberValueChangeMeta = {
5
5
  reason: InputNumberValueChangeReason;
6
6
  valueAsString: string;
7
- event: React.ChangeEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement>;
7
+ event?: React.ChangeEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement>;
8
8
  };
9
9
  export type InputNumberProps = Omit<InputProps, "type" | "inputMode"> & {
10
10
  min?: number;
@@ -16,6 +16,32 @@ export type InputNumberProps = Omit<InputProps, "type" | "inputMode"> & {
16
16
  precision?: number;
17
17
  /** 返回解析后的数值;空值或非法临时值返回 `null`。 */
18
18
  onValueChange?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
19
+ /** 输入值提交时触发,默认在失焦或按下 Enter 时提交。 */
20
+ onValueCommit?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
21
+ };
22
+ export type NumberInputValue = string | number | null;
23
+ export type UseNumberInputOptions = NormalizeOptions & {
24
+ value?: NumberInputValue;
25
+ defaultValue?: string | number | null;
26
+ onValueChange?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
27
+ onValueCommit?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
28
+ };
29
+ export type UseNumberInputGetInputProps = Omit<InputProps, "defaultValue" | "inputMode" | "max" | "min" | "onBlur" | "onChange" | "onKeyDown" | "step" | "type" | "value"> & {
30
+ disabled?: boolean;
31
+ readOnly?: boolean;
32
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
33
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
34
+ onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
35
+ };
36
+ export type UseNumberInputResult = {
37
+ value: string;
38
+ numberValue: number | null;
39
+ setValue: (value: NumberInputValue) => void;
40
+ commitValue: (value?: NumberInputValue) => {
41
+ value: number | null;
42
+ valueAsString: string;
43
+ };
44
+ getInputProps: (props?: UseNumberInputGetInputProps) => InputProps;
19
45
  };
20
46
  export type UseInputNumberStateOptions = NormalizeOptions & {
21
47
  defaultValue?: string | number | null;
@@ -29,8 +55,11 @@ export type UseInputNumberStateResult = {
29
55
  };
30
56
  type NormalizeOptions = Pick<InputNumberProps, "clampOnBlur" | "max" | "min" | "precision" | "step">;
31
57
  /**
32
- * 管理 InputNumber 的字符串输入态与解析后的数字值。
33
- * 它会自动同步 `clampOnBlur` 产生的提交值,避免业务侧手写 commit 分支。
58
+ * 提供数字输入的 headless 行为层,统一管理字符串展示值、解析值和提交归一化。
59
+ */
60
+ export declare function useNumberInput(options?: UseNumberInputOptions): UseNumberInputResult;
61
+ /**
62
+ * @deprecated 优先使用 `useNumberInput`,通过 `getInputProps()` 组合输入控件。
34
63
  */
35
64
  export declare function useInputNumberState(options?: UseInputNumberStateOptions): UseInputNumberStateResult;
36
65
  /**
@@ -47,5 +76,7 @@ export declare const InputNumber: React.ForwardRefExoticComponent<Omit<InputProp
47
76
  precision?: number;
48
77
  /** 返回解析后的数值;空值或非法临时值返回 `null`。 */
49
78
  onValueChange?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
79
+ /** 输入值提交时触发,默认在失焦或按下 Enter 时提交。 */
80
+ onValueCommit?: (value: number | null, meta: InputNumberValueChangeMeta) => void;
50
81
  } & React.RefAttributes<HTMLInputElement>>;
51
82
  export {};
@@ -1,11 +1,183 @@
1
- /**
2
- * Uploader 属性。组件通过 `onChange(FileList | null)` 暴露用户选择的文件列表。
3
- */
4
- export type UploaderProps = {
1
+ import * as React from "react";
2
+ import { type SxProps } from "@/styling";
3
+ export declare const UPLOADER_LIST_IGNORE: "__LDKJ_UPLOADER_LIST_IGNORE__";
4
+ export type UploaderStatus = "ready" | "uploading" | "success" | "error";
5
+ export type UploaderListType = "text" | "picture" | "picture-card";
6
+ export type UploaderValue = unknown;
7
+ export type UploaderFile = {
8
+ uid: string;
9
+ name: string;
10
+ size?: number;
11
+ type?: string;
12
+ status: UploaderStatus;
13
+ percent?: number;
14
+ url?: string;
15
+ thumbUrl?: string;
16
+ value?: UploaderValue;
17
+ response?: unknown;
18
+ error?: Error;
19
+ originFile?: File;
20
+ };
21
+ export type UploaderRequestResult = {
22
+ value?: UploaderValue;
23
+ url?: string;
24
+ thumbUrl?: string;
25
+ response?: unknown;
26
+ name?: string;
27
+ };
28
+ export type UploaderRequestOptions = {
29
+ file: File;
30
+ item: UploaderFile;
31
+ action?: string;
32
+ data?: Record<string, unknown>;
33
+ filename: string;
34
+ headers?: Record<string, string>;
35
+ method: string;
36
+ signal: AbortSignal;
37
+ withCredentials: boolean;
38
+ onProgress: (percent: number) => void;
39
+ };
40
+ export type UploaderRequest = (options: UploaderRequestOptions) => Promise<UploaderRequestResult | void> | UploaderRequestResult | void;
41
+ export type UploaderValueChangeMeta = {
42
+ file?: UploaderFile;
43
+ fileList: UploaderFile[];
44
+ reason: "add" | "success" | "error" | "remove" | "retry" | "reset" | "progress";
45
+ };
46
+ export type UploaderRenderState = {
47
+ disabled: boolean;
48
+ dragging: boolean;
49
+ fileList: UploaderFile[];
50
+ uploading: boolean;
51
+ open: () => void;
52
+ };
53
+ export type UploaderProps = Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & {
5
54
  accept?: string;
55
+ action?: string | ((file: File) => string | Promise<string>);
56
+ autoUpload?: boolean;
57
+ beforeRemove?: (file: UploaderFile, fileList: UploaderFile[]) => boolean | Promise<boolean>;
58
+ beforeUpload?: (file: File, fileList: File[]) => boolean | File | Blob | typeof UPLOADER_LIST_IGNORE | Promise<boolean | File | Blob | typeof UPLOADER_LIST_IGNORE>;
59
+ children?: React.ReactNode | ((state: UploaderRenderState) => React.ReactNode);
60
+ class?: string;
61
+ customRequest?: UploaderRequest;
62
+ data?: Record<string, unknown> | ((file: File) => Record<string, unknown> | Promise<Record<string, unknown>>);
63
+ defaultFileList?: UploaderFile[];
64
+ defaultValue?: UploaderValue | UploaderValue[];
65
+ directory?: boolean;
66
+ disabled?: boolean;
67
+ drag?: boolean;
68
+ fileList?: UploaderFile[];
69
+ getValueFromResult?: (result: UploaderRequestResult | void, file: UploaderFile) => UploaderValue;
70
+ headers?: Record<string, string>;
71
+ listType?: UploaderListType;
72
+ maxCount?: number;
73
+ maxSize?: number;
74
+ method?: string;
6
75
  multiple?: boolean;
7
76
  name?: string;
77
+ openFileDialogOnClick?: boolean;
78
+ pastable?: boolean;
79
+ preview?: boolean;
80
+ request?: UploaderRequest;
81
+ renderActions?: (file: UploaderFile, actions: {
82
+ preview: () => void;
83
+ download: () => void;
84
+ remove: () => void;
85
+ retry: () => void;
86
+ upload: () => void;
87
+ }) => React.ReactNode;
88
+ renderItem?: (file: UploaderFile, originNode: React.ReactNode, actions: {
89
+ preview: () => void;
90
+ download: () => void;
91
+ remove: () => void;
92
+ retry: () => void;
93
+ upload: () => void;
94
+ }) => React.ReactNode;
95
+ renderTrigger?: (state: UploaderRenderState) => React.ReactNode;
96
+ showFileList?: boolean;
97
+ sx?: SxProps;
98
+ transformFile?: (file: File) => File | Blob | Promise<File | Blob>;
99
+ value?: UploaderValue | UploaderValue[];
100
+ withCredentials?: boolean;
101
+ onChange?: (files: FileList | null) => void;
102
+ onDownload?: (file: UploaderFile) => void;
103
+ onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
104
+ onError?: (error: Error, file: UploaderFile, fileList: UploaderFile[]) => void;
105
+ onExceed?: (files: File[], fileList: UploaderFile[]) => void;
106
+ onFileListChange?: (fileList: UploaderFile[], meta: UploaderValueChangeMeta) => void;
107
+ onPreview?: (file: UploaderFile) => boolean | void | Promise<boolean | void>;
108
+ onReject?: (file: File, reason: "accept" | "maxSize") => void;
109
+ onRemove?: (file: UploaderFile, fileList: UploaderFile[]) => void;
110
+ onSelect?: (files: File[]) => void;
111
+ onSuccess?: (file: UploaderFile, fileList: UploaderFile[]) => void;
112
+ onValueChange?: (value: UploaderValue | UploaderValue[] | null, meta: UploaderValueChangeMeta) => void;
113
+ };
114
+ export type UploaderProviderConfig = Partial<Pick<UploaderProps, "accept" | "action" | "autoUpload" | "beforeRemove" | "beforeUpload" | "customRequest" | "data" | "directory" | "disabled" | "drag" | "getValueFromResult" | "headers" | "listType" | "maxCount" | "maxSize" | "method" | "multiple" | "name" | "openFileDialogOnClick" | "pastable" | "preview" | "request" | "renderActions" | "renderItem" | "renderTrigger" | "showFileList" | "transformFile" | "withCredentials" | "onDownload" | "onError" | "onExceed" | "onPreview" | "onReject" | "onRemove" | "onSelect" | "onSuccess">>;
115
+ export type UploaderProviderProps = UploaderProviderConfig & {
116
+ children?: React.ReactNode;
117
+ };
118
+ export declare function UploaderProvider(props: UploaderProviderProps): import("react/jsx-runtime").JSX.Element;
119
+ export declare function useUploaderProvider(): Partial<Pick<UploaderProps, "drag" | "multiple" | "disabled" | "data" | "directory" | "action" | "accept" | "headers" | "name" | "onError" | "onSelect" | "preview" | "method" | "maxSize" | "autoUpload" | "beforeRemove" | "beforeUpload" | "customRequest" | "getValueFromResult" | "listType" | "maxCount" | "openFileDialogOnClick" | "pastable" | "request" | "renderActions" | "renderItem" | "renderTrigger" | "showFileList" | "transformFile" | "withCredentials" | "onDownload" | "onExceed" | "onPreview" | "onReject" | "onRemove" | "onSuccess">> | null;
120
+ export declare const Uploader: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & {
121
+ accept?: string;
122
+ action?: string | ((file: File) => string | Promise<string>);
123
+ autoUpload?: boolean;
124
+ beforeRemove?: (file: UploaderFile, fileList: UploaderFile[]) => boolean | Promise<boolean>;
125
+ beforeUpload?: (file: File, fileList: File[]) => boolean | File | Blob | typeof UPLOADER_LIST_IGNORE | Promise<boolean | File | Blob | typeof UPLOADER_LIST_IGNORE>;
126
+ children?: React.ReactNode | ((state: UploaderRenderState) => React.ReactNode);
127
+ class?: string;
128
+ customRequest?: UploaderRequest;
129
+ data?: Record<string, unknown> | ((file: File) => Record<string, unknown> | Promise<Record<string, unknown>>);
130
+ defaultFileList?: UploaderFile[];
131
+ defaultValue?: UploaderValue | UploaderValue[];
132
+ directory?: boolean;
8
133
  disabled?: boolean;
134
+ drag?: boolean;
135
+ fileList?: UploaderFile[];
136
+ getValueFromResult?: (result: UploaderRequestResult | void, file: UploaderFile) => UploaderValue;
137
+ headers?: Record<string, string>;
138
+ listType?: UploaderListType;
139
+ maxCount?: number;
140
+ maxSize?: number;
141
+ method?: string;
142
+ multiple?: boolean;
143
+ name?: string;
144
+ openFileDialogOnClick?: boolean;
145
+ pastable?: boolean;
146
+ preview?: boolean;
147
+ request?: UploaderRequest;
148
+ renderActions?: (file: UploaderFile, actions: {
149
+ preview: () => void;
150
+ download: () => void;
151
+ remove: () => void;
152
+ retry: () => void;
153
+ upload: () => void;
154
+ }) => React.ReactNode;
155
+ renderItem?: (file: UploaderFile, originNode: React.ReactNode, actions: {
156
+ preview: () => void;
157
+ download: () => void;
158
+ remove: () => void;
159
+ retry: () => void;
160
+ upload: () => void;
161
+ }) => React.ReactNode;
162
+ renderTrigger?: (state: UploaderRenderState) => React.ReactNode;
163
+ showFileList?: boolean;
164
+ sx?: SxProps;
165
+ transformFile?: (file: File) => File | Blob | Promise<File | Blob>;
166
+ value?: UploaderValue | UploaderValue[];
167
+ withCredentials?: boolean;
9
168
  onChange?: (files: FileList | null) => void;
169
+ onDownload?: (file: UploaderFile) => void;
170
+ onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
171
+ onError?: (error: Error, file: UploaderFile, fileList: UploaderFile[]) => void;
172
+ onExceed?: (files: File[], fileList: UploaderFile[]) => void;
173
+ onFileListChange?: (fileList: UploaderFile[], meta: UploaderValueChangeMeta) => void;
174
+ onPreview?: (file: UploaderFile) => boolean | void | Promise<boolean | void>;
175
+ onReject?: (file: File, reason: "accept" | "maxSize") => void;
176
+ onRemove?: (file: UploaderFile, fileList: UploaderFile[]) => void;
177
+ onSelect?: (files: File[]) => void;
178
+ onSuccess?: (file: UploaderFile, fileList: UploaderFile[]) => void;
179
+ onValueChange?: (value: UploaderValue | UploaderValue[] | null, meta: UploaderValueChangeMeta) => void;
180
+ } & React.RefAttributes<HTMLInputElement>> & {
181
+ LIST_IGNORE: "__LDKJ_UPLOADER_LIST_IGNORE__";
182
+ Provider: typeof UploaderProvider;
10
183
  };
11
- export declare function Uploader(props: UploaderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,14 @@
1
1
  import * as React from "react";
2
2
  export type ProgressType = "line" | "circle";
3
3
  export type ProgressStatus = "normal" | "success" | "warning" | "exception";
4
+ export type ProgressSize = "xs" | "sm" | "md" | "lg" | "xl" | number;
4
5
  export type ProgressProps = React.HTMLAttributes<HTMLDivElement> & {
5
6
  value?: number;
6
7
  max?: number;
7
8
  showInfo?: boolean;
8
9
  type?: ProgressType;
9
10
  status?: ProgressStatus;
10
- size?: number;
11
+ size?: ProgressSize;
11
12
  strokeWidth?: number;
12
13
  strokeColor?: string;
13
14
  trailColor?: string;