@tiny-codes/react-easy 1.1.3 → 1.2.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.
- package/CHANGELOG.md +33 -0
- package/es/components/ConfirmAction/index.d.ts +97 -28
- package/es/components/ConfirmAction/index.js +47 -28
- package/es/components/ConfirmAction/index.js.map +1 -1
- package/es/components/ConfirmAction/withConfirmAction.d.ts +48 -0
- package/es/components/ConfirmAction/withConfirmAction.js +131 -0
- package/es/components/ConfirmAction/withConfirmAction.js.map +1 -0
- package/es/components/ContextMenu/index.d.ts +42 -0
- package/es/components/ContextMenu/index.js +188 -0
- package/es/components/ContextMenu/index.js.map +1 -0
- package/es/components/ContextMenu/style/index.d.ts +3 -0
- package/es/components/ContextMenu/style/index.js +25 -0
- package/es/components/ContextMenu/style/index.js.map +1 -0
- package/es/components/DeleteConfirmAction/index.d.ts +1 -1
- package/es/components/DeleteConfirmAction/index.js +9 -3
- package/es/components/DeleteConfirmAction/index.js.map +1 -1
- package/es/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +19 -0
- package/es/components/DeleteConfirmAction/withDeleteConfirmAction.js +20 -0
- package/es/components/DeleteConfirmAction/withDeleteConfirmAction.js.map +1 -0
- package/es/components/EditableText/form.d.ts +12 -6
- package/es/components/EditableText/form.js +106 -56
- package/es/components/EditableText/form.js.map +1 -1
- package/es/components/EditableText/index.d.ts +31 -9
- package/es/components/EditableText/index.js +13 -7
- package/es/components/EditableText/index.js.map +1 -1
- package/es/components/Loading/index.d.ts +2 -2
- package/es/components/Loading/index.js +5 -5
- package/es/components/Loading/index.js.map +1 -1
- package/es/components/ModalAction/index.d.ts +35 -29
- package/es/components/ModalAction/index.js +16 -9
- package/es/components/ModalAction/index.js.map +1 -1
- package/es/components/index.d.ts +5 -1
- package/es/components/index.js +3 -0
- package/es/components/index.js.map +1 -1
- package/lib/components/ConfirmAction/index.d.ts +97 -28
- package/lib/components/ConfirmAction/index.js +57 -32
- package/lib/components/ConfirmAction/index.js.map +2 -2
- package/lib/components/ConfirmAction/withConfirmAction.d.ts +48 -0
- package/lib/components/ConfirmAction/withConfirmAction.js +123 -0
- package/lib/components/ConfirmAction/withConfirmAction.js.map +7 -0
- package/lib/components/ContextMenu/index.d.ts +42 -0
- package/lib/components/ContextMenu/index.js +190 -0
- package/lib/components/ContextMenu/index.js.map +7 -0
- package/lib/components/ContextMenu/style/index.d.ts +3 -0
- package/lib/components/ContextMenu/style/index.js +48 -0
- package/lib/components/ContextMenu/style/index.js.map +7 -0
- package/lib/components/DeleteConfirmAction/index.d.ts +1 -1
- package/lib/components/DeleteConfirmAction/index.js +28 -16
- package/lib/components/DeleteConfirmAction/index.js.map +2 -2
- package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +19 -0
- package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.js +38 -0
- package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.js.map +7 -0
- package/lib/components/EditableText/form.d.ts +12 -6
- package/lib/components/EditableText/form.js +69 -39
- package/lib/components/EditableText/form.js.map +2 -2
- package/lib/components/EditableText/index.d.ts +31 -9
- package/lib/components/EditableText/index.js +12 -5
- package/lib/components/EditableText/index.js.map +2 -2
- package/lib/components/Loading/index.d.ts +2 -2
- package/lib/components/Loading/index.js +4 -4
- package/lib/components/Loading/index.js.map +2 -2
- package/lib/components/ModalAction/index.d.ts +35 -29
- package/lib/components/ModalAction/index.js +22 -17
- package/lib/components/ModalAction/index.js.map +2 -2
- package/lib/components/index.d.ts +5 -1
- package/lib/components/index.js +9 -0
- package/lib/components/index.js.map +2 -2
- package/package.json +3 -2
package/es/components/index.js
CHANGED
|
@@ -2,10 +2,13 @@ export { default as BreakLines } from "./BreakLines";
|
|
|
2
2
|
export { default as ConfigProvider } from "./ConfigProvider";
|
|
3
3
|
export { default as ReactEasyContext } from "./ConfigProvider/context";
|
|
4
4
|
export { withDefaultConfirmActionProps } from "./ConfirmAction";
|
|
5
|
+
export { default as withConfirmAction } from "./ConfirmAction/withConfirmAction";
|
|
5
6
|
export { default as ConfirmAction } from "./ConfirmAction";
|
|
7
|
+
export { default as ContextMenu } from "./ContextMenu";
|
|
6
8
|
|
|
7
9
|
// export * from './DeleteConfirmAction';
|
|
8
10
|
export { default as DeleteConfirmAction } from "./DeleteConfirmAction";
|
|
11
|
+
export { default as withDeleteConfirmAction } from "./DeleteConfirmAction/withDeleteConfirmAction";
|
|
9
12
|
export { default as EditableText } from "./EditableText";
|
|
10
13
|
export { default as FloatDrawer } from "./FloatDrawer";
|
|
11
14
|
export { default as Loading } from "./Loading";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","BreakLines","ConfigProvider","ReactEasyContext","withDefaultConfirmActionProps","ConfirmAction","DeleteConfirmAction","EditableText","FloatDrawer","Loading","withDefaultModalActionProps","withModalAction","ModalAction","OverflowTags"],"sources":["../../src/components/index.tsx"],"sourcesContent":["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\n\nexport type { EditableTextProps } from './EditableText';\nexport { default as EditableText } from './EditableText';\n\nexport type { FloatDrawerProps } from './FloatDrawer';\nexport { default as FloatDrawer } from './FloatDrawer';\n\nexport type { LoadingProps } from './Loading';\nexport { default as Loading } from './Loading';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\nexport type { OverflowTagsProps } from './OverflowTags';\nexport { default as OverflowTags } from './OverflowTags';\n"],"mappings":"AACA,SAASA,OAAO,IAAIC,UAAU;AAG9B,SAASD,OAAO,IAAIE,cAAc;AAElC,SAASF,OAAO,IAAIG,gBAAgB;AAGpC,SAASC,6BAA6B;AACtC,SAASJ,OAAO,IAAIK,
|
|
1
|
+
{"version":3,"names":["default","BreakLines","ConfigProvider","ReactEasyContext","withDefaultConfirmActionProps","withConfirmAction","ConfirmAction","ContextMenu","DeleteConfirmAction","withDeleteConfirmAction","EditableText","FloatDrawer","Loading","withDefaultModalActionProps","withModalAction","ModalAction","OverflowTags"],"sources":["../../src/components/index.tsx"],"sourcesContent":["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef, ActionCompConstraint } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as withConfirmAction } from './ConfirmAction/withConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\nexport type {\n ContextMenuProps,\n ContextMenuItem,\n ContextMenuSeparator,\n ContextMenuSubmenu,\n ContextMenuRef,\n} from './ContextMenu';\nexport { default as ContextMenu } from './ContextMenu';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\nexport { default as withDeleteConfirmAction } from './DeleteConfirmAction/withDeleteConfirmAction';\n\nexport type { EditableTextProps } from './EditableText';\nexport { default as EditableText } from './EditableText';\n\nexport type { FloatDrawerProps } from './FloatDrawer';\nexport { default as FloatDrawer } from './FloatDrawer';\n\nexport type { LoadingProps } from './Loading';\nexport { default as Loading } from './Loading';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\nexport type { OverflowTagsProps } from './OverflowTags';\nexport { default as OverflowTags } from './OverflowTags';\n"],"mappings":"AACA,SAASA,OAAO,IAAIC,UAAU;AAG9B,SAASD,OAAO,IAAIE,cAAc;AAElC,SAASF,OAAO,IAAIG,gBAAgB;AAGpC,SAASC,6BAA6B;AACtC,SAASJ,OAAO,IAAIK,iBAAiB;AACrC,SAASL,OAAO,IAAIM,aAAa;AASjC,SAASN,OAAO,IAAIO,WAAW;;AAE/B;AACA,SAASP,OAAO,IAAIQ,mBAAmB;AACvC,SAASR,OAAO,IAAIS,uBAAuB;AAG3C,SAAST,OAAO,IAAIU,YAAY;AAGhC,SAASV,OAAO,IAAIW,WAAW;AAG/B,SAASX,OAAO,IAAIY,OAAO;AAG3B,SAASC,2BAA2B,EAAEC,eAAe;AACrD,SAASd,OAAO,IAAIe,WAAW;AAG/B,SAASf,OAAO,IAAIgB,YAAY"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';
|
|
2
2
|
import type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';
|
|
3
3
|
import type { ModalFunc } from 'antd/es/modal/confirm';
|
|
4
|
-
import type confirm from 'antd/es/modal/confirm';
|
|
5
4
|
import type { LinkProps } from 'antd/es/typography/Link';
|
|
6
5
|
import type { TextProps } from 'antd/es/typography/Text';
|
|
7
|
-
export type ConfirmActionProps<
|
|
6
|
+
export type ConfirmActionProps<TriggerProp extends object, Event extends keyof TriggerProp> = Omit<ModalFuncProps, 'onOk'> & ConfirmActionTrigger<TriggerProp, Event> & {
|
|
8
7
|
/**
|
|
9
8
|
* - **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
10
9
|
* the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the
|
|
11
10
|
* defaults is `true`.
|
|
12
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* > You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override
|
|
13
|
+
*
|
|
13
14
|
* - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
14
|
-
*
|
|
15
|
+
*
|
|
16
|
+
* > 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖
|
|
15
17
|
*/
|
|
16
18
|
danger?: boolean;
|
|
17
19
|
/**
|
|
@@ -33,7 +35,7 @@ export type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<Mod
|
|
|
33
35
|
* - **EN:** Callback when click confirm button
|
|
34
36
|
* - **CN:** 点击确认按钮的回调
|
|
35
37
|
*/
|
|
36
|
-
onOk?: (...args: Parameters<
|
|
38
|
+
onOk?: (...args: Parameters<TriggerProp[Event]>) => unknown | Promise<unknown>;
|
|
37
39
|
/**
|
|
38
40
|
* - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
39
41
|
* value of `onOk`
|
|
@@ -41,32 +43,34 @@ export type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<Mod
|
|
|
41
43
|
*/
|
|
42
44
|
afterOk?: (data?: any) => void;
|
|
43
45
|
};
|
|
44
|
-
export interface ConfirmActionTrigger<
|
|
46
|
+
export interface ConfirmActionTrigger<TriggerProp extends object, Event extends keyof TriggerProp> {
|
|
45
47
|
/**
|
|
46
48
|
* - **EN:** Trigger component, trigger to show confirm box
|
|
47
49
|
* - **CN:** 触发器组件,触发显示确认弹框
|
|
48
50
|
*/
|
|
49
|
-
triggerComponent?: ComponentType<
|
|
51
|
+
triggerComponent?: ComponentType<TriggerProp>;
|
|
50
52
|
/**
|
|
51
53
|
* - **EN:** Props of trigger component
|
|
52
54
|
* - **CN:** 触发器组件的Props属性
|
|
53
55
|
*/
|
|
54
|
-
triggerProps?:
|
|
56
|
+
triggerProps?: TriggerProp;
|
|
55
57
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
+
* **EN:** The event name that triggers the dialog
|
|
59
|
+
*
|
|
60
|
+
* **CN:** 触发弹窗的事件名称
|
|
61
|
+
*
|
|
58
62
|
* - `Button`: 'onClick'
|
|
59
63
|
* - `Switch`: 'onChange'
|
|
60
64
|
* - `Link`: 'onClick'
|
|
61
65
|
*/
|
|
62
|
-
triggerEvent?:
|
|
66
|
+
triggerEvent?: Event;
|
|
63
67
|
/**
|
|
64
68
|
* - **EN:** Custom trigger content
|
|
65
69
|
* - **CN:** 自定义触发器内容
|
|
66
70
|
*/
|
|
67
71
|
children?: ReactNode;
|
|
68
72
|
}
|
|
69
|
-
export type ConfirmActionRef = ReturnType<
|
|
73
|
+
export type ConfirmActionRef<R = {}> = R & ReturnType<ModalFunc> & {
|
|
70
74
|
/**
|
|
71
75
|
* - **EN:** Show confirm box
|
|
72
76
|
* - **CN:** 显示确认弹框
|
|
@@ -84,24 +88,28 @@ export type ConfirmActionRef = ReturnType<typeof confirm> & {
|
|
|
84
88
|
export declare const genRenderer: (defaultProps: Partial<ConfirmActionProps<any, never>> & {
|
|
85
89
|
confirmType: 'normal' | 'delete';
|
|
86
90
|
}) => {
|
|
87
|
-
<
|
|
91
|
+
<TriggerProp extends object, Event extends keyof TriggerProp>(props: ConfirmActionProps<TriggerProp, Event>, ref: ForwardedRef<ConfirmActionRef>): import("react/jsx-runtime").JSX.Element;
|
|
88
92
|
displayName: string;
|
|
89
93
|
};
|
|
90
94
|
/**
|
|
91
95
|
* - **EN:** Add default properties to the ConfirmAction component
|
|
92
96
|
* - **CN:** 给ConfirmAction组件添加默认属性
|
|
93
97
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @param defaultProps
|
|
98
|
+
* @param RenderComponent The component that renders the ConfirmAction | 实际渲染组件
|
|
99
|
+
* @param defaultProps Add some default values based on the props passed to the component |
|
|
100
|
+
* 在组件传入的props基础上,添加一些默认值
|
|
96
101
|
*/
|
|
97
|
-
export declare const withDefaultConfirmActionProps: <
|
|
102
|
+
export declare const withDefaultConfirmActionProps: <P extends ActionCompConstraint, TriggerProp extends object, Event extends keyof TriggerProp, Ref extends object>(RenderComponent: ComponentType<PropsWithoutRef<P & ConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef<Ref>>>, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & Omit<ModalFuncProps, "onOk"> & ConfirmActionTrigger<TriggerProp, Event> & {
|
|
98
103
|
/**
|
|
99
104
|
* - **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
100
105
|
* the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the
|
|
101
106
|
* defaults is `true`.
|
|
102
|
-
*
|
|
107
|
+
*
|
|
108
|
+
* > You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override
|
|
109
|
+
*
|
|
103
110
|
* - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
104
|
-
*
|
|
111
|
+
*
|
|
112
|
+
* > 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖
|
|
105
113
|
*/
|
|
106
114
|
danger?: boolean | undefined;
|
|
107
115
|
/**
|
|
@@ -123,29 +131,95 @@ export declare const withDefaultConfirmActionProps: <TP extends object, E extend
|
|
|
123
131
|
* - **EN:** Callback when click confirm button
|
|
124
132
|
* - **CN:** 点击确认按钮的回调
|
|
125
133
|
*/
|
|
126
|
-
onOk?: ((...args: Parameters<
|
|
134
|
+
onOk?: ((...args: Parameters<TriggerProp[Event]>) => unknown | Promise<unknown>) | undefined;
|
|
127
135
|
/**
|
|
128
136
|
* - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
129
137
|
* value of `onOk`
|
|
130
138
|
* - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
131
139
|
*/
|
|
132
140
|
afterOk?: ((data?: any) => void) | undefined;
|
|
133
|
-
} &
|
|
141
|
+
}> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>>) | undefined) => import("react").ForwardRefExoticComponent<PropsWithoutRef<Omit<P, keyof ActionCompConstraint> & Omit<ModalFuncProps, "onOk"> & ConfirmActionTrigger<TriggerProp, Event> & {
|
|
142
|
+
/**
|
|
143
|
+
* - **EN:** Whether to display in red danger mode, which will automatically affect the color of
|
|
144
|
+
* the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the
|
|
145
|
+
* defaults is `true`.
|
|
146
|
+
*
|
|
147
|
+
* > You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override
|
|
148
|
+
*
|
|
149
|
+
* - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。
|
|
150
|
+
*
|
|
151
|
+
* > 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖
|
|
152
|
+
*/
|
|
153
|
+
danger?: boolean | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* - **EN:** The color of confirm box title, default is `warning`
|
|
156
|
+
* - **CN:** 弹框标题颜色,默认`warning`
|
|
157
|
+
*/
|
|
158
|
+
titleColor?: TextProps['type'] | 'primary';
|
|
159
|
+
/**
|
|
160
|
+
* - **EN:** The color of confirm box content
|
|
161
|
+
* - **CN:** 弹框内容文本颜色
|
|
162
|
+
*/
|
|
163
|
+
contentColor?: TextProps['type'] | 'primary';
|
|
164
|
+
/**
|
|
165
|
+
* - **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
166
|
+
* - **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
167
|
+
*/
|
|
168
|
+
iconColor?: TextProps['type'] | 'primary';
|
|
169
|
+
/**
|
|
170
|
+
* - **EN:** Callback when click confirm button
|
|
171
|
+
* - **CN:** 点击确认按钮的回调
|
|
172
|
+
*/
|
|
173
|
+
onOk?: ((...args: Parameters<TriggerProp[Event]>) => unknown | Promise<unknown>) | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
176
|
+
* value of `onOk`
|
|
177
|
+
* - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
178
|
+
*/
|
|
179
|
+
afterOk?: ((data?: any) => void) | undefined;
|
|
180
|
+
}> & RefAttributes<ConfirmActionRef<Ref>>>;
|
|
181
|
+
/**
|
|
182
|
+
* - **EN:** Confirm box component with trigger
|
|
183
|
+
* - **CN:** 带触发器的确认框组件
|
|
184
|
+
*/
|
|
185
|
+
declare const ConfirmAction: ConfirmActionWithStatic;
|
|
186
|
+
export interface ActionCompConstraint extends ReturnType<ModalFunc> {
|
|
187
|
+
/**
|
|
188
|
+
* - **EN:** Register the confirm action save event, the passed callback function will be called
|
|
189
|
+
* when the confirm button is clicked, supports asynchronous saving
|
|
190
|
+
* - **CN:** 注册确认框保存事件,传入的回调函数会在点击确认按钮时调用,支持异步保存
|
|
191
|
+
*
|
|
192
|
+
* @param handler Event handler | 事件处理函数
|
|
193
|
+
*/
|
|
194
|
+
setOK: (handler: (
|
|
195
|
+
/**
|
|
196
|
+
* - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get
|
|
197
|
+
* the value of the switch; for the `Button` type trigger, you can get the click event
|
|
198
|
+
* object of the button
|
|
199
|
+
* - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象
|
|
200
|
+
*/
|
|
201
|
+
...triggerEventArgs: any[]) => unknown | Promise<unknown>) => void;
|
|
202
|
+
/**
|
|
203
|
+
* - **EN:** Default trigger DOM element used to render the trigger
|
|
204
|
+
* - **CN:** 默认的触发器组件的 DOM 元素,用于渲染触发器
|
|
205
|
+
*/
|
|
206
|
+
triggerDom: ReactNode;
|
|
207
|
+
}
|
|
134
208
|
/**
|
|
135
209
|
* - **EN:** Interface of generic type component
|
|
136
210
|
* - **CN:** 泛型组件的接口
|
|
137
211
|
*/
|
|
138
|
-
export type GenericConfirmActionInterface = <
|
|
212
|
+
export type GenericConfirmActionInterface = <TriggerProp extends object, Event extends keyof TriggerProp>(props: PropsWithoutRef<TypedConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef>) => ReactElement;
|
|
139
213
|
/**
|
|
140
214
|
* - **EN:** Interface of specific type component
|
|
141
215
|
* - **CN:** 具体类型组件的接口
|
|
142
216
|
*/
|
|
143
|
-
export type TypedConfirmActionInterface<
|
|
217
|
+
export type TypedConfirmActionInterface<TriggerProp extends object, Event extends keyof TriggerProp> = ComponentType<PropsWithoutRef<TypedConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef>>;
|
|
144
218
|
/**
|
|
145
219
|
* - **EN:** Props definition of specific type component
|
|
146
220
|
* - **CN:** 具体类型组件的Props定义
|
|
147
221
|
*/
|
|
148
|
-
type TypedConfirmActionProps<
|
|
222
|
+
type TypedConfirmActionProps<TriggerProp extends object, Event extends keyof TriggerProp> = Omit<ConfirmActionProps<TriggerProp, Event>, 'triggerComponent' | 'triggerEvent'>;
|
|
149
223
|
export type ConfirmActionWithStatic = GenericConfirmActionInterface & {
|
|
150
224
|
/**
|
|
151
225
|
* - **EN:** Confirm box with button trigger
|
|
@@ -163,9 +237,4 @@ export type ConfirmActionWithStatic = GenericConfirmActionInterface & {
|
|
|
163
237
|
*/
|
|
164
238
|
Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;
|
|
165
239
|
};
|
|
166
|
-
/**
|
|
167
|
-
* - **EN:** Confirm box component with trigger
|
|
168
|
-
* - **CN:** 带触发器的确认框组件
|
|
169
|
-
*/
|
|
170
|
-
declare const ConfirmAction: ConfirmActionWithStatic;
|
|
171
240
|
export default ConfirmAction;
|
|
@@ -133,12 +133,13 @@ var genRenderer = (defaultProps) => {
|
|
|
133
133
|
content: coloredText(content, contentColor),
|
|
134
134
|
icon: coloredText(icon, iconColor ?? fallbackColor ?? "warning"),
|
|
135
135
|
autoFocusButton: null,
|
|
136
|
+
closable: true,
|
|
136
137
|
okButtonProps: okProps,
|
|
137
138
|
cancelButtonProps: cancelProps,
|
|
138
139
|
onOk: async () => {
|
|
139
140
|
try {
|
|
140
141
|
api.update({
|
|
141
|
-
closable:
|
|
142
|
+
closable: false,
|
|
142
143
|
okButtonProps: {
|
|
143
144
|
loading: true,
|
|
144
145
|
...okProps
|
|
@@ -152,7 +153,7 @@ var genRenderer = (defaultProps) => {
|
|
|
152
153
|
afterOk == null ? void 0 : afterOk(result);
|
|
153
154
|
} finally {
|
|
154
155
|
api.update({
|
|
155
|
-
closable:
|
|
156
|
+
closable: true,
|
|
156
157
|
okButtonProps: {
|
|
157
158
|
loading: false,
|
|
158
159
|
...okProps
|
|
@@ -190,44 +191,68 @@ var genRenderer = (defaultProps) => {
|
|
|
190
191
|
Render.displayName = "ConfirmAction";
|
|
191
192
|
return Render;
|
|
192
193
|
};
|
|
193
|
-
var withDefaultConfirmActionProps = (
|
|
194
|
-
const WithDefaultProps = (0, import_react.forwardRef)(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
...
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
194
|
+
var withDefaultConfirmActionProps = (RenderComponent, defaultProps) => {
|
|
195
|
+
const WithDefaultProps = (0, import_react.forwardRef)(
|
|
196
|
+
(props, ref) => {
|
|
197
|
+
const actualProps = props;
|
|
198
|
+
const useDefaultProps = typeof defaultProps === "function" ? defaultProps : () => defaultProps;
|
|
199
|
+
const defaults = useDefaultProps(actualProps);
|
|
200
|
+
const mergedProps = typeof defaultProps === "function" ? {
|
|
201
|
+
...actualProps,
|
|
202
|
+
...defaults,
|
|
203
|
+
triggerProps: {
|
|
204
|
+
...actualProps.triggerProps,
|
|
205
|
+
...defaults == null ? void 0 : defaults.triggerProps
|
|
206
|
+
}
|
|
207
|
+
} : {
|
|
208
|
+
...defaults,
|
|
209
|
+
...actualProps,
|
|
210
|
+
triggerProps: {
|
|
211
|
+
...defaults == null ? void 0 : defaults.triggerProps,
|
|
212
|
+
...actualProps.triggerProps
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return /* @__PURE__ */ React.createElement(RenderComponent, { ref, ...mergedProps });
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
WithDefaultProps.displayName = "ForwardRef(WithDefaultProps)";
|
|
206
219
|
return WithDefaultProps;
|
|
207
220
|
};
|
|
208
221
|
var renderConfirmAction = genRenderer({
|
|
209
222
|
confirmType: "normal"
|
|
210
223
|
});
|
|
211
224
|
var forwarded = (0, import_react.forwardRef)(renderConfirmAction);
|
|
212
|
-
forwarded.displayName = "
|
|
225
|
+
forwarded.displayName = "ForwardRef(ConfirmAction)";
|
|
213
226
|
var ConfirmAction = forwarded;
|
|
214
|
-
ConfirmAction.Button = withDefaultConfirmActionProps(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
triggerEvent: "onChange",
|
|
222
|
-
triggerProps: {}
|
|
223
|
-
});
|
|
224
|
-
ConfirmAction.Link = withDefaultConfirmActionProps(forwarded, {
|
|
225
|
-
triggerComponent: import_antd.Typography.Link,
|
|
226
|
-
triggerEvent: "onClick",
|
|
227
|
-
triggerProps: {
|
|
228
|
-
style: { whiteSpace: "nowrap" }
|
|
227
|
+
ConfirmAction.Button = withDefaultConfirmActionProps(
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
+
forwarded,
|
|
230
|
+
{
|
|
231
|
+
triggerComponent: import_antd.Button,
|
|
232
|
+
triggerEvent: "onClick",
|
|
233
|
+
triggerProps: {}
|
|
229
234
|
}
|
|
230
|
-
|
|
235
|
+
);
|
|
236
|
+
ConfirmAction.Switch = withDefaultConfirmActionProps(
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
238
|
+
forwarded,
|
|
239
|
+
{
|
|
240
|
+
triggerComponent: import_antd.Switch,
|
|
241
|
+
triggerEvent: "onChange",
|
|
242
|
+
triggerProps: {}
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
ConfirmAction.Link = withDefaultConfirmActionProps(
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
247
|
+
forwarded,
|
|
248
|
+
{
|
|
249
|
+
triggerComponent: import_antd.Typography.Link,
|
|
250
|
+
triggerEvent: "onClick",
|
|
251
|
+
triggerProps: {
|
|
252
|
+
style: { whiteSpace: "nowrap" }
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
);
|
|
231
256
|
var ConfirmAction_default = ConfirmAction;
|
|
232
257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
233
258
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfirmAction/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useRef, useState } from 'react';\nimport type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';\nimport { App, Button, Modal, Switch, Typography } from 'antd';\nimport type { ModalFunc } from 'antd/es/modal/confirm';\nimport type confirm from 'antd/es/modal/confirm';\nimport useToken from 'antd/es/theme/useToken';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport useContextValidator from '../../hooks/useContextValidator';\nimport useLocalizedText from '../../hooks/useLocalizedText';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport ReactEasyContext from '../ConfigProvider/context';\n\nexport type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ModalFuncProps, 'onOk'> &\n ConfirmActionTrigger<TP, E> & {\n /**\n * - **EN:** Whether to display in red danger mode, which will automatically affect the color of\n * the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the\n * defaults is `true`.\n * - You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override\n * - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。\n * - 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖\n */\n danger?: boolean;\n /**\n * - **EN:** The color of confirm box title, default is `warning`\n * - **CN:** 弹框标题颜色,默认`warning`\n */\n titleColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box content\n * - **CN:** 弹框内容文本颜色\n */\n contentColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box title icon, default is the same as `titleColor`\n * - **CN:** 弹框标题图标颜色,默认与`titleColor`相同\n */\n iconColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** Callback when click confirm button\n * - **CN:** 点击确认按钮的回调\n */\n // @ts-expect-error: because TP[E] should be casted to function type\n onOk?: (...args: Parameters<TP[E]>) => unknown | Promise<unknown>;\n /**\n * - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return\n * value of `onOk`\n * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface ConfirmActionTrigger<TP extends object, E extends keyof TP> {\n /**\n * - **EN:** Trigger component, trigger to show confirm box\n * - **CN:** 触发器组件,触发显示确认弹框\n */\n triggerComponent?: ComponentType<TP>;\n /**\n * - **EN:** Props of trigger component\n * - **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP;\n /**\n * - **EN:** The event name that triggers the dialog\n * - **CN:** 触发弹窗的事件名称\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * - **EN:** Custom trigger content\n * - **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ConfirmActionRef = ReturnType<typeof confirm> & {\n /**\n * - **EN:** Show confirm box\n * - **CN:** 显示确认弹框\n */\n show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;\n};\n\n/**\n * - **EN:** Generate a confirm box component\n * - **CN:** 生成一个确认弹框组件\n *\n * @param defaultProps Default props | 默认属性\n *\n * @returns Component render method | 组件render方法\n */\nexport const genRenderer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' }\n) => {\n const Render = <TP extends object, E extends keyof TP>(\n props: ConfirmActionProps<TP, E>,\n ref: ForwardedRef<ConfirmActionRef>\n ) => {\n const { confirmType, ...restDefaults } = defaultProps;\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...restDefaults,\n ...props,\n okButtonProps: {\n ...restDefaults.okButtonProps,\n ...props.okButtonProps,\n },\n cancelButtonProps: {\n ...restDefaults.cancelButtonProps,\n ...props.cancelButtonProps,\n },\n bodyProps: {\n ...restDefaults.bodyProps,\n ...props.bodyProps,\n },\n maskProps: {\n ...restDefaults.maskProps,\n ...props.maskProps,\n },\n wrapProps: {\n ...restDefaults.wrapProps,\n ...props.wrapProps,\n },\n triggerProps: {\n ...restDefaults.triggerProps,\n ...props.triggerProps,\n style: {\n ...restDefaults.triggerProps?.style,\n ...(props.triggerProps && 'style' in props.triggerProps && typeof props.triggerProps.style === 'object'\n ? props.triggerProps.style\n : {}),\n },\n } as TP,\n };\n const context = useContext(ReactEasyContext);\n const defaultTitle = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmTitle : context.defaultConfirmTitle\n );\n const defaultContent = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmContent : context.defaultConfirmContent\n );\n const {\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n danger,\n title = defaultTitle,\n content = defaultContent,\n titleColor,\n contentColor,\n icon,\n iconColor,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n children,\n ...restProps\n } = mergedProps;\n\n useContextValidator();\n\n const app = App.useApp();\n // @ts-expect-error: because app may return a stub object when App is not used\n const modal = app.modal?.confirm ? app.modal : Modal;\n const { localize } = useContext(ReactEasyContext);\n const [, token] = useToken();\n const [confirmApi, setConfirmApi] = useState<ReturnType<typeof confirm>>();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n\n const fallbackColor = danger ? 'danger' : undefined;\n // Text with color\n const coloredText = (text: ReactNode, color?: TextProps['type'] | 'primary') => {\n const textContent = typeof text === 'string' ? (localize?.(text) ?? text) : text;\n if (!color) {\n return textContent;\n }\n if (color === 'primary') {\n return <Typography.Text style={{ color: token.colorPrimary }}>{textContent}</Typography.Text>;\n }\n return textContent ? <Typography.Text type={color}>{textContent}</Typography.Text> : undefined;\n };\n\n // Show confirm box\n const showConfirm: ConfirmActionRef['show'] = useRefFunction(() => {\n const okProps: ButtonProps = {\n ...(danger ? { type: 'primary', danger: true } : {}),\n ...(okButtonProps ?? {}),\n };\n const cancelProps: ButtonProps = {\n ...(cancelButtonProps ?? {}),\n };\n const api = modal.confirm({\n title: coloredText(title, titleColor ?? fallbackColor ?? 'warning'),\n content: coloredText(content, contentColor),\n icon: coloredText(icon, iconColor ?? fallbackColor ?? 'warning'),\n autoFocusButton: null,\n okButtonProps: okProps,\n cancelButtonProps: cancelProps,\n onOk: async () => {\n try {\n api.update({\n closable: true,\n okButtonProps: {\n loading: true,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: true,\n ...cancelProps,\n },\n });\n const result = await onOk?.(...((triggerEventArgsRef.current ?? []) as Parameters<typeof onOk>));\n afterOk?.(result);\n } finally {\n api.update({\n closable: false,\n okButtonProps: {\n loading: false,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: false,\n ...cancelProps,\n },\n });\n }\n },\n ...restProps,\n });\n setConfirmApi(api);\n return api;\n });\n\n // Output ref\n useImperativeHandle(ref, () => ({ show: showConfirm, ...confirmApi! }), [showConfirm, confirmApi]);\n\n // Render trigger component\n return (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n const api = showConfirm();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args, { api });\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n );\n };\n Render.displayName = 'ConfirmAction';\n return Render;\n};\n\n/**\n * - **EN:** Add default properties to the ConfirmAction component\n * - **CN:** 给ConfirmAction组件添加默认属性\n *\n * @param WrappedComponent ConfirmAction component | ConfirmAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultConfirmActionProps = <TP extends object, E extends keyof TP>(\n WrappedComponent: ComponentType<PropsWithoutRef<ConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>,\n defaultProps?: Partial<ConfirmActionProps<TP, E>>\n) => {\n const WithDefaultProps = forwardRef<ConfirmActionRef, ConfirmActionProps<TP, E>>((props, ref) => {\n const mergedProps: ConfirmActionProps<TP, E> = {\n ...defaultProps,\n ...props,\n triggerProps: {\n ...defaultProps?.triggerProps,\n ...props.triggerProps,\n } as TP,\n };\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return WithDefaultProps;\n};\n\nconst renderConfirmAction = genRenderer({\n confirmType: 'normal',\n});\nconst forwarded = forwardRef(renderConfirmAction);\nforwarded.displayName = 'ForwardedRef(ConfirmAction)';\n\n/**\n * - **EN:** Interface of generic type component\n * - **CN:** 泛型组件的接口\n */\nexport type GenericConfirmActionInterface = <TP extends object, E extends keyof TP>(\n props: PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n) => ReactElement;\n\n/**\n * - **EN:** Interface of specific type component\n * - **CN:** 具体类型组件的接口\n */\nexport type TypedConfirmActionInterface<TP extends object, E extends keyof TP> = ComponentType<\n PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>\n>;\n\n/**\n * - **EN:** Props definition of specific type component\n * - **CN:** 具体类型组件的Props定义\n */\ntype TypedConfirmActionProps<TP extends object, E extends keyof TP> = Omit<\n ConfirmActionProps<TP, E>,\n 'triggerComponent' | 'triggerEvent'\n>;\nexport type ConfirmActionWithStatic = GenericConfirmActionInterface & {\n /**\n * - **EN:** Confirm box with button trigger\n * - **CN:** 按钮类型的确认框\n */\n Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;\n /**\n * - **EN:** Confirm box with switch trigger\n * - **CN:** 开关类型的确认框\n */\n Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;\n /**\n * - **EN:** Confirm box with link trigger\n * - **CN:** 链接类型的确认框\n */\n Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;\n};\n\n/**\n * - **EN:** Confirm box component with trigger\n * - **CN:** 带触发器的确认框组件\n */\nconst ConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n// Type of button\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Button = withDefaultConfirmActionProps<ButtonProps, 'onClick'>(forwarded as any, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n});\n// Type of switch\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Switch = withDefaultConfirmActionProps<SwitchProps, 'onChange'>(forwarded as any, {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n});\n// Type of link\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nConfirmAction.Link = withDefaultConfirmActionProps<LinkProps, 'onClick'>(forwarded as any, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n});\n\nexport default ConfirmAction;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8E;AAE9E,kBAAuD;AAGvD,sBAAqB;AAGrB,iCAAgC;AAChC,8BAA6B;AAC7B,4BAA2B;AAC3B,qBAA6B;
|
|
4
|
+
"sourcesContent": ["import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useRef, useState } from 'react';\nimport type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';\nimport { App, Button, Modal, Switch, Typography } from 'antd';\nimport type { ModalFunc } from 'antd/es/modal/confirm';\nimport type confirm from 'antd/es/modal/confirm';\nimport useToken from 'antd/es/theme/useToken';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport type { TextProps } from 'antd/es/typography/Text';\nimport useContextValidator from '../../hooks/useContextValidator';\nimport useLocalizedText from '../../hooks/useLocalizedText';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport ReactEasyContext from '../ConfigProvider/context';\n\nexport type ConfirmActionProps<TriggerProp extends object, Event extends keyof TriggerProp> = Omit<\n ModalFuncProps,\n 'onOk'\n> &\n ConfirmActionTrigger<TriggerProp, Event> & {\n /**\n * - **EN:** Whether to display in red danger mode, which will automatically affect the color of\n * the title, icon, and confirm button. Default is `false`, for DeleteConfirmAction, the\n * defaults is `true`.\n *\n * > You can explicitly set `titleColor`, `iconColor`, and `okButtonProps.type` to override\n *\n * - **CN:** 是否显示为红色危险模式,会自动影响标题、图标和确认按钮的颜色。默认`false`,DeleteConfirmAction组件的默认值为`true`。\n *\n * > 可以显式设置`titleColor`、`iconColor`和`okButtonProps.type`来覆盖\n */\n danger?: boolean;\n /**\n * - **EN:** The color of confirm box title, default is `warning`\n * - **CN:** 弹框标题颜色,默认`warning`\n */\n titleColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box content\n * - **CN:** 弹框内容文本颜色\n */\n contentColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** The color of confirm box title icon, default is the same as `titleColor`\n * - **CN:** 弹框标题图标颜色,默认与`titleColor`相同\n */\n iconColor?: TextProps['type'] | 'primary';\n /**\n * - **EN:** Callback when click confirm button\n * - **CN:** 点击确认按钮的回调\n */\n // @ts-expect-error: because TriggerProp[Event] should be casted to function type\n onOk?: (...args: Parameters<TriggerProp[Event]>) => unknown | Promise<unknown>;\n /**\n * - **EN:** Callback after confirm event, won't trigger if failed, the argument is the return\n * value of `onOk`\n * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface ConfirmActionTrigger<TriggerProp extends object, Event extends keyof TriggerProp> {\n /**\n * - **EN:** Trigger component, trigger to show confirm box\n * - **CN:** 触发器组件,触发显示确认弹框\n */\n triggerComponent?: ComponentType<TriggerProp>;\n /**\n * - **EN:** Props of trigger component\n * - **CN:** 触发器组件的Props属性\n */\n triggerProps?: TriggerProp;\n /**\n * **EN:** The event name that triggers the dialog\n *\n * **CN:** 触发弹窗的事件名称\n *\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: Event;\n /**\n * - **EN:** Custom trigger content\n * - **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type ConfirmActionRef<R = {}> = R &\n ReturnType<ModalFunc> & {\n /**\n * - **EN:** Show confirm box\n * - **CN:** 显示确认弹框\n */\n show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;\n };\n\n/**\n * - **EN:** Generate a confirm box component\n * - **CN:** 生成一个确认弹框组件\n *\n * @param defaultProps Default props | 默认属性\n *\n * @returns Component render method | 组件render方法\n */\nexport const genRenderer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' }\n) => {\n const Render = <TriggerProp extends object, Event extends keyof TriggerProp>(\n props: ConfirmActionProps<TriggerProp, Event>,\n ref: ForwardedRef<ConfirmActionRef>\n ) => {\n const { confirmType, ...restDefaults } = defaultProps;\n const mergedProps: ConfirmActionProps<TriggerProp, Event> = {\n ...restDefaults,\n ...props,\n okButtonProps: {\n ...restDefaults.okButtonProps,\n ...props.okButtonProps,\n },\n cancelButtonProps: {\n ...restDefaults.cancelButtonProps,\n ...props.cancelButtonProps,\n },\n bodyProps: {\n ...restDefaults.bodyProps,\n ...props.bodyProps,\n },\n maskProps: {\n ...restDefaults.maskProps,\n ...props.maskProps,\n },\n wrapProps: {\n ...restDefaults.wrapProps,\n ...props.wrapProps,\n },\n triggerProps: {\n ...restDefaults.triggerProps,\n ...props.triggerProps,\n style: {\n ...restDefaults.triggerProps?.style,\n ...(props.triggerProps && 'style' in props.triggerProps && typeof props.triggerProps.style === 'object'\n ? props.triggerProps.style\n : {}),\n },\n } as TriggerProp,\n };\n const context = useContext(ReactEasyContext);\n const defaultTitle = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmTitle : context.defaultConfirmTitle\n );\n const defaultContent = useLocalizedText(\n confirmType === 'delete' ? context.defaultDeletionConfirmContent : context.defaultConfirmContent\n );\n const {\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as Event,\n triggerProps,\n danger,\n title = defaultTitle,\n content = defaultContent,\n titleColor,\n contentColor,\n icon,\n iconColor,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n children,\n ...restProps\n } = mergedProps;\n\n useContextValidator();\n\n const app = App.useApp();\n // @ts-expect-error: because app may return a stub object when App is not used\n const modal = app.modal?.confirm ? app.modal : Modal;\n const { localize } = useContext(ReactEasyContext);\n const [, token] = useToken();\n const [confirmApi, setConfirmApi] = useState<ReturnType<typeof confirm>>();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n\n const fallbackColor = danger ? 'danger' : undefined;\n // Text with color\n const coloredText = (text: ReactNode, color?: TextProps['type'] | 'primary') => {\n const textContent = typeof text === 'string' ? (localize?.(text) ?? text) : text;\n if (!color) {\n return textContent;\n }\n if (color === 'primary') {\n return <Typography.Text style={{ color: token.colorPrimary }}>{textContent}</Typography.Text>;\n }\n return textContent ? <Typography.Text type={color}>{textContent}</Typography.Text> : undefined;\n };\n\n // Show confirm box\n const showConfirm: ConfirmActionRef['show'] = useRefFunction(() => {\n const okProps: ButtonProps = {\n ...(danger ? { type: 'primary', danger: true } : {}),\n ...(okButtonProps ?? {}),\n };\n const cancelProps: ButtonProps = {\n ...(cancelButtonProps ?? {}),\n };\n const api = modal.confirm({\n title: coloredText(title, titleColor ?? fallbackColor ?? 'warning'),\n content: coloredText(content, contentColor),\n icon: coloredText(icon, iconColor ?? fallbackColor ?? 'warning'),\n autoFocusButton: null,\n closable: true,\n okButtonProps: okProps,\n cancelButtonProps: cancelProps,\n onOk: async () => {\n try {\n api.update({\n closable: false,\n okButtonProps: {\n loading: true,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: true,\n ...cancelProps,\n },\n });\n const result = await onOk?.(...((triggerEventArgsRef.current ?? []) as Parameters<typeof onOk>));\n afterOk?.(result);\n } finally {\n api.update({\n closable: true,\n okButtonProps: {\n loading: false,\n ...okProps,\n },\n cancelButtonProps: {\n disabled: false,\n ...cancelProps,\n },\n });\n }\n },\n ...restProps,\n });\n setConfirmApi(api);\n return api;\n });\n\n // Output ref\n useImperativeHandle(ref, () => ({ show: showConfirm, ...confirmApi! }), [showConfirm, confirmApi]);\n\n // Render trigger component\n return (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n const api = showConfirm();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args, { api });\n }\n },\n }\n : {}) as TriggerProp)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n );\n };\n Render.displayName = 'ConfirmAction';\n return Render;\n};\n\n/**\n * - **EN:** Add default properties to the ConfirmAction component\n * - **CN:** 给ConfirmAction组件添加默认属性\n *\n * @param RenderComponent The component that renders the ConfirmAction | 实际渲染组件\n * @param defaultProps Add some default values based on the props passed to the component |\n * 在组件传入的props基础上,添加一些默认值\n */\nexport const withDefaultConfirmActionProps = <\n P extends ActionCompConstraint,\n TriggerProp extends object,\n Event extends keyof TriggerProp,\n Ref extends object,\n>(\n RenderComponent: ComponentType<\n PropsWithoutRef<P & ConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef<Ref>>\n >,\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>>)\n) => {\n const WithDefaultProps = forwardRef(\n (\n props: PropsWithoutRef<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>>,\n ref: ForwardedRef<ConfirmActionRef<Ref>>\n ) => {\n const actualProps = props as Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event>;\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps(actualProps);\n const mergedProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<TriggerProp, Event> =\n typeof defaultProps === 'function'\n ? {\n ...actualProps,\n ...defaults,\n triggerProps: {\n ...actualProps.triggerProps,\n ...defaults?.triggerProps,\n },\n }\n : {\n ...defaults,\n ...actualProps,\n triggerProps: {\n ...defaults?.triggerProps,\n ...actualProps.triggerProps,\n },\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return <RenderComponent ref={ref} {...(mergedProps as any)} />;\n }\n );\n WithDefaultProps.displayName = 'ForwardRef(WithDefaultProps)';\n return WithDefaultProps;\n};\n\nconst renderConfirmAction = genRenderer({\n confirmType: 'normal',\n});\nconst forwarded = forwardRef(renderConfirmAction);\nforwarded.displayName = 'ForwardRef(ConfirmAction)';\n\n/**\n * - **EN:** Confirm box component with trigger\n * - **CN:** 带触发器的确认框组件\n */\nconst ConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n// Type of button\n// eslint-disable-next-line @typescript-eslint/ban-types\nConfirmAction.Button = withDefaultConfirmActionProps<ActionCompConstraint, ButtonProps, 'onClick', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n }\n);\n// Type of switch\n// eslint-disable-next-line @typescript-eslint/ban-types\nConfirmAction.Switch = withDefaultConfirmActionProps<ActionCompConstraint, SwitchProps, 'onChange', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n);\n// Type of link\n// eslint-disable-next-line @typescript-eslint/ban-types\nConfirmAction.Link = withDefaultConfirmActionProps<ActionCompConstraint, LinkProps, 'onClick', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n }\n);\n\nexport interface ActionCompConstraint extends ReturnType<ModalFunc> {\n /**\n * - **EN:** Register the confirm action save event, the passed callback function will be called\n * when the confirm button is clicked, supports asynchronous saving\n * - **CN:** 注册确认框保存事件,传入的回调函数会在点击确认按钮时调用,支持异步保存\n *\n * @param handler Event handler | 事件处理函数\n */\n setOK: (\n handler: (\n /**\n * - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get\n * the value of the switch; for the `Button` type trigger, you can get the click event\n * object of the button\n * - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n ...triggerEventArgs: any[]\n ) => unknown | Promise<unknown>\n ) => void;\n\n /**\n * - **EN:** Default trigger DOM element used to render the trigger\n * - **CN:** 默认的触发器组件的 DOM 元素,用于渲染触发器\n */\n triggerDom: ReactNode;\n}\n\n/**\n * - **EN:** Interface of generic type component\n * - **CN:** 泛型组件的接口\n */\nexport type GenericConfirmActionInterface = <TriggerProp extends object, Event extends keyof TriggerProp>(\n props: PropsWithoutRef<TypedConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef>\n) => ReactElement;\n\n/**\n * - **EN:** Interface of specific type component\n * - **CN:** 具体类型组件的接口\n */\nexport type TypedConfirmActionInterface<TriggerProp extends object, Event extends keyof TriggerProp> = ComponentType<\n PropsWithoutRef<TypedConfirmActionProps<TriggerProp, Event>> & RefAttributes<ConfirmActionRef>\n>;\n\n/**\n * - **EN:** Props definition of specific type component\n * - **CN:** 具体类型组件的Props定义\n */\ntype TypedConfirmActionProps<TriggerProp extends object, Event extends keyof TriggerProp> = Omit<\n ConfirmActionProps<TriggerProp, Event>,\n 'triggerComponent' | 'triggerEvent'\n>;\nexport type ConfirmActionWithStatic = GenericConfirmActionInterface & {\n /**\n * - **EN:** Confirm box with button trigger\n * - **CN:** 按钮类型的确认框\n */\n Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;\n /**\n * - **EN:** Confirm box with switch trigger\n * - **CN:** 开关类型的确认框\n */\n Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;\n /**\n * - **EN:** Confirm box with link trigger\n * - **CN:** 链接类型的确认框\n */\n Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;\n};\n\nexport default ConfirmAction;\n"],
|
|
5
|
+
"mappings": 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efFunction"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ComponentType, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
|
|
2
|
+
import type { ActionCompConstraint, ConfirmActionProps, ConfirmActionRef } from '.';
|
|
3
|
+
import { type ButtonProps, type SwitchProps } from 'antd';
|
|
4
|
+
import type { LinkProps } from 'antd/es/typography/Link';
|
|
5
|
+
/**
|
|
6
|
+
* - **EN:** Generate a confirm box component with custom trigger and default props
|
|
7
|
+
* - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性
|
|
8
|
+
*
|
|
9
|
+
* @param actionComponent Custom trigger component | 自定义触发器组件
|
|
10
|
+
* @param defaultProps Default properties of the confirm box | 确认弹框的默认属性
|
|
11
|
+
*/
|
|
12
|
+
export default function withConfirmAction<P extends ActionCompConstraint, OuterTriggerProp extends object, OuterEvent extends keyof OuterTriggerProp, Ref extends object>(ActionComponent: ActionComponentInterface<P, Ref>, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)): WithGenericTriggers<P, Ref>;
|
|
13
|
+
export declare function withConfirmActionInternal<P extends ActionCompConstraint, OuterTriggerProp extends object, OuterEvent extends keyof OuterTriggerProp, Ref extends object>(ActionComponent: ActionComponentInterface<P, Ref>, renderDefaultProps: Partial<ConfirmActionProps<any, never>> & {
|
|
14
|
+
confirmType: 'normal' | 'delete';
|
|
15
|
+
}, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)): WithGenericTriggers<P, Ref>;
|
|
16
|
+
/**
|
|
17
|
+
* - **EN:** ModalAction component type
|
|
18
|
+
* - **CN:** ModalAction组件的类型
|
|
19
|
+
*/
|
|
20
|
+
export type ActionComponentInterface<P extends ActionCompConstraint, Ref extends object> = ComponentType<P & RefAttributes<ConfirmActionRef<Ref>>>;
|
|
21
|
+
type WithGenericTriggers<P extends ActionCompConstraint, Ref extends object> = (<TriggerProp extends object, Event extends keyof TriggerProp>(props: PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event> & RefAttributes<ConfirmActionRef<Ref>>) => ReactNode) & TypedTriggers<P, Ref>;
|
|
22
|
+
/**
|
|
23
|
+
* - **EN:** Built-in trigger types (specified form components)
|
|
24
|
+
* - **CN:** 内置的几种触发器类型(已指定表单组件)
|
|
25
|
+
*/
|
|
26
|
+
export interface TypedTriggers<P extends ActionCompConstraint, Ref extends object> {
|
|
27
|
+
/**
|
|
28
|
+
* - **EN:** Dialog with button type trigger
|
|
29
|
+
* - **CN:** 按钮类型的弹窗
|
|
30
|
+
*/
|
|
31
|
+
Button: ConfirmActionWithTrigger<P, ButtonProps, 'onClick', Ref>;
|
|
32
|
+
/**
|
|
33
|
+
* - **EN:** Dialog with switch type trigger
|
|
34
|
+
* - **CN:** 开关类型的弹窗
|
|
35
|
+
*/
|
|
36
|
+
Switch: ConfirmActionWithTrigger<P, SwitchProps, 'onChange', Ref>;
|
|
37
|
+
/**
|
|
38
|
+
* - **EN:** Dialog with link type trigger
|
|
39
|
+
* - **CN:** 链接类型的弹窗
|
|
40
|
+
*/
|
|
41
|
+
Link: ConfirmActionWithTrigger<P, LinkProps, 'onClick', Ref>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* - **EN:** ModalAction with specified trigger type (specified form component)
|
|
45
|
+
* - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
|
|
46
|
+
*/
|
|
47
|
+
type ConfirmActionWithTrigger<P extends ActionCompConstraint, TriggerProp extends object, Event extends keyof TriggerProp, Ref extends object, OMIT extends string = never> = ComponentType<Omit<PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ConfirmActionRef<Ref>>>;
|
|
48
|
+
export {};
|