@instructure/ui-date-input 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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/CHANGELOG.md +13 -0
- package/es/DateInput/v1/index.js +295 -389
- package/es/DateInput/v1/props.js +40 -26
- package/es/DateInput/v1/styles.js +12 -45
- package/es/DateInput/v2/index.js +192 -275
- package/es/DateInput/v2/props.js +1 -1
- package/es/DateInput2/v1/index.js +188 -267
- package/es/DateInput2/v1/props.js +1 -1
- package/es/exports/a.js +1 -25
- package/es/exports/b.js +1 -25
- package/package.json +18 -24
- package/tsconfig.build.json +0 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/DateInput/v1/index.js +0 -426
- package/lib/DateInput/v1/props.js +0 -31
- package/lib/DateInput/v1/styles.js +0 -52
- package/lib/DateInput/v2/index.js +0 -299
- package/lib/DateInput/v2/props.js +0 -5
- package/lib/DateInput2/v1/index.js +0 -290
- package/lib/DateInput2/v1/props.js +0 -5
- package/lib/exports/a.js +0 -19
- package/lib/exports/b.js +0 -19
- package/lib/package.json +0 -1
package/es/DateInput/v1/index.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The MIT License (MIT)
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
1
|
+
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
26
3
|
import { Children, Component } from 'react';
|
|
27
4
|
import { Calendar } from '@instructure/ui-calendar/v11_6';
|
|
28
5
|
import { IconCalendarMonthLine } from '@instructure/ui-icons';
|
|
@@ -35,383 +12,312 @@ import { DateTime, Locale } from '@instructure/ui-i18n';
|
|
|
35
12
|
import { withStyle } from '@instructure/emotion';
|
|
36
13
|
import generateStyle from './styles.js';
|
|
37
14
|
import { allowedProps } from './props.js';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
category: components
|
|
42
|
-
---
|
|
43
|
-
**/
|
|
44
|
-
let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = class DateInput extends Component {
|
|
45
|
-
static displayName = 'DateInput';
|
|
46
|
-
static componentId = 'DateInput';
|
|
47
|
-
static Day = Calendar.Day;
|
|
48
|
-
static allowedProps = allowedProps;
|
|
49
|
-
static defaultProps = {
|
|
50
|
-
value: '',
|
|
51
|
-
size: 'medium',
|
|
52
|
-
onBlur: () => {},
|
|
53
|
-
// must have a default so createChainedFunction works
|
|
54
|
-
isRequired: false,
|
|
55
|
-
isInline: false,
|
|
56
|
-
layout: 'stacked',
|
|
57
|
-
display: 'inline-block',
|
|
58
|
-
placement: 'bottom center',
|
|
59
|
-
isShowingCalendar: false
|
|
60
|
-
};
|
|
61
|
-
state = {
|
|
62
|
-
hasInputRef: false,
|
|
63
|
-
isShowingCalendar: false,
|
|
64
|
-
validatedDate: undefined,
|
|
65
|
-
messages: []
|
|
66
|
-
};
|
|
67
|
-
_input = undefined;
|
|
68
|
-
ref = null;
|
|
69
|
-
locale() {
|
|
70
|
-
if (this.props.locale) {
|
|
71
|
-
return this.props.locale;
|
|
72
|
-
} else if (this.context && this.context.locale) {
|
|
73
|
-
return this.context.locale;
|
|
15
|
+
class DateInput extends Component {
|
|
16
|
+
static{
|
|
17
|
+
this.displayName = 'DateInput';
|
|
74
18
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
timezone() {
|
|
78
|
-
if (this.props.timezone) {
|
|
79
|
-
return this.props.timezone;
|
|
80
|
-
} else if (this.context && this.context.timezone) {
|
|
81
|
-
return this.context.timezone;
|
|
19
|
+
static{
|
|
20
|
+
this.componentId = 'DateInput';
|
|
82
21
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
componentDidMount() {
|
|
86
|
-
this.props.makeStyles?.();
|
|
87
|
-
}
|
|
88
|
-
componentDidUpdate() {
|
|
89
|
-
this.props.makeStyles?.();
|
|
90
|
-
}
|
|
91
|
-
get selectedDateId() {
|
|
92
|
-
let selectedDateId;
|
|
93
|
-
Children.toArray(this.props.children).forEach(day => {
|
|
94
|
-
const {
|
|
95
|
-
date,
|
|
96
|
-
isSelected
|
|
97
|
-
} = day.props;
|
|
98
|
-
if (isSelected) {
|
|
99
|
-
selectedDateId = this.formatDateId(date);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return selectedDateId;
|
|
103
|
-
}
|
|
104
|
-
get interaction() {
|
|
105
|
-
return getInteraction({
|
|
106
|
-
props: this.props
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
formatDateId = date => {
|
|
110
|
-
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
111
|
-
// date as the id.
|
|
112
|
-
return date.replace(/\s/g, '');
|
|
113
|
-
};
|
|
114
|
-
handleInputRef = el => {
|
|
115
|
-
// Ensures that we position the Calendar with respect to the input correctly
|
|
116
|
-
// if the Calendar is open on mount
|
|
117
|
-
if (!this.state.hasInputRef) {
|
|
118
|
-
this.setState({
|
|
119
|
-
hasInputRef: true
|
|
120
|
-
});
|
|
22
|
+
static{
|
|
23
|
+
this.Day = Calendar.Day;
|
|
121
24
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
handleInputChange = (event, value) => {
|
|
126
|
-
this.props.onChange?.(event, {
|
|
127
|
-
value
|
|
128
|
-
});
|
|
129
|
-
this.handleShowCalendar(event);
|
|
130
|
-
};
|
|
131
|
-
handleShowCalendar = event => {
|
|
132
|
-
if (!this.props.children) {
|
|
133
|
-
this.setState({
|
|
134
|
-
isShowingCalendar: true
|
|
135
|
-
});
|
|
136
|
-
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
137
|
-
this.props.onRequestShowCalendar?.(event);
|
|
25
|
+
static{
|
|
26
|
+
this.allowedProps = allowedProps;
|
|
138
27
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
152
|
-
type: 'error',
|
|
153
|
-
text: disabledDateErrorMessage
|
|
154
|
-
});
|
|
28
|
+
static{
|
|
29
|
+
this.defaultProps = {
|
|
30
|
+
value: '',
|
|
31
|
+
size: 'medium',
|
|
32
|
+
onBlur: ()=>{},
|
|
33
|
+
isRequired: false,
|
|
34
|
+
isInline: false,
|
|
35
|
+
layout: 'stacked',
|
|
36
|
+
display: 'inline-block',
|
|
37
|
+
placement: 'bottom center',
|
|
38
|
+
isShowingCalendar: false
|
|
39
|
+
};
|
|
155
40
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
41
|
+
locale() {
|
|
42
|
+
if (this.props.locale) {
|
|
43
|
+
return this.props.locale;
|
|
44
|
+
} else if (this.context && this.context.locale) {
|
|
45
|
+
return this.context.locale;
|
|
46
|
+
}
|
|
47
|
+
return Locale.browserLocale();
|
|
163
48
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const messages = [];
|
|
170
|
-
if (this.props.onRequestValidateDate) {
|
|
171
|
-
const userValidatedDate = this.props.onRequestValidateDate?.(event, dateString || '', this.validateDate(dateString || ''));
|
|
172
|
-
messages.push(...(userValidatedDate || []));
|
|
173
|
-
} else {
|
|
174
|
-
if (dateString) {
|
|
175
|
-
messages.push(...this.validateDate(dateString));
|
|
49
|
+
timezone() {
|
|
50
|
+
if (this.props.timezone) {
|
|
51
|
+
return this.props.timezone;
|
|
52
|
+
} else if (this.context && this.context.timezone) {
|
|
53
|
+
return this.context.timezone;
|
|
176
54
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
55
|
+
return DateTime.browserTimeZone();
|
|
56
|
+
}
|
|
57
|
+
componentDidMount() {
|
|
58
|
+
this.props.makeStyles?.();
|
|
59
|
+
}
|
|
60
|
+
componentDidUpdate() {
|
|
61
|
+
this.props.makeStyles?.();
|
|
62
|
+
}
|
|
63
|
+
get selectedDateId() {
|
|
64
|
+
let selectedDateId;
|
|
65
|
+
Children.toArray(this.props.children).forEach((day)=>{
|
|
66
|
+
const { date, isSelected } = day.props;
|
|
67
|
+
if (isSelected) {
|
|
68
|
+
selectedDateId = this.formatDateId(date);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return selectedDateId;
|
|
185
72
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}) => {
|
|
190
|
-
const {
|
|
191
|
-
onRequestSelectNextDay,
|
|
192
|
-
onRequestSelectPrevDay,
|
|
193
|
-
onChange,
|
|
194
|
-
value,
|
|
195
|
-
currentDate
|
|
196
|
-
} = this.props;
|
|
197
|
-
const isValueValid = value && DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
198
|
-
if (direction === -1) {
|
|
199
|
-
if (onRequestSelectPrevDay) {
|
|
200
|
-
onRequestSelectPrevDay?.(event);
|
|
201
|
-
} else {
|
|
202
|
-
// @ts-expect-error TODO
|
|
203
|
-
onChange(event, {
|
|
204
|
-
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
73
|
+
get interaction() {
|
|
74
|
+
return getInteraction({
|
|
75
|
+
props: this.props
|
|
205
76
|
});
|
|
206
|
-
|
|
207
|
-
|
|
77
|
+
}
|
|
78
|
+
renderMonthNavigationButton(type = 'prev') {
|
|
79
|
+
const { renderPrevMonthButton, renderNextMonthButton } = this.props;
|
|
80
|
+
const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
|
|
81
|
+
return button && safeCloneElement(callRenderProp(button), {
|
|
82
|
+
tabIndex: -1
|
|
208
83
|
});
|
|
209
|
-
}
|
|
210
84
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
85
|
+
renderDays(getOptionProps) {
|
|
86
|
+
const children = this.props.children;
|
|
87
|
+
if (!children) return;
|
|
88
|
+
return Children.map(children, (day)=>{
|
|
89
|
+
const { date, isOutsideMonth } = day.props;
|
|
90
|
+
const props = {
|
|
91
|
+
tabIndex: -1,
|
|
92
|
+
id: this.formatDateId(date)
|
|
93
|
+
};
|
|
94
|
+
const optionProps = getOptionProps(props);
|
|
95
|
+
const propsAdded = isOutsideMonth ? {
|
|
96
|
+
...props,
|
|
97
|
+
onClick: optionProps.onClick,
|
|
98
|
+
role: 'presentation'
|
|
99
|
+
} : optionProps;
|
|
100
|
+
return safeCloneElement(day, propsAdded);
|
|
218
101
|
});
|
|
219
|
-
|
|
220
|
-
|
|
102
|
+
}
|
|
103
|
+
renderCalendar({ getListProps, getOptionProps }) {
|
|
104
|
+
const { onRequestRenderNextMonth, onRequestRenderPrevMonth, renderNavigationLabel, renderWeekdayLabels, value, onChange, disabledDates, currentDate, selectedLabel } = this.props;
|
|
105
|
+
const isValidDate = value ? DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
106
|
+
const noChildrenProps = this.props.children ? {} : {
|
|
107
|
+
disabledDates,
|
|
108
|
+
currentDate,
|
|
109
|
+
selectedDate: isValidDate ? value : undefined,
|
|
110
|
+
visibleMonth: isValidDate ? value : undefined,
|
|
111
|
+
onDateSelected: (dateString, momentDate, e)=>{
|
|
112
|
+
onChange?.(e, {
|
|
113
|
+
value: `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`
|
|
114
|
+
});
|
|
115
|
+
this.handleHideCalendar(e, dateString);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return /*#__PURE__*/ _jsx(Calendar, {
|
|
119
|
+
...getListProps({
|
|
120
|
+
onRequestRenderNextMonth,
|
|
121
|
+
onRequestRenderPrevMonth,
|
|
122
|
+
renderNavigationLabel,
|
|
123
|
+
renderWeekdayLabels,
|
|
124
|
+
renderNextMonthButton: this.renderMonthNavigationButton('next'),
|
|
125
|
+
renderPrevMonthButton: this.renderMonthNavigationButton('prev'),
|
|
126
|
+
selectedLabel
|
|
127
|
+
}),
|
|
128
|
+
...noChildrenProps,
|
|
129
|
+
children: this.renderDays(getOptionProps)
|
|
221
130
|
});
|
|
222
|
-
}
|
|
223
131
|
}
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
getOptionProps
|
|
259
|
-
}) {
|
|
260
|
-
const {
|
|
261
|
-
onRequestRenderNextMonth,
|
|
262
|
-
onRequestRenderPrevMonth,
|
|
263
|
-
renderNavigationLabel,
|
|
264
|
-
renderWeekdayLabels,
|
|
265
|
-
value,
|
|
266
|
-
onChange,
|
|
267
|
-
disabledDates,
|
|
268
|
-
currentDate,
|
|
269
|
-
selectedLabel
|
|
270
|
-
} = this.props;
|
|
271
|
-
const isValidDate = value ? DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
272
|
-
const noChildrenProps = this.props.children ? {} : {
|
|
273
|
-
disabledDates,
|
|
274
|
-
currentDate,
|
|
275
|
-
selectedDate: isValidDate ? value : undefined,
|
|
276
|
-
visibleMonth: isValidDate ? value : undefined,
|
|
277
|
-
onDateSelected: (dateString, momentDate, e) => {
|
|
278
|
-
// @ts-expect-error TODO
|
|
279
|
-
onChange?.(e, {
|
|
280
|
-
value: `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`
|
|
132
|
+
renderInput({ getInputProps, getTriggerProps }) {
|
|
133
|
+
const { renderLabel, value, placeholder, onBlur, isRequired, size, isInline, layout, width, onRequestValidateDate, onRequestShowCalendar, onRequestHideCalendar, onRequestSelectNextDay, onRequestSelectPrevDay, onRequestRenderNextMonth, onRequestRenderPrevMonth, ...rest } = this.props;
|
|
134
|
+
const { interaction } = this;
|
|
135
|
+
const { ref, ...triggerProps } = getTriggerProps();
|
|
136
|
+
const messages = this.props.messages || this.state.messages;
|
|
137
|
+
return /*#__PURE__*/ _jsx(TextInput, {
|
|
138
|
+
...triggerProps,
|
|
139
|
+
...passthroughProps(rest),
|
|
140
|
+
...getInputProps({
|
|
141
|
+
renderLabel: callRenderProp(renderLabel),
|
|
142
|
+
value,
|
|
143
|
+
placeholder,
|
|
144
|
+
size,
|
|
145
|
+
layout,
|
|
146
|
+
width,
|
|
147
|
+
messages,
|
|
148
|
+
onChange: this.handleInputChange,
|
|
149
|
+
onBlur: createChainedFunction(onBlur, this.handleHideCalendar),
|
|
150
|
+
inputRef: createChainedFunction(ref, this.handleInputRef),
|
|
151
|
+
interaction,
|
|
152
|
+
isRequired,
|
|
153
|
+
display: isInline ? 'inline-block' : 'block',
|
|
154
|
+
renderAfterInput: /*#__PURE__*/ _jsx(IconCalendarMonthLine, {
|
|
155
|
+
inline: false
|
|
156
|
+
})
|
|
157
|
+
}),
|
|
158
|
+
onKeyDown: (e)=>{
|
|
159
|
+
if (!this.props.children) {
|
|
160
|
+
if (e.key === 'Enter') {
|
|
161
|
+
this.handleHideCalendar(e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
triggerProps.onKeyDown?.(e);
|
|
165
|
+
}
|
|
281
166
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
167
|
+
}
|
|
168
|
+
render() {
|
|
169
|
+
const { placement, assistiveText, styles } = this.props;
|
|
170
|
+
const isShowingCalendar = this.shouldShowCalendar();
|
|
171
|
+
return /*#__PURE__*/ _jsx(Selectable, {
|
|
172
|
+
isShowingOptions: isShowingCalendar,
|
|
173
|
+
onRequestShowOptions: this.handleShowCalendar,
|
|
174
|
+
onRequestHideOptions: this.handleHideCalendar,
|
|
175
|
+
onRequestHighlightOption: this.handleHighlightOption,
|
|
176
|
+
onRequestSelectOption: (e)=>this.handleHideCalendar(e),
|
|
177
|
+
selectedOptionId: this.selectedDateId,
|
|
178
|
+
highlightedOptionId: this.selectedDateId,
|
|
179
|
+
children: ({ getRootProps, getInputProps, getTriggerProps, getListProps, getOptionProps, getDescriptionProps })=>/*#__PURE__*/ _jsxs("span", {
|
|
180
|
+
...getRootProps({
|
|
181
|
+
css: styles?.dateInput
|
|
182
|
+
}),
|
|
183
|
+
ref: (el)=>{
|
|
184
|
+
this.ref = el;
|
|
185
|
+
},
|
|
186
|
+
"data-cid": "DateInput",
|
|
187
|
+
children: [
|
|
188
|
+
this.renderInput({
|
|
189
|
+
getInputProps,
|
|
190
|
+
getTriggerProps
|
|
191
|
+
}),
|
|
192
|
+
/*#__PURE__*/ _jsx("span", {
|
|
193
|
+
...getDescriptionProps(),
|
|
194
|
+
css: styles?.assistiveText,
|
|
195
|
+
children: assistiveText
|
|
196
|
+
}),
|
|
197
|
+
/*#__PURE__*/ _jsx(Popover, {
|
|
198
|
+
placement: placement,
|
|
199
|
+
isShowingContent: isShowingCalendar,
|
|
200
|
+
positionTarget: this._input,
|
|
201
|
+
shouldReturnFocus: false,
|
|
202
|
+
shouldFocusContentOnTriggerBlur: true,
|
|
203
|
+
children: this.renderCalendar({
|
|
204
|
+
getListProps,
|
|
205
|
+
getOptionProps
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
constructor(...args){
|
|
213
|
+
super(...args), this.state = {
|
|
214
|
+
hasInputRef: false,
|
|
215
|
+
isShowingCalendar: false,
|
|
216
|
+
validatedDate: undefined,
|
|
217
|
+
messages: []
|
|
218
|
+
}, this._input = undefined, this.ref = null, this.formatDateId = (date)=>{
|
|
219
|
+
return date.replace(/\s/g, '');
|
|
220
|
+
}, this.handleInputRef = (el)=>{
|
|
221
|
+
if (!this.state.hasInputRef) {
|
|
222
|
+
this.setState({
|
|
223
|
+
hasInputRef: true
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
this._input = el;
|
|
227
|
+
this.props.inputRef?.(el);
|
|
228
|
+
}, this.handleInputChange = (event, value)=>{
|
|
229
|
+
this.props.onChange?.(event, {
|
|
230
|
+
value
|
|
231
|
+
});
|
|
232
|
+
this.handleShowCalendar(event);
|
|
233
|
+
}, this.handleShowCalendar = (event)=>{
|
|
234
|
+
if (!this.props.children) {
|
|
235
|
+
this.setState({
|
|
236
|
+
isShowingCalendar: true
|
|
237
|
+
});
|
|
238
|
+
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
239
|
+
this.props.onRequestShowCalendar?.(event);
|
|
240
|
+
}
|
|
241
|
+
}, this.validateDate = (date)=>{
|
|
242
|
+
const { invalidDateErrorMessage } = this.props;
|
|
243
|
+
const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
|
|
244
|
+
const messages = [];
|
|
245
|
+
const { disabledDates } = this.props;
|
|
246
|
+
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find((dateString)=>DateTime.parse(dateString, this.locale(), this.timezone()).isSame(DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
247
|
+
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
248
|
+
type: 'error',
|
|
249
|
+
text: disabledDateErrorMessage
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (!DateTime.parse(date, this.locale(), this.timezone(), [
|
|
253
|
+
DateTime.momentISOFormat,
|
|
254
|
+
'llll',
|
|
255
|
+
'LLLL',
|
|
256
|
+
'lll',
|
|
257
|
+
'LLL',
|
|
258
|
+
'll',
|
|
259
|
+
'LL',
|
|
260
|
+
'l',
|
|
261
|
+
'L'
|
|
262
|
+
], true).isValid()) {
|
|
263
|
+
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
264
|
+
type: 'error',
|
|
265
|
+
text: invalidDateErrorMessage
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return messages;
|
|
269
|
+
}, this.handleHideCalendar = (event, setectedDate)=>{
|
|
270
|
+
if (!this.props.children) {
|
|
271
|
+
const dateString = setectedDate || this.props.value;
|
|
272
|
+
const messages = [];
|
|
273
|
+
if (this.props.onRequestValidateDate) {
|
|
274
|
+
const userValidatedDate = this.props.onRequestValidateDate?.(event, dateString || '', this.validateDate(dateString || ''));
|
|
275
|
+
messages.push(...userValidatedDate || []);
|
|
276
|
+
} else {
|
|
277
|
+
if (dateString) {
|
|
278
|
+
messages.push(...this.validateDate(dateString));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
this.setState({
|
|
282
|
+
messages,
|
|
283
|
+
isShowingCalendar: false
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
this.props.onRequestValidateDate?.(event);
|
|
287
|
+
this.props.onRequestHideCalendar?.(event);
|
|
288
|
+
}
|
|
289
|
+
}, this.handleHighlightOption = (event, { direction })=>{
|
|
290
|
+
const { onRequestSelectNextDay, onRequestSelectPrevDay, onChange, value, currentDate } = this.props;
|
|
291
|
+
const isValueValid = value && DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
292
|
+
if (direction === -1) {
|
|
293
|
+
if (onRequestSelectPrevDay) {
|
|
294
|
+
onRequestSelectPrevDay?.(event);
|
|
295
|
+
} else {
|
|
296
|
+
onChange(event, {
|
|
297
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
298
|
+
});
|
|
299
|
+
this.setState({
|
|
300
|
+
messages: []
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (direction === 1) {
|
|
305
|
+
if (onRequestSelectNextDay) {
|
|
306
|
+
onRequestSelectNextDay?.(event);
|
|
307
|
+
} else {
|
|
308
|
+
onChange(event, {
|
|
309
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
|
|
310
|
+
});
|
|
311
|
+
this.setState({
|
|
312
|
+
messages: []
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}, this.shouldShowCalendar = ()=>this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
DateInput = _ts_decorate([
|
|
320
|
+
withStyle(generateStyle, null)
|
|
321
|
+
], DateInput);
|
|
416
322
|
export default DateInput;
|
|
417
|
-
export { DateInput };
|
|
323
|
+
export { DateInput };
|