@instructure/ui-time-select 8.11.2-snapshot.5 → 8.11.2-snapshot.54

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.
@@ -17,15 +17,7 @@ var _ApplyLocaleContext = require("@instructure/ui-i18n/lib/ApplyLocale/ApplyLoc
17
17
 
18
18
  var _Locale = require("@instructure/ui-i18n/lib/Locale.js");
19
19
 
20
- var _dayjs = _interopRequireDefault(require("dayjs"));
21
-
22
- var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
23
-
24
- var _timezone = _interopRequireDefault(require("dayjs/plugin/timezone"));
25
-
26
- var _localizedFormat = _interopRequireDefault(require("dayjs/plugin/localizedFormat"));
27
-
28
- require("./locales");
20
+ var _DateTime = require("@instructure/ui-i18n/lib/DateTime.js");
29
21
 
30
22
  var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
31
23
 
@@ -45,17 +37,11 @@ const _excluded = ["value", "defaultValue", "placeholder", "renderLabel", "input
45
37
 
46
38
  var _dec, _class, _class2, _temp;
47
39
 
48
- _dayjs.default.extend(_utc.default);
49
-
50
- _dayjs.default.extend(_timezone.default);
51
-
52
- _dayjs.default.extend(_localizedFormat.default);
53
-
54
40
  /**
55
41
  ---
56
42
  category: components
57
43
  ---
58
- **/
44
+ **/
59
45
  let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _class2 = class TimeSelect extends _react.Component {
60
46
  constructor(props) {
61
47
  super(props);
@@ -63,60 +49,65 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
63
49
  this._emptyOptionId = (0, _uid.uid)('Select-EmptyOption');
64
50
 
65
51
  this.handleRef = node => {
66
- this._select = node; // TODO remove this and keep this.ref
67
-
68
52
  this.ref = node;
69
53
  };
70
54
 
71
55
  this.handleBlur = event => {
56
+ var _this$props$onBlur, _this$props;
57
+
72
58
  this.setState({
73
- highlightedOptionId: null
59
+ highlightedOptionId: void 0
74
60
  });
75
- this.props.onBlur(event);
61
+ (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, event);
76
62
  };
77
63
 
78
64
  this.handleInputChange = event => {
79
65
  const value = event.target.value;
80
66
  const newOptions = this.filterOptions(value);
81
- this.setState(state => ({
67
+ this.setState(_state => ({
82
68
  inputValue: value,
83
69
  filteredOptions: newOptions,
84
- highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : null,
70
+ highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : void 0,
85
71
  isShowingOptions: true
86
72
  }));
87
73
 
88
74
  if (!this.state.isShowingOptions) {
89
- this.props.onShowOptions(event);
75
+ var _this$props$onShowOpt, _this$props2;
76
+
77
+ (_this$props$onShowOpt = (_this$props2 = this.props).onShowOptions) === null || _this$props$onShowOpt === void 0 ? void 0 : _this$props$onShowOpt.call(_this$props2, event);
90
78
  }
91
79
  };
92
80
 
93
81
  this.handleShowOptions = event => {
82
+ var _this$props$onShowOpt2, _this$props3;
83
+
94
84
  this.setState({
95
85
  isShowingOptions: true
96
86
  });
97
- this.props.onShowOptions(event);
87
+ (_this$props$onShowOpt2 = (_this$props3 = this.props).onShowOptions) === null || _this$props$onShowOpt2 === void 0 ? void 0 : _this$props$onShowOpt2.call(_this$props3, event);
98
88
  };
99
89
 
100
90
  this.handleHideOptions = event => {
91
+ var _this$props$onHideOpt, _this$props4;
92
+
101
93
  const selectedOptionId = this.state.selectedOptionId;
102
94
  const option = this.getOption('id', selectedOptionId);
103
95
  let prevValue = '';
104
96
 
105
97
  if (this.props.defaultValue) {
106
- const date = (0, _dayjs.default)(this.props.defaultValue).tz(this.timezone(), true).locale(this.locale());
107
- prevValue = date.format(this.props.format);
98
+ const date = _DateTime.DateTime.parse(this.props.defaultValue, this.locale(), this.timezone());
99
+
100
+ prevValue = this.props.format ? date.format(this.props.format) : date.toISOString();
108
101
  }
109
102
 
110
- this.setState(({
111
- inputValue
112
- }) => ({
103
+ this.setState(_state => ({
113
104
  isShowingOptions: false,
114
- highlightedOptionId: null,
105
+ highlightedOptionId: void 0,
115
106
  inputValue: selectedOptionId ? option.label : prevValue,
116
107
  filteredOptions: this.filterOptions(''),
117
108
  ...this.matchValue()
118
109
  }));
119
- this.props.onHideOptions(event);
110
+ (_this$props$onHideOpt = (_this$props4 = this.props).onHideOptions) === null || _this$props$onHideOpt === void 0 ? void 0 : _this$props$onHideOpt.call(_this$props4, event);
120
111
  };
121
112
 
122
113
  this.handleHighlightOption = (event, {
@@ -134,6 +125,8 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
134
125
  this.handleSelectOption = (event, {
135
126
  id
136
127
  }) => {
128
+ var _this$props$onHideOpt2, _this$props6;
129
+
137
130
  if (id === this._emptyOptionId) {
138
131
  this.setState({
139
132
  isShowingOptions: false
@@ -142,37 +135,53 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
142
135
  }
143
136
 
144
137
  const option = this.getOption('id', id);
138
+ let newInputValue;
145
139
 
146
140
  if (this.isControlled) {
147
141
  const prev = this.getOption('id', this.state.selectedOptionId);
142
+ newInputValue = prev ? prev.label : '';
148
143
  this.setState({
149
144
  isShowingOptions: false,
150
- inputValue: prev ? prev.label : '',
145
+ inputValue: newInputValue,
151
146
  filteredOptions: this.filterOptions('')
152
147
  });
153
148
  } else {
149
+ newInputValue = option.label;
154
150
  this.setState({
155
151
  isShowingOptions: false,
156
152
  selectedOptionId: id,
157
- inputValue: option.label,
153
+ inputValue: newInputValue,
158
154
  filteredOptions: this.filterOptions('')
159
155
  });
160
156
  }
161
157
 
162
158
  if (id !== this.state.selectedOptionId) {
163
- this.props.onChange(event, {
164
- value: option.value
159
+ var _this$props$onChange, _this$props5;
160
+
161
+ (_this$props$onChange = (_this$props5 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props5, event, {
162
+ value: option.value,
163
+ inputText: newInputValue
165
164
  });
166
165
  }
167
166
 
168
- this.props.onHideOptions(event);
167
+ (_this$props$onHideOpt2 = (_this$props6 = this.props).onHideOptions) === null || _this$props$onHideOpt2 === void 0 ? void 0 : _this$props$onHideOpt2.call(_this$props6, event);
169
168
  };
170
169
 
171
170
  this.state = this.getInitialState();
172
171
  }
173
172
 
173
+ componentDidMount() {
174
+ // we'll need to recalculate the state because the context value is
175
+ // set at this point (and it might change locale & timezone)
176
+ this.setState(this.getInitialState());
177
+ }
178
+
174
179
  focus() {
175
- this._select && this._select.focus();
180
+ this.ref && this.ref.focus();
181
+ }
182
+
183
+ get _select() {
184
+ return this.ref;
176
185
  }
177
186
 
178
187
  get isControlled() {
@@ -186,11 +195,11 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
186
195
  }
187
196
 
188
197
  get focused() {
189
- return this._select && this._select.focused;
198
+ return this.ref && this.ref.focused;
190
199
  }
191
200
 
192
201
  get id() {
193
- return this._select && this._select.id;
202
+ return this.ref && this.ref.id;
194
203
  }
195
204
 
196
205
  locale() {
@@ -210,7 +219,7 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
210
219
  return this.context.timezone;
211
220
  }
212
221
 
213
- return _dayjs.default.tz.guess();
222
+ return _DateTime.DateTime.browserTimeZone();
214
223
  }
215
224
 
216
225
  componentDidUpdate(prevProps) {
@@ -232,7 +241,7 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
232
241
 
233
242
  this.setState({
234
243
  inputValue: option ? option.label : '',
235
- selectedOptionId: option ? option.id : null
244
+ selectedOptionId: option ? option.id : void 0
236
245
  });
237
246
  }
238
247
  }
@@ -245,17 +254,17 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
245
254
  options: initialOptions,
246
255
  filteredOptions: initialOptions,
247
256
  isShowingOptions: false,
248
- highlightedOptionId: initialSelection ? initialSelection.id : null,
249
- selectedOptionId: initialSelection ? initialSelection.id : null
257
+ highlightedOptionId: initialSelection ? initialSelection.id : void 0,
258
+ selectedOptionId: initialSelection ? initialSelection.id : void 0
250
259
  };
251
260
  }
252
261
 
253
262
  getInitialOption(options) {
254
- const _this$props = this.props,
255
- value = _this$props.value,
256
- defaultValue = _this$props.defaultValue,
257
- defaultToFirstOption = _this$props.defaultToFirstOption,
258
- format = _this$props.format;
263
+ const _this$props7 = this.props,
264
+ value = _this$props7.value,
265
+ defaultValue = _this$props7.defaultValue,
266
+ defaultToFirstOption = _this$props7.defaultToFirstOption,
267
+ format = _this$props7.format;
259
268
  const initialValue = value || defaultValue;
260
269
 
261
270
  if (typeof initialValue === 'string') {
@@ -268,9 +277,10 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
268
277
  } // value does not match an existing option
269
278
 
270
279
 
271
- const date = (0, _dayjs.default)(initialValue).tz(this.timezone(), true).locale(this.locale());
280
+ const date = _DateTime.DateTime.parse(initialValue, this.locale(), this.timezone());
281
+
272
282
  return {
273
- label: date.format(format)
283
+ label: format ? date.format(format) : date.toISOString()
274
284
  };
275
285
  } // otherwise return first option, if desired
276
286
 
@@ -279,7 +289,7 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
279
289
  return options[0];
280
290
  }
281
291
 
282
- return null;
292
+ return void 0;
283
293
  }
284
294
 
285
295
  getOption(field, value, options = this.state.options) {
@@ -290,7 +300,7 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
290
300
  // ISO8601 strings may contain a space. Remove any spaces before using the
291
301
  // date as the id.
292
302
  const dateStr = date.toISOString();
293
- return dateStr ? dateStr.replace(/\s/g, '') : null;
303
+ return dateStr.replace(/\s/g, '');
294
304
  }
295
305
 
296
306
  getBaseDate() {
@@ -298,12 +308,15 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
298
308
  const baseValue = this.props.value || this.props.defaultValue;
299
309
 
300
310
  if (baseValue) {
301
- baseDate = (0, _dayjs.default)(baseValue).tz(this.timezone(), true).locale(this.locale());
311
+ baseDate = _DateTime.DateTime.parse(baseValue, this.locale(), this.timezone());
302
312
  } else {
303
- baseDate = (0, _dayjs.default)().tz(this.timezone(), true).locale(this.locale());
313
+ baseDate = _DateTime.DateTime.now(this.locale(), this.timezone());
304
314
  }
305
315
 
306
- return baseDate.second(0).millisecond(0);
316
+ return baseDate.set({
317
+ second: 0,
318
+ millisecond: 0
319
+ }).clone();
307
320
  }
308
321
 
309
322
  generateOptions() {
@@ -313,15 +326,16 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
313
326
  for (let hour = 0; hour < 24; hour++) {
314
327
  for (let minute = 0; minute < 60 / this.props.step; minute++) {
315
328
  const minutes = minute * this.props.step;
316
- const newDate = date.hour(hour).minute(minutes); // store time options
329
+ const newDate = date.set({
330
+ hour: hour,
331
+ minute: minutes
332
+ }); // store time options
317
333
 
318
334
  options.push({
319
335
  id: this.getFormattedId(newDate),
320
336
  // iso no spaces
321
337
  value: newDate.toISOString(),
322
- // iso
323
- label: newDate.format(this.props.format) // formatted string
324
-
338
+ label: this.props.format ? newDate.format(this.props.format) : newDate.toISOString()
325
339
  });
326
340
  }
327
341
  }
@@ -330,15 +344,17 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
330
344
  }
331
345
 
332
346
  filterOptions(inputValue) {
333
- return this.state.options.filter(option => option.label.toLowerCase().startsWith(inputValue.toLowerCase()));
347
+ var _this$state;
348
+
349
+ return (_this$state = this.state) === null || _this$state === void 0 ? void 0 : _this$state.options.filter(option => option.label.toLowerCase().startsWith(inputValue.toLowerCase()));
334
350
  }
335
351
 
336
352
  matchValue() {
337
- const _this$state = this.state,
338
- inputValue = _this$state.inputValue,
339
- filteredOptions = _this$state.filteredOptions,
340
- highlightedOptionId = _this$state.highlightedOptionId,
341
- selectedOptionId = _this$state.selectedOptionId; // an option matching user input exists
353
+ const _this$state2 = this.state,
354
+ inputValue = _this$state2.inputValue,
355
+ filteredOptions = _this$state2.filteredOptions,
356
+ highlightedOptionId = _this$state2.highlightedOptionId,
357
+ selectedOptionId = _this$state2.selectedOptionId; // an option matching user input exists
342
358
 
343
359
  if (filteredOptions.length === 1) {
344
360
  const onlyOption = filteredOptions[0]; // automatically select the matching option
@@ -378,13 +394,15 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
378
394
  inputValue: ''
379
395
  };
380
396
  }
397
+
398
+ return void 0;
381
399
  }
382
400
 
383
401
  renderOptions() {
384
- const _this$state2 = this.state,
385
- filteredOptions = _this$state2.filteredOptions,
386
- highlightedOptionId = _this$state2.highlightedOptionId,
387
- selectedOptionId = _this$state2.selectedOptionId;
402
+ const _this$state3 = this.state,
403
+ filteredOptions = _this$state3.filteredOptions,
404
+ highlightedOptionId = _this$state3.highlightedOptionId,
405
+ selectedOptionId = _this$state3.selectedOptionId;
388
406
 
389
407
  if (filteredOptions.length < 1) {
390
408
  return this.renderEmptyOption();
@@ -411,33 +429,33 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
411
429
  }
412
430
 
413
431
  render() {
414
- const _this$props2 = this.props,
415
- value = _this$props2.value,
416
- defaultValue = _this$props2.defaultValue,
417
- placeholder = _this$props2.placeholder,
418
- renderLabel = _this$props2.renderLabel,
419
- inputRef = _this$props2.inputRef,
420
- id = _this$props2.id,
421
- listRef = _this$props2.listRef,
422
- renderBeforeInput = _this$props2.renderBeforeInput,
423
- renderAfterInput = _this$props2.renderAfterInput,
424
- isRequired = _this$props2.isRequired,
425
- isInline = _this$props2.isInline,
426
- width = _this$props2.width,
427
- format = _this$props2.format,
428
- step = _this$props2.step,
429
- optionsMaxWidth = _this$props2.optionsMaxWidth,
430
- visibleOptionsCount = _this$props2.visibleOptionsCount,
431
- messages = _this$props2.messages,
432
- placement = _this$props2.placement,
433
- constrain = _this$props2.constrain,
434
- onFocus = _this$props2.onFocus,
435
- onShowOptions = _this$props2.onShowOptions,
436
- onHideOptions = _this$props2.onHideOptions,
437
- rest = (0, _objectWithoutProperties2.default)(_this$props2, _excluded);
438
- const _this$state3 = this.state,
439
- inputValue = _this$state3.inputValue,
440
- isShowingOptions = _this$state3.isShowingOptions;
432
+ const _this$props8 = this.props,
433
+ value = _this$props8.value,
434
+ defaultValue = _this$props8.defaultValue,
435
+ placeholder = _this$props8.placeholder,
436
+ renderLabel = _this$props8.renderLabel,
437
+ inputRef = _this$props8.inputRef,
438
+ id = _this$props8.id,
439
+ listRef = _this$props8.listRef,
440
+ renderBeforeInput = _this$props8.renderBeforeInput,
441
+ renderAfterInput = _this$props8.renderAfterInput,
442
+ isRequired = _this$props8.isRequired,
443
+ isInline = _this$props8.isInline,
444
+ width = _this$props8.width,
445
+ format = _this$props8.format,
446
+ step = _this$props8.step,
447
+ optionsMaxWidth = _this$props8.optionsMaxWidth,
448
+ visibleOptionsCount = _this$props8.visibleOptionsCount,
449
+ messages = _this$props8.messages,
450
+ placement = _this$props8.placement,
451
+ constrain = _this$props8.constrain,
452
+ onFocus = _this$props8.onFocus,
453
+ onShowOptions = _this$props8.onShowOptions,
454
+ onHideOptions = _this$props8.onHideOptions,
455
+ rest = (0, _objectWithoutProperties2.default)(_this$props8, _excluded);
456
+ const _this$state4 = this.state,
457
+ inputValue = _this$state4.inputValue,
458
+ isShowingOptions = _this$state4.isShowingOptions;
441
459
  return /*#__PURE__*/_react.default.createElement(_Select.Select, Object.assign({
442
460
  renderLabel: renderLabel,
443
461
  inputValue: inputValue,
@@ -470,7 +488,9 @@ let TimeSelect = (_dec = (0, _testable.testable)(), _dec(_class = (_temp = _clas
470
488
 
471
489
  }, _class2.displayName = "TimeSelect", _class2.componentId = 'TimeSelect', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
472
490
  defaultToFirstOption: false,
491
+ id: void 0,
473
492
  format: 'LT',
493
+ // see https://momentjs.com/docs/#/displaying/
474
494
  step: 30,
475
495
  isRequired: false,
476
496
  isInline: false,
@@ -70,7 +70,8 @@ const propTypes = {
70
70
  /**
71
71
  * The format to use when displaying the possible and currently selected options.
72
72
  *
73
- * See [moment.js formats](https://momentjs.com/docs/#/displaying/format/) for the list of available formats.
73
+ * See [moment](https://momentjs.com/docs/#/displaying/format/) for the list
74
+ * of available formats.
74
75
  */
75
76
  format: _propTypes.default.string,
76
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-time-select",
3
- "version": "8.11.2-snapshot.5+fd40a2f7b",
3
+ "version": "8.11.2-snapshot.54+a6aaef205",
4
4
  "description": "A component for selecting time values.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -25,22 +25,21 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.13.10",
28
- "@instructure/console": "8.11.2-snapshot.5+fd40a2f7b",
29
- "@instructure/ui-form-field": "8.11.2-snapshot.5+fd40a2f7b",
30
- "@instructure/ui-i18n": "8.11.2-snapshot.5+fd40a2f7b",
31
- "@instructure/ui-position": "8.11.2-snapshot.5+fd40a2f7b",
32
- "@instructure/ui-prop-types": "8.11.2-snapshot.5+fd40a2f7b",
33
- "@instructure/ui-react-utils": "8.11.2-snapshot.5+fd40a2f7b",
34
- "@instructure/ui-select": "8.11.2-snapshot.5+fd40a2f7b",
35
- "@instructure/ui-test-locator": "8.11.2-snapshot.5+fd40a2f7b",
36
- "@instructure/ui-testable": "8.11.2-snapshot.5+fd40a2f7b",
37
- "@instructure/uid": "8.11.2-snapshot.5+fd40a2f7b",
38
- "dayjs": "^1.10.6",
28
+ "@instructure/console": "8.11.2-snapshot.54+a6aaef205",
29
+ "@instructure/ui-form-field": "8.11.2-snapshot.54+a6aaef205",
30
+ "@instructure/ui-i18n": "8.11.2-snapshot.54+a6aaef205",
31
+ "@instructure/ui-position": "8.11.2-snapshot.54+a6aaef205",
32
+ "@instructure/ui-prop-types": "8.11.2-snapshot.54+a6aaef205",
33
+ "@instructure/ui-react-utils": "8.11.2-snapshot.54+a6aaef205",
34
+ "@instructure/ui-select": "8.11.2-snapshot.54+a6aaef205",
35
+ "@instructure/ui-test-locator": "8.11.2-snapshot.54+a6aaef205",
36
+ "@instructure/ui-testable": "8.11.2-snapshot.54+a6aaef205",
37
+ "@instructure/uid": "8.11.2-snapshot.54+a6aaef205",
39
38
  "prop-types": "^15"
40
39
  },
41
40
  "devDependencies": {
42
- "@instructure/ui-babel-preset": "8.11.2-snapshot.5+fd40a2f7b",
43
- "@instructure/ui-test-utils": "8.11.2-snapshot.5+fd40a2f7b",
41
+ "@instructure/ui-babel-preset": "8.11.2-snapshot.54+a6aaef205",
42
+ "@instructure/ui-test-utils": "8.11.2-snapshot.54+a6aaef205",
44
43
  "moment-timezone": "^0.5.33"
45
44
  },
46
45
  "peerDependencies": {
@@ -50,5 +49,5 @@
50
49
  "access": "public"
51
50
  },
52
51
  "sideEffects": false,
53
- "gitHead": "fd40a2f7b84bb29103569d826f4babdd5af84733"
52
+ "gitHead": "a6aaef20508325ae9e5bfbbb29317174edebce9c"
54
53
  }