@atlaskit/datetime-picker 12.3.7 → 12.3.8

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,9 +1,9 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
-
4
3
  /* eslint-disable @repo/internal/react/use-noop */
5
- import React from 'react'; // eslint-disable-next-line no-restricted-imports
4
+ import React from 'react';
6
5
 
6
+ // eslint-disable-next-line no-restricted-imports
7
7
  import { format, isValid } from 'date-fns';
8
8
  import pick from 'lodash/pick';
9
9
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
@@ -15,18 +15,15 @@ import FixedLayer from '../internal/fixed-layer';
15
15
  import parseTime from '../internal/parse-time';
16
16
  import { convertTokens } from './utils';
17
17
  const packageName = "@atlaskit/datetime-picker";
18
- const packageVersion = "12.3.7";
18
+ const packageVersion = "12.3.8";
19
19
  const menuStyles = {
20
20
  /* Need to remove default absolute positioning as that causes issues with position fixed */
21
21
  position: 'static',
22
-
23
22
  /* Need to add overflow to the element with max-height, otherwise causes overflow issues in IE11 */
24
23
  overflowY: 'auto',
25
-
26
24
  /* React-Popper has already offset the menu so we need to reset the margin, otherwise the offset value is doubled */
27
25
  margin: 0
28
26
  };
29
-
30
27
  const FixedLayerMenu = ({
31
28
  selectProps,
32
29
  ...rest
@@ -38,7 +35,6 @@ const FixedLayerMenu = ({
38
35
  })),
39
36
  testId: selectProps.testId
40
37
  });
