@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.
@@ -37,7 +37,7 @@ var _debounce = require("@instructure/debounce");
37
37
 
38
38
  var _props = require("./props");
39
39
 
40
- var _dec, _class, _class2, _IconArrowOpenStartSo, _IconArrowOpenEndSoli;
40
+ var _dec, _class, _IconArrowOpenStartSo, _IconArrowOpenEndSoli;
41
41
 
42
42
  /**
43
43
  ---
@@ -45,171 +45,33 @@ category: components
45
45
  ---
46
46
  @tsProps
47
47
  **/
48
- let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = (_class2 = class DateTimeInput extends _react.Component {
48
+ let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = class DateTimeInput extends _react.Component {
49
+ static displayName = "DateTimeInput";
49
50
  // extra verbose localized date and time
50
- // This is used by Tooltip for positioning
51
+ static DEFAULT_MESSAGE_FORMAT = 'LLLL';
52
+ static propTypes = _props.propTypes;
53
+ static allowedProps = _props.allowedProps;
54
+ static defaultProps = {
55
+ layout: 'inline',
56
+ colSpacing: 'medium',
57
+ rowSpacing: 'small',
58
+ timeStep: 30,
59
+ messageFormat: DateTimeInput.DEFAULT_MESSAGE_FORMAT,
60
+ isRequired: false,
61
+ dateFormat: 'LL' // Localized date with full month, e.g. "August 6, 2014"
62
+
63
+ };
64
+ static contextType = _ApplyLocaleContext.ApplyLocaleContext;
65
+ ref = null; // This is used by Tooltip for positioning
66
+
67
+ handleRef = el => {
68
+ this.ref = el;
69
+ };
70
+
51
71
  constructor(props) {
52
72
  super(props); // State needs to be calculated because render could be called before
53
73
  // componentDidMount()
54
74
 
55
- this.context = void 0;
56
- this.ref = null;
57
-
58
- this.handleRef = el => {
59
- this.ref = el;
60
- };
61
-
62
- this.handleDateTextChange = (_event, date) => {
63
- const dateParsed = this.tryParseDate(date.value);
64
- this.setState({
65
- dateInputText: date.value,
66
- dateInputTextChanged: true,
67
- calendarSelectedDate: dateParsed ? dateParsed : void 0,
68
- renderedDate: dateParsed ? dateParsed.clone() : _DateTime.DateTime.now(this.locale(), this.timezone())
69
- });
70
- };
71
-
72
- this.handleDayClick = (event, _ref) => {
73
- let date = _ref.date;
74
-
75
- const dateParsed = _DateTime.DateTime.parse(date, this.locale(), this.timezone());
76
-
77
- this.updateStateBasedOnDateInput(dateParsed, event);
78
- };
79
-
80
- this.handleHideCalendar = event => {
81
- // update state based on the DateInput's text value
82
- if (this.state.dateInputTextChanged || event.key === 'Enter') {
83
- const dateParsed = this.tryParseDate(this.state.dateInputText);
84
- this.updateStateBasedOnDateInput(dateParsed, event);
85
- } else {
86
- // user clicked outside or tabbed away or pressed esc, reset text
87
- this.setState({
88
- dateInputText: this.state.iso ? this.state.iso.format(this.dateFormat) : '',
89
- calendarSelectedDate: this.state.iso ? this.state.iso.clone() : void 0
90
- });
91
- }
92
-
93
- this.setState({
94
- isShowingCalendar: false,
95
- dateInputTextChanged: false
96
- });
97
- };
98
-
99
- this.handleTimeChange = (event, option) => {
100
- let newValue;
101
-
102
- if (this.state.iso) {
103
- newValue = option.value;
104
- } else {
105
- // if no date is set just return the input text, it will error
106
- newValue = option.inputText;
107
- }
108
-
109
- const newState = this.recalculateState(newValue, true, false);
110
- this.changeStateIfNeeded(newState, event);
111
- this.setState({
112
- timeSelectValue: option.value
113
- });
114
- };
115
-
116
- this.changeStateIfNeeded = (newState, e) => {
117
- this.setState({
118
- message: newState.message
119
- });
120
-
121
- if (!newState.iso && !this.state.iso) {
122
- return;
123
- }
124
-
125
- if (!this.state.iso || !newState.iso || !this.state.iso.isSame(newState.iso)) {
126
- this.setState(newState);
127
-
128
- if (this.props.onChange) {
129
- var _newState$iso;
130
-
131
- this.props.onChange(e, (_newState$iso = newState.iso) === null || _newState$iso === void 0 ? void 0 : _newState$iso.toISOString());
132
- }
133
- }
134
- };
135
-
136
- this.handleBlur = e => {
137
- // when TABbing from the DateInput to TimeInput or visa-versa, the blur
138
- // happens on the target before the relatedTarget gets focus.
139
- // The timeout gives it a moment for that to happen
140
- if (typeof this.props.onBlur === 'function') {
141
- window.setTimeout(() => {
142
- var _this$props$onBlur, _this$props;
143
-
144
- (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, e);
145
- }, 0);
146
- }
147
- };
148
-
149
- this.handleShowCalendar = _event => {
150
- this.setState({
151
- isShowingCalendar: true
152
- });
153
- };
154
-
155
- this.handleSelectNextDay = _event => {
156
- let toAlter;
157
-
158
- if (this.state.calendarSelectedDate) {
159
- toAlter = this.state.calendarSelectedDate.clone();
160
- } else if (this.state.iso) {
161
- toAlter = this.state.iso.clone();
162
- } else {
163
- toAlter = _DateTime.DateTime.now(this.locale(), this.timezone());
164
- }
165
-
166
- toAlter.add({
167
- days: 1
168
- });
169
- this.setState({
170
- calendarSelectedDate: toAlter,
171
- renderedDate: toAlter.clone(),
172
- dateInputText: toAlter.format(this.dateFormat)
173
- });
174
- };
175
-
176
- this.handleSelectPrevDay = _event => {
177
- let toAlter;
178
-
179
- if (this.state.calendarSelectedDate) {
180
- toAlter = this.state.calendarSelectedDate.clone();
181
- } else if (this.state.iso) {
182
- toAlter = this.state.iso.clone();
183
- } else {
184
- toAlter = _DateTime.DateTime.now(this.locale(), this.timezone());
185
- }
186
-
187
- toAlter.subtract({
188
- days: 1
189
- });
190
- this.setState({
191
- calendarSelectedDate: toAlter,
192
- renderedDate: toAlter.clone(),
193
- dateInputText: toAlter.format(this.dateFormat)
194
- });
195
- };
196
-
197
- this.handleRenderNextMonth = _event => {
198
- this.setState({
199
- renderedDate: this.state.renderedDate.clone().add({
200
- months: 1
201
- })
202
- });
203
- };
204
-
205
- this.handleRenderPrevMonth = _event => {
206
- this.setState({
207
- renderedDate: this.state.renderedDate.clone().subtract({
208
- months: 1
209
- })
210
- });
211
- };
212
-
213
75
  this.state = this.recalculateState(props.value || props.defaultValue);
214
76
  }
215
77
 
@@ -354,6 +216,16 @@ let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = (_class2 =
354
216
  } // Called when the user enters text into dateInput
355
217
 
356
218
 
219
+ handleDateTextChange = (_event, date) => {
220
+ const dateParsed = this.tryParseDate(date.value);
221
+ this.setState({
222
+ dateInputText: date.value,
223
+ dateInputTextChanged: true,
224
+ calendarSelectedDate: dateParsed ? dateParsed : void 0,
225
+ renderedDate: dateParsed ? dateParsed.clone() : _DateTime.DateTime.now(this.locale(), this.timezone())
226
+ });
227
+ };
228
+
357
229
  tryParseDate(val) {
358
230
  const parsed = _DateTime.DateTime.parse(val, this.locale(), this.timezone());
359
231
 
@@ -361,6 +233,32 @@ let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = (_class2 =
361
233
  } // date is returned es a ISO string, like 2021-09-14T22:00:00.000Z
362
234
 
363
235
 
236
+ handleDayClick = (event, _ref) => {
237
+ let date = _ref.date;
238
+
239
+ const dateParsed = _DateTime.DateTime.parse(date, this.locale(), this.timezone());
240
+
241
+ this.updateStateBasedOnDateInput(dateParsed, event);
242
+ };
243
+ handleHideCalendar = event => {
244
+ // update state based on the DateInput's text value
245
+ if (this.state.dateInputTextChanged || event.key === 'Enter') {
246
+ const dateParsed = this.tryParseDate(this.state.dateInputText);
247
+ this.updateStateBasedOnDateInput(dateParsed, event);
248
+ } else {
249
+ // user clicked outside or tabbed away or pressed esc, reset text
250
+ this.setState({
251
+ dateInputText: this.state.iso ? this.state.iso.format(this.dateFormat) : '',
252
+ calendarSelectedDate: this.state.iso ? this.state.iso.clone() : void 0
253
+ });
254
+ }
255
+
256
+ this.setState({
257
+ isShowingCalendar: false,
258
+ dateInputTextChanged: false
259
+ });
260
+ };
261
+
364
262
  updateStateBasedOnDateInput(dateParsed, event) {
365
263
  let newState;
366
264
 
@@ -383,6 +281,113 @@ let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = (_class2 =
383
281
  this.changeStateIfNeeded(newState, event);
384
282
  }
385
283
 
284
+ handleTimeChange = (event, option) => {
285
+ let newValue;
286
+
287
+ if (this.state.iso) {
288
+ newValue = option.value;
289
+ } else {
290
+ // if no date is set just return the input text, it will error
291
+ newValue = option.inputText;
292
+ }
293
+
294
+ const newState = this.recalculateState(newValue, true, false);
295
+ this.changeStateIfNeeded(newState, event);
296
+ this.setState({
297
+ timeSelectValue: option.value
298
+ });
299
+ };
300
+ changeStateIfNeeded = (newState, e) => {
301
+ this.setState({
302
+ message: newState.message
303
+ });
304
+
305
+ if (!newState.iso && !this.state.iso) {
306
+ return;
307
+ }
308
+
309
+ if (!this.state.iso || !newState.iso || !this.state.iso.isSame(newState.iso)) {
310
+ this.setState(newState);
311
+
312
+ if (this.props.onChange) {
313
+ var _newState$iso;
314
+
315
+ this.props.onChange(e, (_newState$iso = newState.iso) === null || _newState$iso === void 0 ? void 0 : _newState$iso.toISOString());
316
+ }
317
+ }
318
+ };
319
+ handleBlur = e => {
320
+ // when TABbing from the DateInput to TimeInput or visa-versa, the blur
321
+ // happens on the target before the relatedTarget gets focus.
322
+ // The timeout gives it a moment for that to happen
323
+ if (typeof this.props.onBlur === 'function') {
324
+ window.setTimeout(() => {
325
+ var _this$props$onBlur, _this$props;
326
+
327
+ (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, e);
328
+ }, 0);
329
+ }
330
+ };
331
+ handleShowCalendar = _event => {
332
+ this.setState({
333
+ isShowingCalendar: true
334
+ });
335
+ };
336
+ handleSelectNextDay = _event => {
337
+ let toAlter;
338
+
339
+ if (this.state.calendarSelectedDate) {
340
+ toAlter = this.state.calendarSelectedDate.clone();
341
+ } else if (this.state.iso) {
342
+ toAlter = this.state.iso.clone();
343
+ } else {
344
+ toAlter = _DateTime.DateTime.now(this.locale(), this.timezone());
345
+ }
346
+
347
+ toAlter.add({
348
+ days: 1
349
+ });
350
+ this.setState({
351
+ calendarSelectedDate: toAlter,
352
+ renderedDate: toAlter.clone(),
353
+ dateInputText: toAlter.format(this.dateFormat)
354
+ });
355
+ };
356
+ handleSelectPrevDay = _event => {
357
+ let toAlter;
358
+
359
+ if (this.state.calendarSelectedDate) {
360
+ toAlter = this.state.calendarSelectedDate.clone();
361
+ } else if (this.state.iso) {
362
+ toAlter = this.state.iso.clone();
363
+ } else {
364
+ toAlter = _DateTime.DateTime.now(this.locale(), this.timezone());
365
+ }
366
+
367
+ toAlter.subtract({
368
+ days: 1
369
+ });
370
+ this.setState({
371
+ calendarSelectedDate: toAlter,
372
+ renderedDate: toAlter.clone(),
373
+ dateInputText: toAlter.format(this.dateFormat)
374
+ });
375
+ };
376
+ handleRenderNextMonth = _event => {
377
+ this.setState({
378
+ renderedDate: this.state.renderedDate.clone().add({
379
+ months: 1
380
+ })
381
+ });
382
+ };
383
+ handleRenderPrevMonth = _event => {
384
+ this.setState({
385
+ renderedDate: this.state.renderedDate.clone().subtract({
386
+ months: 1
387
+ })
388
+ });
389
+ };
390
+
386
391
  renderDays() {
387
392
  if (!this.state.isShowingCalendar) {
388
393
  // this is an expensive function, only execute if the calendar is open
@@ -537,16 +542,7 @@ let DateTimeInput = (_dec = (0, _testable.testable)(), _dec(_class = (_class2 =
537
542
  }));
538
543
  }
539
544
 
540
- }, _class2.displayName = "DateTimeInput", _class2.DEFAULT_MESSAGE_FORMAT = 'LLLL', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
541
- layout: 'inline',
542
- colSpacing: 'medium',
543
- rowSpacing: 'small',
544
- timeStep: 30,
545
- messageFormat: _class2.DEFAULT_MESSAGE_FORMAT,
546
- isRequired: false,
547
- dateFormat: 'LL' // Localized date with full month, e.g. "August 6, 2014"
548
-
549
- }, _class2.contextType = _ApplyLocaleContext.ApplyLocaleContext, _class2)) || _class);
545
+ }) || _class);
550
546
  exports.DateTimeInput = DateTimeInput;
