@atlaskit/datetime-picker 15.12.2 → 15.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/components/date-picker.js +639 -7
  3. package/dist/cjs/components/date-time-picker.js +379 -9
  4. package/dist/cjs/components/time-picker.js +2 -2
  5. package/dist/es2019/components/date-picker.js +570 -5
  6. package/dist/es2019/components/date-time-picker.js +347 -6
  7. package/dist/es2019/components/time-picker.js +2 -2
  8. package/dist/esm/components/date-picker.js +637 -7
  9. package/dist/esm/components/date-time-picker.js +375 -8
  10. package/dist/esm/components/time-picker.js +2 -2
  11. package/dist/types/components/date-picker.d.ts +18 -19
  12. package/dist/types/components/date-time-picker.d.ts +14 -31
  13. package/dist/types-ts4.5/components/date-picker.d.ts +18 -19
  14. package/dist/types-ts4.5/components/date-time-picker.d.ts +14 -31
  15. package/package.json +5 -8
  16. package/dist/cjs/components/date-picker-class.js +0 -685
  17. package/dist/cjs/components/date-picker-fc.js +0 -639
  18. package/dist/cjs/components/date-time-picker-class.js +0 -436
  19. package/dist/cjs/components/date-time-picker-fc.js +0 -394
  20. package/dist/cjs/internal/ff-component.js +0 -58
  21. package/dist/es2019/components/date-picker-class.js +0 -649
  22. package/dist/es2019/components/date-picker-fc.js +0 -563
  23. package/dist/es2019/components/date-time-picker-class.js +0 -400
  24. package/dist/es2019/components/date-time-picker-fc.js +0 -354
  25. package/dist/es2019/internal/ff-component.js +0 -47
  26. package/dist/esm/components/date-picker-class.js +0 -680
  27. package/dist/esm/components/date-picker-fc.js +0 -630
  28. package/dist/esm/components/date-time-picker-class.js +0 -434
  29. package/dist/esm/components/date-time-picker-fc.js +0 -384
  30. package/dist/esm/internal/ff-component.js +0 -49
  31. package/dist/types/components/date-picker-class.d.ts +0 -110
  32. package/dist/types/components/date-picker-fc.d.ts +0 -20
  33. package/dist/types/components/date-time-picker-class.d.ts +0 -85
  34. package/dist/types/components/date-time-picker-fc.d.ts +0 -15
  35. package/dist/types/internal/ff-component.d.ts +0 -34
  36. package/dist/types-ts4.5/components/date-picker-class.d.ts +0 -110
  37. package/dist/types-ts4.5/components/date-picker-fc.d.ts +0 -20
  38. package/dist/types-ts4.5/components/date-time-picker-class.d.ts +0 -85
  39. package/dist/types-ts4.5/components/date-time-picker-fc.d.ts +0 -15
  40. package/dist/types-ts4.5/internal/ff-component.d.ts +0 -34
