@atlaskit/datetime-picker 17.6.5 → 17.8.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 +14 -0
- package/date-picker/package.json +17 -0
- package/date-time-picker/package.json +17 -0
- package/dist/cjs/components/date-picker.js +20 -15
- package/dist/cjs/components/date-time-picker-class.js +7 -9
- package/dist/cjs/components/date-time-picker-fc.js +468 -7
- package/dist/cjs/components/time-picker.js +11 -8
- package/dist/cjs/entry-points/date-picker.js +13 -0
- package/dist/cjs/entry-points/date-time-picker.js +13 -0
- package/dist/cjs/entry-points/time-picker.js +13 -0
- package/dist/cjs/entry-points/types.js +1 -0
- package/dist/cjs/internal/convert-to24hr-time.js +66 -0
- package/dist/cjs/internal/default-date-format.js +7 -0
- package/dist/cjs/internal/default-times.js +7 -0
- package/dist/cjs/internal/empty-component.js +12 -0
- package/dist/cjs/internal/format-date-time-zone-into-iso.js +15 -0
- package/dist/cjs/internal/format-date.js +39 -0
- package/dist/cjs/internal/{date-picker-migration.js → get-parsed-iso.js} +4 -48
- 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/pad-two.js +9 -0
- package/dist/cjs/internal/parse-date.js +31 -20
- package/dist/cjs/internal/parse-time.js +6 -102
- package/dist/cjs/internal/placeholder-date-time.js +9 -0
- package/dist/cjs/internal/remove-spacer.js +9 -0
- package/dist/es2019/components/date-picker.js +9 -4
- package/dist/es2019/components/date-time-picker-class.js +4 -6
- package/dist/es2019/components/date-time-picker-fc.js +451 -5
- package/dist/es2019/components/time-picker.js +5 -2
- package/dist/es2019/entry-points/date-picker.js +1 -0
- package/dist/es2019/entry-points/date-time-picker.js +1 -0
- package/dist/es2019/entry-points/time-picker.js +1 -0
- package/dist/es2019/entry-points/types.js +0 -0
- package/dist/es2019/internal/convert-to24hr-time.js +60 -0
- package/dist/es2019/internal/default-date-format.js +1 -0
- package/dist/es2019/internal/default-times.js +1 -0
- package/dist/es2019/internal/empty-component.js +4 -0
- package/dist/es2019/internal/format-date-time-zone-into-iso.js +9 -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/pad-two.js +3 -0
- package/dist/es2019/internal/parse-date.js +33 -18
- package/dist/es2019/internal/parse-time.js +3 -96
- package/dist/es2019/internal/placeholder-date-time.js +3 -0
- package/dist/es2019/internal/remove-spacer.js +3 -0
- package/dist/esm/components/date-picker.js +9 -4
- package/dist/esm/components/date-time-picker-class.js +4 -6
- package/dist/esm/components/date-time-picker-fc.js +468 -7
- package/dist/esm/components/time-picker.js +5 -2
- package/dist/esm/entry-points/date-picker.js +1 -0
- package/dist/esm/entry-points/date-time-picker.js +1 -0
- package/dist/esm/entry-points/time-picker.js +1 -0
- package/dist/esm/entry-points/types.js +0 -0
- package/dist/esm/internal/convert-to24hr-time.js +60 -0
- package/dist/esm/internal/default-date-format.js +1 -0
- package/dist/esm/internal/default-times.js +1 -0
- package/dist/esm/internal/empty-component.js +6 -0
- package/dist/esm/internal/format-date-time-zone-into-iso.js +9 -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/pad-two.js +3 -0
- package/dist/esm/internal/parse-date.js +31 -18
- package/dist/esm/internal/parse-time.js +3 -96
- package/dist/esm/internal/placeholder-date-time.js +3 -0
- package/dist/esm/internal/remove-spacer.js +3 -0
- package/dist/types/components/date-time-picker-class.d.ts +0 -2
- package/dist/types/components/date-time-picker-fc.d.ts +4 -2
- package/dist/types/entry-points/date-picker.d.ts +2 -0
- package/dist/types/entry-points/date-time-picker.d.ts +1 -0
- package/dist/types/entry-points/time-picker.d.ts +1 -0
- package/dist/types/entry-points/types.d.ts +1 -0
- package/dist/types/internal/convert-to24hr-time.d.ts +7 -0
- package/dist/types/internal/default-date-format.d.ts +1 -0
- package/dist/types/internal/default-times.d.ts +1 -0
- package/dist/types/internal/empty-component.d.ts +4 -0
- package/dist/types/internal/format-date-time-zone-into-iso.d.ts +4 -0
- package/dist/{types-ts4.5/internal/date-picker-migration.d.ts → types/internal/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/pad-two.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/placeholder-date-time.d.ts +1 -0
- package/dist/types/internal/remove-spacer.d.ts +1 -0
- package/dist/types-ts4.5/components/date-time-picker-class.d.ts +0 -2
- package/dist/types-ts4.5/components/date-time-picker-fc.d.ts +4 -2
- package/dist/types-ts4.5/entry-points/date-picker.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/date-time-picker.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/time-picker.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/types.d.ts +1 -0
- package/dist/types-ts4.5/internal/convert-to24hr-time.d.ts +7 -0
- package/dist/types-ts4.5/internal/default-date-format.d.ts +1 -0
- package/dist/types-ts4.5/internal/default-times.d.ts +1 -0
- package/dist/types-ts4.5/internal/empty-component.d.ts +4 -0
- package/dist/types-ts4.5/internal/format-date-time-zone-into-iso.d.ts +4 -0
- package/dist/{types/internal/date-picker-migration.d.ts → types-ts4.5/internal/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/pad-two.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/placeholder-date-time.d.ts +1 -0
- package/dist/types-ts4.5/internal/remove-spacer.d.ts +1 -0
- package/package.json +11 -14
- package/time-picker/package.json +17 -0
- package/types/package.json +5 -5
- 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/cjs/internal/index.js +0 -31
- 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/es2019/internal/index.js +0 -20
- 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/esm/internal/index.js +0 -22
- 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/internal/index.d.ts +0 -10
- 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/types-ts4.5/internal/index.d.ts +0 -10
- package/offerings.json +0 -98
- /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,456 +0,0 @@
|
|
|
1
|
-
/* date-time-picker-fc-new.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
-
import "./date-time-picker-fc-new.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 = "17.6.5";
|
|
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';
|
|
64
|
-
const DateTimePickerNew = /*#__PURE__*/forwardRef(({
|
|
65
|
-
'aria-describedby': ariaDescribedBy,
|
|
66
|
-
appearance = 'default',
|
|
67
|
-
autoFocus = false,
|
|
68
|
-
clearControlLabel = 'clear',
|
|
69
|
-
datePickerProps: datePickerPropsWithSelectProps = {},
|
|
70
|
-
defaultValue = '',
|
|
71
|
-
id = '',
|
|
72
|
-
innerProps = {},
|
|
73
|
-
isDisabled = false,
|
|
74
|
-
isInvalid = false,
|
|
75
|
-
isRequired = false,
|
|
76
|
-
name = '',
|
|
77
|
-
// These disables are here for proper typing when used as defaults. They
|
|
78
|
-
// should *not* use the `noop` function.
|
|
79
|
-
/* eslint-disable @repo/internal/react/use-noop */
|
|
80
|
-
onBlur = _event => {},
|
|
81
|
-
onChange: onChangeProp = _value => {},
|
|
82
|
-
onFocus = _event => {},
|
|
83
|
-
/* eslint-enable @repo/internal/react/use-noop */
|
|
84
|
-
parseValue: providedParseValue,
|
|
85
|
-
spacing = 'default',
|
|
86
|
-
locale = 'en-US',
|
|
87
|
-
testId,
|
|
88
|
-
timePickerProps: timePickerPropsWithSelectProps = {},
|
|
89
|
-
value: providedValue
|
|
90
|
-
}, _ref) => {
|
|
91
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Defined inside the component so the reducer closes over `providedParseValue`
|
|
95
|
-
* without needing to smuggle it through every action payload. React always
|
|
96
|
-
* calls the reducer from the latest render, so stale-closure is not a concern.
|
|
97
|
-
*/
|
|
98
|
-
const reducer = (state, action) => {
|
|
99
|
-
switch (action.type) {
|
|
100
|
-
case 'APPLY':
|
|
101
|
-
return action.payload;
|
|
102
|
-
case 'SET_VALUE':
|
|
103
|
-
{
|
|
104
|
-
const newValue = action.payload;
|
|
105
|
-
|
|
106
|
-
// Explicit empty-string handling: clear all sub-fields so the date
|
|
107
|
-
// and time pickers visually reset when a controlled value is cleared.
|
|
108
|
-
if (!newValue) {
|
|
109
|
-
return {
|
|
110
|
-
value: '',
|
|
111
|
-
dateValue: '',
|
|
112
|
-
timeValue: '',
|
|
113
|
-
zoneValue: ''
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
if (providedParseValue) {
|
|
117
|
-
const parsed = providedParseValue(newValue, state.dateValue, state.timeValue, state.zoneValue);
|
|
118
|
-
return parsed ? {
|
|
119
|
-
value: newValue,
|
|
120
|
-
...parsed
|
|
121
|
-
} : {
|
|
122
|
-
value: newValue,
|
|
123
|
-
dateValue: state.dateValue,
|
|
124
|
-
timeValue: state.timeValue,
|
|
125
|
-
zoneValue: state.zoneValue
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const parsed = parseISO(newValue);
|
|
129
|
-
return isValid(parsed) ? {
|
|
130
|
-
value: newValue,
|
|
131
|
-
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
132
|
-
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
133
|
-
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
134
|
-
} : {
|
|
135
|
-
value: newValue,
|
|
136
|
-
dateValue: '',
|
|
137
|
-
timeValue: '',
|
|
138
|
-
zoneValue: ''
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
default:
|
|
142
|
-
return state;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
const [dtState, dispatch] = useReducer(reducer, null, () => {
|
|
146
|
-
const initialValue = providedValue || defaultValue || '';
|
|
147
|
-
const initialDate = (datePickerPropsWithSelectProps === null || datePickerPropsWithSelectProps === void 0 ? void 0 : datePickerPropsWithSelectProps.defaultValue) || '';
|
|
148
|
-
const initialTime = (timePickerPropsWithSelectProps === null || timePickerPropsWithSelectProps === void 0 ? void 0 : timePickerPropsWithSelectProps.defaultValue) || '';
|
|
149
|
-
if (!initialValue) {
|
|
150
|
-
return {
|
|
151
|
-
value: '',
|
|
152
|
-
dateValue: initialDate,
|
|
153
|
-
timeValue: initialTime,
|
|
154
|
-
zoneValue: ''
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (providedParseValue) {
|
|
158
|
-
const parsed = providedParseValue(initialValue, initialDate, initialTime, '');
|
|
159
|
-
return parsed ? {
|
|
160
|
-
value: initialValue,
|
|
161
|
-
...parsed
|
|
162
|
-
} : {
|
|
163
|
-
value: initialValue,
|
|
164
|
-
dateValue: initialDate,
|
|
165
|
-
timeValue: initialTime,
|
|
166
|
-
zoneValue: ''
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
const parsed = parseISO(initialValue);
|
|
170
|
-
return isValid(parsed) ? {
|
|
171
|
-
value: initialValue,
|
|
172
|
-
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
173
|
-
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
174
|
-
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
175
|
-
} : {
|
|
176
|
-
value: initialValue,
|
|
177
|
-
dateValue: initialDate,
|
|
178
|
-
timeValue: initialTime,
|
|
179
|
-
zoneValue: ''
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
useEffect(() => {
|
|
183
|
-
if (providedValue !== undefined) {
|
|
184
|
-
dispatch({
|
|
185
|
-
type: 'SET_VALUE',
|
|
186
|
-
payload: providedValue
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
190
|
-
}, [providedValue]);
|
|
191
|
-
const parseValue = useCallback((value, providedDateValue, providedTimeValue, providedZoneValue) => {
|
|
192
|
-
if (providedParseValue) {
|
|
193
|
-
const parsedFromFn = providedParseValue(value, providedDateValue, providedTimeValue, providedZoneValue);
|
|
194
|
-
// This handles cases found in Jira where the parse function actually does
|
|
195
|
-
// nothing and returns undefined. The previous `getSafeState` function
|
|
196
|
-
// just spread the values over the state, but if it returned `undefined`,
|
|
197
|
-
// it would just rely on the previous state values. Considering this is
|
|
198
|
-
// what is input to this function anyway, this is a safe way to handle
|
|
199
|
-
// this, colocate the behavior, and not rely on `getSafeState`.
|
|
200
|
-
return parsedFromFn || {
|
|
201
|
-
dateValue: providedDateValue,
|
|
202
|
-
timeValue: providedTimeValue,
|
|
203
|
-
zoneValue: providedZoneValue
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
const parsed = parseISO(value);
|
|
207
|
-
return isValid(parsed) ? {
|
|
208
|
-
dateValue: format(parsed, convertTokens('YYYY-MM-DD')),
|
|
209
|
-
timeValue: format(parsed, convertTokens('HH:mm')),
|
|
210
|
-
zoneValue: format(parsed, convertTokens('ZZ'))
|
|
211
|
-
} : {
|
|
212
|
-
dateValue: dtState.dateValue,
|
|
213
|
-
timeValue: dtState.timeValue,
|
|
214
|
-
zoneValue: dtState.zoneValue
|
|
215
|
-
};
|
|
216
|
-
}, [providedParseValue, dtState.dateValue, dtState.timeValue, dtState.zoneValue]);
|
|
217
|
-
const onDateBlur = event => {
|
|
218
|
-
setIsFocused(false);
|
|
219
|
-
onBlur(event);
|
|
220
|
-
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onBlur) {
|
|
221
|
-
datePickerPropsWithSelectProps.onBlur(event);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
const onTimeBlur = event => {
|
|
225
|
-
setIsFocused(false);
|
|
226
|
-
onBlur(event);
|
|
227
|
-
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onBlur) {
|
|
228
|
-
timePickerPropsWithSelectProps.onBlur(event);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
const onDateFocus = event => {
|
|
232
|
-
setIsFocused(false);
|
|
233
|
-
onFocus(event);
|
|
234
|
-
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onFocus) {
|
|
235
|
-
datePickerPropsWithSelectProps.onFocus(event);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
const onTimeFocus = event => {
|
|
239
|
-
setIsFocused(false);
|
|
240
|
-
onFocus(event);
|
|
241
|
-
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onFocus) {
|
|
242
|
-
timePickerPropsWithSelectProps.onFocus(event);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
const onDateChange = newDateValue => {
|
|
246
|
-
const parsedValues = parseValue(dtState.value, newDateValue, dtState.timeValue, dtState.zoneValue);
|
|
247
|
-
onValueChange({
|
|
248
|
-
providedDateValue: newDateValue,
|
|
249
|
-
providedTimeValue: parsedValues.timeValue,
|
|
250
|
-
providedZoneValue: parsedValues.zoneValue
|
|
251
|
-
});
|
|
252
|
-
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
|
|
253
|
-
datePickerPropsWithSelectProps.onChange(newDateValue);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
const onTimeChange = newTimeValue => {
|
|
257
|
-
const parsedValues = parseValue(dtState.value, dtState.dateValue, newTimeValue, dtState.zoneValue);
|
|
258
|
-
onValueChange({
|
|
259
|
-
providedDateValue: parsedValues.dateValue,
|
|
260
|
-
providedTimeValue: newTimeValue,
|
|
261
|
-
providedZoneValue: parsedValues.zoneValue
|
|
262
|
-
});
|
|
263
|
-
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
|
|
264
|
-
timePickerPropsWithSelectProps.onChange(newTimeValue);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
const onClear = () => {
|
|
268
|
-
const parsedValues = parseValue(dtState.value, dtState.dateValue, dtState.timeValue, dtState.zoneValue);
|
|
269
|
-
onValueChange({
|
|
270
|
-
providedDateValue: '',
|
|
271
|
-
providedTimeValue: '',
|
|
272
|
-
providedZoneValue: parsedValues.zoneValue
|
|
273
|
-
});
|
|
274
|
-
if (datePickerPropsWithSelectProps !== null && datePickerPropsWithSelectProps !== void 0 && datePickerPropsWithSelectProps.onChange) {
|
|
275
|
-
datePickerPropsWithSelectProps.onChange('');
|
|
276
|
-
}
|
|
277
|
-
if (timePickerPropsWithSelectProps !== null && timePickerPropsWithSelectProps !== void 0 && timePickerPropsWithSelectProps.onChange) {
|
|
278
|
-
timePickerPropsWithSelectProps.onChange('');
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
const onChangePropWithAnalytics = usePlatformLeafEventHandler({
|
|
282
|
-
fn: onChangeProp,
|
|
283
|
-
action: 'selectedDate',
|
|
284
|
-
actionSubject: 'datePicker',
|
|
285
|
-
...analyticsAttributes
|
|
286
|
-
});
|
|
287
|
-
const onValueChange = ({
|
|
288
|
-
providedDateValue,
|
|
289
|
-
providedTimeValue,
|
|
290
|
-
providedZoneValue
|
|
291
|
-
}) => {
|
|
292
|
-
if (providedDateValue && providedTimeValue) {
|
|
293
|
-
const isoValue = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, providedZoneValue);
|
|
294
|
-
const {
|
|
295
|
-
zoneValue: parsedZone
|
|
296
|
-
} = parseValue(isoValue, providedDateValue, providedTimeValue, providedZoneValue);
|
|
297
|
-
const valueWithValidZone = formatDateTimeZoneIntoIso(providedDateValue, providedTimeValue, parsedZone);
|
|
298
|
-
dispatch({
|
|
299
|
-
type: 'APPLY',
|
|
300
|
-
payload: {
|
|
301
|
-
value: valueWithValidZone,
|
|
302
|
-
dateValue: providedDateValue,
|
|
303
|
-
timeValue: providedTimeValue,
|
|
304
|
-
zoneValue: parsedZone
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
onChangePropWithAnalytics(valueWithValidZone);
|
|
308
|
-
// If the date or time value was cleared when there is an existing datetime value, then clear the value.
|
|
309
|
-
} else if (dtState.value) {
|
|
310
|
-
dispatch({
|
|
311
|
-
type: 'APPLY',
|
|
312
|
-
payload: {
|
|
313
|
-
value: '',
|
|
314
|
-
dateValue: providedDateValue,
|
|
315
|
-
timeValue: providedTimeValue,
|
|
316
|
-
zoneValue: providedZoneValue
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
onChangePropWithAnalytics('');
|
|
320
|
-
} else {
|
|
321
|
-
dispatch({
|
|
322
|
-
type: 'APPLY',
|
|
323
|
-
payload: {
|
|
324
|
-
value: '',
|
|
325
|
-
dateValue: providedDateValue,
|
|
326
|
-
timeValue: providedTimeValue,
|
|
327
|
-
zoneValue: providedZoneValue
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
const {
|
|
333
|
-
selectProps: datePickerSelectProps,
|
|
334
|
-
...datePickerProps
|
|
335
|
-
} = datePickerPropsWithSelectProps;
|
|
336
|
-
const datePickerAriaDescribedBy = datePickerProps['aria-describedby'] || ariaDescribedBy;
|
|
337
|
-
const datePickerLabel = datePickerProps.label || 'Date';
|
|
338
|
-
const mergedDatePickerSelectProps = {
|
|
339
|
-
...datePickerSelectProps,
|
|
340
|
-
styles: mergeStyles(styles, datePickerSelectProps === null || datePickerSelectProps === void 0 ? void 0 : datePickerSelectProps.styles)
|
|
341
|
-
};
|
|
342
|
-
const {
|
|
343
|
-
selectProps: timePickerSelectProps,
|
|
344
|
-
...timePickerProps
|
|
345
|
-
} = timePickerPropsWithSelectProps;
|
|
346
|
-
const timePickerAriaDescribedBy = timePickerProps['aria-describedby'] || ariaDescribedBy;
|
|
347
|
-
const timePickerLabel = timePickerProps.label || 'Time';
|
|
348
|
-
const mergedTimePickerSelectProps = {
|
|
349
|
-
...timePickerSelectProps,
|
|
350
|
-
styles: mergeStyles(styles, timePickerSelectProps === null || timePickerSelectProps === void 0 ? void 0 : timePickerSelectProps.styles)
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
// Render DateTimePicker's IconContainer when a value has been filled
|
|
354
|
-
// Don't use Date or TimePicker's because they can't be customised
|
|
355
|
-
const isClearable = Boolean(dtState.dateValue || dtState.timeValue);
|
|
356
|
-
return /*#__PURE__*/React.createElement(DateTimePickerContainer, {
|
|
357
|
-
appearance: appearance,
|
|
358
|
-
isDisabled: isDisabled,
|
|
359
|
-
isFocused: isFocused,
|
|
360
|
-
isInvalid: isInvalid,
|
|
361
|
-
testId: testId,
|
|
362
|
-
innerProps: innerProps
|
|
363
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
364
|
-
name: name,
|
|
365
|
-
type: "hidden",
|
|
366
|
-
value: dtState.value,
|
|
367
|
-
"data-testid": testId && `${testId}--input`
|
|
368
|
-
}), /*#__PURE__*/React.createElement(Box, {
|
|
369
|
-
xcss: compiledStyles.datePickerContainerStyles
|
|
370
|
-
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
371
|
-
appearance: appearance,
|
|
372
|
-
"aria-describedby": datePickerAriaDescribedBy,
|
|
373
|
-
autoFocus: datePickerProps.autoFocus || autoFocus,
|
|
374
|
-
dateFormat: datePickerProps.dateFormat,
|
|
375
|
-
defaultIsOpen: datePickerProps.defaultIsOpen,
|
|
376
|
-
defaultValue: datePickerProps.defaultValue,
|
|
377
|
-
disabled: datePickerProps.disabled,
|
|
378
|
-
disabledDateFilter: datePickerProps.disabledDateFilter,
|
|
379
|
-
formatDisplayLabel: datePickerProps.formatDisplayLabel,
|
|
380
|
-
hideIcon: datePickerProps.hideIcon || true,
|
|
381
|
-
icon: datePickerProps.icon,
|
|
382
|
-
id: datePickerProps.id || id,
|
|
383
|
-
innerProps: datePickerProps.innerProps,
|
|
384
|
-
inputLabel: datePickerProps.inputLabel,
|
|
385
|
-
inputLabelId: datePickerProps.inputLabelId,
|
|
386
|
-
isDisabled: datePickerProps.isDisabled || isDisabled,
|
|
387
|
-
isInvalid: datePickerProps.isInvalid || isInvalid,
|
|
388
|
-
isOpen: datePickerProps.isOpen,
|
|
389
|
-
isRequired: datePickerProps.isRequired || isRequired,
|
|
390
|
-
label: datePickerLabel,
|
|
391
|
-
locale: datePickerProps.locale || locale,
|
|
392
|
-
maxDate: datePickerProps.maxDate,
|
|
393
|
-
minDate: datePickerProps.minDate,
|
|
394
|
-
name: datePickerProps.name,
|
|
395
|
-
nextMonthLabel: datePickerProps.nextMonthLabel,
|
|
396
|
-
onBlur: onDateBlur,
|
|
397
|
-
onChange: onDateChange,
|
|
398
|
-
onFocus: onDateFocus,
|
|
399
|
-
openCalendarLabel: datePickerProps.openCalendarLabel,
|
|
400
|
-
parseInputValue: datePickerProps.parseInputValue,
|
|
401
|
-
placeholder: datePickerProps.placeholder,
|
|
402
|
-
previousMonthLabel: datePickerProps.previousMonthLabel,
|
|
403
|
-
selectProps: mergedDatePickerSelectProps,
|
|
404
|
-
shouldShowCalendarButton: datePickerProps.shouldShowCalendarButton,
|
|
405
|
-
spacing: datePickerProps.spacing || spacing,
|
|
406
|
-
testId: testId && `${testId}--datepicker` || datePickerProps.testId,
|
|
407
|
-
value: dtState.dateValue,
|
|
408
|
-
weekStartDay: datePickerProps.weekStartDay
|
|
409
|
-
})), /*#__PURE__*/React.createElement(Box, {
|
|
410
|
-
xcss: compiledStyles.timePickerContainerStyles
|
|
411
|
-
}, /*#__PURE__*/React.createElement(TimePicker, {
|
|
412
|
-
appearance: timePickerProps.appearance || appearance,
|
|
413
|
-
"aria-describedby": timePickerAriaDescribedBy,
|
|
414
|
-
autoFocus: timePickerProps.autoFocus,
|
|
415
|
-
defaultIsOpen: timePickerProps.defaultIsOpen,
|
|
416
|
-
defaultValue: timePickerProps.defaultValue,
|
|
417
|
-
formatDisplayLabel: timePickerProps.formatDisplayLabel,
|
|
418
|
-
hideIcon: timePickerProps.hideIcon || true,
|
|
419
|
-
id: timePickerProps.id,
|
|
420
|
-
innerProps: timePickerProps.innerProps,
|
|
421
|
-
isDisabled: timePickerProps.isDisabled || isDisabled,
|
|
422
|
-
isInvalid: timePickerProps.isInvalid || isInvalid,
|
|
423
|
-
isOpen: timePickerProps.isOpen,
|
|
424
|
-
isRequired: timePickerProps.isRequired || isRequired,
|
|
425
|
-
label: timePickerLabel,
|
|
426
|
-
locale: timePickerProps.locale || locale,
|
|
427
|
-
name: timePickerProps.name,
|
|
428
|
-
onBlur: onTimeBlur,
|
|
429
|
-
onChange: onTimeChange,
|
|
430
|
-
onFocus: onTimeFocus,
|
|
431
|
-
parseInputValue: timePickerProps.parseInputValue,
|
|
432
|
-
placeholder: timePickerProps.placeholder,
|
|
433
|
-
selectProps: mergedTimePickerSelectProps,
|
|
434
|
-
spacing: timePickerProps.spacing || spacing,
|
|
435
|
-
testId: timePickerProps.testId || testId && `${testId}--timepicker`,
|
|
436
|
-
timeFormat: timePickerProps.timeFormat,
|
|
437
|
-
timeIsEditable: timePickerProps.timeIsEditable,
|
|
438
|
-
times: timePickerProps.times,
|
|
439
|
-
value: dtState.timeValue
|
|
440
|
-
})), isClearable && !isDisabled ? /*#__PURE__*/React.createElement(Inline, {
|
|
441
|
-
xcss: compiledStyles.iconContainerStyles
|
|
442
|
-
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
443
|
-
appearance: "subtle",
|
|
444
|
-
label: clearControlLabel,
|
|
445
|
-
icon: iconProps => /*#__PURE__*/React.createElement(SelectClearIcon, _extends({}, iconProps, {
|
|
446
|
-
color: "var(--ds-text-subtlest, #6B6E76)",
|
|
447
|
-
size: "small"
|
|
448
|
-
})),
|
|
449
|
-
onClick: onClear,
|
|
450
|
-
testId: testId && `${testId}--icon--container`,
|
|
451
|
-
tabIndex: -1
|
|
452
|
-
})) : null);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
456
|
-
export default DateTimePickerNew;
|