react-dropdown-date 2.2.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/date-dropdown.component.d.ts +96 -0
- package/dist/day-picker.component.d.ts +23 -0
- package/dist/helper.d.ts +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +439 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +464 -0
- package/dist/index.js.map +1 -0
- package/dist/month-picker.component.d.ts +26 -0
- package/dist/year-picker.component.d.ts +23 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -66,6 +66,20 @@ class App extends Component {
|
|
|
66
66
|
console.log(date);
|
|
67
67
|
this.setState({ date: date, selectedDate: formatDate(date) });
|
|
68
68
|
}}
|
|
69
|
+
localizedMonths={ // default is the english options
|
|
70
|
+
0: 'January',
|
|
71
|
+
1: 'February',
|
|
72
|
+
2: 'March',
|
|
73
|
+
3: 'April',
|
|
74
|
+
4: 'May',
|
|
75
|
+
5: 'June',
|
|
76
|
+
6: 'July',
|
|
77
|
+
7: 'August',
|
|
78
|
+
8: 'September',
|
|
79
|
+
9: 'October',
|
|
80
|
+
10: 'November',
|
|
81
|
+
11: 'December'
|
|
82
|
+
}
|
|
69
83
|
ids={ // optional
|
|
70
84
|
{
|
|
71
85
|
year: 'select-year',
|
|
@@ -198,6 +212,20 @@ class App extends Component {
|
|
|
198
212
|
this.setState({ month });
|
|
199
213
|
console.log(month);
|
|
200
214
|
}}
|
|
215
|
+
localizedMonths={ // default is the english options
|
|
216
|
+
0: 'January',
|
|
217
|
+
1: 'February',
|
|
218
|
+
2: 'March',
|
|
219
|
+
3: 'April',
|
|
220
|
+
4: 'May',
|
|
221
|
+
5: 'June',
|
|
222
|
+
6: 'July',
|
|
223
|
+
7: 'August',
|
|
224
|
+
8: 'September',
|
|
225
|
+
9: 'October',
|
|
226
|
+
10: 'November',
|
|
227
|
+
11: 'December'
|
|
228
|
+
}
|
|
201
229
|
id={'month'}
|
|
202
230
|
name={'month'}
|
|
203
231
|
classes={'classes'}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare enum DropdownComponent {
|
|
3
|
+
year = "year",
|
|
4
|
+
month = "month",
|
|
5
|
+
day = "day"
|
|
6
|
+
}
|
|
7
|
+
interface IProps {
|
|
8
|
+
startDate?: string;
|
|
9
|
+
endDate?: string;
|
|
10
|
+
selectedDate?: string;
|
|
11
|
+
order?: DropdownComponent[];
|
|
12
|
+
onMonthChange?: Function;
|
|
13
|
+
onDayChange?: Function;
|
|
14
|
+
onYearChange?: Function;
|
|
15
|
+
onDateChange?: Function;
|
|
16
|
+
localizedMonths?: {
|
|
17
|
+
[key: number]: string;
|
|
18
|
+
};
|
|
19
|
+
ids?: {
|
|
20
|
+
year?: string;
|
|
21
|
+
month?: string;
|
|
22
|
+
day?: string;
|
|
23
|
+
};
|
|
24
|
+
names?: {
|
|
25
|
+
year?: string;
|
|
26
|
+
month?: string;
|
|
27
|
+
day?: string;
|
|
28
|
+
};
|
|
29
|
+
classes?: {
|
|
30
|
+
dateContainer?: string;
|
|
31
|
+
yearContainer?: string;
|
|
32
|
+
monthContainer?: string;
|
|
33
|
+
dayContainer?: string;
|
|
34
|
+
year?: string;
|
|
35
|
+
month?: string;
|
|
36
|
+
day?: string;
|
|
37
|
+
yearOptions?: string;
|
|
38
|
+
monthOptions?: string;
|
|
39
|
+
dayOptions?: string;
|
|
40
|
+
};
|
|
41
|
+
defaultValues?: {
|
|
42
|
+
year?: string;
|
|
43
|
+
month?: string;
|
|
44
|
+
day?: string;
|
|
45
|
+
};
|
|
46
|
+
options?: {
|
|
47
|
+
yearReverse?: boolean;
|
|
48
|
+
monthShort?: boolean;
|
|
49
|
+
monthCaps?: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface IState {
|
|
53
|
+
startYear: number;
|
|
54
|
+
startMonth: number;
|
|
55
|
+
startDay: number;
|
|
56
|
+
endYear: number;
|
|
57
|
+
endMonth: number;
|
|
58
|
+
endDay: number;
|
|
59
|
+
selectedYear: number;
|
|
60
|
+
selectedMonth: number;
|
|
61
|
+
selectedDay: number;
|
|
62
|
+
}
|
|
63
|
+
export declare class DropdownDate extends React.Component<IProps, IState> {
|
|
64
|
+
renderParts: any;
|
|
65
|
+
localizedMonthOptions: {
|
|
66
|
+
[key: number]: string;
|
|
67
|
+
};
|
|
68
|
+
constructor(props: IProps);
|
|
69
|
+
private getLocalizedMonthOptions;
|
|
70
|
+
static getDerivedStateFromProps(nextProps: IProps, prevState: IState): {
|
|
71
|
+
selectedYear: number;
|
|
72
|
+
selectedMonth?: undefined;
|
|
73
|
+
selectedDay?: undefined;
|
|
74
|
+
} | {
|
|
75
|
+
selectedMonth: number;
|
|
76
|
+
selectedYear?: undefined;
|
|
77
|
+
selectedDay?: undefined;
|
|
78
|
+
} | {
|
|
79
|
+
selectedDay: number;
|
|
80
|
+
selectedYear?: undefined;
|
|
81
|
+
selectedMonth?: undefined;
|
|
82
|
+
} | null;
|
|
83
|
+
componentDidUpdate(prevProps: IProps): void;
|
|
84
|
+
generateYearOptions(): JSX.Element[];
|
|
85
|
+
generateMonthOptions(): JSX.Element[];
|
|
86
|
+
generateDayOptions(): JSX.Element[];
|
|
87
|
+
handleDateChange: (type: DropdownComponent, value: number) => void;
|
|
88
|
+
handleYearChange: (e: any) => void;
|
|
89
|
+
handleMonthChange: (e: any) => void;
|
|
90
|
+
handleDayChange: (e: any) => void;
|
|
91
|
+
renderYear: () => JSX.Element;
|
|
92
|
+
renderMonth: () => JSX.Element;
|
|
93
|
+
renderDay: () => JSX.Element;
|
|
94
|
+
render: () => JSX.Element;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface IProps {
|
|
3
|
+
year: number;
|
|
4
|
+
month: number;
|
|
5
|
+
value: number;
|
|
6
|
+
onChange: Function;
|
|
7
|
+
id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
endYearGiven?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
classes?: string;
|
|
14
|
+
optionClasses?: string;
|
|
15
|
+
}
|
|
16
|
+
interface IState {
|
|
17
|
+
}
|
|
18
|
+
export declare class DayPicker extends React.Component<IProps, IState> {
|
|
19
|
+
renderDayOptions: () => JSX.Element[];
|
|
20
|
+
handleSelectionChange: (e: any) => any;
|
|
21
|
+
render: () => JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const monthByNumber: {
|
|
2
|
+
0: string;
|
|
3
|
+
1: string;
|
|
4
|
+
2: string;
|
|
5
|
+
3: string;
|
|
6
|
+
4: string;
|
|
7
|
+
5: string;
|
|
8
|
+
6: string;
|
|
9
|
+
7: string;
|
|
10
|
+
8: string;
|
|
11
|
+
9: string;
|
|
12
|
+
10: string;
|
|
13
|
+
11: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const numberByMonth: {
|
|
16
|
+
January: number;
|
|
17
|
+
February: number;
|
|
18
|
+
March: number;
|
|
19
|
+
April: number;
|
|
20
|
+
May: number;
|
|
21
|
+
June: number;
|
|
22
|
+
July: number;
|
|
23
|
+
August: number;
|
|
24
|
+
September: number;
|
|
25
|
+
October: number;
|
|
26
|
+
November: number;
|
|
27
|
+
December: number;
|
|
28
|
+
};
|
|
29
|
+
export declare const unit: {
|
|
30
|
+
day: string;
|
|
31
|
+
month: string;
|
|
32
|
+
year: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const getDaysInMonth: (year: number, month: number) => number;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/*! *****************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise */
|
|
18
|
+
|
|
19
|
+
var extendStatics = function(d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function __extends(d, b) {
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var YearPicker = /** @class */ (function (_super) {
|
|
33
|
+
__extends(YearPicker, _super);
|
|
34
|
+
function YearPicker() {
|
|
35
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
36
|
+
_this.renderYearOptions = function () {
|
|
37
|
+
var _a = _this.props, start = _a.start, end = _a.end, reverse = _a.reverse, optionClasses = _a.optionClasses, defaultValue = _a.defaultValue;
|
|
38
|
+
var startYear = start || 1900;
|
|
39
|
+
var endYear = end || new Date().getFullYear();
|
|
40
|
+
var years = [];
|
|
41
|
+
if (startYear <= endYear) {
|
|
42
|
+
for (var i = startYear; i <= endYear; ++i) {
|
|
43
|
+
years.push(i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
for (var i = endYear; i >= startYear; --i) {
|
|
48
|
+
years.push(i);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (reverse) {
|
|
52
|
+
years.reverse();
|
|
53
|
+
}
|
|
54
|
+
var yearOptions = [];
|
|
55
|
+
yearOptions.push(React.createElement("option", { value: "", key: -1, className: optionClasses }, defaultValue ? defaultValue : ''));
|
|
56
|
+
years.forEach(function (year, index) {
|
|
57
|
+
yearOptions.push(React.createElement("option", { value: year, key: index, className: optionClasses }, year));
|
|
58
|
+
});
|
|
59
|
+
return yearOptions;
|
|
60
|
+
};
|
|
61
|
+
_this.handleSelectionChange = function (e) { return _this.props.onChange(e.target.value); };
|
|
62
|
+
_this.render = function () {
|
|
63
|
+
var _a = _this.props, id = _a.id, name = _a.name, classes = _a.classes, required = _a.required, disabled = _a.disabled, value = _a.value;
|
|
64
|
+
return (React.createElement("select", { id: id, name: name, className: classes, required: required === true, disabled: disabled === true, onChange: _this.handleSelectionChange, value: value }, _this.renderYearOptions()));
|
|
65
|
+
};
|
|
66
|
+
return _this;
|
|
67
|
+
}
|
|
68
|
+
return YearPicker;
|
|
69
|
+
}(React.Component));
|
|
70
|
+
|
|
71
|
+
var monthByNumber = {
|
|
72
|
+
0: 'January',
|
|
73
|
+
1: 'February',
|
|
74
|
+
2: 'March',
|
|
75
|
+
3: 'April',
|
|
76
|
+
4: 'May',
|
|
77
|
+
5: 'June',
|
|
78
|
+
6: 'July',
|
|
79
|
+
7: 'August',
|
|
80
|
+
8: 'September',
|
|
81
|
+
9: 'October',
|
|
82
|
+
10: 'November',
|
|
83
|
+
11: 'December'
|
|
84
|
+
};
|
|
85
|
+
var getDaysInMonth = function (year, month) {
|
|
86
|
+
year = +(year);
|
|
87
|
+
month = +(month) + 1;
|
|
88
|
+
return new Date(year, month, 0).getDate();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
var MonthPicker = /** @class */ (function (_super) {
|
|
92
|
+
__extends(MonthPicker, _super);
|
|
93
|
+
function MonthPicker() {
|
|
94
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
95
|
+
_this.renderMonthOptions = function () {
|
|
96
|
+
var _a = _this.props, endYearGiven = _a.endYearGiven, year = _a.year, numeric = _a.numeric, caps = _a.caps, short = _a.short, optionClasses = _a.optionClasses, defaultValue = _a.defaultValue, localizedMonths = _a.localizedMonths;
|
|
97
|
+
var today = new Date();
|
|
98
|
+
var months = [];
|
|
99
|
+
var month = 11;
|
|
100
|
+
var localizedMonthOptions = (localizedMonths && Object.entries(localizedMonths).length > 0) ? localizedMonths : monthByNumber;
|
|
101
|
+
if (!endYearGiven) {
|
|
102
|
+
if (year && parseInt(year.toString()) === today.getFullYear()) {
|
|
103
|
+
month = today.getMonth();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (numeric) {
|
|
107
|
+
for (var i = 0; i <= month; ++i) {
|
|
108
|
+
months.push((i + 1).toString());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
for (var i = 0; i <= month; ++i) {
|
|
113
|
+
months.push(localizedMonthOptions[i]);
|
|
114
|
+
}
|
|
115
|
+
if (caps) {
|
|
116
|
+
months = months.map(function (month) { return month.toUpperCase(); });
|
|
117
|
+
}
|
|
118
|
+
if (short) {
|
|
119
|
+
months = months.map(function (month) { return month.substring(0, 3); });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
var monthOptions = [];
|
|
123
|
+
monthOptions.push(React.createElement("option", { value: "", key: -1, className: optionClasses }, defaultValue ? defaultValue : ''));
|
|
124
|
+
months.forEach(function (month, index) {
|
|
125
|
+
monthOptions.push(React.createElement("option", { value: index, key: index, className: optionClasses }, month));
|
|
126
|
+
});
|
|
127
|
+
return monthOptions;
|
|
128
|
+
};
|
|
129
|
+
_this.handleSelectionChange = function (e) { return _this.props.onChange(e.target.value); };
|
|
130
|
+
_this.render = function () {
|
|
131
|
+
var _a = _this.props, id = _a.id, name = _a.name, classes = _a.classes, required = _a.required, disabled = _a.disabled, value = _a.value;
|
|
132
|
+
return (React.createElement("select", { id: id, name: name, className: classes, required: required === true, disabled: disabled === true, value: value, onChange: _this.handleSelectionChange }, _this.renderMonthOptions()));
|
|
133
|
+
};
|
|
134
|
+
return _this;
|
|
135
|
+
}
|
|
136
|
+
return MonthPicker;
|
|
137
|
+
}(React.Component));
|
|
138
|
+
|
|
139
|
+
var DayPicker = /** @class */ (function (_super) {
|
|
140
|
+
__extends(DayPicker, _super);
|
|
141
|
+
function DayPicker() {
|
|
142
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
143
|
+
_this.renderDayOptions = function () {
|
|
144
|
+
var _a = _this.props, month = _a.month, year = _a.year, endYearGiven = _a.endYearGiven, optionClasses = _a.optionClasses, defaultValue = _a.defaultValue;
|
|
145
|
+
var days = month ? getDaysInMonth(year, month) : 31;
|
|
146
|
+
var today = new Date();
|
|
147
|
+
if (!endYearGiven) {
|
|
148
|
+
if (year === today.getFullYear() && month === today.getMonth()) {
|
|
149
|
+
days = today.getDate();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
var dayOptions = [];
|
|
153
|
+
dayOptions.push(React.createElement("option", { value: "", key: -1, className: optionClasses }, defaultValue ? defaultValue : ''));
|
|
154
|
+
for (var i = 1; i <= days; ++i) {
|
|
155
|
+
dayOptions.push(React.createElement("option", { value: i, key: i, className: optionClasses }, i));
|
|
156
|
+
}
|
|
157
|
+
return dayOptions;
|
|
158
|
+
};
|
|
159
|
+
_this.handleSelectionChange = function (e) { return _this.props.onChange(e.target.value); };
|
|
160
|
+
_this.render = function () {
|
|
161
|
+
var _a = _this.props, id = _a.id, name = _a.name, classes = _a.classes, required = _a.required, disabled = _a.disabled, value = _a.value;
|
|
162
|
+
return (React.createElement("select", { id: id, name: name, className: classes, onChange: _this.handleSelectionChange, required: required === true, disabled: disabled === true, value: value }, _this.renderDayOptions()));
|
|
163
|
+
};
|
|
164
|
+
return _this;
|
|
165
|
+
}
|
|
166
|
+
return DayPicker;
|
|
167
|
+
}(React.Component));
|
|
168
|
+
|
|
169
|
+
var DropdownComponent;
|
|
170
|
+
(function (DropdownComponent) {
|
|
171
|
+
DropdownComponent["year"] = "year";
|
|
172
|
+
DropdownComponent["month"] = "month";
|
|
173
|
+
DropdownComponent["day"] = "day";
|
|
174
|
+
})(DropdownComponent || (DropdownComponent = {}));
|
|
175
|
+
var DropdownDate = /** @class */ (function (_super) {
|
|
176
|
+
__extends(DropdownDate, _super);
|
|
177
|
+
function DropdownDate(props) {
|
|
178
|
+
var _this = _super.call(this, props) || this;
|
|
179
|
+
_this.handleDateChange = function (type, value) {
|
|
180
|
+
if (_this.props.onDateChange) {
|
|
181
|
+
var _a = _this.state, selectedYear = _a.selectedYear, selectedMonth = _a.selectedMonth, selectedDay = _a.selectedDay;
|
|
182
|
+
if (type === DropdownComponent.year) {
|
|
183
|
+
selectedYear = value;
|
|
184
|
+
}
|
|
185
|
+
else if (type === DropdownComponent.month) {
|
|
186
|
+
selectedMonth = value;
|
|
187
|
+
}
|
|
188
|
+
else if (type === DropdownComponent.day) {
|
|
189
|
+
selectedDay = value;
|
|
190
|
+
}
|
|
191
|
+
if (selectedYear !== -1 && selectedMonth !== -1 && selectedDay !== -1) {
|
|
192
|
+
_this.props.onDateChange(new Date(selectedYear, selectedMonth, selectedDay));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
_this.handleYearChange = function (e) {
|
|
197
|
+
var year = parseInt(e.target.value);
|
|
198
|
+
_this.setState({ selectedYear: year });
|
|
199
|
+
if (_this.props.onYearChange) {
|
|
200
|
+
_this.props.onYearChange(year);
|
|
201
|
+
}
|
|
202
|
+
_this.handleDateChange(DropdownComponent.year, year);
|
|
203
|
+
};
|
|
204
|
+
_this.handleMonthChange = function (e) {
|
|
205
|
+
var month = parseInt(e.target.value);
|
|
206
|
+
_this.setState({ selectedMonth: month });
|
|
207
|
+
if (_this.props.onMonthChange) {
|
|
208
|
+
_this.props.onMonthChange(_this.localizedMonthOptions[month]);
|
|
209
|
+
}
|
|
210
|
+
_this.handleDateChange(DropdownComponent.month, month);
|
|
211
|
+
};
|
|
212
|
+
_this.handleDayChange = function (e) {
|
|
213
|
+
var day = parseInt(e.target.value);
|
|
214
|
+
_this.setState({ selectedDay: day });
|
|
215
|
+
if (_this.props.onDayChange) {
|
|
216
|
+
_this.props.onDayChange(day);
|
|
217
|
+
}
|
|
218
|
+
_this.handleDateChange(DropdownComponent.day, day);
|
|
219
|
+
};
|
|
220
|
+
_this.renderYear = function () {
|
|
221
|
+
var _a = _this.props, classes = _a.classes, ids = _a.ids, names = _a.names;
|
|
222
|
+
return (React.createElement("div", { key: "year", id: "dropdown-year", className: (classes && classes.yearContainer) ? classes.yearContainer : undefined },
|
|
223
|
+
React.createElement("select", { id: (ids && ids.year) ? ids.year : undefined, name: (names && names.year) ? names.year : undefined, className: (classes && classes.year) ? classes.year : undefined, onChange: _this.handleYearChange, value: _this.state.selectedYear }, _this.generateYearOptions())));
|
|
224
|
+
};
|
|
225
|
+
_this.renderMonth = function () {
|
|
226
|
+
var _a = _this.props, classes = _a.classes, ids = _a.ids, names = _a.names;
|
|
227
|
+
return (React.createElement("div", { key: "month", id: "dropdown-month", className: (classes && classes.monthContainer) ? classes.monthContainer : undefined },
|
|
228
|
+
React.createElement("select", { id: (ids && ids.month) ? ids.month : undefined, name: (names && names.month) ? names.month : undefined, className: (classes && classes.month) ? classes.month : undefined, onChange: _this.handleMonthChange, value: _this.state.selectedMonth }, _this.generateMonthOptions())));
|
|
229
|
+
};
|
|
230
|
+
_this.renderDay = function () {
|
|
231
|
+
var _a = _this.props, classes = _a.classes, ids = _a.ids, names = _a.names;
|
|
232
|
+
return (React.createElement("div", { key: "day", id: "dropdown-day", className: (classes && classes.dayContainer) ? classes.dayContainer : undefined },
|
|
233
|
+
React.createElement("select", { id: (ids && ids.day) ? ids.day : undefined, name: (names && names.day) ? names.day : undefined, className: (classes && classes.day) ? classes.day : undefined, onChange: _this.handleDayChange, value: _this.state.selectedDay }, _this.generateDayOptions())));
|
|
234
|
+
};
|
|
235
|
+
_this.render = function () {
|
|
236
|
+
var classes = _this.props.classes;
|
|
237
|
+
var order = _this.props.order;
|
|
238
|
+
order = order || [DropdownComponent.year, DropdownComponent.month, DropdownComponent.day];
|
|
239
|
+
return (React.createElement("div", { id: "dropdown-date", className: (classes && classes.dateContainer) ? classes.dateContainer : undefined }, order.map(function (part) {
|
|
240
|
+
return _this.renderParts[part]();
|
|
241
|
+
})));
|
|
242
|
+
};
|
|
243
|
+
var startDate = props.startDate, endDate = props.endDate, selectedDate = props.selectedDate;
|
|
244
|
+
var sDate = startDate ? new Date(startDate) : new Date('1900-01-01');
|
|
245
|
+
var eDate = endDate ? new Date(endDate) : new Date();
|
|
246
|
+
var selDate = selectedDate ? new Date(selectedDate) : null;
|
|
247
|
+
_this.state = {
|
|
248
|
+
startYear: sDate.getFullYear(),
|
|
249
|
+
startMonth: sDate.getMonth(),
|
|
250
|
+
startDay: sDate.getDate(),
|
|
251
|
+
endYear: eDate.getFullYear(),
|
|
252
|
+
endMonth: eDate.getMonth(),
|
|
253
|
+
endDay: eDate.getDate(),
|
|
254
|
+
selectedYear: selDate ? selDate.getFullYear() : -1,
|
|
255
|
+
selectedMonth: selDate ? selDate.getMonth() : -1,
|
|
256
|
+
selectedDay: selDate ? selDate.getDate() : -1
|
|
257
|
+
};
|
|
258
|
+
_this.renderParts = {
|
|
259
|
+
year: _this.renderYear,
|
|
260
|
+
month: _this.renderMonth,
|
|
261
|
+
day: _this.renderDay,
|
|
262
|
+
};
|
|
263
|
+
_this.localizedMonthOptions = _this.getLocalizedMonthOptions(props.localizedMonths);
|
|
264
|
+
return _this;
|
|
265
|
+
}
|
|
266
|
+
DropdownDate.prototype.getLocalizedMonthOptions = function (localizedMonths) {
|
|
267
|
+
return (localizedMonths && Object.entries(localizedMonths).length > 0) ? localizedMonths : monthByNumber;
|
|
268
|
+
};
|
|
269
|
+
DropdownDate.getDerivedStateFromProps = function (nextProps, prevState) {
|
|
270
|
+
var selDate = nextProps.selectedDate ? new Date(nextProps.selectedDate) : null;
|
|
271
|
+
var tempSelDate = {
|
|
272
|
+
selectedYear: selDate ? selDate.getFullYear() : -1,
|
|
273
|
+
selectedMonth: selDate ? selDate.getMonth() : -1,
|
|
274
|
+
selectedDay: selDate ? selDate.getDate() : -1
|
|
275
|
+
};
|
|
276
|
+
if (tempSelDate.selectedYear !== prevState.selectedYear) {
|
|
277
|
+
return { selectedYear: tempSelDate.selectedYear };
|
|
278
|
+
}
|
|
279
|
+
if (tempSelDate.selectedMonth !== prevState.selectedMonth) {
|
|
280
|
+
return { selectedMonth: tempSelDate.selectedMonth };
|
|
281
|
+
}
|
|
282
|
+
if (tempSelDate.selectedDay !== prevState.selectedDay) {
|
|
283
|
+
return { selectedDay: tempSelDate.selectedDay };
|
|
284
|
+
}
|
|
285
|
+
return null;
|
|
286
|
+
};
|
|
287
|
+
DropdownDate.prototype.componentDidUpdate = function (prevProps) {
|
|
288
|
+
// Update localizedMonthOptions if localizedMonths prop changed
|
|
289
|
+
if (prevProps.localizedMonths !== this.props.localizedMonths) {
|
|
290
|
+
this.localizedMonthOptions = this.getLocalizedMonthOptions(this.props.localizedMonths);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
DropdownDate.prototype.generateYearOptions = function () {
|
|
294
|
+
var _a = this.props, classes = _a.classes, options = _a.options, defaultValues = _a.defaultValues;
|
|
295
|
+
var _b = this.state, startYear = _b.startYear, endYear = _b.endYear;
|
|
296
|
+
var yearOptions = [];
|
|
297
|
+
yearOptions.push(React.createElement("option", { key: -1, value: "-1", className: (classes && classes.yearOptions) ? classes.yearOptions : undefined }, (defaultValues && defaultValues.year) ? defaultValues.year : ''));
|
|
298
|
+
if (options && options.yearReverse) {
|
|
299
|
+
for (var i = endYear; i >= startYear; i--) {
|
|
300
|
+
yearOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.yearOptions) ? classes.yearOptions : undefined }, i));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
for (var i = startYear; i <= endYear; i++) {
|
|
305
|
+
yearOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.yearOptions) ? classes.yearOptions : undefined }, i));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return yearOptions;
|
|
309
|
+
};
|
|
310
|
+
DropdownDate.prototype.generateMonthOptions = function () {
|
|
311
|
+
var _a = this.props, classes = _a.classes, options = _a.options, defaultValues = _a.defaultValues;
|
|
312
|
+
var _b = this.state, startMonth = _b.startMonth, endMonth = _b.endMonth, startYear = _b.startYear, endYear = _b.endYear, selectedYear = _b.selectedYear;
|
|
313
|
+
var months = [];
|
|
314
|
+
if (selectedYear === startYear && selectedYear === endYear) {
|
|
315
|
+
for (var i = startMonth; i <= endMonth; i++) {
|
|
316
|
+
months.push({
|
|
317
|
+
value: i,
|
|
318
|
+
month: this.localizedMonthOptions[i]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else if (selectedYear === startYear) {
|
|
323
|
+
for (var i = startMonth; i <= 11; i++) {
|
|
324
|
+
months.push({
|
|
325
|
+
value: i,
|
|
326
|
+
month: this.localizedMonthOptions[i]
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else if (selectedYear === endYear) {
|
|
331
|
+
for (var i = 0; i <= endMonth; i++) {
|
|
332
|
+
months.push({
|
|
333
|
+
value: i,
|
|
334
|
+
month: this.localizedMonthOptions[i]
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
for (var i = 0; i <= 11; i++) {
|
|
340
|
+
months.push({
|
|
341
|
+
value: i,
|
|
342
|
+
month: this.localizedMonthOptions[i]
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (options && options.monthShort) {
|
|
347
|
+
months = months.map(function (elem) {
|
|
348
|
+
return {
|
|
349
|
+
value: elem.value,
|
|
350
|
+
month: elem.month.substring(0, 3)
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
if (options && options.monthCaps) {
|
|
355
|
+
months = months.map(function (elem) {
|
|
356
|
+
return {
|
|
357
|
+
value: elem.value,
|
|
358
|
+
month: elem.month.toUpperCase()
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
var monthOptions = [];
|
|
363
|
+
monthOptions.push(React.createElement("option", { key: -1, value: "-1", className: (classes && classes.monthOptions) ? classes.monthOptions : undefined }, (defaultValues && defaultValues.month) ? defaultValues.month : ''));
|
|
364
|
+
months.forEach(function (elem) {
|
|
365
|
+
monthOptions.push(React.createElement("option", { key: elem.value, value: elem.value, className: (classes && classes.monthOptions) ? classes.monthOptions : undefined }, elem.month));
|
|
366
|
+
});
|
|
367
|
+
return monthOptions;
|
|
368
|
+
};
|
|
369
|
+
DropdownDate.prototype.generateDayOptions = function () {
|
|
370
|
+
var _a = this.props, classes = _a.classes, defaultValues = _a.defaultValues;
|
|
371
|
+
var _b = this.state, startYear = _b.startYear, startMonth = _b.startMonth, startDay = _b.startDay, endYear = _b.endYear, endMonth = _b.endMonth, endDay = _b.endDay, selectedYear = _b.selectedYear, selectedMonth = _b.selectedMonth;
|
|
372
|
+
var dayOptions = [];
|
|
373
|
+
dayOptions.push(React.createElement("option", { key: -1, value: "-1", className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, (defaultValues && defaultValues.day) ? defaultValues.day : ''));
|
|
374
|
+
var monthDays = getDaysInMonth(selectedYear, selectedMonth);
|
|
375
|
+
if (selectedYear === startYear && selectedYear === endYear) {
|
|
376
|
+
if (selectedMonth === startMonth && selectedMonth === endMonth) {
|
|
377
|
+
for (var i = startDay; i <= endDay; i++) {
|
|
378
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else if (selectedMonth === startMonth) {
|
|
382
|
+
for (var i = startDay; i <= monthDays; i++) {
|
|
383
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else if (selectedMonth === endMonth) {
|
|
387
|
+
for (var i = 1; i <= endDay; i++) {
|
|
388
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
for (var i = 1; i <= monthDays; i++) {
|
|
393
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if (selectedYear === startYear) {
|
|
398
|
+
if (selectedMonth === startMonth) {
|
|
399
|
+
for (var i = startDay; i <= monthDays; i++) {
|
|
400
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
for (var i = 1; i <= monthDays; i++) {
|
|
405
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else if (selectedYear === endYear) {
|
|
410
|
+
if (selectedMonth === endMonth) {
|
|
411
|
+
for (var i = 1; i <= endDay; i++) {
|
|
412
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
for (var i = 1; i <= monthDays; i++) {
|
|
417
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
if (selectedMonth) {
|
|
423
|
+
for (var i = 1; i <= monthDays; i++) {
|
|
424
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
for (var i = 1; i <= 31; i++) {
|
|
429
|
+
dayOptions.push(React.createElement("option", { key: i, value: i, className: (classes && classes.dayOptions) ? classes.dayOptions : undefined }, i));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return dayOptions;
|
|
434
|
+
};
|
|
435
|
+
return DropdownDate;
|
|
436
|
+
}(React.Component));
|
|
437
|
+
|
|
438
|
+
export { DayPicker, DropdownComponent, DropdownDate, MonthPicker, YearPicker };
|
|
439
|
+
//# sourceMappingURL=index.esm.js.map
|