/
ant-design.tsx
250 lines (233 loc) · 6.2 KB
/
ant-design.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* eslint no-console:0 */
import 'rc-dialog/assets/index.less';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
// use import Dialog from 'rc-dialog'
import Dialog from '../src/DialogWrap';
const clearPath = 'M793 242H366v-74c0-6.7-7.7-10.4-12.9' +
'-6.3l-142 112c-4.1 3.2-4.1 9.4 0 12.6l142 112c' +
'5.2 4.1 12.9 0.4 12.9-6.3v-74h415v470H175c-4.4' +
' 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h618c35.3 0 64-' +
'28.7 64-64V306c0-35.3-28.7-64-64-64z';
const getSvg = (path: string, props = {}, align = false) => {
return (
<i {...props}>
<svg
viewBox="0 0 1024 1024"
width="1em"
height="1em"
fill="currentColor"
style={align ? { verticalAlign: '-.125em ' } : {}}
>
<path d={path} p-id="5827"></path>
</svg>
</i>
);
};
class MyControl extends React.Component<any, any> {
state = {
visible: false,
visible2: false,
visible3: true,
width: 600,
destroyOnClose: false,
center: false,
mousePosition: undefined,
useIcon: false,
forceRender: false,
};
onClick = (e: React.MouseEvent) => {
this.setState({
mousePosition: {
x: e.pageX,
y: e.pageY,
},
visible: true,
});
}
onClose = (e: React.SyntheticEvent) => {
this.setState({
visible: false,
});
}
onClose2 = (e: React.SyntheticEvent) => {
this.setState({
visible: false,
visible2: false,
});
}
onClose3 = (e: React.SyntheticEvent) => {
this.setState({ visible3: false });
}
onDestroyOnCloseChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
destroyOnClose: e.target.checked,
});
}
onForceRenderChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
forceRender: e.target.checked,
});
}
changeWidth = () => {
this.setState({
width: this.state.width === 600 ? 800 : 600,
});
}
center = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
center: e.target.checked,
});
}
toggleCloseIcon = () => {
this.setState({
useIcon: !this.state.useIcon,
});
}
render() {
const style = {
width: this.state.width,
};
let wrapClassName = '';
if (this.state.center) {
wrapClassName = 'center';
}
const dialog = (
<Dialog
visible={this.state.visible}
wrapClassName={wrapClassName}
animation="zoom"
maskAnimation="fade"
onClose={this.onClose}
style={style}
mousePosition={this.state.mousePosition}
destroyOnClose={this.state.destroyOnClose}
closeIcon={this.state.useIcon ? getSvg(clearPath, {}, true) : undefined}
forceRender={this.state.forceRender}
focusTriggerAfterClose={false}
>
<input autoFocus />
<p>basic modal</p>
<button onClick={() => {
this.setState({
visible: false,
visible2: true,
});
}}>打开第二个并关闭当前的</button>
<button onClick={() => {
this.setState({
visible: true,
visible2: true,
});
}}>打开第二个</button>
<button onClick={this.changeWidth}>change width</button>
<button onClick={this.toggleCloseIcon}>
use custom icon, is using icon: {this.state.useIcon && 'true' || 'false'}.
</button>
<div style={{ height: 200 }} />
</Dialog>
);
const dialog2 = (
<Dialog
visible={this.state.visible2}
onClose={this.onClose2}
>
<input autoFocus />
<p>basic modal</p>
<button onClick={() => {
this.setState({
visible: true,
visible2: true,
visible3: true,
});
}}>打开第三个</button>
<button onClick={() => {
this.setState({
visible2: false,
});
}}>关闭当前</button>
<button onClick={this.onClose2}>关闭所有</button>
<button onClick={this.changeWidth}>change width</button>
<button onClick={this.toggleCloseIcon}>
use custom icon, is using icon: {this.state.useIcon && 'true' || 'false'}.
</button>
<div style={{ height: 200 }} />
</Dialog>
);
const dialog3 = (
<Dialog
forceRender
visible={this.state.visible3}
onClose={this.onClose3}
>
<p>initialized with forceRender and visbile true</p>
<button onClick={() => {
this.setState({
visible3: false,
});
}}>关闭当前</button>
<button onClick={this.onClose2}>关闭所有</button>
<button onClick={this.changeWidth}>change width</button>
<button onClick={this.toggleCloseIcon}>
use custom icon, is using icon: {this.state.useIcon && 'true' || 'false'}.
</button>
<div style={{ height: 200 }} />
</Dialog>
);
return (
<div style={{ width: '90%', margin: '0 auto' }}>
<style>
{`
.center {
display: flex;
align-items: center;
justify-content: center;
}
`}
</style>
<p>
<button className="btn btn-primary" onClick={this.onClick}>
show dialog
</button>
<label>
destroy on close:
<input
type="checkbox"
checked={this.state.destroyOnClose}
onChange={this.onDestroyOnCloseChange}
/>
</label>
<label>
center
<input
type="checkbox"
checked={this.state.center}
onChange={this.center}
/>
</label>
<label>
force render
<input
type="checkbox"
checked={this.state.forceRender}
onChange={this.onForceRenderChange}
/>
</label>
</p>
{dialog}
{dialog2}
{dialog3}
</div>
);
}
}
ReactDOM.render(
<div>
<h2>ant-design dialog</h2>
<MyControl />
</div>,
document.getElementById('__react-content'),
);