@povio/ui 2.2.8 → 2.2.9-rc.2
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/inputs/DateTime/TimePicker/TimePicker.js +3 -1
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +1 -0
- package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +3 -1
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +1 -0
- package/dist/components/inputs/Input/TextInput/TextInput.js +3 -0
- package/dist/components/inputs/Inputs/InputItem.d.ts +8 -10
- package/dist/components/inputs/Inputs/InputItem.js +4 -0
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +2 -1
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +3 -18
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +23 -7
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +30 -0
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +15 -0
- package/dist/components/inputs/Selection/Select/QuerySelect.js +56 -0
- package/dist/components/inputs/Selection/Select/Select.js +2 -1
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +5 -1
- package/dist/components/inputs/Selection/shared/SelectBase.js +2 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +6 -2
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +15 -3
- package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +7 -3
- package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +6 -0
- package/dist/components/inputs/Selection/shared/querySelect.utils.js +13 -0
- package/dist/components/inputs/TextEditor/TextEditor.d.ts +1 -0
- package/dist/components/inputs/TextEditor/TextEditor.js +7 -3
- package/dist/config/uiConfig.context.d.ts +7 -1
- package/dist/config/uiConfig.context.js +4 -1
- package/dist/hooks/useQueryAutocomplete.d.ts +25 -0
- package/dist/hooks/useQueryAutocomplete.js +41 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -101,6 +101,7 @@ var TimePickerBase = (props) => {
|
|
|
101
101
|
onPress: onOpen,
|
|
102
102
|
isDisabled,
|
|
103
103
|
isDirty,
|
|
104
|
+
isRequired,
|
|
104
105
|
isInvalid: !!error,
|
|
105
106
|
disableDropdown,
|
|
106
107
|
variant,
|
|
@@ -141,12 +142,13 @@ var TimePicker = (props) => {
|
|
|
141
142
|
return /* @__PURE__ */ jsx(Controller, {
|
|
142
143
|
control: formControl.control,
|
|
143
144
|
name: formControl.name,
|
|
144
|
-
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx(TimePickerBase, {
|
|
145
|
+
render: ({ field, fieldState: { error, isDirty } }) => /* @__PURE__ */ jsx(TimePickerBase, {
|
|
145
146
|
...innerProps,
|
|
146
147
|
ref: mergeRefs(ref, field.ref),
|
|
147
148
|
value: parseTimeValue(field.value),
|
|
148
149
|
onChange: (value) => field.onChange(formatTimeValue(value)),
|
|
149
150
|
onBlur: field.onBlur,
|
|
151
|
+
isDirty,
|
|
150
152
|
isDisabled: field.disabled || props.isDisabled,
|
|
151
153
|
error: props.error ?? error?.message
|
|
152
154
|
})
|
|
@@ -82,6 +82,7 @@ var DatePickerInput = ({ ref, as, groupProps, fieldProps, endFieldProps, buttonP
|
|
|
82
82
|
"data-has-selection": fieldProps.value !== null || void 0,
|
|
83
83
|
"data-is-dirty": isDirty || void 0,
|
|
84
84
|
"data-is-required": isRequired || void 0,
|
|
85
|
+
"data-is-filled": fieldProps.value !== null || void 0,
|
|
85
86
|
...groupProps,
|
|
86
87
|
...focusWithinProps,
|
|
87
88
|
...hoverProps,
|
|
@@ -9,6 +9,7 @@ interface DatePickerInputProps extends InputVariantProps {
|
|
|
9
9
|
state: TimeFieldState;
|
|
10
10
|
isDisabled?: boolean;
|
|
11
11
|
isDirty?: boolean;
|
|
12
|
+
isRequired?: boolean;
|
|
12
13
|
isInvalid?: boolean;
|
|
13
14
|
disableDropdown?: boolean;
|
|
14
15
|
headerProps?: FormFieldHeaderProps;
|
|
@@ -18,5 +19,5 @@ interface DatePickerInputProps extends InputVariantProps {
|
|
|
18
19
|
className?: string;
|
|
19
20
|
onPress: () => void;
|
|
20
21
|
}
|
|
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;
|
|
22
|
+
export declare const TimePickerInput: ({ ref, as, fieldProps, state, isDisabled, isDirty, isRequired, isInvalid, disableDropdown, variant, size, isClearable, headerProps, disableManualEntry, placeholder, className, onPress, ...props }: DatePickerInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
23
|
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, isInvalid, disableDropdown, variant, size, isClearable, headerProps, disableManualEntry, placeholder, className, onPress, ...props }) => {
|
|
15
|
+
var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty, isRequired, 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,6 +38,8 @@ var TimePickerInput = ({ ref, as, fieldProps, state, isDisabled, isDirty, isInva
|
|
|
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,
|
|
41
43
|
...fieldProps,
|
|
42
44
|
...focusWithinProps,
|
|
43
45
|
...hoverProps,
|
|
@@ -101,6 +101,7 @@ 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,
|
|
104
105
|
placeholder: as === "floating" ? "\xA0" : inputProps.placeholder,
|
|
105
106
|
className: "w-full outline-none",
|
|
106
107
|
onFocus: (e) => {
|
|
@@ -75,6 +75,8 @@ 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,
|
|
78
80
|
children: /* @__PURE__ */ jsx("div", {
|
|
79
81
|
className: clsx("relative flex cursor-text has-disabled:cursor-default", inputBaseCva({
|
|
80
82
|
variant,
|
|
@@ -91,6 +93,7 @@ var TextInputBase = (props) => {
|
|
|
91
93
|
...inputProps,
|
|
92
94
|
ref: mergeRefs(ref, inputRef),
|
|
93
95
|
"data-is-empty": value === "" || value === null || value === void 0 || void 0,
|
|
96
|
+
"data-is-filled": !(value === "" || value === null || value === void 0) || void 0,
|
|
94
97
|
"data-is-dirty": isDirty || void 0,
|
|
95
98
|
"data-is-required": isRequired || void 0,
|
|
96
99
|
"data-is-disabled": isDisabled || void 0,
|
|
@@ -11,23 +11,21 @@ declare const componentRegistry: {
|
|
|
11
11
|
readonly passwordInput: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/PasswordInput/PasswordInput').ControlledPasswordInputProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
readonly textArea: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../Input/TextArea/TextArea').ControlledTextAreaProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
13
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
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
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('../../../types/common').OmitDiscriminatedUnion<import('../Selection/shared/SelectBase').SelectBaseProps<TKey>, "onChange" | "value" | "items" | "selectionMode" | "isLoading" | "showSelectionBar" | "showSelectAllOption" | "initialSelection" | "showSelectionContent"> & (import('../Selection/shared/select.types').GroupedSelectControlProps<TFieldValues, TKey> & {
|
|
15
|
+
query: TQueryFn;
|
|
16
|
+
queryParams?: Parameters<TQueryFn>[0] | undefined;
|
|
24
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;
|
|
25
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;
|
|
26
23
|
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;
|
|
27
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;
|
|
28
25
|
readonly dateTimePicker: <TFieldValues extends import('react-hook-form').FieldValues>({ fullIso, ...props }: import('../DateTime/DateTimePicker/DateTimePicker').ControlledDateTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
29
26
|
readonly timePicker: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../DateTime/TimePicker/TimePicker').ControlledTimePickerProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
30
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;
|
|
28
|
+
readonly textEditor: <TFieldValues extends import('react-hook-form').FieldValues>(props: import('../../../text-editor.js').ControlledTextEditorProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
31
29
|
readonly unknown: null;
|
|
32
30
|
};
|
|
33
31
|
export type InputComponentRegistry = typeof componentRegistry;
|
|
@@ -13,6 +13,8 @@ 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";
|
|
16
18
|
import { jsx } from "react/jsx-runtime";
|
|
17
19
|
//#region src/components/inputs/Inputs/InputItem.tsx
|
|
18
20
|
var componentRegistry = {
|
|
@@ -24,6 +26,7 @@ var componentRegistry = {
|
|
|
24
26
|
passwordInput: PasswordInput,
|
|
25
27
|
textArea: TextArea,
|
|
26
28
|
select: Select,
|
|
29
|
+
querySelect: QuerySelect,
|
|
27
30
|
autocomplete: Autocomplete,
|
|
28
31
|
queryAutocomplete: QueryAutocomplete,
|
|
29
32
|
segment: Segment,
|
|
@@ -31,6 +34,7 @@ var componentRegistry = {
|
|
|
31
34
|
dateTimePicker: DateTimePicker,
|
|
32
35
|
timePicker: TimePicker,
|
|
33
36
|
dateRangePicker: DateRangePicker,
|
|
37
|
+
textEditor: TextEditor,
|
|
34
38
|
unknown: null
|
|
35
39
|
};
|
|
36
40
|
function InputItem({ form, inputDef }) {
|
|
@@ -9,12 +9,13 @@ var Autocomplete = (props) => {
|
|
|
9
9
|
return /* @__PURE__ */ jsx(Controller, {
|
|
10
10
|
control: formControl.control,
|
|
11
11
|
name: formControl.name,
|
|
12
|
-
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx(SelectBase, {
|
|
12
|
+
render: ({ field, fieldState: { error, isDirty } }) => /* @__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,
|
|
18
19
|
isDisabled: field.disabled || props.isDisabled,
|
|
19
20
|
error: props.error ?? error?.message,
|
|
20
21
|
isSearchable: true
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import { Key } from 'react-aria-components';
|
|
3
1
|
import { FieldValues } from 'react-hook-form';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
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 {};
|
|
2
|
+
import { QueryAutocompleteProps, QueryFn } from './queryAutocomplete.types';
|
|
3
|
+
import { SelectItem } from '../shared/select.types';
|
|
4
|
+
export declare const QueryAutocomplete: <TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>>({ query, queryParams, queryOptions, queryMap, ...props }: QueryAutocompleteProps<TFieldValues, TSelectItem, TQueryFn>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
+
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
1
2
|
import { Autocomplete } from "./Autocomplete.js";
|
|
3
|
+
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
2
4
|
import { jsx } from "react/jsx-runtime";
|
|
3
5
|
import { useState } from "react";
|
|
4
6
|
//#region src/components/inputs/Selection/Autocomplete/QueryAutocomplete.tsx
|
|
5
|
-
var QueryAutocomplete = ({ query, queryParams, queryOptions, ...props }) => {
|
|
7
|
+
var QueryAutocomplete = ({ query, queryParams, queryOptions, queryMap, ...props }) => {
|
|
8
|
+
const ui = UIConfig.useConfig();
|
|
6
9
|
const [search, setSearch] = useState("");
|
|
7
|
-
const
|
|
10
|
+
const mapItems = (data) => {
|
|
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),
|
|
8
19
|
search,
|
|
9
|
-
|
|
10
|
-
}
|
|
20
|
+
initialQueryState: props.isInitialQueryDisabled ?? ui.queryAutocomplete?.isInitialQueryDisabled
|
|
21
|
+
});
|
|
22
|
+
const { isInitialQueryDisabled: _, ...restProps } = props;
|
|
11
23
|
return /* @__PURE__ */ jsx(Autocomplete, {
|
|
12
|
-
...
|
|
13
|
-
items
|
|
24
|
+
...restProps,
|
|
25
|
+
items,
|
|
14
26
|
onSearchChange: setSearch,
|
|
15
27
|
isClientSearchDisabled: true,
|
|
16
|
-
isLoading
|
|
28
|
+
isLoading,
|
|
29
|
+
onMouseEnter: handleEnableQuery,
|
|
30
|
+
onFocusCapture: handleEnableQuery,
|
|
31
|
+
hasLoadMore: hasNextPage,
|
|
32
|
+
onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0
|
|
17
33
|
});
|
|
18
34
|
};
|
|
19
35
|
//#endregion
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
import { AutocompleteProps } from './Autocomplete';
|
|
5
|
+
import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
|
|
6
|
+
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
7
|
+
export interface QueryAutocompleteInfinitePage<TSelectItem extends SelectItem = SelectItem> {
|
|
8
|
+
items: Array<TSelectItem>;
|
|
9
|
+
totalItems?: number;
|
|
10
|
+
}
|
|
11
|
+
export type QueryResult<TSelectItem extends SelectItem = SelectItem> = UseQueryResult<Array<TSelectItem>> | UseInfiniteQueryResult<QueryAutocompleteInfinitePage<TSelectItem>>;
|
|
12
|
+
export type QueryFn<TSelectItem extends SelectItem = SelectItem> = (...args: any[]) => QueryResult<TSelectItem>;
|
|
13
|
+
export type QueryAutocompleteExtractedData<TSelectItem extends SelectItem = SelectItem> = Array<TSelectItem>;
|
|
14
|
+
export type QueryAutocompleteProps<TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>> = OmitDiscriminatedUnion<AutocompleteProps<TSelectItem["id"]>, "items" | "onSearchChange" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TSelectItem["id"]> & {
|
|
15
|
+
query: Parameters<TQueryFn>[0] extends {
|
|
16
|
+
search?: string;
|
|
17
|
+
} ? TQueryFn : never;
|
|
18
|
+
queryParams?: Omit<Parameters<TQueryFn>[0], "search">;
|
|
19
|
+
queryOptions?: Parameters<TQueryFn>[1];
|
|
20
|
+
queryMap?: (data: QueryAutocompleteExtractedData<TSelectItem>) => SelectItem<TSelectItem["id"]>[];
|
|
21
|
+
isInitialQueryDisabled?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export interface UseQueryAutocompleteOptions<TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>, TKey extends Key = QueryAutocompleteExtractedData<TSelectItem>[number]["id"]> {
|
|
24
|
+
query: TQueryFn;
|
|
25
|
+
queryParams?: Parameters<TQueryFn>[0];
|
|
26
|
+
queryOptions?: Parameters<TQueryFn>[1];
|
|
27
|
+
queryMap?: (data: QueryAutocompleteExtractedData<TSelectItem>) => SelectItem<TKey>[];
|
|
28
|
+
initialQueryState?: boolean;
|
|
29
|
+
search: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
|
|
2
|
+
import { SelectBaseProps } from '../shared/SelectBase';
|
|
3
|
+
import { QueryDataType, QueryFn } from '../shared/querySelect.utils';
|
|
4
|
+
import { OmitDiscriminatedUnion } from '../../../../types/common';
|
|
5
|
+
import { Key } from 'react-aria-components';
|
|
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> & {
|
|
8
|
+
query: TQueryFn;
|
|
9
|
+
queryParams?: Parameters<TQueryFn>[0];
|
|
10
|
+
queryOptions?: Parameters<TQueryFn>[1];
|
|
11
|
+
queryMap?: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[];
|
|
12
|
+
isInitialQueryDisabled?: boolean;
|
|
13
|
+
};
|
|
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 {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
2
|
+
import { SelectBase } from "../shared/SelectBase.js";
|
|
3
|
+
import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
|
|
4
|
+
import { getQueryItems } from "../shared/querySelect.utils.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
7
|
+
import { Controller } from "react-hook-form";
|
|
8
|
+
//#region src/components/inputs/Selection/Select/QuerySelect.tsx
|
|
9
|
+
var QuerySelect = ({ query, queryParams, queryOptions, queryMap, ...props }) => {
|
|
10
|
+
const ui = UIConfig.useConfig();
|
|
11
|
+
const { items, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
|
|
12
|
+
query,
|
|
13
|
+
queryParams,
|
|
14
|
+
queryOptions,
|
|
15
|
+
mapItems: (data) => getQueryItems(data, queryMap),
|
|
16
|
+
initialQueryState: props.isInitialQueryDisabled ?? ui.querySelect?.isInitialQueryDisabled
|
|
17
|
+
});
|
|
18
|
+
if ("formControl" in props && props.formControl) {
|
|
19
|
+
const { formControl, ref, isInitialQueryDisabled: _, ...innerProps } = props;
|
|
20
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
21
|
+
control: formControl.control,
|
|
22
|
+
name: formControl.name,
|
|
23
|
+
render: ({ field, fieldState: { error, isDirty } }) => /* @__PURE__ */ jsx(SelectBase, {
|
|
24
|
+
...innerProps,
|
|
25
|
+
ref: mergeRefs(ref, field.ref),
|
|
26
|
+
items,
|
|
27
|
+
isLoading,
|
|
28
|
+
hasLoadMore: hasNextPage,
|
|
29
|
+
onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0,
|
|
30
|
+
value: field.value,
|
|
31
|
+
onChange: (value) => {
|
|
32
|
+
field.onChange(value);
|
|
33
|
+
field.onBlur?.();
|
|
34
|
+
},
|
|
35
|
+
onBlur: field.onBlur,
|
|
36
|
+
isDirty,
|
|
37
|
+
isDisabled: field.disabled || props.isDisabled,
|
|
38
|
+
error: props.error ?? error?.message,
|
|
39
|
+
onMouseEnter: handleEnableQuery,
|
|
40
|
+
onFocusCapture: handleEnableQuery
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const { isInitialQueryDisabled: _, ...restProps } = props;
|
|
45
|
+
return /* @__PURE__ */ jsx(SelectBase, {
|
|
46
|
+
...restProps,
|
|
47
|
+
items,
|
|
48
|
+
isLoading,
|
|
49
|
+
hasLoadMore: hasNextPage,
|
|
50
|
+
onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0,
|
|
51
|
+
onMouseEnter: handleEnableQuery,
|
|
52
|
+
onFocusCapture: handleEnableQuery
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { QuerySelect };
|
|
@@ -9,12 +9,13 @@ var Select = (props) => {
|
|
|
9
9
|
return /* @__PURE__ */ jsx(Controller, {
|
|
10
10
|
control: formControl.control,
|
|
11
11
|
name: formControl.name,
|
|
12
|
-
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx(SelectBase, {
|
|
12
|
+
render: ({ field, fieldState: { error, isDirty } }) => /* @__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,
|
|
18
19
|
isDisabled: field.disabled || props.isDisabled,
|
|
19
20
|
error: props.error ?? error?.message
|
|
20
21
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactElement, Ref } from 'react';
|
|
1
|
+
import { FocusEventHandler, MouseEventHandler, ReactElement, Ref } from 'react';
|
|
2
2
|
import { AriaButtonProps } from 'react-aria';
|
|
3
3
|
import { Key } from 'react-aria-components';
|
|
4
4
|
import { FormFieldProps } from '../../FormField/FormField';
|
|
@@ -7,6 +7,7 @@ import { InputVariantProps } from '../../shared/input.cva';
|
|
|
7
7
|
export type SelectBaseProps<TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>> = FormFieldProps & GroupedSelectProps<TKey, TInitialSelectItem> & SelectNewItemProps & SelectAsyncProps & SelectVirtualizationProps & InputVariantProps & Pick<AriaButtonProps, "onBlur"> & {
|
|
8
8
|
ref?: Ref<HTMLDivElement>;
|
|
9
9
|
className?: string;
|
|
10
|
+
isDirty?: boolean;
|
|
10
11
|
placeholder?: string;
|
|
11
12
|
hideDropdownIcon?: boolean;
|
|
12
13
|
hideSearchIcon?: boolean;
|
|
@@ -20,8 +21,11 @@ export type SelectBaseProps<TKey extends Key = Key, TInitialSelectItem = Default
|
|
|
20
21
|
customTrigger?: ReactElement;
|
|
21
22
|
selectedTagsType?: "tags" | "list";
|
|
22
23
|
collapseAfter?: number;
|
|
24
|
+
fireBlurOnChange?: boolean;
|
|
23
25
|
onInputChange?: (value: string) => void;
|
|
24
26
|
onSearchChange?: (value: string) => void;
|
|
25
27
|
mapInitialToSelectItem?: (item: TInitialSelectItem) => SelectItem<TKey>;
|
|
28
|
+
onMouseEnter?: MouseEventHandler<HTMLDivElement>;
|
|
29
|
+
onFocusCapture?: FocusEventHandler<HTMLDivElement>;
|
|
26
30
|
};
|
|
27
31
|
export declare const SelectBase: <TKey extends Key = Key, TInitialSelectItem = DefaultInitialSelectItem<TKey>>(dProps: SelectBaseProps<TKey, TInitialSelectItem>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -19,7 +19,8 @@ var SelectBase = (dProps) => {
|
|
|
19
19
|
selectedTagsType: dProps.selectedTagsType ?? ui.select.selectedTagsType,
|
|
20
20
|
ignoreTriggerWidth: dProps.virtualizerOptions || dProps.items.length > 100 ? false : dProps.ignoreTriggerWidth ?? false,
|
|
21
21
|
collapseAfter: dProps.collapseAfter ?? ui.select.collapseAfter,
|
|
22
|
-
hideSearchIcon: dProps.hideSearchIcon ?? ui.select.hideSearchIcon
|
|
22
|
+
hideSearchIcon: dProps.hideSearchIcon ?? ui.select.hideSearchIcon,
|
|
23
|
+
fireBlurOnChange: dProps.fireBlurOnChange ?? ui.select.fireBlurOnChange
|
|
23
24
|
};
|
|
24
25
|
const isDesktop = useBreakpoint("md");
|
|
25
26
|
return /* @__PURE__ */ jsx(SelectContext.Provider, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Key } from 'react-aria-components';
|
|
2
2
|
import { SelectBaseProps } from './SelectBase';
|
|
3
3
|
type SelectDesktopProps<TKey extends Key = Key> = SelectBaseProps<TKey>;
|
|
4
|
-
export declare const SelectDesktop: <TKey extends Key = Key>({ ref, error, ignoreTriggerWidth, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, ...props }: SelectDesktopProps<TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare const SelectDesktop: <TKey extends Key = Key>({ ref, error, ignoreTriggerWidth, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, onMouseEnter, onFocusCapture, ...props }: SelectDesktopProps<TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export {};
|
|
@@ -13,8 +13,8 @@ import { ComboBox, DialogTrigger, Popover } from "react-aria-components";
|
|
|
13
13
|
import { useLabel, usePreventScroll } from "react-aria";
|
|
14
14
|
import { mergeRefs } from "@react-aria/utils";
|
|
15
15
|
//#region src/components/inputs/Selection/shared/SelectDesktop.tsx
|
|
16
|
-
var SelectDesktop = ({ ref, error, ignoreTriggerWidth, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, ...props }) => {
|
|
17
|
-
const { label, tooltipText, helperText, isRequired, rightContent, isHeaderHidden, headerClassName, errorClassName, placeholder, variant, isDisabled, className, hideLabel, hideDropdownIcon, isSearchable, isClearable, isLoading, as, size, collapseAfter, selectedTagsType } = props;
|
|
16
|
+
var SelectDesktop = ({ ref, error, ignoreTriggerWidth, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, onMouseEnter, onFocusCapture, ...props }) => {
|
|
17
|
+
const { label, tooltipText, helperText, isDirty, isRequired, rightContent, isHeaderHidden, headerClassName, errorClassName, placeholder, variant, isDisabled, className, hideLabel, hideDropdownIcon, isSearchable, isClearable, isLoading, as, size, collapseAfter, selectedTagsType } = props;
|
|
18
18
|
const popoverCva = UIStyle.useCva("popover.cva", popover);
|
|
19
19
|
const formFieldProps = {
|
|
20
20
|
error,
|
|
@@ -119,6 +119,8 @@ var SelectDesktop = ({ ref, error, ignoreTriggerWidth, showSelectionContent, inp
|
|
|
119
119
|
children: /* @__PURE__ */ jsx("div", {
|
|
120
120
|
...fieldProps,
|
|
121
121
|
ref: mergeRefs(ref, triggerRef),
|
|
122
|
+
onMouseEnter,
|
|
123
|
+
onFocusCapture,
|
|
122
124
|
children: customTrigger
|
|
123
125
|
})
|
|
124
126
|
}) : /* @__PURE__ */ jsx(SelectInput, {
|
|
@@ -137,6 +139,8 @@ var SelectDesktop = ({ ref, error, ignoreTriggerWidth, showSelectionContent, inp
|
|
|
137
139
|
inputClassName,
|
|
138
140
|
collapseAfter,
|
|
139
141
|
selectedTagsType,
|
|
142
|
+
isRequired,
|
|
143
|
+
isDirty,
|
|
140
144
|
onBlur,
|
|
141
145
|
onCloseComboBox: (state) => {
|
|
142
146
|
if (isSearchable) closeComboBoxRef.current = state;
|
|
@@ -4,12 +4,12 @@ import { FormFieldHeaderProps } from '../../FormField/FormFieldHeader';
|
|
|
4
4
|
import { SelectBaseProps } from './SelectBase';
|
|
5
5
|
import { SelectItem } from './select.types';
|
|
6
6
|
import { InputVariantProps } from '../../shared/input.cva';
|
|
7
|
-
interface SelectInputProps extends InputVariantProps, Pick<SelectBaseProps, "ref" | "placeholder" | "isDisabled" | "hideDropdownIcon" | "isSearchable" | "isClearable" | "onBlur" | "showSelectionContent" | "inputClassName" | "selectedTagsType" | "collapseAfter"> {
|
|
7
|
+
interface SelectInputProps extends InputVariantProps, Pick<SelectBaseProps, "ref" | "placeholder" | "isDisabled" | "hideDropdownIcon" | "isSearchable" | "isClearable" | "onBlur" | "showSelectionContent" | "inputClassName" | "selectedTagsType" | "collapseAfter" | "isRequired" | "isDirty" | "fireBlurOnChange" | "onMouseEnter" | "onFocusCapture"> {
|
|
8
8
|
isInvalid?: boolean;
|
|
9
9
|
className?: string;
|
|
10
10
|
fieldProps?: AriaFieldProps;
|
|
11
11
|
headerProps?: FormFieldHeaderProps;
|
|
12
12
|
onCloseComboBox?: (state: ComboBoxState<SelectItem> | null) => void;
|
|
13
13
|
}
|
|
14
|
-
export declare const SelectInput: ({ ref, placeholder, variant, as, size, isDisabled, isInvalid, className, hideDropdownIcon, isSearchable, isClearable, showSelectionContent, inputClassName, fieldProps, headerProps, selectedTagsType, collapseAfter, onCloseComboBox, onBlur, ...props }: SelectInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const SelectInput: ({ ref, placeholder, variant, as, size, isDisabled, isInvalid, className, hideDropdownIcon, isSearchable, isClearable, showSelectionContent, inputClassName, fieldProps, headerProps, selectedTagsType, collapseAfter, isRequired, isDirty, onCloseComboBox, onBlur, fireBlurOnChange, onMouseEnter, onFocusCapture, ...props }: SelectInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
15
|
export {};
|
|
@@ -14,7 +14,7 @@ import { Button, ComboBoxStateContext, Input } from "react-aria-components";
|
|
|
14
14
|
import { useFocusVisible, useFocusWithin, useHover } from "react-aria";
|
|
15
15
|
import { useTranslation } from "react-i18next";
|
|
16
16
|
//#region src/components/inputs/Selection/shared/SelectInput.tsx
|
|
17
|
-
var SelectInput = ({ ref, placeholder, variant, as, size, isDisabled, isInvalid, className, hideDropdownIcon, isSearchable, isClearable, showSelectionContent, inputClassName, fieldProps, headerProps, selectedTagsType, collapseAfter, onCloseComboBox, onBlur, ...props }) => {
|
|
17
|
+
var SelectInput = ({ ref, placeholder, variant, as, size, isDisabled, isInvalid, className, hideDropdownIcon, isSearchable, isClearable, showSelectionContent, inputClassName, fieldProps, headerProps, selectedTagsType, collapseAfter, isRequired, isDirty, onCloseComboBox, onBlur, fireBlurOnChange, onMouseEnter, onFocusCapture, ...props }) => {
|
|
18
18
|
const inputSizeCva = UIStyle.useCva("input.sizeCva", inputSize);
|
|
19
19
|
const inputBaseCva = UIStyle.useCva("input.baseCva", inputBase);
|
|
20
20
|
const { t } = useTranslation("ui");
|
|
@@ -44,9 +44,13 @@ var SelectInput = ({ ref, placeholder, variant, as, size, isDisabled, isInvalid,
|
|
|
44
44
|
if (e.key === "Enter" && !isMultiple && !isLoading && listItems.length === 1 && !listItems[0].isDisabled) {
|
|
45
45
|
e.preventDefault();
|
|
46
46
|
onChange(listItems[0].id);
|
|
47
|
+
if (fireBlurOnChange) onBlur?.({});
|
|
47
48
|
onCloseComboBox?.(state);
|
|
48
49
|
}
|
|
49
|
-
if (e.key === "Backspace" && isMultiple && fieldState.inputValue === "" && Array.isArray(fieldState.value) && fieldState.value.length > 0)
|
|
50
|
+
if (e.key === "Backspace" && isMultiple && fieldState.inputValue === "" && Array.isArray(fieldState.value) && fieldState.value.length > 0) {
|
|
51
|
+
onChange(fieldState.value.slice(0, -1));
|
|
52
|
+
if (fireBlurOnChange) onBlur?.({});
|
|
53
|
+
}
|
|
50
54
|
};
|
|
51
55
|
const onClick = () => {
|
|
52
56
|
if (isDisabled) return;
|
|
@@ -75,7 +79,12 @@ var SelectInput = ({ ref, placeholder, variant, as, size, isDisabled, isInvalid,
|
|
|
75
79
|
"data-has-search": fieldState.searchValue !== "" || void 0,
|
|
76
80
|
"data-invalid": isInvalid || void 0,
|
|
77
81
|
"data-is-empty": isEmpty || void 0,
|
|
82
|
+
"data-is-filled": !isEmpty || void 0,
|
|
83
|
+
"data-is-required": isRequired || void 0,
|
|
84
|
+
"data-is-dirty": isDirty || void 0,
|
|
78
85
|
"data-select-input": "",
|
|
86
|
+
onMouseEnter,
|
|
87
|
+
onFocusCapture,
|
|
79
88
|
...hoverProps,
|
|
80
89
|
...focusWithinProps,
|
|
81
90
|
children: [
|
|
@@ -125,7 +134,10 @@ var SelectInput = ({ ref, placeholder, variant, as, size, isDisabled, isInvalid,
|
|
|
125
134
|
]
|
|
126
135
|
}),
|
|
127
136
|
isClearable && /* @__PURE__ */ jsx(InputClear, {
|
|
128
|
-
onClear
|
|
137
|
+
onClear: () => {
|
|
138
|
+
onClear();
|
|
139
|
+
if (fireBlurOnChange) onBlur?.({});
|
|
140
|
+
},
|
|
129
141
|
show: showClearButton
|
|
130
142
|
}),
|
|
131
143
|
!hideDropdownIcon && /* @__PURE__ */ jsx(Button, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Key } from 'react-aria-components';
|
|
2
2
|
import { SelectBaseProps } from './SelectBase';
|
|
3
3
|
type SelectMobileProps<TKey extends Key = Key> = SelectBaseProps<TKey>;
|
|
4
|
-
export declare const SelectMobile: <TKey extends Key = Key>({ ref, error, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, ...props }: SelectMobileProps<TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare const SelectMobile: <TKey extends Key = Key>({ ref, error, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, onMouseEnter, onFocusCapture, ...props }: SelectMobileProps<TKey>) => import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export {};
|
|
@@ -13,8 +13,8 @@ import { useRef } from "react";
|
|
|
13
13
|
import { DialogTrigger } from "react-aria-components";
|
|
14
14
|
import { useLabel } from "react-aria";
|
|
15
15
|
//#region src/components/inputs/Selection/shared/SelectMobile.tsx
|
|
16
|
-
var SelectMobile = ({ ref, error, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, ...props }) => {
|
|
17
|
-
const { label, tooltipText, helperText, isRequired, rightContent, isHeaderHidden, headerClassName, errorClassName, placeholder, variant, isDisabled, className, hideLabel, hideDropdownIcon, hideSearchIcon, isSearchable, isClearable, as, size, collapseAfter, selectedTagsType } = props;
|
|
16
|
+
var SelectMobile = ({ ref, error, showSelectionContent, inputClassName, containerClassName, customTrigger, onBlur, onMouseEnter, onFocusCapture, ...props }) => {
|
|
17
|
+
const { label, tooltipText, helperText, isDirty, isRequired, rightContent, isHeaderHidden, headerClassName, errorClassName, placeholder, variant, isDisabled, className, hideLabel, hideDropdownIcon, hideSearchIcon, isSearchable, isClearable, as, size, collapseAfter, selectedTagsType } = props;
|
|
18
18
|
const formFieldProps = {
|
|
19
19
|
error,
|
|
20
20
|
label,
|
|
@@ -62,6 +62,8 @@ var SelectMobile = ({ ref, error, showSelectionContent, inputClassName, containe
|
|
|
62
62
|
children: [customTrigger ? /* @__PURE__ */ jsx("div", {
|
|
63
63
|
...fieldProps,
|
|
64
64
|
ref,
|
|
65
|
+
onMouseEnter,
|
|
66
|
+
onFocusCapture,
|
|
65
67
|
children: customTrigger
|
|
66
68
|
}) : /* @__PURE__ */ jsx(SelectInput, {
|
|
67
69
|
ref,
|
|
@@ -80,7 +82,9 @@ var SelectMobile = ({ ref, error, showSelectionContent, inputClassName, containe
|
|
|
80
82
|
fieldProps,
|
|
81
83
|
headerProps,
|
|
82
84
|
collapseAfter,
|
|
83
|
-
selectedTagsType
|
|
85
|
+
selectedTagsType,
|
|
86
|
+
isRequired,
|
|
87
|
+
isDirty
|
|
84
88
|
}), /* @__PURE__ */ jsx(BottomSheet, {
|
|
85
89
|
isOpen,
|
|
86
90
|
onOpenChange: handleOpenChange,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
3
|
+
import { SelectItem } from './select.types';
|
|
4
|
+
export type QueryFn<TData = any> = (...args: any[]) => UseQueryResult<TData> | UseInfiniteQueryResult<TData>;
|
|
5
|
+
export type QueryDataType<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>;
|
|
6
|
+
export declare const getQueryItems: <TQueryFn extends QueryFn, TKey extends Key = Key>(data: QueryDataType<TQueryFn> | undefined, queryMap?: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[]) => SelectItem<TKey>[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/components/inputs/Selection/shared/querySelect.utils.ts
|
|
2
|
+
var getQueryItems = (data, queryMap) => {
|
|
3
|
+
if (!data) return [];
|
|
4
|
+
if (queryMap) return queryMap(data);
|
|
5
|
+
if (Array.isArray(data)) return data;
|
|
6
|
+
if (typeof data === "object" && data !== null) {
|
|
7
|
+
if ("items" in data && Array.isArray(data.items)) return data.items;
|
|
8
|
+
if ("pages" in data && Array.isArray(data.pages)) return data.pages.flatMap((page) => page && typeof page === "object" && "items" in page && Array.isArray(page.items) ? page.items : []);
|
|
9
|
+
}
|
|
10
|
+
return [];
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getQueryItems };
|
|
@@ -15,6 +15,7 @@ export interface TextEditorBaseProps extends FormFieldProps {
|
|
|
15
15
|
onBlur?: () => void;
|
|
16
16
|
as?: "default" | "filter" | "floating" | "inline" | null;
|
|
17
17
|
editorClassName?: string;
|
|
18
|
+
isDirty?: boolean;
|
|
18
19
|
}
|
|
19
20
|
export type TextEditorProps = TextEditorBaseProps;
|
|
20
21
|
export type ControlledTextEditorProps<TFieldValues extends FieldValues> = ControlProps<TextEditorProps, TFieldValues>;
|
|
@@ -37,7 +37,7 @@ var extensions = [
|
|
|
37
37
|
defaultProtocol: "https"
|
|
38
38
|
})
|
|
39
39
|
];
|
|
40
|
-
var TextEditorBase = ({ ref, as = "default", placeholder, label, hideLabel, tooltipText, helperText, isRequired, rightContent, isDisabled, headerClassName, errorClassName, isHeaderHidden, error, value, className, editorClassName, onChange, onBlur }) => {
|
|
40
|
+
var TextEditorBase = ({ ref, as = "default", placeholder, label, hideLabel, tooltipText, helperText, isRequired, rightContent, isDisabled, headerClassName, errorClassName, isHeaderHidden, error, value, className, editorClassName, isDirty, onChange, onBlur }) => {
|
|
41
41
|
const contentRef = useRef(null);
|
|
42
42
|
const { hoverProps, isHovered } = useHover({ isDisabled });
|
|
43
43
|
const [isFocused, setIsFocused] = useState(false);
|
|
@@ -109,6 +109,8 @@ var TextEditorBase = ({ ref, as = "default", placeholder, label, hideLabel, tool
|
|
|
109
109
|
"data-focus-within": isFocused || void 0,
|
|
110
110
|
"data-focus-visible": isFocused && isFocusVisible || void 0,
|
|
111
111
|
"data-is-filled": !editor?.isEmpty,
|
|
112
|
+
"data-is-required": isRequired || void 0,
|
|
113
|
+
"data-is-dirty": isDirty || void 0,
|
|
112
114
|
...hoverProps,
|
|
113
115
|
...focusWithinProps,
|
|
114
116
|
...fieldProps,
|
|
@@ -136,13 +138,15 @@ var TextEditor = (props) => {
|
|
|
136
138
|
return /* @__PURE__ */ jsx(Controller, {
|
|
137
139
|
control: formControl.control,
|
|
138
140
|
name: formControl.name,
|
|
139
|
-
render: ({ field }) => /* @__PURE__ */ jsx(TextEditorBase, {
|
|
141
|
+
render: ({ field, fieldState: { error, isDirty } }) => /* @__PURE__ */ jsx(TextEditorBase, {
|
|
140
142
|
...innerProps,
|
|
141
143
|
ref: mergeRefs(ref, field.ref),
|
|
142
144
|
value: field.value,
|
|
143
145
|
onChange: field.onChange,
|
|
144
146
|
onBlur: field.onBlur,
|
|
145
|
-
|
|
147
|
+
isDirty,
|
|
148
|
+
isDisabled: field.disabled || props.isDisabled,
|
|
149
|
+
error: props.error ?? error?.message
|
|
146
150
|
})
|
|
147
151
|
});
|
|
148
152
|
}
|
|
@@ -24,7 +24,13 @@ export declare namespace UIConfig {
|
|
|
24
24
|
numberInput: Pick<NumberInputProps, "formatOptions">;
|
|
25
25
|
radioGroup: Pick<RadioGroupProps, "variant" | "hideLabel">;
|
|
26
26
|
checkbox: Pick<CheckboxProps, "variant">;
|
|
27
|
-
select: Pick<SelectBaseProps, "selectionMode" | "isSearchable" | "collapseAfter" | "selectedTagsType" | "hideSearchIcon">;
|
|
27
|
+
select: Pick<SelectBaseProps, "selectionMode" | "isSearchable" | "collapseAfter" | "selectedTagsType" | "hideSearchIcon" | "fireBlurOnChange">;
|
|
28
|
+
queryAutocomplete: {
|
|
29
|
+
isInitialQueryDisabled?: boolean;
|
|
30
|
+
};
|
|
31
|
+
querySelect: {
|
|
32
|
+
isInitialQueryDisabled?: boolean;
|
|
33
|
+
};
|
|
28
34
|
toggle: Pick<ToggleProps, "variant">;
|
|
29
35
|
slider: Pick<SliderProps, "minValue" | "maxValue">;
|
|
30
36
|
dateInput: Pick<DatePickerProps, "todayIcon" | "shouldForceLeadingZeros" | "disableManualEntry">;
|
|
@@ -31,8 +31,11 @@ var UIConfig;
|
|
|
31
31
|
isSearchable: false,
|
|
32
32
|
selectedTagsType: "list",
|
|
33
33
|
collapseAfter: 3,
|
|
34
|
-
hideSearchIcon: false
|
|
34
|
+
hideSearchIcon: false,
|
|
35
|
+
fireBlurOnChange: false
|
|
35
36
|
},
|
|
37
|
+
queryAutocomplete: { isInitialQueryDisabled: false },
|
|
38
|
+
querySelect: { isInitialQueryDisabled: false },
|
|
36
39
|
toggle: { variant: "default" },
|
|
37
40
|
slider: {
|
|
38
41
|
minValue: 0,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
3
|
+
import { SelectItem } from '../components/inputs/Selection/shared/select.types';
|
|
4
|
+
type QueryResult<TData = any> = UseQueryResult<TData> | UseInfiniteQueryResult<TData>;
|
|
5
|
+
type QueryFn<TData = any> = (...args: any[]) => QueryResult<TData>;
|
|
6
|
+
type QueryDataType<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>;
|
|
7
|
+
interface UseQueryAutocompleteOptions<TQueryFn extends QueryFn, TKey extends Key = Key> {
|
|
8
|
+
query: TQueryFn;
|
|
9
|
+
queryParams?: Parameters<TQueryFn>[0];
|
|
10
|
+
queryOptions?: Parameters<TQueryFn>[1];
|
|
11
|
+
mapItems: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[];
|
|
12
|
+
initialQueryState?: boolean;
|
|
13
|
+
search?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const useQueryAutocomplete: <TQueryFn extends QueryFn, TKey extends Key = Key>({ query, queryParams, queryOptions, mapItems, initialQueryState, search, }: UseQueryAutocompleteOptions<TQueryFn, TKey>) => {
|
|
16
|
+
data: any;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
isQueryEnabled: boolean;
|
|
19
|
+
handleEnableQuery: () => void;
|
|
20
|
+
items: SelectItem<TKey>[];
|
|
21
|
+
hasNextPage: boolean;
|
|
22
|
+
fetchNextPage: (() => Promise<unknown>) | ((options?: import('@tanstack/react-query').FetchNextPageOptions) => Promise<import('@tanstack/react-query').InfiniteQueryObserverResult<any, Error>>) | undefined;
|
|
23
|
+
isFetchingNextPage: boolean;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
//#region src/hooks/useQueryAutocomplete.ts
|
|
3
|
+
var useQueryAutocomplete = ({ query, queryParams, queryOptions, mapItems, initialQueryState, search }) => {
|
|
4
|
+
const [isQueryEnabled, setIsQueryEnabled] = useState(!initialQueryState);
|
|
5
|
+
const queryResult = query(search === void 0 ? queryParams : {
|
|
6
|
+
search,
|
|
7
|
+
...queryParams
|
|
8
|
+
}, {
|
|
9
|
+
...queryOptions,
|
|
10
|
+
enabled: isQueryEnabled && (queryOptions?.enabled ?? true)
|
|
11
|
+
});
|
|
12
|
+
const data = queryResult.data;
|
|
13
|
+
const isLoading = queryResult.isLoading;
|
|
14
|
+
const isInfiniteQueryResult = (result) => {
|
|
15
|
+
return "hasNextPage" in result && "fetchNextPage" in result;
|
|
16
|
+
};
|
|
17
|
+
const isInfiniteQuery = isInfiniteQueryResult(queryResult);
|
|
18
|
+
const handleEnableQuery = () => {
|
|
19
|
+
setIsQueryEnabled(true);
|
|
20
|
+
};
|
|
21
|
+
const infiniteQueryResult = isInfiniteQuery ? queryResult : void 0;
|
|
22
|
+
const hasNextPage = infiniteQueryResult?.hasNextPage ?? false;
|
|
23
|
+
const fetchNextPage = infiniteQueryResult?.fetchNextPage;
|
|
24
|
+
const isFetchingNextPage = infiniteQueryResult?.isFetchingNextPage ?? false;
|
|
25
|
+
const items = useMemo(() => {
|
|
26
|
+
if (!data) return [];
|
|
27
|
+
return mapItems(data);
|
|
28
|
+
}, [data, mapItems]);
|
|
29
|
+
return {
|
|
30
|
+
data,
|
|
31
|
+
isLoading: isLoading || isFetchingNextPage,
|
|
32
|
+
isQueryEnabled,
|
|
33
|
+
handleEnableQuery,
|
|
34
|
+
items,
|
|
35
|
+
hasNextPage,
|
|
36
|
+
fetchNextPage,
|
|
37
|
+
isFetchingNextPage
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useQueryAutocomplete };
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ import { QueryAutocomplete } from "./components/inputs/Selection/Autocomplete/Qu
|
|
|
92
92
|
import { Slider } from "./components/inputs/Slider/Slider.js";
|
|
93
93
|
import { Toggle } from "./components/inputs/Toggle/Toggle.js";
|
|
94
94
|
import { Segment } from "./components/segment/Segment.js";
|
|
95
|
+
import { ResponsivePopover } from "./components/overlays/ResponsivePopover/ResponsivePopover.js";
|
|
95
96
|
import { StringUtils } from "./utils/string.utils.js";
|
|
96
97
|
import { dynamicInputs } from "./helpers/dynamicInputs.js";
|
|
97
98
|
import { Form } from "./components/inputs/Inputs/Form.js";
|
|
@@ -102,7 +103,6 @@ import { Stepper } from "./components/navigation/Stepper/Stepper.js";
|
|
|
102
103
|
import { Modal } from "./components/overlays/Modal/Modal.js";
|
|
103
104
|
import { ActionModal } from "./components/overlays/ActionModal/ActionModal.js";
|
|
104
105
|
import { Drawer } from "./components/overlays/Drawer/Drawer.js";
|
|
105
|
-
import { ResponsivePopover } from "./components/overlays/ResponsivePopover/ResponsivePopover.js";
|
|
106
106
|
import { TooltipEllipsis } from "./components/overlays/Tooltip/TooltipEllipsis.js";
|
|
107
107
|
import { PaginationList } from "./components/shared/pagination/PaginationList.js";
|
|
108
108
|
import { Pagination } from "./components/shared/pagination/Pagination.js";
|