@atlaskit/datetime-picker 12.8.1 → 12.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/datetime-picker
2
2
 
3
+ ## 12.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`829d92bcf37`](https://bitbucket.org/atlassian/atlassian-frontend/commits/829d92bcf37) - Remove out of date lifecycle methods in favor of up to date methods.
8
+
3
9
  ## 12.8.1
4
10
 
5
11
  ### Patch Changes
@@ -38,7 +38,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
38
38
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
39
39
  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; } } /** @jsx jsx */
40
40
  var packageName = "@atlaskit/datetime-picker";
41
- var packageVersion = "12.8.1";
41
+ var packageVersion = "12.8.2";
42
42
  function getValidDate(iso) {
43
43
  var date = (0, _dateFns.parseISO)(iso);
44
44
  return (0, _dateFns.isValid)(date) ? {
@@ -415,20 +415,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
415
415
  selectInputValue: _this.props.selectProps.inputValue,
416
416
  value: _this.props.value || _this.props.defaultValue,
417
417
  calendarValue: _this.props.value || _this.props.defaultValue || getShortISOString(new Date()),
418
- l10n: (0, _locale.createLocalizationProvider)(_this.props.locale)
418
+ l10n: (0, _locale.createLocalizationProvider)(_this.props.locale),
419
+ locale: _this.props.locale
419
420
  };
420
421
  return _this;
421
422
  }
422
423
  (0, _createClass2.default)(DatePicker, [{
423
- key: "UNSAFE_componentWillReceiveProps",
424
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
425
- if (this.props.locale !== nextProps.locale) {
426
- this.setState({
427
- l10n: (0, _locale.createLocalizationProvider)(nextProps.locale)
428
- });
429
- }
430
- }
431
- }, {
432
424
  key: "render",
433
425
  value: function render() {
434
426
  var _this$props3 = this.props,
@@ -554,6 +546,18 @@ var DatePicker = /*#__PURE__*/function (_Component) {
554
546
  })))
555
547
  );
556
548
  }
549
+ }], [{
550
+ key: "getDerivedStateFromProps",
551
+ value: function getDerivedStateFromProps(nextProps, prevState) {
552
+ if (nextProps.locale !== prevState.locale) {
553
+ return {
554
+ l10n: (0, _locale.createLocalizationProvider)(nextProps.locale),
555
+ locale: nextProps.locale
556
+ };
557
+ } else {
558
+ return null;
559
+ }
560
+ }
557
561
  }]);
558
562
  return DatePicker;
559
563
  }(_react.Component);
@@ -31,7 +31,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
31
31
  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; }
32
32
  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) { (0, _defineProperty2.default)(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; } /** @jsx jsx */
33
33
  var packageName = "@atlaskit/datetime-picker";
34
- var packageVersion = "12.8.1";
34
+ var packageVersion = "12.8.2";
35
35
  var isInvalidBorderStyles = (0, _react2.css)({
36
36
  borderColor: "var(--ds-border-danger, ".concat(_colors.R400, ")")
37
37
  });
@@ -37,7 +37,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
37
37
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
38
38
  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; } }
39
39
  var packageName = "@atlaskit/datetime-picker";
40
- var packageVersion = "12.8.1";
40
+ var packageVersion = "12.8.2";
41
41
  var menuStyles = {
42
42
  /* Need to remove default absolute positioning as that causes issues with position fixed */
43
43
  position: 'static',
@@ -102,8 +102,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
102
102
  isOpen: _this.props.defaultIsOpen,
103
103
  clearingFromIcon: false,
104
104
  value: _this.props.defaultValue,
105
- isFocused: false,
106
- l10n: (0, _locale.createLocalizationProvider)(_this.props.locale)
105
+ isFocused: false
107
106
  });
108
107
  // All state needs to be accessed via this function so that the state is mapped from props
109
108
  // correctly to allow controlled/uncontrolled usage.
@@ -203,92 +202,72 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
203
202
  });
204
203
  }
205
204
  });
206
- /**
207
- * There are multiple props that can change how the time is formatted.
208
- * The priority of props used is:
209
- * 1. formatDisplayLabel
210
- * 2. timeFormat
211
- * 3. locale
212
- */
213
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatTime", function (time) {
214
- var _this$props2 = _this.props,
215
- formatDisplayLabel = _this$props2.formatDisplayLabel,
216
- timeFormat = _this$props2.timeFormat;
217
- var _this$getSafeState = _this.getSafeState(),
218
- l10n = _this$getSafeState.l10n;
219
- if (formatDisplayLabel) {
220
- return formatDisplayLabel(time, timeFormat || _internal.defaultTimeFormat);
221
- }
222
- var date = (0, _parseTime.default)(time);
223
- if (!(date instanceof Date)) {
224
- return '';
225
- }
226
- if (!(0, _dateFns.isValid)(date)) {
227
- return time;
228
- }
229
- if (timeFormat) {
230
- return (0, _dateFns.format)(date, (0, _utils.convertTokens)(timeFormat));
231
- }
232
- return l10n.formatTime(date);
233
- });
234
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPlaceholder", function () {
235
- var placeholder = _this.props.placeholder;
236
- if (placeholder) {
237
- return placeholder;
238
- }
239
- var _this$getSafeState2 = _this.getSafeState(),
240
- l10n = _this$getSafeState2.l10n;
241
- return l10n.formatTime(_internal.placeholderDatetime);
242
- });
243
205
  return _this;
