@instructure/ui-date-time-input 8.25.1-snapshot-7 → 8.25.1-snapshot-10

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.25.1-snapshot-7](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-7) (2022-06-13)
6
+ ## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-date-time-input
9
9
 
@@ -1,4 +1,4 @@
1
- var _dec, _class, _class2, _IconArrowOpenStartSo, _IconArrowOpenEndSoli;
1
+ var _dec, _class, _IconArrowOpenStartSo, _IconArrowOpenEndSoli;
2
2
 
3
3
  /*
4
4
  * The MIT License (MIT)
@@ -42,169 +42,33 @@ category: components
42
42
  @tsProps
43
43
  **/
44
44
 
45
- let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeInput extends Component {
45
+ let DateTimeInput = (_dec = testable(), _dec(_class = class DateTimeInput extends Component {
46
+ static displayName = "DateTimeInput";
46
47
  // extra verbose localized date and time
47
- // This is used by Tooltip for positioning
48
+ static DEFAULT_MESSAGE_FORMAT = 'LLLL';
49
+ static propTypes = propTypes;
50
+ static allowedProps = allowedProps;
51
+ static defaultProps = {
52
+ layout: 'inline',
53
+ colSpacing: 'medium',
54
+ rowSpacing: 'small',
55
+ timeStep: 30,
56
+ messageFormat: DateTimeInput.DEFAULT_MESSAGE_FORMAT,
57
+ isRequired: false,
58
+ dateFormat: 'LL' // Localized date with full month, e.g. "August 6, 2014"
59
+
60
+ };
61
+ static contextType = ApplyLocaleContext;
62
+ ref = null; // This is used by Tooltip for positioning
63
+
64
+ handleRef = el => {
65
+ this.ref = el;
66
+ };
67
+
48
68
  constructor(props) {
49
69
  super(props); // State needs to be calculated because render could be called before
50
70
  // componentDidMount()
51
71
 
52
- this.context = void 0;
53
- this.ref = null;
54
-
55
- this.handleRef = el => {
56
- this.ref = el;
57
- };
58
-
59
- this.handleDateTextChange = (_event, date) => {
60
- const dateParsed = this.tryParseDate(date.value);
61
- this.setState({
62
- dateInputText: date.value,
63
- dateInputTextChanged: true,
64
- calendarSelectedDate: dateParsed ? dateParsed : void 0,
65
- renderedDate: dateParsed ? dateParsed.clone() : DateTime.now(this.locale(), this.timezone())
66
- });
67
- };
68
-
69
- this.handleDayClick = (event, _ref) => {
70
- let date = _ref.date;
71
- const dateParsed = DateTime.parse(date, this.locale(), this.timezone());
72
- this.updateStateBasedOnDateInput(dateParsed, event);
73
- };
74
-
75
- this.handleHideCalendar = event => {
76
- // update state based on the DateInput's text value
77
- if (this.state.dateInputTextChanged || event.key === 'Enter') {
78
- const dateParsed = this.tryParseDate(this.state.dateInputText);
79
- this.updateStateBasedOnDateInput(dateParsed, event);
80
- } else {
81
- // user clicked outside or tabbed away or pressed esc, reset text
82
- this.setState({
83
- dateInputText: this.state.iso ? this.state.iso.format(this.dateFormat) : '',
84
- calendarSelectedDate: this.state.iso ? this.state.iso.clone() : void 0
85
- });
86
- }
87
-
88
- this.setState({
89
- isShowingCalendar: false,
90
- dateInputTextChanged: false
91
- });
92
- };
93
-
94
- this.handleTimeChange = (event, option) => {
95
- let newValue;
96
-
97
- if (this.state.iso) {
98
- newValue = option.value;
99
- } else {
100
- // if no date is set just return the input text, it will error
101
- newValue = option.inputText;
102
- }
103
-
104
- const newState = this.recalculateState(newValue, true, false);
105
- this.changeStateIfNeeded(newState, event);
106
- this.setState({
107
- timeSelectValue: option.value
108
- });
109
- };
110
-
111
- this.changeStateIfNeeded = (newState, e) => {
112
- this.setState({
113
- message: newState.message
114
- });
115
-
116
- if (!newState.iso && !this.state.iso) {
117
- return;
118
- }
119
-
120
- if (!this.state.iso || !newState.iso || !this.state.iso.isSame(newState.iso)) {
121
- this.setState(newState);
122
-
123
- if (this.props.onChange) {
124
- var _newState$iso;
125
-
126
- this.props.onChange(e, (_newState$iso = newState.iso) === null || _newState$iso === void 0 ? void 0 : _newState$iso.toISOString());
127
- }
128
- }
129
- };
130
-
131
- this.handleBlur = e => {
132
- // when TABbing from the DateInput to TimeInput or visa-versa, the blur
133
- // happens on the target before the relatedTarget gets focus.
134
- // The timeout gives it a moment for that to happen
135
- if (typeof this.props.onBlur === 'function') {
136
- window.setTimeout(() => {
137
- var _this$props$onBlur, _this$props;
138
-
139
- (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, e);
140
- }, 0);
141
- }
142
- };
143
-
144
- this.handleShowCalendar = _event => {
145
- this.setState({
146
- isShowingCalendar: true
147
- });
148
- };
149
-
150
- this.handleSelectNextDay = _event => {
151
- let toAlter;
152
-
153
- if (this.state.calendarSelectedDate) {
154
- toAlter = this.state.calendarSelectedDate.clone();
155
- } else if (this.state.iso) {
156
- toAlter = this.state.iso.clone();
157
- } else {
158
- toAlter = DateTime.now(this.locale(), this.timezone());
159
- }
160
-
161
- toAlter.add({
162
- days: 1
163
- });
164
- this.setState({
165
- calendarSelectedDate: toAlter,
166
- renderedDate: toAlter.clone(),
167
- dateInputText: toAlter.format(this.dateFormat)
168
- });
169
- };
170
-
171
- this.handleSelectPrevDay = _event => {
172
- let toAlter;
173
-
174
- if (this.state.calendarSelectedDate) {
175
- toAlter = this.state.calendarSelectedDate.clone();
176
- } else if (this.state.iso) {
177
- toAlter = this.state.iso.clone();
178
- } else {
179
- toAlter = DateTime.now(this.locale(), this.timezone());
180
- }
181
-
182
- toAlter.subtract({
183
- days: 1
184
- });
185
- this.setState({
186
- calendarSelectedDate: toAlter,
187
- renderedDate: toAlter.clone(),
188
- dateInputText: toAlter.format(this.dateFormat)
189
- });
190
- };
191
-
192
- this.handleRenderNextMonth = _event => {
193
- this.setState({
194
- renderedDate: this.state.renderedDate.clone().add({
195
- months: 1
196
- })
197
- });
198
- };
199
-
200
- this.handleRenderPrevMonth = _event => {
201
- this.setState({
202
- renderedDate: this.state.renderedDate.clone().subtract({
203
- months: 1
204
- })
205
- });
206
- };
207
-
208
72
  this.state = this.recalculateState(props.value || props.defaultValue);
209
73
  }
210
74
 
@@ -348,12 +212,46 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
348
212
  } // Called when the user enters text into dateInput
349
213
 
350
214
 
215
+ handleDateTextChange = (_event, date) => {
216
+ const dateParsed = this.tryParseDate(date.value);
217
+ this.setState({
218
+ dateInputText: date.value,
219
+ dateInputTextChanged: true,
220
+ calendarSelectedDate: dateParsed ? dateParsed : void 0,
221
+ renderedDate: dateParsed ? dateParsed.clone() : DateTime.now(this.locale(), this.timezone())
222
+ });
223
+ };
224
+
351
225
  tryParseDate(val) {
352
226
  const parsed = DateTime.parse(val, this.locale(), this.timezone());
353
227
  return parsed.isValid() ? parsed : null;
354
228
  } // date is returned es a ISO string, like 2021-09-14T22:00:00.000Z
355
229
 
356
230
 
231
+ handleDayClick = (event, _ref) => {
232
+ let date = _ref.date;
233
+ const dateParsed = DateTime.parse(date, this.locale(), this.timezone());
234
+ this.updateStateBasedOnDateInput(dateParsed, event);
235
+ };
236
+ handleHideCalendar = event => {
237
+ // update state based on the DateInput's text value
238
+ if (this.state.dateInputTextChanged || event.key === 'Enter') {
239
+ const dateParsed = this.tryParseDate(this.state.dateInputText);
240
+ this.updateStateBasedOnDateInput(dateParsed, event);
241
+ } else {
242
+ // user clicked outside or tabbed away or pressed esc, reset text
243
+ this.setState({
244
+ dateInputText: this.state.iso ? this.state.iso.format(this.dateFormat) : '',
245
+ calendarSelectedDate: this.state.iso ? this.state.iso.clone() : void 0
246
+ });
247
+ }
248
+
249
+ this.setState({
250
+ isShowingCalendar: false,
251
+ dateInputTextChanged: false
252
+ });
253
+ };
254
+
357
255
  updateStateBasedOnDateInput(dateParsed, event) {
358
256
  let newState;
359
257
 
@@ -375,6 +273,113 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
375
273
  this.changeStateIfNeeded(newState, event);
376
274
  }
377
275
 
276
+ handleTimeChange = (event, option) => {
277
+ let newValue;
278
+
279
+ if (this.state.iso) {
280
+ newValue = option.value;
281
+ } else {
282
+ // if no date is set just return the input text, it will error
283
+ newValue = option.inputText;
284
+ }
285
+
286
+ const newState = this.recalculateState(newValue, true, false);
287
+ this.changeStateIfNeeded(newState, event);
288
+ this.setState({
289
+ timeSelectValue: option.value
290
+ });
291
+ };
292
+ changeStateIfNeeded = (newState, e) => {
293
+ this.setState({
294
+ message: newState.message
295
+ });
296
+
297
+ if (!newState.iso && !this.state.iso) {
298
+ return;
299
+ }
300
+
301
+ if (!this.state.iso || !newState.iso || !this.state.iso.isSame(newState.iso)) {
302
+ this.setState(newState);
303
+
304
+ if (this.props.onChange) {
305
+ var _newState$iso;
306
+
307
+ this.props.onChange(e, (_newState$iso = newState.iso) === null || _newState$iso === void 0 ? void 0 : _newState$iso.toISOString());
308
+ }
309
+ }
310
+ };
311
+ handleBlur = e => {
312
+ // when TABbing from the DateInput to TimeInput or visa-versa, the blur
313
+ // happens on the target before the relatedTarget gets focus.
314
+ // The timeout gives it a moment for that to happen
315
+ if (typeof this.props.onBlur === 'function') {
316
+ window.setTimeout(() => {
317
+ var _this$props$onBlur, _this$props;
318
+
319
+ (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, e);
320
+ }, 0);
321
+ }
322
+ };
323
+ handleShowCalendar = _event => {
324
+ this.setState({
325
+ isShowingCalendar: true
326
+ });
327
+ };
328
+ handleSelectNextDay = _event => {
329
+ let toAlter;
330
+
331
+ if (this.state.calendarSelectedDate) {
332
+ toAlter = this.state.calendarSelectedDate.clone();
333
+ } else if (this.state.iso) {
334
+ toAlter = this.state.iso.clone();
335
+ } else {
336
+ toAlter = DateTime.now(this.locale(), this.timezone());
337
+ }
338
+
339
+ toAlter.add({
340
+ days: 1
341
+ });
342
+ this.setState({
343
+ calendarSelectedDate: toAlter,
344
+ renderedDate: toAlter.clone(),
345
+ dateInputText: toAlter.format(this.dateFormat)
346
+ });
347
+ };
348
+ handleSelectPrevDay = _event => {
349
+ let toAlter;
350
+
351
+ if (this.state.calendarSelectedDate) {
352
+ toAlter = this.state.calendarSelectedDate.clone();
353
+ } else if (this.state.iso) {
354
+ toAlter = this.state.iso.clone();
355
+ } else {
356
+ toAlter = DateTime.now(this.locale(), this.timezone());
357
+ }
358
+
359
+ toAlter.subtract({
360
+ days: 1
361
+ });
362
+ this.setState({
363
+ calendarSelectedDate: toAlter,
364
+ renderedDate: toAlter.clone(),
365
+ dateInputText: toAlter.format(this.dateFormat)
366
+ });
367
+ };
368
+ handleRenderNextMonth = _event => {
369
+ this.setState({
370
+ renderedDate: this.state.renderedDate.clone().add({
371
+ months: 1
372
+ })
373
+ });
374
+ };
375
+ handleRenderPrevMonth = _event => {
376
+ this.setState({
377
+ renderedDate: this.state.renderedDate.clone().subtract({
378
+ months: 1
379
+ })
380
+ });
381
+ };
382
+
378
383
  renderDays() {
379
384
  if (!this.state.isShowingCalendar) {
380
385
  // this is an expensive function, only execute if the calendar is open
@@ -526,15 +531,6 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
526
531
  }));
527
532
  }
528
533
 
529
- }, _class2.displayName = "DateTimeInput", _class2.DEFAULT_MESSAGE_FORMAT = 'LLLL', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
530
- layout: 'inline',
531
- colSpacing: 'medium',
532
- rowSpacing: 'small',
533
- timeStep: 30,
534
- messageFormat: _class2.DEFAULT_MESSAGE_FORMAT,
535
- isRequired: false,
536
- dateFormat: 'LL' // Localized date with full month, e.g. "August 6, 2014"
537
-
538
- }, _class2.contextType = ApplyLocaleContext, _class2)) || _class);
534
+ }) || _class);
539
535
  export default DateTimeInput;
540
536
  export { DateTimeInput };