@povio/ui 2.2.9-rc.2 → 2.2.9-rc.21
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/InlineIconButton/InlineIconButton.d.ts +1 -1
- package/dist/components/buttons/InlineIconButton/InlineIconButton.js +2 -2
- package/dist/components/inputs/Checkbox/Checkbox.js +6 -1
- package/dist/components/inputs/Checkbox/checkbox.cva.d.ts +3 -0
- package/dist/components/inputs/Checkbox/checkbox.cva.js +2 -1
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +9 -4
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +97 -9
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +9 -4
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +116 -7
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +10 -4
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +92 -7
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +5 -3
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +80 -6
- package/dist/components/inputs/DateTime/shared/Calendar.d.ts +5 -2
- package/dist/components/inputs/DateTime/shared/Calendar.js +23 -6
- package/dist/components/inputs/DateTime/shared/CalendarCell.d.ts +1 -1
- package/dist/components/inputs/DateTime/shared/CalendarCell.js +3 -3
- package/dist/components/inputs/DateTime/shared/CalendarGrid.d.ts +1 -1
- package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +5 -2
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +21 -12
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +7 -3
- package/dist/components/inputs/DateTime/shared/datePicker.types.d.ts +3 -0
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.d.ts +7 -0
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.js +13 -0
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.d.ts +6 -0
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.js +20 -0
- package/dist/components/inputs/FormField/FormField.d.ts +3 -3
- package/dist/components/inputs/FormField/FormFieldHeader.js +3 -1
- package/dist/components/inputs/FormField/formFieldHeader.cva.d.ts +6 -0
- package/dist/components/inputs/FormField/formFieldHeader.cva.js +11 -0
- package/dist/components/inputs/Input/NumberInput/NumberInput.d.ts +5 -2
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +92 -8
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.d.ts +38 -0
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +318 -0
- package/dist/components/inputs/Input/TextInput/TextInput.d.ts +3 -1
- package/dist/components/inputs/Input/TextInput/TextInput.js +95 -8
- package/dist/components/inputs/Inputs/InputItem.d.ts +15 -18
- package/dist/components/inputs/Inputs/InputItem.js +2 -0
- package/dist/components/inputs/RadioGroup/RadioGroup.js +17 -9
- package/dist/components/inputs/RadioGroup/radio.cva.d.ts +3 -0
- package/dist/components/inputs/RadioGroup/radio.cva.js +2 -1
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +6 -2
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +87 -6
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +1 -1
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +15 -10
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +25 -19
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +1 -2
- package/dist/components/inputs/Selection/Select/QuerySelect.js +5 -3
- package/dist/components/inputs/Selection/Select/Select.d.ts +7 -3
- package/dist/components/inputs/Selection/Select/Select.js +86 -4
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +4 -1
- package/dist/components/inputs/Selection/shared/SelectBase.js +3 -2
- package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +8 -4
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +12 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.js +3 -3
- package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +5 -3
- package/dist/components/inputs/Selection/shared/select.context.d.ts +3 -2
- package/dist/components/inputs/Selection/shared/select.context.js +22 -4
- package/dist/components/inputs/Selection/shared/select.types.d.ts +3 -2
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.d.ts +3 -0
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.js +5 -0
- package/dist/components/inputs/Selection/shared/staticSelect.utils.d.ts +23 -0
- package/dist/components/inputs/Selection/shared/staticSelect.utils.js +35 -0
- package/dist/components/inputs/Toggle/Toggle.js +6 -1
- package/dist/components/inputs/Toggle/toggle.cva.d.ts +3 -0
- package/dist/components/inputs/Toggle/toggle.cva.js +2 -1
- package/dist/components/inputs/shared/CheckContent.d.ts +2 -1
- package/dist/components/inputs/shared/CheckContent.js +3 -4
- package/dist/components/inputs/shared/StaticInput.d.ts +37 -0
- package/dist/components/inputs/shared/StaticInput.js +91 -0
- package/dist/components/inputs/shared/TooltipWrapper.js +5 -1
- package/dist/components/inputs/shared/input.cva.d.ts +5 -0
- package/dist/components/inputs/shared/input.cva.js +10 -1
- package/dist/components/inputs/shared/tooltipWrapper.cva.d.ts +4 -0
- package/dist/components/inputs/shared/tooltipWrapper.cva.js +5 -0
- package/dist/config/uiConfig.context.d.ts +8 -2
- package/dist/config/uiConfig.context.js +11 -1
- package/dist/config/uiStyle.context.d.ts +19 -3
- package/dist/helpers/dynamicInputs.d.ts +5 -5
- package/dist/helpers/dynamicInputs.js +3 -0
- package/dist/hooks/useIntersectionObserver.d.ts +1 -1
- package/dist/hooks/useIntersectionObserver.js +29 -10
- package/dist/hooks/useQueryAutocomplete.d.ts +5 -16
- package/dist/hooks/useQueryAutocomplete.js +13 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -2
- package/dist/utils/date-time.utils.d.ts +23 -9
- package/dist/utils/date-time.utils.js +97 -1
- package/dist/utils/query.utils.d.ts +4 -0
- package/dist/utils/query.utils.js +8 -0
- package/package.json +1 -1
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { UIStyle } from "../../../../config/uiStyle.context.js";
|
|
2
|
+
import { Loader } from "../../../status/Loader/Loader.js";
|
|
2
3
|
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
3
4
|
import { inputBase } from "../../shared/input.cva.js";
|
|
4
5
|
import { FormField } from "../../FormField/FormField.js";
|
|
6
|
+
import { StaticInput } from "../../shared/StaticInput.js";
|
|
5
7
|
import { TooltipWrapper } from "../../shared/TooltipWrapper.js";
|
|
6
8
|
import { InputContent } from "../shared/InputContent.js";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
10
|
import { clsx } from "clsx";
|
|
9
|
-
import { useRef } from "react";
|
|
11
|
+
import { isValidElement, useEffect, useRef, useState } from "react";
|
|
10
12
|
import { Input } from "react-aria-components";
|
|
11
13
|
import { useFocusVisible, useTextField } from "react-aria";
|
|
12
14
|
import { mergeRefs } from "@react-aria/utils";
|
|
13
|
-
import { Controller } from "react-hook-form";
|
|
15
|
+
import { Controller, useWatch } from "react-hook-form";
|
|
14
16
|
//#region src/components/inputs/Input/TextInput/TextInput.tsx
|
|
15
17
|
var TextInputBase = (props) => {
|
|
16
18
|
const ui = UIConfig.useConfig();
|
|
17
19
|
const inputBaseCva = UIStyle.useCva("input.baseCva", inputBase);
|
|
18
20
|
const inputRef = useRef(null);
|
|
19
|
-
const { ref, inputClassName, label, tooltipText, helperText, isRequired, rightContent, isDisabled, isDirty, headerClassName, errorClassName, isHeaderHidden, error, className, unit, isLoading, action, leadingIcon, trailingIcon, value, onChange, onBlur, as = ui.input.as, hideLabel = ui.input.hideLabel, variant = ui.input.variant, size = ui.input.size, isClearable = ui.input.isClearable, ...rest } = props;
|
|
21
|
+
const { ref, inputClassName, label, tooltipText, helperText, isRequired, rightContent, isDisabled, isDirty, headerClassName, errorClassName, isHeaderHidden, error, className, unit, isLoading, action, leadingIcon, trailingIcon, value, onChange, onBlur, as = ui.input.as, hideLabel = ui.input.hideLabel, variant = ui.input.variant, size = ui.input.size, isClearable = ui.input.isClearable, autoFocusOnMount, ...rest } = props;
|
|
20
22
|
const textFieldRef = useRef(null);
|
|
21
23
|
const { isFocusVisible } = useFocusVisible();
|
|
22
24
|
const { labelProps, inputProps } = useTextField({
|
|
@@ -29,6 +31,10 @@ var TextInputBase = (props) => {
|
|
|
29
31
|
onChange,
|
|
30
32
|
onBlur
|
|
31
33
|
}, textFieldRef);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!autoFocusOnMount || isDisabled) return;
|
|
36
|
+
requestAnimationFrame(() => inputRef.current?.focus());
|
|
37
|
+
}, [autoFocusOnMount, isDisabled]);
|
|
32
38
|
const formFieldProps = {
|
|
33
39
|
error,
|
|
34
40
|
label,
|
|
@@ -84,6 +90,8 @@ var TextInputBase = (props) => {
|
|
|
84
90
|
...rest
|
|
85
91
|
}), inputClassName),
|
|
86
92
|
onClick: () => inputRef.current?.focus(),
|
|
93
|
+
"data-is-empty": value === "" || value === null || value === void 0 || void 0,
|
|
94
|
+
"data-is-required": isRequired || void 0,
|
|
87
95
|
children: /* @__PURE__ */ jsx(InputContent, {
|
|
88
96
|
...inputContentProps,
|
|
89
97
|
headerProps,
|
|
@@ -109,7 +117,81 @@ var TextInputBase = (props) => {
|
|
|
109
117
|
})
|
|
110
118
|
});
|
|
111
119
|
};
|
|
112
|
-
var
|
|
120
|
+
var renderIconVisual = (icon) => {
|
|
121
|
+
if (!icon) return null;
|
|
122
|
+
if (isValidElement(icon)) return icon;
|
|
123
|
+
return /* @__PURE__ */ jsx(icon, { className: "size-6 text-interactive-text-secondary-idle" });
|
|
124
|
+
};
|
|
125
|
+
var TextInput = ({ renderStaticInput, ...props }) => {
|
|
126
|
+
const ui = UIConfig.useConfig();
|
|
127
|
+
const [renderInput, setRenderInput] = useState(!(renderStaticInput ?? ui.renderStaticInput));
|
|
128
|
+
const [shouldFocus, setShouldFocus] = useState(false);
|
|
129
|
+
const inputRef = useRef(null);
|
|
130
|
+
const watchedValue = "formControl" in props && props.formControl ? useWatch({
|
|
131
|
+
control: props.formControl.control,
|
|
132
|
+
name: props.formControl.name
|
|
133
|
+
}) : props.value;
|
|
134
|
+
let isFormControlDisabled = false;
|
|
135
|
+
if ("formControl" in props && props.formControl) isFormControlDisabled = !!props.formControl.control._options?.disabled;
|
|
136
|
+
const staticValue = watchedValue ?? props.value ?? props.defaultValue ?? "";
|
|
137
|
+
const inputType = props.type;
|
|
138
|
+
if (!renderInput && inputType === "password" && `${staticValue}`.length > 0) setRenderInput(true);
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!renderInput || !shouldFocus) return;
|
|
141
|
+
requestAnimationFrame(() => inputRef.current?.focus());
|
|
142
|
+
setShouldFocus(false);
|
|
143
|
+
}, [renderInput, shouldFocus]);
|
|
144
|
+
if (!renderInput) {
|
|
145
|
+
const as = props.as ?? ui.input.as;
|
|
146
|
+
const size = props.size ?? ui.input.size;
|
|
147
|
+
const variant = props.variant ?? ui.input.variant;
|
|
148
|
+
const hideLabel = props.hideLabel ?? ui.input.hideLabel;
|
|
149
|
+
const isHeaderHidden = props.isHeaderHidden || as === "inline" || as === "filter" || as === "floating";
|
|
150
|
+
let isDisabled = !!props.isDisabled;
|
|
151
|
+
if (isFormControlDisabled) isDisabled = true;
|
|
152
|
+
const maskedPasswordValue = inputType === "password" && `${staticValue}`.length > 0 ? "•".repeat(`${staticValue}`.length) : staticValue;
|
|
153
|
+
const displayValue = maskedPasswordValue == null ? "" : `${maskedPasswordValue}`;
|
|
154
|
+
const hasValue = displayValue !== "";
|
|
155
|
+
const trailingContent = !!props.unit || !!props.isLoading || !!props.action && !props.isLoading || !!props.trailingIcon && !props.isLoading && !props.action ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
156
|
+
props.unit && /* @__PURE__ */ jsx("span", {
|
|
157
|
+
className: "text-label-2 text-text-default-3",
|
|
158
|
+
children: props.unit
|
|
159
|
+
}),
|
|
160
|
+
props.isLoading && /* @__PURE__ */ jsx(Loader, {}),
|
|
161
|
+
!props.isLoading && props.action && renderIconVisual(props.action.icon),
|
|
162
|
+
!props.isLoading && !props.action && props.trailingIcon && renderIconVisual(props.trailingIcon)
|
|
163
|
+
] }) : void 0;
|
|
164
|
+
return /* @__PURE__ */ jsx(StaticInput, {
|
|
165
|
+
...props,
|
|
166
|
+
onInteract: (focus) => {
|
|
167
|
+
setShouldFocus(focus);
|
|
168
|
+
setRenderInput(true);
|
|
169
|
+
},
|
|
170
|
+
as,
|
|
171
|
+
size,
|
|
172
|
+
variant,
|
|
173
|
+
hideLabel,
|
|
174
|
+
isHeaderHidden,
|
|
175
|
+
isDisabled,
|
|
176
|
+
className: clsx("group w-full", as === "inline" && "h-full", props.className),
|
|
177
|
+
inputClassName: props.inputClassName,
|
|
178
|
+
placeholder: props.placeholder,
|
|
179
|
+
displayValue,
|
|
180
|
+
isEmpty: !hasValue,
|
|
181
|
+
dataAttributes: {
|
|
182
|
+
dataIsEmpty: !hasValue,
|
|
183
|
+
dataIsFilled: hasValue,
|
|
184
|
+
dataIsDirty: props.isDirty,
|
|
185
|
+
dataIsRequired: props.isRequired,
|
|
186
|
+
dataIsDisabled: isDisabled,
|
|
187
|
+
dataDisabled: isDisabled,
|
|
188
|
+
dataInvalid: !!props.error,
|
|
189
|
+
dataHasSelection: hasValue
|
|
190
|
+
},
|
|
191
|
+
leadingVisual: renderIconVisual(props.leadingIcon),
|
|
192
|
+
trailingContent
|
|
193
|
+
});
|
|
194
|
+
}
|
|
113
195
|
if ("formControl" in props && props.formControl) {
|
|
114
196
|
const { formControl, ref, ...innerProps } = props;
|
|
115
197
|
return /* @__PURE__ */ jsx(Controller, {
|
|
@@ -117,17 +199,22 @@ var TextInput = (props) => {
|
|
|
117
199
|
name: formControl.name,
|
|
118
200
|
render: ({ field, fieldState: { error, isDirty } }) => /* @__PURE__ */ jsx(TextInputBase, {
|
|
119
201
|
...innerProps,
|
|
120
|
-
ref: mergeRefs(ref, field.ref),
|
|
202
|
+
ref: mergeRefs(ref, field.ref, inputRef),
|
|
121
203
|
value: field.value,
|
|
122
204
|
onChange: field.onChange,
|
|
123
205
|
onBlur: field.onBlur,
|
|
124
206
|
isDirty,
|
|
125
207
|
isDisabled: field.disabled || props.isDisabled,
|
|
126
|
-
error: props.error ?? error?.message
|
|
208
|
+
error: props.error ?? error?.message,
|
|
209
|
+
autoFocusOnMount: shouldFocus
|
|
127
210
|
})
|
|
128
211
|
});
|
|
129
212
|
}
|
|
130
|
-
return /* @__PURE__ */ jsx(TextInputBase, {
|
|
213
|
+
return /* @__PURE__ */ jsx(TextInputBase, {
|
|
214
|
+
...props,
|
|
215
|
+
ref: mergeRefs(props.ref, inputRef),
|
|
216
|
+
autoFocusOnMount: shouldFocus
|
|
217
|
+
});
|
|
131
218
|
};
|
|
132
219
|
//#endregion
|
|
133
220
|
export { TextInput };
|
|
@@ -1,30 +1,27 @@
|
|
|
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';
|
|
4
6
|
import { HasRequiredProperty } from '../../../types/common';
|
|
5
7
|
declare const componentRegistry: {
|
|
6
8
|
readonly toggle: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Toggle/Toggle').ControlledToggleProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
readonly checkbox: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Checkbox/Checkbox').ControlledCheckboxProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
readonly numberInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/NumberInput/NumberInput').ControlledNumberInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
readonly numberInput: <TFieldValues extends import('react-hook-form').FieldValues>({ renderStaticInput, ...props }: import('../Input/NumberInput/NumberInput').ControlledNumberInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
readonly numberRangeInput: <TFieldValues extends import('react-hook-form').FieldValues>({ renderStaticInput, ...props }: import('../Input/NumberRangeInput/NumberRangeInput').ControlledNumberRangeInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
9
12
|
readonly slider: <TFieldValues extends import('react-hook-form').FieldValues, IsRange extends boolean = false>(props: import('../Slider/Slider').ControlledSliderProps<TFieldValues, IsRange>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
readonly textInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/TextInput/TextInput').ControlledTextInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
readonly textInput: <TFieldValues extends import('react-hook-form').FieldValues>({ renderStaticInput, ...props }: import('../Input/TextInput/TextInput').ControlledTextInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
11
14
|
readonly passwordInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/PasswordInput/PasswordInput').ControlledPasswordInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
12
15
|
readonly textArea: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/TextArea/TextArea').ControlledTextAreaProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
readonly select:
|
|
14
|
-
readonly querySelect: <TFieldValues extends import('react-hook-form').FieldValues, TQueryFn extends import('../Selection/shared/querySelect.utils').QueryFn, TKey extends import('react-aria').Key = import('react-aria').Key>({ query, queryParams, queryOptions, queryMap, ...props }: import('
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
queryOptions?: Parameters<TQueryFn>[1] | undefined;
|
|
18
|
-
queryMap?: ((data: Exclude<ReturnType<TQueryFn>["data"], undefined>) => import('../Selection/shared/select.types').SelectItem<TKey>[]) | undefined;
|
|
19
|
-
isInitialQueryDisabled?: boolean;
|
|
20
|
-
})) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
-
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;
|
|
22
|
-
readonly queryAutocomplete: <TFieldValues extends import('react-hook-form').FieldValues, TSelectItem extends import('../Selection/shared/select.types').SelectItem<any>, TQueryFn extends import('../Selection/Autocomplete/queryAutocomplete.types').QueryFn<TSelectItem>>({ query, queryParams, queryOptions, queryMap, ...props }: import('../Selection/Autocomplete/queryAutocomplete.types').QueryAutocompleteProps<TFieldValues, TSelectItem, TQueryFn>) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
readonly select: typeof Select;
|
|
17
|
+
readonly querySelect: <TFieldValues extends import('react-hook-form').FieldValues, TQueryFn extends import('../Selection/shared/querySelect.utils').QueryFn, TKey extends import('react-aria').Key = import('react-aria').Key>({ query, queryParams, queryOptions, queryMap, ...props }: import('../Selection/Select/QuerySelect.js').QuerySelectProps<TFieldValues, TQueryFn, TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
readonly autocomplete: typeof Autocomplete;
|
|
19
|
+
readonly queryAutocomplete: <TFieldValues extends import('react-hook-form').FieldValues, TSelectItem extends import('../../..').SelectItem<any>, TQueryFn extends import('../Selection/Autocomplete/queryAutocomplete.types').QueryFn>({ query, queryParams, queryOptions, queryMap, leadingContent, ...props }: import('../Selection/Autocomplete/queryAutocomplete.types').QueryAutocompleteProps<TFieldValues, TSelectItem, TQueryFn>) => import("react/jsx-runtime").JSX.Element;
|
|
23
20
|
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;
|
|
24
|
-
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;
|
|
25
|
-
readonly dateTimePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, ...props }: import('../DateTime/DateTimePicker/DateTimePicker').ControlledDateTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
readonly timePicker: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../DateTime/TimePicker/TimePicker').ControlledTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
-
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;
|
|
21
|
+
readonly datePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, minValue, maxValue, renderStaticInput, ...props }: import('../DateTime/DatePicker/DatePicker').ControlledDatePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
readonly dateTimePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, renderStaticInput, ...props }: import('../DateTime/DateTimePicker/DateTimePicker').ControlledDateTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
readonly timePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ renderStaticInput, ...props }: import('../DateTime/TimePicker/TimePicker').ControlledTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
readonly dateRangePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, minValue, maxValue, renderStaticInput, ...props }: import('../DateTime/DateRangePicker/DateRangePicker').ControlledDateRangePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
28
25
|
readonly textEditor: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../../../text-editor.js').ControlledTextEditorProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
29
26
|
readonly unknown: null;
|
|
30
27
|
};
|
|
@@ -54,8 +51,8 @@ type TypeBasedInputDef<TSchemaType extends Record<string, any>, T extends InputC
|
|
|
54
51
|
interface RenderBasedInputDef<TSchemaType extends Record<string, any>, K extends keyof TSchemaType> {
|
|
55
52
|
type?: never;
|
|
56
53
|
name: K;
|
|
57
|
-
label?:
|
|
58
|
-
placeholder?:
|
|
54
|
+
label?: string;
|
|
55
|
+
placeholder?: string;
|
|
59
56
|
props?: never;
|
|
60
57
|
inputWrapper?: never;
|
|
61
58
|
render: (formControl: {
|
|
@@ -6,6 +6,7 @@ import { DateRangePicker } from "../DateTime/DateRangePicker/DateRangePicker.js"
|
|
|
6
6
|
import { DateTimePicker } from "../DateTime/DateTimePicker/DateTimePicker.js";
|
|
7
7
|
import { TimePicker } from "../DateTime/TimePicker/TimePicker.js";
|
|
8
8
|
import { NumberInput } from "../Input/NumberInput/NumberInput.js";
|
|
9
|
+
import { NumberRangeInput } from "../Input/NumberRangeInput/NumberRangeInput.js";
|
|
9
10
|
import { PasswordInput } from "../Input/PasswordInput/PasswordInput.js";
|
|
10
11
|
import { TextArea } from "../Input/TextArea/TextArea.js";
|
|
11
12
|
import { Autocomplete } from "../Selection/Autocomplete/Autocomplete.js";
|
|
@@ -21,6 +22,7 @@ var componentRegistry = {
|
|
|
21
22
|
toggle: Toggle,
|
|
22
23
|
checkbox: Checkbox,
|
|
23
24
|
numberInput: NumberInput,
|
|
25
|
+
numberRangeInput: NumberRangeInput,
|
|
24
26
|
slider: Slider,
|
|
25
27
|
textInput: TextInput,
|
|
26
28
|
passwordInput: PasswordInput,
|
|
@@ -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, radioIndicatorClass, radioTypography } from "./radio.cva.js";
|
|
5
|
+
import { radio, radioContentClassName, 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,20 @@ 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);
|
|
16
17
|
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
|
+
const radioClassName = radioCva({
|
|
19
|
+
variant,
|
|
20
|
+
...rest
|
|
21
|
+
});
|
|
22
|
+
const radioTypographyProps = radioTypographyMap({
|
|
23
|
+
variant,
|
|
24
|
+
...rest
|
|
25
|
+
});
|
|
26
|
+
const radioContentClassNameValue = radioContentClassNameMap({
|
|
27
|
+
variant,
|
|
28
|
+
...rest
|
|
29
|
+
});
|
|
17
30
|
const formFieldProps = {
|
|
18
31
|
className,
|
|
19
32
|
error,
|
|
@@ -41,14 +54,9 @@ var RadioGroupBase = (props) => {
|
|
|
41
54
|
children: options.map((option) => /* @__PURE__ */ jsxs(Radio, {
|
|
42
55
|
value: option.value,
|
|
43
56
|
className: clsx("relative", radioIndicatorClass),
|
|
44
|
-
children: [/* @__PURE__ */ jsx("div", { className:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}) }), /* @__PURE__ */ jsx(CheckContent, {
|
|
48
|
-
typography: radioTypographyMap({
|
|
49
|
-
variant,
|
|
50
|
-
...rest
|
|
51
|
-
}),
|
|
57
|
+
children: [/* @__PURE__ */ jsx("div", { className: radioClassName }), /* @__PURE__ */ jsx(CheckContent, {
|
|
58
|
+
typography: radioTypographyProps,
|
|
59
|
+
contentClassName: radioContentClassNameValue,
|
|
52
60
|
className: labelClassName,
|
|
53
61
|
children: option.label
|
|
54
62
|
})]
|
|
@@ -9,3 +9,6 @@ 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,5 +31,6 @@ var radioTypography = compoundMapper({ default: {
|
|
|
31
31
|
sizeMobile: "label-1",
|
|
32
32
|
variant: "default"
|
|
33
33
|
} });
|
|
34
|
+
var radioContentClassName = compoundMapper({ default: "text-text-default-2" });
|
|
34
35
|
//#endregion
|
|
35
|
-
export { radio, radioIndicatorClass, radioTypography };
|
|
36
|
+
export { radio, radioContentClassName, radioIndicatorClass, radioTypography };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import { Key } from 'react-aria-components';
|
|
2
3
|
import { FieldValues } from 'react-hook-form';
|
|
3
4
|
import { SelectBaseProps } from '../shared/SelectBase';
|
|
4
5
|
import { DefaultInitialSelectItem, GroupedSelectControlProps, GroupedSelectProps } from '../shared/select.types';
|
|
5
6
|
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
6
|
-
export type AutocompleteProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = OmitDiscriminatedUnion<SelectBaseProps<TKey, TInitialSelectItem>, "isSearchable"
|
|
7
|
+
export type AutocompleteProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = OmitDiscriminatedUnion<SelectBaseProps<TKey, TInitialSelectItem>, "isSearchable"> & {
|
|
8
|
+
renderStaticInput?: boolean;
|
|
9
|
+
};
|
|
7
10
|
export type ControlledAutocompleteProps<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = Omit<AutocompleteProps<TKey, TInitialSelectItem>, keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey, TInitialSelectItem>;
|
|
8
|
-
export declare
|
|
11
|
+
export declare function Autocomplete<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: AutocompleteProps<TKey, TInitialSelectItem>): ReactElement;
|
|
12
|
+
export declare function Autocomplete<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: ControlledAutocompleteProps<TFieldValues, TKey, TInitialSelectItem>): ReactElement;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { ArrowDropDownIcon } from "../../../../assets/icons/ArrowDropDown.js";
|
|
2
|
+
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
3
|
+
import { StaticInput } from "../../shared/StaticInput.js";
|
|
1
4
|
import { SelectBase } from "../shared/SelectBase.js";
|
|
2
|
-
import {
|
|
5
|
+
import { getStaticSelectValue } from "../shared/staticSelect.utils.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { clsx } from "clsx";
|
|
8
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
9
|
import { mergeRefs } from "@react-aria/utils";
|
|
4
|
-
import { Controller } from "react-hook-form";
|
|
10
|
+
import { Controller, useWatch } from "react-hook-form";
|
|
5
11
|
//#region src/components/inputs/Selection/Autocomplete/Autocomplete.tsx
|
|
6
|
-
|
|
12
|
+
function _Autocomplete(props) {
|
|
7
13
|
if ("formControl" in props && props.formControl) {
|
|
8
|
-
const { formControl, ref, ...innerProps } = props;
|
|
14
|
+
const { ignoreInputValueFiltering = true, formControl, ref, ...innerProps } = props;
|
|
9
15
|
return /* @__PURE__ */ jsx(Controller, {
|
|
10
16
|
control: formControl.control,
|
|
11
17
|
name: formControl.name,
|
|
@@ -18,7 +24,8 @@ var Autocomplete = (props) => {
|
|
|
18
24
|
isDirty,
|
|
19
25
|
isDisabled: field.disabled || props.isDisabled,
|
|
20
26
|
error: props.error ?? error?.message,
|
|
21
|
-
isSearchable: true
|
|
27
|
+
isSearchable: true,
|
|
28
|
+
ignoreInputValueFiltering
|
|
22
29
|
})
|
|
23
30
|
});
|
|
24
31
|
}
|
|
@@ -26,6 +33,80 @@ var Autocomplete = (props) => {
|
|
|
26
33
|
...props,
|
|
27
34
|
isSearchable: true
|
|
28
35
|
});
|
|
29
|
-
}
|
|
36
|
+
}
|
|
37
|
+
function Autocomplete({ renderStaticInput, ...props }) {
|
|
38
|
+
const ui = UIConfig.useConfig();
|
|
39
|
+
const [renderInput, setRenderInput] = useState(!(renderStaticInput ?? ui.renderStaticInput));
|
|
40
|
+
const [shouldFocus, setShouldFocus] = useState(false);
|
|
41
|
+
const rootRef = useRef(null);
|
|
42
|
+
const currentValue = ("formControl" in props && props.formControl ? useWatch({
|
|
43
|
+
control: props.formControl.control,
|
|
44
|
+
name: props.formControl.name
|
|
45
|
+
}) : props.value) ?? props.value;
|
|
46
|
+
let isFormControlDisabled = false;
|
|
47
|
+
if ("formControl" in props && props.formControl) isFormControlDisabled = !!props.formControl.control._options?.disabled;
|
|
48
|
+
if (!renderInput && !!props.customTrigger) setRenderInput(true);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!renderInput || !shouldFocus) return;
|
|
51
|
+
requestAnimationFrame(() => {
|
|
52
|
+
(rootRef.current?.querySelector("input, [data-type='select-trigger'], button, [tabindex]"))?.focus();
|
|
53
|
+
});
|
|
54
|
+
setShouldFocus(false);
|
|
55
|
+
}, [renderInput, shouldFocus]);
|
|
56
|
+
if (!renderInput) {
|
|
57
|
+
const as = props.as ?? ui.input.as;
|
|
58
|
+
let isDisabled = !!props.isDisabled;
|
|
59
|
+
if (isFormControlDisabled) isDisabled = true;
|
|
60
|
+
const mode = props.selectionMode ?? ui.select.selectionMode;
|
|
61
|
+
const { displayValue, isEmpty } = getStaticSelectValue({
|
|
62
|
+
items: props.items,
|
|
63
|
+
value: currentValue,
|
|
64
|
+
selectionMode: mode,
|
|
65
|
+
initialSelection: props.initialSelection,
|
|
66
|
+
mapInitialToSelectItem: props.mapInitialToSelectItem,
|
|
67
|
+
showSelectionContent: props.showSelectionContent,
|
|
68
|
+
isDisabled,
|
|
69
|
+
collapseAfter: props.collapseAfter ?? ui.select.collapseAfter,
|
|
70
|
+
selectedTagsType: props.selectedTagsType ?? ui.select.selectedTagsType
|
|
71
|
+
});
|
|
72
|
+
const trailingContent = props.trailingContent || !props.hideDropdownIcon ? /* @__PURE__ */ jsxs(Fragment, { children: [props.trailingContent, !props.hideDropdownIcon ? /* @__PURE__ */ jsx(ArrowDropDownIcon, { className: "size-6 shrink-0 text-interactive-text-secondary-idle" }) : void 0] }) : void 0;
|
|
73
|
+
return /* @__PURE__ */ jsx(StaticInput, {
|
|
74
|
+
...props,
|
|
75
|
+
onInteract: (focus) => {
|
|
76
|
+
setShouldFocus(focus);
|
|
77
|
+
setRenderInput(true);
|
|
78
|
+
},
|
|
79
|
+
as,
|
|
80
|
+
size: props.size ?? ui.input.size,
|
|
81
|
+
variant: props.variant ?? ui.input.variant,
|
|
82
|
+
isHeaderHidden: props.isHeaderHidden || as === "inline" || as === "filter" || as === "floating",
|
|
83
|
+
hideLabel: props.hideLabel ?? ui.input.hideLabel,
|
|
84
|
+
isDisabled,
|
|
85
|
+
className: clsx("w-full", props.containerClassName),
|
|
86
|
+
inputClassName: clsx(props.className, props.inputClassName),
|
|
87
|
+
placeholder: props.placeholder,
|
|
88
|
+
showPlacholderIfFilled: mode !== "single",
|
|
89
|
+
displayValue,
|
|
90
|
+
isEmpty,
|
|
91
|
+
dataAttributes: {
|
|
92
|
+
dataIsEmpty: isEmpty,
|
|
93
|
+
dataIsFilled: !isEmpty,
|
|
94
|
+
dataIsDirty: props.isDirty,
|
|
95
|
+
dataIsRequired: props.isRequired,
|
|
96
|
+
dataIsDisabled: isDisabled,
|
|
97
|
+
dataDisabled: isDisabled,
|
|
98
|
+
dataInvalid: !!props.error,
|
|
99
|
+
dataHasSelection: !isEmpty,
|
|
100
|
+
dataHasSearch: false
|
|
101
|
+
},
|
|
102
|
+
leadingContent: props.leadingContent,
|
|
103
|
+
trailingContent
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return /* @__PURE__ */ jsx(_Autocomplete, {
|
|
107
|
+
...props,
|
|
108
|
+
ref: mergeRefs(props.ref, rootRef)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
30
111
|
//#endregion
|
|
31
112
|
export { Autocomplete };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FieldValues } from 'react-hook-form';
|
|
2
2
|
import { QueryAutocompleteProps, QueryFn } from './queryAutocomplete.types';
|
|
3
3
|
import { SelectItem } from '../shared/select.types';
|
|
4
|
-
export declare const QueryAutocomplete: <TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn
|
|
4
|
+
export declare const QueryAutocomplete: <TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn>({ query, queryParams, queryOptions, queryMap, leadingContent, ...props }: QueryAutocompleteProps<TFieldValues, TSelectItem, TQueryFn>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
2
2
|
import { Autocomplete } from "./Autocomplete.js";
|
|
3
|
+
import { getQueryItems } from "../shared/querySelect.utils.js";
|
|
3
4
|
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { useState } from "react";
|
|
6
7
|
//#region src/components/inputs/Selection/Autocomplete/QueryAutocomplete.tsx
|
|
7
|
-
var QueryAutocomplete = ({ query, queryParams, queryOptions, queryMap, ...props }) => {
|
|
8
|
+
var QueryAutocomplete = ({ query, queryParams, queryOptions, queryMap, leadingContent, ...props }) => {
|
|
8
9
|
const ui = UIConfig.useConfig();
|
|
9
10
|
const [search, setSearch] = useState("");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return queryMap?.(extractedData) ?? extractedData;
|
|
13
|
-
};
|
|
14
|
-
const { items, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
11
|
+
const { onChange, ...restProps } = props;
|
|
12
|
+
const { items, totalItems, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
15
13
|
query,
|
|
16
14
|
queryParams,
|
|
17
15
|
queryOptions,
|
|
18
|
-
mapItems: (data) =>
|
|
16
|
+
mapItems: (data) => getQueryItems(data, queryMap),
|
|
19
17
|
search,
|
|
20
18
|
initialQueryState: props.isInitialQueryDisabled ?? ui.queryAutocomplete?.isInitialQueryDisabled
|
|
21
19
|
});
|
|
22
|
-
const
|
|
20
|
+
const handleChange = (value) => {
|
|
21
|
+
onChange?.(value);
|
|
22
|
+
props.onBlur?.({ target: { value: null } });
|
|
23
|
+
};
|
|
24
|
+
const { isInitialQueryDisabled: _, ...autocompleteProps } = restProps;
|
|
23
25
|
return /* @__PURE__ */ jsx(Autocomplete, {
|
|
24
|
-
...
|
|
26
|
+
...autocompleteProps,
|
|
25
27
|
items,
|
|
28
|
+
totalItems,
|
|
26
29
|
onSearchChange: setSearch,
|
|
27
30
|
isClientSearchDisabled: true,
|
|
28
31
|
isLoading,
|
|
32
|
+
onChange: handleChange,
|
|
29
33
|
onMouseEnter: handleEnableQuery,
|
|
30
34
|
onFocusCapture: handleEnableQuery,
|
|
35
|
+
leadingContent,
|
|
31
36
|
hasLoadMore: hasNextPage,
|
|
32
|
-
onLoadMore: fetchNextPage
|
|
37
|
+
onLoadMore: fetchNextPage
|
|
33
38
|
});
|
|
34
39
|
};
|
|
35
40
|
//#endregion
|
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
1
|
+
import { InfiniteData, UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { Key } from 'react-aria-components';
|
|
3
3
|
import { FieldValues } from 'react-hook-form';
|
|
4
4
|
import { AutocompleteProps } from './Autocomplete';
|
|
5
5
|
import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
|
|
6
6
|
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
7
|
-
export
|
|
8
|
-
items
|
|
7
|
+
export type InfiniteQueryPage<TKey extends Key> = {
|
|
8
|
+
items?: SelectItem<TKey>[];
|
|
9
9
|
totalItems?: number;
|
|
10
|
-
}
|
|
11
|
-
export type QueryResult<
|
|
12
|
-
export type QueryFn
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
};
|
|
11
|
+
export type QueryResult<TData> = UseQueryResult<TData> | UseInfiniteQueryResult<TData>;
|
|
12
|
+
export type QueryFn = (params: any, options?: any) => QueryResult<any>;
|
|
13
|
+
export type ExtractQueryParams<TQueryFn> = TQueryFn extends (params: infer TParams, ...args: any[]) => any ? TParams : never;
|
|
14
|
+
export type ExtractQueryOptions<TQueryFn> = TQueryFn extends (params: any, options?: infer TOptions) => any ? TOptions : never;
|
|
15
|
+
export type QueryDataType<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>;
|
|
16
|
+
export type ExtractPageType<T> = T extends InfiniteData<infer TPage> ? TPage : T;
|
|
17
|
+
export type ExtractedDataType<TQueryFn extends QueryFn> = ExtractPageType<QueryDataType<TQueryFn>> | ExtractPageType<QueryDataType<TQueryFn>>[];
|
|
18
|
+
export type QueryAutocompleteProps<TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn> = OmitDiscriminatedUnion<AutocompleteProps<TSelectItem["id"]>, "items" | "onSearchChange" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TSelectItem["id"]> & {
|
|
19
|
+
query: TQueryFn;
|
|
20
|
+
queryParams?: Omit<ExtractQueryParams<TQueryFn>, "search" | "limit"> & {
|
|
21
|
+
limit?: number;
|
|
22
|
+
};
|
|
23
|
+
queryOptions?: ExtractQueryOptions<TQueryFn>;
|
|
24
|
+
queryMap?: (data: ExtractedDataType<TQueryFn>) => SelectItem<TSelectItem["id"]>[];
|
|
21
25
|
isInitialQueryDisabled?: boolean;
|
|
22
26
|
};
|
|
23
|
-
export interface UseQueryAutocompleteOptions<
|
|
27
|
+
export interface UseQueryAutocompleteOptions<TQueryFn extends QueryFn, TKey extends Key = Key> {
|
|
24
28
|
query: TQueryFn;
|
|
25
|
-
queryParams?:
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
queryParams?: Omit<ExtractQueryParams<TQueryFn>, "search" | "limit"> & {
|
|
30
|
+
limit?: number;
|
|
31
|
+
};
|
|
32
|
+
queryOptions?: ExtractQueryOptions<TQueryFn>;
|
|
33
|
+
mapItems: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[];
|
|
28
34
|
initialQueryState?: boolean;
|
|
29
|
-
search
|
|
35
|
+
search?: string;
|
|
30
36
|
}
|
|
@@ -4,7 +4,7 @@ import { QueryDataType, QueryFn } from '../shared/querySelect.utils';
|
|
|
4
4
|
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
5
5
|
import { Key } from 'react-aria-components';
|
|
6
6
|
import { FieldValues } from 'react-hook-form';
|
|
7
|
-
type QuerySelectProps<TFieldValues extends FieldValues, TQueryFn extends QueryFn, TKey extends Key = Key> = OmitDiscriminatedUnion<SelectBaseProps<TKey>, "items" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey> & {
|
|
7
|
+
export type QuerySelectProps<TFieldValues extends FieldValues, TQueryFn extends QueryFn, TKey extends Key = Key> = OmitDiscriminatedUnion<SelectBaseProps<TKey>, "items" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey> & {
|
|
8
8
|
query: TQueryFn;
|
|
9
9
|
queryParams?: Parameters<TQueryFn>[0];
|
|
10
10
|
queryOptions?: Parameters<TQueryFn>[1];
|
|
@@ -12,4 +12,3 @@ type QuerySelectProps<TFieldValues extends FieldValues, TQueryFn extends QueryFn
|
|
|
12
12
|
isInitialQueryDisabled?: boolean;
|
|
13
13
|
};
|
|
14
14
|
export declare const QuerySelect: <TFieldValues extends FieldValues, TQueryFn extends QueryFn, TKey extends Key = Key>({ query, queryParams, queryOptions, queryMap, ...props }: QuerySelectProps<TFieldValues, TQueryFn, TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
2
2
|
import { SelectBase } from "../shared/SelectBase.js";
|
|
3
|
-
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
4
3
|
import { getQueryItems } from "../shared/querySelect.utils.js";
|
|
4
|
+
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { mergeRefs } from "@react-aria/utils";
|
|
7
7
|
import { Controller } from "react-hook-form";
|
|
8
8
|
//#region src/components/inputs/Selection/Select/QuerySelect.tsx
|
|
9
9
|
var QuerySelect = ({ query, queryParams, queryOptions, queryMap, ...props }) => {
|
|
10
10
|
const ui = UIConfig.useConfig();
|
|
11
|
-
const { items, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
11
|
+
const { items, totalItems, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
12
12
|
query,
|
|
13
13
|
queryParams,
|
|
14
14
|
queryOptions,
|
|
@@ -25,8 +25,9 @@ var QuerySelect = ({ query, queryParams, queryOptions, queryMap, ...props }) =>
|
|
|
25
25
|
ref: mergeRefs(ref, field.ref),
|
|
26
26
|
items,
|
|
27
27
|
isLoading,
|
|
28
|
+
totalItems,
|
|
28
29
|
hasLoadMore: hasNextPage,
|
|
29
|
-
onLoadMore: fetchNextPage
|
|
30
|
+
onLoadMore: fetchNextPage,
|
|
30
31
|
value: field.value,
|
|
31
32
|
onChange: (value) => {
|
|
32
33
|
field.onChange(value);
|
|
@@ -46,6 +47,7 @@ var QuerySelect = ({ query, queryParams, queryOptions, queryMap, ...props }) =>
|
|
|
46
47
|
...restProps,
|
|
47
48
|
items,
|
|
48
49
|
isLoading,
|
|
50
|
+
totalItems,
|
|
49
51
|
hasLoadMore: hasNextPage,
|
|
50
52
|
onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0,
|
|
51
53
|
onMouseEnter: handleEnableQuery,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import { Key } from 'react-aria-components';
|
|
2
3
|
import { FieldValues } from 'react-hook-form';
|
|
3
4
|
import { SelectBaseProps } from '../shared/SelectBase';
|
|
4
5
|
import { DefaultInitialSelectItem, GroupedSelectControlProps, GroupedSelectProps, SelectAsyncProps } from '../shared/select.types';
|
|
5
6
|
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
6
|
-
export type SelectProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = OmitDiscriminatedUnion<SelectBaseProps<TKey, TInitialSelectItem>,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export type SelectProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = OmitDiscriminatedUnion<SelectBaseProps<TKey, TInitialSelectItem>, keyof SelectAsyncProps> & {
|
|
8
|
+
renderStaticInput?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ControlledSelectProps<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = Omit<SelectProps<TKey, TInitialSelectItem>, keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey, TInitialSelectItem>;
|
|
11
|
+
export declare function Select<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: SelectProps<TKey, TInitialSelectItem>): ReactElement;
|
|
12
|
+
export declare function Select<TFieldValues extends FieldValues, TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(props: ControlledSelectProps<TFieldValues, TKey, TInitialSelectItem>): ReactElement;
|