@atlaskit/datetime-picker 17.8.8 → 17.9.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 (38) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/components/date-picker.js +1 -1
  3. package/dist/cjs/components/date-time-picker.js +502 -9
  4. package/dist/cjs/components/time-picker.js +1 -1
  5. package/dist/cjs/internal/date-time-picker-container.compiled.css +1 -1
  6. package/dist/cjs/internal/date-time-picker-container.js +1 -1
  7. package/dist/cjs/internal/get-parsed-iso.js +2 -2
  8. package/dist/es2019/components/date-picker.js +1 -1
  9. package/dist/es2019/components/date-time-picker.js +485 -6
  10. package/dist/es2019/components/time-picker.js +1 -1
  11. package/dist/es2019/internal/date-time-picker-container.compiled.css +1 -1
  12. package/dist/es2019/internal/date-time-picker-container.js +1 -1
  13. package/dist/es2019/internal/get-parsed-iso.js +2 -2
  14. package/dist/esm/components/date-picker.js +1 -1
  15. package/dist/esm/components/date-time-picker.js +502 -8
  16. package/dist/esm/components/time-picker.js +1 -1
  17. package/dist/esm/internal/date-time-picker-container.compiled.css +1 -1
  18. package/dist/esm/internal/date-time-picker-container.js +1 -1
  19. package/dist/esm/internal/get-parsed-iso.js +2 -2
  20. package/dist/types/components/date-time-picker.d.ts +14 -30
  21. package/dist/types-ts4.5/components/date-time-picker.d.ts +14 -30
  22. package/package.json +6 -12
  23. package/dist/cjs/components/date-time-picker-class.compiled.css +0 -19
  24. package/dist/cjs/components/date-time-picker-class.js +0 -408
  25. package/dist/cjs/components/date-time-picker-fc.js +0 -484
  26. package/dist/es2019/components/date-time-picker-class.compiled.css +0 -19
  27. package/dist/es2019/components/date-time-picker-class.js +0 -373
  28. package/dist/es2019/components/date-time-picker-fc.js +0 -461
  29. package/dist/esm/components/date-time-picker-class.compiled.css +0 -19
  30. package/dist/esm/components/date-time-picker-class.js +0 -405
  31. package/dist/esm/components/date-time-picker-fc.js +0 -478
  32. package/dist/types/components/date-time-picker-class.d.ts +0 -82
  33. package/dist/types/components/date-time-picker-fc.d.ts +0 -13
  34. package/dist/types-ts4.5/components/date-time-picker-class.d.ts +0 -82
  35. package/dist/types-ts4.5/components/date-time-picker-fc.d.ts +0 -13
  36. /package/dist/cjs/components/{date-time-picker-fc.compiled.css → date-time-picker.compiled.css} +0 -0
  37. /package/dist/es2019/components/{date-time-picker-fc.compiled.css → date-time-picker.compiled.css} +0 -0
  38. /package/dist/esm/components/{date-time-picker-fc.compiled.css → date-time-picker.compiled.css} +0 -0
