@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.
@@ -1,28 +1,5 @@
1
- var _dec, _class;
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
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
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
- return Locale.browserLocale();
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
- return DateTime.browserTimeZone();
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
- this._input = el;
123
- this.props.inputRef?.(el);
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
- validateDate = date => {
141
- const {
142
- invalidDateErrorMessage
143
- } = this.props;
144
- const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
145
- const messages = [];
146
- // check if date is enabled
147
- const {
148
- disabledDates
149
- } = this.props;
150
- 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'))) {
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
- // check if date is valid
158
- if (!DateTime.parse(date, this.locale(), this.timezone(), [DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
159
- messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
160
- type: 'error',
161
- text: invalidDateErrorMessage
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
- return messages;
165
- };
166
- handleHideCalendar = (event, setectedDate) => {
167
- if (!this.props.children) {
168
- const dateString = setectedDate || this.props.value;
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
- this.setState({
179
- messages,
180
- isShowingCalendar: false
181
- });
182
- } else {
183
- this.props.onRequestValidateDate?.(event);
184
- this.props.onRequestHideCalendar?.(event);
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
- handleHighlightOption = (event, {
188
- direction
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
- this.setState({
207
- messages: []
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
- if (direction === 1) {
212
- if (onRequestSelectNextDay) {
213
- onRequestSelectNextDay?.(event);
214
- } else {
215
- // @ts-expect-error TODO
216
- onChange(event, {
217
- value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
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
- this.setState({
220
- messages: []
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
- renderMonthNavigationButton(type = 'prev') {
226
- const {
227
- renderPrevMonthButton,
228
- renderNextMonthButton
229
- } = this.props;
230
- const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
231
- return button && safeCloneElement(callRenderProp(button), {
232
- tabIndex: -1
233
- });
234
- }
235
- renderDays(getOptionProps) {
236
- const children = this.props.children;
237
- if (!children) return;
238
- return Children.map(children, day => {
239
- const {
240
- date,
241
- isOutsideMonth
242
- } = day.props;
243
- const props = {
244
- tabIndex: -1,
245
- id: this.formatDateId(date)
246
- };
247
- const optionProps = getOptionProps(props);
248
- const propsAdded = isOutsideMonth ? {
249
- ...props,
250
- onClick: optionProps.onClick,
251
- role: 'presentation'
252
- } : optionProps;
253
- return safeCloneElement(day, propsAdded);
254
- });
255
- }
256
- renderCalendar({
257
- getListProps,
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
- this.handleHideCalendar(e, dateString);
283
- }
284
- };
285
- return _jsx(Calendar, {
286
- ...getListProps({
287
- onRequestRenderNextMonth,
288
- onRequestRenderPrevMonth,
289
- renderNavigationLabel,
290
- renderWeekdayLabels,
291
- renderNextMonthButton: this.renderMonthNavigationButton('next'),
292
- renderPrevMonthButton: this.renderMonthNavigationButton('prev'),
293
- selectedLabel
294
- }),
295
- ...noChildrenProps,
296
- children: this.renderDays(getOptionProps)
297
- });
298
- }
299
- renderInput({
300
- getInputProps,
301
- getTriggerProps
302
- }) {
303
- const {
304
- renderLabel,
305
- value,
306
- placeholder,
307
- onBlur,
308
- isRequired,
309
- size,
310
- isInline,
311
- layout,
312
- width,
313
- onRequestValidateDate,
314
- onRequestShowCalendar,
315
- onRequestHideCalendar,
316
- onRequestSelectNextDay,
317
- onRequestSelectPrevDay,
318
- onRequestRenderNextMonth,
319
- onRequestRenderPrevMonth,
320
- ...rest
321
- } = this.props;
322
- const {
323
- interaction
324
- } = this;
325
- const {
326
- ref,
327
- // Apply this to the actual inputRef
328
- ...triggerProps
329
- } = getTriggerProps();
330
- const messages = this.props.messages || this.state.messages;
331
- return _jsx(TextInput, {
332
- ...triggerProps,
333
- ...passthroughProps(rest),
334
- ...getInputProps({
335
- renderLabel: callRenderProp(renderLabel),
336
- value,
337
- placeholder,
338
- size,
339
- layout,
340
- width,
341
- messages,
342
- onChange: this.handleInputChange,
343
- onBlur: createChainedFunction(onBlur, this.handleHideCalendar),
344
- inputRef: createChainedFunction(ref, this.handleInputRef),
345
- interaction,
346
- isRequired,
347
- display: isInline ? 'inline-block' : 'block',
348
- renderAfterInput: _jsx(IconCalendarMonthLine, {
349
- inline: false
350
- })
351
- }),
352
- onKeyDown: e => {
353
- if (!this.props.children) {
354
- if (e.key === 'Enter') {
355
- // @ts-expect-error TODO
356
- this.handleHideCalendar(e);
357
- }
358
- }
359
- triggerProps.onKeyDown?.(e);
360
- }
361
- });
362
- }
363
- shouldShowCalendar = () => this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
364
- render() {
365
- const {
366
- placement,
367
- assistiveText,
368
- styles
369
- } = this.props;
370
- const isShowingCalendar = this.shouldShowCalendar();
371
- return _jsx(Selectable, {
372
- isShowingOptions: isShowingCalendar,
373
- onRequestShowOptions: this.handleShowCalendar,
374
- onRequestHideOptions: this.handleHideCalendar,
375
- onRequestHighlightOption: this.handleHighlightOption,
376
- onRequestSelectOption: e => this.handleHideCalendar(e),
377
- selectedOptionId: this.selectedDateId,
378
- highlightedOptionId: this.selectedDateId,
379
- children: ({
380
- getRootProps,
381
- getInputProps,
382
- getTriggerProps,
383
- getListProps,
384
- getOptionProps,
385
- getDescriptionProps
386
- }) => _jsxs("span", {
387
- ...getRootProps({
388
- css: styles?.dateInput
389
- }),
390
- ref: el => {
391
- this.ref = el;
392
- },
393
- "data-cid": "DateInput",
394
- children: [this.renderInput({
395
- getInputProps,
396
- getTriggerProps
397
- }), _jsx("span", {
398
- ...getDescriptionProps(),
399
- css: styles?.assistiveText,
400
- children: assistiveText
401
- }), _jsx(Popover, {
402
- placement: placement,
403
- isShowingContent: isShowingCalendar,
404
- positionTarget: this._input,
405
- shouldReturnFocus: false,
406
- shouldFocusContentOnTriggerBlur: true,
407
- children: this.renderCalendar({
408
- getListProps,
409
- getOptionProps
410
- })
411
- })]
412
- })
413
- });
414
- }
415
- }) || _class);
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 };