@atlaskit/datetime-picker 14.0.1 → 14.0.3

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.
@@ -1,22 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
10
5
  var _excluded = ["styles"];
11
6
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- 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); }; }
14
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
- import React from 'react';
8
+ import React, { forwardRef, useReducer, useState } from 'react';
16
9
 
17
10
  // eslint-disable-next-line no-restricted-imports
18
11
  import { format, isValid } from 'date-fns';
19
- import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
12
+ import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
13
+ import __noop from '@atlaskit/ds-lib/noop';
20
14
  import { createLocalizationProvider } from '@atlaskit/locale';
21
15
  import Select, { CreatableSelect, mergeStyles } from '@atlaskit/select';
22
16
  // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
@@ -27,7 +21,7 @@ import parseTime from '../internal/parse-time';
27
21
  import { convertTokens } from '../internal/parse-tokens';
28
22
  import { makeSingleValue } from '../internal/single-value';
29
23
  var packageName = "@atlaskit/datetime-picker";
30
- var packageVersion = "14.0.1";
24
+ var packageVersion = "14.0.3";
31
25
  var menuStyles = {
32
26
  /* Need to remove default absolute positioning as that causes issues with position fixed */
33
27
  position: 'static',
@@ -36,296 +30,11 @@ var menuStyles = {
36
30
  /* React-Popper has already offset the menu so we need to reset the margin, otherwise the offset value is doubled */
37
31
  margin: 0
38
32
  };
39
- var timePickerDefaultProps = {
40
- appearance: 'default',
41
- autoFocus: false,
42
- defaultIsOpen: false,
43
- defaultValue: '',
44
- hideIcon: false,
45
- id: '',
46
- innerProps: {},
47
- isDisabled: false,
48
- isInvalid: false,
49
- label: '',
50
- name: '',
51
- // These disables are here for proper typing when used as defaults. They
52
- // should *not* use the `noop` function.
53
- /* eslint-disable @repo/internal/react/use-noop */
54
- onBlur: function onBlur(_event) {},
55
- onChange: function onChange(_value) {},
56
- onFocus: function onFocus(_event) {},
57
- /* eslint-enable @repo/internal/react/use-noop */
58
- parseInputValue: function parseInputValue(time, _timeFormat) {
59
- return parseTime(time);
60
- },
61
- selectProps: {},
62
- spacing: 'default',
63
- times: defaultTimes,
64
- timeIsEditable: false,
65
- locale: 'en-US'
66
- // Not including a default prop for value as it will
67
- // Make the component a controlled component
33
+ var analyticsAttributes = {
34
+ componentName: 'timePicker',
35
+ packageName: packageName,
36
+ packageVersion: packageVersion
68
37
  };
69
- var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
70
- _inherits(TimePickerComponent, _React$Component);
71
- var _super = _createSuper(TimePickerComponent);
72
- function TimePickerComponent() {
73
- var _this;
74
- _classCallCheck(this, TimePickerComponent);
75
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
76
- args[_key] = arguments[_key];
77
- }
78
- _this = _super.call.apply(_super, [this].concat(args));
79
- _defineProperty(_assertThisInitialized(_this), "containerRef", null);
80
- _defineProperty(_assertThisInitialized(_this), "state", {
81
- isOpen: _this.props.defaultIsOpen,
82
- clearingFromIcon: false,
83
- value: _this.props.defaultValue,
84
- isFocused: false
85
- });
86
- // All state needs to be accessed via this function so that the state is mapped from props
87
- // correctly to allow controlled/uncontrolled usage.
88
- _defineProperty(_assertThisInitialized(_this), "getValue", function () {
89
- var _this$props$value;
90
- return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
91
- });
92
- _defineProperty(_assertThisInitialized(_this), "getIsOpen", function () {
93
- var _this$props$isOpen;
94
- return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
95
- });
96
- _defineProperty(_assertThisInitialized(_this), "onChange", function (newValue, action) {
97
- var rawValue = newValue ? newValue.value || newValue : '';
98
- var value = rawValue.toString();
99
- var changedState = {
100
- value: value
101
- };
102
- if (action && action.action === 'clear') {
103
- changedState = _objectSpread(_objectSpread({}, changedState), {}, {
104
- clearingFromIcon: true
105
- });
106
- }
107
- _this.setState(changedState);
108
- _this.props.onChange(value);
109
- });
110
- /**
111
- * Only allow custom times if timeIsEditable prop is true
112
- */
113
- _defineProperty(_assertThisInitialized(_this), "onCreateOption", function (inputValue) {
114
- if (_this.props.timeIsEditable) {
115
- var _this$props = _this.props,
116
- parseInputValue = _this$props.parseInputValue,
117
- timeFormat = _this$props.timeFormat;
118
- var sanitizedInput;
119
- try {
120
- sanitizedInput = parseInputValue(inputValue, timeFormat || defaultTimeFormat);
121
- } catch (e) {
122
- return; // do nothing, the main validation should happen in the form
123
- }
124
- var includesSeconds = !!(timeFormat && /[:.]?(s|ss)/.test(timeFormat));
125
- var formatFormat = includesSeconds ? 'HH:mm:ss' : 'HH:mm';
126
- var formattedValue = format(sanitizedInput, formatFormat) || '';
127
- _this.setState({
128
- value: formattedValue
129
- });
130
- _this.props.onChange(formattedValue);
131
- } else {
132
- _this.onChange(inputValue);
133
- }
134
- });
135
- _defineProperty(_assertThisInitialized(_this), "onMenuOpen", function () {
136
- // Don't open menu after the user has clicked clear
137
- if (_this.state.clearingFromIcon) {
138
- _this.setState({
139
- clearingFromIcon: false
140
- });
141
- } else {
142
- _this.setState({
143
- isOpen: true
144
- });
145
- }
146
- });
147
- _defineProperty(_assertThisInitialized(_this), "onMenuClose", function () {
148
- // Don't close menu after the user has clicked clear
149
- if (_this.state.clearingFromIcon) {
150
- _this.setState({
151
- clearingFromIcon: false
152
- });
153
- } else {
154
- _this.setState({
155
- isOpen: false
156
- });
157
- }
158
- });
159
- _defineProperty(_assertThisInitialized(_this), "setContainerRef", function (ref) {
160
- var oldRef = _this.containerRef;
161
- _this.containerRef = ref;
162
- // Cause a re-render if we're getting the container ref for the first time
163
- // as the layered menu requires it for dimension calculation
164
- if (oldRef == null && ref != null) {
165
- _this.forceUpdate();
166
- }
167
- });
168
- _defineProperty(_assertThisInitialized(_this), "onBlur", function (event) {
169
- _this.setState({
170
- isFocused: false
171
- });
172
- _this.props.onBlur(event);
173
- });
174
- _defineProperty(_assertThisInitialized(_this), "onFocus", function (event) {
175
- _this.setState({
176
- isFocused: true
177
- });
178
- _this.props.onFocus(event);
179
- });
180
- _defineProperty(_assertThisInitialized(_this), "onSelectKeyDown", function (event) {
181
- var key = event.key;
182
- var keyPressed = key.toLowerCase();
183
- if (_this.state.clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
184
- // If being cleared from keyboard, don't change behaviour
185
- _this.setState({
186
- clearingFromIcon: false
187
- });
188
- }
189
- });
190
- return _this;
191
- }
192
- _createClass(TimePickerComponent, [{
193
- key: "render",
194
- value: function render() {
195
- var _this2 = this;
196
- var _this$props2 = this.props,
197
- appearance = _this$props2.appearance,
198
- ariaDescribedBy = _this$props2['aria-describedby'],
199
- autoFocus = _this$props2.autoFocus,
200
- formatDisplayLabel = _this$props2.formatDisplayLabel,
201
- hideIcon = _this$props2.hideIcon,
202
- id = _this$props2.id,
203
- innerProps = _this$props2.innerProps,
204
- isDisabled = _this$props2.isDisabled,
205
- label = _this$props2.label,
206
- locale = _this$props2.locale,
207
- name = _this$props2.name,
208
- placeholder = _this$props2.placeholder,
209
- selectProps = _this$props2.selectProps,
210
- spacing = _this$props2.spacing,
211
- testId = _this$props2.testId,
212
- isInvalid = _this$props2.isInvalid,
213
- timeIsEditable = _this$props2.timeIsEditable,
214
- timeFormat = _this$props2.timeFormat,
215
- times = _this$props2.times;
216
- var ICON_PADDING = 2;
217
- var l10n = createLocalizationProvider(locale);
218
- var value = this.getValue() || '';
219
- var isOpen = this.getIsOpen();
220
- var _selectProps$styles = selectProps.styles,
221
- selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
222
- otherSelectProps = _objectWithoutProperties(selectProps, _excluded);
223
- var SelectComponent = timeIsEditable ? CreatableSelect : Select;
224
-
225
- /**
226
- * There are multiple props that can change how the time is formatted.
227
- * The priority of props used is:
228
- * 1. formatDisplayLabel
229
- * 2. timeFormat
230
- * 3. locale
231
- */
232
- var formatTime = function formatTime(time) {
233
- if (formatDisplayLabel) {
234
- return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
235
- }
236
- var date = parseTime(time);
237
- if (!(date instanceof Date)) {
238
- return '';
239
- }
240
- if (!isValid(date)) {
241
- return time;
242
- }
243
- if (timeFormat) {
244
- return format(date, convertTokens(timeFormat));
245
- }
246
- return l10n.formatTime(date);
247
- };
248
- var options = times.map(function (time) {
249
- return {
250
- label: formatTime(time),
251
- value: time
252
- };
253
- });
254
- var initialValue = value ? {
255
- label: formatTime(value),
256
- value: value
257
- } : null;
258
- var SingleValue = makeSingleValue({
259
- lang: this.props.locale
260
- });
261
- var selectComponents = _objectSpread({
262
- DropdownIndicator: EmptyComponent,
263
- Menu: FixedLayerMenu,
264
- SingleValue: SingleValue
265
- }, hideIcon && {
266
- ClearIndicator: EmptyComponent
267
- });
268
- var renderIconContainer = Boolean(!hideIcon && value);
269
- var mergedStyles = mergeStyles(selectStyles, {
270
- control: function control(base) {
271
- return _objectSpread({}, base);
272
- },
273
- menu: function menu(base) {
274
- return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
275
- // Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
276
- // menu width to the width of our container
277
- width: _this2.containerRef ? _this2.containerRef.getBoundingClientRect().width : 'auto'
278
- });
279
- },
280
- indicatorsContainer: function indicatorsContainer(base) {
281
- return _objectSpread(_objectSpread({}, base), {}, {
282
- paddingLeft: renderIconContainer ? ICON_PADDING : 0,
283
- paddingRight: renderIconContainer ? gridSize() - ICON_PADDING : 0
284
- });
285
- }
286
- });
287
- return /*#__PURE__*/React.createElement("div", _extends({}, innerProps, {
288
- ref: this.setContainerRef,
289
- "data-testid": testId && "".concat(testId, "--container")
290
- }), /*#__PURE__*/React.createElement("input", {
291
- name: name,
292
- type: "hidden",
293
- value: value,
294
- "data-testid": testId && "".concat(testId, "--input"),
295
- onKeyDown: this.onSelectKeyDown
296
- }), /*#__PURE__*/React.createElement(SelectComponent, _extends({
297
- "aria-describedby": ariaDescribedBy,
298
- "aria-label": label || undefined,
299
- appearance: appearance,
300
- autoFocus: autoFocus,
301
- components: selectComponents,
302
- inputId: id,
303
- isClearable: true,
304
- isDisabled: isDisabled,
305
- menuIsOpen: isOpen && !isDisabled,
306
- menuPlacement: "auto",
307
- openMenuOnFocus: true,
308
- onBlur: this.onBlur,
309
- onCreateOption: this.onCreateOption,
310
- onChange: this.onChange,
311
- options: options,
312
- onFocus: this.onFocus,
313
- onMenuOpen: this.onMenuOpen,
314
- onMenuClose: this.onMenuClose,
315
- placeholder: placeholder || l10n.formatTime(placeholderDatetime),
316
- styles: mergedStyles,
317
- value: initialValue,
318
- spacing: spacing,
319
- fixedLayerRef: this.containerRef,
320
- isInvalid: isInvalid,
321
- testId: testId
322
- }, otherSelectProps)));
323
- }
324
- }]);
325
- return TimePickerComponent;
326
- }(React.Component);
327
- _defineProperty(TimePickerComponent, "defaultProps", timePickerDefaultProps);
328
- export { TimePickerComponent as TimePickerWithoutAnalytics };
329
38
 
