@tiny-codes/react-easy 1.0.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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +194 -0
- package/README.zh-CN.md +190 -0
- package/es/components/ConfigProvider/context.d.ts +49 -0
- package/es/components/ConfigProvider/context.js +5 -0
- package/es/components/ConfigProvider/context.js.map +1 -0
- package/es/components/ConfigProvider/index.d.ts +12 -0
- package/es/components/ConfigProvider/index.js +24 -0
- package/es/components/ConfigProvider/index.js.map +1 -0
- package/es/components/ConfirmAction/index.d.ts +178 -0
- package/es/components/ConfirmAction/index.js +150 -0
- package/es/components/ConfirmAction/index.js.map +1 -0
- package/es/components/DeleteConfirmAction/index.d.ts +8 -0
- package/es/components/DeleteConfirmAction/index.js +55 -0
- package/es/components/DeleteConfirmAction/index.js.map +1 -0
- package/es/components/ModalAction/index.d.ts +237 -0
- package/es/components/ModalAction/index.js +259 -0
- package/es/components/ModalAction/index.js.map +1 -0
- package/es/components/index.d.ts +9 -0
- package/es/components/index.js +9 -0
- package/es/components/index.js.map +1 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/index.js.map +1 -0
- package/es/hooks/useLocalizedText.d.ts +11 -0
- package/es/hooks/useLocalizedText.js +16 -0
- package/es/hooks/useLocalizedText.js.map +1 -0
- package/es/hooks/useRefFunction.d.ts +13 -0
- package/es/hooks/useRefFunction.js +22 -0
- package/es/hooks/useRefFunction.js.map +1 -0
- package/es/hooks/useValidateContext.d.ts +2 -0
- package/es/hooks/useValidateContext.js +16 -0
- package/es/hooks/useValidateContext.js.map +1 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -0
- package/es/index.js.map +1 -0
- package/lib/components/ConfigProvider/context.d.ts +49 -0
- package/lib/components/ConfigProvider/context.js +5 -0
- package/lib/components/ConfigProvider/context.js.map +1 -0
- package/lib/components/ConfigProvider/index.d.ts +12 -0
- package/lib/components/ConfigProvider/index.js +24 -0
- package/lib/components/ConfigProvider/index.js.map +1 -0
- package/lib/components/ConfirmAction/index.d.ts +178 -0
- package/lib/components/ConfirmAction/index.js +150 -0
- package/lib/components/ConfirmAction/index.js.map +1 -0
- package/lib/components/DeleteConfirmAction/index.d.ts +8 -0
- package/lib/components/DeleteConfirmAction/index.js +55 -0
- package/lib/components/DeleteConfirmAction/index.js.map +1 -0
- package/lib/components/ModalAction/index.d.ts +237 -0
- package/lib/components/ModalAction/index.js +259 -0
- package/lib/components/ModalAction/index.js.map +1 -0
- package/lib/components/index.d.ts +9 -0
- package/lib/components/index.js +9 -0
- package/lib/components/index.js.map +1 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useLocalizedText.d.ts +11 -0
- package/lib/hooks/useLocalizedText.js +16 -0
- package/lib/hooks/useLocalizedText.js.map +1 -0
- package/lib/hooks/useRefFunction.d.ts +13 -0
- package/lib/hooks/useRefFunction.js +22 -0
- package/lib/hooks/useRefFunction.js.map +1 -0
- package/lib/hooks/useValidateContext.d.ts +2 -0
- package/lib/hooks/useValidateContext.js +16 -0
- package/lib/hooks/useValidateContext.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { ComponentType, ForwardedRef, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from 'react';
|
|
2
|
+
import type { ButtonProps, ModalFuncProps, SwitchProps } from 'antd';
|
|
3
|
+
import type { ModalFunc } from 'antd/es/modal/confirm';
|
|
4
|
+
import type confirm from 'antd/es/modal/confirm';
|
|
5
|
+
import type { LinkProps } from 'antd/es/typography/Link';
|
|
6
|
+
import type { TextProps } from 'antd/es/typography/Text';
|
|
7
|
+
export type ConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ModalFuncProps, 'onOk'> & ConfirmActionTrigger<TP, E> & {
|
|
8
|
+
/**
|
|
9
|
+
* **EN:** The color of confirm box title, default is `warning`
|
|
10
|
+
*
|
|
11
|
+
* **CN:** 弹框标题颜色,默认`warning`
|
|
12
|
+
*/
|
|
13
|
+
titleColor?: TextProps['type'] | 'primary';
|
|
14
|
+
/**
|
|
15
|
+
* **EN:** The color of confirm box content
|
|
16
|
+
*
|
|
17
|
+
* **CN:** 弹框内容文本颜色
|
|
18
|
+
*/
|
|
19
|
+
contentColor?: TextProps['type'] | 'primary';
|
|
20
|
+
/**
|
|
21
|
+
* **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
22
|
+
*
|
|
23
|
+
* **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
24
|
+
*/
|
|
25
|
+
iconColor?: TextProps['type'] | 'primary';
|
|
26
|
+
/**
|
|
27
|
+
* **EN:** Callback when click confirm button
|
|
28
|
+
*
|
|
29
|
+
* **CN:** 点击确认按钮的回调
|
|
30
|
+
*/
|
|
31
|
+
onOk?: (...args: Parameters<TP[E]>) => unknown | Promise<unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
34
|
+
* value of `onOk`
|
|
35
|
+
*
|
|
36
|
+
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
37
|
+
*/
|
|
38
|
+
afterOk?: (data?: any) => void;
|
|
39
|
+
};
|
|
40
|
+
export interface ConfirmActionTrigger<TP extends object, E extends keyof TP> {
|
|
41
|
+
/**
|
|
42
|
+
* **EN:** Trigger component, trigger to show confirm box
|
|
43
|
+
*
|
|
44
|
+
* **CN:** 触发器组件,触发显示确认弹框
|
|
45
|
+
*/
|
|
46
|
+
triggerComponent?: ComponentType<TP>;
|
|
47
|
+
/**
|
|
48
|
+
* **EN:** Props of trigger component
|
|
49
|
+
*
|
|
50
|
+
* **CN:** 触发器组件的Props属性
|
|
51
|
+
*/
|
|
52
|
+
triggerProps?: TP;
|
|
53
|
+
/**
|
|
54
|
+
* **EN:** The event name that triggers the dialog
|
|
55
|
+
*
|
|
56
|
+
* **CN:** 触发弹窗的事件名称
|
|
57
|
+
*
|
|
58
|
+
* - `Button`: 'onClick'
|
|
59
|
+
* - `Switch`: 'onChange'
|
|
60
|
+
* - `Link`: 'onClick'
|
|
61
|
+
*/
|
|
62
|
+
triggerEvent?: E;
|
|
63
|
+
/**
|
|
64
|
+
* **EN:** Custom trigger content
|
|
65
|
+
*
|
|
66
|
+
* **CN:** 自定义触发器内容
|
|
67
|
+
*/
|
|
68
|
+
children?: ReactNode;
|
|
69
|
+
}
|
|
70
|
+
export type ConfirmActionRef = ReturnType<typeof confirm> & {
|
|
71
|
+
/**
|
|
72
|
+
* **EN:** Show confirm box
|
|
73
|
+
*
|
|
74
|
+
* **CN:** 显示确认弹框
|
|
75
|
+
*/
|
|
76
|
+
show: (props?: Parameters<ModalFunc>[0]) => ReturnType<ModalFunc>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* **EN:** Generate a confirm box component
|
|
80
|
+
*
|
|
81
|
+
* **CN:** 生成一个确认弹框组件
|
|
82
|
+
*
|
|
83
|
+
* @param defaultProps Default props | 默认属性
|
|
84
|
+
*
|
|
85
|
+
* @returns Component render method | 组件render方法
|
|
86
|
+
*/
|
|
87
|
+
export declare const genRenderer: (defaultProps: Partial<ConfirmActionProps<any, never>> & {
|
|
88
|
+
confirmType: "normal" | "delete";
|
|
89
|
+
}) => {
|
|
90
|
+
<TP extends object, E extends keyof TP>(props: ConfirmActionProps<TP, E>, ref: ForwardedRef<ConfirmActionRef>): import("react/jsx-runtime").JSX.Element;
|
|
91
|
+
displayName: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* **EN:** Add default properties to the ConfirmAction component
|
|
95
|
+
*
|
|
96
|
+
* **CN:** 给ConfirmAction组件添加默认属性
|
|
97
|
+
*
|
|
98
|
+
* @param WrappedComponent ConfirmAction component | ConfirmAction组件
|
|
99
|
+
* @param defaultProps Default properties | 默认属性
|
|
100
|
+
*/
|
|
101
|
+
export declare const withDefaultConfirmActionProps: <TP extends object, E extends keyof TP>(WrappedComponent: ComponentType<PropsWithoutRef<ConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>, defaultProps?: Partial<ConfirmActionProps<TP, E>>) => import("react").ForwardRefExoticComponent<Omit<ModalFuncProps, "onOk"> & ConfirmActionTrigger<TP, E> & {
|
|
102
|
+
/**
|
|
103
|
+
* **EN:** The color of confirm box title, default is `warning`
|
|
104
|
+
*
|
|
105
|
+
* **CN:** 弹框标题颜色,默认`warning`
|
|
106
|
+
*/
|
|
107
|
+
titleColor?: TextProps["type"] | "primary";
|
|
108
|
+
/**
|
|
109
|
+
* **EN:** The color of confirm box content
|
|
110
|
+
*
|
|
111
|
+
* **CN:** 弹框内容文本颜色
|
|
112
|
+
*/
|
|
113
|
+
contentColor?: TextProps["type"] | "primary";
|
|
114
|
+
/**
|
|
115
|
+
* **EN:** The color of confirm box title icon, default is the same as `titleColor`
|
|
116
|
+
*
|
|
117
|
+
* **CN:** 弹框标题图标颜色,默认与`titleColor`相同
|
|
118
|
+
*/
|
|
119
|
+
iconColor?: TextProps["type"] | "primary";
|
|
120
|
+
/**
|
|
121
|
+
* **EN:** Callback when click confirm button
|
|
122
|
+
*
|
|
123
|
+
* **CN:** 点击确认按钮的回调
|
|
124
|
+
*/
|
|
125
|
+
onOk?: ((...args: Parameters<TP[E]>) => unknown | Promise<unknown>) | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* **EN:** Callback after confirm event, won't trigger if failed, the argument is the return
|
|
128
|
+
* value of `onOk`
|
|
129
|
+
*
|
|
130
|
+
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
131
|
+
*/
|
|
132
|
+
afterOk?: (data?: any) => void;
|
|
133
|
+
} & RefAttributes<ConfirmActionRef>>;
|
|
134
|
+
/**
|
|
135
|
+
* **EN:** Interface of generic type component
|
|
136
|
+
*
|
|
137
|
+
* **CN:** 泛型组件的接口
|
|
138
|
+
*/
|
|
139
|
+
export type GenericConfirmActionInterface = <TP extends object, E extends keyof TP>(props: PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>) => ReactElement;
|
|
140
|
+
/**
|
|
141
|
+
* **EN:** Interface of specific type component
|
|
142
|
+
*
|
|
143
|
+
* **CN:** 具体类型组件的接口
|
|
144
|
+
*/
|
|
145
|
+
export type TypedConfirmActionInterface<TP extends object, E extends keyof TP> = ComponentType<PropsWithoutRef<TypedConfirmActionProps<TP, E>> & RefAttributes<ConfirmActionRef>>;
|
|
146
|
+
/**
|
|
147
|
+
* **EN:** Props definition of specific type component
|
|
148
|
+
*
|
|
149
|
+
* **CN:** 具体类型组件的Props定义
|
|
150
|
+
*/
|
|
151
|
+
type TypedConfirmActionProps<TP extends object, E extends keyof TP> = Omit<ConfirmActionProps<TP, E>, 'triggerComponent' | 'triggerEvent'>;
|
|
152
|
+
export type ConfirmActionWithStatic = GenericConfirmActionInterface & {
|
|
153
|
+
/**
|
|
154
|
+
* **EN:** Confirm box with button trigger
|
|
155
|
+
*
|
|
156
|
+
* **CN:** 按钮类型的确认框
|
|
157
|
+
*/
|
|
158
|
+
Button: TypedConfirmActionInterface<ButtonProps, 'onClick'>;
|
|
159
|
+
/**
|
|
160
|
+
* **EN:** Confirm box with switch trigger
|
|
161
|
+
*
|
|
162
|
+
* **CN:** 开关类型的确认框
|
|
163
|
+
*/
|
|
164
|
+
Switch: TypedConfirmActionInterface<SwitchProps, 'onChange'>;
|
|
165
|
+
/**
|
|
166
|
+
* **EN:** Confirm box with link trigger
|
|
167
|
+
*
|
|
168
|
+
* **CN:** 链接类型的确认框
|
|
169
|
+
*/
|
|
170
|
+
Link: TypedConfirmActionInterface<LinkProps, 'onClick'>;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* **EN:** Confirm box component with trigger
|
|
174
|
+
*
|
|
175
|
+
* **CN:** 带触发器的确认框组件
|
|
176
|
+
*/
|
|
177
|
+
declare const ConfirmAction: ConfirmActionWithStatic;
|
|
178
|
+
export default ConfirmAction;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { forwardRef, useContext, useImperativeHandle, useRef, useState } from 'react';
|
|
23
|
+
import { App, Button, Modal, Switch, Typography } from 'antd';
|
|
24
|
+
import useToken from 'antd/es/theme/useToken';
|
|
25
|
+
import useLocalizedText from '../../hooks/useLocalizedText';
|
|
26
|
+
import useRefFunction from '../../hooks/useRefFunction';
|
|
27
|
+
import useValidateContext from '../../hooks/useValidateContext';
|
|
28
|
+
import AntHelperContext from '../ConfigProvider/context';
|
|
29
|
+
/**
|
|
30
|
+
* **EN:** Generate a confirm box component
|
|
31
|
+
*
|
|
32
|
+
* **CN:** 生成一个确认弹框组件
|
|
33
|
+
*
|
|
34
|
+
* @param defaultProps Default props | 默认属性
|
|
35
|
+
*
|
|
36
|
+
* @returns Component render method | 组件render方法
|
|
37
|
+
*/
|
|
38
|
+
export const genRenderer = (
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
defaultProps) => {
|
|
41
|
+
const Render = (props, ref) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const { confirmType } = defaultProps, restDefaults = __rest(defaultProps, ["confirmType"]);
|
|
44
|
+
const mergedProps = Object.assign(Object.assign(Object.assign({}, restDefaults), props), { okButtonProps: Object.assign(Object.assign({}, restDefaults.okButtonProps), props.okButtonProps), cancelButtonProps: Object.assign(Object.assign({}, restDefaults.cancelButtonProps), props.cancelButtonProps), bodyProps: Object.assign(Object.assign({}, restDefaults.bodyProps), props.bodyProps), maskProps: Object.assign(Object.assign({}, restDefaults.maskProps), props.maskProps), wrapProps: Object.assign(Object.assign({}, restDefaults.wrapProps), props.wrapProps), triggerProps: Object.assign(Object.assign(Object.assign({}, restDefaults.triggerProps), props.triggerProps), { style: Object.assign(Object.assign({}, (_a = restDefaults.triggerProps) === null || _a === void 0 ? void 0 : _a.style), (props.triggerProps && 'style' in props.triggerProps && typeof props.triggerProps.style === 'object'
|
|
45
|
+
? props.triggerProps.style
|
|
46
|
+
: {})) }) });
|
|
47
|
+
const context = useContext(AntHelperContext);
|
|
48
|
+
const defaultTitle = useLocalizedText(confirmType === 'delete' ? context.defaultDeletionConfirmTitle : context.defaultConfirmTitle);
|
|
49
|
+
const defaultContent = useLocalizedText(confirmType === 'delete' ? context.defaultDeletionConfirmContent : context.defaultConfirmContent);
|
|
50
|
+
const { triggerComponent: Trigger = Button, triggerEvent = 'onClick', triggerProps, title = defaultTitle, content = defaultContent, titleColor = 'warning', contentColor, icon, iconColor, onOk, afterOk, children } = mergedProps, restProps = __rest(mergedProps, ["triggerComponent", "triggerEvent", "triggerProps", "title", "content", "titleColor", "contentColor", "icon", "iconColor", "onOk", "afterOk", "children"]);
|
|
51
|
+
useValidateContext();
|
|
52
|
+
const { modal: modalFromApp } = App.useApp();
|
|
53
|
+
const modal = modalFromApp !== null && modalFromApp !== void 0 ? modalFromApp : Modal;
|
|
54
|
+
const { localize } = useContext(AntHelperContext);
|
|
55
|
+
const [, token] = useToken();
|
|
56
|
+
const [confirmApi, setConfirmApi] = useState();
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
const triggerEventArgsRef = useRef(undefined);
|
|
59
|
+
// Text with color
|
|
60
|
+
const coloredText = (text, color) => {
|
|
61
|
+
var _a;
|
|
62
|
+
const textContent = typeof text === 'string' ? ((_a = localize === null || localize === void 0 ? void 0 : localize(text)) !== null && _a !== void 0 ? _a : text) : text;
|
|
63
|
+
if (!color) {
|
|
64
|
+
return textContent;
|
|
65
|
+
}
|
|
66
|
+
if (color === 'primary') {
|
|
67
|
+
return _jsx(Typography.Text, { style: { color: token.colorPrimary }, children: textContent });
|
|
68
|
+
}
|
|
69
|
+
return textContent ? _jsx(Typography.Text, { type: color, children: textContent }) : undefined;
|
|
70
|
+
};
|
|
71
|
+
// Show confirm box
|
|
72
|
+
const showConfirm = useRefFunction(() => {
|
|
73
|
+
const api = modal.confirm(Object.assign({ title: coloredText(title, titleColor), content: coloredText(content, contentColor), icon: coloredText(icon, iconColor), autoFocusButton: null, onOk: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
var _a;
|
|
75
|
+
const result = yield (onOk === null || onOk === void 0 ? void 0 : onOk(...((_a = triggerEventArgsRef.current) !== null && _a !== void 0 ? _a : [])));
|
|
76
|
+
afterOk === null || afterOk === void 0 ? void 0 : afterOk(result);
|
|
77
|
+
}) }, restProps));
|
|
78
|
+
setConfirmApi(api);
|
|
79
|
+
return api;
|
|
80
|
+
});
|
|
81
|
+
// Output ref
|
|
82
|
+
useImperativeHandle(ref, () => (Object.assign({ show: showConfirm }, confirmApi)), [showConfirm, confirmApi]);
|
|
83
|
+
// Render trigger component
|
|
84
|
+
return (_jsx(Trigger, Object.assign({}, triggerProps, (triggerEvent
|
|
85
|
+
? {
|
|
86
|
+
[triggerEvent]: (...args) => {
|
|
87
|
+
triggerEventArgsRef.current = args;
|
|
88
|
+
showConfirm();
|
|
89
|
+
if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {
|
|
90
|
+
triggerProps[triggerEvent](...args);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
: {}), { children: (_b = triggerProps.children) !== null && _b !== void 0 ? _b : children })));
|
|
95
|
+
};
|
|
96
|
+
Render.displayName = 'ConfirmAction';
|
|
97
|
+
return Render;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* **EN:** Add default properties to the ConfirmAction component
|
|
101
|
+
*
|
|
102
|
+
* **CN:** 给ConfirmAction组件添加默认属性
|
|
103
|
+
*
|
|
104
|
+
* @param WrappedComponent ConfirmAction component | ConfirmAction组件
|
|
105
|
+
* @param defaultProps Default properties | 默认属性
|
|
106
|
+
*/
|
|
107
|
+
export const withDefaultConfirmActionProps = (WrappedComponent, defaultProps) => {
|
|
108
|
+
const WithDefaultProps = forwardRef((props, ref) => {
|
|
109
|
+
const mergedProps = Object.assign(Object.assign(Object.assign({}, defaultProps), props), { triggerProps: Object.assign(Object.assign({}, defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.triggerProps), props.triggerProps) });
|
|
110
|
+
return _jsx(WrappedComponent, Object.assign({ ref: ref }, mergedProps));
|
|
111
|
+
});
|
|
112
|
+
WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';
|
|
113
|
+
return WithDefaultProps;
|
|
114
|
+
};
|
|
115
|
+
const renderConfirmAction = genRenderer({
|
|
116
|
+
confirmType: 'normal',
|
|
117
|
+
});
|
|
118
|
+
const forwarded = forwardRef(renderConfirmAction);
|
|
119
|
+
forwarded.displayName = 'ForwardedRef(ConfirmAction)';
|
|
120
|
+
/**
|
|
121
|
+
* **EN:** Confirm box component with trigger
|
|
122
|
+
*
|
|
123
|
+
* **CN:** 带触发器的确认框组件
|
|
124
|
+
*/
|
|
125
|
+
const ConfirmAction = forwarded;
|
|
126
|
+
// Type of button
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
+
ConfirmAction.Button = withDefaultConfirmActionProps(forwarded, {
|
|
129
|
+
triggerComponent: Button,
|
|
130
|
+
triggerEvent: 'onClick',
|
|
131
|
+
triggerProps: {},
|
|
132
|
+
});
|
|
133
|
+
// Type of switch
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
+
ConfirmAction.Switch = withDefaultConfirmActionProps(forwarded, {
|
|
136
|
+
triggerComponent: Switch,
|
|
137
|
+
triggerEvent: 'onChange',
|
|
138
|
+
triggerProps: {},
|
|
139
|
+
});
|
|
140
|
+
// Type of link
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
|
+
ConfirmAction.Link = withDefaultConfirmActionProps(forwarded, {
|
|
143
|
+
triggerComponent: Typography.Link,
|
|
144
|
+
triggerEvent: 'onClick',
|
|
145
|
+
triggerProps: {
|
|
146
|
+
style: { whiteSpace: 'nowrap' },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
export default ConfirmAction;
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/ConfirmAction/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;A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,CAAC;AAEF,MAAM,mBAAmB,GAAG,WAAW,CAAC;IACtC,WAAW,EAAE,QAAQ;CACtB,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;AAClD,SAAS,CAAC,WAAW,GAAG,6BAA6B,CAAC;AAkDtD;;;;GAIG;AACH,MAAM,aAAa,GAAG,SAA+C,CAAC;AACtE,iBAAiB;AACjB,8DAA8D;AAC9D,aAAa,CAAC,MAAM,GAAG,6BAA6B,CAAyB,SAAgB,EAAE;IAC7F,gBAAgB,EAAE,MAAM;IACxB,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE,EAAE;CACjB,CAAC,CAAC;AACH,iBAAiB;AACjB,8DAA8D;AAC9D,aAAa,CAAC,MAAM,GAAG,6BAA6B,CAA0B,SAAgB,EAAE;IAC9F,gBAAgB,EAAE,MAAM;IACxB,YAAY,EAAE,UAAU;IACxB,YAAY,EAAE,EAAE;CACjB,CAAC,CAAC;AACH,eAAe;AACf,8DAA8D;AAC9D,aAAa,CAAC,IAAI,GAAG,6BAA6B,CAAuB,SAAgB,EAAE;IACzF,gBAAgB,EAAE,UAAU,CAAC,IAAI;IACjC,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE;KAChC;CACF,CAAC,CAAC;AAEH,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { Button, Switch, Typography } from 'antd';
|
|
4
|
+
import { CloseCircleFilled } from '@ant-design/icons';
|
|
5
|
+
import { genRenderer, withDefaultConfirmActionProps } from '../ConfirmAction';
|
|
6
|
+
const renderDeleteConfirmAction = genRenderer({
|
|
7
|
+
confirmType: 'delete',
|
|
8
|
+
titleColor: 'danger',
|
|
9
|
+
icon: (_jsx(Typography.Text, { type: "danger", children: _jsx(CloseCircleFilled, {}) })),
|
|
10
|
+
okButtonProps: { danger: true },
|
|
11
|
+
});
|
|
12
|
+
const forwarded = forwardRef(renderDeleteConfirmAction);
|
|
13
|
+
/**
|
|
14
|
+
* **EN:** Delete operation confirmation box
|
|
15
|
+
*
|
|
16
|
+
* **CN:** 删除操作确认框
|
|
17
|
+
*/
|
|
18
|
+
const DeleteConfirmAction = forwarded;
|
|
19
|
+
/**
|
|
20
|
+
* **EN:** Deletion confirmation box with button type
|
|
21
|
+
*
|
|
22
|
+
* **CN:** 按钮类型的删除确认框
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
DeleteConfirmAction.Button = withDefaultConfirmActionProps(forwarded, {
|
|
26
|
+
triggerComponent: Button,
|
|
27
|
+
triggerEvent: 'onClick',
|
|
28
|
+
triggerProps: {},
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* **EN:** Deletion confirmation box with switch type
|
|
32
|
+
*
|
|
33
|
+
* **CN:** 开关类型的删除确认框
|
|
34
|
+
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
DeleteConfirmAction.Switch = withDefaultConfirmActionProps(forwarded, {
|
|
37
|
+
triggerComponent: Switch,
|
|
38
|
+
triggerEvent: 'onChange',
|
|
39
|
+
triggerProps: {},
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* **EN:** Deletion confirmation box with link type
|
|
43
|
+
*
|
|
44
|
+
* **CN:** 链接类型的删除确认框
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
DeleteConfirmAction.Link = withDefaultConfirmActionProps(forwarded, {
|
|
48
|
+
triggerComponent: Typography.Link,
|
|
49
|
+
triggerEvent: 'onClick',
|
|
50
|
+
triggerProps: {
|
|
51
|
+
style: { whiteSpace: 'nowrap' },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export default DeleteConfirmAction;
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/DeleteConfirmAction/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAgC,WAAW,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAE5G,MAAM,yBAAyB,GAAG,WAAW,CAAC;IAC5C,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,IAAI,EAAE,CACJ,KAAC,UAAU,CAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,YAC5B,KAAC,iBAAiB,KAAG,GACL,CACnB;IACD,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;CAChC,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,UAAU,CAAC,yBAAyB,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,SAA+C,CAAC;AAC5E;;;;GAIG;AACH,8DAA8D;AAC9D,mBAAmB,CAAC,MAAM,GAAG,6BAA6B,CAAyB,SAAgB,EAAE;IACnG,gBAAgB,EAAE,MAAM;IACxB,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE,EAAE;CACjB,CAAC,CAAC;AACH;;;;GAIG;AACH,8DAA8D;AAC9D,mBAAmB,CAAC,MAAM,GAAG,6BAA6B,CAA0B,SAAgB,EAAE;IACpG,gBAAgB,EAAE,MAAM;IACxB,YAAY,EAAE,UAAU;IACxB,YAAY,EAAE,EAAE;CACjB,CAAC,CAAC;AACH;;;;GAIG;AACH,8DAA8D;AAC9D,mBAAmB,CAAC,IAAI,GAAG,6BAA6B,CAAuB,SAAgB,EAAE;IAC/F,gBAAgB,EAAE,UAAU,CAAC,IAAI;IACjC,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE;KAChC;CACF,CAAC,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttributes } from 'react';
|
|
2
|
+
import type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';
|
|
3
|
+
import type { LinkProps } from 'antd/es/typography/Link';
|
|
4
|
+
/**
|
|
5
|
+
* **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
|
|
6
|
+
* returning in the `onSave` event of the editing form component
|
|
7
|
+
*
|
|
8
|
+
* **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
|
|
9
|
+
*/
|
|
10
|
+
export declare const SubmitWithoutClosingSymbol: unique symbol;
|
|
11
|
+
export type ModalActionProps<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object> = Omit<ModalProps, 'onOk'> & ModalActionTrigger<TP, E> & {
|
|
12
|
+
/**
|
|
13
|
+
* **EN:** Form editing component, do not use the Form component inside the component, the form
|
|
14
|
+
* component and form instance are automatically created by the parent component
|
|
15
|
+
*
|
|
16
|
+
* **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
|
|
17
|
+
*/
|
|
18
|
+
formComp: ComponentType<CP & RefAttributes<CRef>>;
|
|
19
|
+
/**
|
|
20
|
+
* **EN:** Props of the form editing component
|
|
21
|
+
*
|
|
22
|
+
* **CN:** 表单编辑组件的Props属性
|
|
23
|
+
*/
|
|
24
|
+
formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;
|
|
25
|
+
/**
|
|
26
|
+
* **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
|
|
27
|
+
* `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be
|
|
28
|
+
* passed to the `afterOk` event, if any
|
|
29
|
+
*
|
|
30
|
+
* **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
|
|
31
|
+
*/
|
|
32
|
+
onOk?: (formData: FD, ...args: Parameters<TP[E]>) => unknown | Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* **EN:** The callback after the confirmation event is completed, it will not be triggered when
|
|
35
|
+
* it fails, the parameter is the return value of `onOk`
|
|
36
|
+
*
|
|
37
|
+
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
38
|
+
*/
|
|
39
|
+
afterOk?: (data?: any) => void;
|
|
40
|
+
};
|
|
41
|
+
export interface FormCompPropsConstraint<FD> {
|
|
42
|
+
/** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例 */
|
|
43
|
+
form: FormInstance<FD>;
|
|
44
|
+
/** 设置表单保存方法,支持异步保存 */
|
|
45
|
+
onSave: (handler: (formData: FD, ...triggerEventData: any[]) => unknown | Promise<unknown>) => void;
|
|
46
|
+
/** 监听弹框打开关闭状态。当`destroyOnClose`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框 */
|
|
47
|
+
onOpenChange: (listener: ModalProps['afterOpenChange']) => void;
|
|
48
|
+
/** 设置弹框打开状态 */
|
|
49
|
+
setOpen: (open: boolean) => void;
|
|
50
|
+
/** 修改弹窗的属性,例如标题、宽度,按钮属性等 */
|
|
51
|
+
updateModalProps: (props: Partial<ModalProps>) => void;
|
|
52
|
+
/** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值 */
|
|
53
|
+
triggerEventData?: any[];
|
|
54
|
+
}
|
|
55
|
+
export interface ModalActionTrigger<TP extends object, E extends keyof TP> {
|
|
56
|
+
/**
|
|
57
|
+
* **EN:** Trigger component, click to show the dialog
|
|
58
|
+
*
|
|
59
|
+
* **CN:** 弹窗触发器组件,点击触发显示弹框
|
|
60
|
+
*/
|
|
61
|
+
triggerComponent?: ComponentType<TP> | FC<TP>;
|
|
62
|
+
/**
|
|
63
|
+
* **EN:** Props of the trigger component
|
|
64
|
+
*
|
|
65
|
+
* **CN:** 触发器组件的Props属性
|
|
66
|
+
*/
|
|
67
|
+
triggerProps?: TP;
|
|
68
|
+
/**
|
|
69
|
+
* **EN:** The event name that triggers the dialog
|
|
70
|
+
*
|
|
71
|
+
* **CN:** 触发弹窗的事件名称
|
|
72
|
+
*
|
|
73
|
+
* - `Button`: 'onClick'
|
|
74
|
+
* - `Switch`: 'onChange'
|
|
75
|
+
* - `Link`: 'onClick'
|
|
76
|
+
*/
|
|
77
|
+
triggerEvent?: E;
|
|
78
|
+
/**
|
|
79
|
+
* **EN:** Custom trigger content
|
|
80
|
+
*
|
|
81
|
+
* **CN:** 自定义触发器内容
|
|
82
|
+
*/
|
|
83
|
+
children?: ReactNode;
|
|
84
|
+
}
|
|
85
|
+
export type ModalActionRef<R> = R & {
|
|
86
|
+
/**
|
|
87
|
+
* **EN:** Show the dialog
|
|
88
|
+
*
|
|
89
|
+
* **CN:** 显示弹框
|
|
90
|
+
*/
|
|
91
|
+
show: () => void;
|
|
92
|
+
};
|
|
93
|
+
export declare const genModalActionRenderer: (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(props: ModalActionProps<FD, CP, TP, E, CRef>, ref: ForwardedRef<ModalActionRef<CRef>>) => import("react/jsx-runtime").JSX.Element;
|
|
94
|
+
/**
|
|
95
|
+
* **EN:** Add default properties to the ModalAction component
|
|
96
|
+
*
|
|
97
|
+
* **CN:** 给ModalAction组件添加默认属性
|
|
98
|
+
*
|
|
99
|
+
* @param WrappedComponent ModalAction component | ModalAction组件
|
|
100
|
+
* @param defaultProps Default properties | 默认属性
|
|
101
|
+
*/
|
|
102
|
+
export declare const withDefaultModalActionProps: <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>, defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)) => import("react").ForwardRefExoticComponent<Omit<ModalProps, "onOk"> & ModalActionTrigger<TP, E> & {
|
|
103
|
+
/**
|
|
104
|
+
* **EN:** Form editing component, do not use the Form component inside the component, the form
|
|
105
|
+
* component and form instance are automatically created by the parent component
|
|
106
|
+
*
|
|
107
|
+
* **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
|
|
108
|
+
*/
|
|
109
|
+
formComp: ComponentType<CP & RefAttributes<CRef>>;
|
|
110
|
+
/**
|
|
111
|
+
* **EN:** Props of the form editing component
|
|
112
|
+
*
|
|
113
|
+
* **CN:** 表单编辑组件的Props属性
|
|
114
|
+
*/
|
|
115
|
+
formProps?: Omit<CP, keyof FormCompPropsConstraint<FD_1>> | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
|
|
118
|
+
* `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be
|
|
119
|
+
* passed to the `afterOk` event, if any
|
|
120
|
+
*
|
|
121
|
+
* **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
|
|
122
|
+
*/
|
|
123
|
+
onOk?: ((formData: FD, ...args: Parameters<TP[E]>) => unknown | Promise<unknown>) | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* **EN:** The callback after the confirmation event is completed, it will not be triggered when
|
|
126
|
+
* it fails, the parameter is the return value of `onOk`
|
|
127
|
+
*
|
|
128
|
+
* **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
|
|
129
|
+
*/
|
|
130
|
+
afterOk?: (data?: any) => void;
|
|
131
|
+
} & RefAttributes<ModalActionRef<CRef>>>;
|
|
132
|
+
/**
|
|
133
|
+
* **EN:** ModalAction component type
|
|
134
|
+
*
|
|
135
|
+
* **CN:** ModalAction组件的类型
|
|
136
|
+
*/
|
|
137
|
+
export type ModalActionInterface<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;
|
|
138
|
+
/**
|
|
139
|
+
* **EN:** ModalAction component with generic type
|
|
140
|
+
*
|
|
141
|
+
* **CN:** ModalAction泛型组件的类型
|
|
142
|
+
*/
|
|
143
|
+
export type GenericModalActionInterface = <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>) => ReactElement;
|
|
144
|
+
/**
|
|
145
|
+
* **EN:** ModalAction with specified trigger type (specified form component)
|
|
146
|
+
*
|
|
147
|
+
* **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
|
|
148
|
+
*/
|
|
149
|
+
type ModalActionWithTrigger<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object, OMIT extends string = never> = ComponentType<Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ModalActionRef<CRef>>>;
|
|
150
|
+
/**
|
|
151
|
+
* **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)
|
|
152
|
+
*
|
|
153
|
+
* **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)
|
|
154
|
+
*/
|
|
155
|
+
type GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object>(props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ModalActionRef<CRef>>) => ReactElement;
|
|
156
|
+
/**
|
|
157
|
+
* **EN:** Built-in trigger types (specified form components)
|
|
158
|
+
*
|
|
159
|
+
* **CN:** 内置的几种触发器类型(已指定表单组件)
|
|
160
|
+
*/
|
|
161
|
+
interface TypedTriggers<FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object, OMIT extends string = never> {
|
|
162
|
+
/**
|
|
163
|
+
* **EN:** Dialog with button type trigger
|
|
164
|
+
*
|
|
165
|
+
* **CN:** 按钮类型的弹窗
|
|
166
|
+
*/
|
|
167
|
+
Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
168
|
+
/**
|
|
169
|
+
* **EN:** Dialog with switch type trigger
|
|
170
|
+
*
|
|
171
|
+
* **CN:** 开关类型的弹窗
|
|
172
|
+
*/
|
|
173
|
+
Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
174
|
+
/**
|
|
175
|
+
* **EN:** Dialog with link type trigger
|
|
176
|
+
*
|
|
177
|
+
* **CN:** 链接类型的弹窗
|
|
178
|
+
*/
|
|
179
|
+
Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* **EN:** Built-in trigger types (generic types, unspecified form components)
|
|
183
|
+
*
|
|
184
|
+
* **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)
|
|
185
|
+
*/
|
|
186
|
+
interface GenericTypedTriggers<OMIT extends string = never> {
|
|
187
|
+
/**
|
|
188
|
+
* **EN:** Dialog with button type trigger
|
|
189
|
+
*
|
|
190
|
+
* **CN:** 按钮类型的弹窗
|
|
191
|
+
*/
|
|
192
|
+
Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
193
|
+
/**
|
|
194
|
+
* **EN:** Dialog with switch type trigger
|
|
195
|
+
*
|
|
196
|
+
* **CN:** 开关类型的弹窗
|
|
197
|
+
*/
|
|
198
|
+
Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
199
|
+
/**
|
|
200
|
+
* **EN:** Dialog with link type trigger
|
|
201
|
+
*
|
|
202
|
+
* **CN:** 链接类型的弹窗
|
|
203
|
+
*/
|
|
204
|
+
Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;
|
|
205
|
+
}
|
|
206
|
+
type WithGenericTriggers<FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object, OMIT extends string = never> = (<TP extends object, E extends keyof TP>(props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>) => ReactElement) & (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);
|
|
207
|
+
/**
|
|
208
|
+
* **EN:** Dialog component with trigger
|
|
209
|
+
*
|
|
210
|
+
* **CN:** 带触发器的弹窗组件
|
|
211
|
+
*/
|
|
212
|
+
declare const ModalAction: WithGenericTriggers<object, FormCompPropsConstraint<object>, object, never>;
|
|
213
|
+
/**
|
|
214
|
+
* **EN:** Dialog component with trigger
|
|
215
|
+
*
|
|
216
|
+
* **CN:** 带触发器的弹窗组件
|
|
217
|
+
*/
|
|
218
|
+
export type ModalActionWithStatic = typeof ModalAction & {
|
|
219
|
+
/**
|
|
220
|
+
* **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
|
|
221
|
+
* returning in the `onSave` event of the editing form component
|
|
222
|
+
*
|
|
223
|
+
* **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
|
|
224
|
+
*/
|
|
225
|
+
SubmitWithoutClosing: symbol;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* **EN:** Generate a dialog component based on the editing form component
|
|
229
|
+
*
|
|
230
|
+
* **CN:** 基于编辑表单组件生成一个弹框组件
|
|
231
|
+
*
|
|
232
|
+
* @param formComp Component of dialog content | 弹窗内容组件
|
|
233
|
+
* @param defaultProps Default properties of the dialog | 弹窗的默认属性
|
|
234
|
+
*/
|
|
235
|
+
export declare function withModalAction<FD extends object, CP extends FormCompPropsConstraint<FD>, OuterTP extends object, OuterE extends keyof OuterTP, CRef extends object>(formComp: ComponentType<CP & FormCompPropsConstraint<FD> & RefAttributes<CRef>>, defaultProps?: Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>> | (() => Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>)): WithGenericTriggers<FD, CP, CRef, "formComp">;
|
|
236
|
+
declare const _default: ModalActionWithStatic;
|
|
237
|
+
export default _default;
|