@povio/ui 2.2.9-rc.9 → 2.2.11
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/buttons/Button/Button.d.ts +2 -2
- package/dist/components/buttons/Button/Button.js +1 -1
- package/dist/components/buttons/PillButton/PillButton.d.ts +2 -2
- package/dist/components/buttons/PillButton/PillButton.js +1 -1
- package/dist/components/buttons/TextButton/TextButton.d.ts +2 -1
- package/dist/components/buttons/ToggleButton/ToggleButton.d.ts +2 -1
- package/dist/components/buttons/shared/ButtonContent.d.ts +3 -3
- package/dist/components/buttons/shared/ButtonContent.js +2 -2
- package/dist/components/inputs/Checkbox/Checkbox.js +1 -6
- package/dist/components/inputs/Checkbox/checkbox.cva.d.ts +0 -3
- package/dist/components/inputs/Checkbox/checkbox.cva.js +1 -2
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +9 -8
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +82 -35
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +4 -7
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +5 -15
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +8 -7
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +42 -23
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +3 -3
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +14 -21
- package/dist/components/inputs/DateTime/shared/Calendar.d.ts +6 -1
- package/dist/components/inputs/DateTime/shared/Calendar.js +85 -12
- package/dist/components/inputs/DateTime/shared/CalendarHeader.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/CalendarHeader.js +28 -4
- package/dist/components/inputs/DateTime/shared/DateField.d.ts +5 -1
- package/dist/components/inputs/DateTime/shared/DateField.js +54 -14
- package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +7 -5
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +20 -18
- package/dist/components/inputs/DateTime/shared/MonthPicker.d.ts +5 -1
- package/dist/components/inputs/DateTime/shared/MonthPicker.js +40 -8
- package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +1 -2
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +2 -7
- package/dist/components/inputs/DateTime/shared/YearPicker.d.ts +5 -1
- package/dist/components/inputs/DateTime/shared/YearPicker.js +42 -8
- package/dist/components/inputs/FormField/FormFieldHeader.js +1 -3
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +0 -1
- package/dist/components/inputs/Input/TextInput/TextInput.js +0 -3
- package/dist/components/inputs/Inputs/InputItem.d.ts +16 -10
- package/dist/components/inputs/Inputs/InputItem.js +0 -4
- package/dist/components/inputs/RadioGroup/RadioGroup.js +1 -6
- package/dist/components/inputs/RadioGroup/radio.cva.d.ts +0 -3
- package/dist/components/inputs/RadioGroup/radio.cva.js +1 -2
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +1 -3
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +3 -4
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +18 -3
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +7 -23
- package/dist/components/inputs/Selection/Select/Select.d.ts +2 -4
- package/dist/components/inputs/Selection/Select/Select.js +3 -4
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +1 -8
- package/dist/components/inputs/Selection/shared/SelectBase.js +1 -3
- package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +2 -8
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +3 -23
- package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +5 -10
- package/dist/components/inputs/Selection/shared/select.context.d.ts +2 -3
- package/dist/components/inputs/Selection/shared/select.context.js +4 -22
- package/dist/components/inputs/Selection/shared/select.types.d.ts +2 -2
- package/dist/components/inputs/TextEditor/TextEditor.d.ts +0 -1
- package/dist/components/inputs/TextEditor/TextEditor.js +3 -7
- package/dist/components/inputs/Toggle/Toggle.js +1 -6
- package/dist/components/inputs/Toggle/toggle.cva.d.ts +0 -3
- package/dist/components/inputs/Toggle/toggle.cva.js +1 -2
- package/dist/components/inputs/shared/CheckContent.d.ts +1 -2
- package/dist/components/inputs/shared/CheckContent.js +4 -3
- package/dist/components/overlays/BottomSheet/BottomSheet.js +1 -2
- package/dist/components/overlays/Tooltip/TooltipEllipsis.d.ts +2 -2
- package/dist/config/link.context.js +4 -2
- package/dist/config/uiConfig.context.d.ts +2 -8
- package/dist/config/uiConfig.context.js +3 -5
- package/dist/config/uiStyle.context.d.ts +1 -6
- package/dist/helpers/dynamicInputs.d.ts +5 -5
- package/dist/helpers/dynamicInputs.js +0 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.js +4 -5
- package/dist/utils/date-time.utils.d.ts +7 -6
- package/dist/utils/date-time.utils.js +66 -16
- package/package.json +1 -1
- package/dist/components/inputs/DateTime/shared/datePicker.types.d.ts +0 -3
- package/dist/components/inputs/FormField/formFieldHeader.cva.d.ts +0 -6
- package/dist/components/inputs/FormField/formFieldHeader.cva.js +0 -11
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +0 -30
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +0 -14
- package/dist/components/inputs/Selection/Select/QuerySelect.js +0 -56
- package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +0 -6
- package/dist/components/inputs/Selection/shared/querySelect.utils.js +0 -13
- package/dist/hooks/useQueryAutocomplete.d.ts +0 -25
- package/dist/hooks/useQueryAutocomplete.js +0 -41
|
@@ -2,6 +2,7 @@ import { CalendarIcon } from "../../../../assets/icons/Calendar.js";
|
|
|
2
2
|
import { DateTimeIcon } from "../../../../assets/icons/DateTime.js";
|
|
3
3
|
import { UIStyle } from "../../../../config/uiStyle.context.js";
|
|
4
4
|
import { Typography } from "../../../text/Typography/Typography.js";
|
|
5
|
+
import { IconButton } from "../../../buttons/IconButton/IconButton.js";
|
|
5
6
|
import { InlineIconButton } from "../../../buttons/InlineIconButton/InlineIconButton.js";
|
|
6
7
|
import { TodayIcon } from "../../../../assets/icons/Today.js";
|
|
7
8
|
import { DateField } from "./DateField.js";
|
|
@@ -15,7 +16,9 @@ import { Button } from "react-aria-components";
|
|
|
15
16
|
import { useFocusVisible, useFocusWithin, useHover } from "react-aria";
|
|
16
17
|
import { getLocalTimeZone, now, toCalendarDateTime, today } from "@internationalized/date";
|
|
17
18
|
//#region src/components/inputs/DateTime/shared/DatePickerInput.tsx
|
|
18
|
-
var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonProps, isDisabled, isInvalid, disableDropdown, variant, size, isDateTime, isClearable, headerProps, todayIcon,
|
|
19
|
+
var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonProps, isDisabled, isInvalid, disableDropdown, variant, size, isDateTime, isClearable, headerProps, todayIcon, isDirty, isRequired, disableManualEntry, placeholder, className, onOpenDropdown, dateGranularity = "day", timeZone, autoFixYear, isTimeOptional = false, format, ...props }) => {
|
|
20
|
+
let effectiveTimeZone = getLocalTimeZone();
|
|
21
|
+
if (timeZone) effectiveTimeZone = timeZone;
|
|
19
22
|
const inputBaseCva = UIStyle.useCva("input.baseCva", inputBase);
|
|
20
23
|
const inputSizeCva = UIStyle.useCva("input.sizeCva", inputSize);
|
|
21
24
|
const [canClear, setCanClear] = useState(false);
|
|
@@ -40,7 +43,6 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
40
43
|
if (endFieldProps) endFieldProps.onChange?.(null);
|
|
41
44
|
setCanClear(false);
|
|
42
45
|
fieldProps.onBlur?.(null);
|
|
43
|
-
endFieldProps?.onBlur?.(null);
|
|
44
46
|
},
|
|
45
47
|
getContainer: () => containerRef.current
|
|
46
48
|
}));
|
|
@@ -51,25 +53,19 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
51
53
|
dateFieldRef.current?.clearField();
|
|
52
54
|
fieldProps.onChange?.(null);
|
|
53
55
|
endDateFieldRef.current?.clearField();
|
|
54
|
-
endFieldProps?.onChange?.(null);
|
|
55
56
|
setCanClear(false);
|
|
56
|
-
fieldProps.onBlur?.(null);
|
|
57
|
-
endFieldProps?.onBlur?.(null);
|
|
58
57
|
};
|
|
59
58
|
const onToday = () => {
|
|
60
59
|
if (isDateTime) {
|
|
61
|
-
const calendarDateTime = toCalendarDateTime(now(
|
|
60
|
+
const calendarDateTime = toCalendarDateTime(now(effectiveTimeZone));
|
|
62
61
|
fieldProps.onChange?.(calendarDateTime);
|
|
63
62
|
if (endFieldProps) endFieldProps.onChange?.(calendarDateTime);
|
|
64
63
|
} else {
|
|
65
|
-
fieldProps.onChange?.(today(
|
|
66
|
-
if (endFieldProps) endFieldProps.onChange?.(today(
|
|
64
|
+
fieldProps.onChange?.(today(effectiveTimeZone));
|
|
65
|
+
if (endFieldProps) endFieldProps.onChange?.(today(effectiveTimeZone));
|
|
67
66
|
}
|
|
68
|
-
fieldProps.onBlur?.(null);
|
|
69
|
-
endFieldProps?.onBlur?.(null);
|
|
70
67
|
};
|
|
71
68
|
const hidePlaceholder = as === "floating" && !fieldProps.value && !isFocused;
|
|
72
|
-
const todayIconComponent = todayIcon === true ? TodayIcon : todayIcon || null;
|
|
73
69
|
return /* @__PURE__ */ jsxs("div", {
|
|
74
70
|
ref: containerRef,
|
|
75
71
|
className: clsx(inputBaseCva({
|
|
@@ -88,7 +84,6 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
88
84
|
"data-has-selection": fieldProps.value !== null || void 0,
|
|
89
85
|
"data-is-dirty": isDirty || void 0,
|
|
90
86
|
"data-is-required": isRequired || void 0,
|
|
91
|
-
"data-is-filled": fieldProps.value !== null || void 0,
|
|
92
87
|
...groupProps,
|
|
93
88
|
...focusWithinProps,
|
|
94
89
|
...hoverProps,
|
|
@@ -108,12 +103,12 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
108
103
|
className: "absolute inset-0 z-0",
|
|
109
104
|
isDisabled
|
|
110
105
|
}),
|
|
111
|
-
|
|
106
|
+
todayIcon && /* @__PURE__ */ jsx(IconButton, {
|
|
112
107
|
label: "",
|
|
113
|
-
icon:
|
|
114
|
-
size:
|
|
108
|
+
icon: TodayIcon,
|
|
109
|
+
size: "none",
|
|
115
110
|
onPress: onToday,
|
|
116
|
-
className: "relative z-1
|
|
111
|
+
className: "relative z-1"
|
|
117
112
|
}),
|
|
118
113
|
disableManualEntry && placeholder && !fieldProps.value ? /* @__PURE__ */ jsx(Typography, {
|
|
119
114
|
size: "label-1",
|
|
@@ -126,7 +121,11 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
126
121
|
isInvalid,
|
|
127
122
|
onClearChange,
|
|
128
123
|
hidePlaceholder,
|
|
129
|
-
disableManualEntry
|
|
124
|
+
disableManualEntry,
|
|
125
|
+
dateGranularity,
|
|
126
|
+
isTimeOptional,
|
|
127
|
+
format,
|
|
128
|
+
timeZone: effectiveTimeZone
|
|
130
129
|
}), endFieldProps && /* @__PURE__ */ jsxs(Fragment, { children: [!((as === "floating" || as === "filter") && hidePlaceholder) && /* @__PURE__ */ jsx("span", {
|
|
131
130
|
className: clsx("pointer-events-none select-none", isDisabled && "text-interactive-text-secondary-disabled"),
|
|
132
131
|
children: "–"
|
|
@@ -137,7 +136,10 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
137
136
|
isInvalid,
|
|
138
137
|
onClearChange,
|
|
139
138
|
hidePlaceholder,
|
|
140
|
-
disableManualEntry
|
|
139
|
+
disableManualEntry,
|
|
140
|
+
isTimeOptional,
|
|
141
|
+
format,
|
|
142
|
+
timeZone: effectiveTimeZone
|
|
141
143
|
})] })] })
|
|
142
144
|
]
|
|
143
145
|
})]
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { CalendarDate } from '@internationalized/date';
|
|
1
2
|
import { CalendarState, RangeCalendarState } from '@react-stately/calendar';
|
|
2
3
|
import { Key } from 'react-aria-components';
|
|
3
4
|
export interface MonthPickerProps {
|
|
4
5
|
state: CalendarState | RangeCalendarState;
|
|
5
6
|
onSelectionChange: (key: Set<Key>) => void;
|
|
7
|
+
onDateChange?: (selectedDate: CalendarDate) => void;
|
|
8
|
+
onCommit?: () => void;
|
|
9
|
+
selectedDate?: CalendarDate | null;
|
|
6
10
|
}
|
|
7
|
-
export declare const MonthPicker: ({ state, onSelectionChange }: MonthPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const MonthPicker: ({ state, onSelectionChange, onDateChange, onCommit, selectedDate }: MonthPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Typography } from "../../../text/Typography/Typography.js";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { clsx } from "clsx";
|
|
4
|
+
import { useRef } from "react";
|
|
4
5
|
import { ListBox, ListBoxItem } from "react-aria-components";
|
|
5
6
|
import { useDateFormatter } from "@react-aria/i18n";
|
|
6
7
|
//#region src/components/inputs/DateTime/shared/MonthPicker.tsx
|
|
7
|
-
var MonthPicker = ({ state, onSelectionChange }) => {
|
|
8
|
+
var MonthPicker = ({ state, onSelectionChange, onDateChange, onCommit, selectedDate }) => {
|
|
8
9
|
const formatter = useDateFormatter({
|
|
9
10
|
month: "long",
|
|
10
11
|
timeZone: state.timeZone
|
|
@@ -23,34 +24,65 @@ var MonthPicker = ({ state, onSelectionChange }) => {
|
|
|
23
24
|
if (state.maxValue && state.focusedDate.set({ month }) > state.maxValue) return true;
|
|
24
25
|
return false;
|
|
25
26
|
};
|
|
27
|
+
const getSelectedMonth = () => {
|
|
28
|
+
if (!selectedDate) return null;
|
|
29
|
+
return selectedDate.month;
|
|
30
|
+
};
|
|
31
|
+
const selectedMonth = getSelectedMonth();
|
|
32
|
+
const lastPressedMonthRef = useRef(null);
|
|
33
|
+
const listBoxSelectionProps = {};
|
|
34
|
+
if (selectedMonth !== null) listBoxSelectionProps.selectedKeys = [selectedMonth];
|
|
35
|
+
const parseMonthFromKey = (key) => {
|
|
36
|
+
if (typeof key === "number") return key;
|
|
37
|
+
if (typeof key === "string") {
|
|
38
|
+
const parsedMonth = Number.parseInt(key, 10);
|
|
39
|
+
if (!Number.isNaN(parsedMonth)) return parsedMonth;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
26
43
|
return /* @__PURE__ */ jsx(ListBox, {
|
|
27
44
|
autoFocus: true,
|
|
28
45
|
"aria-label": "Month",
|
|
29
46
|
selectionMode: "single",
|
|
30
47
|
layout: "grid",
|
|
31
|
-
|
|
48
|
+
...listBoxSelectionProps,
|
|
32
49
|
onSelectionChange: (key) => {
|
|
33
50
|
if (key === "all") return;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const selectedKey = [...key][0];
|
|
52
|
+
const selectedMonthValue = parseMonthFromKey(selectedKey);
|
|
53
|
+
if (selectedMonthValue !== null) {
|
|
54
|
+
const nextSelectedDate = state.focusedDate.set({ month: selectedMonthValue });
|
|
55
|
+
state.setFocusedDate(nextSelectedDate);
|
|
56
|
+
onDateChange?.(nextSelectedDate);
|
|
37
57
|
}
|
|
38
58
|
onSelectionChange(key);
|
|
39
59
|
},
|
|
40
60
|
className: "grid size-full min-h-72 grid-cols-3 grid-rows-4 gap-2 p-3 md:w-80",
|
|
41
61
|
children: getMonths().map((month, index) => {
|
|
42
|
-
const
|
|
62
|
+
const monthNumber = index + 1;
|
|
63
|
+
const isDisabled = isMonthDisabled(monthNumber);
|
|
43
64
|
return /* @__PURE__ */ jsx(ListBoxItem, {
|
|
44
|
-
id:
|
|
65
|
+
id: monthNumber,
|
|
45
66
|
textValue: month,
|
|
46
67
|
isDisabled,
|
|
68
|
+
onPress: () => {
|
|
69
|
+
const isSecondConsecutivePress = lastPressedMonthRef.current === monthNumber;
|
|
70
|
+
lastPressedMonthRef.current = monthNumber;
|
|
71
|
+
const nextSelectedDate = state.focusedDate.set({ month: monthNumber });
|
|
72
|
+
state.setFocusedDate(nextSelectedDate);
|
|
73
|
+
onDateChange?.(nextSelectedDate);
|
|
74
|
+
if (!isSecondConsecutivePress) return;
|
|
75
|
+
if (selectedMonth === null) return;
|
|
76
|
+
if (monthNumber !== selectedMonth) return;
|
|
77
|
+
onCommit?.();
|
|
78
|
+
},
|
|
47
79
|
className: clsx("flex items-center justify-center text-interactive-text-secondary-idle", "rounded-button-rounding-m border border-elevation-outline-default-1 border-solid bg-elevation-fill-default-1", "hover:text-interactive-text-secondary-hover", "selected:border-interactive-contained-primary-idle selected:bg-interactive-contained-primary-idle selected:text-interactive-text-secondary-idle-inverted", "focus:outline-none focus-visible:outline-1 focus-visible:outline-interactive-contained-primary-focus focus-visible:outline-offset-1", isDisabled ? "cursor-default opacity-50" : "cursor-pointer"),
|
|
48
80
|
children: /* @__PURE__ */ jsx(Typography, {
|
|
49
81
|
as: "span",
|
|
50
82
|
size: "label-2",
|
|
51
83
|
children: month
|
|
52
84
|
})
|
|
53
|
-
},
|
|
85
|
+
}, monthNumber);
|
|
54
86
|
})
|
|
55
87
|
});
|
|
56
88
|
};
|
|
@@ -9,7 +9,6 @@ interface DatePickerInputProps extends InputVariantProps {
|
|
|
9
9
|
state: TimeFieldState;
|
|
10
10
|
isDisabled?: boolean;
|
|
11
11
|
isDirty?: boolean;
|
|
12
|
-
isRequired?: boolean;
|
|
13
12
|
isInvalid?: boolean;
|
|
14
13
|
disableDropdown?: boolean;
|
|
15
14
|
headerProps?: FormFieldHeaderProps;
|
|
@@ -19,5 +18,5 @@ interface DatePickerInputProps extends InputVariantProps {
|
|
|
19
18
|
className?: string;
|
|
20
19
|
onPress: () => void;
|
|
21
20
|
}
|
|
22
|
-
export declare const TimePickerInput: ({ ref, as, fieldProps, state, isDisabled, isDirty,
|
|
21
|
+
export declare const TimePickerInput: ({ ref, as, fieldProps, state, isDisabled, isDirty, isInvalid, disableDropdown, variant, size, isClearable, headerProps, disableManualEntry, placeholder, className, onPress, ...props }: DatePickerInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
23
22
|
export {};
|
|
@@ -12,7 +12,7 @@ import { useState } from "react";
|
|
|
12
12
|
import { Button } from "react-aria-components";
|
|
13
13
|
import { useFocusVisible, useFocusWithin, useHover } from "react-aria";
|
|
14
14
|
//#region src/components/inputs/DateTime/shared/TimePickerInput.tsx
|
|
15
|
-
var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty,
|
|
15
|
+
var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty, isInvalid, disableDropdown, variant, size, isClearable, headerProps, disableManualEntry, placeholder, className, onPress, ...props }) => {
|
|
16
16
|
const inputBaseCva = UIStyle.useCva("input.baseCva", inputBase);
|
|
17
17
|
const inputSizeCva = UIStyle.useCva("input.sizeCva", inputSize);
|
|
18
18
|
const { hoverProps, isHovered } = useHover({ isDisabled });
|
|
@@ -38,8 +38,6 @@ var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty, isRequ
|
|
|
38
38
|
"data-focus-visible": isFocused && isFocusVisible || void 0,
|
|
39
39
|
"data-has-selection": state.value !== null || void 0,
|
|
40
40
|
"data-is-dirty": isDirty || void 0,
|
|
41
|
-
"data-is-required": isRequired || void 0,
|
|
42
|
-
"data-is-filled": state.value !== null || void 0,
|
|
43
41
|
...fieldProps,
|
|
44
42
|
...focusWithinProps,
|
|
45
43
|
...hoverProps,
|
|
@@ -74,10 +72,7 @@ var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty, isRequ
|
|
|
74
72
|
as
|
|
75
73
|
}), "flex items-center gap-input-gap-trailing-elements py-0! pl-0!"),
|
|
76
74
|
children: [isClearable && /* @__PURE__ */ jsx(InputClear, {
|
|
77
|
-
onClear: () =>
|
|
78
|
-
state.setValue(null);
|
|
79
|
-
fieldProps.onBlur?.(null);
|
|
80
|
-
},
|
|
75
|
+
onClear: () => state.setValue(null),
|
|
81
76
|
show: canClear
|
|
82
77
|
}), (!disableDropdown || disableManualEntry) && /* @__PURE__ */ jsx(InlineIconButton, {
|
|
83
78
|
label: "",
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { CalendarDate } from '@internationalized/date';
|
|
1
2
|
import { CalendarState, RangeCalendarState } from '@react-stately/calendar';
|
|
2
3
|
import { Key } from 'react-aria-components';
|
|
3
4
|
interface YearPickerProps {
|
|
4
5
|
state: CalendarState | RangeCalendarState;
|
|
5
6
|
onSelectionChange: (key: Set<Key>) => void;
|
|
7
|
+
onDateChange?: (selectedDate: CalendarDate) => void;
|
|
8
|
+
onCommit?: () => void;
|
|
9
|
+
selectedDate?: CalendarDate | null;
|
|
6
10
|
}
|
|
7
|
-
export declare const YearPicker: ({ state, onSelectionChange }: YearPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const YearPicker: ({ state, onSelectionChange, onDateChange, onCommit, selectedDate }: YearPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
12
|
export {};
|
|
@@ -2,12 +2,12 @@ import { Typography } from "../../../text/Typography/Typography.js";
|
|
|
2
2
|
import { useScrollableListBox } from "../../../../hooks/useScrollableListBox.js";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { clsx } from "clsx";
|
|
5
|
-
import { useMemo } from "react";
|
|
5
|
+
import { useMemo, useRef } from "react";
|
|
6
6
|
import { ListBox, ListBoxItem } from "react-aria-components";
|
|
7
7
|
import { today } from "@internationalized/date";
|
|
8
8
|
import { useDateFormatter } from "@react-aria/i18n";
|
|
9
9
|
//#region src/components/inputs/DateTime/shared/YearPicker.tsx
|
|
10
|
-
var YearPicker = ({ state, onSelectionChange }) => {
|
|
10
|
+
var YearPicker = ({ state, onSelectionChange, onDateChange, onCommit, selectedDate }) => {
|
|
11
11
|
const formatter = useDateFormatter({
|
|
12
12
|
year: "numeric",
|
|
13
13
|
timeZone: state.timeZone
|
|
@@ -28,20 +28,42 @@ var YearPicker = ({ state, onSelectionChange }) => {
|
|
|
28
28
|
if (state.maxValue && year > state.maxValue.year) return true;
|
|
29
29
|
return false;
|
|
30
30
|
};
|
|
31
|
-
const
|
|
31
|
+
const getSelectedYearIndex = () => {
|
|
32
|
+
if (selectedDate) {
|
|
33
|
+
const selectedIndexFromValue = years.findIndex((year) => year.value === selectedDate.year);
|
|
34
|
+
if (selectedIndexFromValue >= 0) return selectedIndexFromValue;
|
|
35
|
+
}
|
|
36
|
+
const focusedYearIndex = years.findIndex((year) => year.value === state.focusedDate.year);
|
|
37
|
+
if (focusedYearIndex < 0) return null;
|
|
38
|
+
return focusedYearIndex;
|
|
39
|
+
};
|
|
40
|
+
const selectedYearIndex = getSelectedYearIndex();
|
|
41
|
+
const lastPressedYearIndexRef = useRef(null);
|
|
42
|
+
const listBoxSelectionProps = {};
|
|
43
|
+
if (selectedYearIndex !== null) listBoxSelectionProps.selectedKeys = [selectedYearIndex];
|
|
44
|
+
const parseYearIndexFromKey = (key) => {
|
|
45
|
+
if (typeof key === "number") return key;
|
|
46
|
+
if (typeof key === "string") {
|
|
47
|
+
const parsedIndex = Number.parseInt(key, 10);
|
|
48
|
+
if (!Number.isNaN(parsedIndex)) return parsedIndex;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
32
52
|
const { ref } = useScrollableListBox();
|
|
33
53
|
return /* @__PURE__ */ jsx(ListBox, {
|
|
34
54
|
ref,
|
|
35
55
|
autoFocus: true,
|
|
36
56
|
"aria-label": "Year",
|
|
37
57
|
selectionMode: "single",
|
|
38
|
-
|
|
58
|
+
...listBoxSelectionProps,
|
|
39
59
|
onSelectionChange: (key) => {
|
|
40
60
|
if (key === "all") return;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
state.
|
|
61
|
+
const selectedKey = [...key][0];
|
|
62
|
+
const selectedYearIndexValue = parseYearIndexFromKey(selectedKey);
|
|
63
|
+
if (selectedYearIndexValue !== null && years[selectedYearIndexValue]) {
|
|
64
|
+
const nextSelectedDate = state.focusedDate.set({ year: years[selectedYearIndexValue].value });
|
|
65
|
+
state.setFocusedDate(nextSelectedDate);
|
|
66
|
+
onDateChange?.(nextSelectedDate);
|
|
45
67
|
}
|
|
46
68
|
onSelectionChange(key);
|
|
47
69
|
},
|
|
@@ -52,6 +74,18 @@ var YearPicker = ({ state, onSelectionChange }) => {
|
|
|
52
74
|
id: index,
|
|
53
75
|
textValue: year.formatted,
|
|
54
76
|
isDisabled,
|
|
77
|
+
onPress: () => {
|
|
78
|
+
const isSecondConsecutivePress = lastPressedYearIndexRef.current === index;
|
|
79
|
+
lastPressedYearIndexRef.current = index;
|
|
80
|
+
const nextSelectedDate = state.focusedDate.set({ year: year.value });
|
|
81
|
+
state.setFocusedDate(nextSelectedDate);
|
|
82
|
+
onDateChange?.(nextSelectedDate);
|
|
83
|
+
if (!isSecondConsecutivePress) return;
|
|
84
|
+
if (!selectedDate) return;
|
|
85
|
+
if (selectedYearIndex === null) return;
|
|
86
|
+
if (index !== selectedYearIndex) return;
|
|
87
|
+
onCommit?.();
|
|
88
|
+
},
|
|
55
89
|
className: clsx("flex px-4 py-2 text-interactive-text-secondary-idle outline-none", "border-elevation-outline-default-1 border-b border-solid bg-elevation-fill-default-1 last:border-b-0", "hover:text-interactive-text-secondary-hover", "selected:bg-interactive-contained-primary-idle selected:text-interactive-text-secondary-idle-inverted", "focus-visible:bg-interactive-contained-primary-focus focus-visible:text-interactive-text-secondary-idle-inverted", isDisabled ? "cursor-default opacity-50" : "cursor-pointer"),
|
|
56
90
|
children: /* @__PURE__ */ jsx(Typography, {
|
|
57
91
|
as: "span",
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { InfoIcon } from "../../../assets/icons/Info.js";
|
|
2
|
-
import { UIStyle } from "../../../config/uiStyle.context.js";
|
|
3
2
|
import { Typography } from "../../text/Typography/Typography.js";
|
|
4
3
|
import { Tooltip as Tooltip$1 } from "../../overlays/Tooltip/Tooltip.js";
|
|
5
4
|
import { FormFieldLabel } from "./FormFieldLabel.js";
|
|
6
|
-
import { formFieldHeader } from "./formFieldHeader.cva.js";
|
|
7
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
import { clsx } from "clsx";
|
|
9
7
|
import { Focusable } from "react-aria-components";
|
|
10
8
|
//#region src/components/inputs/FormField/FormFieldHeader.tsx
|
|
11
9
|
var FormFieldHeader = ({ label, tooltipText, helperText, isRequired, rightContent, isHeaderHidden, isDisabled, className, labelProps }) => {
|
|
12
10
|
return /* @__PURE__ */ jsxs("div", {
|
|
13
|
-
className: clsx(
|
|
11
|
+
className: clsx(isHeaderHidden ? "sr-only" : "mb-1", className),
|
|
14
12
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
15
13
|
className: "flex items-start justify-between",
|
|
16
14
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -101,7 +101,6 @@ var NumberInputBase = (props) => {
|
|
|
101
101
|
"data-is-dirty": isDirty || void 0,
|
|
102
102
|
"data-is-required": isRequired || void 0,
|
|
103
103
|
"data-is-empty": value === null || value === void 0 || void 0,
|
|
104
|
-
"data-is-filled": !("" + value === "" || value === null || value === void 0) || void 0,
|
|
105
104
|
placeholder: as === "floating" ? "\xA0" : inputProps.placeholder,
|
|
106
105
|
className: "w-full outline-none",
|
|
107
106
|
onFocus: (e) => {
|
|
@@ -75,8 +75,6 @@ var TextInputBase = (props) => {
|
|
|
75
75
|
labelProps,
|
|
76
76
|
className: clsx("group w-full", as === "inline" && "h-full", className),
|
|
77
77
|
tabIndex: as === "inline" ? -1 : void 0,
|
|
78
|
-
"data-is-empty": value === "" || value === null || value === void 0 || void 0,
|
|
79
|
-
"data-is-required": isRequired || void 0,
|
|
80
78
|
children: /* @__PURE__ */ jsx("div", {
|
|
81
79
|
className: clsx("relative flex cursor-text has-disabled:cursor-default", inputBaseCva({
|
|
82
80
|
variant,
|
|
@@ -93,7 +91,6 @@ var TextInputBase = (props) => {
|
|
|
93
91
|
...inputProps,
|
|
94
92
|
ref: mergeRefs(ref, inputRef),
|
|
95
93
|
"data-is-empty": value === "" || value === null || value === void 0 || void 0,
|
|
96
|
-
"data-is-filled": !(value === "" || value === null || value === void 0) || void 0,
|
|
97
94
|
"data-is-dirty": isDirty || void 0,
|
|
98
95
|
"data-is-required": isRequired || void 0,
|
|
99
96
|
"data-is-disabled": isDisabled || void 0,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ComponentProps, JSXElementConstructor, ReactElement, ReactNode } from 'react';
|
|
2
2
|
import { Control, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { Autocomplete } from '../Selection/Autocomplete/Autocomplete';
|
|
5
|
-
import { Select } from '../Selection/Select/Select';
|
|
6
4
|
import { HasRequiredProperty } from '../../../types/common';
|
|
7
5
|
declare const componentRegistry: {
|
|
8
6
|
readonly toggle: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Toggle/Toggle').ControlledToggleProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,16 +10,24 @@ declare const componentRegistry: {
|
|
|
12
10
|
readonly textInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/TextInput/TextInput').ControlledTextInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
13
11
|
readonly passwordInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/PasswordInput/PasswordInput').ControlledPasswordInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
14
12
|
readonly textArea: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/TextArea/TextArea').ControlledTextAreaProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
readonly select:
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
|
|
13
|
+
readonly select: <TFieldValues extends import('react-hook-form').FieldValues, TKey extends import('react-aria').Key = import('react-aria').Key, TInitialSelectItem = import('../Selection/shared/select.types').DefaultInitialSelectItem<TKey>>(props: import('../Selection/Select/Select').ControlledSelectProps<TFieldValues, TKey, TInitialSelectItem>) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
readonly autocomplete: <TFieldValues extends import('react-hook-form').FieldValues, TKey extends import('react-aria').Key = import('react-aria').Key, TInitialSelectItem = import('../Selection/shared/select.types').DefaultInitialSelectItem<TKey>>(props: import('../Selection/Autocomplete/Autocomplete').ControlledAutocompleteProps<TFieldValues, TKey, TInitialSelectItem>) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
readonly queryAutocomplete: <TFieldValues extends import('react-hook-form').FieldValues, TSelectItem extends import('../Selection/shared/select.types').SelectItem<any>, TQueryFn extends (...args: any) => import('@tanstack/react-query').UseQueryResult<TSelectItem[]>>({ query, queryParams, queryOptions, ...props }: import('../../../types/common').OmitDiscriminatedUnion<import('../Selection/Autocomplete/Autocomplete').AutocompleteProps<Exclude<ReturnType<TQueryFn>["data"], undefined>[0] extends {
|
|
16
|
+
id: infer InferredKey extends import('react-aria').Key;
|
|
17
|
+
} ? InferredKey : never>, "onChange" | "value" | "items" | "selectionMode" | "isLoading" | "showSelectionBar" | "showSelectAllOption" | "initialSelection" | "showSelectionContent" | "onSearchChange"> & (import('../Selection/shared/select.types').GroupedSelectControlProps<TFieldValues, Exclude<ReturnType<TQueryFn>["data"], undefined>[0] extends {
|
|
18
|
+
id: infer InferredKey extends import('react-aria').Key;
|
|
19
|
+
} ? InferredKey : never> & {
|
|
20
|
+
query: Parameters<TQueryFn>[0] extends {
|
|
21
|
+
search?: string;
|
|
22
|
+
} ? TQueryFn : never;
|
|
23
|
+
queryParams?: Omit<Parameters<TQueryFn>[0], "search"> | undefined;
|
|
24
|
+
queryOptions?: Parameters<TQueryFn>[1] | undefined;
|
|
25
|
+
})) => import("react/jsx-runtime").JSX.Element;
|
|
19
26
|
readonly segment: <TFieldValues extends import('react-hook-form').FieldValues, TKey extends import('react-aria').Key = import('react-aria').Key>(props: import('../../..').ControlledSegmentProps<TFieldValues, TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
readonly datePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, minValue, maxValue, ...props }: import('../DateTime/DatePicker/DatePicker').ControlledDatePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
readonly datePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, granularity, minValue, maxValue, ...props }: import('../DateTime/DatePicker/DatePicker').ControlledDatePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
21
28
|
readonly dateTimePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, ...props }: import('../DateTime/DateTimePicker/DateTimePicker').ControlledDateTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
22
29
|
readonly timePicker: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../DateTime/TimePicker/TimePicker').ControlledTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
23
30
|
readonly dateRangePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, minValue, maxValue, ...props }: import('../DateTime/DateRangePicker/DateRangePicker').ControlledDateRangePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
-
readonly textEditor: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../../../text-editor.js').ControlledTextEditorProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
25
31
|
readonly unknown: null;
|
|
26
32
|
};
|
|
27
33
|
export type InputComponentRegistry = typeof componentRegistry;
|
|
@@ -50,8 +56,8 @@ type TypeBasedInputDef<TSchemaType extends Record<string, any>, T extends InputC
|
|
|
50
56
|
interface RenderBasedInputDef<TSchemaType extends Record<string, any>, K extends keyof TSchemaType> {
|
|
51
57
|
type?: never;
|
|
52
58
|
name: K;
|
|
53
|
-
label?:
|
|
54
|
-
placeholder?:
|
|
59
|
+
label?: never;
|
|
60
|
+
placeholder?: never;
|
|
55
61
|
props?: never;
|
|
56
62
|
inputWrapper?: never;
|
|
57
63
|
render: (formControl: {
|
|
@@ -13,8 +13,6 @@ import { QueryAutocomplete } from "../Selection/Autocomplete/QueryAutocomplete.j
|
|
|
13
13
|
import { Slider } from "../Slider/Slider.js";
|
|
14
14
|
import { Toggle } from "../Toggle/Toggle.js";
|
|
15
15
|
import { Segment } from "../../segment/Segment.js";
|
|
16
|
-
import { QuerySelect } from "../Selection/Select/QuerySelect.js";
|
|
17
|
-
import { TextEditor } from "../TextEditor/TextEditor.js";
|
|
18
16
|
import { jsx } from "react/jsx-runtime";
|
|
19
17
|
//#region src/components/inputs/Inputs/InputItem.tsx
|
|
20
18
|
var componentRegistry = {
|
|
@@ -26,7 +24,6 @@ var componentRegistry = {
|
|
|
26
24
|
passwordInput: PasswordInput,
|
|
27
25
|
textArea: TextArea,
|
|
28
26
|
select: Select,
|
|
29
|
-
querySelect: QuerySelect,
|
|
30
27
|
autocomplete: Autocomplete,
|
|
31
28
|
queryAutocomplete: QueryAutocomplete,
|
|
32
29
|
segment: Segment,
|
|
@@ -34,7 +31,6 @@ var componentRegistry = {
|
|
|
34
31
|
dateTimePicker: DateTimePicker,
|
|
35
32
|
timePicker: TimePicker,
|
|
36
33
|
dateRangePicker: DateRangePicker,
|
|
37
|
-
textEditor: TextEditor,
|
|
38
34
|
unknown: null
|
|
39
35
|
};
|
|
40
36
|
function InputItem({ form, inputDef }) {
|
|
@@ -2,7 +2,7 @@ import { UIStyle } from "../../../config/uiStyle.context.js";
|
|
|
2
2
|
import { UIConfig } from "../../../config/uiConfig.context.js";
|
|
3
3
|
import { CheckContent } from "../shared/CheckContent.js";
|
|
4
4
|
import { FormField } from "../FormField/FormField.js";
|
|
5
|
-
import { radio,
|
|
5
|
+
import { radio, radioIndicatorClass, radioTypography } from "./radio.cva.js";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { clsx } from "clsx";
|
|
8
8
|
import { Radio, RadioGroup } from "react-aria-components";
|
|
@@ -13,7 +13,6 @@ var RadioGroupBase = (props) => {
|
|
|
13
13
|
const ui = UIConfig.useConfig();
|
|
14
14
|
const radioCva = UIStyle.useCva("radio.cva", radio);
|
|
15
15
|
const radioTypographyMap = UIStyle.useMapper("radio.typography", radioTypography);
|
|
16
|
-
const radioContentClassNameMap = UIStyle.useMapper("radio.contentClassName", radioContentClassName);
|
|
17
16
|
const { label, tooltipText, helperText, isDirty, isRequired, rightContent, isDisabled, headerClassName, errorClassName, labelClassName, inputClassName, isHeaderHidden, error, className, options, variant = ui.radioGroup.variant, hideLabel = ui.radioGroup.hideLabel, ...rest } = props;
|
|
18
17
|
const formFieldProps = {
|
|
19
18
|
className,
|
|
@@ -50,10 +49,6 @@ var RadioGroupBase = (props) => {
|
|
|
50
49
|
variant,
|
|
51
50
|
...rest
|
|
52
51
|
}),
|
|
53
|
-
contentClassName: radioContentClassNameMap({
|
|
54
|
-
variant,
|
|
55
|
-
...rest
|
|
56
|
-
}),
|
|
57
52
|
className: labelClassName,
|
|
58
53
|
children: option.label
|
|
59
54
|
})]
|
|
@@ -9,6 +9,3 @@ export declare const radioIndicatorClass = "group flex items-center gap-2";
|
|
|
9
9
|
export declare const radioTypography: (props: {
|
|
10
10
|
variant?: "default" | null | undefined;
|
|
11
11
|
}) => TypographyVariantProps | undefined;
|
|
12
|
-
export declare const radioContentClassName: (props: {
|
|
13
|
-
variant?: "default" | null | undefined;
|
|
14
|
-
}) => string | undefined;
|
|
@@ -31,6 +31,5 @@ var radioTypography = compoundMapper({ default: {
|
|
|
31
31
|
sizeMobile: "label-1",
|
|
32
32
|
variant: "default"
|
|
33
33
|
} });
|
|
34
|
-
var radioContentClassName = compoundMapper({ default: "text-text-default-2" });
|
|
35
34
|
//#endregion
|
|
36
|
-
export { radio,
|
|
35
|
+
export { radio, radioIndicatorClass, radioTypography };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
1
|
import { Key } from 'react-aria-components';
|
|
3
2
|
import { FieldValues } from 'react-hook-form';
|
|
4
3
|
import { SelectBaseProps } from '../shared/SelectBase';
|
|
@@ -6,5 +5,4 @@ import { DefaultInitialSelectItem, GroupedSelectControlProps, GroupedSelectProps
|
|
|
6
5
|
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
7
6
|
export type AutocompleteProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = OmitDiscriminatedUnion<SelectBaseProps<TKey, TInitialSelectItem>, "isSearchable">;
|
|
8
7
|
export type ControlledAutocompleteProps<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = Omit<AutocompleteProps<TKey, TInitialSelectItem>, keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey, TInitialSelectItem>;
|
|
9
|
-
export declare
|
|
10
|
-
export declare function Autocomplete<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: ControlledAutocompleteProps<TFieldValues, TKey, TInitialSelectItem>): ReactElement;
|
|
8
|
+
export declare const Autocomplete: <TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: ControlledAutocompleteProps<TFieldValues, TKey, TInitialSelectItem>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,19 +3,18 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { mergeRefs } from "@react-aria/utils";
|
|
4
4
|
import { Controller } from "react-hook-form";
|
|
5
5
|
//#region src/components/inputs/Selection/Autocomplete/Autocomplete.tsx
|
|
6
|
-
|
|
6
|
+
var Autocomplete = (props) => {
|
|
7
7
|
if ("formControl" in props && props.formControl) {
|
|
8
8
|
const { formControl, ref, ...innerProps } = props;
|
|
9
9
|
return /* @__PURE__ */ jsx(Controller, {
|
|
10
10
|
control: formControl.control,
|
|
11
11
|
name: formControl.name,
|
|
12
|
-
render: ({ field, fieldState: { error
|
|
12
|
+
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx(SelectBase, {
|
|
13
13
|
...innerProps,
|
|
14
14
|
ref: mergeRefs(ref, field.ref),
|
|
15
15
|
value: field.value,
|
|
16
16
|
onChange: field.onChange,
|
|
17
17
|
onBlur: field.onBlur,
|
|
18
|
-
isDirty,
|
|
19
18
|
isDisabled: field.disabled || props.isDisabled,
|
|
20
19
|
error: props.error ?? error?.message,
|
|
21
20
|
isSearchable: true
|
|
@@ -26,6 +25,6 @@ function Autocomplete(props) {
|
|
|
26
25
|
...props,
|
|
27
26
|
isSearchable: true
|
|
28
27
|
});
|
|
29
|
-
}
|
|
28
|
+
};
|
|
30
29
|
//#endregion
|
|
31
30
|
export { Autocomplete };
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
1
3
|
import { FieldValues } from 'react-hook-form';
|
|
2
|
-
import {
|
|
3
|
-
import { SelectItem } from '../shared/select.types';
|
|
4
|
-
|
|
4
|
+
import { AutocompleteProps } from './Autocomplete';
|
|
5
|
+
import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
|
|
6
|
+
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
7
|
+
type QueryFn<TSelectItem extends SelectItem = SelectItem> = (...args: any) => UseQueryResult<Array<TSelectItem>>;
|
|
8
|
+
type TKey<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>[0] extends {
|
|
9
|
+
id: infer InferredKey extends Key;
|
|
10
|
+
} ? InferredKey : never;
|
|
11
|
+
type QueryAutocompleteProps<TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>> = OmitDiscriminatedUnion<AutocompleteProps<TKey<TQueryFn>>, "items" | "onSearchChange" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey<TQueryFn>> & {
|
|
12
|
+
query: Parameters<TQueryFn>[0] extends {
|
|
13
|
+
search?: string;
|
|
14
|
+
} ? TQueryFn : never;
|
|
15
|
+
queryParams?: Omit<Parameters<TQueryFn>[0], "search">;
|
|
16
|
+
queryOptions?: Parameters<TQueryFn>[1];
|
|
17
|
+
};
|
|
18
|
+
export declare const QueryAutocomplete: <TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>>({ query, queryParams, queryOptions, ...props }: QueryAutocompleteProps<TFieldValues, TSelectItem, TQueryFn>) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
2
1
|
import { Autocomplete } from "./Autocomplete.js";
|
|
3
|
-
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
4
2
|
import { jsx } from "react/jsx-runtime";
|
|
5
3
|
import { useState } from "react";
|
|
6
4
|
//#region src/components/inputs/Selection/Autocomplete/QueryAutocomplete.tsx
|
|
7
|
-
var QueryAutocomplete = ({ query, queryParams, queryOptions,
|
|
8
|
-
const ui = UIConfig.useConfig();
|
|
5
|
+
var QueryAutocomplete = ({ query, queryParams, queryOptions, ...props }) => {
|
|
9
6
|
const [search, setSearch] = useState("");
|
|
10
|
-
const
|
|
11
|
-
const extractedData = Array.isArray(data) ? data : data.pages.flatMap((page) => page.items ?? []);
|
|
12
|
-
return queryMap?.(extractedData) ?? extractedData;
|
|
13
|
-
};
|
|
14
|
-
const { items, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
15
|
-
query,
|
|
16
|
-
queryParams,
|
|
17
|
-
queryOptions,
|
|
18
|
-
mapItems: (data) => mapItems(data),
|
|
7
|
+
const { data: items, isLoading } = query({
|
|
19
8
|
search,
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
const { isInitialQueryDisabled: _, ...restProps } = props;
|
|
9
|
+
...queryParams
|
|
10
|
+
}, queryOptions);
|
|
23
11
|
return /* @__PURE__ */ jsx(Autocomplete, {
|
|
24
|
-
...
|
|
25
|
-
items,
|
|
12
|
+
...props,
|
|
13
|
+
items: items ?? [],
|
|
26
14
|
onSearchChange: setSearch,
|
|
27
15
|
isClientSearchDisabled: true,
|
|
28
|
-
isLoading
|
|
29
|
-
onMouseEnter: handleEnableQuery,
|
|
30
|
-
onFocusCapture: handleEnableQuery,
|
|
31
|
-
hasLoadMore: hasNextPage,
|
|
32
|
-
onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0
|
|
16
|
+
isLoading
|
|
33
17
|
});
|
|
34
18
|
};
|
|
35
19
|
//#endregion
|