@@ -1,373 +0,0 @@
1
- /* date-time-picker-class.tsx generated by @compiled/babel-plugin v0.39.1 */
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import "./date-time-picker-class.compiled.css";
4
- import { ax, ix } from "@compiled/react/runtime";
5
- /// <reference types="node" />
6
-
7
- import React from 'react';
8
- // oxlint-disable-next-line @atlassian/no-restricted-imports
9
- import { format, isValid, parseISO } from 'date-fns';
10
- import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
11
- import SelectClearIcon from '@atlaskit/icon/core/cross-circle';
12
- import { mergeStyles } from '@atlaskit/select';
13
- import { DateTimePickerContainer } from '../internal/date-time-picker-container';
14
- import { formatDateTimeZoneIntoIso } from '../internal/format-date-time-zone-into-iso';
15
- import { convertTokens } from '../internal/parse-tokens';
16
- import DatePicker from './date-picker';
17
- import TimePicker from './time-picker';
18
- const packageName = "@atlaskit/datetime-picker";
19
- const packageVersion = "17.8.7";
20
- const compiledStyles = {
21
- datePickerContainerStyles: "_i0dl1ssb _16jlkb7n _1o9zidpf",
22
- timePickerContainerStyles: "_i0dl1ssb _16jlkb7n",
23
- iconContainerStyles: "_19itglyw _v564vrg3 _1e0c1txw _4cvr1h6o _i0dl1kw7 _bfhk1kw7 _syaz1rpy _6rthe4h9 _1pfhe4h9 _12l2e4h9 _ahbqe4h9 _85i512x7 _1q5112x7 _y4tiu2gc _bozg1b66 _30l3azsu"
24
- };
25
-
26
- // react-select overrides (via @atlaskit/select).
27
- const styles = {
28
- control: style => ({
29
- ...style,
30
- backgroundColor: 'transparent',
31
- border: 2,
32
- borderRadius: 0,
33
- paddingLeft: 0,
34
- ':hover': {
35
- backgroundColor: 'transparent',
36
- cursor: 'inherit'
37
- }
38
- })
39
- };
40
- const dateTimePickerDefaultProps = {
41
- // These disables are here for proper typing when used as defaults. They
42
- // should *not* use the `noop` function.
43
- /* eslint-disable @repo/internal/react/use-noop */
44
- onBlur: _event => {},
45
- onChange: _value => {},
46
- onFocus: _event => {}
47
- /* eslint-enable @repo/internal/react/use-noop */
48
- // Not including a default prop for value as it will
49
- // Make the component a controlled component
50
- };
51
-
52
- // eslint-disable-next-line @repo/internal/react/no-class-components
53
- class DateTimePickerComponent extends React.Component {
54
- constructor(...args) {
55
- var _this$props$datePicke, _this$props$timePicke;
56
- super(...args);
57
- _defineProperty(this, "state", {
58
- dateValue: ((_this$props$datePicke = this.props.datePickerProps) === null || _this$props$datePicke === void 0 ? void 0 : _this$props$datePicke.defaultValue) || '',
59
- isFocused: false,
60
- timeValue: ((_this$props$timePicke = this.props.timePickerProps) === null || _this$props$timePicke === void 0 ? void 0 : _this$props$timePicke.defaultValue) || '',
61
- value: this.props.defaultValue || '',
62
- zoneValue: ''
63
- });
64
- // All state needs to be accessed via this function so that the state is mapped from props
65
- // correctly to allow controlled/uncontrolled usage.
66
- _defineProperty(this, "getParsedValues", () => this.parseValue(this.getValue(), this.state.dateValue, this.state.timeValue, this.state.zoneValue));
67
- _defineProperty(this, "getValue", () => {
68
- var _this$props$value;
69
- return (_this$props$value = this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : this.state.value;
70
- });
71
- _defineProperty(this, "onDateBlur", event => {
72
- var _this$props$onBlur, _this$props, _this$props$datePicke2;
73
- this.setState({
74
- isFocused: false
75
- });
76
- (_this$props$onBlur = (_this$props = this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props, event);
77
- if ((_this$props$datePicke2 = this.props.datePickerProps) !== null && _this$props$datePicke2 !== void 0 && _this$props$datePicke2.onBlur) {
78
- this.props.datePickerProps.onBlur(event);
79
- }
80
- });
81
- _defineProperty(this, "onTimeBlur", event => {
82
- var _this$props$onBlur2, _this$props2, _this$props$timePicke2;
83
- this.setState({
84
- isFocused: false
85
- });
86
- (_this$props$onBlur2 = (_this$props2 = this.props).onBlur) === null || _this$props$onBlur2 === void 0 ? void 0 : _this$props$onBlur2.call(_this$props2, event);
87
- if ((_this$props$timePicke2 = this.props.timePickerProps) !== null && _this$props$timePicke2 !== void 0 && _this$props$timePicke2.onBlur) {
88
- this.props.timePickerProps.onBlur(event);
89
- }
90
- });
91
- _defineProperty(this, "onDateFocus", event => {
92
- var _this$props$onFocus, _this$props3, _this$props$datePicke3;
93
- this.setState({
94
- isFocused: true
95
- });
96
- (_this$props$onFocus = (_this$props3 = this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props3, event);
97
- if ((_this$props$datePicke3 = this.props.datePickerProps) !== null && _this$props$datePicke3 !== void 0 && _this$props$datePicke3.onFocus) {
98
- this.props.datePickerProps.onFocus(event);
99
- }
100
- });
101
- _defineProperty(this, "onTimeFocus", event => {
102
- var _this$props$onFocus2, _this$props4, _this$props$timePicke3;
103
- this.setState({
104
- isFocused: true
105
- });
106
- (_this$props$onFocus2 = (_this$props4 = this.props).onFocus) === null || _this$props$onFocus2 === void 0 ? void 0 : _this$props$onFocus2.call(_this$props4, event);
107
- if ((_this$props$timePicke3 = this.props.timePickerProps) !== null && _this$props$timePicke3 !== void 0 && _this$props$timePicke3.onFocus) {
108
- this.props.timePickerProps.onFocus(event);
109
- }
110
- });
111
- _defineProperty(this, "onDateChange", dateValue => {
112
- var _this$props$datePicke4;
113
- const parsedValues = this.getParsedValues();
114
- this.onValueChange({
115
- dateValue,
116
- timeValue: parsedValues.timeValue,
117
- zoneValue: parsedValues.zoneValue
118
- });
119
- if ((_this$props$datePicke4 = this.props.datePickerProps) !== null && _this$props$datePicke4 !== void 0 && _this$props$datePicke4.onChange) {
120
- this.props.datePickerProps.onChange(dateValue);
121
- }
122
- });
123
- _defineProperty(this, "onTimeChange", timeValue => {
124
- var _this$props$timePicke4;
125
- const parsedValues = this.getParsedValues();
126
- this.onValueChange({
127
- dateValue: parsedValues.dateValue,
128
- timeValue,
129
- zoneValue: parsedValues.zoneValue
130
- });
131
- if ((_this$props$timePicke4 = this.props.timePickerProps) !== null && _this$props$timePicke4 !== void 0 && _this$props$timePicke4.onChange) {
132
- this.props.timePickerProps.onChange(timeValue);
133
- }
134
- });
135
- _defineProperty(this, "onClear", () => {
136
- var _this$props$datePicke5, _this$props$timePicke5;
137
- const parsedValues = this.getParsedValues();
138
- this.onValueChange({
139
- dateValue: '',
140
- timeValue: '',
141
- zoneValue: parsedValues.zoneValue
142
- });
143
- if ((_this$props$datePicke5 = this.props.datePickerProps) !== null && _this$props$datePicke5 !== void 0 && _this$props$datePicke5.onChange) {
144
- this.props.datePickerProps.onChange('');
145
- }
146
- if ((_this$props$timePicke5 = this.props.timePickerProps) !== null && _this$props$timePicke5 !== void 0 && _this$props$timePicke5.onChange) {
147
- this.props.timePickerProps.onChange('');
148
- }
149
- });
150
- }
151
- parseValue(value, dateValue, timeValue, zoneValue) {
152
- if (this.props.parseValue) {
153
- const parsedFromFn = this.props.parseValue(value, dateValue, timeValue, zoneValue);
154
- // This handles cases found in Jira where the parse function actually does
155
- // nothing and returns undefined. The previous `getSafeState` function
156
- // just spread the values over the state, but if it returned `undefined`,
157
- // it would just rely on the previous state values. Considering this is
158
- // what is input to this function anyway, this is a safe way to handle
159
- // this, colocate the behavior, and not rely on `getSafeState`.
160
- return parsedFromFn || {
161
- dateValue,
162
- timeValue,
163
- zoneValue
164
- };
165
- }
166
- const parsed = parseISO(value);
167
- return isValid(parsed) ? {
168
- dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
169
- timeValue: format(parsed, convertTokens('HH:mm')),
170
- zoneValue: format(parsed, convertTokens('ZZ'))
171
- } : {
172
- dateValue,
173
- timeValue,
174
- zoneValue
175
- };
176
- }
177
- onValueChange({
178
- dateValue,
179
- timeValue,
180
- zoneValue
181
- }) {
182
- this.setState({
183
- dateValue,
184
- timeValue,
185
- zoneValue
186
- });
187
- if (dateValue && timeValue) {
188
- var _this$props$onChange, _this$props5;
189
- const value = formatDateTimeZoneIntoIso(dateValue, timeValue, zoneValue);
190
- const {
191
- zoneValue: parsedZone
192
- } = this.parseValue(value, dateValue, timeValue, zoneValue);
193
- const valueWithValidZone = formatDateTimeZoneIntoIso(dateValue, timeValue, parsedZone);
194
- this.setState({
195
- value: valueWithValidZone
196
- });
197
- (_this$props$onChange = (_this$props5 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props5, valueWithValidZone);
198
- // If the date or time value was cleared when there is an existing datetime value, then clear the value.
199
- } else if (this.getValue()) {
200
- var _this$props$onChange2, _this$props6;
201
- this.setState({
202
- value: ''
203
- });
204
- (_this$props$onChange2 = (_this$props6 = this.props).onChange) === null || _this$props$onChange2 === void 0 ? void 0 : _this$props$onChange2.call(_this$props6, '');
205
- }
206
- }
207
- render() {
208
- const {
209
- 'aria-describedby': ariaDescribedBy,
210
- appearance = 'default',
211
- autoFocus = false,
212
- clearControlLabel = 'clear',
213
- datePickerProps = {},
214
- id = '',
215
- innerProps = {},
216
- isDisabled = false,
217
- isInvalid = false,
218
- isRequired = false,
219
- locale = 'en-US',
220
- name = '',
221
- spacing = 'default',
222
- testId,
223
- timePickerProps = {}
224
- } = this.props;
225
- const value = this.getValue();
226
- const {
227
- isFocused
228
- } = this.state;
229
- const parsedValues = this.getParsedValues();
230
- const dateValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.dateValue;
231
- const timeValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.timeValue;
232
- const datePickerSelectProps = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.selectProps;
233
- const datePickerAriaDescribedBy = datePickerProps['aria-describedby'] || ariaDescribedBy;
234
- const datePickerLabel = datePickerProps.label || 'Date';
235
- const mergedDatePickerSelectProps = {
236
- ...datePickerSelectProps,
237
- styles: mergeStyles(styles, datePickerSelectProps === null || datePickerSelectProps === void 0 ? void 0 : datePickerSelectProps.styles)
238
- };
239
- const timePickerSelectProps = timePickerProps === null || timePickerProps === void 0 ? void 0 : timePickerProps.selectProps;
240
- const timePickerAriaDescribedBy = timePickerProps['aria-describedby'] || ariaDescribedBy;
241
- const timePickerLabel = timePickerProps.label || 'Time';
242
- const mergedTimePickerSelectProps = {
243
- ...timePickerSelectProps,
244
- styles: mergeStyles(styles, timePickerSelectProps === null || timePickerSelectProps === void 0 ? void 0 : timePickerSelectProps.styles)
245
- };
246
-
247
- // Render DateTimePicker's IconContainer when a value has been filled
248
- // Don't use Date or TimePicker's because they can't be customised
249
- const isClearable = Boolean(dateValue || timeValue);
250
- return /*#__PURE__*/React.createElement(DateTimePickerContainer, {
251
- appearance: appearance,
252
- isDisabled: isDisabled,
253
- isFocused: isFocused,
254
- isInvalid: isInvalid,
255
- testId: testId,
256
- innerProps: innerProps
257
- }, /*#__PURE__*/React.createElement("input", {
258
- name: name,
259
- type: "hidden",
260
- value: value,
261
- "data-testid": testId && `${testId}--input`
262
- }), /*#__PURE__*/React.createElement("div", {
263
- className: ax([compiledStyles.datePickerContainerStyles])
264
- }, /*#__PURE__*/React.createElement(DatePicker, {
265
- appearance: appearance,
266
- "aria-describedby": datePickerAriaDescribedBy,
267
- autoFocus: datePickerProps.autoFocus || autoFocus,
268
- dateFormat: datePickerProps.dateFormat,
269
- defaultIsOpen: datePickerProps.defaultIsOpen,
270
- defaultValue: datePickerProps.defaultValue,
271
- disabled: datePickerProps.disabled,
272
- disabledDateFilter: datePickerProps.disabledDateFilter,
273
- formatDisplayLabel: datePickerProps.formatDisplayLabel,
274
- hideIcon: datePickerProps.hideIcon || true,
275
- icon: datePickerProps.icon,
276
- id: datePickerProps.id || id,
277
- innerProps: datePickerProps.innerProps,
278
- isDisabled: datePickerProps.isDisabled || isDisabled,
279
- isInvalid: datePickerProps.isInvalid || isInvalid,
280
- isRequired: datePickerProps.isRequired || isRequired,
281
- isOpen: datePickerProps.isOpen,
282
- label: datePickerLabel,
283
- locale: datePickerProps.locale || locale,
284
- maxDate: datePickerProps.maxDate,
285
- minDate: datePickerProps.minDate,
286
- name: datePickerProps.name,
287
- nextMonthLabel: datePickerProps.nextMonthLabel,
288
- onBlur: this.onDateBlur,
289
- onChange: this.onDateChange,
290
- onFocus: this.onDateFocus,
291
- parseInputValue: datePickerProps.parseInputValue,
292
- placeholder: datePickerProps.placeholder,
293
- previousMonthLabel: datePickerProps.previousMonthLabel,
294
- selectProps: mergedDatePickerSelectProps,
295
- shouldShowCalendarButton: datePickerProps.shouldShowCalendarButton,
296
- spacing: datePickerProps.spacing || spacing,
297
- testId: testId && `${testId}--datepicker` || datePickerProps.testId,
298
- value: dateValue,
299
- weekStartDay: datePickerProps.weekStartDay
300
- })), /*#__PURE__*/React.createElement("div", {
301
- className: ax([compiledStyles.timePickerContainerStyles])
302
- }, /*#__PURE__*/React.createElement(TimePicker, {
303
- appearance: timePickerProps.appearance || appearance,
304
- "aria-describedby": timePickerAriaDescribedBy,
305
- autoFocus: timePickerProps.autoFocus,
306
- defaultIsOpen: timePickerProps.defaultIsOpen,
307
- defaultValue: timePickerProps.defaultValue,
308
- formatDisplayLabel: timePickerProps.formatDisplayLabel,
309
- hideIcon: timePickerProps.hideIcon || true,
310
- id: timePickerProps.id,
311
- innerProps: timePickerProps.innerProps,
312
- isDisabled: timePickerProps.isDisabled || isDisabled,
313
- isInvalid: timePickerProps.isInvalid || isInvalid,
314
- isOpen: timePickerProps.isOpen,
315
- isRequired: timePickerProps.isRequired || isRequired,
316
- label: timePickerLabel,
317
- locale: timePickerProps.locale || locale,
318
- name: timePickerProps.name,
319
- onBlur: this.onTimeBlur,
320
- onChange: this.onTimeChange,
321
- onFocus: this.onTimeFocus,
322
- parseInputValue: timePickerProps.parseInputValue,
323
- placeholder: timePickerProps.placeholder,
324
- selectProps: mergedTimePickerSelectProps,
325
- spacing: timePickerProps.spacing || spacing,
326
- testId: timePickerProps.testId || testId && `${testId}--timepicker`,
327
- timeFormat: timePickerProps.timeFormat,
328
- timeIsEditable: timePickerProps.timeIsEditable,
329
- times: timePickerProps.times,
330
- value: timeValue
331
- })), isClearable && !isDisabled ? /*#__PURE__*/React.createElement("button", {
332
- onClick: this.onClear,
333
- "data-testid": testId && `${testId}--icon--container`,
334
- tabIndex: -1,
335
- type: "button",
336
- className: ax([compiledStyles.iconContainerStyles])
337
- }, /*#__PURE__*/React.createElement(SelectClearIcon, {
338
- color: "currentColor",
339
- label: clearControlLabel,
340
- size: "small"
341
- }), ' ') : null);
342
- }
343
- }
344
- _defineProperty(DateTimePickerComponent, "defaultProps", dateTimePickerDefaultProps);
345
- export { DateTimePickerComponent as DateTimePickerWithoutAnalytics };
346
-
347
- /**
348
- * __Date time picker__
349
- *
350
- * A date time picker allows the user to select an associated date and time.
351
- *
352
- * - [Examples](https://atlassian.design/components/datetime-picker/examples)
353
- * - [Code](https://atlassian.design/components/datetime-picker/code)
354
- * - [Usage](https://atlassian.design/components/datetime-picker/usage)
355
- */
356
- const DateTimePicker = withAnalyticsContext({
357
- componentName: 'dateTimePicker',
358
- packageName,
359
- packageVersion
360
- })(withAnalyticsEvents({
361
- onChange: createAndFireEvent('atlaskit')({
362
- action: 'changed',
363
- actionSubject: 'dateTimePicker',
364
- attributes: {
365
- componentName: 'dateTimePicker',
366
- packageName,
367
- packageVersion
368
- }
369
- })
370
- })(DateTimePickerComponent));
371
-
372
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
373
- export default DateTimePicker;