@autoguru/overdrive 4.47.0 → 4.47.1
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.d.ts +11 -6
- package/dist/components/Calendar/Calendar.d.ts.map +1 -1
- package/dist/components/Calendar/Calendar.js +18 -11
- package/dist/components/DatePicker/DatePicker.d.ts +30 -7
- package/dist/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/components/DatePicker/DatePicker.js +37 -10
- package/dist/components/Slider/Slider.d.ts +7 -7
- package/dist/components/Slider/Slider.d.ts.map +1 -1
- package/dist/components/Slider/Slider.js +16 -12
- package/package.json +1 -1
|
@@ -43,18 +43,23 @@ export interface CalendarProps extends TestIdProp {
|
|
|
43
43
|
* - Custom default values and date ranges
|
|
44
44
|
* - Flexible styling and theming
|
|
45
45
|
*
|
|
46
|
+
* ## Working with dates
|
|
47
|
+
* - Use `parseDate('YYYY-MM-DD')` from `@internationalized/date` to create
|
|
48
|
+
* DateValue objects.
|
|
49
|
+
* - Other useful utilities include `today(getLocalTimeZone())` for current
|
|
50
|
+
* date, and `date.add({ days: 7, months: 1 })` for date arithmetic.
|
|
51
|
+
*
|
|
46
52
|
* ## Date Restrictions
|
|
47
53
|
* You can restrict date selection using the `calendar` prop with react-aria calendar properties:
|
|
48
54
|
* - `minValue` / `maxValue`: Define selectable date range
|
|
49
55
|
* - `isDateUnavailable`: Function to disable specific dates
|
|
50
56
|
* - `allowPastDate` prop: Convenient way to allow/disallow past dates
|
|
51
57
|
*
|
|
52
|
-
* ##
|
|
53
|
-
*
|
|
54
|
-
* -
|
|
55
|
-
* -
|
|
56
|
-
* -
|
|
57
|
-
* - Localization examples
|
|
58
|
+
* ## Internationalization
|
|
59
|
+
* - Override text values via `lang={{ openCalendar: 'open calendar' }}`
|
|
60
|
+
* - Date formatting helper available in `...utils/dateFormat.ts` or use `@internationalized/date` utils
|
|
61
|
+
* - Advanced i18n and localization handled by [React Aria I18Provider](https://react-spectrum.adobe.com/react-aria/I18nProvider.html)
|
|
62
|
+
* - Read more about [International calendars](https://react-spectrum.adobe.com/react-aria/useDatePicker.html#international-calendars)
|
|
58
63
|
*/
|
|
59
64
|
export declare const Calendar: {
|
|
60
65
|
({ allowPastDate, calendarOptions, lang, onChange, testId, }: CalendarProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.d.ts","sourceRoot":"","sources":["../../../lib/components/Calendar/Calendar.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAGN,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAS9C,QAAA,MAAM,cAAc;;;CAGV,CAAC;AAEX,KAAK,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E,MAAM,WAAW,aAAc,SAAQ,UAAU;IAChD;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;IACpE;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACvB;AAUD
|
|
1
|
+
{"version":3,"file":"Calendar.d.ts","sourceRoot":"","sources":["../../../lib/components/Calendar/Calendar.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAGN,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAS9C,QAAA,MAAM,cAAc;;;CAGV,CAAC;AAEX,KAAK,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E,MAAM,WAAW,aAAc,SAAQ,UAAU;IAChD;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;IACpE;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACvB;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,QAAQ;kEAMlB,aAAa;;CA8Df,CAAC"}
|
|
@@ -42,18 +42,23 @@ function createCalendar(identifier) {
|
|
|
42
42
|
* - Custom default values and date ranges
|
|
43
43
|
* - Flexible styling and theming
|
|
44
44
|
*
|
|
45
|
+
* ## Working with dates
|
|
46
|
+
* - Use `parseDate('YYYY-MM-DD')` from `@internationalized/date` to create
|
|
47
|
+
* DateValue objects.
|
|
48
|
+
* - Other useful utilities include `today(getLocalTimeZone())` for current
|
|
49
|
+
* date, and `date.add({ days: 7, months: 1 })` for date arithmetic.
|
|
50
|
+
*
|
|
45
51
|
* ## Date Restrictions
|
|
46
52
|
* You can restrict date selection using the `calendar` prop with react-aria calendar properties:
|
|
47
53
|
* - `minValue` / `maxValue`: Define selectable date range
|
|
48
54
|
* - `isDateUnavailable`: Function to disable specific dates
|
|
49
55
|
* - `allowPastDate` prop: Convenient way to allow/disallow past dates
|
|
50
56
|
*
|
|
51
|
-
* ##
|
|
52
|
-
*
|
|
53
|
-
* -
|
|
54
|
-
* -
|
|
55
|
-
* -
|
|
56
|
-
* - Localization examples
|
|
57
|
+
* ## Internationalization
|
|
58
|
+
* - Override text values via `lang={{ openCalendar: 'open calendar' }}`
|
|
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)
|
|
57
62
|
*/
|
|
58
63
|
export const Calendar = ({
|
|
59
64
|
allowPastDate = false,
|
|
@@ -64,15 +69,18 @@ export const Calendar = ({
|
|
|
64
69
|
}) => {
|
|
65
70
|
var _lang$prevLabel, _lang$nextLabel;
|
|
66
71
|
const selectedDate = useRef(null);
|
|
67
|
-
const
|
|
68
|
-
|
|
72
|
+
const hasValue = !!(calendarOptions !== null && calendarOptions !== void 0 && calendarOptions.value) || !!(calendarOptions !== null && calendarOptions !== void 0 && calendarOptions.defaultValue);
|
|
73
|
+
const fallbackDefaultValue = hasValue ? {} : {
|
|
74
|
+
defaultValue: today(getLocalTimeZone())
|
|
75
|
+
};
|
|
76
|
+
const calendarComponentProps = _objectSpread(_objectSpread({
|
|
69
77
|
firstDayOfWeek: FIRST_DAY_OF_WEEK,
|
|
70
78
|
minValue: allowPastDate ? undefined : today(getLocalTimeZone()),
|
|
71
79
|
onChange: value => {
|
|
72
80
|
selectedDate.current = value;
|
|
73
81
|
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
74
82
|
}
|
|
75
|
-
}, calendarOptions);
|
|
83
|
+
}, calendarOptions), fallbackDefaultValue);
|
|
76
84
|
const {
|
|
77
85
|
locale
|
|
78
86
|
} = useLocale();
|
|
@@ -90,8 +98,7 @@ export const Calendar = ({
|
|
|
90
98
|
if (state.value) {
|
|
91
99
|
selectedDate.current = state.value;
|
|
92
100
|
}
|
|
93
|
-
|
|
94
|
-
}, []);
|
|
101
|
+
}, [state.value]);
|
|
95
102
|
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({}, dataAttrs({
|
|
96
103
|
testid: testId
|
|
97
104
|
})), {}, {
|
|
@@ -7,12 +7,16 @@ declare const defaultEnglish: {
|
|
|
7
7
|
readonly openCalendar: "open calendar";
|
|
8
8
|
};
|
|
9
9
|
type LanguageEntries = Partial<Record<keyof typeof defaultEnglish, string>>;
|
|
10
|
-
export interface DatePickerProps extends
|
|
10
|
+
export interface DatePickerProps extends TestIdProp {
|
|
11
11
|
/**
|
|
12
12
|
* Options to customise the calendar: `allowPastDate`, `lang`, etc.
|
|
13
13
|
*/
|
|
14
14
|
calendarOptions?: Omit<CalendarProps, 'onChange'>;
|
|
15
15
|
className?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Default selected date as an ISO string YYYY-MM-DD (uncontrolled)
|
|
18
|
+
*/
|
|
19
|
+
defaultValue?: string;
|
|
16
20
|
/**
|
|
17
21
|
* Whether the picker is disabled and non-interactive
|
|
18
22
|
*/
|
|
@@ -21,15 +25,28 @@ export interface DatePickerProps extends Pick<HTMLInputElement, 'id' | 'name'>,
|
|
|
21
25
|
* Icon to render inside the picker (defaults to calendar icon)
|
|
22
26
|
*/
|
|
23
27
|
icon?: IconType;
|
|
28
|
+
/**
|
|
29
|
+
* Form field id
|
|
30
|
+
*/
|
|
31
|
+
id?: string;
|
|
24
32
|
/**
|
|
25
33
|
* Show a loading state spinner instead of the icon
|
|
26
34
|
*/
|
|
27
35
|
isLoading?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Input field name recommended for form usage
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
28
40
|
onChange(date: string): void;
|
|
29
41
|
/**
|
|
30
42
|
* Visual size of the picker control (small, medium, large)
|
|
31
43
|
*/
|
|
32
44
|
size?: SizeScale;
|
|
45
|
+
/**
|
|
46
|
+
* The selected date as an ISO string (YYYY-MM-DD). Use `undefined` for an empty value
|
|
47
|
+
* (controlled)
|
|
48
|
+
*/
|
|
49
|
+
value?: string;
|
|
33
50
|
/**
|
|
34
51
|
* Fallback label to display when no date value is selected.
|
|
35
52
|
*/
|
|
@@ -64,12 +81,21 @@ export interface DatePickerProps extends Pick<HTMLInputElement, 'id' | 'name'>,
|
|
|
64
81
|
* - Advanced i18n and localization handled by [React Aria I18Provider](https://react-spectrum.adobe.com/react-aria/I18nProvider.html)
|
|
65
82
|
* - Read more about [International calendars](https://react-spectrum.adobe.com/react-aria/useDatePicker.html#international-calendars)
|
|
66
83
|
*
|
|
84
|
+
* @example
|
|
85
|
+
* // Uncontrolled component with default value
|
|
86
|
+
* <DatePicker
|
|
87
|
+
* name="eventDate"
|
|
88
|
+
* defaultValue="2025-03-15"
|
|
89
|
+
* onChange={(isoDate) => console.log('Selected date:', isoDate)}
|
|
90
|
+
* />
|
|
67
91
|
*
|
|
68
92
|
* @example
|
|
93
|
+
* // Controlled component
|
|
69
94
|
* <DatePicker
|
|
70
95
|
* name="bookingDate"
|
|
96
|
+
* value={selectedDate}
|
|
71
97
|
* valueLabel="Select a date"
|
|
72
|
-
* onChange={(isoDate) =>
|
|
98
|
+
* onChange={(isoDate) => setSelectedDate(isoDate)}
|
|
73
99
|
* calendarOptions={{
|
|
74
100
|
* allowPastDate: false,
|
|
75
101
|
* weekdayFormat: 'short',
|
|
@@ -81,13 +107,10 @@ export interface DatePickerProps extends Pick<HTMLInputElement, 'id' | 'name'>,
|
|
|
81
107
|
* <DatePicker
|
|
82
108
|
* name="startDate"
|
|
83
109
|
* useNativePicker
|
|
84
|
-
*
|
|
110
|
+
* defaultValue="2025-03-12"
|
|
85
111
|
* onChange={(isoDate) => console.log('Native picked date:', isoDate)}
|
|
86
112
|
* />
|
|
87
113
|
*/
|
|
88
|
-
export declare const DatePicker:
|
|
89
|
-
({ calendarOptions, className, disabled, icon, isLoading, lang, onChange, size, testId, useNativePicker, valueLabel, ...inputProps }: DatePickerProps): React.JSX.Element;
|
|
90
|
-
displayName: string;
|
|
91
|
-
};
|
|
114
|
+
export declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
92
115
|
export {};
|
|
93
116
|
//# sourceMappingURL=DatePicker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../lib/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQzD,OAAO,
|
|
1
|
+
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../lib/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQzD,OAAO,KAMN,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAS3D,KAAK,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE9C,QAAA,MAAM,cAAc;;CAEV,CAAC;AAEX,KAAK,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAClD;;OAEG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACvB;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,UAAU,0FAqLtB,CAAC"}
|
|
@@ -2,13 +2,13 @@
|
|
|
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 = ["calendarOptions", "className", "disabled", "icon", "isLoading", "lang", "onChange", "size", "testId", "useNativePicker", "valueLabel"];
|
|
5
|
+
const _excluded = ["calendarOptions", "className", "defaultValue", "disabled", "icon", "isLoading", "lang", "onChange", "size", "testId", "useNativePicker", "value", "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
9
|
import { getLocalTimeZone, parseDate, today } from '@internationalized/date';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
|
-
import React, { useMemo, useState } from 'react';
|
|
11
|
+
import React, { useEffect, useMemo, useState, forwardRef } from 'react';
|
|
12
12
|
import { elementStyles } from "../../styles/elementStyles.js";
|
|
13
13
|
import { sprinkles } from "../../styles/sprinkles.css.js";
|
|
14
14
|
import { Calendar } from "../Calendar/index.js";
|
|
@@ -60,12 +60,21 @@ const parseDateString = dateString => {
|
|
|
60
60
|
* - Advanced i18n and localization handled by [React Aria I18Provider](https://react-spectrum.adobe.com/react-aria/I18nProvider.html)
|
|
61
61
|
* - Read more about [International calendars](https://react-spectrum.adobe.com/react-aria/useDatePicker.html#international-calendars)
|
|
62
62
|
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Uncontrolled component with default value
|
|
65
|
+
* <DatePicker
|
|
66
|
+
* name="eventDate"
|
|
67
|
+
* defaultValue="2025-03-15"
|
|
68
|
+
* onChange={(isoDate) => console.log('Selected date:', isoDate)}
|
|
69
|
+
* />
|
|
63
70
|
*
|
|
64
71
|
* @example
|
|
72
|
+
* // Controlled component
|
|
65
73
|
* <DatePicker
|
|
66
74
|
* name="bookingDate"
|
|
75
|
+
* value={selectedDate}
|
|
67
76
|
* valueLabel="Select a date"
|
|
68
|
-
* onChange={(isoDate) =>
|
|
77
|
+
* onChange={(isoDate) => setSelectedDate(isoDate)}
|
|
69
78
|
* calendarOptions={{
|
|
70
79
|
* allowPastDate: false,
|
|
71
80
|
* weekdayFormat: 'short',
|
|
@@ -77,15 +86,16 @@ const parseDateString = dateString => {
|
|
|
77
86
|
* <DatePicker
|
|
78
87
|
* name="startDate"
|
|
79
88
|
* useNativePicker
|
|
80
|
-
*
|
|
89
|
+
* defaultValue="2025-03-12"
|
|
81
90
|
* onChange={(isoDate) => console.log('Native picked date:', isoDate)}
|
|
82
91
|
* />
|
|
83
92
|
*/
|
|
84
|
-
export const DatePicker = _ref => {
|
|
93
|
+
export const DatePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
85
94
|
var _lang$openCalendar;
|
|
86
95
|
let {
|
|
87
96
|
calendarOptions,
|
|
88
97
|
className,
|
|
98
|
+
defaultValue,
|
|
89
99
|
disabled = false,
|
|
90
100
|
icon = CalendarIcon,
|
|
91
101
|
isLoading = false,
|
|
@@ -94,11 +104,24 @@ export const DatePicker = _ref => {
|
|
|
94
104
|
size = 'medium',
|
|
95
105
|
testId,
|
|
96
106
|
useNativePicker = false,
|
|
107
|
+
value,
|
|
97
108
|
valueLabel
|
|
98
109
|
} = _ref,
|
|
99
110
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
100
|
-
const
|
|
111
|
+
const isControlled = value !== undefined;
|
|
112
|
+
const [selectedDate, setSelectedDate] = useState(() => {
|
|
113
|
+
const initialValue = isControlled ? value : defaultValue;
|
|
114
|
+
return initialValue ? parseDateString(initialValue) : null;
|
|
115
|
+
});
|
|
101
116
|
const [popoverState, setPopoverState] = useState(null);
|
|
117
|
+
|
|
118
|
+
// Sync external value changes (only for controlled components)
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (isControlled) {
|
|
121
|
+
const parsedDate = value ? parseDateString(value) : null;
|
|
122
|
+
setSelectedDate(parsedDate);
|
|
123
|
+
}
|
|
124
|
+
}, [value, isControlled]);
|
|
102
125
|
const onChangeEvent = event => {
|
|
103
126
|
const dateString = event.currentTarget.value;
|
|
104
127
|
if (dateString) {
|
|
@@ -128,9 +151,11 @@ export const DatePicker = _ref => {
|
|
|
128
151
|
children: valueLabel
|
|
129
152
|
}) : null;
|
|
130
153
|
const calendarProps = useMemo(() => ({
|
|
131
|
-
|
|
154
|
+
calendarOptions: _objectSpread(_objectSpread({}, isControlled ? {
|
|
155
|
+
value: selectedDate || today(getLocalTimeZone())
|
|
156
|
+
} : {
|
|
132
157
|
defaultValue: selectedDate || today(getLocalTimeZone())
|
|
133
|
-
}, calendarOptions),
|
|
158
|
+
}), calendarOptions),
|
|
134
159
|
onChange: date => {
|
|
135
160
|
setSelectedDate(date);
|
|
136
161
|
if (typeof onChange === 'function') {
|
|
@@ -141,7 +166,7 @@ export const DatePicker = _ref => {
|
|
|
141
166
|
popoverState.close();
|
|
142
167
|
}
|
|
143
168
|
}
|
|
144
|
-
}), [selectedDate, calendarOptions, onChange, popoverState]);
|
|
169
|
+
}), [selectedDate, calendarOptions, onChange, popoverState, isControlled]);
|
|
145
170
|
const contentCalendar = useMemo(() => /*#__PURE__*/_jsx(Calendar, _objectSpread({}, calendarProps)), [calendarProps]);
|
|
146
171
|
|
|
147
172
|
// Use native picker only if explicitly requested
|
|
@@ -149,6 +174,7 @@ export const DatePicker = _ref => {
|
|
|
149
174
|
return /*#__PURE__*/_jsxs("div", {
|
|
150
175
|
className: clsx(containerStyle, styles.inputContainer),
|
|
151
176
|
children: [/*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, inputProps), {}, {
|
|
177
|
+
ref: ref,
|
|
152
178
|
className: elementStyles({
|
|
153
179
|
className: [styles.input, {
|
|
154
180
|
[styles.disabled.default]: disabled
|
|
@@ -184,9 +210,10 @@ export const DatePicker = _ref => {
|
|
|
184
210
|
children: (_lang$openCalendar = lang === null || lang === void 0 ? void 0 : lang.openCalendar) !== null && _lang$openCalendar !== void 0 ? _lang$openCalendar : defaultEnglish.openCalendar
|
|
185
211
|
})]
|
|
186
212
|
}), label, /*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, inputProps), {}, {
|
|
213
|
+
ref: ref,
|
|
187
214
|
value: formatDateToString(selectedDate),
|
|
188
215
|
type: "hidden"
|
|
189
216
|
}))]
|
|
190
217
|
});
|
|
191
|
-
};
|
|
218
|
+
});
|
|
192
219
|
DatePicker.displayName = 'DatePicker';
|
|
@@ -3,9 +3,9 @@ import { type AriaSliderProps, type AriaSliderThumbProps } from 'react-aria';
|
|
|
3
3
|
import type { TestIdProp } from '../../types';
|
|
4
4
|
export interface SliderProps extends AriaSliderProps, Pick<AriaSliderThumbProps, 'name'>, TestIdProp {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Label for the slider. Can be a string or custom child element.
|
|
7
7
|
*/
|
|
8
|
-
label?:
|
|
8
|
+
label?: React.ReactNode;
|
|
9
9
|
/**
|
|
10
10
|
* Unit text to display with the value (e.g., 'kms', 'miles', '%')
|
|
11
11
|
*/
|
|
@@ -25,11 +25,11 @@ export interface SliderProps extends AriaSliderProps, Pick<AriaSliderThumbProps,
|
|
|
25
25
|
* supports configurable step values and value unit post-fix. Use the `onChange` handler
|
|
26
26
|
* in most instances for retrieving the current value.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* };
|
|
28
|
+
* Supports flexible label approach:
|
|
29
|
+
* - Pre-styled label `label="Distance"`
|
|
30
|
+
* - Custom label content: `label={<label className={customlabelStyles}>Distance</label>}`
|
|
32
31
|
*
|
|
32
|
+
* @example
|
|
33
33
|
* <Slider
|
|
34
34
|
* label="Distance"
|
|
35
35
|
* value={distance}
|
|
@@ -41,7 +41,7 @@ export interface SliderProps extends AriaSliderProps, Pick<AriaSliderThumbProps,
|
|
|
41
41
|
* />;
|
|
42
42
|
*/
|
|
43
43
|
export declare const Slider: {
|
|
44
|
-
({
|
|
44
|
+
({ formatOptions, label, step, testId, unitText, ...props }: SliderProps): React.JSX.Element;
|
|
45
45
|
displayName: string;
|
|
46
46
|
};
|
|
47
47
|
//# sourceMappingURL=Slider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../lib/components/Slider/Slider.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../lib/components/Slider/Slider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyB,MAAM,OAAO,CAAC;AAC9C,OAAO,EAMN,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQ9C,MAAM,WAAW,WAChB,SAAQ,eAAe,EACtB,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,EAClC,UAAU;IACX;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACzC;AAqCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM;iEAOhB,WAAW;;CAqEb,CAAC"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
-
const _excluded = ["
|
|
5
|
+
const _excluded = ["formatOptions", "label", "step", "testId", "unitText"];
|
|
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 { MinusIcon, PlusIcon } from '@autoguru/icons';
|
|
9
|
-
import React from 'react';
|
|
9
|
+
import React, { isValidElement } from 'react';
|
|
10
10
|
import { mergeProps, useFocusRing, useNumberFormatter, useSlider, useSliderThumb } from 'react-aria';
|
|
11
11
|
import { useSliderState } from 'react-stately';
|
|
12
12
|
import { dataAttrs } from "../../utils/dataAttrs.js";
|
|
@@ -57,11 +57,11 @@ const SliderThumb = ({
|
|
|
57
57
|
* supports configurable step values and value unit post-fix. Use the `onChange` handler
|
|
58
58
|
* in most instances for retrieving the current value.
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* };
|
|
60
|
+
* Supports flexible label approach:
|
|
61
|
+
* - Pre-styled label `label="Distance"`
|
|
62
|
+
* - Custom label content: `label={<label className={customlabelStyles}>Distance</label>}`
|
|
64
63
|
*
|
|
64
|
+
* @example
|
|
65
65
|
* <Slider
|
|
66
66
|
* label="Distance"
|
|
67
67
|
* value={distance}
|
|
@@ -74,14 +74,17 @@ const SliderThumb = ({
|
|
|
74
74
|
*/
|
|
75
75
|
export const Slider = _ref => {
|
|
76
76
|
let {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
formatOptions,
|
|
78
|
+
label,
|
|
79
79
|
step = 5,
|
|
80
|
-
|
|
80
|
+
testId,
|
|
81
|
+
unitText
|
|
81
82
|
} = _ref,
|
|
82
83
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
83
84
|
const trackRef = React.useRef(null);
|
|
84
85
|
const numberFormatter = useNumberFormatter(formatOptions);
|
|
86
|
+
const hasTextLabel = !!label && typeof label === 'string' && label !== '';
|
|
87
|
+
const hasCustomLabel = !hasTextLabel && /*#__PURE__*/isValidElement(label);
|
|
85
88
|
const state = useSliderState(_objectSpread(_objectSpread({}, props), {}, {
|
|
86
89
|
step,
|
|
87
90
|
numberFormatter
|
|
@@ -92,16 +95,17 @@ export const Slider = _ref => {
|
|
|
92
95
|
labelProps,
|
|
93
96
|
outputProps
|
|
94
97
|
} = useSlider(_objectSpread(_objectSpread({}, props), {}, {
|
|
98
|
+
label,
|
|
95
99
|
step
|
|
96
100
|
}), state, trackRef);
|
|
97
101
|
return /*#__PURE__*/_jsxs(Box, _objectSpread(_objectSpread({}, groupProps), {}, {
|
|
98
102
|
className: styles.container,
|
|
99
103
|
odComponent: "slider",
|
|
100
104
|
testId: testId,
|
|
101
|
-
children: [
|
|
105
|
+
children: [hasTextLabel && /*#__PURE__*/_jsx("label", _objectSpread(_objectSpread({}, labelProps), {}, {
|
|
102
106
|
className: styles.label,
|
|
103
|
-
children:
|
|
104
|
-
})), /*#__PURE__*/_jsx("div", {
|
|
107
|
+
children: label
|
|
108
|
+
})), hasCustomLabel && /*#__PURE__*/React.cloneElement(label, _objectSpread({}, labelProps)), /*#__PURE__*/_jsx("div", {
|
|
105
109
|
className: styles.valueDisplay,
|
|
106
110
|
children: /*#__PURE__*/_jsxs("output", _objectSpread(_objectSpread({}, outputProps), {}, {
|
|
107
111
|
className: styles.valueText,
|