330
39
  /**
331
40
  * __Time picker__
@@ -336,19 +45,280 @@ export { TimePickerComponent as TimePickerWithoutAnalytics };
336
45
  * - [Code](https://atlassian.design/components/datetime-picker/time-picker/code)
337
46
  * - [Usage](https://atlassian.design/components/datetime-picker/time-picker/usage)
338
47
  */
339
- var TimePicker = withAnalyticsContext({
340
- componentName: 'timePicker',
341
- packageName: packageName,
342
- packageVersion: packageVersion
343
- })(withAnalyticsEvents({
344
- onChange: createAndFireEvent('atlaskit')({
48
+ var TimePicker = /*#__PURE__*/forwardRef(function (_ref, ref) {
49
+ var ariaDescribedBy = _ref['aria-describedby'],
50
+ analyticsContext = _ref.analyticsContext,
51
+ _ref$appearance = _ref.appearance,
52
+ appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
53
+ _ref$autoFocus = _ref.autoFocus,
54
+ autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
55
+ _ref$defaultIsOpen = _ref.defaultIsOpen,
56
+ defaultIsOpen = _ref$defaultIsOpen === void 0 ? false : _ref$defaultIsOpen,
57
+ _ref$defaultValue = _ref.defaultValue,
58
+ defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
59
+ formatDisplayLabel = _ref.formatDisplayLabel,
60
+ _ref$hideIcon = _ref.hideIcon,
61
+ hideIcon = _ref$hideIcon === void 0 ? false : _ref$hideIcon,
62
+ _ref$id = _ref.id,
63
+ id = _ref$id === void 0 ? '' : _ref$id,
64
+ _ref$innerProps = _ref.innerProps,
65
+ innerProps = _ref$innerProps === void 0 ? {} : _ref$innerProps,
66
+ _ref$isDisabled = _ref.isDisabled,
67
+ isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
68
+ _ref$isInvalid = _ref.isInvalid,
69
+ isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
70
+ providedIsOpen = _ref.isOpen,
71
+ _ref$label = _ref.label,
72
+ label = _ref$label === void 0 ? '' : _ref$label,
73
+ _ref$locale = _ref.locale,
74
+ locale = _ref$locale === void 0 ? 'en-US' : _ref$locale,
75
+ _ref$name = _ref.name,
76
+ name = _ref$name === void 0 ? '' : _ref$name,
77
+ _ref$onBlur = _ref.onBlur,
78
+ providedOnBlur = _ref$onBlur === void 0 ? __noop : _ref$onBlur,
79
+ _ref$onChange = _ref.onChange,
80
+ providedOnChange = _ref$onChange === void 0 ? __noop : _ref$onChange,
81
+ _ref$onFocus = _ref.onFocus,
82
+ providedOnFocus = _ref$onFocus === void 0 ? __noop : _ref$onFocus,
83
+ _ref$parseInputValue = _ref.parseInputValue,
84
+ parseInputValue = _ref$parseInputValue === void 0 ? function (time, _timeFormat) {
85
+ return parseTime(time);
86
+ } : _ref$parseInputValue,
87
+ placeholder = _ref.placeholder,
88
+ _ref$selectProps = _ref.selectProps,
89
+ selectProps = _ref$selectProps === void 0 ? {} : _ref$selectProps,
90
+ _ref$spacing = _ref.spacing,
91
+ spacing = _ref$spacing === void 0 ? 'default' : _ref$spacing,
92
+ testId = _ref.testId,
93
+ timeFormat = _ref.timeFormat,
94
+ _ref$timeIsEditable = _ref.timeIsEditable,
95
+ timeIsEditable = _ref$timeIsEditable === void 0 ? false : _ref$timeIsEditable,
96
+ _ref$times = _ref.times,
97
+ times = _ref$times === void 0 ? defaultTimes : _ref$times,
98
+ providedValue = _ref.value;
99
+ var _useState = useState(null),
100
+ _useState2 = _slicedToArray(_useState, 2),
101
+ containerRef = _useState2[0],
102
+ setContainerRef = _useState2[1];
103
+ /**
104
+ * When being cleared from the icon the TimePicker is blurred.
105
+ * This variable defines whether the default onMenuOpen or onMenuClose
106
+ * events should behave as normal
107
+ */
108
+ var _useState3 = useState(false),
109
+ _useState4 = _slicedToArray(_useState3, 2),
110
+ clearingFromIcon = _useState4[0],
111
+ setClearingFromIcon = _useState4[1];
112
+ // TODO: Remove isFocused? Does it do anything?
113
+ var _useState5 = useState(false),
114
+ _useState6 = _slicedToArray(_useState5, 2),
115
+ _ = _useState6[0],
116
+ setIsFocused = _useState6[1];
117
+ var _useState7 = useState(providedIsOpen || defaultIsOpen),
118
+ _useState8 = _slicedToArray(_useState7, 2),
119
+ isOpen = _useState8[0],
120
+ setIsOpen = _useState8[1];
121
+ var _useState9 = useState(providedValue || defaultValue),
122
+ _useState10 = _slicedToArray(_useState9, 2),
123
+ value = _useState10[0],
124
+ setValue = _useState10[1];
125
+
126
+ // Hack to force update: https://legacy.reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
127
+ var _useReducer = useReducer(function (x) {
128
+ return x + 1;
129
+ }, 0),
130
+ _useReducer2 = _slicedToArray(_useReducer, 2),
131
+ forceUpdate = _useReducer2[1];
132
+ var providedOnChangeWithAnalytics = usePlatformLeafEventHandler(_objectSpread({
133
+ fn: providedOnChange,
345
134
  action: 'selectedTime',
346
- actionSubject: 'timePicker',
347
- attributes: {
348
- componentName: 'timePicker',
349
- packageName: packageName,
350
- packageVersion: packageVersion
135
+ analyticsData: analyticsContext
136
+ }, analyticsAttributes));
137
+ var onChange = function onChange(newValue, action) {
138
+ var rawValue = newValue ? newValue.value || newValue : '';
139
+ var finalValue = rawValue.toString();
140
+ setValue(finalValue);
141
+ if (action && action.action === 'clear') {
142
+ setClearingFromIcon(true);
143
+ }
144
+ providedOnChangeWithAnalytics(finalValue);
145
+ };
146
+
147
+ /**
148
+ * Only allow custom times if timeIsEditable prop is true
149
+ */
150
+ var onCreateOption = function onCreateOption(inputValue) {
151
+ if (timeIsEditable) {
152
+ var sanitizedInput;
153
+ try {
154
+ sanitizedInput = parseInputValue(inputValue, timeFormat || defaultTimeFormat);
155
+ } catch (e) {
156
+ return; // do nothing, the main validation should happen in the form
157
+ }
158
+ var includesSeconds = !!(timeFormat && /[:.]?(s|ss)/.test(timeFormat));
159
+ var formatFormat = includesSeconds ? 'HH:mm:ss' : 'HH:mm';
160
+ var formattedValue = format(sanitizedInput, formatFormat) || '';
161
+ setValue(formattedValue);
162
+ providedOnChange(formattedValue);
163
+ } else {
164
+ providedOnChange(inputValue);
165
+ }
166
+ };
167
+ var onMenuOpen = function onMenuOpen() {
168
+ // Don't open menu after the user has clicked clear
169
+ if (clearingFromIcon) {
170
+ setClearingFromIcon(false);
171
+ } else {
172
+ setIsOpen(true);
173
+ }
174
+ };
175
+ var onMenuClose = function onMenuClose() {
176
+ // Don't close menu after the user has clicked clear
177
+ if (clearingFromIcon) {
178
+ setClearingFromIcon(false);
179
+ } else {
180
+ setIsOpen(false);
181
+ }
182
+ };
183
+ var setInternalContainerRef = function setInternalContainerRef(ref) {
184
+ var oldRef = containerRef;
185
+ setContainerRef(ref);
186
+ // Cause a re-render if we're getting the container ref for the first time
187
+ // as the layered menu requires it for dimension calculation
188
+ if (oldRef === null && ref !== null) {
189
+ forceUpdate();
190
+ }
191
+ };
192
+ var onBlur = function onBlur(event) {
193
+ setIsFocused(false);
194
+ providedOnBlur(event);
195
+ };
196
+ var onFocus = function onFocus(event) {
197
+ setIsFocused(true);
198
+ providedOnFocus(event);
199
+ };
200
+ var onSelectKeyDown = function onSelectKeyDown(event) {
201
+ var key = event.key;
202
+ var keyPressed = key.toLowerCase();
203
+ if (clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
204
+ // If being cleared from keyboard, don't change behaviour
205
+ setClearingFromIcon(false);
206
+ }
207
+ };
208
+ var ICON_PADDING = 2;
209
+ var l10n = createLocalizationProvider(locale);
210
+ var _selectProps$styles = selectProps.styles,
211
+ selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
212
+ otherSelectProps = _objectWithoutProperties(selectProps, _excluded);
213
+ var SelectComponent = timeIsEditable ? CreatableSelect : Select;
214
+
215
+ /**
216
+ * There are multiple props that can change how the time is formatted.
217
+ * The priority of props used is:
218
+ * 1. formatDisplayLabel
219
+ * 2. timeFormat
220
+ * 3. locale
221
+ */
222
+ var formatTime = function formatTime(time) {
223
+ if (formatDisplayLabel) {
224
+ return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
225
+ }
226
+ var date = parseTime(time);
227
+ if (!(date instanceof Date)) {
228
+ return '';
229
+ }
230
+ if (!isValid(date)) {
231
+ return time;
232
+ }
233
+ if (timeFormat) {
234
+ return format(date, convertTokens(timeFormat));
235
+ }
236
+ return l10n.formatTime(date);
237
+ };
238
+ var options = times.map(function (time) {
239
+ return {
240
+ label: formatTime(time),
241
+ value: time
242
+ };
243
+ });
244
+ var initialValue;
245
+ if (providedValue !== null && providedValue !== undefined && providedValue !== '') {
246
+ initialValue = {
247
+ label: formatTime(providedValue),
248
+ value: providedValue
249
+ };
250
+ } else if (providedValue !== '' && value) {
251
+ initialValue = {
252
+ label: formatTime(value),
253
+ value: value
254
+ };
255
+ } else {
256
+ initialValue = null;
257
+ }
258
+ var SingleValue = makeSingleValue({
259
+ lang: locale
260
+ });
261
+ var selectComponents = _objectSpread({
262
+ DropdownIndicator: EmptyComponent,
263
+ Menu: FixedLayerMenu,
264
+ SingleValue: SingleValue
265
+ }, hideIcon && {
266
+ ClearIndicator: EmptyComponent
267
+ });
268
+ var renderIconContainer = Boolean(!hideIcon && value);
269
+ var mergedStyles = mergeStyles(selectStyles, {
270
+ control: function control(base) {
271
+ return _objectSpread({}, base);
272
+ },
273
+ menu: function menu(base) {
274
+ return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
275
+ // Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
276
+ // menu width to the width of our container
277
+ width: containerRef ? containerRef.getBoundingClientRect().width : 'auto'
278
+ });
279
+ },
280
+ indicatorsContainer: function indicatorsContainer(base) {
281
+ return _objectSpread(_objectSpread({}, base), {}, {
282
+ paddingLeft: renderIconContainer ? ICON_PADDING : 0,
283
+ paddingRight: renderIconContainer ? gridSize() - ICON_PADDING : 0
284
+ });
351
285
  }
352
- })
353
- })(TimePickerComponent));
286
+ });
287
+ return /*#__PURE__*/React.createElement("div", _extends({}, innerProps, {
288
+ ref: setInternalContainerRef,
289
+ "data-testid": testId && "".concat(testId, "--container")
290
+ }), /*#__PURE__*/React.createElement("input", {
291
+ name: name,
292
+ type: "hidden",
293
+ value: value,
294
+ "data-testid": testId && "".concat(testId, "--input"),
295
+ onKeyDown: onSelectKeyDown
296
+ }), /*#__PURE__*/React.createElement(SelectComponent, _extends({
297
+ "aria-describedby": ariaDescribedBy,
298
+ "aria-label": label || undefined,
299
+ appearance: appearance,
300
+ autoFocus: autoFocus,
301
+ components: selectComponents,
302
+ inputId: id,
303
+ isClearable: true,
304
+ isDisabled: isDisabled,
305
+ menuIsOpen: isOpen && !isDisabled,
306
+ menuPlacement: "auto",
307
+ openMenuOnFocus: true,
308
+ onBlur: onBlur,
309
+ onCreateOption: onCreateOption,
310
+ onChange: onChange,
311
+ options: options,
312
+ onFocus: onFocus,
313
+ onMenuOpen: onMenuOpen,
314
+ onMenuClose: onMenuClose,
315
+ placeholder: placeholder || l10n.formatTime(placeholderDatetime),
316
+ styles: mergedStyles,
317
+ value: initialValue,
318
+ spacing: spacing,
319
+ fixedLayerRef: containerRef,
320
+ isInvalid: isInvalid,
321
+ testId: testId
322
+ }, otherSelectProps)));
323
+ });
354
324
  export default TimePicker;
