@autoguru/overdrive 4.45.2 → 4.47.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/dist/components/Calendar/Calendar.css.d.ts +8 -0
- package/dist/components/Calendar/Calendar.css.d.ts.map +1 -0
- package/dist/components/Calendar/Calendar.css.js +113 -0
- package/dist/components/Calendar/Calendar.d.ts +64 -0
- package/dist/components/Calendar/Calendar.d.ts.map +1 -0
- package/dist/components/Calendar/Calendar.js +122 -0
- package/dist/components/Calendar/CalendarButton.d.ts +7 -0
- package/dist/components/Calendar/CalendarButton.d.ts.map +1 -0
- package/dist/components/{DateTimePicker → Calendar}/CalendarButton.js +4 -3
- package/dist/components/{DateTimePicker → Calendar}/CalendarGrid.d.ts +4 -1
- package/dist/components/Calendar/CalendarGrid.d.ts.map +1 -0
- package/dist/components/{DateTimePicker → Calendar}/CalendarGrid.js +8 -7
- package/dist/components/Calendar/index.d.ts +3 -0
- package/dist/components/Calendar/index.d.ts.map +1 -0
- package/dist/components/Calendar/index.js +3 -0
- package/dist/components/DatePicker/DatePicker.css.d.ts +2 -1
- package/dist/components/DatePicker/DatePicker.css.d.ts.map +1 -1
- package/dist/components/DatePicker/DatePicker.css.js +60 -30
- package/dist/components/DatePicker/DatePicker.d.ts +83 -5
- package/dist/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/components/DatePicker/DatePicker.js +160 -43
- package/dist/components/DateTimePicker/DateTimePicker.css.d.ts +0 -15
- package/dist/components/DateTimePicker/DateTimePicker.css.d.ts.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.css.js +16 -99
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +5 -2
- package/dist/components/DateTimePicker/DateTimePicker.d.ts.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.js +24 -80
- package/dist/components/OptionGrid/OptionGrid.css.d.ts +33 -34
- package/dist/components/OptionGrid/OptionGrid.css.d.ts.map +1 -1
- package/dist/components/OptionGrid/OptionGrid.css.js +208 -146
- package/dist/components/OptionGrid/OptionGrid.d.ts +16 -5
- package/dist/components/OptionGrid/OptionGrid.d.ts.map +1 -1
- package/dist/components/OptionGrid/OptionGrid.js +38 -13
- package/dist/components/OptionList/OptionList.css.d.ts +2 -10
- package/dist/components/OptionList/OptionList.css.d.ts.map +1 -1
- package/dist/components/OptionList/OptionList.css.js +92 -92
- package/dist/components/OptionList/OptionList.d.ts +10 -3
- package/dist/components/OptionList/OptionList.d.ts.map +1 -1
- package/dist/components/OptionList/OptionListItem.js +3 -3
- package/dist/components/Popover/Popover.css.d.ts +4 -0
- package/dist/components/Popover/Popover.css.d.ts.map +1 -0
- package/dist/components/Popover/Popover.css.js +46 -0
- package/dist/components/Popover/Popover.d.ts +34 -0
- package/dist/components/Popover/Popover.d.ts.map +1 -0
- package/dist/components/Popover/Popover.js +127 -0
- package/dist/components/Popover/PopoverTrigger.d.ts +51 -0
- package/dist/components/Popover/PopoverTrigger.d.ts.map +1 -0
- package/dist/components/Popover/PopoverTrigger.js +94 -0
- package/dist/components/Popover/index.d.ts +5 -0
- package/dist/components/Popover/index.d.ts.map +1 -0
- package/dist/components/Popover/index.js +4 -0
- package/dist/components/SearchBar/SearchBar.css.d.ts +7 -12
- package/dist/components/SearchBar/SearchBar.css.d.ts.map +1 -1
- package/dist/components/SearchBar/SearchBar.css.js +121 -66
- package/dist/components/SearchBar/SearchBar.d.ts.map +1 -1
- package/dist/components/SearchBar/SearchBar.js +17 -10
- package/dist/components/Slider/Slider.css.d.ts +9 -0
- package/dist/components/Slider/Slider.css.d.ts.map +1 -0
- package/dist/components/Slider/Slider.css.js +92 -0
- package/dist/components/Slider/Slider.d.ts +47 -0
- package/dist/components/Slider/Slider.d.ts.map +1 -0
- package/dist/components/Slider/Slider.js +137 -0
- package/dist/components/Slider/index.d.ts +2 -0
- package/dist/components/Slider/index.d.ts.map +1 -0
- package/dist/components/Slider/index.js +3 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/hooks/useMedia/useMedia.spec.d.ts +2 -0
- package/dist/hooks/useMedia/useMedia.spec.d.ts.map +1 -0
- package/dist/hooks/useMedia/useMedia.spec.js +288 -0
- package/dist/styles/selectors.d.ts +14 -0
- package/dist/styles/selectors.d.ts.map +1 -0
- package/dist/styles/selectors.js +27 -0
- package/dist/utils/css.d.ts +0 -22
- package/dist/utils/css.d.ts.map +1 -1
- package/dist/utils/css.js +0 -52
- package/dist/utils/css.spec.d.ts +2 -0
- package/dist/utils/css.spec.d.ts.map +1 -0
- package/dist/utils/css.spec.js +66 -0
- package/dist/utils/dateFormat.d.ts +24 -0
- package/dist/utils/dateFormat.d.ts.map +1 -0
- package/dist/utils/dateFormat.js +57 -0
- package/dist/utils/object.spec.d.ts +2 -0
- package/dist/utils/object.spec.d.ts.map +1 -0
- package/dist/utils/object.spec.js +135 -0
- package/dist/utils/responsiveStyle.spec.d.ts +2 -0
- package/dist/utils/responsiveStyle.spec.d.ts.map +1 -0
- package/dist/utils/responsiveStyle.spec.js +134 -0
- package/dist/utils/utils.spec.d.ts.map +1 -1
- package/dist/utils/utils.spec.js +342 -0
- package/package.json +25 -25
- package/dist/components/DateTimePicker/CalendarButton.d.ts +0 -4
- package/dist/components/DateTimePicker/CalendarButton.d.ts.map +0 -1
- package/dist/components/DateTimePicker/CalendarGrid.d.ts.map +0 -1
|
@@ -2,74 +2,191 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
const _excluded = ["
|
|
5
|
+
const _excluded = ["calendarOptions", "className", "disabled", "icon", "isLoading", "lang", "onChange", "size", "testId", "useNativePicker", "valueLabel"];
|
|
6
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import { CalendarIcon } from '@autoguru/icons';
|
|
9
|
+
import { getLocalTimeZone, parseDate, today } from '@internationalized/date';
|
|
9
10
|
import clsx from 'clsx';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import React, { useMemo, useState } from 'react';
|
|
12
|
+
import { elementStyles } from "../../styles/elementStyles.js";
|
|
13
|
+
import { sprinkles } from "../../styles/sprinkles.css.js";
|
|
14
|
+
import { Calendar } from "../Calendar/index.js";
|
|
13
15
|
import { Icon } from "../Icon/Icon.js";
|
|
16
|
+
import { PopoverTrigger } from "../Popover/index.js";
|
|
14
17
|
import { ProgressSpinner } from "../ProgressSpinner/ProgressSpinner.js";
|
|
15
18
|
import { Text } from "../Text/Text.js";
|
|
19
|
+
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
16
20
|
import * as styles from "./DatePicker.css.js";
|
|
17
21
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
const defaultEnglish = {
|
|
23
|
+
openCalendar: 'open calendar'
|
|
24
|
+
};
|
|
18
25
|
const textSizeMap = {
|
|
19
26
|
small: '2',
|
|
20
27
|
medium: '3',
|
|
21
28
|
large: '5'
|
|
22
29
|
};
|
|
30
|
+
const formatDateToString = date => {
|
|
31
|
+
if (!date) return '';
|
|
32
|
+
return date.toString(); // ISO format: YYYY-MM-DD to match native input
|
|
33
|
+
};
|
|
34
|
+
const parseDateString = dateString => {
|
|
35
|
+
try {
|
|
36
|
+
return parseDate(dateString);
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The DatePicker has been updated to render the Calendar component with a Popover while
|
|
44
|
+
* maintaining backwards compatability.
|
|
45
|
+
*
|
|
46
|
+
* ## Props
|
|
47
|
+
* - Visual size controlled by `size` (small | medium | large)
|
|
48
|
+
* - Icon can be customized via the `icon` prop
|
|
49
|
+
*
|
|
50
|
+
* ## Event handling
|
|
51
|
+
* - `onChange` is always invoked with the raw ISO date string (or empty string when cleared)
|
|
52
|
+
*
|
|
53
|
+
* ## Compatibility mode
|
|
54
|
+
* - Setting `useNativePicker={true}` preserves the original browser-specific experience.
|
|
55
|
+
*
|
|
56
|
+
* ## Internationalization
|
|
57
|
+
* - Override text values via `lang={{ openCalendar: 'open calendar' }}`
|
|
58
|
+
* - Calendar options including `lang`can be passed via `calendarOptions` prop
|
|
59
|
+
* - Date formatting helper available in `...utils/dateFormat.ts` or use `@internationalized/date` utils
|
|
60
|
+
* - Advanced i18n and localization handled by [React Aria I18Provider](https://react-spectrum.adobe.com/react-aria/I18nProvider.html)
|
|
61
|
+
* - Read more about [International calendars](https://react-spectrum.adobe.com/react-aria/useDatePicker.html#international-calendars)
|
|
62
|
+
*
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* <DatePicker
|
|
66
|
+
* name="bookingDate"
|
|
67
|
+
* valueLabel="Select a date"
|
|
68
|
+
* onChange={(isoDate) => console.log('Selected date:', isoDate)}
|
|
69
|
+
* calendarOptions={{
|
|
70
|
+
* allowPastDate: false,
|
|
71
|
+
* weekdayFormat: 'short',
|
|
72
|
+
* }}
|
|
73
|
+
* />
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Native date picker usage
|
|
77
|
+
* <DatePicker
|
|
78
|
+
* name="startDate"
|
|
79
|
+
* useNativePicker
|
|
80
|
+
* value={initialDateISO} // e.g., "2025-03-12"
|
|
81
|
+
* onChange={(isoDate) => console.log('Native picked date:', isoDate)}
|
|
82
|
+
* />
|
|
83
|
+
*/
|
|
23
84
|
export const DatePicker = _ref => {
|
|
85
|
+
var _lang$openCalendar;
|
|
24
86
|
let {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
size = 'medium',
|
|
87
|
+
calendarOptions,
|
|
88
|
+
className,
|
|
28
89
|
disabled = false,
|
|
90
|
+
icon = CalendarIcon,
|
|
29
91
|
isLoading = false,
|
|
30
|
-
|
|
31
|
-
onChange
|
|
92
|
+
lang,
|
|
93
|
+
onChange,
|
|
94
|
+
size = 'medium',
|
|
95
|
+
testId,
|
|
96
|
+
useNativePicker = false,
|
|
97
|
+
valueLabel
|
|
32
98
|
} = _ref,
|
|
33
99
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
100
|
+
const [selectedDate, setSelectedDate] = useState(null);
|
|
101
|
+
const [popoverState, setPopoverState] = useState(null);
|
|
34
102
|
const onChangeEvent = event => {
|
|
103
|
+
const dateString = event.currentTarget.value;
|
|
104
|
+
if (dateString) {
|
|
105
|
+
const parsedDate = parseDateString(dateString);
|
|
106
|
+
setSelectedDate(parsedDate);
|
|
107
|
+
} else {
|
|
108
|
+
setSelectedDate(null);
|
|
109
|
+
}
|
|
35
110
|
if (typeof onChange === 'function') {
|
|
36
|
-
onChange(
|
|
111
|
+
onChange(dateString);
|
|
37
112
|
}
|
|
38
113
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
overflow: "hidden",
|
|
42
|
-
className: clsx(className, {
|
|
114
|
+
const containerStyle = elementStyles({
|
|
115
|
+
className: [className, {
|
|
43
116
|
[styles.disabled.default]: disabled,
|
|
44
117
|
[styles.disabled.root]: disabled
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
118
|
+
}]
|
|
119
|
+
});
|
|
120
|
+
const indicator = isLoading ? /*#__PURE__*/_jsx(ProgressSpinner, {
|
|
121
|
+
size: size
|
|
122
|
+
}) : /*#__PURE__*/_jsx(Icon, {
|
|
123
|
+
icon: icon,
|
|
124
|
+
size: size
|
|
125
|
+
});
|
|
126
|
+
const label = valueLabel ? /*#__PURE__*/_jsx(Text, {
|
|
127
|
+
size: textSizeMap[size],
|
|
128
|
+
children: valueLabel
|
|
129
|
+
}) : null;
|
|
130
|
+
const calendarProps = useMemo(() => ({
|
|
131
|
+
calendar: _objectSpread({
|
|
132
|
+
defaultValue: selectedDate || today(getLocalTimeZone())
|
|
133
|
+
}, calendarOptions),
|
|
134
|
+
onChange: date => {
|
|
135
|
+
setSelectedDate(date);
|
|
136
|
+
if (typeof onChange === 'function') {
|
|
137
|
+
onChange(formatDateToString(date));
|
|
138
|
+
}
|
|
139
|
+
// Close the popover after date selection
|
|
140
|
+
if (popoverState) {
|
|
141
|
+
popoverState.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}), [selectedDate, calendarOptions, onChange, popoverState]);
|
|
145
|
+
const contentCalendar = useMemo(() => /*#__PURE__*/_jsx(Calendar, _objectSpread({}, calendarProps)), [calendarProps]);
|
|
146
|
+
|
|
147
|
+
// Use native picker only if explicitly requested
|
|
148
|
+
if (useNativePicker) {
|
|
149
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
150
|
+
className: clsx(containerStyle, styles.inputContainer),
|
|
151
|
+
children: [/*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, inputProps), {}, {
|
|
152
|
+
className: elementStyles({
|
|
153
|
+
className: [styles.input, {
|
|
154
|
+
[styles.disabled.default]: disabled
|
|
155
|
+
}]
|
|
156
|
+
}),
|
|
157
|
+
type: "date",
|
|
158
|
+
disabled: disabled,
|
|
159
|
+
onChange: onChangeEvent
|
|
160
|
+
})), /*#__PURE__*/_jsx("div", {
|
|
161
|
+
className: styles.inputOverlay,
|
|
162
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
163
|
+
className: clsx(styles.contents.default, {
|
|
164
|
+
[styles.contents.withLabel]: Boolean(valueLabel)
|
|
165
|
+
}),
|
|
166
|
+
children: [indicator, label]
|
|
167
|
+
})
|
|
168
|
+
})]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
172
|
+
className: clsx(containerStyle, sprinkles({
|
|
173
|
+
display: 'flex',
|
|
174
|
+
alignItems: 'center',
|
|
175
|
+
gap: '1'
|
|
176
|
+
})),
|
|
177
|
+
children: [/*#__PURE__*/_jsxs(PopoverTrigger, {
|
|
178
|
+
content: contentCalendar,
|
|
179
|
+
placement: "bottom left",
|
|
180
|
+
testId: testId,
|
|
181
|
+
isDisabled: disabled,
|
|
182
|
+
onStateReady: setPopoverState,
|
|
183
|
+
children: [indicator, /*#__PURE__*/_jsx(VisuallyHidden, {
|
|
184
|
+
children: (_lang$openCalendar = lang === null || lang === void 0 ? void 0 : lang.openCalendar) !== null && _lang$openCalendar !== void 0 ? _lang$openCalendar : defaultEnglish.openCalendar
|
|
72
185
|
})]
|
|
73
|
-
})
|
|
186
|
+
}), label, /*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, inputProps), {}, {
|
|
187
|
+
value: formatDateToString(selectedDate),
|
|
188
|
+
type: "hidden"
|
|
189
|
+
}))]
|
|
74
190
|
});
|
|
75
|
-
};
|
|
191
|
+
};
|
|
192
|
+
DatePicker.displayName = 'DatePicker';
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
export declare const queryContainer: string;
|
|
2
2
|
export declare const queryContainerStyle: string;
|
|
3
3
|
export declare const layoutStyle: string;
|
|
4
|
-
export declare const calendarGridStyle: string;
|
|
5
|
-
export declare const calendarStyle: string;
|
|
6
|
-
export declare const styledCell: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
7
|
-
[x: string]: {
|
|
8
|
-
[x: string]: string | import("@vanilla-extract/css").ComplexStyleRule;
|
|
9
|
-
};
|
|
10
|
-
}>;
|
|
11
|
-
export declare const styledButton: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
12
|
-
[x: string]: {
|
|
13
|
-
[x: string]: string | import("@vanilla-extract/css").ComplexStyleRule;
|
|
14
|
-
};
|
|
15
|
-
}>;
|
|
16
|
-
export declare const thStyle: string;
|
|
17
|
-
export declare const tdStyle: string;
|
|
18
|
-
export declare const titleStyle: string;
|
|
19
4
|
//# sourceMappingURL=DateTimePicker.css.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimePicker.css.d.ts","sourceRoot":"","sources":["../../../lib/components/DateTimePicker/DateTimePicker.css.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DateTimePicker.css.d.ts","sourceRoot":"","sources":["../../../lib/components/DateTimePicker/DateTimePicker.css.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,QAAoB,CAAC;AAChD,eAAO,MAAM,mBAAmB,QAO9B,CAAC;AAEH,eAAO,MAAM,WAAW,QAWtB,CAAC"}
|
|
@@ -3,111 +3,28 @@
|
|
|
3
3
|
import * as __vanilla_filescope__ from '@vanilla-extract/css/fileScope';
|
|
4
4
|
__vanilla_filescope__.setFileScope("lib/components/DateTimePicker/DateTimePicker.css.ts", "@autoguru/overdrive");
|
|
5
5
|
import { createContainer, style } from '@vanilla-extract/css';
|
|
6
|
-
import {
|
|
7
|
-
import { focusOutlineStyle } from "../../styles/focusOutline.css.js";
|
|
8
|
-
import { sprinkles } from "../../styles/sprinkles.css.js";
|
|
9
|
-
import { overdriveTokens as tokens } from "../../themes/index.js";
|
|
6
|
+
import { cssLayerComponent } from "../../styles/layers.css.js";
|
|
10
7
|
import { breakpoints } from "../../themes/makeTheme.js";
|
|
11
|
-
import {
|
|
8
|
+
import { overdriveTokens as tokens } from "../../themes/theme.css.js"; // === Container styles
|
|
12
9
|
export const queryContainer = createContainer("queryContainer");
|
|
13
10
|
export const queryContainerStyle = style({
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
'@layer': {
|
|
12
|
+
[cssLayerComponent]: {
|
|
13
|
+
containerName: queryContainer,
|
|
14
|
+
containerType: 'inline-size'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
16
17
|
}, "queryContainerStyle");
|
|
17
18
|
export const layoutStyle = style({
|
|
18
|
-
'@
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
'@layer': {
|
|
20
|
+
[cssLayerComponent]: {
|
|
21
|
+
'@container': {
|
|
22
|
+
[`${queryContainer} (min-width: ${breakpoints.tablet})`]: {
|
|
23
|
+
display: 'flex',
|
|
24
|
+
gap: tokens.space[7]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
}, "layoutStyle");
|
|
25
|
-
export const calendarGridStyle = style({
|
|
26
|
-
width: '100%',
|
|
27
|
-
'@container': {
|
|
28
|
-
[`${queryContainer} (min-width: ${breakpoints.tablet})`]: {
|
|
29
|
-
width: 'auto'
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, "calendarGridStyle");
|
|
33
|
-
export const calendarStyle = style({
|
|
34
|
-
alignItems: 'center',
|
|
35
|
-
display: 'flex',
|
|
36
|
-
justifyContent: 'space-between',
|
|
37
|
-
marginBottom: tokens.space[2],
|
|
38
|
-
padding: `0 ${tokens.space[1]}`
|
|
39
|
-
}, "calendarStyle");
|
|
40
|
-
|
|
41
|
-
// -- Cell styles
|
|
42
|
-
|
|
43
|
-
export const styledCell = recipe({
|
|
44
|
-
base: [{
|
|
45
|
-
alignItems: 'center',
|
|
46
|
-
backgroundColor: tokens.colours.background.body,
|
|
47
|
-
borderRadius: tokens.border.radius['md'],
|
|
48
|
-
color: tokens.colours.foreground.body,
|
|
49
|
-
cursor: 'pointer',
|
|
50
|
-
display: 'inline-flex',
|
|
51
|
-
fontSize: 'md',
|
|
52
|
-
justifyContent: 'center'
|
|
53
|
-
}, interactionStyle({
|
|
54
|
-
hoverNotSelected: {
|
|
55
|
-
backgroundColor: tokens.colours.gamut.gray200
|
|
56
|
-
},
|
|
57
|
-
selected: {
|
|
58
|
-
backgroundColor: tokens.colours.foreground.body,
|
|
59
|
-
color: tokens.colours.background.body
|
|
60
|
-
},
|
|
61
|
-
disabled: {
|
|
62
|
-
backgroundColor: tokens.colours.background.body,
|
|
63
|
-
color: tokens.colours.gamut.gray400,
|
|
64
|
-
cursor: 'default'
|
|
65
|
-
}
|
|
66
|
-
}), sprinkles({
|
|
67
|
-
size: '7'
|
|
68
|
-
}), focusOutlineStyle]
|
|
69
|
-
}, "styledCell");
|
|
70
|
-
|
|
71
|
-
// -- Button styles
|
|
72
|
-
|
|
73
|
-
export const styledButton = recipe({
|
|
74
|
-
base: [{
|
|
75
|
-
alignItems: 'center',
|
|
76
|
-
backgroundColor: tokens.colours.background.body,
|
|
77
|
-
borderColor: tokens.border.colours.gray,
|
|
78
|
-
borderRadius: tokens.border.radius['md'],
|
|
79
|
-
borderStyle: 'solid',
|
|
80
|
-
borderWidth: tokens.border.width[1],
|
|
81
|
-
color: tokens.colours.gamut.gray600,
|
|
82
|
-
cursor: 'pointer',
|
|
83
|
-
display: 'flex',
|
|
84
|
-
justifyContent: 'center',
|
|
85
|
-
padding: 0
|
|
86
|
-
}, interactionStyle({
|
|
87
|
-
hover: {
|
|
88
|
-
backgroundColor: tokens.colours.gamut.gray200
|
|
89
|
-
},
|
|
90
|
-
disabled: {
|
|
91
|
-
backgroundColor: tokens.colours.background.body,
|
|
92
|
-
borderColor: tokens.border.colours.light,
|
|
93
|
-
color: tokens.colours.gamut.gray300,
|
|
94
|
-
cursor: 'not-allowed'
|
|
95
|
-
}
|
|
96
|
-
}), sprinkles({
|
|
97
|
-
size: '7'
|
|
98
|
-
}), focusOutlineStyle]
|
|
99
|
-
}, "styledButton");
|
|
100
|
-
export const thStyle = style({
|
|
101
|
-
color: tokens.colours.gamut.gray600
|
|
102
|
-
}, "thStyle");
|
|
103
|
-
export const tdStyle = style({
|
|
104
|
-
padding: tokens.space[1],
|
|
105
|
-
textAlign: 'center'
|
|
106
|
-
}, "tdStyle");
|
|
107
|
-
|
|
108
|
-
// -- Heading styles
|
|
109
|
-
export const titleStyle = style({
|
|
110
|
-
fontWeight: tokens.typography.fontWeight.bold,
|
|
111
|
-
margin: 0
|
|
112
|
-
}, "titleStyle");
|
|
113
30
|
__vanilla_filescope__.endFileScope();
|
|
@@ -26,7 +26,7 @@ export interface DateTimePickerProps<D extends DateValue> extends TestIdProp {
|
|
|
26
26
|
* - `defaultValue`: Today's date
|
|
27
27
|
* - `firstDayOfWeek`: Monday
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
calendarOptions?: Exclude<AriaCalendarProps<D>, 'onChange'>;
|
|
30
30
|
/**
|
|
31
31
|
* `OptionGrid` props used to generate the time picker items. Ensure to include a descriptive `label` value (for
|
|
32
32
|
* assistive technology). Currently time options are not tied to the day selection.
|
|
@@ -60,6 +60,9 @@ export interface DateTimePickerProps<D extends DateValue> extends TestIdProp {
|
|
|
60
60
|
* This component implements the react-aria `useCalendar` hook and supports controlled state as well
|
|
61
61
|
* ([docs](https://react-spectrum.adobe.com/react-aria/useCalendar.html))
|
|
62
62
|
*/
|
|
63
|
-
export declare const DateTimePicker:
|
|
63
|
+
export declare const DateTimePicker: {
|
|
64
|
+
<D extends DateValue>({ allowPastDate, calendarOptions, lang, onChange, timeOptions, title, testId, }: DateTimePickerProps<D>): React.JSX.Element;
|
|
65
|
+
displayName: string;
|
|
66
|
+
};
|
|
64
67
|
export {};
|
|
65
68
|
//# sourceMappingURL=DateTimePicker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimePicker.d.ts","sourceRoot":"","sources":["../../../lib/components/DateTimePicker/DateTimePicker.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DateTimePicker.d.ts","sourceRoot":"","sources":["../../../lib/components/DateTimePicker/DateTimePicker.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiB,MAAM,OAAO,CAAC;AACtC,OAAO,EAAS,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAI3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,MAAM,0BAA0B,CAAC;AAIlC,QAAA,MAAM,cAAc;;;;;CAKV,CAAC;AAEX,KAAK,WAAW,GAAG,MAAM,OAAO,cAAc,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,SAAS,CAAE,SAAQ,UAAU;IAC3E;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5C;AAQD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc;KAAI,CAAC,SAAS,SAAS,mFAQ/C,mBAAmB,CAAC,CAAC,CAAC;;CA+ExB,CAAC"}
|
|
@@ -3,23 +3,15 @@
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
GregorianCalendar, today } from '@internationalized/date';
|
|
10
|
-
import React, { useEffect, useRef } from 'react';
|
|
11
|
-
import { useCalendar,
|
|
12
|
-
// useDateFormatter,
|
|
13
|
-
useLocale, useId } from 'react-aria';
|
|
14
|
-
import { useCalendarState } from 'react-stately';
|
|
6
|
+
import { getLocalTimeZone, today } from '@internationalized/date';
|
|
7
|
+
import React, { useRef } from 'react';
|
|
8
|
+
import { useId } from 'react-aria';
|
|
15
9
|
import { sprinkles } from "../../styles/sprinkles.css.js";
|
|
16
10
|
import { dataAttrs } from "../../utils/dataAttrs.js";
|
|
11
|
+
import { Calendar } from "../Calendar/index.js";
|
|
17
12
|
import { Heading } from "../Heading/index.js";
|
|
18
|
-
import { Icon } from "../Icon/index.js";
|
|
19
13
|
import { OptionGrid } from "../OptionGrid/OptionGrid.js";
|
|
20
|
-
import {
|
|
21
|
-
import { CalendarGrid } from "./CalendarGrid.js";
|
|
22
|
-
import { calendarStyle, layoutStyle, queryContainerStyle, titleStyle } from "./DateTimePicker.css.js";
|
|
14
|
+
import { layoutStyle, queryContainerStyle } from "./DateTimePicker.css.js";
|
|
23
15
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
16
|
const defaultEnglish = {
|
|
25
17
|
dateLabel: 'Date',
|
|
@@ -27,13 +19,6 @@ const defaultEnglish = {
|
|
|
27
19
|
nextLabel: 'Next month',
|
|
28
20
|
prevLabel: 'Previous month'
|
|
29
21
|
};
|
|
30
|
-
function createCalendar(identifier) {
|
|
31
|
-
if (identifier === 'gregory') {
|
|
32
|
-
return new GregorianCalendar();
|
|
33
|
-
}
|
|
34
|
-
throw new Error(`Unsupported calendar configured ${identifier}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
22
|
// const dateTextPunctuationEN = (text: string) =>
|
|
38
23
|
// text
|
|
39
24
|
// .split(' ')
|
|
@@ -54,15 +39,15 @@ function createCalendar(identifier) {
|
|
|
54
39
|
*/
|
|
55
40
|
export const DateTimePicker = ({
|
|
56
41
|
allowPastDate = false,
|
|
57
|
-
|
|
42
|
+
calendarOptions,
|
|
58
43
|
lang,
|
|
59
44
|
onChange,
|
|
60
45
|
timeOptions,
|
|
61
46
|
title,
|
|
62
47
|
testId
|
|
63
48
|
}) => {
|
|
64
|
-
var _lang$dateLabel, _lang$
|
|
65
|
-
const selectedDate = useRef(
|
|
49
|
+
var _lang$dateLabel, _lang$timeLabel;
|
|
50
|
+
const selectedDate = useRef(today(getLocalTimeZone()));
|
|
66
51
|
const selectedTimeOption = useRef(null);
|
|
67
52
|
const handleChange = () => {
|
|
68
53
|
var _selectedTimeOption$c;
|
|
@@ -73,6 +58,10 @@ export const DateTimePicker = ({
|
|
|
73
58
|
});
|
|
74
59
|
}
|
|
75
60
|
};
|
|
61
|
+
const handleDateChange = value => {
|
|
62
|
+
selectedDate.current = value;
|
|
63
|
+
handleChange();
|
|
64
|
+
};
|
|
76
65
|
const handleTimeChange = keys => {
|
|
77
66
|
if (keys === 'all') return;
|
|
78
67
|
// we expect only a single value for time picker
|
|
@@ -80,15 +69,6 @@ export const DateTimePicker = ({
|
|
|
80
69
|
selectedTimeOption.current = time;
|
|
81
70
|
handleChange();
|
|
82
71
|
};
|
|
83
|
-
const calendarComponentProps = _objectSpread({
|
|
84
|
-
defaultValue: today(getLocalTimeZone()),
|
|
85
|
-
firstDayOfWeek: 'sun',
|
|
86
|
-
minValue: allowPastDate ? undefined : today(getLocalTimeZone()),
|
|
87
|
-
onChange: value => {
|
|
88
|
-
selectedDate.current = value;
|
|
89
|
-
handleChange();
|
|
90
|
-
}
|
|
91
|
-
}, calendar);
|
|
92
72
|
const optionGridComponentProps = _objectSpread({
|
|
93
73
|
columns: '3',
|
|
94
74
|
onSelectionChange: handleTimeChange,
|
|
@@ -96,34 +76,13 @@ export const DateTimePicker = ({
|
|
|
96
76
|
selectionMode: 'single',
|
|
97
77
|
disallowEmptySelection: true
|
|
98
78
|
}, timeOptions);
|
|
99
|
-
const {
|
|
100
|
-
locale
|
|
101
|
-
} = useLocale();
|
|
102
|
-
const state = useCalendarState(_objectSpread(_objectSpread({}, calendarComponentProps), {}, {
|
|
103
|
-
locale,
|
|
104
|
-
createCalendar
|
|
105
|
-
}));
|
|
106
|
-
const {
|
|
107
|
-
calendarProps,
|
|
108
|
-
prevButtonProps,
|
|
109
|
-
nextButtonProps,
|
|
110
|
-
title: calendarTitle
|
|
111
|
-
} = useCalendar(calendarComponentProps, state);
|
|
112
79
|
const titleId = useId();
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
if (state.value) {
|
|
115
|
-
selectedDate.current = state.value;
|
|
116
|
-
}
|
|
117
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- run only once
|
|
118
|
-
}, []);
|
|
119
|
-
|
|
120
|
-
// const formatter = useDateFormatter({ dateStyle: 'full' });
|
|
121
|
-
// const dateText = state.value
|
|
122
|
-
// ? dateTextPunctuationEN(
|
|
123
|
-
// formatter.format(state?.value?.toDate(getLocalTimeZone())),
|
|
124
|
-
// )
|
|
125
|
-
// : '';
|
|
126
80
|
|
|
81
|
+
// Create calendar lang props from our lang props
|
|
82
|
+
const calendarLang = lang ? {
|
|
83
|
+
nextLabel: lang.nextLabel,
|
|
84
|
+
prevLabel: lang.prevLabel
|
|
85
|
+
} : undefined;
|
|
127
86
|
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
128
87
|
role: "group",
|
|
129
88
|
"aria-labelledby": titleId,
|
|
@@ -148,27 +107,11 @@ export const DateTimePicker = ({
|
|
|
148
107
|
mb: "4",
|
|
149
108
|
size: "6",
|
|
150
109
|
children: (_lang$dateLabel = lang === null || lang === void 0 ? void 0 : lang.dateLabel) !== null && _lang$dateLabel !== void 0 ? _lang$dateLabel : defaultEnglish.dateLabel
|
|
151
|
-
}), /*#__PURE__*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
icon: ChevronLeftIcon,
|
|
157
|
-
size: "medium"
|
|
158
|
-
})
|
|
159
|
-
})), /*#__PURE__*/_jsx("h4", {
|
|
160
|
-
className: titleStyle,
|
|
161
|
-
children: calendarTitle
|
|
162
|
-
}), /*#__PURE__*/_jsx(CalendarButton, _objectSpread(_objectSpread({}, nextButtonProps), {}, {
|
|
163
|
-
"aria-label": (_lang$nextLabel = lang === null || lang === void 0 ? void 0 : lang.nextLabel) !== null && _lang$nextLabel !== void 0 ? _lang$nextLabel : defaultEnglish.nextLabel,
|
|
164
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
|
165
|
-
icon: ChevronRightIcon,
|
|
166
|
-
size: "medium"
|
|
167
|
-
})
|
|
168
|
-
}))]
|
|
169
|
-
})), /*#__PURE__*/_jsx(CalendarGrid, {
|
|
170
|
-
state: state,
|
|
171
|
-
firstDayOfWeek: calendarComponentProps.firstDayOfWeek
|
|
110
|
+
}), /*#__PURE__*/_jsx(Calendar, {
|
|
111
|
+
allowPastDate: allowPastDate,
|
|
112
|
+
calendarOptions: calendarOptions,
|
|
113
|
+
lang: calendarLang,
|
|
114
|
+
onChange: handleDateChange
|
|
172
115
|
})]
|
|
173
116
|
}), /*#__PURE__*/_jsxs("div", {
|
|
174
117
|
className: sprinkles({
|
|
@@ -183,4 +126,5 @@ export const DateTimePicker = ({
|
|
|
183
126
|
})]
|
|
184
127
|
})]
|
|
185
128
|
}));
|
|
186
|
-
};
|
|
129
|
+
};
|
|
130
|
+
DateTimePicker.displayName = 'DateTimePicker';
|