-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbasic.tsx
More file actions
145 lines (132 loc) · 5.27 KB
/
Copy pathbasic.tsx
File metadata and controls
145 lines (132 loc) · 5.27 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
/* tslint:disable:no-console */
import 'rmc-picker/assets/index.css';
import 'rmc-date-picker/assets/index.css';
import 'rmc-calendar/assets/index.less';
import React from 'react';
import ReactDOM from 'react-dom';
import { Calendar, ExtraData, CalendarPropsType } from '../src';
import zhCN from '../src/locale/zh_CN';
import enUS from '../src/locale/en_US';
const en = location.search.indexOf('en') !== -1;
const extra: { [key: string]: ExtraData } = {
1501516800000: { info: '建军节' },
'2017/06/14': { info: '禁止选择', disable: true },
'2017/06/15': { info: 'Disable', disable: true },
};
const now = new Date;
extra[+new Date(now.getFullYear(), now.getMonth(), now.getDate() + 5)] = { info: '禁止选择', disable: true };
extra[+new Date(now.getFullYear(), now.getMonth(), now.getDate() + 6)] = { info: 'Disable', disable: true };
extra[+new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7)] = { info: 'Disable', disable: true };
extra[+new Date(now.getFullYear(), now.getMonth(), now.getDate() + 8)] = { info: 'Disable', disable: true };
for (let key in extra) {
if (extra.hasOwnProperty(key)) {
let info = extra[key];
const date = new Date(key);
if (!Number.isNaN(+date) && !extra[+date]) {
extra[+date] = info;
}
}
}
class BasicDemo extends React.Component<{}, {
show: boolean;
config?: CalendarPropsType;
startTime?: Date;
endTime?: Date;
}> {
originbodyScrollY = document.getElementsByTagName('body')[0].style.overflowY;
constructor(props: any) {
super(props);
this.state = {
show: false,
config: {},
};
}
renderBtn(text: string, text2: string, config: CalendarPropsType = {}) {
return <div style={{ background: '#1A7BE6', padding: 5, margin: 10, textAlign: 'center' }}
onClick={() => {
document.getElementsByTagName('body')[0].style.overflowY = 'hidden';
this.setState({
show: true,
config,
});
}}>
<p style={{ color: '#fff', margin: 0, padding: 0 }}>{text}</p>
<p style={{ color: '#fff', margin: 0, padding: 0 }}>{text2}</p>
</div>;
}
renderMonthTitle = (date: Date) => {
const style = { color: 'rgba(25,124,217,1)', fontWeight: 600, fontSize: 14, lineHeight: 22 };
return <div style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
height: 40,
background: 'rgba(255,255,255,1) rgba(29,43,61,0.03)'}}>
<span style={{ ...style }}>{`${date.getFullYear()}年`}</span>
<span style={{ ...style }}>{`${date.getMonth()}月`}</span>
</div>;
}
render() {
return (
<div style={{ marginTop: 10, marginBottom: 10, fontSize: 14 }}>
{this.renderBtn('选择日期区间', 'Select Date Range')}
{this.renderBtn('选择日期时间区间', 'Select DateTime Range', { pickTime: true })}
{this.renderBtn('选择日期', 'Select Date', { type: 'one' })}
{this.renderBtn('选择日期时间', 'Select DateTime', { type: 'one', pickTime: true })}
{this.renderBtn('选择日期区间(快捷)', 'Select Date Range (Shortcut)', { showShortcut: true })}
{this.renderBtn('选择日期时间区间(快捷)', 'Select DateTime Range (Shortcut)', { pickTime: true, showShortcut: true })}
{this.renderBtn('水平进入', 'Horizontal Enter Aniamtion', { enterDirection: 'horizontal' })}
{this.renderBtn('默认选择范围', 'Selected Date Range', { defaultValue: [new Date(+new Date - 1 * 24 * 3600 * 1000), new Date(+new Date - 4 * 24 * 3600 * 1000)] })}
{this.renderBtn('onSelectAPI', 'onSelectAPI', {
onSelect: (date) => {
console.log('onSelect', date);
return [date, new Date(+new Date - 7 * 24 * 3600 * 1000)];
}
})}
<div style={{ marginLeft: 10, fontSize: 14 }}>
{
this.state.startTime &&
<p>开始时间:{this.state.startTime.toLocaleString()}</p>
}
{
this.state.endTime &&
<p>结束时间:{this.state.endTime.toLocaleString()}</p>
}
</div>
<Calendar
locale={en ? enUS : zhCN}
{...this.state.config}
visible={this.state.show}
onCancel={() => {
document.getElementsByTagName('body')[0].style.overflowY = this.originbodyScrollY;
this.setState({
show: false,
startTime: undefined,
endTime: undefined,
});
}}
onConfirm={(startTime, endTime) => {
console.log('onConfirm', startTime, endTime);
document.getElementsByTagName('body')[0].style.overflowY = this.originbodyScrollY;
this.setState({
show: false,
startTime,
endTime,
});
}}
onSelectHasDisableDate={(dates: Date[]) => {
console.warn('onSelectHasDisableDate', dates);
}}
getDateExtra={(date) => {
return extra[+date];
}}
minDate={new Date(+new Date - 62 * 24 * 3600 * 1000)}
maxDate={new Date(+new Date + 365 * 24 * 3600 * 1000)}
renderMonthTitle={this.renderMonthTitle}
/>
</div>
);
}
}
ReactDOM.render(<BasicDemo />, document.getElementById('__react-content'));