551
547
  var _default = DateTimeInput;
552
548
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-date-time-input",
3
- "version": "8.25.1-snapshot-7",
3
+ "version": "8.25.1-snapshot-10",
4
4
  "description": "A UI component that allows to select date and time.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,26 +23,26 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.25.1-snapshot-7",
27
- "@instructure/ui-test-locator": "8.25.1-snapshot-7",
28
- "@instructure/ui-test-utils": "8.25.1-snapshot-7"
26
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-10",
27
+ "@instructure/ui-test-locator": "8.25.1-snapshot-10",
28
+ "@instructure/ui-test-utils": "8.25.1-snapshot-10"
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.13.10",
32
- "@instructure/debounce": "8.25.1-snapshot-7",
33
- "@instructure/emotion": "8.25.1-snapshot-7",
34
- "@instructure/ui-a11y-content": "8.25.1-snapshot-7",
35
- "@instructure/ui-buttons": "8.25.1-snapshot-7",
36
- "@instructure/ui-calendar": "8.25.1-snapshot-7",
37
- "@instructure/ui-date-input": "8.25.1-snapshot-7",
38
- "@instructure/ui-form-field": "8.25.1-snapshot-7",
39
- "@instructure/ui-i18n": "8.25.1-snapshot-7",
40
- "@instructure/ui-icons": "8.25.1-snapshot-7",
41
- "@instructure/ui-prop-types": "8.25.1-snapshot-7",
42
- "@instructure/ui-react-utils": "8.25.1-snapshot-7",
43
- "@instructure/ui-testable": "8.25.1-snapshot-7",
44
- "@instructure/ui-time-select": "8.25.1-snapshot-7",
45
- "@instructure/ui-utils": "8.25.1-snapshot-7",
32
+ "@instructure/debounce": "8.25.1-snapshot-10",
33
+ "@instructure/emotion": "8.25.1-snapshot-10",
34
+ "@instructure/ui-a11y-content": "8.25.1-snapshot-10",
35
+ "@instructure/ui-buttons": "8.25.1-snapshot-10",
36
+ "@instructure/ui-calendar": "8.25.1-snapshot-10",
37
+ "@instructure/ui-date-input": "8.25.1-snapshot-10",
38
+ "@instructure/ui-form-field": "8.25.1-snapshot-10",
39
+ "@instructure/ui-i18n": "8.25.1-snapshot-10",
40
+ "@instructure/ui-icons": "8.25.1-snapshot-10",
41
+ "@instructure/ui-prop-types": "8.25.1-snapshot-10",
42
+ "@instructure/ui-react-utils": "8.25.1-snapshot-10",
43
+ "@instructure/ui-testable": "8.25.1-snapshot-10",
44
+ "@instructure/ui-time-select": "8.25.1-snapshot-10",
45
+ "@instructure/ui-utils": "8.25.1-snapshot-10",
46
46
  "prop-types": "^15"
47
47
  },
48
48
  "peerDependencies": {
@@ -64,8 +64,7 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
64
64
  dateFormat: 'LL' // Localized date with full month, e.g. "August 6, 2014"
65
65
  } as const
66
66
 
67
- context!: React.ContextType<typeof ApplyLocaleContext>
68
-
67
+ declare context: React.ContextType<typeof ApplyLocaleContext>
69
68
  static contextType = ApplyLocaleContext
70
69
 
71
70
  ref: Element | null = null // This is used by Tooltip for positioning
@@ -69,22 +69,7 @@ type DateTimeInputProps = {
69
69
  /**
70
70
  * The label over the time input
71
71
  **/
72
- timeRenderLabel:
73
- | React.ReactNode
74
- | (({
75
- id,
76
- isDisabled,
77
- isSelected,
78
- isHighlighted,
79
- children
80
- }: // TODO type this better when Select is typed
81
- {
82
- id: any
83
- isDisabled: any
84
- isSelected: any
85
- isHighlighted: any
86
- children: any
87
- }) => React.ReactNode)
72
+ timeRenderLabel: React.ReactNode | (() => React.ReactNode)
88
73
  /**
89
74
  * The number of minutes to increment by when generating the allowable time options.
90
75
  */