@elliemae/ds-time-picker 1.60.0 → 2.0.0-alpha.12

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.
Files changed (54) hide show
  1. package/cjs/DSTimePicker.js +28 -71
  2. package/cjs/DSTimePickerMenu.js +17 -27
  3. package/cjs/PickerPanel.js +323 -340
  4. package/cjs/TimePickerDropdown.js +19 -29
  5. package/cjs/TimePickerImpl.js +89 -124
  6. package/cjs/TimePickerMenu.js +257 -295
  7. package/cjs/index.js +1 -30
  8. package/cjs/moveElementOnScroll.js +19 -28
  9. package/cjs/utils.js +14 -19
  10. package/esm/DSTimePicker.js +27 -69
  11. package/esm/DSTimePickerMenu.js +14 -25
  12. package/esm/PickerPanel.js +321 -330
  13. package/esm/TimePickerDropdown.js +18 -27
  14. package/esm/TimePickerImpl.js +84 -117
  15. package/esm/TimePickerMenu.js +254 -285
  16. package/esm/index.js +0 -29
  17. package/esm/moveElementOnScroll.js +18 -27
  18. package/esm/utils.js +14 -19
  19. package/package.json +66 -17
  20. package/types/DSTimePicker.d.ts +181 -0
  21. package/types/DSTimePickerMenu.d.ts +4 -0
  22. package/types/PickerPanel.d.ts +24 -0
  23. package/types/TimePickerDropdown.d.ts +25 -0
  24. package/types/TimePickerImpl.d.ts +35 -0
  25. package/types/TimePickerMenu.d.ts +19 -0
  26. package/types/index.d.ts +5 -0
  27. package/types/moveElementOnScroll.d.ts +13 -0
  28. package/types/utils.d.ts +8 -0
  29. package/DSTimePicker/package.json +0 -10
  30. package/DSTimePickerMenu/package.json +0 -10
  31. package/PickerPanel/package.json +0 -10
  32. package/TimePickerDropdown/package.json +0 -10
  33. package/TimePickerImpl/package.json +0 -10
  34. package/TimePickerMenu/package.json +0 -10
  35. package/cjs/DSTimePicker.js.map +0 -1
  36. package/cjs/DSTimePickerMenu.js.map +0 -1
  37. package/cjs/PickerPanel.js.map +0 -1
  38. package/cjs/TimePickerDropdown.js.map +0 -1
  39. package/cjs/TimePickerImpl.js.map +0 -1
  40. package/cjs/TimePickerMenu.js.map +0 -1
  41. package/cjs/index.js.map +0 -1
  42. package/cjs/moveElementOnScroll.js.map +0 -1
  43. package/cjs/utils.js.map +0 -1
  44. package/esm/DSTimePicker.js.map +0 -1
  45. package/esm/DSTimePickerMenu.js.map +0 -1
  46. package/esm/PickerPanel.js.map +0 -1
  47. package/esm/TimePickerDropdown.js.map +0 -1
  48. package/esm/TimePickerImpl.js.map +0 -1
  49. package/esm/TimePickerMenu.js.map +0 -1
  50. package/esm/index.js.map +0 -1
  51. package/esm/moveElementOnScroll.js.map +0 -1
  52. package/esm/utils.js.map +0 -1
  53. package/moveElementOnScroll/package.json +0 -10
  54. package/utils/package.json +0 -10
@@ -1,13 +1,15 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
3
- import _toArray from '@babel/runtime/helpers/esm/toArray';
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.filter.js';
3
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
4
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
5
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
5
- import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
6
- import _createClass from '@babel/runtime/helpers/esm/createClass';
7
- import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
8
- import _inherits from '@babel/runtime/helpers/esm/inherits';
9
- import _possibleConstructorReturn from '@babel/runtime/helpers/esm/possibleConstructorReturn';
10
- import _getPrototypeOf from '@babel/runtime/helpers/esm/getPrototypeOf';
6
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
7
+ import 'core-js/modules/web.dom-collections.iterator.js';
8
+ import 'core-js/modules/esnext.async-iterator.find.js';
9
+ import 'core-js/modules/esnext.iterator.constructor.js';
10
+ import 'core-js/modules/esnext.iterator.find.js';
11
+ import 'core-js/modules/esnext.async-iterator.map.js';
12
+ import 'core-js/modules/esnext.iterator.map.js';
11
13
  import React, { Component } from 'react';
