Skip to content

Commit dee0a71

Browse files
committed
feat: extract colorValue to theme
1 parent 966c0ae commit dee0a71

File tree

9 files changed

+156
-132
lines changed

9 files changed

+156
-132
lines changed

src/components/Modal/actionButton.tsx

-64
This file was deleted.

src/components/Modal/ConfirmDialog.tsx src/components/dialog/ConfirmDialog.tsx

+43-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as React from 'react';
2-
import { classNames, getBEMElement, getBEMModifier, prefixClaName } from 'mo/common/className';
2+
import {
3+
classNames,
4+
getBEMElement,
5+
getBEMModifier,
6+
prefixClaName,
7+
} from 'mo/common/className';
38
import Dialog, { IModalFuncProps } from './modal';
49
import ActionButton from './actionButton';
510

@@ -42,28 +47,31 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
4247
maskTransitionName = 'fade',
4348
} = props;
4449

45-
const confirmDescriperClassName = getBEMElement(confirmClassName, `${props.type}`)
50+
const confirmDescriperClassName = getBEMElement(
51+
confirmClassName,
52+
`${props.type}`
53+
);
4654
const containerClassName = getBEMElement(confirmClassName, 'container');
4755
const indicatorClassName = getBEMElement(confirmClassName, 'indicator');
48-
const contentClassName = getBEMElement(confirmClassName, 'content');
49-
const messageClassName = getBEMElement(confirmClassName, 'message');
56+
const contentClassName = getBEMElement(confirmClassName, 'content');
57+
const messageClassName = getBEMElement(confirmClassName, 'message');
5058
const btnsClassName = getBEMElement(confirmClassName, 'btns');
5159

5260
const classString = classNames(
5361
confirmClassName,
5462
confirmDescriperClassName,
55-
className,
63+
className
5664
);
5765

5866
const cancelButton = okCancel && (
5967
<ActionButton
60-
actionFn={onCancel}
61-
closeModal={close}
62-
buttonProps={cancelButtonProps}
68+
actionFn={onCancel}
69+
closeModal={close}
70+
buttonProps={cancelButtonProps}
6371
>
64-
{cancelText}
72+
{cancelText}
6573
</ActionButton>
66-
);
74+
);
6775

6876
return (
6977
<Dialog
@@ -96,31 +104,42 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
96104
<div className={indicatorClassName}> {icon} </div>
97105
<div className={messageClassName}>
98106
{props.title !== undefined && (
99-
<span className={getBEMModifier(messageClassName, 'text')}>
107+
<span
108+
className={getBEMModifier(
109+
messageClassName,
110+
'text'
111+
)}
112+
>
100113
{props.title}
101114
</span>
102115
)}
103-
<div className={`${getBEMModifier(messageClassName, 'detail')}`}>
116+
<div
117+
className={`${getBEMModifier(
118+
messageClassName,
119+
'detail'
120+
)}`}
121+
>
104122
{props.content}
105123
</div>
106124
</div>
107125
</div>
108126
<div className={btnsClassName}>
109-
{
110-
actions === undefined ? (
127+
{actions === undefined ? (
111128
<>
112129
{cancelButton}
113-
{<ActionButton
114-
actionFn={onOk}
115-
closeModal={close}
116-
buttonProps={okButtonProps}
117-
>
118-
{okText}
119-
</ActionButton>
120-
}
130+
{
131+
<ActionButton
132+
actionFn={onOk}
133+
closeModal={close}
134+
buttonProps={okButtonProps}
135+
>
136+
{okText}
137+
</ActionButton>
138+
}
121139
</>
122-
) : actions
123-
}
140+
) : (
141+
actions
142+
)}
124143
</div>
125144
</div>
126145
</Dialog>
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as React from 'react';
2+
import { Button, IButton } from 'mo/components/button';
3+
export interface ActionButtonProps {
4+
actionFn?: (...args: any[]) => any | PromiseLike<any>;
5+
closeModal: Function;
6+
buttonProps?: IButton;
7+
}
8+
9+
const ActionButton: React.FC<ActionButtonProps> = (props) => {
10+
const clickedRef = React.useRef<boolean>(false);
11+
12+
const handlePromiseOnOk = (returnValueOfOnOk?: PromiseLike<any>) => {
13+
const { closeModal } = props;
14+
if (!returnValueOfOnOk || !returnValueOfOnOk.then) {
15+
return;
16+
}
17+
returnValueOfOnOk.then(
18+
(...args: any[]) => {
19+
closeModal(...args);
20+
},
21+
(e: Error) => {
22+
// eslint-disable-next-line no-console
23+
console.error(e);
24+
clickedRef.current = false;
25+
}
26+
);
27+
};
28+
29+
const onClick = () => {
30+
const { actionFn, closeModal } = props;
31+
if (clickedRef.current) {
32+
return;
33+
}
34+
clickedRef.current = true;
35+
if (!actionFn) {
36+
closeModal();
37+
return;
38+
}
39+
let returnValueOfOnOk;
40+
if (actionFn.length) {
41+
returnValueOfOnOk = actionFn(closeModal);
42+
clickedRef.current = false;
43+
} else {
44+
returnValueOfOnOk = actionFn();
45+
if (!returnValueOfOnOk) {
46+
closeModal();
47+
return;
48+
}
49+
}
50+
handlePromiseOnOk(returnValueOfOnOk);
51+
};
52+
53+
const { children, buttonProps } = props;
54+
return (
55+
<Button onClick={onClick} {...buttonProps}>
56+
{children}
57+
</Button>
58+
);
59+
};
60+
61+
export default ActionButton;

src/components/Modal/confirm.tsx src/components/dialog/confirm.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export default function confirm(config: IModalFuncProps) {
5252
okText={okText}
5353
cancelText={cancelText}
5454
/>,
55-
div,
56-
)
55+
div
56+
);
5757
});
5858
}
5959

