@instructure/ui-time-select 8.25.1-snapshot-10 → 8.25.1-snapshot-13
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 +1 -1
- package/es/TimeSelect/index.js +148 -149
- package/lib/TimeSelect/index.js +149 -150
- package/package.json +12 -12
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-
|
|
6
|
+
## [8.25.1-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-13) (2022-06-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-time-select
|
|
9
9
|
|
package/es/TimeSelect/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["value", "defaultValue", "placeholder", "renderLabel", "inputRef", "id", "listRef", "renderBeforeInput", "renderAfterInput", "isRequired", "isInline", "width", "format", "step", "optionsMaxWidth", "visibleOptionsCount", "messages", "placement", "constrain", "onFocus", "onShowOptions", "onHideOptions"];
|
|
3
3
|
|
|
4
|
-
var _dec, _dec2, _class;
|
|
4
|
+
var _dec, _dec2, _class, _class2;
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* The MIT License (MIT)
|
|
@@ -41,29 +41,138 @@ category: components
|
|
|
41
41
|
|
|
42
42
|
A component used to select a time value.
|
|
43
43
|
**/
|
|
44
|
-
let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = class TimeSelect extends Component {
|
|
45
|
-
static displayName = "TimeSelect";
|
|
46
|
-
static componentId = 'TimeSelect';
|
|
47
|
-
static allowedProps = allowedProps;
|
|
48
|
-
static propTypes = propTypes;
|
|
49
|
-
static defaultProps = {
|
|
50
|
-
defaultToFirstOption: false,
|
|
51
|
-
format: 'LT',
|
|
52
|
-
// see https://momentjs.com/docs/#/displaying/
|
|
53
|
-
step: 30,
|
|
54
|
-
isRequired: false,
|
|
55
|
-
isInline: false,
|
|
56
|
-
visibleOptionsCount: 8,
|
|
57
|
-
placement: 'bottom stretch',
|
|
58
|
-
constrain: 'window',
|
|
59
|
-
renderEmptyOption: '---'
|
|
60
|
-
};
|
|
61
|
-
static contextType = ApplyLocaleContext;
|
|
62
|
-
ref = null;
|
|
63
|
-
_emptyOptionId = this.props.deterministicId('Select-EmptyOption');
|
|
64
|
-
|
|
44
|
+
let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class TimeSelect extends Component {
|
|
65
45
|
constructor(props) {
|
|
46
|
+
var _this;
|
|
47
|
+
|
|
66
48
|
super(props);
|
|
49
|
+
_this = this;
|
|
50
|
+
this.ref = null;
|
|
51
|
+
this._emptyOptionId = this.props.deterministicId('Select-EmptyOption');
|
|
52
|
+
|
|
53
|
+
this.getOption = function (field, value) {
|
|
54
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : _this.state.options;
|
|
55
|
+
return options.find(option => option[field] === value);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
this.handleRef = node => {
|
|
59
|
+
this.ref = node;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
this.handleBlur = event => {
|
|
63
|
+
var _this$props$onBlur, _this$props;
|
|
64
|
+
|
|
65
|
+
this.setState({
|
|
66
|
+
highlightedOptionId: void 0
|
|
67
|
+
});
|
|
68
|
+
(_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, event);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
this.handleInputChange = event => {
|
|
72
|
+
const value = event.target.value;
|
|
73
|
+
const newOptions = this.filterOptions(value);
|
|
74
|
+
this.setState({
|
|
75
|
+
inputValue: value,
|
|
76
|
+
filteredOptions: newOptions,
|
|
77
|
+
highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : void 0,
|
|
78
|
+
isShowingOptions: true
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!this.state.isShowingOptions) {
|
|
82
|
+
var _this$props$onShowOpt, _this$props2;
|
|
83
|
+
|
|
84
|
+
(_this$props$onShowOpt = (_this$props2 = this.props).onShowOptions) === null || _this$props$onShowOpt === void 0 ? void 0 : _this$props$onShowOpt.call(_this$props2, event);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
this.handleShowOptions = event => {
|
|
89
|
+
var _this$props$onShowOpt2, _this$props3;
|
|
90
|
+
|
|
91
|
+
this.setState({
|
|
92
|
+
isShowingOptions: true,
|
|
93
|
+
highlightedOptionId: this.state.selectedOptionId
|
|
94
|
+
});
|
|
95
|
+
(_this$props$onShowOpt2 = (_this$props3 = this.props).onShowOptions) === null || _this$props$onShowOpt2 === void 0 ? void 0 : _this$props$onShowOpt2.call(_this$props3, event);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
this.handleHideOptions = event => {
|
|
99
|
+
var _this$props$onHideOpt, _this$props4;
|
|
100
|
+
|
|
101
|
+
const selectedOptionId = this.state.selectedOptionId;
|
|
102
|
+
const option = this.getOption('id', selectedOptionId);
|
|
103
|
+
let prevValue = '';
|
|
104
|
+
|
|
105
|
+
if (this.props.defaultValue) {
|
|
106
|
+
const date = DateTime.parse(this.props.defaultValue, this.locale(), this.timezone());
|
|
107
|
+
prevValue = this.props.format ? date.format(this.props.format) : date.toISOString();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.setState(() => ({
|
|
111
|
+
isShowingOptions: false,
|
|
112
|
+
highlightedOptionId: void 0,
|
|
113
|
+
inputValue: selectedOptionId ? option.label : prevValue,
|
|
114
|
+
filteredOptions: this.filterOptions(''),
|
|
115
|
+
...this.matchValue()
|
|
116
|
+
}));
|
|
117
|
+
(_this$props$onHideOpt = (_this$props4 = this.props).onHideOptions) === null || _this$props$onHideOpt === void 0 ? void 0 : _this$props$onHideOpt.call(_this$props4, event);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.handleHighlightOption = (event, _ref) => {
|
|
121
|
+
let id = _ref.id;
|
|
122
|
+
if (id === this._emptyOptionId) return;
|
|
123
|
+
const type = event.type;
|
|
124
|
+
const option = this.getOption('id', id).label;
|
|
125
|
+
this.setState(state => ({
|
|
126
|
+
highlightedOptionId: id,
|
|
127
|
+
inputValue: type === 'keydown' ? option : state.inputValue
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
this.handleSelectOption = (event, _ref2) => {
|
|
132
|
+
var _this$props$onHideOpt2, _this$props6;
|
|
133
|
+
|
|
134
|
+
let id = _ref2.id;
|
|
135
|
+
|
|
136
|
+
if (id === this._emptyOptionId) {
|
|
137
|
+
this.setState({
|
|
138
|
+
isShowingOptions: false
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const option = this.getOption('id', id);
|
|
144
|
+
let newInputValue;
|
|
145
|
+
|
|
146
|
+
if (this.isControlled) {
|
|
147
|
+
const prev = this.getOption('id', this.state.selectedOptionId);
|
|
148
|
+
newInputValue = prev ? prev.label : '';
|
|
149
|
+
this.setState({
|
|
150
|
+
isShowingOptions: false,
|
|
151
|
+
inputValue: newInputValue,
|
|
152
|
+
filteredOptions: this.filterOptions('')
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
newInputValue = option.label;
|
|
156
|
+
this.setState({
|
|
157
|
+
isShowingOptions: false,
|
|
158
|
+
selectedOptionId: id,
|
|
159
|
+
inputValue: newInputValue,
|
|
160
|
+
filteredOptions: this.filterOptions('')
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (id !== this.state.selectedOptionId) {
|
|
165
|
+
var _this$props$onChange, _this$props5;
|
|
166
|
+
|
|
167
|
+
(_this$props$onChange = (_this$props5 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props5, event, {
|
|
168
|
+
value: option.value,
|
|
169
|
+
inputText: newInputValue
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
(_this$props$onHideOpt2 = (_this$props6 = this.props).onHideOptions) === null || _this$props$onHideOpt2 === void 0 ? void 0 : _this$props$onHideOpt2.call(_this$props6, event);
|
|
174
|
+
};
|
|
175
|
+
|
|
67
176
|
this.state = this.getInitialState();
|
|
68
177
|
}
|
|
69
178
|
|
|
@@ -177,11 +286,11 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
177
286
|
}
|
|
178
287
|
|
|
179
288
|
getInitialOption(options) {
|
|
180
|
-
const _this$
|
|
181
|
-
value = _this$
|
|
182
|
-
defaultValue = _this$
|
|
183
|
-
defaultToFirstOption = _this$
|
|
184
|
-
format = _this$
|
|
289
|
+
const _this$props7 = this.props,
|
|
290
|
+
value = _this$props7.value,
|
|
291
|
+
defaultValue = _this$props7.defaultValue,
|
|
292
|
+
defaultToFirstOption = _this$props7.defaultToFirstOption,
|
|
293
|
+
format = _this$props7.format;
|
|
185
294
|
const initialValue = value || defaultValue;
|
|
186
295
|
|
|
187
296
|
if (typeof initialValue === 'string') {
|
|
@@ -208,15 +317,6 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
208
317
|
return void 0;
|
|
209
318
|
}
|
|
210
319
|
|
|
211
|
-
getOption = (() => {
|
|
212
|
-
var _this = this;
|
|
213
|
-
|
|
214
|
-
return function (field, value) {
|
|
215
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : _this.state.options;
|
|
216
|
-
return options.find(option => option[field] === value);
|
|
217
|
-
};
|
|
218
|
-
})();
|
|
219
|
-
|
|
220
320
|
getFormattedId(date) {
|
|
221
321
|
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
222
322
|
// date as the id.
|
|
@@ -318,118 +418,6 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
318
418
|
return void 0;
|
|
319
419
|
}
|
|
320
420
|
|
|
321
|
-
handleRef = node => {
|
|
322
|
-
this.ref = node;
|
|
323
|
-
};
|
|
324
|
-
handleBlur = event => {
|
|
325
|
-
var _this$props$onBlur, _this$props2;
|
|
326
|
-
|
|
327
|
-
this.setState({
|
|
328
|
-
highlightedOptionId: void 0
|
|
329
|
-
});
|
|
330
|
-
(_this$props$onBlur = (_this$props2 = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props2, event);
|
|
331
|
-
};
|
|
332
|
-
handleInputChange = event => {
|
|
333
|
-
const value = event.target.value;
|
|
334
|
-
const newOptions = this.filterOptions(value);
|
|
335
|
-
this.setState({
|
|
336
|
-
inputValue: value,
|
|
337
|
-
filteredOptions: newOptions,
|
|
338
|
-
highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : void 0,
|
|
339
|
-
isShowingOptions: true
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
if (!this.state.isShowingOptions) {
|
|
343
|
-
var _this$props$onShowOpt, _this$props3;
|
|
344
|
-
|
|
345
|
-
(_this$props$onShowOpt = (_this$props3 = this.props).onShowOptions) === null || _this$props$onShowOpt === void 0 ? void 0 : _this$props$onShowOpt.call(_this$props3, event);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
handleShowOptions = event => {
|
|
349
|
-
var _this$props$onShowOpt2, _this$props4;
|
|
350
|
-
|
|
351
|
-
this.setState({
|
|
352
|
-
isShowingOptions: true,
|
|
353
|
-
highlightedOptionId: this.state.selectedOptionId
|
|
354
|
-
});
|
|
355
|
-
(_this$props$onShowOpt2 = (_this$props4 = this.props).onShowOptions) === null || _this$props$onShowOpt2 === void 0 ? void 0 : _this$props$onShowOpt2.call(_this$props4, event);
|
|
356
|
-
};
|
|
357
|
-
handleHideOptions = event => {
|
|
358
|
-
var _this$props$onHideOpt, _this$props5;
|
|
359
|
-
|
|
360
|
-
const selectedOptionId = this.state.selectedOptionId;
|
|
361
|
-
const option = this.getOption('id', selectedOptionId);
|
|
362
|
-
let prevValue = '';
|
|
363
|
-
|
|
364
|
-
if (this.props.defaultValue) {
|
|
365
|
-
const date = DateTime.parse(this.props.defaultValue, this.locale(), this.timezone());
|
|
366
|
-
prevValue = this.props.format ? date.format(this.props.format) : date.toISOString();
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
this.setState(() => ({
|
|
370
|
-
isShowingOptions: false,
|
|
371
|
-
highlightedOptionId: void 0,
|
|
372
|
-
inputValue: selectedOptionId ? option.label : prevValue,
|
|
373
|
-
filteredOptions: this.filterOptions(''),
|
|
374
|
-
...this.matchValue()
|
|
375
|
-
}));
|
|
376
|
-
(_this$props$onHideOpt = (_this$props5 = this.props).onHideOptions) === null || _this$props$onHideOpt === void 0 ? void 0 : _this$props$onHideOpt.call(_this$props5, event);
|
|
377
|
-
};
|
|
378
|
-
handleHighlightOption = (event, _ref) => {
|
|
379
|
-
let id = _ref.id;
|
|
380
|
-
if (id === this._emptyOptionId) return;
|
|
381
|
-
const type = event.type;
|
|
382
|
-
const option = this.getOption('id', id).label;
|
|
383
|
-
this.setState(state => ({
|
|
384
|
-
highlightedOptionId: id,
|
|
385
|
-
inputValue: type === 'keydown' ? option : state.inputValue
|
|
386
|
-
}));
|
|
387
|
-
};
|
|
388
|
-
handleSelectOption = (event, _ref2) => {
|
|
389
|
-
var _this$props$onHideOpt2, _this$props7;
|
|
390
|
-
|
|
391
|
-
let id = _ref2.id;
|
|
392
|
-
|
|
393
|
-
if (id === this._emptyOptionId) {
|
|
394
|
-
this.setState({
|
|
395
|
-
isShowingOptions: false
|
|
396
|
-
});
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const option = this.getOption('id', id);
|
|
401
|
-
let newInputValue;
|
|
402
|
-
|
|
403
|
-
if (this.isControlled) {
|
|
404
|
-
const prev = this.getOption('id', this.state.selectedOptionId);
|
|
405
|
-
newInputValue = prev ? prev.label : '';
|
|
406
|
-
this.setState({
|
|
407
|
-
isShowingOptions: false,
|
|
408
|
-
inputValue: newInputValue,
|
|
409
|
-
filteredOptions: this.filterOptions('')
|
|
410
|
-
});
|
|
411
|
-
} else {
|
|
412
|
-
newInputValue = option.label;
|
|
413
|
-
this.setState({
|
|
414
|
-
isShowingOptions: false,
|
|
415
|
-
selectedOptionId: id,
|
|
416
|
-
inputValue: newInputValue,
|
|
417
|
-
filteredOptions: this.filterOptions('')
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (id !== this.state.selectedOptionId) {
|
|
422
|
-
var _this$props$onChange, _this$props6;
|
|
423
|
-
|
|
424
|
-
(_this$props$onChange = (_this$props6 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props6, event, {
|
|
425
|
-
value: option.value,
|
|
426
|
-
inputText: newInputValue
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
(_this$props$onHideOpt2 = (_this$props7 = this.props).onHideOptions) === null || _this$props$onHideOpt2 === void 0 ? void 0 : _this$props$onHideOpt2.call(_this$props7, event);
|
|
431
|
-
};
|
|
432
|
-
|
|
433
421
|
renderOptions() {
|
|
434
422
|
const _this$state3 = this.state,
|
|
435
423
|
filteredOptions = _this$state3.filteredOptions,
|
|
@@ -519,6 +507,17 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
519
507
|
}, passthroughProps(rest)), isShowingOptions && this.renderOptions());
|
|
520
508
|
}
|
|
521
509
|
|
|
522
|
-
}
|
|
510
|
+
}, _class2.displayName = "TimeSelect", _class2.componentId = 'TimeSelect', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
511
|
+
defaultToFirstOption: false,
|
|
512
|
+
format: 'LT',
|
|
513
|
+
// see https://momentjs.com/docs/#/displaying/
|
|
514
|
+
step: 30,
|
|
515
|
+
isRequired: false,
|
|
516
|
+
isInline: false,
|
|
517
|
+
visibleOptionsCount: 8,
|
|
518
|
+
placement: 'bottom stretch',
|
|
519
|
+
constrain: 'window',
|
|
520
|
+
renderEmptyOption: '---'
|
|
521
|
+
}, _class2.contextType = ApplyLocaleContext, _class2)) || _class) || _class);
|
|
523
522
|
export { TimeSelect };
|
|
524
523
|
export default TimeSelect;
|
package/lib/TimeSelect/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var _props = require("./props");
|
|
|
35
35
|
|
|
36
36
|
const _excluded = ["value", "defaultValue", "placeholder", "renderLabel", "inputRef", "id", "listRef", "renderBeforeInput", "renderAfterInput", "isRequired", "isInline", "width", "format", "step", "optionsMaxWidth", "visibleOptionsCount", "messages", "placement", "constrain", "onFocus", "onShowOptions", "onHideOptions"];
|
|
37
37
|
|
|
38
|
-
var _dec, _dec2, _class;
|
|
38
|
+
var _dec, _dec2, _class, _class2;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
---
|
|
@@ -45,29 +45,139 @@ category: components
|
|
|
45
45
|
|
|
46
46
|
A component used to select a time value.
|
|
47
47
|
**/
|
|
48
|
-
let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = class TimeSelect extends _react.Component {
|
|
49
|
-
static displayName = "TimeSelect";
|
|
50
|
-
static componentId = 'TimeSelect';
|
|
51
|
-
static allowedProps = _props.allowedProps;
|
|
52
|
-
static propTypes = _props.propTypes;
|
|
53
|
-
static defaultProps = {
|
|
54
|
-
defaultToFirstOption: false,
|
|
55
|
-
format: 'LT',
|
|
56
|
-
// see https://momentjs.com/docs/#/displaying/
|
|
57
|
-
step: 30,
|
|
58
|
-
isRequired: false,
|
|
59
|
-
isInline: false,
|
|
60
|
-
visibleOptionsCount: 8,
|
|
61
|
-
placement: 'bottom stretch',
|
|
62
|
-
constrain: 'window',
|
|
63
|
-
renderEmptyOption: '---'
|
|
64
|
-
};
|
|
65
|
-
static contextType = _ApplyLocaleContext.ApplyLocaleContext;
|
|
66
|
-
ref = null;
|
|
67
|
-
_emptyOptionId = this.props.deterministicId('Select-EmptyOption');
|
|
68
|
-
|
|
48
|
+
let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class TimeSelect extends _react.Component {
|
|
69
49
|
constructor(props) {
|
|
50
|
+
var _this;
|
|
51
|
+
|
|
70
52
|
super(props);
|
|
53
|
+
_this = this;
|
|
54
|
+
this.ref = null;
|
|
55
|
+
this._emptyOptionId = this.props.deterministicId('Select-EmptyOption');
|
|
56
|
+
|
|
57
|
+
this.getOption = function (field, value) {
|
|
58
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : _this.state.options;
|
|
59
|
+
return options.find(option => option[field] === value);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
this.handleRef = node => {
|
|
63
|
+
this.ref = node;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
this.handleBlur = event => {
|
|
67
|
+
var _this$props$onBlur, _this$props;
|
|
68
|
+
|
|
69
|
+
this.setState({
|
|
70
|
+
highlightedOptionId: void 0
|
|
71
|
+
});
|
|
72
|
+
(_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, event);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
this.handleInputChange = event => {
|
|
76
|
+
const value = event.target.value;
|
|
77
|
+
const newOptions = this.filterOptions(value);
|
|
78
|
+
this.setState({
|
|
79
|
+
inputValue: value,
|
|
80
|
+
filteredOptions: newOptions,
|
|
81
|
+
highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : void 0,
|
|
82
|
+
isShowingOptions: true
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!this.state.isShowingOptions) {
|
|
86
|
+
var _this$props$onShowOpt, _this$props2;
|
|
87
|
+
|
|
88
|
+
(_this$props$onShowOpt = (_this$props2 = this.props).onShowOptions) === null || _this$props$onShowOpt === void 0 ? void 0 : _this$props$onShowOpt.call(_this$props2, event);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
this.handleShowOptions = event => {
|
|
93
|
+
var _this$props$onShowOpt2, _this$props3;
|
|
94
|
+
|
|
95
|
+
this.setState({
|
|
96
|
+
isShowingOptions: true,
|
|
97
|
+
highlightedOptionId: this.state.selectedOptionId
|
|
98
|
+
});
|
|
99
|
+
(_this$props$onShowOpt2 = (_this$props3 = this.props).onShowOptions) === null || _this$props$onShowOpt2 === void 0 ? void 0 : _this$props$onShowOpt2.call(_this$props3, event);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
this.handleHideOptions = event => {
|
|
103
|
+
var _this$props$onHideOpt, _this$props4;
|
|
104
|
+
|
|
105
|
+
const selectedOptionId = this.state.selectedOptionId;
|
|
106
|
+
const option = this.getOption('id', selectedOptionId);
|
|
107
|
+
let prevValue = '';
|
|
108
|
+
|
|
109
|
+
if (this.props.defaultValue) {
|
|
110
|
+
const date = _DateTime.DateTime.parse(this.props.defaultValue, this.locale(), this.timezone());
|
|
111
|
+
|
|
112
|
+
prevValue = this.props.format ? date.format(this.props.format) : date.toISOString();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.setState(() => ({
|
|
116
|
+
isShowingOptions: false,
|
|
117
|
+
highlightedOptionId: void 0,
|
|
118
|
+
inputValue: selectedOptionId ? option.label : prevValue,
|
|
119
|
+
filteredOptions: this.filterOptions(''),
|
|
120
|
+
...this.matchValue()
|
|
121
|
+
}));
|
|
122
|
+
(_this$props$onHideOpt = (_this$props4 = this.props).onHideOptions) === null || _this$props$onHideOpt === void 0 ? void 0 : _this$props$onHideOpt.call(_this$props4, event);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
this.handleHighlightOption = (event, _ref) => {
|
|
126
|
+
let id = _ref.id;
|
|
127
|
+
if (id === this._emptyOptionId) return;
|
|
128
|
+
const type = event.type;
|
|
129
|
+
const option = this.getOption('id', id).label;
|
|
130
|
+
this.setState(state => ({
|
|
131
|
+
highlightedOptionId: id,
|
|
132
|
+
inputValue: type === 'keydown' ? option : state.inputValue
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
this.handleSelectOption = (event, _ref2) => {
|
|
137
|
+
var _this$props$onHideOpt2, _this$props6;
|
|
138
|
+
|
|
139
|
+
let id = _ref2.id;
|
|
140
|
+
|
|
141
|
+
if (id === this._emptyOptionId) {
|
|
142
|
+
this.setState({
|
|
143
|
+
isShowingOptions: false
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const option = this.getOption('id', id);
|
|
149
|
+
let newInputValue;
|
|
150
|
+
|
|
151
|
+
if (this.isControlled) {
|
|
152
|
+
const prev = this.getOption('id', this.state.selectedOptionId);
|
|
153
|
+
newInputValue = prev ? prev.label : '';
|
|
154
|
+
this.setState({
|
|
155
|
+
isShowingOptions: false,
|
|
156
|
+
inputValue: newInputValue,
|
|
157
|
+
filteredOptions: this.filterOptions('')
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
newInputValue = option.label;
|
|
161
|
+
this.setState({
|
|
162
|
+
isShowingOptions: false,
|
|
163
|
+
selectedOptionId: id,
|
|
164
|
+
inputValue: newInputValue,
|
|
165
|
+
filteredOptions: this.filterOptions('')
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (id !== this.state.selectedOptionId) {
|
|
170
|
+
var _this$props$onChange, _this$props5;
|
|
171
|
+
|
|
172
|
+
(_this$props$onChange = (_this$props5 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props5, event, {
|
|
173
|
+
value: option.value,
|
|
174
|
+
inputText: newInputValue
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
(_this$props$onHideOpt2 = (_this$props6 = this.props).onHideOptions) === null || _this$props$onHideOpt2 === void 0 ? void 0 : _this$props$onHideOpt2.call(_this$props6, event);
|
|
179
|
+
};
|
|
180
|
+
|
|
71
181
|
this.state = this.getInitialState();
|
|
72
182
|
}
|
|
73
183
|
|
|
@@ -182,11 +292,11 @@ let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2
|
|
|
182
292
|
}
|
|
183
293
|
|
|
184
294
|
getInitialOption(options) {
|
|
185
|
-
const _this$
|
|
186
|
-
value = _this$
|
|
187
|
-
defaultValue = _this$
|
|
188
|
-
defaultToFirstOption = _this$
|
|
189
|
-
format = _this$
|
|
295
|
+
const _this$props7 = this.props,
|
|
296
|
+
value = _this$props7.value,
|
|
297
|
+
defaultValue = _this$props7.defaultValue,
|
|
298
|
+
defaultToFirstOption = _this$props7.defaultToFirstOption,
|
|
299
|
+
format = _this$props7.format;
|
|
190
300
|
const initialValue = value || defaultValue;
|
|
191
301
|
|
|
192
302
|
if (typeof initialValue === 'string') {
|
|
@@ -214,15 +324,6 @@ let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2
|
|
|
214
324
|
return void 0;
|
|
215
325
|
}
|
|
216
326
|
|
|
217
|
-
getOption = (() => {
|
|
218
|
-
var _this = this;
|
|
219
|
-
|
|
220
|
-
return function (field, value) {
|
|
221
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : _this.state.options;
|
|
222
|
-
return options.find(option => option[field] === value);
|
|
223
|
-
};
|
|
224
|
-
})();
|
|
225
|
-
|
|
226
327
|
getFormattedId(date) {
|
|
227
328
|
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
228
329
|
// date as the id.
|
|
@@ -324,119 +425,6 @@ let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2
|
|
|
324
425
|
return void 0;
|
|
325
426
|
}
|
|
326
427
|
|
|
327
|
-
handleRef = node => {
|
|
328
|
-
this.ref = node;
|
|
329
|
-
};
|
|
330
|
-
handleBlur = event => {
|
|
331
|
-
var _this$props$onBlur, _this$props2;
|
|
332
|
-
|
|
333
|
-
this.setState({
|
|
334
|
-
highlightedOptionId: void 0
|
|
335
|
-
});
|
|
336
|
-
(_this$props$onBlur = (_this$props2 = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props2, event);
|
|
337
|
-
};
|
|
338
|
-
handleInputChange = event => {
|
|
339
|
-
const value = event.target.value;
|
|
340
|
-
const newOptions = this.filterOptions(value);
|
|
341
|
-
this.setState({
|
|
342
|
-
inputValue: value,
|
|
343
|
-
filteredOptions: newOptions,
|
|
344
|
-
highlightedOptionId: newOptions.length > 0 ? newOptions[0].id : void 0,
|
|
345
|
-
isShowingOptions: true
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
if (!this.state.isShowingOptions) {
|
|
349
|
-
var _this$props$onShowOpt, _this$props3;
|
|
350
|
-
|
|
351
|
-
(_this$props$onShowOpt = (_this$props3 = this.props).onShowOptions) === null || _this$props$onShowOpt === void 0 ? void 0 : _this$props$onShowOpt.call(_this$props3, event);
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
handleShowOptions = event => {
|
|
355
|
-
var _this$props$onShowOpt2, _this$props4;
|
|
356
|
-
|
|
357
|
-
this.setState({
|
|
358
|
-
isShowingOptions: true,
|
|
359
|
-
highlightedOptionId: this.state.selectedOptionId
|
|
360
|
-
});
|
|
361
|
-
(_this$props$onShowOpt2 = (_this$props4 = this.props).onShowOptions) === null || _this$props$onShowOpt2 === void 0 ? void 0 : _this$props$onShowOpt2.call(_this$props4, event);
|
|
362
|
-
};
|
|
363
|
-
handleHideOptions = event => {
|
|
364
|
-
var _this$props$onHideOpt, _this$props5;
|
|
365
|
-
|
|
366
|
-
const selectedOptionId = this.state.selectedOptionId;
|
|
367
|
-
const option = this.getOption('id', selectedOptionId);
|
|
368
|
-
let prevValue = '';
|
|
369
|
-
|
|
370
|
-
if (this.props.defaultValue) {
|
|
371
|
-
const date = _DateTime.DateTime.parse(this.props.defaultValue, this.locale(), this.timezone());
|
|
372
|
-
|
|
373
|
-
prevValue = this.props.format ? date.format(this.props.format) : date.toISOString();
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
this.setState(() => ({
|
|
377
|
-
isShowingOptions: false,
|
|
378
|
-
highlightedOptionId: void 0,
|
|
379
|
-
inputValue: selectedOptionId ? option.label : prevValue,
|
|
380
|
-
filteredOptions: this.filterOptions(''),
|
|
381
|
-
...this.matchValue()
|
|
382
|
-
}));
|
|
383
|
-
(_this$props$onHideOpt = (_this$props5 = this.props).onHideOptions) === null || _this$props$onHideOpt === void 0 ? void 0 : _this$props$onHideOpt.call(_this$props5, event);
|
|
384
|
-
};
|
|
385
|
-
handleHighlightOption = (event, _ref) => {
|
|
386
|
-
let id = _ref.id;
|
|
387
|
-
if (id === this._emptyOptionId) return;
|
|
388
|
-
const type = event.type;
|
|
389
|
-
const option = this.getOption('id', id).label;
|
|
390
|
-
this.setState(state => ({
|
|
391
|
-
highlightedOptionId: id,
|
|
392
|
-
inputValue: type === 'keydown' ? option : state.inputValue
|
|
393
|
-
}));
|
|
394
|
-
};
|
|
395
|
-
handleSelectOption = (event, _ref2) => {
|
|
396
|
-
var _this$props$onHideOpt2, _this$props7;
|
|
397
|
-
|
|
398
|
-
let id = _ref2.id;
|
|
399
|
-
|
|
400
|
-
if (id === this._emptyOptionId) {
|
|
401
|
-
this.setState({
|
|
402
|
-
isShowingOptions: false
|
|
403
|
-
});
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const option = this.getOption('id', id);
|
|
408
|
-
let newInputValue;
|
|
409
|
-
|
|
410
|
-
if (this.isControlled) {
|
|
411
|
-
const prev = this.getOption('id', this.state.selectedOptionId);
|
|
412
|
-
newInputValue = prev ? prev.label : '';
|
|
413
|
-
this.setState({
|
|
414
|
-
isShowingOptions: false,
|
|
415
|
-
inputValue: newInputValue,
|
|
416
|
-
filteredOptions: this.filterOptions('')
|
|
417
|
-
});
|
|
418
|
-
} else {
|
|
419
|
-
newInputValue = option.label;
|
|
420
|
-
this.setState({
|
|
421
|
-
isShowingOptions: false,
|
|
422
|
-
selectedOptionId: id,
|
|
423
|
-
inputValue: newInputValue,
|
|
424
|
-
filteredOptions: this.filterOptions('')
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
if (id !== this.state.selectedOptionId) {
|
|
429
|
-
var _this$props$onChange, _this$props6;
|
|
430
|
-
|
|
431
|
-
(_this$props$onChange = (_this$props6 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props6, event, {
|
|
432
|
-
value: option.value,
|
|
433
|
-
inputText: newInputValue
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
(_this$props$onHideOpt2 = (_this$props7 = this.props).onHideOptions) === null || _this$props$onHideOpt2 === void 0 ? void 0 : _this$props$onHideOpt2.call(_this$props7, event);
|
|
438
|
-
};
|
|
439
|
-
|
|
440
428
|
renderOptions() {
|
|
441
429
|
const _this$state3 = this.state,
|
|
442
430
|
filteredOptions = _this$state3.filteredOptions,
|
|
@@ -525,7 +513,18 @@ let TimeSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2
|
|
|
525
513
|
}, (0, _passthroughProps.passthroughProps)(rest)), isShowingOptions && this.renderOptions());
|
|
526
514
|
}
|
|
527
515
|
|
|
528
|
-
}
|
|
516
|
+
}, _class2.displayName = "TimeSelect", _class2.componentId = 'TimeSelect', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
|
517
|
+
defaultToFirstOption: false,
|
|
518
|
+
format: 'LT',
|
|
519
|
+
// see https://momentjs.com/docs/#/displaying/
|
|
520
|
+
step: 30,
|
|
521
|
+
isRequired: false,
|
|
522
|
+
isInline: false,
|
|
523
|
+
visibleOptionsCount: 8,
|
|
524
|
+
placement: 'bottom stretch',
|
|
525
|
+
constrain: 'window',
|
|
526
|
+
renderEmptyOption: '---'
|
|
527
|
+
}, _class2.contextType = _ApplyLocaleContext.ApplyLocaleContext, _class2)) || _class) || _class);
|
|
529
528
|
exports.TimeSelect = TimeSelect;
|
|
530
529
|
var _default = TimeSelect;
|
|
531
530
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-time-select",
|
|
3
|
-
"version": "8.25.1-snapshot-
|
|
3
|
+
"version": "8.25.1-snapshot-13",
|
|
4
4
|
"description": "A component for selecting time values.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.13.10",
|
|
27
|
-
"@instructure/shared-types": "8.25.1-snapshot-
|
|
28
|
-
"@instructure/ui-form-field": "8.25.1-snapshot-
|
|
29
|
-
"@instructure/ui-i18n": "8.25.1-snapshot-
|
|
30
|
-
"@instructure/ui-position": "8.25.1-snapshot-
|
|
31
|
-
"@instructure/ui-prop-types": "8.25.1-snapshot-
|
|
32
|
-
"@instructure/ui-react-utils": "8.25.1-snapshot-
|
|
33
|
-
"@instructure/ui-select": "8.25.1-snapshot-
|
|
34
|
-
"@instructure/ui-test-locator": "8.25.1-snapshot-
|
|
35
|
-
"@instructure/ui-testable": "8.25.1-snapshot-
|
|
27
|
+
"@instructure/shared-types": "8.25.1-snapshot-13",
|
|
28
|
+
"@instructure/ui-form-field": "8.25.1-snapshot-13",
|
|
29
|
+
"@instructure/ui-i18n": "8.25.1-snapshot-13",
|
|
30
|
+
"@instructure/ui-position": "8.25.1-snapshot-13",
|
|
31
|
+
"@instructure/ui-prop-types": "8.25.1-snapshot-13",
|
|
32
|
+
"@instructure/ui-react-utils": "8.25.1-snapshot-13",
|
|
33
|
+
"@instructure/ui-select": "8.25.1-snapshot-13",
|
|
34
|
+
"@instructure/ui-test-locator": "8.25.1-snapshot-13",
|
|
35
|
+
"@instructure/ui-testable": "8.25.1-snapshot-13",
|
|
36
36
|
"prop-types": "^15"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@instructure/ui-babel-preset": "8.25.1-snapshot-
|
|
40
|
-
"@instructure/ui-test-utils": "8.25.1-snapshot-
|
|
39
|
+
"@instructure/ui-babel-preset": "8.25.1-snapshot-13",
|
|
40
|
+
"@instructure/ui-test-utils": "8.25.1-snapshot-13",
|
|
41
41
|
"moment-timezone": "^0.5.33"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|