@@ -65,7 +65,6 @@ export var Menu = function Menu(_ref) {
65
65
  onChange: selectProps.onCalendarChange,
66
66
  onSelect: selectProps.onCalendarSelect,
67
67
  previousMonthLabel: selectProps.previousMonthLabel,
68
- calendarRef: selectProps.calendarRef,
69
68
  selected: [selectProps.calendarValue],
70
69
  shouldSetFocusOnCurrentDay: selectProps.shouldSetFocusOnCurrentDay,
71
70
  locale: selectProps.calendarLocale,
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { Component } from 'react';
6
6
  import { jsx } from '@emotion/react';
7
- import { type CalendarRef } from '@atlaskit/calendar';
8
7
  import { type LocalizationProvider } from '@atlaskit/locale';
9
8
  import { type ActionMeta, type DropdownIndicatorProps, type GroupType, type InputActionMeta, type OptionType } from '@atlaskit/select';
10
9
  import { type Appearance, type DatePickerBaseProps, type Spacing } from '../types';
@@ -70,7 +69,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
70
69
  spacing: Spacing;
71
70
  locale: string;
72
71
  };
73
- calendarRef: CalendarRef | null;
74
72
  containerRef: HTMLElement | null;
75
73
  constructor(props: any);
76
74
  static getDerivedStateFromProps(nextProps: Readonly<DatePickerProps>, prevState: State): {
@@ -95,7 +93,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
95
93
  onInputKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
96
94
  onClear: () => void;
97
95
  onSelectChange: (_value: unknown, action: ActionMeta) => void;
98
- refCalendar: (ref: CalendarRef | null) => void;
99
96
  handleSelectInputChange: (selectInputValue: string, actionMeta: InputActionMeta) => void;
100
97
  getContainerRef: (ref: HTMLElement | null) => void;
101
98
  /**