244
206
  }
245
207
  (0, _createClass2.default)(TimePicker, [{
246
- key: "UNSAFE_componentWillReceiveProps",
247
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
248
- if (this.props.locale !== nextProps.locale) {
249
- this.setState({
250
- l10n: (0, _locale.createLocalizationProvider)(nextProps.locale)
251
- });
252
- }
253
- }
254
- }, {
255
- key: "getOptions",
256
- value: function getOptions() {
257
- var _this2 = this;
258
- return this.props.times.map(function (time) {
259
- return {
260
- label: _this2.formatTime(time),
261
- value: time
262
- };
263
- });
264
- }
265
- }, {
266
208
  key: "render",
267
209
  value: function render() {
268
- var _this3 = this;
269
- var _this$props3 = this.props,
270
- autoFocus = _this$props3.autoFocus,
271
- hideIcon = _this$props3.hideIcon,
272
- id = _this$props3.id,
273
- innerProps = _this$props3.innerProps,
274
- isDisabled = _this$props3.isDisabled,
275
- name = _this$props3.name,
276
- selectProps = _this$props3.selectProps,
277
- spacing = _this$props3.spacing,
278
- testId = _this$props3.testId,
279
- isInvalid = _this$props3.isInvalid,
280
- timeIsEditable = _this$props3.timeIsEditable;
210
+ var _this2 = this;
211
+ var _this$props2 = this.props,
212
+ appearance = _this$props2.appearance,
213
+ autoFocus = _this$props2.autoFocus,
214
+ formatDisplayLabel = _this$props2.formatDisplayLabel,
215
+ hideIcon = _this$props2.hideIcon,
216
+ id = _this$props2.id,
217
+ innerProps = _this$props2.innerProps,
218
+ isDisabled = _this$props2.isDisabled,
219
+ locale = _this$props2.locale,
220
+ name = _this$props2.name,
221
+ placeholder = _this$props2.placeholder,
222
+ selectProps = _this$props2.selectProps,
223
+ spacing = _this$props2.spacing,
224
+ testId = _this$props2.testId,
225
+ isInvalid = _this$props2.isInvalid,
226
+ timeIsEditable = _this$props2.timeIsEditable,
227
+ timeFormat = _this$props2.timeFormat,
228
+ times = _this$props2.times;
281
229
  var ICON_PADDING = 2;
282
- var _this$getSafeState3 = this.getSafeState(),
283
- _this$getSafeState3$v = _this$getSafeState3.value,
284
- value = _this$getSafeState3$v === void 0 ? '' : _this$getSafeState3$v,
285
- isOpen = _this$getSafeState3.isOpen;
230
+ var l10n = (0, _locale.createLocalizationProvider)(locale);
231
+ var _this$getSafeState = this.getSafeState(),
232
+ _this$getSafeState$va = _this$getSafeState.value,
233
+ value = _this$getSafeState$va === void 0 ? '' : _this$getSafeState$va,
234
+ isOpen = _this$getSafeState.isOpen;
286
235
  var _selectProps$styles = selectProps.styles,
287
236
  selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
288
237
  otherSelectProps = (0, _objectWithoutProperties2.default)(selectProps, _excluded2);
289
238
  var SelectComponent = timeIsEditable ? _select.CreatableSelect : _select.default;
239
+
240
+ /**
241
+ * There are multiple props that can change how the time is formatted.
242
+ * The priority of props used is:
243
+ * 1. formatDisplayLabel
244
+ * 2. timeFormat
245
+ * 3. locale
246
+ */
247
+ var formatTime = function formatTime(time) {
248
+ if (formatDisplayLabel) {
249
+ return formatDisplayLabel(time, timeFormat || _internal.defaultTimeFormat);
250
+ }
251
+ var date = (0, _parseTime.default)(time);
252
+ if (!(date instanceof Date)) {
253
+ return '';
254
+ }
255
+ if (!(0, _dateFns.isValid)(date)) {
256
+ return time;
257
+ }
258
+ if (timeFormat) {
259
+ return (0, _dateFns.format)(date, (0, _utils.convertTokens)(timeFormat));
260
+ }
261
+ return l10n.formatTime(date);
262
+ };
263
+ var options = times.map(function (time) {
264
+ return {
265
+ label: formatTime(time),
266
+ value: time
267
+ };
268
+ });
290
269
  var labelAndValue = value && {
291
- label: this.formatTime(value),
270
+ label: formatTime(value),
292
271
  value: value
293
272
  };
294
273
  var SingleValue = (0, _singleValue.makeSingleValue)({
@@ -310,7 +289,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
310
289
  return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
311
290
  // Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
312
291
  // menu width to the width of our container
313
- width: _this3.containerRef ? _this3.containerRef.getBoundingClientRect().width : 'auto'
292
+ width: _this2.containerRef ? _this2.containerRef.getBoundingClientRect().width : 'auto'
314
293
  });
315
294
  },
316
295
  indicatorsContainer: function indicatorsContainer(base) {
@@ -330,7 +309,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
330
309
  "data-testid": testId && "".concat(testId, "--input"),
331
310
  onKeyDown: this.onSelectKeyDown
332
311
  }), /*#__PURE__*/_react.default.createElement(SelectComponent, (0, _extends2.default)({
333
- appearance: this.props.appearance,
312
+ appearance: appearance,
334
313
  autoFocus: autoFocus,
335
314
  components: selectComponents,
336
315
  instanceId: id,
@@ -342,11 +321,11 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
342
321
  onBlur: this.onBlur,
343
322
  onCreateOption: this.onCreateOption,
344
323
  onChange: this.onChange,
345
- options: this.getOptions(),
324
+ options: options,
346
325
  onFocus: this.onFocus,
347
326
  onMenuOpen: this.onMenuOpen,
348
327
  onMenuClose: this.onMenuClose,
349
- placeholder: this.getPlaceholder(),
328
+ placeholder: placeholder || l10n.formatTime(_internal.placeholderDatetime),
350
329
  styles: mergedStyles,
351
330
  value: labelAndValue,
352
331
  spacing: spacing
@@ -18,7 +18,7 @@ import FixedLayer from '../internal/fixed-layer';
18
18
  import { makeSingleValue } from '../internal/single-value';
19
19
  import { convertTokens } from './utils';
20
20
  const packageName = "@atlaskit/datetime-picker";
21
- const packageVersion = "12.8.1";
21
+ const packageVersion = "12.8.2";
22
22
  function getValidDate(iso) {
23
23
  const date = parseISO(iso);
24
24
  return isValid(date) ? {
@@ -404,14 +404,18 @@ class DatePicker extends Component {
404
404
  selectInputValue: this.props.selectProps.inputValue,
405
405
  value: this.props.value || this.props.defaultValue,
406
406
  calendarValue: this.props.value || this.props.defaultValue || getShortISOString(new Date()),
407
- l10n: createLocalizationProvider(this.props.locale)
407
+ l10n: createLocalizationProvider(this.props.locale),
408
+ locale: this.props.locale
408
409
  };
409
410
  }
410
- UNSAFE_componentWillReceiveProps(nextProps) {
411
- if (this.props.locale !== nextProps.locale) {
412
- this.setState({
413
- l10n: createLocalizationProvider(nextProps.locale)
414
- });
411
+ static getDerivedStateFromProps(nextProps, prevState) {
412
+ if (nextProps.locale !== prevState.locale) {
413
+ return {
414
+ l10n: createLocalizationProvider(nextProps.locale),
415
+ locale: nextProps.locale
416
+ };
417
+ } else {
418
+ return null;
415
419
  }
416
420
  }
417
421
  render() {
@@ -15,7 +15,7 @@ import DatePicker from './date-picker';
15
15
  import TimePicker from './time-picker';
16
16
  import { convertTokens } from './utils';
17
17
  const packageName = "@atlaskit/datetime-picker";
18
- const packageVersion = "12.8.1";
18
+ const packageVersion = "12.8.2";
19
19
  const isInvalidBorderStyles = css({
20
20
  borderColor: `var(--ds-border-danger, ${R400})`
21
21
  });
@@ -16,7 +16,7 @@ import parseTime from '../internal/parse-time';
16
16
  import { makeSingleValue } from '../internal/single-value';
17
17
  import { convertTokens } from './utils';
18
18
  const packageName = "@atlaskit/datetime-picker";
19
- const packageVersion = "12.8.1";
19
+ const packageVersion = "12.8.2";
20
20
  const menuStyles = {
21
21
  /* Need to remove default absolute positioning as that causes issues with position fixed */
22
22
  position: 'static',
@@ -72,8 +72,7 @@ class TimePicker extends React.Component {
72
72
  isOpen: this.props.defaultIsOpen,
73
73
  clearingFromIcon: false,
74
74
  value: this.props.defaultValue,
75
- isFocused: false,
76
- l10n: createLocalizationProvider(this.props.locale)
75
+ isFocused: false
77
76
  });
78
77
  // All state needs to be accessed via this function so that the state is mapped from props
79
78
  // correctly to allow controlled/uncontrolled usage.
@@ -180,6 +179,39 @@ class TimePicker extends React.Component {
180
179
  });
181
180
  }
182
181
  });
182
+ }
183
+ render() {
184
+ const {
185
+ appearance,
186
+ autoFocus,
187
+ formatDisplayLabel,
188
+ hideIcon,
189
+ id,
190
+ innerProps,
191
+ isDisabled,
192
+ locale,
193
+ name,
194
+ placeholder,
195
+ selectProps,
196
+ spacing,
197
+ testId,
198
+ isInvalid,
199
+ timeIsEditable,
200
+ timeFormat,
201
+ times
202
+ } = this.props;
203
+ const ICON_PADDING = 2;
204
+ const l10n = createLocalizationProvider(locale);
205
+ const {
206
+ value = '',
207
+ isOpen
208
+ } = this.getSafeState();
209
+ const {
210
+ styles: selectStyles = {},
211
+ ...otherSelectProps
212
+ } = selectProps;
213
+ const SelectComponent = timeIsEditable ? CreatableSelect : Select;
214
+
183
215
  /**
184
216
  * There are multiple props that can change how the time is formatted.
185
217
  * The priority of props used is:
@@ -187,14 +219,7 @@ class TimePicker extends React.Component {
187
219
  * 2. timeFormat
188
220
  * 3. locale
189
221
  */
190
- _defineProperty(this, "formatTime", time => {
191
- const {
192
- formatDisplayLabel,
193
- timeFormat
194
- } = this.props;
195
- const {
196
- l10n
197
- } = this.getSafeState();
222
+ const formatTime = time => {
198
223
  if (formatDisplayLabel) {
199
224
  return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
200
225
  }
@@ -209,61 +234,15 @@ class TimePicker extends React.Component {
209
234
  return format(date, convertTokens(timeFormat));
210
235
  }
211
236
  return l10n.formatTime(date);
212
- });
213
- _defineProperty(this, "getPlaceholder", () => {
214
- const {
215
- placeholder
216
- } = this.props;
217
- if (placeholder) {
218
- return placeholder;
219
- }
220
- const {
221
- l10n
222
- } = this.getSafeState();
223
- return l10n.formatTime(placeholderDatetime);
224
- });
225
- }
226
- UNSAFE_componentWillReceiveProps(nextProps) {
227
- if (this.props.locale !== nextProps.locale) {
228
- this.setState({
229
- l10n: createLocalizationProvider(nextProps.locale)
230
- });
231
- }
232
- }
233
- getOptions() {
234
- return this.props.times.map(time => {
237
+ };
238
+ const options = times.map(time => {
235
239
  return {
236
- label: this.formatTime(time),
240
+ label: formatTime(time),
237
241
  value: time
238
242
  };
239
243
  });
240
- }
241
- render() {
242
- const {
243
- autoFocus,
244
- hideIcon,
245
- id,
246
- innerProps,
247
- isDisabled,
248
- name,
249
- selectProps,
250
- spacing,
251
- testId,
252
- isInvalid,
253
- timeIsEditable
254
- } = this.props;
255
- const ICON_PADDING = 2;
256
- const {
257
- value = '',
258
- isOpen
259
- } = this.getSafeState();
260
- const {
261
- styles: selectStyles = {},
262
- ...otherSelectProps
263
- } = selectProps;
264
- const SelectComponent = timeIsEditable ? CreatableSelect : Select;
265
244
  const labelAndValue = value && {
266
- label: this.formatTime(value),
245
+ label: formatTime(value),
267
246
  value
268
247
  };
269
248
  const SingleValue = makeSingleValue({
@@ -305,7 +284,7 @@ class TimePicker extends React.Component {
305
284
  "data-testid": testId && `${testId}--input`,
306
285
  onKeyDown: this.onSelectKeyDown
307
286
  }), /*#__PURE__*/React.createElement(SelectComponent, _extends({
308
- appearance: this.props.appearance,
287
+ appearance: appearance,
309
288
  autoFocus: autoFocus,
310
289
  components: selectComponents,
311
290
  instanceId: id,
@@ -317,11 +296,11 @@ class TimePicker extends React.Component {
317
296
  onBlur: this.onBlur,
318
297
  onCreateOption: this.onCreateOption,
319
298
  onChange: this.onChange,
320
- options: this.getOptions(),
299
+ options: options,
321
300
  onFocus: this.onFocus,
322
301
  onMenuOpen: this.onMenuOpen,
323
302
  onMenuClose: this.onMenuClose,
324
- placeholder: this.getPlaceholder(),
303
+ placeholder: placeholder || l10n.formatTime(placeholderDatetime),
325
304
  styles: mergedStyles,
326
305
  value: labelAndValue,
327
306
  spacing: spacing
@@ -29,7 +29,7 @@ import FixedLayer from '../internal/fixed-layer';
29
29
  import { makeSingleValue } from '../internal/single-value';
30
30
  import { convertTokens } from './utils';
31
31
  var packageName = "@atlaskit/datetime-picker";
32
- var packageVersion = "12.8.1";
32
+ var packageVersion = "12.8.2";
33
33
  function getValidDate(iso) {
34
34
  var date = parseISO(iso);
35
35
  return isValid(date) ? {
@@ -406,20 +406,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
406
406
  selectInputValue: _this.props.selectProps.inputValue,
407
407
  value: _this.props.value || _this.props.defaultValue,
408
408
  calendarValue: _this.props.value || _this.props.defaultValue || getShortISOString(new Date()),
409
- l10n: createLocalizationProvider(_this.props.locale)
409
+ l10n: createLocalizationProvider(_this.props.locale),
410
+ locale: _this.props.locale
410
411
  };
411
412
  return _this;
412
413
  }
413
414
  _createClass(DatePicker, [{
414
- key: "UNSAFE_componentWillReceiveProps",
415
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
416
- if (this.props.locale !== nextProps.locale) {
417
- this.setState({
418
- l10n: createLocalizationProvider(nextProps.locale)
419
- });
420
- }
421
- }
422
- }, {
423
415
  key: "render",
424
416
  value: function render() {
425
417
  var _this$props3 = this.props,
@@ -545,6 +537,18 @@ var DatePicker = /*#__PURE__*/function (_Component) {
545
537
  })))
546
538
  );
547
539
  }
540
+ }], [{
541
+ key: "getDerivedStateFromProps",
542
+ value: function getDerivedStateFromProps(nextProps, prevState) {
543
+ if (nextProps.locale !== prevState.locale) {
544
+ return {
545
+ l10n: createLocalizationProvider(nextProps.locale),
546
+ locale: nextProps.locale
547
+ };
548
+ } else {
549
+ return null;
550
+ }
551
+ }
548
552
  }]);
549
553
  return DatePicker;
550
554
  }(Component);
@@ -25,7 +25,7 @@ import DatePicker from './date-picker';
25
25
  import TimePicker from './time-picker';
26
26
  import { convertTokens } from './utils';
27
27
  var packageName = "@atlaskit/datetime-picker";
28
- var packageVersion = "12.8.1";
28
+ var packageVersion = "12.8.2";
29
29
  var isInvalidBorderStyles = css({
30
30
  borderColor: "var(--ds-border-danger, ".concat(R400, ")")
31
31
  });
@@ -29,7 +29,7 @@ import parseTime from '../internal/parse-time';
29
29
  import { makeSingleValue } from '../internal/single-value';
30
30
  import { convertTokens } from './utils';
31
31
  var packageName = "@atlaskit/datetime-picker";
32
- var packageVersion = "12.8.1";
32
+ var packageVersion = "12.8.2";
33
33
  var menuStyles = {
34
34
  /* Need to remove default absolute positioning as that causes issues with position fixed */
35
35
  position: 'static',
@@ -94,8 +94,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
94
94
  isOpen: _this.props.defaultIsOpen,
95
95
  clearingFromIcon: false,
96
96
  value: _this.props.defaultValue,
97
- isFocused: false,
98
- l10n: createLocalizationProvider(_this.props.locale)
97
+ isFocused: false
99
98
  });
100
99
  // All state needs to be accessed via this function so that the state is mapped from props
101
100
  // correctly to allow controlled/uncontrolled usage.
@@ -195,92 +194,72 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
195
194
  });
196
195
  }
197
196
  });