12
14
  import { findIndex } from 'lodash';
13
15
  import { aggregatedClasses } from '@elliemae/ds-classnames';
@@ -16,378 +18,368 @@ import { ChevronSmallUp, ChevronSmallDown } from '@elliemae/ds-icons';
16
18
  import DSButton from '@elliemae/ds-button';
17
19
  import { MoveElementOnScroll } from './moveElementOnScroll.js';
18
20
  import { validateIndex } from './utils.js';
21
+ import { jsx } from 'react/jsx-runtime';
22
+
23
+ var _SelectedCircle, _ChevronSmallUp, _ChevronSmallDown;
19
24
 
20
25
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
26
 
22
27
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
25
-
26
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
- var blockName = 'time-picker-panel';
28
- var Container = aggregatedClasses('div')(blockName, null, function (_ref) {
29
- var scrolling = _ref.scrolling;
28
+ const blockName = 'time-picker-panel';
29
+ const Container = aggregatedClasses('div')(blockName, null, _ref => {
30
+ let {
31
+ scrolling
32
+ } = _ref;
30
33
  return {
31
- scrolling: scrolling
34
+ scrolling
32
35
  };
33
36
  });
34
- var Wrapper = aggregatedClasses('div')(blockName, 'wrapper');
35
- var PickerItemListContainer = aggregatedClasses('div')(blockName, 'item-list-container');
36
- var PickerItemList = aggregatedClasses('div')(blockName, 'item-list');
37
- var PickerHeader = aggregatedClasses('div')(blockName, 'header');
38
- var PickerItemContainer = aggregatedClasses('div')(blockName, 'item', function (_ref2) {
39
- var selected = _ref2.selected,
40
- disabled = _ref2.disabled;
37
+ const Wrapper = aggregatedClasses('div')(blockName, 'wrapper');
38
+ const PickerItemListContainer = aggregatedClasses('div')(blockName, 'item-list-container');
39
+ const PickerItemList = aggregatedClasses('div')(blockName, 'item-list');
40
+ const PickerHeader = aggregatedClasses('div')(blockName, 'header');
41
+ const PickerItemContainer = aggregatedClasses('div')(blockName, 'item', _ref2 => {
42
+ let {
43
+ selected,
44
+ disabled
45
+ } = _ref2;
41
46
  return {
42
- selected: selected,
43
- disabled: disabled
47
+ selected,
48
+ disabled
44
49
  };
45
50
  });
46
- var PickerSelectedOptionSelected = aggregatedClasses('div')(blockName, 'selected-container');
47
- var SelectedCircle = aggregatedClasses('div')(blockName, 'selected-circle');
48
- var ArrowButtonContainer = aggregatedClasses('div')(blockName, 'arrow-container');
49
-
50
- var getOptionIndex = function getOptionIndex(options, selectedOption) {
51
- var valueProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'value';
52
- var index = options.findIndex(function (option) {
53
- return option[valueProperty] === selectedOption;
54
- });
51
+ const PickerSelectedOptionSelected = aggregatedClasses('div')(blockName, 'selected-container');
52
+ const SelectedCircle = aggregatedClasses('div')(blockName, 'selected-circle');
53
+ const ArrowButtonContainer = aggregatedClasses('div')(blockName, 'arrow-container');
54
+
55
+ const getOptionIndex = function (options, selectedOption) {
56
+ let valueProperty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'value';
57
+ const index = options.findIndex(option => option[valueProperty] === selectedOption);
55
58
  return validateIndex(index, options);
56
59
  };
57
60
 
58
- var arrowProps = {
61
+ const arrowProps = {
59
62
  buttonType: 'text',
60
63
  fluidHeight: true,
61
64
  fluidWidth: true,
62
65
  size: 's'
63
66
  };
64
-
65
- var PickerPanel = /*#__PURE__*/function (_Component) {
66
- _inherits(PickerPanel, _Component);
67
-
68
- var _super = _createSuper(PickerPanel);
69
-
70
- function PickerPanel(props) {
71
- var _this;
72
-
73
- _classCallCheck(this, PickerPanel);
74
-
75
- _this = _super.call(this, props);
76
- _this.computeContainerTranslation = memoizeOne(function (index) {
77
- var _this$props = _this.props,
78
- options = _this$props.options,
79
- valueProperty = _this$props.valueProperty;
80
- var _this$state = _this.state,
81
- selectedOption = _this$state.selectedOption,
82
- scrolling = _this$state.scrolling;
83
- var selectedOptionIndex = index || getOptionIndex(options, selectedOption, valueProperty);
84
- var listYPosition = _this.minYListPosition - selectedOptionIndex * _this.optionHeight;
85
- if (_this.scrollHandler && !scrolling) _this.scrollHandler.updatePosition(listYPosition);
67
+ class PickerPanel extends Component {
68
+ constructor(props) {
69
+ super(props);
70
+ this.computeContainerTranslation = memoizeOne(index => {
71
+ const {
72
+ options,
73
+ valueProperty
74
+ } = this.props;
75
+ const {
76
+ selectedOption,
77
+ scrolling
78
+ } = this.state;
79
+ const selectedOptionIndex = index || getOptionIndex(options, selectedOption, valueProperty);
80
+ const listYPosition = this.minYListPosition - selectedOptionIndex * this.optionHeight;
81
+ if (this.scrollHandler && !scrolling) this.scrollHandler.updatePosition(listYPosition);
86
82
  return listYPosition;
87
83
  });
88
84
 
89
- _this.renderHeader = function () {
90
- var header = _this.props.header;
91
- return /*#__PURE__*/React.createElement(PickerHeader, null, header);
85
+ this.renderHeader = () => {
86
+ const {
87
+ header
88
+ } = this.props;
89
+ return /*#__PURE__*/_jsx(PickerHeader, {}, void 0, header);
92
90
  };
93
91
 
94
- _this.pickerListContainerRef = /*#__PURE__*/React.createRef();
95
- _this.pickerListRef = /*#__PURE__*/React.createRef();
96
- _this.pickerItemRef = /*#__PURE__*/React.createRef();
97
- _this.selectedOptionRef = /*#__PURE__*/React.createRef();
98
- _this.state = {
92
+ this.pickerListContainerRef = /*#__PURE__*/React.createRef();
93
+ this.pickerListRef = /*#__PURE__*/React.createRef();
94
+ this.pickerItemRef = /*#__PURE__*/React.createRef();
95
+ this.selectedOptionRef = /*#__PURE__*/React.createRef();
96
+ this.state = {
99
97
  selectedOption: props.selected,
100
98
  activeIndex: 0,
101
99
  // eslint-disable-next-line react/no-unused-state
102
100
  prevProps: {}
103
101
  };
104
- _this.handleKeyDown = _this.handleKeyDown.bind(_assertThisInitialized(_this));
105
- _this.handleStepMoveUp = _this.handleStepMoveUp.bind(_assertThisInitialized(_this));
106
- _this.handleStepMoveDown = _this.handleStepMoveDown.bind(_assertThisInitialized(_this));
107
- return _this;
102
+ this.handleKeyDown = this.handleKeyDown.bind(this);
103
+ this.handleStepMoveUp = this.handleStepMoveUp.bind(this);
104
+ this.handleStepMoveDown = this.handleStepMoveDown.bind(this);
108
105
  }
109
106
 
110
- _createClass(PickerPanel, [{
111
- key: "componentDidMount",
112
- value: function componentDidMount() {
113
- var _this2 = this;
114
-
115
- this.computeSizes();
116
- var pickerListContainerEl = this.pickerListContainerRef.current;
117
- var pickerListEl = this.pickerListRef.current;
118
- this.scrollHandler = new MoveElementOnScroll(pickerListEl, {
119
- container: pickerListContainerEl,
120
- min: -this.minYListPosition,
121
- max: this.maxYListPosition,
122
- onUpdate: function onUpdate(pos, delta) {
123
- var options = _this2.props.options;
124
- var index = options.length - -Math.floor((pos - _this2.maxYListPosition) / _this2.optionHeight) + (delta > 0 ? 1 : -1);
125
-
126
- _this2.moveTo(index, true);
127
- },
128
- onEndScroll: function onEndScroll() {
129
- _this2.setState({
130
- scrolling: false
131
- });
132
- }
133
- });
134
- this.computeContainerTranslation();
135
- }
136
- }, {
137
- key: "componentWillUnmount",
138
- value: function componentWillUnmount() {
139
- this.scrollHandler.unsubscribe();
140
- }
141
- }, {
142
- key: "getOptionValue",
143
- value: function getOptionValue(option) {
144
- var valueProperty = this.props.valueProperty;
145
- return option[valueProperty];
146
- }
147
- }, {
148
- key: "getOptionLabel",
149
- value: function getOptionLabel(option) {
150
- var labelProperty = this.props.labelProperty;
151
- return option[labelProperty];
152
- }
153
- }, {
154
- key: "computeSizes",
155
- value: function computeSizes() {
156
- var _this$props2 = this.props,
157
- options = _this$props2.options,
158
- numberItemsOnScreen = _this$props2.numberItemsOnScreen;
159
- var optionHeight = this.pickerItemRef.current.offsetHeight;
160
- this.optionHeight = optionHeight;
161
- this.listHeight = this.optionHeight * numberItemsOnScreen;
162
- this.minYListPosition = this.listHeight / 2 - this.optionHeight / 2;
163
- this.maxYListPosition = this.optionHeight * (options.length - Math.ceil(numberItemsOnScreen / 2));
164
- }
165
- }, {
166
- key: "handleOptionSelect",
167
- value: function handleOptionSelect(optionValue, index, scrolling) {
168
- var onChange = this.props.onChange;
169
- this.setState(function (state) {
170
- return _objectSpread(_objectSpread({}, state), {}, {
171
- scrolling: scrolling,
172
- selectedOption: optionValue,
173
- activeIndex: index
107
+ componentDidMount() {
108
+ this.computeSizes();
109
+ const pickerListContainerEl = this.pickerListContainerRef.current;
110
+ const pickerListEl = this.pickerListRef.current;
111
+ this.scrollHandler = new MoveElementOnScroll(pickerListEl, {
112
+ container: pickerListContainerEl,
113
+ min: -this.minYListPosition,
114
+ max: this.maxYListPosition,
115
+ onUpdate: (pos, delta) => {
116
+ const {
117
+ options
118
+ } = this.props;
119
+ const index = options.length - -Math.floor((pos - this.maxYListPosition) / this.optionHeight) + (delta > 0 ? 1 : -1);
120
+ this.moveTo(index, true);
121
+ },
122
+ onEndScroll: () => {
123
+ this.setState({
124
+ scrolling: false
174
125
  });
175
- }, function () {
176
- onChange(optionValue, index);
177
- });
178
- } // TODO: this needs a refactor from de FocusGroup
179
- // eslint-disable-next-line max-statements
180
-
181
- }, {
182
- key: "handleKeyDown",
183
- value: function handleKeyDown(e) {
184
- var activeIndex = this.state.activeIndex;
185
- var options = this.props.options;
186
-
187
- var _document$getElements = document.getElementsByClassName('em-ds-time-picker-panel'),
188
- _document$getElements2 = _toArray(_document$getElements),
189
- firstColumn = _document$getElements2[0],
190
- restColumns = _document$getElements2.slice(1);
191
-
192
- var _restColumns$slice = restColumns.slice(-1),
193
- _restColumns$slice2 = _slicedToArray(_restColumns$slice, 1),
194
- lastColumn = _restColumns$slice2[0];
195
-
196
- var _document$getElements3 = document.getElementsByClassName('DayPickerNavigation_button'),
197
- _document$getElements4 = _slicedToArray(_document$getElements3, 1),
198
- prev = _document$getElements4[0];
199
-
200
- var focusedElement = document.activeElement;
201
-
202
- switch (e.key) {
203
- case 'Home':
204
- this.moveTo(0);
205
- break;
126
+ }
127
+ });
128
+ this.computeContainerTranslation();
129
+ }
206
130
 
207
- case 'End':
208
- this.moveTo(options.length - 1);
209
- break;
131
+ componentWillUnmount() {
132
+ this.scrollHandler.unsubscribe();
133
+ }
210
134
 
211
- case 'ArrowUp':
212
- this.moveTo(activeIndex - 1);
213
- break;
135
+ static getDerivedStateFromProps(nextProps, _ref3) {
136
+ let {
137
+ prevProps
138
+ } = _ref3;
139
+ const {
140
+ selected,
141
+ valueProperty,
142
+ options
143
+ } = nextProps;
144
+
145
+ if (selected !== prevProps.selected) {
146
+ return {
147
+ selectedOption: selected,
148
+ activeIndex: getOptionIndex(options, selected, valueProperty),
149
+ prevProps: nextProps
150
+ };
151
+ }
214
152
 
215
- case 'ArrowDown':
216
- this.moveTo(activeIndex + 1);
217
- break;
153
+ return null;
154
+ }
218
155
 
219
- case 'Tab':
220
- {
221
- e.preventDefault(); // If it is DateTimePicker, move focus to prev arrow element
156
+ getOptionValue(option) {
157
+ const {
158
+ valueProperty
159
+ } = this.props;
160
+ return option[valueProperty];
161
+ }
222
162
 
223
- if (prev && focusedElement === lastColumn) {
224
- prev.focus();
225
- } else if (focusedElement === lastColumn) {
226
- firstColumn.focus();
227
- } else {
228
- var position = findIndex(restColumns, focusedElement);
229
- restColumns[position + 1].focus();
230
- }
163
+ getOptionLabel(option) {
164
+ const {
165
+ labelProperty
166
+ } = this.props;
167
+ return option[labelProperty];
168
+ }
231
169
 
232
- break;
170
+ computeSizes() {
171
+ const {
172
+ options,
173
+ numberItemsOnScreen
174
+ } = this.props;
175
+ const {
176
+ offsetHeight: optionHeight
177
+ } = this.pickerItemRef.current;
178
+ this.optionHeight = optionHeight;
179
+ this.listHeight = this.optionHeight * numberItemsOnScreen;
180
+ this.minYListPosition = this.listHeight / 2 - this.optionHeight / 2;
181
+ this.maxYListPosition = this.optionHeight * (options.length - Math.ceil(numberItemsOnScreen / 2));
182
+ }
183
+
184
+ handleOptionSelect(optionValue, index, scrolling) {
185
+ const {
186
+ onChange
187
+ } = this.props;
188
+ this.setState(state => _objectSpread(_objectSpread({}, state), {}, {
189
+ scrolling,
190
+ selectedOption: optionValue,
191
+ activeIndex: index
192
+ }), () => {
193
+ onChange(optionValue, index);
194
+ });
195
+ } // TODO: this needs a refactor from de FocusGroup
196
+ // eslint-disable-next-line max-statements
197
+
198
+
199
+ handleKeyDown(e) {
200
+ const {
201
+ activeIndex
202
+ } = this.state;
203
+ const {
204
+ options
205
+ } = this.props;
206
+ const [firstColumn, ...restColumns] = document.getElementsByClassName('em-ds-time-picker-panel');
207
+ const [lastColumn] = restColumns.slice(-1);
208
+ const [prev] = document.getElementsByClassName('DayPickerNavigation_button');
209
+ const focusedElement = document.activeElement;
210
+
211
+ switch (e.key) {
212
+ case 'Home':
213
+ this.moveTo(0);
214
+ break;
215
+
216
+ case 'End':
217
+ this.moveTo(options.length - 1);
218
+ break;
219
+
220
+ case 'ArrowUp':
221
+ this.moveTo(activeIndex - 1);
222
+ break;
223
+
224
+ case 'ArrowDown':
225
+ this.moveTo(activeIndex + 1);
226
+ break;
227
+
228
+ case 'Tab':
229
+ {
230
+ e.preventDefault(); // If it is DateTimePicker, move focus to prev arrow element
231
+
232
+ if (prev && focusedElement === lastColumn) {
233
+ prev.focus();
234
+ } else if (focusedElement === lastColumn) {
235
+ firstColumn.focus();
236
+ } else {
237
+ const position = findIndex(restColumns, focusedElement);
238
+ restColumns[position + 1].focus();
233
239
  }
234
- }
235
- }
236
- }, {
237
- key: "moveTo",
238
- value: function moveTo(index, scrolling) {
239
- var options = this.props.options;
240
- var selectedOption = this.state.selectedOption;
241
- var validIndex = validateIndex(index, options);
242
- var option = options[validIndex];
243
- var optionValue = this.getOptionValue(option);
244
-
245
- if (selectedOption !== optionValue && option.disabled !== true) {
246
- this.handleOptionSelect(optionValue, validIndex, scrolling);
247
- } // TO-DO: if date disabled, add nextValidOption selection
248
240
 
249
- }
250
- }, {
251
- key: "handleStepMoveUp",
252
- value: function handleStepMoveUp() {
253
- var activeIndex = this.state.activeIndex;
254
- var _this$props3 = this.props,
255
- arrowStep = _this$props3.arrowStep,
256
- options = _this$props3.options;
257
- var supposedPos = activeIndex - arrowStep;
258
- var nextPos = supposedPos >= 0 ? supposedPos : activeIndex - 1;
259
- var nextValidOption = options.find(function (op) {
260
- return !op.disabled;
261
- });
262
- this.moveTo(nextPos, true, nextValidOption);
263
- }
264
- }, {
265
- key: "handleStepMoveDown",
266
- value: function handleStepMoveDown() {
267
- var activeIndex = this.state.activeIndex;
268
- var _this$props4 = this.props,
269
- arrowStep = _this$props4.arrowStep,
270
- options = _this$props4.options;
271
- var supposedPos = activeIndex + arrowStep;
272
- var nextPos = supposedPos <= options.length ? supposedPos : activeIndex + 1;
273
- this.moveTo(nextPos);
274
- }
275
- }, {
276
- key: "render",
277
- value: function render() {
278
- var _this3 = this;
279
-
280
- var _this$props5 = this.props,
281
- options = _this$props5.options,
282
- hasHeader = _this$props5.hasHeader,
283
- type = _this$props5.type,
284
- time = _this$props5.time,
285
- meridiem = _this$props5.meridiem,
286
- disabledTimes = _this$props5.disabledTimes;
287
- var _this$state2 = this.state,
288
- selectedOption = _this$state2.selectedOption,
289
- activeIndex = _this$state2.activeIndex,
290
- scrolling = _this$state2.scrolling;
291
- var listYPosition = this.computeContainerTranslation(activeIndex);
292
- return /*#__PURE__*/React.createElement(Wrapper, null, hasHeader && this.renderHeader(), /*#__PURE__*/React.createElement(Container, {
293
- classProps: {
294
- scrolling: scrolling
295
- },
296
- onKeyDown: this.handleKeyDown,
297
- tabIndex: 0
298
- }, /*#__PURE__*/React.createElement(PickerSelectedOptionSelected, {
299
- innerRef: this.selectedOptionRef
300
- }, /*#__PURE__*/React.createElement(SelectedCircle, null)), /*#__PURE__*/React.createElement(ArrowButtonContainer, null, /*#__PURE__*/React.createElement(DSButton, _extends({}, arrowProps, {
301
- "aria-label": "Chevron Up",
302
- "data-testid": "".concat(type, "-chevron-up"),
303
- disabled: activeIndex <= 0,
304
- icon: /*#__PURE__*/React.createElement(ChevronSmallUp, null),
305
- onClick: this.handleStepMoveUp,
306
- tabIndex: -1
307
- }))), /*#__PURE__*/React.createElement(PickerItemListContainer, {
308
- innerRef: this.pickerListContainerRef,
309
- style: {
310
- height: this.listHeight
311
- }
312
- }, /*#__PURE__*/React.createElement(PickerItemList, {
313
- "data-testid": "".concat(type, "-list"),
314
- innerRef: this.pickerListRef,
315
- style: {
316
- transform: "translateY(".concat(listYPosition, "px)")
241
+ break;
317
242
  }
318
- }, options.map(function (option, index) {
319
- var value = _this3.getOptionValue(option);
243
+ }
244
+ }
320
245
 
321
- var label = _this3.getOptionLabel(option);
246
+ moveTo(index, scrolling) {
247
+ const {
248
+ options
249
+ } = this.props;
250
+ const {
251
+ selectedOption
252
+ } = this.state;
253
+ const validIndex = validateIndex(index, options);
254
+ const option = options[validIndex];
255
+ const optionValue = this.getOptionValue(option);
256
+
257
+ if (selectedOption !== optionValue && option.disabled !== true) {
258
+ this.handleOptionSelect(optionValue, validIndex, scrolling);
259
+ } // TO-DO: if date disabled, add nextValidOption selection
322
260
 
323
- var valueFormatted;
324
- if (meridiem === 'AM') valueFormatted = value;else if (meridiem === 'PM' && value === 12) valueFormatted = value;else if (meridiem === 'PM') valueFormatted = value + 12;
325
- var disabled = false;
261
+ }
326
262
 
327
- if (disabledTimes) {
328
- var from = disabledTimes.from,
329
- to = disabledTimes.to;
263
+ handleStepMoveUp() {
264
+ const {
265
+ activeIndex
266
+ } = this.state;
267
+ const {
268
+ arrowStep,
269
+ options
270
+ } = this.props;
271
+ const supposedPos = activeIndex - arrowStep;
272
+ const nextPos = supposedPos >= 0 ? supposedPos : activeIndex - 1;
273
+ const nextValidOption = options.find(op => !op.disabled);
274
+ this.moveTo(nextPos, true, nextValidOption);
275
+ }
330
276
 
331
- if (type === 'hour' && valueFormatted >= (from === null || from === void 0 ? void 0 : from.hour) && valueFormatted < (to === null || to === void 0 ? void 0 : to.hour) || type === 'minutes' && value >= (from === null || from === void 0 ? void 0 : from.min) && value < (to === null || to === void 0 ? void 0 : to.min)) {
332
- disabled = true;
333
- }
277
+ handleStepMoveDown() {
278
+ const {
279
+ activeIndex
280
+ } = this.state;
281
+ const {
282
+ arrowStep,
283
+ options
284
+ } = this.props;
285
+ const supposedPos = activeIndex + arrowStep;
286
+ const nextPos = supposedPos <= options.length ? supposedPos : activeIndex + 1;
287
+ this.moveTo(nextPos);
288
+ }
334
289
 
335
- if (type === 'minutes' && ((time === null || time === void 0 ? void 0 : time.hour()) > (to === null || to === void 0 ? void 0 : to.hour) || (time === null || time === void 0 ? void 0 : time.hour()) < (from === null || from === void 0 ? void 0 : from.hour))) {
336
- disabled = false;
337
- }
290
+ render() {
291
+ const {
292
+ options,
293
+ hasHeader,
294
+ type,
295
+ time,
296
+ meridiem,
297
+ disabledTimes
298
+ } = this.props;
299
+ const {
300
+ selectedOption,
301
+ activeIndex,
302
+ scrolling
303
+ } = this.state;
304
+ const listYPosition = this.computeContainerTranslation(activeIndex);
305
+ return /*#__PURE__*/_jsx(Wrapper, {}, void 0, hasHeader && this.renderHeader(), /*#__PURE__*/_jsx(Container, {
306
+ classProps: {
307
+ scrolling
308
+ },
309
+ onKeyDown: this.handleKeyDown,
310
+ tabIndex: 0
311
+ }, void 0, /*#__PURE__*/_jsx(PickerSelectedOptionSelected, {
312
+ innerRef: this.selectedOptionRef
313
+ }, void 0, _SelectedCircle || (_SelectedCircle = /*#__PURE__*/_jsx(SelectedCircle, {}))), /*#__PURE__*/_jsx(ArrowButtonContainer, {}, void 0, /*#__PURE__*/jsx(DSButton, _objectSpread(_objectSpread({}, arrowProps), {}, {
314
+ "aria-label": "Chevron Up",
315
+ "data-testid": "".concat(type, "-chevron-up"),
316
+ disabled: activeIndex <= 0,
317
+ icon: _ChevronSmallUp || (_ChevronSmallUp = /*#__PURE__*/_jsx(ChevronSmallUp, {})),
318
+ onClick: this.handleStepMoveUp,
319
+ tabIndex: -1
320
+ }))), /*#__PURE__*/_jsx(PickerItemListContainer, {
321
+ innerRef: this.pickerListContainerRef,
322
+ style: {
323
+ height: this.listHeight
324
+ }
325
+ }, void 0, /*#__PURE__*/_jsx(PickerItemList, {
326
+ "data-testid": "".concat(type, "-list"),
327
+ innerRef: this.pickerListRef,
328
+ style: {
329
+ transform: "translateY(".concat(listYPosition, "px)")
330
+ }
331
+ }, void 0, options.map((option, index) => {
332
+ const value = this.getOptionValue(option);
333
+ const label = this.getOptionLabel(option);
334
+ let valueFormatted;
335
+ if (meridiem === 'AM') valueFormatted = value;else if (meridiem === 'PM' && value === 12) valueFormatted = value;else if (meridiem === 'PM') valueFormatted = value + 12;
336
+ let disabled = false;
337
+
338
+ if (disabledTimes) {
339
+ const {
340
+ from,
341
+ to
342
+ } = disabledTimes;
343
+
344
+ if (type === 'hour' && valueFormatted >= (from === null || from === void 0 ? void 0 : from.hour) && valueFormatted < (to === null || to === void 0 ? void 0 : to.hour) || type === 'minutes' && value >= (from === null || from === void 0 ? void 0 : from.min) && value < (to === null || to === void 0 ? void 0 : to.min)) {
345
+ disabled = true;
346
+ }
338
347
 
339
- if (label === 'am' && (from === null || from === void 0 ? void 0 : from.hour) == 0 && (to === null || to === void 0 ? void 0 : to.hour) >= 12) {
340
- disabled = true;
341
- }
348
+ if (type === 'minutes' && ((time === null || time === void 0 ? void 0 : time.hour()) > (to === null || to === void 0 ? void 0 : to.hour) || (time === null || time === void 0 ? void 0 : time.hour()) < (from === null || from === void 0 ? void 0 : from.hour))) {
349
+ disabled = false;
350
+ }
342
351
 
343
- if (label === 'pm' && (to === null || to === void 0 ? void 0 : to.hour) == 24) {
344
- disabled = true;
345
- }
352
+ if (label === 'am' && (from === null || from === void 0 ? void 0 : from.hour) == 0 && (to === null || to === void 0 ? void 0 : to.hour) >= 12) {
353
+ disabled = true;
346
354
  }
347
355
 
348
- option.disabled = disabled;
349
- return /*#__PURE__*/React.createElement(PickerItemContainer, {
350
- key: value,
351
- classProps: {
352
- selected: selectedOption ? value === selectedOption : index === 0,
353
- disabled: disabled
354
- },
355
- innerRef: _this3.pickerItemRef,
356
- onClick: function onClick() {
357
- if (!disabled) _this3.handleOptionSelect(value, index);
358
- }
359
- }, label);
360
- }))), /*#__PURE__*/React.createElement(ArrowButtonContainer, null, /*#__PURE__*/React.createElement(DSButton, _extends({}, arrowProps, {
361
- "aria-label": "Chevron Down",
362
- "data-testid": "".concat(type, "-chevron-down"),
363
- disabled: activeIndex >= options.length - 1,
364
- icon: /*#__PURE__*/React.createElement(ChevronSmallDown, null),
365
- onClick: this.handleStepMoveDown,
366
- tabIndex: -1
367
- })))));
368
- }
369
- }], [{
370
- key: "getDerivedStateFromProps",
371
- value: function getDerivedStateFromProps(nextProps, _ref3) {
372
- var prevProps = _ref3.prevProps;
373
- var selected = nextProps.selected,
374
- valueProperty = nextProps.valueProperty,
375
- options = nextProps.options;
376
-
377
- if (selected !== prevProps.selected) {
378
- return {
379
- selectedOption: selected,
380
- activeIndex: getOptionIndex(options, selected, valueProperty),
381
- prevProps: nextProps
382
- };
356
+ if (label === 'pm' && (to === null || to === void 0 ? void 0 : to.hour) == 24) {
357
+ disabled = true;
358
+ }
383
359
  }
384
360
 
385
- return null;
386
- }
387
- }]);
361
+ option.disabled = disabled;
362
+ return /*#__PURE__*/_jsx(PickerItemContainer, {
363
+ classProps: {
364
+ selected: selectedOption ? value === selectedOption : index === 0,
365
+ disabled
366
+ },
367
+ innerRef: this.pickerItemRef,
368
+ onClick: () => {
369
+ if (!disabled) this.handleOptionSelect(value, index);
370
+ }
371
+ }, value, label);
372
+ }))), /*#__PURE__*/_jsx(ArrowButtonContainer, {}, void 0, /*#__PURE__*/jsx(DSButton, _objectSpread(_objectSpread({}, arrowProps), {}, {
373
+ "aria-label": "Chevron Down",
374
+ "data-testid": "".concat(type, "-chevron-down"),
375
+ disabled: activeIndex >= options.length - 1,
376
+ icon: _ChevronSmallDown || (_ChevronSmallDown = /*#__PURE__*/_jsx(ChevronSmallDown, {})),
377
+ onClick: this.handleStepMoveDown,
378
+ tabIndex: -1
379
+ })))));
380
+ }
388
381
 
389
- return PickerPanel;
390
- }(Component);
382
+ }
391
383
  PickerPanel.defaultProps = {
392
384
  valueProperty: 'value',
393
385
  labelProperty: 'label',
@@ -398,4 +390,3 @@ PickerPanel.defaultProps = {
398
390
  };
399
391
 
400
392
  export { PickerPanel as default };
401
- //# sourceMappingURL=PickerPanel.js.map