@atlaskit/datetime-picker 17.6.5 → 17.7.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/components/date-picker.js +17 -12
- package/dist/cjs/components/date-time-picker-class.js +1 -1
- package/dist/cjs/components/date-time-picker-fc.js +472 -8
- package/dist/cjs/components/time-picker.js +1 -1
- package/dist/cjs/internal/convert-to24hr-time.js +66 -0
- package/dist/cjs/internal/format-date.js +39 -0
- package/dist/cjs/internal/{date-picker-migration.js → get-parsed-iso.js} +1 -45
- package/dist/cjs/internal/get-placeholder.js +32 -0
- package/dist/cjs/internal/get-safe-calendar-value.js +18 -0
- package/dist/cjs/internal/get-short-iso-string.js +13 -0
- package/dist/cjs/internal/is-date-disabled.js +29 -0
- package/dist/cjs/internal/is-valid.js +39 -0
- package/dist/cjs/internal/parse-date.js +31 -20
- package/dist/cjs/internal/parse-time.js +6 -102
- package/dist/cjs/internal/remove-spacer.js +9 -0
- package/dist/es2019/components/date-picker.js +8 -3
- package/dist/es2019/components/date-time-picker-class.js +1 -1
- package/dist/es2019/components/date-time-picker-fc.js +454 -5
- package/dist/es2019/components/time-picker.js +1 -1
- package/dist/es2019/internal/convert-to24hr-time.js +60 -0
- package/dist/es2019/internal/format-date.js +34 -0
- package/dist/es2019/internal/{date-picker-migration.js → get-parsed-iso.js} +2 -54
- package/dist/es2019/internal/get-placeholder.js +28 -0
- package/dist/es2019/internal/get-safe-calendar-value.js +11 -0
- package/dist/es2019/internal/get-short-iso-string.js +6 -0
- package/dist/es2019/internal/is-date-disabled.js +25 -0
- package/dist/es2019/internal/is-valid.js +33 -0
- package/dist/es2019/internal/parse-date.js +33 -18
- package/dist/es2019/internal/parse-time.js +3 -96
- package/dist/es2019/internal/remove-spacer.js +3 -0
- package/dist/esm/components/date-picker.js +8 -3
- package/dist/esm/components/date-time-picker-class.js +1 -1
- package/dist/esm/components/date-time-picker-fc.js +471 -7
- package/dist/esm/components/time-picker.js +1 -1
- package/dist/esm/internal/convert-to24hr-time.js +60 -0
- package/dist/esm/internal/format-date.js +32 -0
- package/dist/esm/internal/{date-picker-migration.js → get-parsed-iso.js} +2 -46
- package/dist/esm/internal/get-placeholder.js +26 -0
- package/dist/esm/internal/get-safe-calendar-value.js +11 -0
- package/dist/esm/internal/get-short-iso-string.js +6 -0
- package/dist/esm/internal/is-date-disabled.js +23 -0
- package/dist/esm/internal/is-valid.js +33 -0
- package/dist/esm/internal/parse-date.js +31 -18
- package/dist/esm/internal/parse-time.js +3 -96
- package/dist/esm/internal/remove-spacer.js +3 -0
- package/dist/types/components/date-time-picker-fc.d.ts +6 -2
- package/dist/types/internal/convert-to24hr-time.d.ts +7 -0
- package/dist/types/internal/{date-picker-migration.d.ts → format-date.d.ts} +0 -28
- package/dist/types/internal/get-parsed-iso.d.ts +20 -0
- package/dist/types/internal/get-placeholder.d.ts +22 -0
- package/dist/types/internal/get-safe-calendar-value.d.ts +1 -0
- package/dist/types/internal/get-short-iso-string.d.ts +1 -0
- package/dist/types/internal/is-date-disabled.d.ts +20 -0
- package/dist/types/internal/is-valid.d.ts +1 -0
- package/dist/types/internal/parse-date.d.ts +26 -5
- package/dist/types/internal/parse-time.d.ts +0 -9
- package/dist/types/internal/remove-spacer.d.ts +1 -0
- package/dist/types-ts4.5/components/date-time-picker-fc.d.ts +6 -2
- package/dist/types-ts4.5/internal/convert-to24hr-time.d.ts +7 -0
- package/dist/types-ts4.5/internal/{date-picker-migration.d.ts → format-date.d.ts} +0 -28
- package/dist/types-ts4.5/internal/get-parsed-iso.d.ts +20 -0
- package/dist/types-ts4.5/internal/get-placeholder.d.ts +22 -0
- package/dist/types-ts4.5/internal/get-safe-calendar-value.d.ts +1 -0
- package/dist/types-ts4.5/internal/get-short-iso-string.d.ts +1 -0
- package/dist/types-ts4.5/internal/is-date-disabled.d.ts +20 -0
- package/dist/types-ts4.5/internal/is-valid.d.ts +1 -0
- package/dist/types-ts4.5/internal/parse-date.d.ts +26 -5
- package/dist/types-ts4.5/internal/parse-time.d.ts +0 -9
- package/dist/types-ts4.5/internal/remove-spacer.d.ts +1 -0
- package/package.json +8 -11
- package/dist/cjs/components/date-time-picker-fc-new.js +0 -479
- package/dist/cjs/components/date-time-picker-fc-old.js +0 -370
- package/dist/es2019/components/date-time-picker-fc-new.js +0 -456
- package/dist/es2019/components/date-time-picker-fc-old.compiled.css +0 -6
- package/dist/es2019/components/date-time-picker-fc-old.js +0 -336
- package/dist/esm/components/date-time-picker-fc-new.compiled.css +0 -6
- package/dist/esm/components/date-time-picker-fc-new.js +0 -473
- package/dist/esm/components/date-time-picker-fc-old.compiled.css +0 -6
- package/dist/esm/components/date-time-picker-fc-old.js +0 -364
- package/dist/types/components/date-time-picker-fc-new.d.ts +0 -6
- package/dist/types/components/date-time-picker-fc-old.d.ts +0 -6
- package/dist/types-ts4.5/components/date-time-picker-fc-new.d.ts +0 -6
- package/dist/types-ts4.5/components/date-time-picker-fc-old.d.ts +0 -6
- /package/dist/cjs/components/{date-time-picker-fc-new.compiled.css → date-time-picker-fc.compiled.css} +0 -0
- /package/dist/{cjs/components/date-time-picker-fc-old.compiled.css → es2019/components/date-time-picker-fc.compiled.css} +0 -0
- /package/dist/{es2019/components/date-time-picker-fc-new.compiled.css → esm/components/date-time-picker-fc.compiled.css} +0 -0
|
@@ -1,7 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
/* date-time-picker-fc.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import "./date-time-picker-fc.compiled.css";
|
|
4
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
// for typing `process`
|
|
7
|
+
|
|
8
|
+
import React, { forwardRef, useCallback, useEffect, useReducer, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
// oxlint-disable-next-line @atlassian/no-restricted-imports
|
|
11
|
+
import { format, isValid, parseISO } from 'date-fns';
|
|
12
|
+
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
13
|
+
import { IconButton } from '@atlaskit/button/new';
|
|
14
|
+
import SelectClearIcon from '@atlaskit/icon/core/cross-circle';
|
|
15
|
+
import { Box, Inline } from '@atlaskit/primitives/compiled';
|
|
16
|
+
import { mergeStyles } from '@atlaskit/select';
|
|
17
|
+
import { formatDateTimeZoneIntoIso } from '../internal';
|
|
18
|
+
import { DateTimePickerContainer } from '../internal/date-time-picker-container';
|
|
19
|
+
import { convertTokens } from '../internal/parse-tokens';
|
|
20
|
+
import DatePicker from './date-picker';
|
|
21
|
+
import TimePicker from './time-picker';
|
|
22
|
+
const packageName = "@atlaskit/datetime-picker";
|
|
23
|
+
const packageVersion = "0.0.0-development";
|
|
24
|
+
const analyticsAttributes = {
|
|
25
|
+
componentName: 'dateTimePicker',
|
|
26
|
+
packageName,
|
|
27
|
+
packageVersion
|
|
28
|
+
};
|
|
29
|
+
const compiledStyles = {
|
|
30
|
+
datePickerContainerStyles: "_i0dl1ssb _16jlkb7n _1o9zidpf",
|
|
31
|
+
timePickerContainerStyles: "_i0dl1ssb _16jlkb7n",
|
|
32
|
+
iconContainerStyles: "_1e0c1txw _4cvr1h6o _i0dl1kw7"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// react-select overrides (via @atlaskit/select).
|
|
36
|
+
const styles = {
|
|
37
|
+
control: style => ({
|
|
38
|
+
...style,
|
|
39
|
+
backgroundColor: 'transparent',
|
|
40
|
+
border: 2,
|
|
41
|
+
borderRadius: 0,
|
|
42
|
+
paddingLeft: 0,
|
|
43
|
+
':hover': {
|
|
44
|
+
backgroundColor: 'transparent',
|
|
45
|
+
cursor: 'inherit'
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Two action types keep the reducer focused:
|
|
52
|
+
*
|
|
53
|
+
* - APPLY: used by user-interaction handlers. The handler computes the full
|
|
54
|
+
* next state (including the new ISO value) and applies it atomically. This
|
|
55
|
+
* guarantees a single re-render with no cascades regardless of React version.
|
|
56
|
+
*
|
|
57
|
+
* - SET_VALUE: used by the `providedValue` prop effect. The reducer owns all
|
|
58
|
+
* parsing logic for external value changes, including the empty-string case
|
|
59
|
+
* that the previous useState approach missed.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
export const datePickerDefaultAriaLabel = 'Date';
|
|
63
|
+
export const timePickerDefaultAriaLabel = 'Time';
|
|
5
64
|
|
|
6
65
|
/**
|
|
7
66
|
* __Date time picker__
|
|
@@ -12,4 +71,394 @@ import DateTimePickerOld from './date-time-picker-fc-old';
|
|
|
12
71
|
* - [Code](https://atlassian.design/components/datetime-picker/code)
|
|
13
72
|
* - [Usage](https://atlassian.design/components/datetime-picker/usage)
|
|
14
73
|
*/
|
|
15
|
-
|
|
74
|
+
const DateTimePicker = /*#__PURE__*/forwardRef(({
|
|
75
|
+
'aria-describedby': ariaDescribedBy,
|
|
76
|
+
appearance = 'default',
|
|
77
|
+
autoFocus = false,
|
|
78
|
+
clearControlLabel = 'clear',
|
|
79
|
+
datePickerProps: datePickerPropsWithSelectProps = {},
|
|
80
|
+
defaultValue = '',
|
|
81
|
+
id = '',
|
|
82
|
+
innerProps = {},
|
|
83
|
+
isDisabled = false,
|
|
84
|
+
isInvalid = false,
|
|
85
|
+
isRequired = false,
|
|
86
|
+
name = '',
|
|
87
|
+
// These disables are here for proper typing when used as defaults. They
|
|
88
|
+
// should *not* use the `noop` function.
|
|
89
|
+
/* eslint-disable @repo/internal/react/use-noop */
|
|
90
|
+
onBlur = _event => {},
|
|
91
|
+
onChange: onChangeProp = _value => {},
|
|
92
|
+
onFocus = _event => {},
|
|
93
|
+
/* eslint-enable @repo/internal/react/use-noop */
|
|
94
|
+
parseValue: providedParseValue,
|
|
95
|
+
spacing = 'default',
|
|
96
|
+
locale = 'en-US',
|
|
97
|
+
testId,
|
|
98
|
+
timePickerProps: timePickerPropsWithSelectProps = {},
|
|
99
|
+
value: providedValue
|
|
100
|
+
}, _ref) => {
|
|
101
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Defined inside the component so the reducer closes over `providedParseValue`
|
|
105
|
+
* without needing to smuggle it through every action payload. React always
|
|
106
|
+
* calls the reducer from the latest render, so stale-closure is not a concern.
|
|
107
|
+
*/
|
|
108
|
+
const reducer = (state, action) => {
|
|
109
|
+
switch (action.type) {
|
|
110
|
+
case 'APPLY':
|
|
111
|
+
return action.payload;
|
|
112
|
+
case 'SET_VALUE':
|
|
113
|
+
{
|
|
114
|
+
const newValue = action.payload;
|
|
115
|
+
|
|
116
|
+
// Explicit empty-string handling: clear all sub-fields so the date
|
|
117
|
+
// and time pickers visually reset when a controlled value is cleared.
|
|
118
|
+
if (!newValue) {
|
|
119
|
+
return {
|
|
120
|
+
value: '',
|
|
121
|
+
dateValue: '',
|
|
122
|
+
timeValue: '',
|
|
123
|
+
zoneValue: ''
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (providedParseValue) {
|
|
127
|
+
const parsed = providedParseValue(newValue, state.dateValue, state.timeValue, state.zoneValue);
|
|
128
|
+
return parsed ? {
|
|
129
|
+
value: newValue,
|
|
130
|
+
...parsed
|
|
131
|
+
} : {
|
|
132
|
+
value: newValue,
|
|
133
|
+
dateValue: state.dateValue,
|
|
134
|
+
timeValue: state.timeValue,
|
|
135
|
+
zoneValue: state.zoneValue
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const parsed = parseISO(newValue);
|
|
139
|
+
return isValid(parsed) ? {
|
|
140
|
+
value: newValue,
|
|
141
|
+
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
142
|
+
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
143
|
+
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
144
|
+
} : {
|
|
145
|
+
value: newValue,
|
|
146
|
+
dateValue: '',
|
|
147
|
+
timeValue: '',
|
|
148
|
+
zoneValue: ''
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
default:
|
|
152
|
+
return state;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const [dtState, dispatch] = useReducer(reducer, null, () => {
|
|
156
|
+
const initialValue = providedValue || defaultValue || '';
|
|
157
|
+
const initialDate = (datePickerPropsWithSelectProps === null || datePickerPropsWithSelectProps === void 0 ? void 0 : datePickerPropsWithSelectProps.defaultValue) || '';
|
|
158
|
+
const initialTime = (timePickerPropsWithSelectProps === null || timePickerPropsWithSelectProps === void 0 ? void 0 : timePickerPropsWithSelectProps.defaultValue) || '';
|
|
159
|
+
if (!initialValue) {
|
|
160
|
+
return {
|
|
161
|
+
value: '',
|
|
162
|
+
dateValue: initialDate,
|
|
163
|
+
timeValue: initialTime,
|
|
164
|
+
zoneValue: ''
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (providedParseValue) {
|
|
168
|
+
const parsed = providedParseValue(initialValue, initialDate, initialTime, '');
|
|
169
|
+
return parsed ? {
|
|
170
|
+
value: initialValue,
|
|
171
|
+
...parsed
|
|
172
|
+
} : {
|
|
173
|
+
value: initialValue,
|
|
174
|
+
dateValue: initialDate,
|
|
175
|
+
timeValue: initialTime,
|
|
176
|
+
zoneValue: ''
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const parsed = parseISO(initialValue);
|
|
180
|
+
return isValid(parsed) ? {
|
|
181
|
+
value: initialValue,
|
|
182
|
+
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
183
|
+
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
184
|
+
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
185
|
+
} : {
|
|
186
|
+
value: initialValue,
|
|
187
|
+
dateValue: initialDate,
|
|
188
|
+
timeValue: initialTime,
|
|
189
|
+
zoneValue: ''
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (providedValue !== undefined) {
|
|
194
|
+
dispatch({
|
|
195
|
+
type: 'SET_VALUE',
|
|
196
|
+
payload: providedValue
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
200
|
+
}, [providedValue]);
|
|
201
|
+
const parseValue = useCallback((value, providedDateValue, providedTimeValue, providedZoneValue) => {
|
|
202
|
+
if (providedParseValue) {
|
|
203
|
+
const parsedFromFn = providedParseValue(value, providedDateValue, providedTimeValue, providedZoneValue);
|
|
204
|
+
// This handles cases found in Jira where the parse function actually does
|
|
205
|
+
// nothing and returns undefined. The previous `getSafeState` function
|
|
206
|
+
// just spread the values over the state, but if it returned `undefined`,
|
|
207
|
+
// it would just rely on the previous state values. Considering this is
|
|
208
|
+
// what is input to this function anyway, this is a safe way to handle
|
|
209
|
+
// this, colocate the behavior, and not rely on `getSafeState`.
|
|
210
|
+
return parsedFromFn || {
|
|
211
|
+
dateValue: providedDateValue,
|
|
212
|
+
timeValue: providedTimeValue,
|
|
213
|
+
zoneValue: providedZoneValue
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const parsed = parseISO(value);
|
|
217
|
+
return isValid(parsed) ? {
|
|
218
|
+
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
219
|
+
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
220
|
+
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
221
|
+
} : {
|
|
222
|
+
dateValue: dtState.dateValue,
|
|
223
|
+
timeValue: dtState.timeValue,
|
|
224
|
+
zoneValue: dtState.zoneValue
|
|
225
|
+
};
|
|
226
|
+
}, [providedParseValue, dtState.dateValue, dtState.timeValue, dtState.zoneValue]);
|
|
227
|
+
const onDateBlur = event => {
|
|
228
|
+
setIsFocused(false);
|
|
229
|
+
onBlur(event);
|
|
230
|
+
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onBlur) {
|
|
231
|
+
datePickerPropsWithSelectProps.onBlur(event);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const onTimeBlur = event => {
|
|
235
|
+
setIsFocused(false);
|
|
236
|
+
onBlur(event);
|
|
237
|
+
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onBlur) {
|
|
238
|
+
timePickerPropsWithSelectProps.onBlur(event);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const onDateFocus = event => {
|
|
242
|
+
setIsFocused(false);
|
|
243
|
+
onFocus(event);
|
|
244
|
+
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onFocus) {
|
|
245
|
+
datePickerPropsWithSelectProps.onFocus(event);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const onTimeFocus = event => {
|
|
249
|
+
setIsFocused(false);
|
|
250
|
+
onFocus(event);
|
|
251
|
+
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onFocus) {
|
|
252
|
+
timePickerPropsWithSelectProps.onFocus(event);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const onDateChange = newDateValue => {
|
|
256
|
+
const parsedValues = parseValue(dtState.value, newDateValue, dtState.timeValue, dtState.zoneValue);
|
|
257
|
+
onValueChange({
|
|
258
|
+
providedDateValue: newDateValue,
|
|
259
|
+
providedTimeValue: parsedValues.timeValue,
|
|
260
|
+
providedZoneValue: parsedValues.zoneValue
|
|
261
|
+
});
|
|
262
|
+
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
|
|
263
|
+
datePickerPropsWithSelectProps.onChange(newDateValue);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const onTimeChange = newTimeValue => {
|
|
267
|
+
const parsedValues = parseValue(dtState.value, dtState.dateValue, newTimeValue, dtState.zoneValue);
|
|
268
|
+
onValueChange({
|
|
269
|
+
providedDateValue: parsedValues.dateValue,
|
|
270
|
+
providedTimeValue: newTimeValue,
|
|
271
|
+
providedZoneValue: parsedValues.zoneValue
|
|
272
|
+
});
|
|
273
|
+
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
|
|
274
|
+
timePickerPropsWithSelectProps.onChange(newTimeValue);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
const onClear = () => {
|
|
278
|
+
const parsedValues = parseValue(dtState.value, dtState.dateValue, dtState.timeValue, dtState.zoneValue);
|
|
279
|
+
onValueChange({
|
|
280
|
+
providedDateValue: '',
|
|
281
|
+
providedTimeValue: '',
|
|
282
|
+
providedZoneValue: parsedValues.zoneValue
|
|
283
|
+
});
|
|
284
|
+
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
|
|
285
|
+
datePickerPropsWithSelectProps.onChange('');
|
|
286
|
+
}
|
|
287
|
+
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
|
|
288
|
+
timePickerPropsWithSelectProps.onChange('');
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const onChangePropWithAnalytics = usePlatformLeafEventHandler({
|
|
292
|
+
fn: onChangeProp,
|
|
293
|
+
action: 'selectedDate',
|
|
294
|
+
actionSubject: 'datePicker',
|
|
295
|
+
...analyticsAttributes
|
|
296
|
+
});
|
|
297
|
+
const onValueChange = ({
|
|
298
|
+
providedDateValue,
|
|
299
|
+
providedTimeValue,
|
|
300
|
+
providedZoneValue
|
|
301
|
+
}) => {
|
|
302
|
+
if (providedDateValue && providedTimeValue) {
|
|
303
|
+
const isoValue = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, providedZoneValue);
|
|
304
|
+
const {
|
|
305
|
+
zoneValue: parsedZone
|
|
306
|
+
} = parseValue(isoValue, providedDateValue, providedTimeValue, providedZoneValue);
|
|
307
|
+
const valueWithValidZone = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, parsedZone);
|
|
308
|
+
dispatch({
|
|
309
|
+
type: 'APPLY',
|
|
310
|
+
payload: {
|
|
311
|
+
value: valueWithValidZone,
|
|
312
|
+
dateValue: providedDateValue,
|
|
313
|
+
timeValue: providedTimeValue,
|
|
314
|
+
zoneValue: parsedZone
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
onChangePropWithAnalytics(valueWithValidZone);
|
|
318
|
+
// If the date or time value was cleared when there is an existing datetime value, then clear the value.
|
|
319
|
+
} else if (dtState.value) {
|
|
320
|
+
dispatch({
|
|
321
|
+
type: 'APPLY',
|
|
322
|
+
payload: {
|
|
323
|
+
value: '',
|
|
324
|
+
dateValue: providedDateValue,
|
|
325
|
+
timeValue: providedTimeValue,
|
|
326
|
+
zoneValue: providedZoneValue
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
onChangePropWithAnalytics('');
|
|
330
|
+
} else {
|
|
331
|
+
dispatch({
|
|
332
|
+
type: 'APPLY',
|
|
333
|
+
payload: {
|
|
334
|
+
value: '',
|
|
335
|
+
dateValue: providedDateValue,
|
|
336
|
+
timeValue: providedTimeValue,
|
|
337
|
+
zoneValue: providedZoneValue
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const {
|
|
343
|
+
selectProps: datePickerSelectProps,
|
|
344
|
+
...datePickerProps
|
|
345
|
+
} = datePickerPropsWithSelectProps;
|
|
346
|
+
const datePickerAriaDescribedBy = datePickerProps['aria-describedby'] || ariaDescribedBy;
|
|
347
|
+
const datePickerLabel = datePickerProps.label || 'Date';
|
|
348
|
+
const mergedDatePickerSelectProps = {
|
|
349
|
+
...datePickerSelectProps,
|
|
350
|
+
styles: mergeStyles(styles, datePickerSelectProps === null || datePickerSelectProps === void 0 ? void 0 : datePickerSelectProps.styles)
|
|
351
|
+
};
|
|
352
|
+
const {
|
|
353
|
+
selectProps: timePickerSelectProps,
|
|
354
|
+
...timePickerProps
|
|
355
|
+
} = timePickerPropsWithSelectProps;
|
|
356
|
+
const timePickerAriaDescribedBy = timePickerProps['aria-describedby'] || ariaDescribedBy;
|
|
357
|
+
const timePickerLabel = timePickerProps.label || 'Time';
|
|
358
|
+
const mergedTimePickerSelectProps = {
|
|
359
|
+
...timePickerSelectProps,
|
|
360
|
+
styles: mergeStyles(styles, timePickerSelectProps === null || timePickerSelectProps === void 0 ? void 0 : timePickerSelectProps.styles)
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// Render DateTimePicker's IconContainer when a value has been filled
|
|
364
|
+
// Don't use Date or TimePicker's because they can't be customised
|
|
365
|
+
const isClearable = Boolean(dtState.dateValue || dtState.timeValue);
|
|
366
|
+
return /*#__PURE__*/React.createElement(DateTimePickerContainer, {
|
|
367
|
+
appearance: appearance,
|
|
368
|
+
isDisabled: isDisabled,
|
|
369
|
+
isFocused: isFocused,
|
|
370
|
+
isInvalid: isInvalid,
|
|
371
|
+
testId: testId,
|
|
372
|
+
innerProps: innerProps
|
|
373
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
374
|
+
name: name,
|
|
375
|
+
type: "hidden",
|
|
376
|
+
value: dtState.value,
|
|
377
|
+
"data-testid": testId && `${testId}--input`
|
|
378
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
379
|
+
xcss: compiledStyles.datePickerContainerStyles
|
|
380
|
+
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
381
|
+
appearance: appearance,
|
|
382
|
+
"aria-describedby": datePickerAriaDescribedBy,
|
|
383
|
+
autoFocus: datePickerProps.autoFocus || autoFocus,
|
|
384
|
+
dateFormat: datePickerProps.dateFormat,
|
|
385
|
+
defaultIsOpen: datePickerProps.defaultIsOpen,
|
|
386
|
+
defaultValue: datePickerProps.defaultValue,
|
|
387
|
+
disabled: datePickerProps.disabled,
|
|
388
|
+
disabledDateFilter: datePickerProps.disabledDateFilter,
|
|
389
|
+
formatDisplayLabel: datePickerProps.formatDisplayLabel,
|
|
390
|
+
hideIcon: datePickerProps.hideIcon || true,
|
|
391
|
+
icon: datePickerProps.icon,
|
|
392
|
+
id: datePickerProps.id || id,
|
|
393
|
+
innerProps: datePickerProps.innerProps,
|
|
394
|
+
inputLabel: datePickerProps.inputLabel,
|
|
395
|
+
inputLabelId: datePickerProps.inputLabelId,
|
|
396
|
+
isDisabled: datePickerProps.isDisabled || isDisabled,
|
|
397
|
+
isInvalid: datePickerProps.isInvalid || isInvalid,
|
|
398
|
+
isOpen: datePickerProps.isOpen,
|
|
399
|
+
isRequired: datePickerProps.isRequired || isRequired,
|
|
400
|
+
label: datePickerLabel,
|
|
401
|
+
locale: datePickerProps.locale || locale,
|
|
402
|
+
maxDate: datePickerProps.maxDate,
|
|
403
|
+
minDate: datePickerProps.minDate,
|
|
404
|
+
name: datePickerProps.name,
|
|
405
|
+
nextMonthLabel: datePickerProps.nextMonthLabel,
|
|
406
|
+
onBlur: onDateBlur,
|
|
407
|
+
onChange: onDateChange,
|
|
408
|
+
onFocus: onDateFocus,
|
|
409
|
+
openCalendarLabel: datePickerProps.openCalendarLabel,
|
|
410
|
+
parseInputValue: datePickerProps.parseInputValue,
|
|
411
|
+
placeholder: datePickerProps.placeholder,
|
|
412
|
+
previousMonthLabel: datePickerProps.previousMonthLabel,
|
|
413
|
+
selectProps: mergedDatePickerSelectProps,
|
|
414
|
+
shouldShowCalendarButton: datePickerProps.shouldShowCalendarButton,
|
|
415
|
+
spacing: datePickerProps.spacing || spacing,
|
|
416
|
+
testId: testId && `${testId}--datepicker` || datePickerProps.testId,
|
|
417
|
+
value: dtState.dateValue,
|
|
418
|
+
weekStartDay: datePickerProps.weekStartDay
|
|
419
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
420
|
+
xcss: compiledStyles.timePickerContainerStyles
|
|
421
|
+
}, /*#__PURE__*/React.createElement(TimePicker, {
|
|
422
|
+
appearance: timePickerProps.appearance || appearance,
|
|
423
|
+
"aria-describedby": timePickerAriaDescribedBy,
|
|
424
|
+
autoFocus: timePickerProps.autoFocus,
|
|
425
|
+
defaultIsOpen: timePickerProps.defaultIsOpen,
|
|
426
|
+
defaultValue: timePickerProps.defaultValue,
|
|
427
|
+
formatDisplayLabel: timePickerProps.formatDisplayLabel,
|
|
428
|
+
hideIcon: timePickerProps.hideIcon || true,
|
|
429
|
+
id: timePickerProps.id,
|
|
430
|
+
innerProps: timePickerProps.innerProps,
|
|
431
|
+
isDisabled: timePickerProps.isDisabled || isDisabled,
|
|
432
|
+
isInvalid: timePickerProps.isInvalid || isInvalid,
|
|
433
|
+
isOpen: timePickerProps.isOpen,
|
|
434
|
+
isRequired: timePickerProps.isRequired || isRequired,
|
|
435
|
+
label: timePickerLabel,
|
|
436
|
+
locale: timePickerProps.locale || locale,
|
|
437
|
+
name: timePickerProps.name,
|
|
438
|
+
onBlur: onTimeBlur,
|
|
439
|
+
onChange: onTimeChange,
|
|
440
|
+
onFocus: onTimeFocus,
|
|
441
|
+
parseInputValue: timePickerProps.parseInputValue,
|
|
442
|
+
placeholder: timePickerProps.placeholder,
|
|
443
|
+
selectProps: mergedTimePickerSelectProps,
|
|
444
|
+
spacing: timePickerProps.spacing || spacing,
|
|
445
|
+
testId: timePickerProps.testId || testId && `${testId}--timepicker`,
|
|
446
|
+
timeFormat: timePickerProps.timeFormat,
|
|
447
|
+
timeIsEditable: timePickerProps.timeIsEditable,
|
|
448
|
+
times: timePickerProps.times,
|
|
449
|
+
value: dtState.timeValue
|
|
450
|
+
})), isClearable && !isDisabled ? /*#__PURE__*/React.createElement(Inline, {
|
|
451
|
+
xcss: compiledStyles.iconContainerStyles
|
|
452
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
453
|
+
appearance: "subtle",
|
|
454
|
+
label: clearControlLabel,
|
|
455
|
+
icon: iconProps => /*#__PURE__*/React.createElement(SelectClearIcon, _extends({}, iconProps, {
|
|
456
|
+
color: "var(--ds-text-subtlest, #6B6E76)",
|
|
457
|
+
size: "small"
|
|
458
|
+
})),
|
|
459
|
+
onClick: onClear,
|
|
460
|
+
testId: testId && `${testId}--icon--container`,
|
|
461
|
+
tabIndex: -1
|
|
462
|
+
})) : null);
|
|
463
|
+
});
|
|
464
|
+
export default DateTimePicker;
|
|
@@ -13,7 +13,7 @@ import parseTime from '../internal/parse-time';
|
|
|
13
13
|
import { convertTokens } from '../internal/parse-tokens';
|
|
14
14
|
import { makeSingleValue } from '../internal/single-value';
|
|
15
15
|
const packageName = "@atlaskit/datetime-picker";
|
|
16
|
-
const packageVersion = "
|
|
16
|
+
const packageVersion = "0.0.0-development";
|
|
17
17
|
const menuStyles = {
|
|
18
18
|
/* Need to remove default absolute positioning as that causes issues with position fixed */
|
|
19
19
|
position: 'static',
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const map24 = {
|
|
2
|
+
'12': '12',
|
|
3
|
+
'01': '13',
|
|
4
|
+
'02': '14',
|
|
5
|
+
'03': '15',
|
|
6
|
+
'04': '16',
|
|
7
|
+
'05': '17',
|
|
8
|
+
'06': '18',
|
|
9
|
+
'07': '19',
|
|
10
|
+
'08': '20',
|
|
11
|
+
'09': '21',
|
|
12
|
+
'10': '22',
|
|
13
|
+
'11': '23'
|
|
14
|
+
};
|
|
15
|
+
function formatSemi24(time) {
|
|
16
|
+
if (time.length === 1) {
|
|
17
|
+
return `0${time}00`;
|
|
18
|
+
}
|
|
19
|
+
if (time.length === 2) {
|
|
20
|
+
return `${time}00`;
|
|
21
|
+
}
|
|
22
|
+
if (time.length === 3 || time.length === 5) {
|
|
23
|
+
return `0${time}`;
|
|
24
|
+
}
|
|
25
|
+
return time;
|
|
26
|
+
}
|
|
27
|
+
function checkHour(hour, meridiem) {
|
|
28
|
+
if (hour > '24') {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (hour === '12' && meridiem === 'a') {
|
|
32
|
+
return '00';
|
|
33
|
+
}
|
|
34
|
+
if (hour < '12' && meridiem === 'p') {
|
|
35
|
+
return map24[hour];
|
|
36
|
+
}
|
|
37
|
+
return hour;
|
|
38
|
+
}
|
|
39
|
+
function checkMinuteSecond(value) {
|
|
40
|
+
if (value > '59') {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
export function convertTo24hrTime(time) {
|
|
46
|
+
const timeArray = time.toLowerCase().split(/(p|a)/i);
|
|
47
|
+
const meridiem = timeArray[1];
|
|
48
|
+
const semi24 = formatSemi24(timeArray[0].trim());
|
|
49
|
+
const hour = checkHour(semi24.substring(0, 2), meridiem);
|
|
50
|
+
const minute = checkMinuteSecond(semi24.substring(2, 4));
|
|
51
|
+
const seconds = semi24.length === 6 && checkMinuteSecond(semi24.substring(4, 6));
|
|
52
|
+
if (!hour || !minute) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
hour: parseInt(hour, 10),
|
|
57
|
+
minute: parseInt(minute, 10),
|
|
58
|
+
seconds: parseInt(seconds || '0', 10) || 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything in this file is to smooth out the migration of the new date picker
|
|
3
|
+
* (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
|
|
4
|
+
* complete, all of these functions will ilkely be merged back into the date
|
|
5
|
+
* picker. Please do not pre-optimize and put these back into the date picker
|
|
6
|
+
* unless you are working on the DTP Refresh and you have a good reason to do
|
|
7
|
+
* so, thank you!
|
|
8
|
+
*
|
|
9
|
+
* All variables within the `di` objects are dependency injections. They should
|
|
10
|
+
* be read from within the component at the end of the day. But because we are
|
|
11
|
+
* extracting them, we have to inject them in every place manually. When we
|
|
12
|
+
* re-introduce them to the components, we can likely remove the `di` variables
|
|
13
|
+
* and instead use internal variables.
|
|
14
|
+
*
|
|
15
|
+
* If component _only_ has injected variables, it is fully internal and was
|
|
16
|
+
* broken out to be it's own function.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// oxlint-disable-next-line @atlassian/no-restricted-imports
|
|
20
|
+
import { format, parseISO } from 'date-fns';
|
|
21
|
+
import { convertTokens } from './parse-tokens';
|
|
22
|
+
import { defaultDateFormat } from './index';
|
|
23
|
+
export const formatDate = (value, di) => {
|
|
24
|
+
const {
|
|
25
|
+
formatDisplayLabel,
|
|
26
|
+
dateFormat,
|
|
27
|
+
l10n
|
|
28
|
+
} = di;
|
|
29
|
+
if (formatDisplayLabel) {
|
|
30
|
+
return formatDisplayLabel(value, dateFormat || defaultDateFormat);
|
|
31
|
+
}
|
|
32
|
+
const date = parseISO(value);
|
|
33
|
+
return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
|
|
34
|
+
};
|
|
@@ -17,15 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
// oxlint-disable-next-line @atlassian/no-restricted-imports
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { defaultDateFormat, padToTwo, placeholderDatetime } from './index';
|
|
23
|
-
export const isDateDisabled = (date, di) => {
|
|
24
|
-
const {
|
|
25
|
-
disabled
|
|
26
|
-
} = di;
|
|
27
|
-
return disabled.indexOf(date) > -1;
|
|
28
|
-
};
|
|
20
|
+
import { lastDayOfMonth } from 'date-fns';
|
|
21
|
+
import { padToTwo } from './index';
|
|
29
22
|
export const getParsedISO = di => {
|
|
30
23
|
const {
|
|
31
24
|
iso
|
|
@@ -43,49 +36,4 @@ export const getParsedISO = di => {
|
|
|
43
36
|
newIso = `${parsedYear}-${padToTwo(parsedMonth)}-${padToTwo(parsedDate)}`;
|
|
44
37
|
}
|
|
45
38
|
return newIso;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* There are two props that can change how the date is parsed.
|
|
50
|
-
* The priority of props used is:
|
|
51
|
-
* 1. `parseInputValue`
|
|
52
|
-
* 2. `locale`
|
|
53
|
-
*/
|
|
54
|
-
export const parseDate = (date, di) => {
|
|
55
|
-
const {
|
|
56
|
-
parseInputValue,
|
|
57
|
-
dateFormat,
|
|
58
|
-
l10n
|
|
59
|
-
} = di;
|
|
60
|
-
if (parseInputValue) {
|
|
61
|
-
return parseInputValue(date, dateFormat || defaultDateFormat);
|
|
62
|
-
}
|
|
63
|
-
return l10n.parseDate(date);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* There are multiple props that can change how the date is formatted.
|
|
68
|
-
* The priority of props used is:
|
|
69
|
-
* 1. `formatDisplayLabel`
|
|
70
|
-
* 2. `dateFormat`
|
|
71
|
-
* 3. `locale`
|
|
72
|
-
*/
|
|
73
|
-
export const formatDate = (value, di) => {
|
|
74
|
-
const {
|
|
75
|
-
formatDisplayLabel,
|
|
76
|
-
dateFormat,
|
|
77
|
-
l10n
|
|
78
|
-
} = di;
|
|
79
|
-
if (formatDisplayLabel) {
|
|
80
|
-
return formatDisplayLabel(value, dateFormat || defaultDateFormat);
|
|
81
|
-
}
|
|
82
|
-
const date = parseISO(value);
|
|
83
|
-
return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
|
|
84
|
-
};
|
|
85
|
-
export const getPlaceholder = di => {
|
|
86
|
-
const {
|
|
87
|
-
placeholder,
|
|
88
|
-
l10n
|
|
89
|
-
} = di;
|
|
90
|
-
return placeholder || l10n.formatDate(placeholderDatetime);
|
|
91
39
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything in this file is to smooth out the migration of the new date picker
|
|
3
|
+
* (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
|
|
4
|
+
* complete, all of these functions will ilkely be merged back into the date
|
|
5
|
+
* picker. Please do not pre-optimize and put these back into the date picker
|
|
6
|
+
* unless you are working on the DTP Refresh and you have a good reason to do
|
|
7
|
+
* so, thank you!
|
|
8
|
+
*
|
|
9
|
+
* All variables within the `di` objects are dependency injections. They should
|
|
10
|
+
* be read from within the component at the end of the day. But because we are
|
|
11
|
+
* extracting them, we have to inject them in every place manually. When we
|
|
12
|
+
* re-introduce them to the components, we can likely remove the `di` variables
|
|
13
|
+
* and instead use internal variables.
|
|
14
|
+
*
|
|
15
|
+
* If component _only_ has injected variables, it is fully internal and was
|
|
16
|
+
* broken out to be it's own function.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// oxlint-disable-next-line @atlassian/no-restricted-imports
|
|
20
|
+
|
|
21
|
+
import { placeholderDatetime } from './index';
|
|
22
|
+
export const getPlaceholder = di => {
|
|
23
|
+
const {
|
|
24
|
+
placeholder,
|
|
25
|
+
l10n
|
|
26
|
+
} = di;
|
|
27
|
+
return placeholder || l10n.formatDate(placeholderDatetime);
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// oxlint-disable-next-line @atlassian/no-restricted-imports
|
|
2
|
+
import { getShortISOString } from './get-short-iso-string';
|
|
3
|
+
export function getSafeCalendarValue(calendarValue) {
|
|
4
|
+
// If `calendarValue` has a year that is greater than 9999, default to
|
|
5
|
+
// today's date
|
|
6
|
+
const yearIsOverLimit = calendarValue.match(/^\d{5,}/);
|
|
7
|
+
if (yearIsOverLimit) {
|
|
8
|
+
return getShortISOString(new Date());
|
|
9
|
+
}
|
|
10
|
+
return calendarValue;
|
|
11
|
+
}
|