198
- /**
199
- * There are multiple props that can change how the time is formatted.
200
- * The priority of props used is:
201
- * 1. formatDisplayLabel
202
- * 2. timeFormat
203
- * 3. locale
204
- */
205
- _defineProperty(_assertThisInitialized(_this), "formatTime", function (time) {
206
- var _this$props2 = _this.props,
207
- formatDisplayLabel = _this$props2.formatDisplayLabel,
208
- timeFormat = _this$props2.timeFormat;
209
- var _this$getSafeState = _this.getSafeState(),
210
- l10n = _this$getSafeState.l10n;
211
- if (formatDisplayLabel) {
212
- return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
213
- }
214
- var date = parseTime(time);
215
- if (!(date instanceof Date)) {
216
- return '';
217
- }
218
- if (!isValid(date)) {
219
- return time;
220
- }
221
- if (timeFormat) {
222
- return format(date, convertTokens(timeFormat));
223
- }
224
- return l10n.formatTime(date);
225
- });
226
- _defineProperty(_assertThisInitialized(_this), "getPlaceholder", function () {
227
- var placeholder = _this.props.placeholder;
228
- if (placeholder) {
229
- return placeholder;
230
- }
231
- var _this$getSafeState2 = _this.getSafeState(),
232
- l10n = _this$getSafeState2.l10n;
233
- return l10n.formatTime(placeholderDatetime);
234
- });
235
197
  return _this;
