-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathcustomize.tsx
More file actions
209 lines (191 loc) Β· 5.65 KB
/
customize.tsx
File metadata and controls
209 lines (191 loc) Β· 5.65 KB
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
import moment, { type Moment } from 'moment';
import * as React from 'react';
import '../../assets/index.less';
import Picker, { PickerPanel } from '../../src';
import momentGenerateConfig from '../../src/generate/moment';
import zhCN from '../../src/locale/zh_CN';
import './slide.less';
interface DateRangeState {
startValue: Moment | null;
endValue: Moment | null;
endOpen: boolean;
initValue: Moment;
}
type PanelMode = 'time' | 'datetime' | 'date' | 'week' | 'month' | 'year' | 'decade';
const now = moment();
function disabledDate(current: Moment) {
// Can not select days before today
return current && current < moment().subtract(1, 'days').endOf('day');
}
function changePanelCallBack(value: Moment, mode: PanelMode) {
console.log(value, mode);
}
class Customize extends React.Component<{}, DateRangeState> {
poupContainerRef: React.RefObject<HTMLDivElement>;
constructor(props: {}) {
super(props);
this.poupContainerRef = React.createRef();
}
state: DateRangeState = {
initValue: now,
startValue: null,
endValue: null,
endOpen: false,
};
disabledStartDate = (startValue: Moment) => {
const { endValue } = this.state;
if (!startValue || !endValue) {
return false;
}
return startValue.valueOf() > endValue!.valueOf();
};
disabledEndDate = (endValue: Moment) => {
const { startValue } = this.state;
if (!endValue || !startValue) {
return false;
}
return endValue.valueOf() <= startValue.valueOf();
};
onChange = (field: string, value: Moment) => {
this.setState({
[field]: value,
} as any);
};
onStartChange = (value: Moment | null) => {
this.onChange('startValue', value!);
};
onEndChange = (value: Moment | null) => {
this.onChange('endValue', value!);
};
handleStartOpenChange = (open: boolean) => {
if (!open) {
console.error('Start Trigger end open:', open);
this.setState({ endOpen: true });
}
};
handleEndOpenChange = (open: boolean) => {
console.error('End Trigger end open:', open);
this.setState({ endOpen: open });
};
handleSelect = (value: Moment) => {
console.log('selected:', value);
this.setState({
initValue: value,
});
};
handleSelectMonth = (value: Moment) => {
console.log('month-calendar select', value && value.format('YYYY/MM'));
};
getPopupContainer = (node: HTMLElement) => {
console.log(node, 2333);
return this.poupContainerRef.current;
};
monthCellRender = (date: Moment) => (
<div
style={{
width: 60,
height: 40,
borderTop: '3px solid #CCC',
}}
>
{date.month() + 1}
</div>
);
render() {
const { startValue, endValue, endOpen, initValue } = this.state;
console.log('->', endOpen);
return (
<div>
<div
style={{
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-between',
}}
>
<div>
<h3>custom icon</h3>
<Picker
generateConfig={momentGenerateConfig}
locale={zhCN}
getPopupContainer={this.getPopupContainer}
// format="YYYY/MM/DD"
format={['YYYY-MM-DD', 'YYYY/MM/DD']}
allowClear
clearIcon={<span>X</span>}
suffixIcon={<span>O</span>}
prevIcon={<span><</span>}
nextIcon={<span>></span>}
superPrevIcon={<span><<</span>}
superNextIcon={<span>>></span>}
placeholder="please select"
// inputReadOnly
style={{ width: 200, height: 28 }}
/>
<div ref={this.poupContainerRef} />
</div>
<div>
<h3>extraFooterRender</h3>
<PickerPanel
generateConfig={momentGenerateConfig}
locale={zhCN}
showToday
disabledDate={disabledDate}
onSelect={this.handleSelect}
value={initValue}
onPanelChange={changePanelCallBack}
extraFooterRender={(mode: PanelMode) => <div>{mode} extra footer</div>}
/>
</div>
<div>
<h3>month picker</h3>
<PickerPanel
generateConfig={momentGenerateConfig}
locale={zhCN}
picker="month"
defaultValue={now}
onSelect={this.handleSelectMonth}
extraFooterRender={() => <div>extra footer</div>}
/>
</div>
<div>
<h3>monthCellRender</h3>
<PickerPanel
generateConfig={momentGenerateConfig}
locale={zhCN}
picker="month"
monthCellRender={this.monthCellRender}
/>
</div>
</div>
<Picker
generateConfig={momentGenerateConfig}
locale={zhCN}
defaultValue={now}
disabledDate={this.disabledStartDate}
showTime
format="YYYY-MM-DD HH:mm:ss"
value={startValue}
placeholder="Start"
onChange={this.onStartChange}
onOpenChange={this.handleStartOpenChange}
transitionName="slide-up"
/>
<Picker
generateConfig={momentGenerateConfig}
disabledDate={this.disabledEndDate}
locale={zhCN}
showTime
format="YYYY-MM-DD HH:mm:ss"
value={endValue}
placeholder="End"
onChange={this.onEndChange}
open={endOpen}
onOpenChange={this.handleEndOpenChange}
transitionName="slide-up"
/>
</div>
);
}
}
export default Customize;