@@ -1,354 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import React, { forwardRef, useCallback, useEffect, useState } from 'react';
3
- import { format, isValid, parseISO } from 'date-fns';
4
- import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
5
- import { IconButton } from '@atlaskit/button/new';
6
- import SelectClearIcon from '@atlaskit/icon/utility/migration/cross-circle--select-clear';
7
- import { fg } from '@atlaskit/platform-feature-flags';
8
- import { Box, Inline, xcss } from '@atlaskit/primitives';
9
- import { mergeStyles } from '@atlaskit/select';
10
- import { formatDateTimeZoneIntoIso } from '../internal';
11
- import { DateTimePickerContainer } from '../internal/date-time-picker-container';
12
- import { componentWithCondition } from '../internal/ff-component';
13
- import { convertTokens } from '../internal/parse-tokens';
14
- import DatePickerOld from './date-picker-class';
15
- import DatePickerNew from './date-picker-fc';
16
- import TimePicker from './time-picker';
17
- const DatePicker = componentWithCondition(
18
- // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
19
- () => fg('dst-date-picker-use-functional-component'), DatePickerNew, DatePickerOld);
20
- const packageName = "@atlaskit/datetime-picker";
21
- const packageVersion = "15.12.2";
22
- const analyticsAttributes = {
23
- componentName: 'dateTimePicker',
24
- packageName,
25
- packageVersion
26
- };
27
-
28
- // Make DatePicker 50% the width of DateTimePicker
29
- // If rendering an icon container, shrink the TimePicker
30
- const datePickerContainerStyles = xcss({
31
- flexBasis: '50%',
32
- flexGrow: 1,
33
- flexShrink: 0
34
- });
35
- const timePickerContainerStyles = xcss({
36
- flexBasis: '50%',
37
- flexGrow: 1
38
- });
39
- const iconContainerStyles = xcss({
40
- display: 'flex',
41
- alignItems: 'center',
42
- flexBasis: 'inherit'
43
- });
44
-
45
- // react-select overrides (via @atlaskit/select).
46
- const styles = {
47
- control: style => ({
48
- ...style,
49
- backgroundColor: 'transparent',
50
- border: 2,
51
- borderRadius: 0,
52
- paddingLeft: 0,
53
- ':hover': {
54
- backgroundColor: 'transparent',
55
- cursor: 'inherit'
56
- }
57
- })
58
- };
59
- export const datePickerDefaultAriaLabel = 'Date';
60
- export const timePickerDefaultAriaLabel = 'Time';
61
-
62
- /**
63
- * __Date time picker__
64
- *
65
- * A date time picker allows the user to select an associated date and time.
66
- *
67
- * - [Examples](https://atlassian.design/components/datetime-picker/examples)
68
- * - [Code](https://atlassian.design/components/datetime-picker/code)
69
- * - [Usage](https://atlassian.design/components/datetime-picker/usage)
70
- */
71
- const DateTimePicker = /*#__PURE__*/forwardRef(({
72
- 'aria-describedby': ariaDescribedBy,
73
- appearance = 'default',
74
- autoFocus = false,
75
- clearControlLabel = 'clear',
76
- datePickerProps: datePickerPropsWithSelectProps = {},
77
- defaultValue = '',
78
- id = '',
79
- innerProps = {},
80
- isDisabled = false,
81
- isInvalid = false,
82
- isRequired = false,
83
- name = '',
84
- // These disables are here for proper typing when used as defaults. They
85
- // should *not* use the `noop` function.
86
- /* eslint-disable @repo/internal/react/use-noop */
87
- onBlur = _event => {},
88
- onChange: onChangeProp = _value => {},
89
- onFocus = _event => {},
90
- /* eslint-enable @repo/internal/react/use-noop */
91
- parseValue: providedParseValue,
92
- spacing = 'default',
93
- locale = 'en-US',
94
- testId,
95
- timePickerProps: timePickerPropsWithSelectProps = {},
96
- value: providedValue
97
- }, ref) => {
98
- const [dateValue, setDateValue] = useState((datePickerPropsWithSelectProps === null || datePickerPropsWithSelectProps === void 0 ? void 0 : datePickerPropsWithSelectProps.defaultValue) || '');
99
- const [isFocused, setIsFocused] = useState(false);
100
- const [timeValue, setTimeValue] = useState((timePickerPropsWithSelectProps === null || timePickerPropsWithSelectProps === void 0 ? void 0 : timePickerPropsWithSelectProps.defaultValue) || '');
101
- const [value, setValue] = useState(defaultValue || '');
102
- const [zoneValue, setZoneValue] = useState('');
103
- useEffect(() => {
104
- if (providedValue) {
105
- setValue(providedValue);
106
- }
107
- }, [providedValue]);
108
- const parseValue = useCallback((value, providedDateValue, providedTimeValue, providedZoneValue) => {
109
- if (providedParseValue) {
110
- const parsedFromFn = providedParseValue(value, providedDateValue, providedTimeValue, providedZoneValue);
111
- // This handles cases found in Jira where the parse function actually does
112
- // nothing and returns undefined. The previous `getSafeState` function
113
- // just spread the values over the state, but if it returned `undefined`,
114
- // it would just rely on the previous state values. Considering this is
115
- // what is input to this function anyway, this is a safe way to handle
116
- // this, colocate the behavior, and not rely on `getSafeState`.
117
- return parsedFromFn || {
118
- dateValue: providedDateValue,
119
- timeValue: providedTimeValue,
120
- zoneValue: providedZoneValue
121
- };
122
- }
123
- const parsed = parseISO(value);
124
- return isValid(parsed) ? {
125
- dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
126
- timeValue: format(parsed, convertTokens('HH:mm')),
127
- zoneValue: format(parsed, convertTokens('ZZ'))
128
- } : {
129
- dateValue,
130
- timeValue,
131
- zoneValue
132
- };
133
- }, [providedParseValue, dateValue, timeValue, zoneValue]);
134
- useEffect(() => {
135
- const parsedValues = parseValue(value, dateValue, timeValue, zoneValue);
136
- setDateValue(parsedValues.dateValue);
137
- setTimeValue(parsedValues.timeValue);
138
- setZoneValue(parsedValues.zoneValue);
139
- }, [value, dateValue, timeValue, zoneValue, parseValue]);
140
- const onDateBlur = event => {
141
- setIsFocused(false);
142
- onBlur(event);
143
- if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onBlur) {
144
- datePickerPropsWithSelectProps.onBlur(event);
145
- }
146
- };
147
- const onTimeBlur = event => {
148
- setIsFocused(false);
149
- onBlur(event);
150
- if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onBlur) {
151
- timePickerPropsWithSelectProps.onBlur(event);
152
- }
153
- };
154
- const onDateFocus = event => {
155
- setIsFocused(false);
156
- onFocus(event);
157
- if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onFocus) {
158
- datePickerPropsWithSelectProps.onFocus(event);
159
- }
160
- };
161
- const onTimeFocus = event => {
162
- setIsFocused(false);
163
- onFocus(event);
164
- if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onFocus) {
165
- timePickerPropsWithSelectProps.onFocus(event);
166
- }
167
- };
168
- const onDateChange = dateValue => {
169
- const parsedValues = parseValue(value, dateValue, timeValue, zoneValue);
170
- onValueChange({
171
- providedDateValue: dateValue,
172
- providedTimeValue: parsedValues.timeValue,
173
- providedZoneValue: parsedValues.zoneValue
174
- });
175
- if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
176
- datePickerPropsWithSelectProps.onChange(dateValue);
177
- }
178
- };
179
- const onTimeChange = timeValue => {
180
- const parsedValues = parseValue(value, dateValue, timeValue, zoneValue);
181
- onValueChange({
182
- providedDateValue: parsedValues.dateValue,
183
- providedTimeValue: timeValue,
184
- providedZoneValue: parsedValues.zoneValue
185
- });
186
- if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
187
- timePickerPropsWithSelectProps.onChange(timeValue);
188
- }
189
- };
190
- const onClear = () => {
191
- const parsedValues = parseValue(value, dateValue, timeValue, zoneValue);
192
- onValueChange({
193
- providedDateValue: '',
194
- providedTimeValue: '',
195
- providedZoneValue: parsedValues.zoneValue
196
- });
197
- if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
198
- datePickerPropsWithSelectProps.onChange('');
199
- }
200
- if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
201
- timePickerPropsWithSelectProps.onChange('');
202
- }
203
- };
204
- const onChangePropWithAnalytics = usePlatformLeafEventHandler({
205
- fn: onChangeProp,
206
- action: 'selectedDate',
207
- actionSubject: 'datePicker',
208
- ...analyticsAttributes
209
- });
210
- const onValueChange = ({
211
- providedDateValue,
212
- providedTimeValue,
213
- providedZoneValue
214
- }) => {
215
- setDateValue(providedDateValue);
216
- setTimeValue(providedTimeValue);
217
- setZoneValue(providedZoneValue);
218
- if (providedDateValue && providedTimeValue) {
219
- const value = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, providedZoneValue);
220
- const {
221
- zoneValue: parsedZone
222
- } = parseValue(value, providedDateValue, providedTimeValue, providedZoneValue);
223
- const valueWithValidZone = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, parsedZone);
224
- setValue(valueWithValidZone);
225
- onChangePropWithAnalytics(valueWithValidZone);
226
- // If the date or time value was cleared when there is an existing datetime value, then clear the value.
227
- } else if (value) {
228
- setValue('');
229
- onChangePropWithAnalytics('');
230
- }
231
- };
232
- const {
233
- selectProps: datePickerSelectProps,
234
- ...datePickerProps
235
- } = datePickerPropsWithSelectProps;
236
- const datePickerAriaDescribedBy = datePickerProps['aria-describedby'] || ariaDescribedBy;
237
- const datePickerLabel = datePickerProps.label || datePickerDefaultAriaLabel;
238
- const mergedDatePickerSelectProps = {
239
- ...datePickerSelectProps,
240
- styles: mergeStyles(styles, datePickerSelectProps === null || datePickerSelectProps === void 0 ? void 0 : datePickerSelectProps.styles)
241
- };
242
- const {
243
- selectProps: timePickerSelectProps,
244
- ...timePickerProps
245
- } = timePickerPropsWithSelectProps;
246
- const timePickerAriaDescribedBy = timePickerProps['aria-describedby'] || ariaDescribedBy;
247
- const timePickerLabel = timePickerProps.label || timePickerDefaultAriaLabel;
248
- const mergedTimePickerSelectProps = {
249
- ...timePickerSelectProps,
250
- styles: mergeStyles(styles, timePickerSelectProps === null || timePickerSelectProps === void 0 ? void 0 : timePickerSelectProps.styles)
251
- };
252
-
253
- // Render DateTimePicker's IconContainer when a value has been filled
254
- // Don't use Date or TimePicker's because they can't be customised
255
- const isClearable = Boolean(dateValue || timeValue);
256
- return /*#__PURE__*/React.createElement(DateTimePickerContainer, {
257
- appearance: appearance,
258
- isDisabled: isDisabled,
259
- isFocused: isFocused,
260
- isInvalid: isInvalid,
261
- testId: testId,
262
- innerProps: innerProps
263
- }, /*#__PURE__*/React.createElement("input", {
264
- name: name,
265
- type: "hidden",
266
- value: value,
267
- "data-testid": testId && `${testId}--input`
268
- }), /*#__PURE__*/React.createElement(Box, {
269
- xcss: datePickerContainerStyles
270
- }, /*#__PURE__*/React.createElement(DatePicker, {
271
- appearance: appearance,
272
- "aria-describedby": datePickerAriaDescribedBy,
273
- autoFocus: datePickerProps.autoFocus || autoFocus,
274
- dateFormat: datePickerProps.dateFormat,
275
- defaultIsOpen: datePickerProps.defaultIsOpen,
276
- defaultValue: datePickerProps.defaultValue,
277
- disabled: datePickerProps.disabled,
278
- disabledDateFilter: datePickerProps.disabledDateFilter,
279
- formatDisplayLabel: datePickerProps.formatDisplayLabel,
280
- hideIcon: datePickerProps.hideIcon || true,
281
- icon: datePickerProps.icon,
282
- id: datePickerProps.id || id,
283
- innerProps: datePickerProps.innerProps,
284
- inputLabel: datePickerProps.inputLabel,
285
- inputLabelId: datePickerProps.inputLabelId,
286
- isDisabled: datePickerProps.isDisabled || isDisabled,
287
- isInvalid: datePickerProps.isInvalid || isInvalid,
288
- isOpen: datePickerProps.isOpen,
289
- isRequired: datePickerProps.isRequired || isRequired,
290
- label: datePickerLabel,
291
- locale: datePickerProps.locale || locale,
292
- maxDate: datePickerProps.maxDate,
293
- minDate: datePickerProps.minDate,
294
- name: datePickerProps.name,
295
- nextMonthLabel: datePickerProps.nextMonthLabel,
296
- onBlur: onDateBlur,
297
- onChange: onDateChange,
298
- onFocus: onDateFocus,
299
- openCalendarLabel: datePickerProps.openCalendarLabel,
300
- parseInputValue: datePickerProps.parseInputValue,
301
- placeholder: datePickerProps.placeholder,
302
- previousMonthLabel: datePickerProps.previousMonthLabel,
303
- selectProps: mergedDatePickerSelectProps,
304
- shouldShowCalendarButton: datePickerProps.shouldShowCalendarButton,
305
- spacing: datePickerProps.spacing || spacing,
306
- testId: testId && `${testId}--datepicker` || datePickerProps.testId,
307
- value: dateValue,
308
- weekStartDay: datePickerProps.weekStartDay
309
- })), /*#__PURE__*/React.createElement(Box, {
310
- xcss: timePickerContainerStyles
311
- }, /*#__PURE__*/React.createElement(TimePicker, {
312
- appearance: timePickerProps.appearance || appearance,
313
- "aria-describedby": timePickerAriaDescribedBy,
314
- autoFocus: timePickerProps.autoFocus,
315
- defaultIsOpen: timePickerProps.defaultIsOpen,
316
- defaultValue: timePickerProps.defaultValue,
317
- formatDisplayLabel: timePickerProps.formatDisplayLabel,
318
- hideIcon: timePickerProps.hideIcon || true,
319
- id: timePickerProps.id,
320
- innerProps: timePickerProps.innerProps,
321
- isDisabled: timePickerProps.isDisabled || isDisabled,
322
- isInvalid: timePickerProps.isInvalid || isInvalid,
323
- isOpen: timePickerProps.isOpen,
324
- isRequired: timePickerProps.isRequired || isRequired,
325
- label: timePickerLabel,
326
- locale: timePickerProps.locale || locale,
327
- name: timePickerProps.name,
328
- onBlur: onTimeBlur,
329
- onChange: onTimeChange,
330
- onFocus: onTimeFocus,
331
- parseInputValue: timePickerProps.parseInputValue,
332
- placeholder: timePickerProps.placeholder,
333
- selectProps: mergedTimePickerSelectProps,
334
- spacing: timePickerProps.spacing || spacing,
335
- testId: timePickerProps.testId || testId && `${testId}--timepicker`,
336
- timeFormat: timePickerProps.timeFormat,
337
- timeIsEditable: timePickerProps.timeIsEditable,
338
- times: timePickerProps.times,
339
- value: timeValue
340
- })), isClearable && !isDisabled ? /*#__PURE__*/React.createElement(Inline, {
341
- xcss: iconContainerStyles
342
- }, /*#__PURE__*/React.createElement(IconButton, {
343
- appearance: "subtle",
344
- label: clearControlLabel,
345
- icon: iconProps => /*#__PURE__*/React.createElement(SelectClearIcon, _extends({}, iconProps, {
346
- color: "var(--ds-text-subtlest, #626F86)",
347
- LEGACY_size: "small"
348
- })),
349
- onClick: onClear,
350
- testId: testId && `${testId}--icon--container`,
351
- tabIndex: -1
352
- })) : null);
353
- });
354
- export default DateTimePicker;
@@ -1,47 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import React, { forwardRef } from 'react';
3
-
4
- /**
5
- * Gets all available ref types from two prop sets and returns
6
- * them in a ref prop
7
- *
8
- * @example
9
- * ```
10
- * type P1 = { ref: Ref(HTMLDivElement), ... };
11
- * type P2 = { ref: Ref(HTMLSpanElement), ... };
12
- *
13
- * GetRefAttributes(P1, P2) // {ref: Ref(HTMLDivElement | HTMLSpanElement)}
14
- * ```
15
- */
16
-
17
- /**
18
- * Returns one of components depending on a boolean condition.
19
- * The result component will be a union of the two props and
20
- * an or on both ref types.
21
- *
22
- * @example
23
- * ```
24
- * const Component = componentWithCondition(
25
- * isBooleanConditionMet,
26
- * ComponentWithConditionMet,
27
- * ComponentWithConditionNotMet,
28
- * );
29
- *
30
- * @param condition Function returning boolean value
31
- * @param componentTrue Component that will be returned if conditionGetter is "true"
32
- * @param componentFalse Component that will be returned if conditionGetter is "false"
33
- * @returns Component Depending on a Condition result
34
- */
35
- export function componentWithCondition(condition, ComponentTrue, ComponentFalse) {
36
- const ComponentWithCondition = /*#__PURE__*/forwardRef((props, ref) => condition() ? /*#__PURE__*/React.createElement(ComponentTrue, _extends({}, props, {
37
- ref: ref
38
- })) : /*#__PURE__*/React.createElement(ComponentFalse, _extends({}, props, {
39
- ref: ref
40
- })));
41
- if (ComponentTrue.name !== '') {
42
- ComponentWithCondition.displayName = `ComponentWithCondition[${condition.name}]`;
43
- }
44
-
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
46
- return ComponentWithCondition;
47
- }