236
198
  }
237
199
  _createClass(TimePicker, [{
238
- key: "UNSAFE_componentWillReceiveProps",
239
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
240
- if (this.props.locale !== nextProps.locale) {
241
- this.setState({
242
- l10n: createLocalizationProvider(nextProps.locale)
243
- });
244
- }
245
- }
246
- }, {
247
- key: "getOptions",
248
- value: function getOptions() {
249
- var _this2 = this;
250
- return this.props.times.map(function (time) {
251
- return {
252
- label: _this2.formatTime(time),
253
- value: time
254
- };
255
- });
256
- }
257
- }, {
258
200
  key: "render",
259
201
  value: function render() {
260
- var _this3 = this;
261
- var _this$props3 = this.props,
262
- autoFocus = _this$props3.autoFocus,
263
- hideIcon = _this$props3.hideIcon,
264
- id = _this$props3.id,
265
- innerProps = _this$props3.innerProps,
266
- isDisabled = _this$props3.isDisabled,
267
- name = _this$props3.name,
268
- selectProps = _this$props3.selectProps,
269
- spacing = _this$props3.spacing,
270
- testId = _this$props3.testId,
271
- isInvalid = _this$props3.isInvalid,
272
- timeIsEditable = _this$props3.timeIsEditable;
202
+ var _this2 = this;
203
+ var _this$props2 = this.props,
204
+ appearance = _this$props2.appearance,
205
+ autoFocus = _this$props2.autoFocus,
206
+ formatDisplayLabel = _this$props2.formatDisplayLabel,
207
+ hideIcon = _this$props2.hideIcon,
208
+ id = _this$props2.id,
209
+ innerProps = _this$props2.innerProps,
210
+ isDisabled = _this$props2.isDisabled,
211
+ locale = _this$props2.locale,
212
+ name = _this$props2.name,
213
+ placeholder = _this$props2.placeholder,
214
+ selectProps = _this$props2.selectProps,
215
+ spacing = _this$props2.spacing,
216
+ testId = _this$props2.testId,
217
+ isInvalid = _this$props2.isInvalid,
218
+ timeIsEditable = _this$props2.timeIsEditable,
219
+ timeFormat = _this$props2.timeFormat,
220
+ times = _this$props2.times;
273
221
  var ICON_PADDING = 2;
274
- var _this$getSafeState3 = this.getSafeState(),
275
- _this$getSafeState3$v = _this$getSafeState3.value,
276
- value = _this$getSafeState3$v === void 0 ? '' : _this$getSafeState3$v,
277
- isOpen = _this$getSafeState3.isOpen;
222
+ var l10n = createLocalizationProvider(locale);
223
+ var _this$getSafeState = this.getSafeState(),
224
+ _this$getSafeState$va = _this$getSafeState.value,
225
+ value = _this$getSafeState$va === void 0 ? '' : _this$getSafeState$va,
226
+ isOpen = _this$getSafeState.isOpen;
278
227
  var _selectProps$styles = selectProps.styles,
279
228
  selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
280
229
  otherSelectProps = _objectWithoutProperties(selectProps, _excluded2);
281
230
  var SelectComponent = timeIsEditable ? CreatableSelect : Select;
231
+
232
+ /**
233
+ * There are multiple props that can change how the time is formatted.
234
+ * The priority of props used is:
235
+ * 1. formatDisplayLabel
236
+ * 2. timeFormat
237
+ * 3. locale
238
+ */
239
+ var formatTime = function formatTime(time) {
240
+ if (formatDisplayLabel) {
241
+ return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
242
+ }
243
+ var date = parseTime(time);
244
+ if (!(date instanceof Date)) {
245
+ return '';
246
+ }
247
+ if (!isValid(date)) {
248
+ return time;
249
+ }
250
+ if (timeFormat) {
251
+ return format(date, convertTokens(timeFormat));
252
+ }
253
+ return l10n.formatTime(date);
254
+ };
255
+ var options = times.map(function (time) {
256
+ return {
257
+ label: formatTime(time),
258
+ value: time
259
+ };
260
+ });
282
261
  var labelAndValue = value && {
283
- label: this.formatTime(value),
262
+ label: formatTime(value),
284
263
  value: value
285
264
  };
286
265
  var SingleValue = makeSingleValue({
@@ -302,7 +281,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
302
281
  return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
303
282
  // Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
304
283
  // menu width to the width of our container
305
- width: _this3.containerRef ? _this3.containerRef.getBoundingClientRect().width : 'auto'
284
+ width: _this2.containerRef ? _this2.containerRef.getBoundingClientRect().width : 'auto'
306
285
  });
307
286
  },
308
287
  indicatorsContainer: function indicatorsContainer(base) {
@@ -322,7 +301,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
322
301
  "data-testid": testId && "".concat(testId, "--input"),
323
302
  onKeyDown: this.onSelectKeyDown
324
303
  }), /*#__PURE__*/React.createElement(SelectComponent, _extends({
325
- appearance: this.props.appearance,
304
+ appearance: appearance,
326
305
  autoFocus: autoFocus,
327
306
  components: selectComponents,
328
307
  instanceId: id,
@@ -334,11 +313,11 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
334
313
  onBlur: this.onBlur,
335
314
  onCreateOption: this.onCreateOption,
336
315
  onChange: this.onChange,
337
- options: this.getOptions(),
316
+ options: options,
338
317
  onFocus: this.onFocus,
339
318
  onMenuOpen: this.onMenuOpen,
340
319
  onMenuClose: this.onMenuClose,
341
- placeholder: this.getPlaceholder(),
320
+ placeholder: placeholder || l10n.formatTime(placeholderDatetime),
342
321
  styles: mergedStyles,
343
322
  value: labelAndValue,
344
323
  spacing: spacing
@@ -166,6 +166,7 @@ interface State {
166
166
  calendarValue: string;
167
167
  selectInputValue: string;
168
168
  l10n: LocalizationProvider;
169
+ locale: string;
169
170
  }
170
171
  declare const datePickerDefaultProps: {
171
172
  appearance: Appearance;
@@ -213,7 +214,10 @@ declare class DatePicker extends Component<DatePickerProps, State> {
213
214
  calendarRef: CalendarRef | null;
214
215
  containerRef: HTMLElement | null;
215
216
  constructor(props: any);
216
- UNSAFE_componentWillReceiveProps(nextProps: Readonly<DatePickerProps>): void;
217
+ static getDerivedStateFromProps(nextProps: Readonly<DatePickerProps>, prevState: State): {
218
+ l10n: LocalizationProvider;
219
+ locale: string;
220
+ } | null;
217
221
  getSafeState: () => {
218
222
  inputValue: any;
219
223
  value: string;
@@ -223,6 +227,7 @@ declare class DatePicker extends Component<DatePickerProps, State> {
223
227
  calendarValue: string;
224
228
  selectInputValue: string;
225
229
  l10n: LocalizationProvider;
230
+ locale: string;
226
231
  };
227
232
  isDateDisabled: (date: string) => boolean;
228
233
  onCalendarChange: ({ iso }: {
@@ -1,12 +1,7 @@
1
1
  import React from 'react';
2
2
  import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
3
- import { LocalizationProvider } from '@atlaskit/locale';
4
3
  import { ActionMeta, OptionType, SelectProps, ValueType } from '@atlaskit/select';
5
4
  import { Appearance, Spacing } from '../types';
6
- interface Option {
7
- label: string;
8
- value: string;
9
- }
10
5
  export interface TimePickerBaseProps extends WithAnalyticsEventsProps {
11
6
  /**
12
7
  * Set the appearance of the picker.
@@ -123,7 +118,6 @@ interface State {
123
118
  clearingFromIcon: boolean;
124
119
  value: string;
125
120
  isFocused: boolean;
126
- l10n: LocalizationProvider;
127
121
  }
128
122
  declare const timePickerDefaultProps: {
129
123
  appearance: Appearance;
@@ -174,11 +168,8 @@ declare class TimePicker extends React.Component<TimePickerProps, State> {
174
168
  clearingFromIcon: boolean;
175
169
  value: string;
176
170
  isFocused: boolean;
177
- l10n: LocalizationProvider;
178
171
  };
179
- UNSAFE_componentWillReceiveProps(nextProps: TimePickerProps): void;
180
172
  getSafeState: () => State;
181
- getOptions(): Array<Option>;
182
173
  onChange: (newValue: ValueType<OptionType> | string, action?: ActionMeta<OptionType>) => void;
183
174
  /**
184
175
  * Only allow custom times if timeIsEditable prop is true
@@ -190,15 +181,6 @@ declare class TimePicker extends React.Component<TimePickerProps, State> {
190
181
  onBlur: (event: React.FocusEvent<HTMLElement>) => void;
191
182
  onFocus: (event: React.FocusEvent<HTMLElement>) => void;
192
183
  onSelectKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
193
- /**
194
- * There are multiple props that can change how the time is formatted.
195
- * The priority of props used is:
196
- * 1. formatDisplayLabel
197
- * 2. timeFormat
198
- * 3. locale
199
- */
200
- formatTime: (time: string) => string;
201
- getPlaceholder: () => string;
202
184
  render(): JSX.Element;
203
185
  }
204
186
  export { TimePicker as TimePickerWithoutAnalytics };
@@ -166,6 +166,7 @@ interface State {
166
166
  calendarValue: string;
167
167
  selectInputValue: string;
168
168
  l10n: LocalizationProvider;
169
+ locale: string;
169
170
  }
170
171
  declare const datePickerDefaultProps: {
171
172
  appearance: Appearance;
@@ -213,7 +214,10 @@ declare class DatePicker extends Component<DatePickerProps, State> {
213
214
  calendarRef: CalendarRef | null;
214
215
  containerRef: HTMLElement | null;
215
216
  constructor(props: any);
216
- UNSAFE_componentWillReceiveProps(nextProps: Readonly<DatePickerProps>): void;
217
+ static getDerivedStateFromProps(nextProps: Readonly<DatePickerProps>, prevState: State): {
218
+ l10n: LocalizationProvider;
219
+ locale: string;
220
+ } | null;
217
221
  getSafeState: () => {
218
222
  inputValue: any;
219
223
  value: string;
@@ -223,6 +227,7 @@ declare class DatePicker extends Component<DatePickerProps, State> {
223
227
  calendarValue: string;
224
228
  selectInputValue: string;
225
229
  l10n: LocalizationProvider;
230
+ locale: string;
226
231
  };
227
232
  isDateDisabled: (date: string) => boolean;
228
233
  onCalendarChange: ({ iso }: {
@@ -1,12 +1,7 @@
1
1
  import React from 'react';
2
2
  import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
3
- import { LocalizationProvider } from '@atlaskit/locale';
4
3
  import { ActionMeta, OptionType, SelectProps, ValueType } from '@atlaskit/select';
5
4
  import { Appearance, Spacing } from '../types';
6
- interface Option {
7
- label: string;
8
- value: string;
9
- }
10
5
  export interface TimePickerBaseProps extends WithAnalyticsEventsProps {
11
6
  /**
12
7
  * Set the appearance of the picker.
@@ -123,7 +118,6 @@ interface State {
123
118
  clearingFromIcon: boolean;
124
119
  value: string;
125
120
  isFocused: boolean;
126
- l10n: LocalizationProvider;
127
121
  }
128
122
  declare const timePickerDefaultProps: {
129
123
  appearance: Appearance;
@@ -174,11 +168,8 @@ declare class TimePicker extends React.Component<TimePickerProps, State> {
174
168
  clearingFromIcon: boolean;
175
169
  value: string;
176
170
  isFocused: boolean;
177
- l10n: LocalizationProvider;
178
171
  };
179
- UNSAFE_componentWillReceiveProps(nextProps: TimePickerProps): void;
180
172
  getSafeState: () => State;
181
- getOptions(): Array<Option>;
182
173
  onChange: (newValue: ValueType<OptionType> | string, action?: ActionMeta<OptionType>) => void;
183
174
  /**
184
175
  * Only allow custom times if timeIsEditable prop is true
@@ -190,15 +181,6 @@ declare class TimePicker extends React.Component<TimePickerProps, State> {
190
181
  onBlur: (event: React.FocusEvent<HTMLElement>) => void;
191
182
  onFocus: (event: React.FocusEvent<HTMLElement>) => void;
192
183
  onSelectKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
193
- /**
194
- * There are multiple props that can change how the time is formatted.
195
- * The priority of props used is:
196
- * 1. formatDisplayLabel
197
- * 2. timeFormat
198
- * 3. locale
199
- */
200
- formatTime: (time: string) => string;
201
- getPlaceholder: () => string;
202
184
  render(): JSX.Element;
203
185
  }
204
186
  export { TimePicker as TimePickerWithoutAnalytics };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/datetime-picker",
3
- "version": "12.8.1",
3
+ "version": "12.8.2",
4
4
  "description": "A date time picker allows the user to select an associated date and time.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -41,7 +41,7 @@
41
41
  "@atlaskit/popper": "^5.5.0",
42
42
  "@atlaskit/select": "^16.5.0",
43
43
  "@atlaskit/theme": "^12.6.0",
44
- "@atlaskit/tokens": "^1.18.0",
44
+ "@atlaskit/tokens": "^1.20.0",
45
45
  "@babel/runtime": "^7.0.0",
46
46
  "@emotion/react": "^11.7.1",
47
47
  "date-fns": "^2.17.0",