Skip to content

Commit 1640b0a

Browse files
committed
feat: Update Dialog content supoort custom animation
1 parent e6f6a36 commit 1640b0a

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/Dialog/index.doc.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,37 @@
2727
"name": "defaultShow",
2828
"documentation": "Set Dialog show status.",
2929
"isRequired": false,
30-
"type": "boolean"
30+
"type": "prototype"
3131
},
3232
{
3333
"name": "isControlled",
3434
"documentation": "If set true, click the mask background will not close dialog.",
3535
"isRequired": false,
36-
"type": "boolean"
36+
"type": "prototype"
3737
},
3838
{
3939
"name": "contentStyle",
4040
"documentation": "Set custom content style.",
4141
"isRequired": false,
42-
"type": "CSSProperties"
42+
"type": "prototype"
43+
},
44+
{
45+
"name": "contentEnterStyle",
46+
"documentation": "Set custom content enter style.",
47+
"isRequired": false,
48+
"type": "prototype"
49+
},
50+
{
51+
"name": "contentLeaveStyle",
52+
"documentation": "Set custom content leave style.",
53+
"isRequired": false,
54+
"type": "prototype"
4355
},
4456
{
4557
"name": "onCloseDialog",
4658
"documentation": "Set onCloseDialog callback.",
4759
"isRequired": false,
48-
"type": "() => void"
60+
"type": "prototype"
4961
}
5062
]
5163
},
@@ -62,7 +74,7 @@
6274
{
6375
"name": "showDialog",
6476
"isRequired": false,
65-
"type": "boolean"
77+
"type": "prototype"
6678
}
6779
]
6880
},
@@ -71,7 +83,12 @@
7183
"exports": [
7284
{
7385
"name": "prototype",
74-
"type": "prototype"
86+
"type": "any"
87+
},
88+
{
89+
"name": "defaultProps",
90+
"initializerText": " {\n contentEnterStyle: { transform: \"scale(1)\" },\n contentLeaveStyle: { transform: \"scale(0)\" }\n }",
91+
"type": "DialogProps"
7592
},
7693
{
7794
"name": "contextTypes",

src/Dialog/index.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export interface DataProps {
1818
* Set custom content style.
1919
*/
2020
contentStyle?: React.CSSProperties;
21+
/**
22+
* Set custom content enter style.
23+
*/
24+
contentEnterStyle?: React.CSSProperties;
25+
/**
26+
* Set custom content leave style.
27+
*/
28+
contentLeaveStyle?: React.CSSProperties;
2129
/**
2230
* Set onCloseDialog callback.
2331
*/
@@ -30,6 +38,10 @@ export interface DialogState {
3038
}
3139

3240
export class Dialog extends React.Component<DialogProps, DialogState> {
41+
static defaultProps: DialogProps = {
42+
contentEnterStyle: { transform: "scale(1)" },
43+
contentLeaveStyle: { transform: "scale(0)" }
44+
}
3345
state: DialogState = {
3446
showDialog: this.props.defaultShow
3547
};
@@ -87,6 +99,8 @@ export class Dialog extends React.Component<DialogProps, DialogState> {
8799
render() {
88100
const {
89101
contentStyle,
102+
contentEnterStyle,
103+
contentLeaveStyle,
90104
defaultShow,
91105
children,
92106
onCloseDialog,
@@ -117,7 +131,16 @@ export class Dialog extends React.Component<DialogProps, DialogState> {
117131
}
118132

119133
function getStyles(dialog: Dialog) {
120-
const { context, state: { showDialog }, props: { style, contentStyle } } = dialog;
134+
const {
135+
context,
136+
state: { showDialog },
137+
props: {
138+
style,
139+
contentStyle,
140+
contentEnterStyle,
141+
contentLeaveStyle
142+
}
143+
} = dialog;
121144
const { theme } = context;
122145
const { prefixStyle } = theme;
123146

@@ -143,8 +166,8 @@ function getStyles(dialog: Dialog) {
143166
content: prefixStyle({
144167
display: "inline-block",
145168
transition: "all .25s",
146-
transform: `scale(${showDialog ? 1 : 0})`,
147-
...contentStyle
169+
...contentStyle,
170+
...(showDialog ? contentEnterStyle : contentLeaveStyle)
148171
})
149172
};
150173
}

0 commit comments

Comments
 (0)