1 | "use client";
|
2 |
|
3 | import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
4 | var __rest = this && this.__rest || function (s, e) {
|
5 | var t = {};
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
7 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
8 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
9 | }
|
10 | return t;
|
11 | };
|
12 | import * as React from 'react';
|
13 | import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
|
14 | import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
|
15 | import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
|
16 | import InfoCircleFilled from "@ant-design/icons/es/icons/InfoCircleFilled";
|
17 | import classNames from 'classnames';
|
18 | import { CONTAINER_MAX_OFFSET } from '../_util/hooks/useZIndex';
|
19 | import { getTransitionName } from '../_util/motion';
|
20 | import { devUseWarning } from '../_util/warning';
|
21 | import ConfigProvider from '../config-provider';
|
22 | import { useLocale } from '../locale';
|
23 | import useToken from '../theme/useToken';
|
24 | import CancelBtn from './components/ConfirmCancelBtn';
|
25 | import OkBtn from './components/ConfirmOkBtn';
|
26 | import { ModalContextProvider } from './context';
|
27 | import Modal from './Modal';
|
28 | import Confirm from './style/confirm';
|
29 | export function ConfirmContent(props) {
|
30 | const {
|
31 | prefixCls,
|
32 | icon,
|
33 | okText,
|
34 | cancelText,
|
35 | confirmPrefixCls,
|
36 | type,
|
37 | okCancel,
|
38 | footer,
|
39 |
|
40 | locale: staticLocale
|
41 | } = props,
|
42 | resetProps = __rest(props, ["prefixCls", "icon", "okText", "cancelText", "confirmPrefixCls", "type", "okCancel", "footer", "locale"]);
|
43 | if (process.env.NODE_ENV !== 'production') {
|
44 | const warning = devUseWarning('Modal');
|
45 | process.env.NODE_ENV !== "production" ? warning(!(typeof icon === 'string' && icon.length > 2), 'breaking', `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`) : void 0;
|
46 | }
|
47 |
|
48 | let mergedIcon = icon;
|
49 |
|
50 | if (!icon && icon !== null) {
|
51 | switch (type) {
|
52 | case 'info':
|
53 | mergedIcon = React.createElement(InfoCircleFilled, null);
|
54 | break;
|
55 | case 'success':
|
56 | mergedIcon = React.createElement(CheckCircleFilled, null);
|
57 | break;
|
58 | case 'error':
|
59 | mergedIcon = React.createElement(CloseCircleFilled, null);
|
60 | break;
|
61 | default:
|
62 | mergedIcon = React.createElement(ExclamationCircleFilled, null);
|
63 | }
|
64 | }
|
65 |
|
66 | const mergedOkCancel = okCancel !== null && okCancel !== void 0 ? okCancel : type === 'confirm';
|
67 | const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
|
68 | const [locale] = useLocale('Modal');
|
69 | const mergedLocale = staticLocale || locale;
|
70 |
|
71 | const okTextLocale = okText || (mergedOkCancel ? mergedLocale === null || mergedLocale === void 0 ? void 0 : mergedLocale.okText : mergedLocale === null || mergedLocale === void 0 ? void 0 : mergedLocale.justOkText);
|
72 | const cancelTextLocale = cancelText || (mergedLocale === null || mergedLocale === void 0 ? void 0 : mergedLocale.cancelText);
|
73 |
|
74 | const btnCtxValue = Object.assign({
|
75 | autoFocusButton,
|
76 | cancelTextLocale,
|
77 | okTextLocale,
|
78 | mergedOkCancel
|
79 | }, resetProps);
|
80 | const btnCtxValueMemo = React.useMemo(() => btnCtxValue, _toConsumableArray(Object.values(btnCtxValue)));
|
81 |
|
82 | const footerOriginNode = React.createElement(React.Fragment, null, React.createElement(CancelBtn, null), React.createElement(OkBtn, null));
|
83 | const hasTitle = props.title !== undefined && props.title !== null;
|
84 | const bodyCls = `${confirmPrefixCls}-body`;
|
85 | return React.createElement("div", {
|
86 | className: `${confirmPrefixCls}-body-wrapper`
|
87 | }, React.createElement("div", {
|
88 | className: classNames(bodyCls, {
|
89 | [`${bodyCls}-has-title`]: hasTitle
|
90 | })
|
91 | }, mergedIcon, React.createElement("div", {
|
92 | className: `${confirmPrefixCls}-paragraph`
|
93 | }, hasTitle && React.createElement("span", {
|
94 | className: `${confirmPrefixCls}-title`
|
95 | }, props.title), React.createElement("div", {
|
96 | className: `${confirmPrefixCls}-content`
|
97 | }, props.content))), footer === undefined || typeof footer === 'function' ? (React.createElement(ModalContextProvider, {
|
98 | value: btnCtxValueMemo
|
99 | }, React.createElement("div", {
|
100 | className: `${confirmPrefixCls}-btns`
|
101 | }, typeof footer === 'function' ? footer(footerOriginNode, {
|
102 | OkBtn,
|
103 | CancelBtn
|
104 | }) : footerOriginNode))) : footer, React.createElement(Confirm, {
|
105 | prefixCls: prefixCls
|
106 | }));
|
107 | }
|
108 | const ConfirmDialog = props => {
|
109 | const {
|
110 | close,
|
111 | zIndex,
|
112 | afterClose,
|
113 | open,
|
114 | keyboard,
|
115 | centered,
|
116 | getContainer,
|
117 | maskStyle,
|
118 | direction,
|
119 | prefixCls,
|
120 | wrapClassName,
|
121 | rootPrefixCls,
|
122 | bodyStyle,
|
123 | closable = false,
|
124 | closeIcon,
|
125 | modalRender,
|
126 | focusTriggerAfterClose,
|
127 | onConfirm,
|
128 | styles
|
129 | } = props;
|
130 | if (process.env.NODE_ENV !== 'production') {
|
131 | const warning = devUseWarning('Modal');
|
132 | [['visible', 'open'], ['bodyStyle', 'styles.body'], ['maskStyle', 'styles.mask']].forEach(_ref => {
|
133 | let [deprecatedName, newName] = _ref;
|
134 | warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
|
135 | });
|
136 | }
|
137 | const confirmPrefixCls = `${prefixCls}-confirm`;
|
138 | const width = props.width || 416;
|
139 | const style = props.style || {};
|
140 | const mask = props.mask === undefined ? true : props.mask;
|
141 |
|
142 | const maskClosable = props.maskClosable === undefined ? false : props.maskClosable;
|
143 | const classString = classNames(confirmPrefixCls, `${confirmPrefixCls}-${props.type}`, {
|
144 | [`${confirmPrefixCls}-rtl`]: direction === 'rtl'
|
145 | }, props.className);
|
146 |
|
147 | const [, token] = useToken();
|
148 | const mergedZIndex = React.useMemo(() => {
|
149 | if (zIndex !== undefined) {
|
150 | return zIndex;
|
151 | }
|
152 |
|
153 | return token.zIndexPopupBase + CONTAINER_MAX_OFFSET;
|
154 | }, [zIndex, token]);
|
155 |
|
156 | return React.createElement(Modal, {
|
157 | prefixCls: prefixCls,
|
158 | className: classString,
|
159 | wrapClassName: classNames({
|
160 | [`${confirmPrefixCls}-centered`]: !!props.centered
|
161 | }, wrapClassName),
|
162 | onCancel: () => {
|
163 | close === null || close === void 0 ? void 0 : close({
|
164 | triggerCancel: true
|
165 | });
|
166 | onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(false);
|
167 | },
|
168 | open: open,
|
169 | title: "",
|
170 | footer: null,
|
171 | transitionName: getTransitionName(rootPrefixCls || '', 'zoom', props.transitionName),
|
172 | maskTransitionName: getTransitionName(rootPrefixCls || '', 'fade', props.maskTransitionName),
|
173 | mask: mask,
|
174 | maskClosable: maskClosable,
|
175 | style: style,
|
176 | styles: Object.assign({
|
177 | body: bodyStyle,
|
178 | mask: maskStyle
|
179 | }, styles),
|
180 | width: width,
|
181 | zIndex: mergedZIndex,
|
182 | afterClose: afterClose,
|
183 | keyboard: keyboard,
|
184 | centered: centered,
|
185 | getContainer: getContainer,
|
186 | closable: closable,
|
187 | closeIcon: closeIcon,
|
188 | modalRender: modalRender,
|
189 | focusTriggerAfterClose: focusTriggerAfterClose
|
190 | }, React.createElement(ConfirmContent, Object.assign({}, props, {
|
191 | confirmPrefixCls: confirmPrefixCls
|
192 | })));
|
193 | };
|
194 | const ConfirmDialogWrapper = props => {
|
195 | const {
|
196 | rootPrefixCls,
|
197 | iconPrefixCls,
|
198 | direction,
|
199 | theme
|
200 | } = props;
|
201 | return React.createElement(ConfigProvider, {
|
202 | prefixCls: rootPrefixCls,
|
203 | iconPrefixCls: iconPrefixCls,
|
204 | direction: direction,
|
205 | theme: theme
|
206 | }, React.createElement(ConfirmDialog, Object.assign({}, props)));
|
207 | };
|
208 | if (process.env.NODE_ENV !== 'production') {
|
209 | ConfirmDialog.displayName = 'ConfirmDialog';
|
210 | ConfirmDialogWrapper.displayName = 'ConfirmDialogWrapper';
|
211 | }
|
212 | export default ConfirmDialogWrapper; |
\ | No newline at end of file |