41
-
42
38
  const timePickerDefaultProps = {
43
39
  appearance: 'default',
44
40
  autoFocus: false,
@@ -58,17 +54,15 @@ const timePickerDefaultProps = {
58
54
  spacing: 'default',
59
55
  times: defaultTimes,
60
56
  timeIsEditable: false,
61
- locale: 'en-US' // Not including a default prop for value as it will
57
+ locale: 'en-US'
58
+ // Not including a default prop for value as it will
62
59
  // Make the component a controlled component
63
-
64
60
  };
65
61
 
66
62
  class TimePicker extends React.Component {
67
63
  constructor(...args) {
68
64
  super(...args);
69
-
70
65
  _defineProperty(this, "containerRef", null);
71
-
72
66
  _defineProperty(this, "state", {
73
67
  isOpen: this.props.defaultIsOpen,
74
68
  clearingFromIcon: false,
@@ -76,30 +70,27 @@ class TimePicker extends React.Component {
76
70
  isFocused: false,
77
71
  l10n: createLocalizationProvider(this.props.locale)
78
72
  });
79
-
80
73
  _defineProperty(this, "getSafeState", () => {
81
- return { ...this.state,
74
+ return {
75
+ ...this.state,
82
76
  ...pick(this.props, ['value', 'isOpen'])
83
77
  };
84
78
  });
85
-
86
79
  _defineProperty(this, "onChange", (newValue, action) => {
87
80
  const rawValue = newValue ? newValue.value || newValue : '';
88
81
  const value = rawValue.toString();
89
82
  let changedState = {
90
83
  value
91
84
  };
92
-
93
85
  if (action && action.action === 'clear') {
94
- changedState = { ...changedState,
86
+ changedState = {
87
+ ...changedState,
95
88
  clearingFromIcon: true
96
89
  };
97
90
  }
98
-
99
91
  this.setState(changedState);
100
92
  this.props.onChange(value);
101
93
  });
102
-
103
94
  _defineProperty(this, "onCreateOption", inputValue => {
104
95
  if (this.props.timeIsEditable) {
105
96
  const {
@@ -107,7 +98,6 @@ class TimePicker extends React.Component {
107
98
  timeFormat
108
99
  } = this.props;
109
100
  let sanitizedInput;
110
-
111
101
  try {
112
102
  sanitizedInput = parseInputValue(inputValue, timeFormat || defaultTimeFormat);
113
103
  } catch (e) {
@@ -123,7 +113,6 @@ class TimePicker extends React.Component {
123
113
  this.onChange(inputValue);
124
114
  }
125
115
  });
126
-
127
116
  _defineProperty(this, "onMenuOpen", () => {
128
117
  // Don't open menu after the user has clicked clear
129
118
  if (this.getSafeState().clearingFromIcon) {
@@ -136,7 +125,6 @@ class TimePicker extends React.Component {
136
125
  });
137
126
  }
138
127
  });
139
-
140
128
  _defineProperty(this, "onMenuClose", () => {
141
129
  // Don't close menu after the user has clicked clear
142
130
  if (this.getSafeState().clearingFromIcon) {
@@ -149,37 +137,32 @@ class TimePicker extends React.Component {
149
137
  });
150
138
  }
151
139
  });
152
-
153
140
  _defineProperty(this, "setContainerRef", ref => {
154
141
  const oldRef = this.containerRef;
155
- this.containerRef = ref; // Cause a re-render if we're getting the container ref for the first time
142
+ this.containerRef = ref;
143
+ // Cause a re-render if we're getting the container ref for the first time
156
144
  // as the layered menu requires it for dimension calculation
157
-
158
145
  if (oldRef == null && ref != null) {
159
146
  this.forceUpdate();
160
147
  }
161
148
  });
162
-
163
149
  _defineProperty(this, "onBlur", event => {
164
150
  this.setState({
165
151
  isFocused: false
166
152
  });
167
153
  this.props.onBlur(event);
168
154
  });
169
-
170
155
  _defineProperty(this, "onFocus", event => {
171
156
  this.setState({
172
157
  isFocused: true
173
158
  });
174
159
  this.props.onFocus(event);
175
160
  });
176
-
177
161
  _defineProperty(this, "onSelectKeyDown", event => {
178
162
  const {
179
163
  key
180
164
  } = event;
181
165
  const keyPressed = key.toLowerCase();
182
-
183
166
  if (this.getSafeState().clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
184
167
  // If being cleared from keyboard, don't change behaviour
185
168
  this.setState({
@@ -187,7 +170,6 @@ class TimePicker extends React.Component {
187
170
  });
188
171
  }
189
172
  });
190
-
191
173
  _defineProperty(this, "formatTime", time => {
192
174
  const {
193
175
  formatDisplayLabel,
@@ -196,53 +178,44 @@ class TimePicker extends React.Component {
196
178
  const {
197
179
  l10n
198
180
  } = this.getSafeState();
199
-
200
181
  if (formatDisplayLabel) {
201
182
  return formatDisplayLabel(time, timeFormat || defaultTimeFormat);
202
183
  }
203
-
204
184
  const date = parseTime(time);
205
-
206
185
  if (!(date instanceof Date)) {
207
186
  return '';
208
187
  }
209
-
210
188
  if (!isValid(date)) {
211
189
  return time;
212
190
  }
213
-
214
191
  if (timeFormat) {
215
192
  return format(date, convertTokens(timeFormat));
216
193
  }
217
-
218
194
  return l10n.formatTime(date);
219
195
  });
220
-
221
196
  _defineProperty(this, "getPlaceholder", () => {
222
197
  const {
223
198
  placeholder
224
199
  } = this.props;
225
-
226
200
  if (placeholder) {
227
201
  return placeholder;
228
202
  }
229
-
230
203
  const {
231
204
  l10n
232
205
  } = this.getSafeState();
233
206
  return l10n.formatTime(placeholderDatetime);
234
207
  });
235
208
  }
236
-
237
209
  UNSAFE_componentWillReceiveProps(nextProps) {
238
210
  if (this.props.locale !== nextProps.locale) {
239
211
  this.setState({
240
212
  l10n: createLocalizationProvider(nextProps.locale)
241
213
  });
242
214
  }
243
- } // All state needs to be accessed via this function so that the state is mapped from props
244
- // correctly to allow controlled/uncontrolled usage.
215
+ }
245
216
 
217
+ // All state needs to be accessed via this function so that the state is mapped from props
218
+ // correctly to allow controlled/uncontrolled usage.
246
219
 
247
220
  getOptions() {
248
221
  return this.props.times.map(time => {
@@ -252,7 +225,6 @@ class TimePicker extends React.Component {
252
225
  };
253
226
  });
254
227
  }
255
-
256
228
  render() {
257
229
  const {
258
230
  autoFocus,
@@ -290,15 +262,18 @@ class TimePicker extends React.Component {
290
262
  };
291
263
  const renderIconContainer = Boolean(!hideIcon && value);
292
264
  const mergedStyles = mergeStyles(selectStyles, {
293
- control: base => ({ ...base
265
+ control: base => ({
266
+ ...base
294
267
  }),
295
- menu: base => ({ ...base,
268
+ menu: base => ({
269
+ ...base,
296
270
  ...menuStyles,
297
271
  // Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
298
272
  // menu width to the width of our container
299
273
  width: this.containerRef ? this.containerRef.getBoundingClientRect().width : 'auto'
300
274
  }),
301
- indicatorsContainer: base => ({ ...base,
275
+ indicatorsContainer: base => ({
276
+ ...base,
302
277
  paddingLeft: renderIconContainer ? ICON_PADDING : 0,
303
278
  paddingRight: renderIconContainer ? gridSize() - ICON_PADDING : 0
304
279
  })
@@ -335,7 +310,8 @@ class TimePicker extends React.Component {
335
310
  placeholder: this.getPlaceholder(),
336
311
  styles: mergedStyles,
337
312
  value: labelAndValue,
338
- spacing: spacing // @ts-ignore caused by prop not part of @atlaskit/select
313
+ spacing: spacing
314
+ // @ts-ignore caused by prop not part of @atlaskit/select
339
315
  ,
340
316
  fixedLayerRef: this.containerRef,
341
317
  isInvalid: isInvalid,
@@ -343,11 +319,8 @@ class TimePicker extends React.Component {
343
319
  }, otherSelectProps)))
344
320
  );
345
321
  }
346
-
347
322
  }
348
-
349
323
  _defineProperty(TimePicker, "defaultProps", timePickerDefaultProps);
350
-
351
324
  export { TimePicker as TimePickerWithoutAnalytics };
352
325
  export default withAnalyticsContext({
353
326
  componentName: 'timePicker',
@@ -1,4 +1,5 @@
1
1
  // https://github.com/date-fns/date-fns-upgrade/blob/master/src/v2/convertTokens/index.ts
2
+
2
3
  const tokensMap = {
3
4
  // 'D MMMM': '',
4
5
  // 'Do MMMM': '',
@@ -52,32 +53,25 @@ const v1tokens = Object.keys(tokensMap).sort().reverse();
52
53
  const tokensRegExp = new RegExp('(\\[[^\\[]*\\])|(\\\\)?' + '(' + v1tokens.join('|') + '|.)', 'g');
53
54
  export function convertTokens(format) {
54
55
  const tokensCaptures = format.match(tokensRegExp);
55
-
56
56
  if (tokensCaptures) {
57
57
  return tokensCaptures.reduce((acc, tokenString, index) => {
58
58
  const v2token = tokensMap[tokenString];
59
-
60
59
  if (!v2token) {
61
60
  const escapedCaptures = tokenString.match(/^\[(.+)\]$/);
62
-
63
61
  if (escapedCaptures) {
64
62
  acc.textBuffer.push(escapedCaptures[1]);
65
63
  } else {
66
64
  acc.textBuffer.push(tokenString);
67
65
  }
68
66
  }
69
-
70
67
  const endOfString = index === tokensCaptures.length - 1;
71
-
72
68
  if (acc.textBuffer.length && (v2token || endOfString)) {
73
69
  acc.formatBuffer.push(`'${acc.textBuffer.join('')}'`);
74
70
  acc.textBuffer = [];
75
71
  }
76
-
77
72
  if (v2token) {
78
73
  acc.formatBuffer.push(v2token);
79
74
  }
80
-
81
75
  return acc;
82
76
  }, {
83
77
  formatBuffer: [],
@@ -5,7 +5,6 @@ import noop from '@atlaskit/ds-lib/noop';
5
5
  import { sizes } from '@atlaskit/icon';
6
6
  import { Manager, Popper, Reference } from '@atlaskit/popper';
7
7
  import { gridSize, layers } from '@atlaskit/theme/constants';
8
-
9
8
  /**
10
9
  * This component renders layered content with fixed positioning.
11
10
  * Scroll is locked outside the layer to prevent the layered content from detaching from the
@@ -14,31 +13,27 @@ import { gridSize, layers } from '@atlaskit/theme/constants';
14
13
  export default class FixedLayer extends React.Component {
15
14
  constructor(...args) {
16
15
  super(...args);
17
-
18
16
  _defineProperty(this, "update", noop);
19
17
  }
20
-
21
18
  componentDidUpdate(prevProps) {
22
19
  if (prevProps.inputValue !== this.props.inputValue) {
23
20
  this.update();
24
21
  }
25
22
  }
26
-
27
23
  render() {
28
24
  const {
29
25
  containerRef,
30
26
  content,
31
27
  testId
32
- } = this.props; // Wait for containerRef callback to cause a re-render
28
+ } = this.props;
33
29
 
30
+ // Wait for containerRef callback to cause a re-render
34
31
  if (!containerRef) {
35
32
  return /*#__PURE__*/React.createElement("div", null);
36
33
  }
37
-
38
34
  const containerRect = containerRef.getBoundingClientRect();
39
35
  return (
40
36
  /*#__PURE__*/
41
-
42
37
  /* Need to wrap layer in a fixed position div so that it will render its content as fixed
43
38
  * We need to set the intial top value to where the container is and zIndex so that it still
44
39
  * applies since we're creating a new stacking context. */
@@ -63,7 +58,8 @@ export default class FixedLayer extends React.Component {
63
58
  this.update = update;
64
59
  return /*#__PURE__*/React.createElement("div", {
65
60
  ref: ref,
66
- style: { ...style,
61
+ style: {
62
+ ...style,
67
63
  zIndex: layers.dialog()
68
64
  },
69
65
  "data-testid": testId && `${testId}--popper--container`
@@ -71,5 +67,4 @@ export default class FixedLayer extends React.Component {
71
67
  }))
72
68
  );
73
69
  }
74
-
75
70
  }
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable @repo/internal/react/require-jsdoc */
2
- export const EmptyComponent = () => null; // This date was chosen to clearly show date and time formats (day > 12)
3
- // e.g. 18/02/1993 vs. 2/18/1993 and 1:00 PM vs 13:00
4
2
 
3
+ export const EmptyComponent = () => null;
4
+
5
+ // This date was chosen to clearly show date and time formats (day > 12)
6
+ // e.g. 18/02/1993 vs. 2/18/1993 and 1:00 PM vs 13:00
5
7
  export const placeholderDatetime = new Date(1993, 1, 18, 13);
6
8
  export const defaultTimes = ['09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00'];
7
9
  export const defaultTimeFormat = 'h:mma';
@@ -16,23 +16,18 @@ export function isValid(timeString) {
16
16
  const time = timeString.trim().match(/(\d+)(?::(\d\d))?\s*(a|p)?/i);
17
17
  const time24hr = timeString.trim().match(/(\d\d)[:.]?(\d\d)/);
18
18
  const num = timeString.replace(/[^0-9]/g, '');
19
-
20
19
  if (!time && !time24hr) {
21
20
  return false;
22
21
  }
23
-
24
22
  if (time && !time[1]) {
25
23
  return false;
26
24
  }
27
-
28
25
  if (num.length > 4) {
29
26
  return false;
30
27
  }
31
-
32
28
  if (num.length === 2 && parseInt(num, 10) > 12) {
33
29
  return false;
34
30
  }
35
-
36
31
  return true;
37
32
  }
38
33
  export function removeSpacer(time) {
@@ -42,37 +37,30 @@ export function formatSemi24(time) {
42
37
  if (time.length === 1) {
43
38
  return `0${time}00`;
44
39
  }
45
-
46
40
  if (time.length === 2) {
47
41
  return `${time}00`;
48
42
  }
49
-
50
43
  if (time.length === 3) {
51
44
  return `0${time}`;
52
45
  }
53
-
54
46
  return time;
55
47
  }
56
48
  export function checkHour(hour, meridiem) {
57
49
  if (hour > '24') {
58
50
  return null;
59
51
  }
60
-
61
52
  if (hour === '12' && meridiem === 'a') {
62
53
  return '00';
63
54
  }
64
-
65
55
  if (hour < '12' && meridiem === 'p') {
66
56
  return map24[hour];
67
57
  }
68
-
69
58
  return hour;
70
59
  }
71
60
  export function checkMinute(minute) {
72
61
  if (minute > '59') {
73
62
  return null;
74
63
  }
75
-
76
64
  return minute;
77
65
  }
78
66
  export function convertTo24hrTime(time) {
@@ -81,11 +69,9 @@ export function convertTo24hrTime(time) {
81
69
  const semi24 = formatSemi24(timeArray[0].trim());
82
70
  const hour = checkHour(semi24.substring(0, 2), meridiem);
83
71
  const minute = checkMinute(semi24.substring(2, 4));
84
-
85
72
  if (!hour || !minute) {
86
73
  return null;
87
74
  }
88
-
89
75
  return {
90
76
  hour: parseInt(hour, 10),
91
77
  minute: parseInt(minute, 10)
@@ -100,17 +86,13 @@ export function assignToDate(time) {
100
86
  }
101
87
  export default function (time) {
102
88
  const trimmedTime = time.toString().trim();
103
-
104
89
  if (!isValid(trimmedTime)) {
105
90
  throw RangeError('invalid time format');
106
91
  }
107
-
108
92
  const time1 = removeSpacer(trimmedTime);
109
93
  const time2 = convertTo24hrTime(time1);
110
-
111
94
  if (!time2) {
112
95
  throw RangeError('invalid time format');
113
96
  }
114
-
115
97
  return assignToDate(time2);
116
98
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/datetime-picker",
3
- "version": "12.3.7",
3
+ "version": "12.3.8",
4
4
  "sideEffects": false
5
5
  }