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