@atlaskit/datetime-picker 13.11.2 → 13.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/components/date-picker.js +22 -24
- package/dist/cjs/components/date-time-picker.js +50 -44
- package/dist/cjs/components/time-picker.js +13 -11
- package/dist/es2019/components/date-picker.js +21 -22
- package/dist/es2019/components/date-time-picker.js +43 -47
- package/dist/es2019/components/time-picker.js +13 -14
- package/dist/esm/components/date-picker.js +22 -24
- package/dist/esm/components/date-time-picker.js +50 -44
- package/dist/esm/components/time-picker.js +13 -11
- package/dist/types/components/date-picker.d.ts +2 -12
- package/dist/types/components/date-time-picker.d.ts +2 -3
- package/dist/types/components/time-picker.d.ts +2 -1
- package/dist/types-ts4.5/components/date-picker.d.ts +2 -12
- package/dist/types-ts4.5/components/date-time-picker.d.ts +2 -3
- package/dist/types-ts4.5/components/time-picker.d.ts +2 -1
- package/package.json +4 -5
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
/**
|
|
4
3
|
* @jsxRuntime classic
|
|
@@ -9,7 +8,6 @@ import React from 'react';
|
|
|
9
8
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
10
9
|
import { css, jsx } from '@emotion/react';
|
|
11
10
|
import { format, isValid, parseISO } from 'date-fns';
|
|
12
|
-
import pick from 'lodash/pick';
|
|
13
11
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
14
12
|
import SelectClearIcon from '@atlaskit/icon/glyph/select-clear';
|
|
15
13
|
import { mergeStyles } from '@atlaskit/select';
|
|
@@ -20,7 +18,7 @@ import { convertTokens } from '../internal/parse-tokens';
|
|
|
20
18
|
import DatePicker from './date-picker';
|
|
21
19
|
import TimePicker from './time-picker';
|
|
22
20
|
const packageName = "@atlaskit/datetime-picker";
|
|
23
|
-
const packageVersion = "13.11.
|
|
21
|
+
const packageVersion = "13.11.3";
|
|
24
22
|
// Make DatePicker 50% the width of DateTimePicker
|
|
25
23
|
// If rendering an icon container, shrink the TimePicker
|
|
26
24
|
const datePickerContainerStyles = css({
|
|
@@ -105,15 +103,10 @@ class DateTimePickerComponent extends React.Component {
|
|
|
105
103
|
});
|
|
106
104
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
107
105
|
// correctly to allow controlled/uncontrolled usage.
|
|
108
|
-
_defineProperty(this, "
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
113
|
-
return {
|
|
114
|
-
...mappedState,
|
|
115
|
-
...this.parseValue(mappedState.value, mappedState.dateValue, mappedState.timeValue, mappedState.zoneValue)
|
|
116
|
-
};
|
|
106
|
+
_defineProperty(this, "getParsedValues", () => this.parseValue(this.getValue(), this.state.dateValue, this.state.timeValue, this.state.zoneValue));
|
|
107
|
+
_defineProperty(this, "getValue", () => {
|
|
108
|
+
var _this$props$value;
|
|
109
|
+
return (_this$props$value = this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : this.state.value;
|
|
117
110
|
});
|
|
118
111
|
_defineProperty(this, "onBlur", event => {
|
|
119
112
|
this.setState({
|
|
@@ -128,28 +121,44 @@ class DateTimePickerComponent extends React.Component {
|
|
|
128
121
|
this.props.onFocus(event);
|
|
129
122
|
});
|
|
130
123
|
_defineProperty(this, "onDateChange", dateValue => {
|
|
124
|
+
const parsedValues = this.getParsedValues();
|
|
131
125
|
this.onValueChange({
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
dateValue,
|
|
127
|
+
timeValue: parsedValues.timeValue,
|
|
128
|
+
zoneValue: parsedValues.zoneValue
|
|
134
129
|
});
|
|
135
130
|
});
|
|
136
131
|
_defineProperty(this, "onTimeChange", timeValue => {
|
|
132
|
+
const parsedValues = this.getParsedValues();
|
|
137
133
|
this.onValueChange({
|
|
138
|
-
|
|
139
|
-
timeValue
|
|
134
|
+
dateValue: parsedValues.dateValue,
|
|
135
|
+
timeValue,
|
|
136
|
+
zoneValue: parsedValues.zoneValue
|
|
140
137
|
});
|
|
141
138
|
});
|
|
142
139
|
_defineProperty(this, "onClear", () => {
|
|
140
|
+
const parsedValues = this.getParsedValues();
|
|
143
141
|
this.onValueChange({
|
|
144
|
-
|
|
142
|
+
dateValue: '',
|
|
145
143
|
timeValue: '',
|
|
146
|
-
|
|
144
|
+
zoneValue: parsedValues.zoneValue
|
|
147
145
|
});
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
148
|
parseValue(value, dateValue, timeValue, zoneValue) {
|
|
151
149
|
if (this.props.parseValue) {
|
|
152
|
-
|
|
150
|
+
const parsedFromFn = this.props.parseValue(value, dateValue, timeValue, zoneValue);
|
|
151
|
+
// This handles cases found in Jira where the parse function actually does
|
|
152
|
+
// nothing and returns undefined. The previous `getSafeState` function
|
|
153
|
+
// just spread the values over the state, but if it returned `undefined`,
|
|
154
|
+
// it would just rely on the previous state values. Considering this is
|
|
155
|
+
// what is input to this function anyway, this is a safe way to handle
|
|
156
|
+
// this, colocate the behavior, and not rely on `getSafeState`.
|
|
157
|
+
return parsedFromFn || {
|
|
158
|
+
dateValue,
|
|
159
|
+
timeValue,
|
|
160
|
+
zoneValue
|
|
161
|
+
};
|
|
153
162
|
}
|
|
154
163
|
const parsed = parseISO(value);
|
|
155
164
|
return isValid(parsed) ? {
|
|
@@ -183,7 +192,7 @@ class DateTimePickerComponent extends React.Component {
|
|
|
183
192
|
});
|
|
184
193
|
this.props.onChange(valueWithValidZone);
|
|
185
194
|
// If the date or time value was cleared when there is an existing datetime value, then clear the value.
|
|
186
|
-
} else if (this.
|
|
195
|
+
} else if (this.getValue()) {
|
|
187
196
|
this.setState({
|
|
188
197
|
value: ''
|
|
189
198
|
});
|
|
@@ -212,12 +221,13 @@ class DateTimePickerComponent extends React.Component {
|
|
|
212
221
|
timePickerSelectProps,
|
|
213
222
|
times
|
|
214
223
|
} = this.props;
|
|
224
|
+
const value = this.getValue();
|
|
215
225
|
const {
|
|
216
|
-
isFocused
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
isFocused
|
|
227
|
+
} = this.state;
|
|
228
|
+
const parsedValues = this.getParsedValues();
|
|
229
|
+
const dateValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.dateValue;
|
|
230
|
+
const timeValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.timeValue;
|
|
221
231
|
const {
|
|
222
232
|
styles: datePickerStyles = {}
|
|
223
233
|
} = datePickerSelectProps;
|
|
@@ -254,7 +264,7 @@ class DateTimePickerComponent extends React.Component {
|
|
|
254
264
|
"data-testid": testId && `${testId}--input`
|
|
255
265
|
}), jsx("div", {
|
|
256
266
|
css: datePickerContainerStyles
|
|
257
|
-
}, jsx(DatePicker,
|
|
267
|
+
}, jsx(DatePicker, {
|
|
258
268
|
appearance: appearance,
|
|
259
269
|
autoFocus: datePickerProps.autoFocus || autoFocus,
|
|
260
270
|
dateFormat: datePickerProps.dateFormat || dateFormat,
|
|
@@ -268,15 +278,8 @@ class DateTimePickerComponent extends React.Component {
|
|
|
268
278
|
id: datePickerProps.id || id,
|
|
269
279
|
innerProps: datePickerProps.innerProps,
|
|
270
280
|
isDisabled: datePickerProps.isDisabled || isDisabled,
|
|
271
|
-
isInvalid: datePickerProps.isInvalid || isInvalid
|
|
272
|
-
|
|
273
|
-
// `isOpen={datePickerProps.isOpen}`, the date picker will set
|
|
274
|
-
// `isOpen` to `undefined` forever. I believe this has to do with
|
|
275
|
-
// the `getSafeState` function in the picker, since it overwrites
|
|
276
|
-
// state with values from the props.
|
|
277
|
-
}, datePickerProps.isOpen ? {
|
|
278
|
-
isOpen: datePickerProps.isOpen
|
|
279
|
-
} : {}, {
|
|
281
|
+
isInvalid: datePickerProps.isInvalid || isInvalid,
|
|
282
|
+
isOpen: datePickerProps.isOpen,
|
|
280
283
|
locale: datePickerProps.locale || locale,
|
|
281
284
|
maxDate: datePickerProps.maxDate,
|
|
282
285
|
minDate: datePickerProps.minDate,
|
|
@@ -293,9 +296,9 @@ class DateTimePickerComponent extends React.Component {
|
|
|
293
296
|
testId: testId && `${testId}--datepicker` || datePickerProps.testId,
|
|
294
297
|
value: dateValue,
|
|
295
298
|
weekStartDay: datePickerProps.weekStartDay
|
|
296
|
-
}))
|
|
299
|
+
})), jsx("div", {
|
|
297
300
|
css: timePickerContainerStyles
|
|
298
|
-
}, jsx(TimePicker,
|
|
301
|
+
}, jsx(TimePicker, {
|
|
299
302
|
appearance: timePickerProps.appearance || appearance,
|
|
300
303
|
autoFocus: timePickerProps.autoFocus,
|
|
301
304
|
defaultIsOpen: timePickerProps.defaultIsOpen,
|
|
@@ -305,15 +308,8 @@ class DateTimePickerComponent extends React.Component {
|
|
|
305
308
|
id: timePickerProps.id,
|
|
306
309
|
innerProps: timePickerProps.innerProps,
|
|
307
310
|
isDisabled: timePickerProps.isDisabled || isDisabled,
|
|
308
|
-
isInvalid: timePickerProps.isInvalid || isInvalid
|
|
309
|
-
|
|
310
|
-
// `isOpen={datePickerProps.isOpen}`, the date picker will set
|
|
311
|
-
// `isOpen` to `undefined` forever. I believe this has to do with
|
|
312
|
-
// the `getSafeState` function in the picker, since it overwrites
|
|
313
|
-
// state with values from the props.
|
|
314
|
-
}, timePickerProps.isOpen ? {
|
|
315
|
-
isOpen: timePickerProps.isOpen
|
|
316
|
-
} : {}, {
|
|
311
|
+
isInvalid: timePickerProps.isInvalid || isInvalid,
|
|
312
|
+
isOpen: timePickerProps.isOpen,
|
|
317
313
|
locale: timePickerProps.locale || locale,
|
|
318
314
|
name: timePickerProps.name,
|
|
319
315
|
onBlur: timePickerProps.onBlur || this.onBlur,
|
|
@@ -328,7 +324,7 @@ class DateTimePickerComponent extends React.Component {
|
|
|
328
324
|
timeIsEditable: timePickerProps.timeIsEditable || timeIsEditable,
|
|
329
325
|
times: timePickerProps.times || times,
|
|
330
326
|
value: timeValue
|
|
331
|
-
}))
|
|
327
|
+
})), isClearable && !isDisabled ? jsx("button", {
|
|
332
328
|
css: iconContainerStyles,
|
|
333
329
|
onClick: this.onClear,
|
|
334
330
|
"data-testid": testId && `${testId}--icon--container`,
|
|
@@ -4,7 +4,6 @@ import React from 'react';
|
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line no-restricted-imports
|
|
6
6
|
import { format, isValid } from 'date-fns';
|
|
7
|
-
import pick from 'lodash/pick';
|
|
8
7
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
9
8
|
import { createLocalizationProvider } from '@atlaskit/locale';
|
|
10
9
|
import Select, { CreatableSelect, mergeStyles } from '@atlaskit/select';
|
|
@@ -16,7 +15,7 @@ import parseTime from '../internal/parse-time';
|
|
|
16
15
|
import { convertTokens } from '../internal/parse-tokens';
|
|
17
16
|
import { makeSingleValue } from '../internal/single-value';
|
|
18
17
|
const packageName = "@atlaskit/datetime-picker";
|
|
19
|
-
const packageVersion = "13.11.
|
|
18
|
+
const packageVersion = "13.11.3";
|
|
20
19
|
const menuStyles = {
|
|
21
20
|
/* Need to remove default absolute positioning as that causes issues with position fixed */
|
|
22
21
|
position: 'static',
|
|
@@ -65,11 +64,13 @@ class TimePickerComponent extends React.Component {
|
|
|
65
64
|
});
|
|
66
65
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
67
66
|
// correctly to allow controlled/uncontrolled usage.
|
|
68
|
-
_defineProperty(this, "
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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, "getIsOpen", () => {
|
|
72
|
+
var _this$props$isOpen;
|
|
73
|
+
return (_this$props$isOpen = this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : this.state.isOpen;
|
|
73
74
|
});
|
|
74
75
|
_defineProperty(this, "onChange", (newValue, action) => {
|
|
75
76
|
const rawValue = newValue ? newValue.value || newValue : '';
|
|
@@ -114,7 +115,7 @@ class TimePickerComponent extends React.Component {
|
|
|
114
115
|
});
|
|
115
116
|
_defineProperty(this, "onMenuOpen", () => {
|
|
116
117
|
// Don't open menu after the user has clicked clear
|
|
117
|
-
if (this.
|
|
118
|
+
if (this.state.clearingFromIcon) {
|
|
118
119
|
this.setState({
|
|
119
120
|
clearingFromIcon: false
|
|
120
121
|
});
|
|
@@ -126,7 +127,7 @@ class TimePickerComponent extends React.Component {
|
|
|
126
127
|
});
|
|
127
128
|
_defineProperty(this, "onMenuClose", () => {
|
|
128
129
|
// Don't close menu after the user has clicked clear
|
|
129
|
-
if (this.
|
|
130
|
+
if (this.state.clearingFromIcon) {
|
|
130
131
|
this.setState({
|
|
131
132
|
clearingFromIcon: false
|
|
132
133
|
});
|
|
@@ -162,7 +163,7 @@ class TimePickerComponent extends React.Component {
|
|
|
162
163
|
key
|
|
163
164
|
} = event;
|
|
164
165
|
const keyPressed = key.toLowerCase();
|
|
165
|
-
if (this.
|
|
166
|
+
if (this.state.clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
|
|
166
167
|
// If being cleared from keyboard, don't change behaviour
|
|
167
168
|
this.setState({
|
|
168
169
|
clearingFromIcon: false
|
|
@@ -194,10 +195,8 @@ class TimePickerComponent extends React.Component {
|
|
|
194
195
|
} = this.props;
|
|
195
196
|
const ICON_PADDING = 2;
|
|
196
197
|
const l10n = createLocalizationProvider(locale);
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
isOpen
|
|
200
|
-
} = this.getSafeState();
|
|
198
|
+
const value = this.getValue() || '';
|
|
199
|
+
const isOpen = this.getIsOpen();
|
|
201
200
|
const {
|
|
202
201
|
styles: selectStyles = {},
|
|
203
202
|
...otherSelectProps
|
|
@@ -20,7 +20,6 @@ import { Component } from 'react';
|
|
|
20
20
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
21
21
|
import { jsx } from '@emotion/react';
|
|
22
22
|
import { format, isValid, lastDayOfMonth, parseISO } from 'date-fns';
|
|
23
|
-
import pick from 'lodash/pick';
|
|
24
23
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
25
24
|
import CalendarIcon from '@atlaskit/icon/glyph/calendar';
|
|
26
25
|
import { createLocalizationProvider } from '@atlaskit/locale';
|
|
@@ -31,7 +30,7 @@ import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date'
|
|
|
31
30
|
import { convertTokens } from '../internal/parse-tokens';
|
|
32
31
|
import { makeSingleValue } from '../internal/single-value';
|
|
33
32
|
var packageName = "@atlaskit/datetime-picker";
|
|
34
|
-
var packageVersion = "13.11.
|
|
33
|
+
var packageVersion = "13.11.3";
|
|
35
34
|
var datePickerDefaultProps = {
|
|
36
35
|
appearance: 'default',
|
|
37
36
|
autoFocus: false,
|
|
@@ -73,8 +72,13 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
73
72
|
_defineProperty(_assertThisInitialized(_this), "containerRef", null);
|
|
74
73
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
75
74
|
// correctly to allow controlled/uncontrolled usage.
|
|
76
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
77
|
-
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this), "getValue", function () {
|
|
76
|
+
var _this$props$value;
|
|
77
|
+
return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
|
|
78
|
+
});
|
|
79
|
+
_defineProperty(_assertThisInitialized(_this), "getIsOpen", function () {
|
|
80
|
+
var _this$props$isOpen;
|
|
81
|
+
return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
|
|
78
82
|
});
|
|
79
83
|
_defineProperty(_assertThisInitialized(_this), "isDateDisabled", function (date) {
|
|
80
84
|
return _this.props.disabled.indexOf(date) > -1;
|
|
@@ -124,7 +128,7 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
124
128
|
});
|
|
125
129
|
});
|
|
126
130
|
_defineProperty(_assertThisInitialized(_this), "onInputClick", function () {
|
|
127
|
-
if (!_this.props.isDisabled && !_this.
|
|
131
|
+
if (!_this.props.isDisabled && !_this.getIsOpen()) {
|
|
128
132
|
_this.setState({
|
|
129
133
|
isOpen: true
|
|
130
134
|
});
|
|
@@ -149,7 +153,7 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
149
153
|
_defineProperty(_assertThisInitialized(_this), "onSelectBlur", function (event) {
|
|
150
154
|
var _this$containerRef3;
|
|
151
155
|
var newlyFocusedElement = event.relatedTarget;
|
|
152
|
-
if (_this.
|
|
156
|
+
if (_this.state.clearingFromIcon) {
|
|
153
157
|
// Don't close menu if blurring after the user has clicked clear
|
|
154
158
|
_this.setState({
|
|
155
159
|
clearingFromIcon: false
|
|
@@ -164,9 +168,8 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
164
168
|
}
|
|
165
169
|
});
|
|
166
170
|
_defineProperty(_assertThisInitialized(_this), "onSelectFocus", function (event) {
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
value = _this$getSafeState.value;
|
|
171
|
+
var clearingFromIcon = _this.state.clearingFromIcon;
|
|
172
|
+
var value = _this.getValue();
|
|
170
173
|
if (clearingFromIcon) {
|
|
171
174
|
// Don't open menu if focussing after the user has clicked clear
|
|
172
175
|
_this.setState({
|
|
@@ -200,9 +203,8 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
200
203
|
});
|
|
201
204
|
_defineProperty(_assertThisInitialized(_this), "onInputKeyDown", function (event) {
|
|
202
205
|
var _this$containerRef4;
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
-
calendarValue = _this$getSafeState2.calendarValue;
|
|
206
|
+
var calendarValue = _this.state.calendarValue;
|
|
207
|
+
var value = _this.getValue();
|
|
206
208
|
var keyPressed = event.key.toLowerCase();
|
|
207
209
|
|
|
208
210
|
// If the input is focused and the calendar is not visible, handle space and enter clicks
|
|
@@ -330,8 +332,7 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
330
332
|
if (parseInputValue) {
|
|
331
333
|
return parseInputValue(date, dateFormat || defaultDateFormat);
|
|
332
334
|
}
|
|
333
|
-
var
|
|
334
|
-
l10n = _this$getSafeState3.l10n;
|
|
335
|
+
var l10n = _this.state.l10n;
|
|
335
336
|
return l10n.parseDate(date);
|
|
336
337
|
});
|
|
337
338
|
/**
|
|
@@ -345,8 +346,7 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
345
346
|
var _this$props2 = _this.props,
|
|
346
347
|
formatDisplayLabel = _this$props2.formatDisplayLabel,
|
|
347
348
|
dateFormat = _this$props2.dateFormat;
|
|
348
|
-
var
|
|
349
|
-
l10n = _this$getSafeState4.l10n;
|
|
349
|
+
var l10n = _this.state.l10n;
|
|
350
350
|
if (formatDisplayLabel) {
|
|
351
351
|
return formatDisplayLabel(value, dateFormat || defaultDateFormat);
|
|
352
352
|
}
|
|
@@ -358,8 +358,7 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
358
358
|
if (placeholder) {
|
|
359
359
|
return placeholder;
|
|
360
360
|
}
|
|
361
|
-
var
|
|
362
|
-
l10n = _this$getSafeState5.l10n;
|
|
361
|
+
var l10n = _this.state.l10n;
|
|
363
362
|
return l10n.formatDate(placeholderDatetime);
|
|
364
363
|
});
|
|
365
364
|
_this.state = {
|
|
@@ -401,14 +400,13 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
|
|
|
401
400
|
locale = _this$props3.locale,
|
|
402
401
|
testId = _this$props3.testId,
|
|
403
402
|
weekStartDay = _this$props3.weekStartDay;
|
|
404
|
-
var _this$
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
selectInputValue = _this$getSafeState6.selectInputValue;
|
|
403
|
+
var _this$state = this.state,
|
|
404
|
+
calendarValue = _this$state.calendarValue,
|
|
405
|
+
selectInputValue = _this$state.selectInputValue;
|
|
406
|
+
var value = this.getValue();
|
|
409
407
|
var actualSelectInputValue;
|
|
410
408
|
actualSelectInputValue = selectInputValue;
|
|
411
|
-
var menuIsOpen =
|
|
409
|
+
var menuIsOpen = this.getIsOpen() && !isDisabled;
|
|
412
410
|
var showClearIndicator = Boolean((value || selectInputValue) && !hideIcon);
|
|
413
411
|
var dropDownIcon = appearance === 'subtle' || hideIcon || showClearIndicator ? null : icon;
|
|
414
412
|
var SingleValue = makeSingleValue({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
3
|
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
@@ -19,7 +18,6 @@ import React from 'react';
|
|
|
19
18
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
20
19
|
import { css, jsx } from '@emotion/react';
|
|
21
20
|
import { format, isValid, parseISO } from 'date-fns';
|
|
22
|
-
import pick from 'lodash/pick';
|
|
23
21
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
24
22
|
import SelectClearIcon from '@atlaskit/icon/glyph/select-clear';
|
|
25
23
|
import { mergeStyles } from '@atlaskit/select';
|
|
@@ -30,7 +28,7 @@ import { convertTokens } from '../internal/parse-tokens';
|
|
|
30
28
|
import DatePicker from './date-picker';
|
|
31
29
|
import TimePicker from './time-picker';
|
|
32
30
|
var packageName = "@atlaskit/datetime-picker";
|
|
33
|
-
var packageVersion = "13.11.
|
|
31
|
+
var packageVersion = "13.11.3";
|
|
34
32
|
// Make DatePicker 50% the width of DateTimePicker
|
|
35
33
|
// If rendering an icon container, shrink the TimePicker
|
|
36
34
|
var datePickerContainerStyles = css({
|
|
@@ -123,9 +121,12 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
123
121
|
});
|
|
124
122
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
125
123
|
// correctly to allow controlled/uncontrolled usage.
|
|
126
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
_defineProperty(_assertThisInitialized(_this), "getParsedValues", function () {
|
|
125
|
+
return _this.parseValue(_this.getValue(), _this.state.dateValue, _this.state.timeValue, _this.state.zoneValue);
|
|
126
|
+
});
|
|
127
|
+
_defineProperty(_assertThisInitialized(_this), "getValue", function () {
|
|
128
|
+
var _this$props$value;
|
|
129
|
+
return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
|
|
129
130
|
});
|
|
130
131
|
_defineProperty(_assertThisInitialized(_this), "onBlur", function (event) {
|
|
131
132
|
_this.setState({
|
|
@@ -140,20 +141,28 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
140
141
|
_this.props.onFocus(event);
|
|
141
142
|
});
|
|
142
143
|
_defineProperty(_assertThisInitialized(_this), "onDateChange", function (dateValue) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
var parsedValues = _this.getParsedValues();
|
|
145
|
+
_this.onValueChange({
|
|
146
|
+
dateValue: dateValue,
|
|
147
|
+
timeValue: parsedValues.timeValue,
|
|
148
|
+
zoneValue: parsedValues.zoneValue
|
|
149
|
+
});
|
|
146
150
|
});
|
|
147
151
|
_defineProperty(_assertThisInitialized(_this), "onTimeChange", function (timeValue) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
var parsedValues = _this.getParsedValues();
|
|
153
|
+
_this.onValueChange({
|
|
154
|
+
dateValue: parsedValues.dateValue,
|
|
155
|
+
timeValue: timeValue,
|
|
156
|
+
zoneValue: parsedValues.zoneValue
|
|
157
|
+
});
|
|
151
158
|
});
|
|
152
159
|
_defineProperty(_assertThisInitialized(_this), "onClear", function () {
|
|
153
|
-
|
|
160
|
+
var parsedValues = _this.getParsedValues();
|
|
161
|
+
_this.onValueChange({
|
|
162
|
+
dateValue: '',
|
|
154
163
|
timeValue: '',
|
|
155
|
-
|
|
156
|
-
})
|
|
164
|
+
zoneValue: parsedValues.zoneValue
|
|
165
|
+
});
|
|
157
166
|
});
|
|
158
167
|
return _this;
|
|
159
168
|
}
|
|
@@ -161,7 +170,18 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
161
170
|
key: "parseValue",
|
|
162
171
|
value: function parseValue(value, dateValue, timeValue, zoneValue) {
|
|
163
172
|
if (this.props.parseValue) {
|
|
164
|
-
|
|
173
|
+
var parsedFromFn = this.props.parseValue(value, dateValue, timeValue, zoneValue);
|
|
174
|
+
// This handles cases found in Jira where the parse function actually does
|
|
175
|
+
// nothing and returns undefined. The previous `getSafeState` function
|
|
176
|
+
// just spread the values over the state, but if it returned `undefined`,
|
|
177
|
+
// it would just rely on the previous state values. Considering this is
|
|
178
|
+
// what is input to this function anyway, this is a safe way to handle
|
|
179
|
+
// this, colocate the behavior, and not rely on `getSafeState`.
|
|
180
|
+
return parsedFromFn || {
|
|
181
|
+
dateValue: dateValue,
|
|
182
|
+
timeValue: timeValue,
|
|
183
|
+
zoneValue: zoneValue
|
|
184
|
+
};
|
|
165
185
|
}
|
|
166
186
|
var parsed = parseISO(value);
|
|
167
187
|
return isValid(parsed) ? {
|
|
@@ -195,7 +215,7 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
195
215
|
});
|
|
196
216
|
this.props.onChange(valueWithValidZone);
|
|
197
217
|
// If the date or time value was cleared when there is an existing datetime value, then clear the value.
|
|
198
|
-
} else if (this.
|
|
218
|
+
} else if (this.getValue()) {
|
|
199
219
|
this.setState({
|
|
200
220
|
value: ''
|
|
201
221
|
});
|
|
@@ -225,11 +245,11 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
225
245
|
timePickerProps = _this$props.timePickerProps,
|
|
226
246
|
timePickerSelectProps = _this$props.timePickerSelectProps,
|
|
227
247
|
times = _this$props.times;
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
248
|
+
var value = this.getValue();
|
|
249
|
+
var isFocused = this.state.isFocused;
|
|
250
|
+
var parsedValues = this.getParsedValues();
|
|
251
|
+
var dateValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.dateValue;
|
|
252
|
+
var timeValue = parsedValues === null || parsedValues === void 0 ? void 0 : parsedValues.timeValue;
|
|
233
253
|
var _datePickerSelectProp = datePickerSelectProps.styles,
|
|
234
254
|
datePickerStyles = _datePickerSelectProp === void 0 ? {} : _datePickerSelectProp;
|
|
235
255
|
var _timePickerSelectProp = timePickerSelectProps.styles,
|
|
@@ -262,7 +282,7 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
262
282
|
"data-testid": testId && "".concat(testId, "--input")
|
|
263
283
|
}), jsx("div", {
|
|
264
284
|
css: datePickerContainerStyles
|
|
265
|
-
}, jsx(DatePicker,
|
|
285
|
+
}, jsx(DatePicker, {
|
|
266
286
|
appearance: appearance,
|
|
267
287
|
autoFocus: datePickerProps.autoFocus || autoFocus,
|
|
268
288
|
dateFormat: datePickerProps.dateFormat || dateFormat,
|
|
@@ -276,15 +296,8 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
276
296
|
id: datePickerProps.id || id,
|
|
277
297
|
innerProps: datePickerProps.innerProps,
|
|
278
298
|
isDisabled: datePickerProps.isDisabled || isDisabled,
|
|
279
|
-
isInvalid: datePickerProps.isInvalid || isInvalid
|
|
280
|
-
|
|
281
|
-
// `isOpen={datePickerProps.isOpen}`, the date picker will set
|
|
282
|
-
// `isOpen` to `undefined` forever. I believe this has to do with
|
|
283
|
-
// the `getSafeState` function in the picker, since it overwrites
|
|
284
|
-
// state with values from the props.
|
|
285
|
-
}, datePickerProps.isOpen ? {
|
|
286
|
-
isOpen: datePickerProps.isOpen
|
|
287
|
-
} : {}, {
|
|
299
|
+
isInvalid: datePickerProps.isInvalid || isInvalid,
|
|
300
|
+
isOpen: datePickerProps.isOpen,
|
|
288
301
|
locale: datePickerProps.locale || locale,
|
|
289
302
|
maxDate: datePickerProps.maxDate,
|
|
290
303
|
minDate: datePickerProps.minDate,
|
|
@@ -301,9 +314,9 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
301
314
|
testId: testId && "".concat(testId, "--datepicker") || datePickerProps.testId,
|
|
302
315
|
value: dateValue,
|
|
303
316
|
weekStartDay: datePickerProps.weekStartDay
|
|
304
|
-
}))
|
|
317
|
+
})), jsx("div", {
|
|
305
318
|
css: timePickerContainerStyles
|
|
306
|
-
}, jsx(TimePicker,
|
|
319
|
+
}, jsx(TimePicker, {
|
|
307
320
|
appearance: timePickerProps.appearance || appearance,
|
|
308
321
|
autoFocus: timePickerProps.autoFocus,
|
|
309
322
|
defaultIsOpen: timePickerProps.defaultIsOpen,
|
|
@@ -313,15 +326,8 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
313
326
|
id: timePickerProps.id,
|
|
314
327
|
innerProps: timePickerProps.innerProps,
|
|
315
328
|
isDisabled: timePickerProps.isDisabled || isDisabled,
|
|
316
|
-
isInvalid: timePickerProps.isInvalid || isInvalid
|
|
317
|
-
|
|
318
|
-
// `isOpen={datePickerProps.isOpen}`, the date picker will set
|
|
319
|
-
// `isOpen` to `undefined` forever. I believe this has to do with
|
|
320
|
-
// the `getSafeState` function in the picker, since it overwrites
|
|
321
|
-
// state with values from the props.
|
|
322
|
-
}, timePickerProps.isOpen ? {
|
|
323
|
-
isOpen: timePickerProps.isOpen
|
|
324
|
-
} : {}, {
|
|
329
|
+
isInvalid: timePickerProps.isInvalid || isInvalid,
|
|
330
|
+
isOpen: timePickerProps.isOpen,
|
|
325
331
|
locale: timePickerProps.locale || locale,
|
|
326
332
|
name: timePickerProps.name,
|
|
327
333
|
onBlur: timePickerProps.onBlur || this.onBlur,
|
|
@@ -336,7 +342,7 @@ var DateTimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
336
342
|
timeIsEditable: timePickerProps.timeIsEditable || timeIsEditable,
|
|
337
343
|
times: timePickerProps.times || times,
|
|
338
344
|
value: timeValue
|
|
339
|
-
}))
|
|
345
|
+
})), isClearable && !isDisabled ? jsx("button", {
|
|
340
346
|
css: iconContainerStyles,
|
|
341
347
|
onClick: this.onClear,
|
|
342
348
|
"data-testid": testId && "".concat(testId, "--icon--container"),
|
|
@@ -16,7 +16,6 @@ import React from 'react';
|
|
|
16
16
|
|
|
17
17
|
// eslint-disable-next-line no-restricted-imports
|
|
18
18
|
import { format, isValid } from 'date-fns';
|
|
19
|
-
import pick from 'lodash/pick';
|
|
20
19
|
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
21
20
|
import { createLocalizationProvider } from '@atlaskit/locale';
|
|
22
21
|
import Select, { CreatableSelect, mergeStyles } from '@atlaskit/select';
|
|
@@ -28,7 +27,7 @@ import parseTime from '../internal/parse-time';
|
|
|
28
27
|
import { convertTokens } from '../internal/parse-tokens';
|
|
29
28
|
import { makeSingleValue } from '../internal/single-value';
|
|
30
29
|
var packageName = "@atlaskit/datetime-picker";
|
|
31
|
-
var packageVersion = "13.11.
|
|
30
|
+
var packageVersion = "13.11.3";
|
|
32
31
|
var menuStyles = {
|
|
33
32
|
/* Need to remove default absolute positioning as that causes issues with position fixed */
|
|
34
33
|
position: 'static',
|
|
@@ -86,8 +85,13 @@ var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
86
85
|
});
|
|
87
86
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
88
87
|
// correctly to allow controlled/uncontrolled usage.
|
|
89
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
90
|
-
|
|
88
|
+
_defineProperty(_assertThisInitialized(_this), "getValue", function () {
|
|
89
|
+
var _this$props$value;
|
|
90
|
+
return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
|
|
91
|
+
});
|
|
92
|
+
_defineProperty(_assertThisInitialized(_this), "getIsOpen", function () {
|
|
93
|
+
var _this$props$isOpen;
|
|
94
|
+
return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
|
|
91
95
|
});
|
|
92
96
|
_defineProperty(_assertThisInitialized(_this), "onChange", function (newValue, action) {
|
|
93
97
|
var rawValue = newValue ? newValue.value || newValue : '';
|
|
@@ -130,7 +134,7 @@ var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
130
134
|
});
|
|
131
135
|
_defineProperty(_assertThisInitialized(_this), "onMenuOpen", function () {
|
|
132
136
|
// Don't open menu after the user has clicked clear
|
|
133
|
-
if (_this.
|
|
137
|
+
if (_this.state.clearingFromIcon) {
|
|
134
138
|
_this.setState({
|
|
135
139
|
clearingFromIcon: false
|
|
136
140
|
});
|
|
@@ -142,7 +146,7 @@ var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
142
146
|
});
|
|
143
147
|
_defineProperty(_assertThisInitialized(_this), "onMenuClose", function () {
|
|
144
148
|
// Don't close menu after the user has clicked clear
|
|
145
|
-
if (_this.
|
|
149
|
+
if (_this.state.clearingFromIcon) {
|
|
146
150
|
_this.setState({
|
|
147
151
|
clearingFromIcon: false
|
|
148
152
|
});
|
|
@@ -176,7 +180,7 @@ var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
176
180
|
_defineProperty(_assertThisInitialized(_this), "onSelectKeyDown", function (event) {
|
|
177
181
|
var key = event.key;
|
|
178
182
|
var keyPressed = key.toLowerCase();
|
|
179
|
-
if (_this.
|
|
183
|
+
if (_this.state.clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
|
|
180
184
|
// If being cleared from keyboard, don't change behaviour
|
|
181
185
|
_this.setState({
|
|
182
186
|
clearingFromIcon: false
|
|
@@ -211,10 +215,8 @@ var TimePickerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
211
215
|
times = _this$props2.times;
|
|
212
216
|
var ICON_PADDING = 2;
|
|
213
217
|
var l10n = createLocalizationProvider(locale);
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
value = _this$getSafeState$va === void 0 ? '' : _this$getSafeState$va,
|
|
217
|
-
isOpen = _this$getSafeState.isOpen;
|
|
218
|
+
var value = this.getValue() || '';
|
|
219
|
+
var isOpen = this.getIsOpen();
|
|
218
220
|
var _selectProps$styles = selectProps.styles,
|
|
219
221
|
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
|
|
220
222
|
otherSelectProps = _objectWithoutProperties(selectProps, _excluded);
|
|
@@ -77,18 +77,8 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
|
|
|
77
77
|
l10n: LocalizationProvider;
|
|
78
78
|
locale: string;
|
|
79
79
|
} | null;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
value: string;
|
|
83
|
-
isOpen: boolean;
|
|
84
|
-
isFocused: boolean;
|
|
85
|
-
clearingFromIcon: boolean;
|
|
86
|
-
calendarValue: string;
|
|
87
|
-
selectInputValue: string;
|
|
88
|
-
l10n: LocalizationProvider;
|
|
89
|
-
locale: string;
|
|
90
|
-
shouldSetFocusOnCurrentDay: boolean;
|
|
91
|
-
};
|
|
80
|
+
getValue: () => string;
|
|
81
|
+
getIsOpen: () => boolean;
|
|
92
82
|
isDateDisabled: (date: string) => boolean;
|
|
93
83
|
onCalendarChange: ({ iso }: {
|
|
94
84
|
iso: string;
|