@@ -79,16 +79,16 @@ export function withWarn(props: IModalFuncProps): IModalFuncProps {
7979
return {
8080
type: 'warning',
8181
okCancel: false,
82-
icon: <Icon type="warning"/>,
82+
icon: <Icon type="warning" />,
8383
...props,
8484
};
8585
}
8686

8787
export function withConfirm(props: IModalFuncProps): IModalFuncProps {
8888
return {
89-
type: 'confirm',
90-
okCancel: true,
91-
icon: <Icon type="warning"/>,
92-
...props,
89+
type: 'confirm',
90+
okCancel: true,
91+
icon: <Icon type="warning" />,
92+
...props,
9393
};
94-
}
94+
}

src/components/Modal/index.tsx src/components/dialog/index.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import './style.scss'
1+
import './style.scss';
22
import OriginModal, { IModalFuncProps, destroyFns } from './modal';
3-
import confirm, { withWarn, withConfirm, ModalStaticFunctions } from './confirm';
3+
import confirm, {
4+
withWarn,
5+
withConfirm,
6+
ModalStaticFunctions,
7+
} from './confirm';
48

59
function modalWarn(props: IModalFuncProps) {
610
return confirm(withWarn(props));
@@ -18,7 +22,7 @@ Modal.warn = modalWarn;
1822
Modal.confirm = function confirmFn(props: IModalFuncProps) {
1923
return confirm(withConfirm(props));
2024
};
21-
25+
2226
Modal.destroyAll = function destroyAllFn() {
2327
while (destroyFns.length) {
2428
const close = destroyFns.pop();

src/components/Modal/modal.tsx src/components/dialog/modal.tsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as React from 'react';
22
import Dialog from 'rc-dialog';
33
import { IDialogPropTypes } from 'rc-dialog/lib/IDialogPropTypes';
44

5-
import { classNames, prefixClaName, getBEMElement ,getBEMModifier} from 'mo/common/className';
5+
import {
6+
classNames,
7+
prefixClaName,
8+
getBEMElement,
9+
getBEMModifier,
10+
} from 'mo/common/className';
611
import { Icon } from 'mo/components/icon';
712
import { Button, IButton } from 'mo/components/button';
813

@@ -26,7 +31,6 @@ export const destroyFns: Array<() => void> = [];
2631

2732
export const modalClassName = prefixClaName('modal');
2833

29-
3034
export interface IModalProps extends IDialogPropTypes {
3135
onOk?: (e: React.MouseEvent<HTMLElement>) => void;
3236
onCancel?: (e: React.SyntheticEvent<Element, Event>) => void;
@@ -82,23 +86,25 @@ const Modal: React.FC<IModalProps> = (props) => {
8286
const closeDescriptorClassName = getBEMModifier(`${closeClassName}`, 'x');
8387

8488
const closeIconToRender = (
85-
<span className={closeDescriptorClassName}><Icon type="close"/></span>
89+
<span className={closeDescriptorClassName}>
90+
<Icon type="close" />
91+
</span>
8692
);
8793

8894
const renderFooter = () => {
89-
const { footer, cancelButtonProps, okButtonProps } = props
90-
if (footer !== undefined) return footer
95+
const { footer, cancelButtonProps, okButtonProps } = props;
96+
if (footer !== undefined) return footer;
9197
return (
9298
<>
93-
<Button onClick={handleCancel} {...cancelButtonProps }>
99+
<Button onClick={handleCancel} {...cancelButtonProps}>
94100
{cancelText}
95101
</Button>
96-
<Button onClick={handleOk} {...okButtonProps }>
102+
<Button onClick={handleOk} {...okButtonProps}>
97103
{okText}
98104
</Button>
99105
</>
100-
)
101-
}
106+
);
107+
};
102108
return (
103109
<Dialog
104110
{...restProps}

src/components/Modal/style.scss src/components/dialog/style.scss

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,14 @@ $confirm: 'confirm';
9393
width: 40px;
9494
}
9595
}
96-
9796
}
9897

9998
#{prefix($confirm)} {
10099
&__container {
101100
display: flex;
102101
flex-flow: column wrap;
103102
font-size: 14px;
104-
padding: 25px 10px 10px 10;
103+
padding: 25px 10px 10px;
105104
}
106105

107106
&__indicator {
@@ -143,4 +142,4 @@ $confirm: 'confirm';
143142
justify-content: flex-end;
144143
padding: 20px 10px 10px;
145144
}
146-
}
145+
}

0 commit comments

Comments
 (0)