periplo-ui 4.2.1 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Combobox/Combobox.d.ts +6 -42
- package/dist/components/Combobox/Combobox.js +25 -54
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/Combobox/ComboboxTrigger.d.ts +14 -0
- package/dist/components/Combobox/ComboboxTrigger.js +74 -0
- package/dist/components/Combobox/ComboboxTrigger.js.map +1 -0
- package/dist/components/Combobox/StaticComboboxList.js +1 -1
- package/dist/components/Combobox/StaticComboboxList.js.map +1 -1
- package/dist/components/Combobox/VirtualizedComboboxList.js +1 -1
- package/dist/components/Combobox/VirtualizedComboboxList.js.map +1 -1
- package/dist/components/Combobox/hooks/index.d.ts +6 -0
- package/dist/components/Combobox/hooks/index.js +7 -0
- package/dist/components/Combobox/hooks/index.js.map +1 -0
- package/dist/components/Combobox/hooks/useComboboxOpenState.d.ts +7 -0
- package/dist/components/Combobox/hooks/useComboboxOpenState.js +18 -0
- package/dist/components/Combobox/hooks/useComboboxOpenState.js.map +1 -0
- package/dist/components/Combobox/hooks/useComboboxSelection.d.ts +7 -0
- package/dist/components/Combobox/hooks/useComboboxSelection.js +49 -0
- package/dist/components/Combobox/hooks/useComboboxSelection.js.map +1 -0
- package/dist/components/Combobox/hooks/useDebouncedState.d.ts +5 -0
- package/dist/components/Combobox/hooks/useDebouncedState.js +19 -0
- package/dist/components/Combobox/hooks/useDebouncedState.js.map +1 -0
- package/dist/components/Combobox/hooks/useDisplayValue.d.ts +11 -0
- package/dist/components/Combobox/hooks/useDisplayValue.js +32 -0
- package/dist/components/Combobox/hooks/useDisplayValue.js.map +1 -0
- package/dist/components/Combobox/hooks/usePaginatedOptions.d.ts +24 -0
- package/dist/components/Combobox/hooks/usePaginatedOptions.js +54 -0
- package/dist/components/Combobox/hooks/usePaginatedOptions.js.map +1 -0
- package/dist/components/Combobox/hooks/useSelectedCache.d.ts +4 -0
- package/dist/components/Combobox/hooks/useSelectedCache.js +17 -0
- package/dist/components/Combobox/hooks/useSelectedCache.js.map +1 -0
- package/dist/components/Combobox/useCombobox.d.ts +3 -3
- package/dist/components/Combobox/useCombobox.js +25 -158
- package/dist/components/Combobox/useCombobox.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +7 -1
- package/dist/components/Tooltip/Tooltip.js +31 -24
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tooltip/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -51,6 +51,8 @@ type ComboboxBaseProps<T> = {
|
|
|
51
51
|
container?: HTMLElement;
|
|
52
52
|
/** Alignment of the dropdown relative to the trigger. Defaults to 'center'. */
|
|
53
53
|
align?: 'start' | 'center' | 'end';
|
|
54
|
+
/** Auto-focus the search input when the dropdown opens. */
|
|
55
|
+
onOpenAutoFocus?: boolean;
|
|
54
56
|
};
|
|
55
57
|
export type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {
|
|
56
58
|
multiple?: false;
|
|
@@ -70,6 +72,8 @@ export type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {
|
|
|
70
72
|
hasNextPage: boolean;
|
|
71
73
|
nextPage: number;
|
|
72
74
|
}>;
|
|
75
|
+
/** Prefetch the first page on mount (virtualized only), so data is ready before opening. */
|
|
76
|
+
prefetch?: boolean;
|
|
73
77
|
};
|
|
74
78
|
export type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {
|
|
75
79
|
multiple: true;
|
|
@@ -79,6 +83,8 @@ export type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {
|
|
|
79
83
|
renderLabel?: (selectedOptions: Array<T>, onRemove: (value: string) => void) => React.ReactNode;
|
|
80
84
|
/** fetchPage is not allowed with multiple selection */
|
|
81
85
|
fetchPage?: never;
|
|
86
|
+
/** prefetch is not allowed with multiple selection */
|
|
87
|
+
prefetch?: never;
|
|
82
88
|
};
|
|
83
89
|
export type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T>;
|
|
84
90
|
/**
|
|
@@ -86,54 +92,12 @@ export type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T>
|
|
|
86
92
|
*
|
|
87
93
|
* @example Basic usage
|
|
88
94
|
* ```tsx
|
|
89
|
-
* interface User {
|
|
90
|
-
* id: string
|
|
91
|
-
* name: string
|
|
92
|
-
* email: string
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* <Combobox<User>
|
|
96
|
-
* options={users}
|
|
97
|
-
* value={selectedUserId}
|
|
98
|
-
* onChange={setSelectedUserId}
|
|
99
|
-
* getOptionValue={(user) => user.id}
|
|
100
|
-
* getOptionLabel={(user) => user.name}
|
|
101
|
-
* />
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* @example Custom filtering
|
|
105
|
-
* ```tsx
|
|
106
95
|
* <Combobox<User>
|
|
107
96
|
* options={users}
|
|
108
97
|
* value={selectedUserId}
|
|
109
98
|
* onChange={setSelectedUserId}
|
|
110
99
|
* getOptionValue={(user) => user.id}
|
|
111
100
|
* getOptionLabel={(user) => user.name}
|
|
112
|
-
* filterOptions={(options, searchTerm) =>
|
|
113
|
-
* options.filter(user =>
|
|
114
|
-
* user.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
115
|
-
* user.email.toLowerCase().includes(searchTerm.toLowerCase())
|
|
116
|
-
* )
|
|
117
|
-
* }
|
|
118
|
-
* />
|
|
119
|
-
* ```
|
|
120
|
-
*
|
|
121
|
-
* @example Virtualized infinite scrolling with pagination
|
|
122
|
-
* ```tsx
|
|
123
|
-
* <Combobox<User>
|
|
124
|
-
* options={[]} // Initial options can be empty
|
|
125
|
-
* value={selectedUserId}
|
|
126
|
-
* onChange={setSelectedUserId}
|
|
127
|
-
* getOptionValue={(user) => user.id}
|
|
128
|
-
* getOptionLabel={(user) => user.name}
|
|
129
|
-
* fetchPage={async ({ page, search }) => {
|
|
130
|
-
* const response = await api.getUsers({ page, search })
|
|
131
|
-
* return {
|
|
132
|
-
* items: response.users,
|
|
133
|
-
* hasNextPage: response.page < response.totalPages,
|
|
134
|
-
* nextPage: page + 1
|
|
135
|
-
* }
|
|
136
|
-
* }}
|
|
137
101
|
* />
|
|
138
102
|
* ```
|
|
139
103
|
*/
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
3
|
-
import { X } from '@phosphor-icons/react/dist/ssr/X';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
4
3
|
import { cn } from '../../lib/utils.js';
|
|
5
|
-
import { Button, buttonVariants } from '../Button/Button.js';
|
|
6
4
|
import { Command, CommandInput } from '../Command/Command.js';
|
|
7
5
|
import { PopoverRoot, PopoverTrigger, PopoverContent } from '../Popover/Popover.js';
|
|
6
|
+
import { ComboboxTrigger } from './ComboboxTrigger.js';
|
|
8
7
|
import { StaticComboboxList } from './StaticComboboxList.js';
|
|
9
8
|
import { useCombobox } from './useCombobox.js';
|
|
10
9
|
import { VirtualizedComboboxList } from './VirtualizedComboboxList.js';
|
|
@@ -33,8 +32,10 @@ const Combobox = (props) => {
|
|
|
33
32
|
specialOptions,
|
|
34
33
|
specialOptionsTitle,
|
|
35
34
|
container,
|
|
36
|
-
align
|
|
35
|
+
align,
|
|
36
|
+
onOpenAutoFocus = false
|
|
37
37
|
} = props;
|
|
38
|
+
const searchInputRef = useRef(null);
|
|
38
39
|
const normalizedMaxHeight = typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight;
|
|
39
40
|
const boundedListMaxHeight = `min(${normalizedMaxHeight}, max(120px, calc(var(--radix-popover-content-available-height, 100dvh) - 68px)))`;
|
|
40
41
|
const {
|
|
@@ -54,6 +55,12 @@ const Combobox = (props) => {
|
|
|
54
55
|
handleClear,
|
|
55
56
|
loadNextPage
|
|
56
57
|
} = useCombobox(props);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!open || !onOpenAutoFocus) return;
|
|
60
|
+
const timeoutId = globalThis.setTimeout(() => searchInputRef.current?.focus(), 0);
|
|
61
|
+
return () => globalThis.clearTimeout(timeoutId);
|
|
62
|
+
}, [open, onOpenAutoFocus]);
|
|
63
|
+
const hasMultipleRenderLabel = !!(multiple && "renderLabel" in props && props.renderLabel);
|
|
57
64
|
return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-1", children: [
|
|
58
65
|
/* @__PURE__ */ jsxs(PopoverRoot, { open, onOpenChange: setOpen, modal, children: [
|
|
59
66
|
/* @__PURE__ */ jsx(
|
|
@@ -73,59 +80,21 @@ const Combobox = (props) => {
|
|
|
73
80
|
event.preventDefault();
|
|
74
81
|
event.stopPropagation();
|
|
75
82
|
},
|
|
76
|
-
children: /* @__PURE__ */
|
|
77
|
-
|
|
83
|
+
children: /* @__PURE__ */ jsx(
|
|
84
|
+
ComboboxTrigger,
|
|
78
85
|
{
|
|
79
86
|
id,
|
|
80
|
-
type: "button",
|
|
81
87
|
disabled,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"aria-expanded": open,
|
|
93
|
-
"aria-haspopup": "listbox",
|
|
94
|
-
onMouseEnter: () => setIsHovered(true),
|
|
95
|
-
onMouseLeave: () => setIsHovered(false),
|
|
96
|
-
children: [
|
|
97
|
-
/* @__PURE__ */ jsx(
|
|
98
|
-
"span",
|
|
99
|
-
{
|
|
100
|
-
className: cn(
|
|
101
|
-
"block",
|
|
102
|
-
!hasValue && "text-neutral-300",
|
|
103
|
-
!(multiple && "renderLabel" in props && props.renderLabel) && "truncate"
|
|
104
|
-
),
|
|
105
|
-
children: displayValue
|
|
106
|
-
}
|
|
107
|
-
),
|
|
108
|
-
/* @__PURE__ */ jsx(
|
|
109
|
-
CaretDown,
|
|
110
|
-
{
|
|
111
|
-
className: cn(
|
|
112
|
-
"h-4 w-4 shrink-0 opacity-50 transition-opacity duration-150",
|
|
113
|
-
showClearButton ? "opacity-0" : "opacity-50"
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
),
|
|
117
|
-
onClear && hasValue && /* @__PURE__ */ jsx(
|
|
118
|
-
X,
|
|
119
|
-
{
|
|
120
|
-
"data-testid": "clear-button",
|
|
121
|
-
className: cn(
|
|
122
|
-
"absolute right-4 z-10 h-4 w-4 shrink-0 cursor-pointer transition-opacity duration-150",
|
|
123
|
-
showClearButton ? "opacity-100 hover:opacity-70" : "opacity-0"
|
|
124
|
-
),
|
|
125
|
-
onClick: handleClear
|
|
126
|
-
}
|
|
127
|
-
)
|
|
128
|
-
]
|
|
88
|
+
open,
|
|
89
|
+
error,
|
|
90
|
+
hasValue,
|
|
91
|
+
showClearButton,
|
|
92
|
+
showClearIcon: !!onClear,
|
|
93
|
+
isMultilineLabel: hasMultipleRenderLabel,
|
|
94
|
+
displayValue,
|
|
95
|
+
className,
|
|
96
|
+
onHoverChange: setIsHovered,
|
|
97
|
+
onClear: handleClear
|
|
129
98
|
}
|
|
130
99
|
)
|
|
131
100
|
}
|
|
@@ -137,10 +106,12 @@ const Combobox = (props) => {
|
|
|
137
106
|
container,
|
|
138
107
|
side: "bottom",
|
|
139
108
|
align,
|
|
109
|
+
onOpenAutoFocus: onOpenAutoFocus ? (event) => event.preventDefault() : void 0,
|
|
140
110
|
children: /* @__PURE__ */ jsxs(Command, { shouldFilter: false, children: [
|
|
141
111
|
/* @__PURE__ */ jsx(
|
|
142
112
|
CommandInput,
|
|
143
113
|
{
|
|
114
|
+
ref: searchInputRef,
|
|
144
115
|
placeholder: searchPlaceholder,
|
|
145
116
|
disabled: loading,
|
|
146
117
|
value: searchTerm,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","sources":["../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import { CaretDown } from '@phosphor-icons/react/dist/ssr/CaretDown'\nimport { X } from '@phosphor-icons/react/dist/ssr/X'\n\nimport { cn } from '../../lib/utils'\nimport { Button, buttonVariants } from '../Button'\nimport { Command, CommandInput } from '../Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../Popover'\n\nimport { StaticComboboxList } from './StaticComboboxList'\nimport { useCombobox } from './useCombobox'\nimport { VirtualizedComboboxList } from './VirtualizedComboboxList'\n\ntype ComboboxBaseProps<T> = {\n /** Unique identifier for the combobox */\n id?: string\n /** Array of options to display in the combobox */\n options: Array<T>\n /** Function to get the unique identifier from an option. */\n getOptionValue: (option: T) => string\n /** Function to get the display text from an option. */\n getOptionLabel: (option: T) => string\n /** Custom render function for options. If not provided, defaults to showing a checkmark and label */\n renderOption?: (option: T, isSelected: boolean) => React.ReactNode\n /** Placeholder text shown when no option is selected */\n placeholder?: string\n /** Placeholder text for the search input field */\n searchPlaceholder?: string\n /** Message shown when no options match the search query */\n emptyMessage?: string\n /** Additional CSS classes to apply to the combobox trigger */\n className?: string\n /** Additional CSS classes to apply to the popover content */\n contentClassName?: string\n /** Whether the combobox is disabled */\n disabled?: boolean\n /** Maximum height of the options list. Can be any valid CSS height value */\n maxHeight?: string | number\n /** Whether to close the dropdown when an option is selected. Defaults to `true` for single select and `false` for multi-select. */\n closeOnSelect?: boolean\n /** Whether the combobox is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the combobox has an error */\n error?: boolean | string\n /** Custom function to filter options based on search term */\n filterOptions?: (options: Array<T>, searchTerm: string) => Array<T>\n /** Callback function executed when the clear button is clicked. When provided, an X button will appear on hover to clear the selection. */\n onClear?: boolean | (() => void)\n /** Whether the selection can be cleared */\n clearable?: boolean\n /** Whether the combobox is inside a modal */\n modal?: boolean\n /** Placeholder text for the selected multiple options */\n selectedMultiplePlaceholder?: string\n /** Placeholder text for the multiple options */\n multipleOptionsPlaceholder?: string\n /** Special options that appear at the top with their own title. When selected, the combobox switches to single-select mode. */\n specialOptions?: Array<T>\n /** Title for the special options group */\n specialOptionsTitle?: string\n /** Container element to position the combobox relative to. */\n container?: HTMLElement\n /** Alignment of the dropdown relative to the trigger. Defaults to 'center'. */\n align?: 'start' | 'center' | 'end'\n}\n\nexport type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n /**\n * Async pagination function.\n * Note: Multiple selection is not supported with virtualization.\n */\n fetchPage?: (params: {\n page: number\n search?: string\n }) => Promise<{ items: Array<T>; hasNextPage: boolean; nextPage: number }>\n}\n\nexport type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {\n multiple: true\n value?: Array<string>\n onChange: (value: Array<string>) => void\n /** Custom render function for the selected value(s) display. */\n renderLabel?: (selectedOptions: Array<T>, onRemove: (value: string) => void) => React.ReactNode\n /** fetchPage is not allowed with multiple selection */\n fetchPage?: never\n}\n\nexport type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T>\n\n/**\n * A searchable combobox component with support for custom rendering, keyboard navigation, and search filtering.\n *\n * @example Basic usage\n * ```tsx\n * interface User {\n * id: string\n * name: string\n * email: string\n * }\n *\n * <Combobox<User>\n * options={users}\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * />\n * ```\n *\n * @example Custom filtering\n * ```tsx\n * <Combobox<User>\n * options={users}\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * filterOptions={(options, searchTerm) =>\n * options.filter(user =>\n * user.name.toLowerCase().includes(searchTerm.toLowerCase()) ||\n * user.email.toLowerCase().includes(searchTerm.toLowerCase())\n * )\n * }\n * />\n * ```\n *\n * @example Virtualized infinite scrolling with pagination\n * ```tsx\n * <Combobox<User>\n * options={[]} // Initial options can be empty\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * fetchPage={async ({ page, search }) => {\n * const response = await api.getUsers({ page, search })\n * return {\n * items: response.users,\n * hasNextPage: response.page < response.totalPages,\n * nextPage: page + 1\n * }\n * }}\n * />\n * ```\n */\nexport const Combobox = <T extends object>(props: ComboboxProps<T>) => {\n const {\n id,\n options,\n getOptionValue,\n getOptionLabel,\n searchPlaceholder = 'Search...',\n emptyMessage = 'No results found.',\n className = 'w-60',\n contentClassName,\n disabled = false,\n maxHeight = '300px',\n renderOption,\n loading = false,\n loadingPlaceholder = 'Cargando...',\n error = false,\n multiple,\n onClear,\n modal = false,\n selectedMultiplePlaceholder = 'Selected',\n multipleOptionsPlaceholder = 'Options',\n specialOptions,\n specialOptionsTitle,\n container,\n align,\n } = props\n\n const normalizedMaxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight\n const boundedListMaxHeight = `min(${normalizedMaxHeight}, max(120px, calc(var(--radix-popover-content-available-height, 100dvh) - 68px)))`\n\n const {\n open,\n setOpen,\n searchTerm,\n setSearchTerm,\n setIsHovered,\n hasNextPage,\n loadingMore,\n isVirtualized,\n filteredOptions,\n displayValue,\n hasValue,\n showClearButton,\n handleSelect,\n handleClear,\n loadNextPage,\n } = useCombobox(props)\n\n return (\n <div className=\"flex w-full flex-col gap-1\">\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <PopoverTrigger\n asChild\n onPointerDown={(event) => {\n event.stopPropagation()\n if (open) {\n setOpen(false)\n event.preventDefault()\n } else {\n setOpen(true)\n }\n }}\n onClick={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n >\n <Button\n id={id}\n type=\"button\"\n disabled={disabled}\n variant=\"text\"\n className={cn(\n buttonVariants({ variant: 'input', size: 'lg' }),\n 'relative flex justify-between rounded-lg',\n multiple && 'renderLabel' in props && props.renderLabel ? 'h-auto min-h-12' : 'h-12',\n open && 'border-neutral-950',\n disabled && 'cursor-not-allowed',\n error && 'border-error-400 focus-visible:border-error-700',\n className,\n )}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <span\n className={cn(\n 'block',\n !hasValue && 'text-neutral-300',\n !(multiple && 'renderLabel' in props && props.renderLabel) && 'truncate',\n )}\n >\n {displayValue}\n </span>\n <CaretDown\n className={cn(\n 'h-4 w-4 shrink-0 opacity-50 transition-opacity duration-150',\n showClearButton ? 'opacity-0' : 'opacity-50',\n )}\n />\n {onClear && hasValue && (\n <X\n data-testid=\"clear-button\"\n className={cn(\n 'absolute right-4 z-10 h-4 w-4 shrink-0 cursor-pointer transition-opacity duration-150',\n showClearButton ? 'opacity-100 hover:opacity-70' : 'opacity-0',\n )}\n onClick={handleClear}\n />\n )}\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className={cn('overflow-hidden p-0', contentClassName)}\n container={container}\n side=\"bottom\"\n align={align}\n >\n <Command shouldFilter={false}>\n <CommandInput\n placeholder={searchPlaceholder}\n disabled={loading}\n value={searchTerm}\n onValueChange={setSearchTerm}\n />\n {isVirtualized ? (\n <VirtualizedComboboxList\n localOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n value={props.value as string}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n hasNextPage={hasNextPage}\n loadingMore={loadingMore}\n onLoadMore={loadNextPage}\n />\n ) : (\n <StaticComboboxList\n filteredOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n multiple={!!multiple}\n value={props.value}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n selectedMultiplePlaceholder={selectedMultiplePlaceholder}\n multipleOptionsPlaceholder={multipleOptionsPlaceholder}\n options={options}\n specialOptions={specialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n )}\n </Command>\n </PopoverContent>\n </PopoverRoot>\n {typeof error === 'string' && <span className=\"text-error-500 text-sm\">{error}</span>}\n </div>\n )\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAuJO,MAAM,QAAA,GAAW,CAAmB,KAAA,KAA4B;AACrE,EAAA,MAAM;AAAA,IACJ,EAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,iBAAA,GAAoB,WAAA;AAAA,IACpB,YAAA,GAAe,mBAAA;AAAA,IACf,SAAA,GAAY,MAAA;AAAA,IACZ,gBAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,SAAA,GAAY,OAAA;AAAA,IACZ,YAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,kBAAA,GAAqB,aAAA;AAAA,IACrB,KAAA,GAAQ,KAAA;AAAA,IACR,QAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA,GAAQ,KAAA;AAAA,IACR,2BAAA,GAA8B,UAAA;AAAA,IAC9B,0BAAA,GAA6B,SAAA;AAAA,IAC7B,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AAEJ,EAAA,MAAM,sBAAsB,OAAO,SAAA,KAAc,QAAA,GAAW,CAAA,EAAG,SAAS,CAAA,EAAA,CAAA,GAAO,SAAA;AAC/E,EAAA,MAAM,oBAAA,GAAuB,OAAO,mBAAmB,CAAA,iFAAA,CAAA;AAEvD,EAAA,MAAM;AAAA,IACJ,IAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,YAAA;AAAA,IACA,QAAA;AAAA,IACA,eAAA;AA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AA;AAAA,gBACb,QAAA,EAAU,OAAA;AAAA,gBACV,KAAA,EAAO,UAAA;AAAA,gBACP,aAAA,EAAe;AAAA;AAAA,aACjB;AAAA,YACC,aAAA,mBACC,GAAA;AAAA,cAAC,uBAAA;AAAA,cAAA;AAAA,gBACC,YAAA,EAAc,eAAA;AAAA,gBACd,OAAA;AAAA,gBACA,kBAAA;AAAA,gBACA,YAAA;AAAA,gBACA,OAAO,KAAA,CAAM,KAAA;AAAA,gBACb,cAAA;AAAA,gBACA,cAAA;AAAA,gBACA,YAAA;AAAA,gBACA,YAAA;AAAA,gBACA,SAAA,EAAW,oBAAA;AAAA,gBACX,WAAA;AAAA,gBACA,WAAA;AAAA,gBACA,UAAA,EAAY;AAAA;AAAA,aACd,mBAEA,GAAA;AAAA,cAAC,kBAAA;AAAA,cAAA;AAAA,gBACC,eAAA;AAAA,gBACA,OAAA;AAAA,gBACA,kBAAA;AAAA,gBACA,YAAA;AAAA,gBACA,QAAA,EAAU,CAAC,CAAC,QAAA;AAAA,gBACZ,OAAO,KAAA,CAAM,KAAA;AAAA,gBACb,cAAA;AAAA,gBACA,cAAA;AAAA,gBACA,YAAA;AAAA,gBACA,YAAA;AAAA,gBACA,SAAA,EAAW,oBAAA;AAAA,gBACX,2BAAA;AAAA,gBACA,0BAAA;AAAA,gBACA,OAAA;AAAA,gBACA,cAAA;AAAA,gBACA;AAAA;AAAA;AACF,WAAA,EAEJ;AAAA;AAAA;AACF,KAAA,EACF,CAAA;AAAA,IACC,OAAO,KAAA,KAAU,QAAA,wBAAa,MAAA,EAAA,EAAK,SAAA,EAAU,0BAA0B,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EAChF,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nimport { cn } from '../../lib/utils'\nimport { Command, CommandInput } from '../Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../Popover'\n\nimport { ComboboxTrigger } from './ComboboxTrigger'\nimport { StaticComboboxList } from './StaticComboboxList'\nimport { useCombobox } from './useCombobox'\nimport { VirtualizedComboboxList } from './VirtualizedComboboxList'\n\ntype ComboboxBaseProps<T> = {\n /** Unique identifier for the combobox */\n id?: string\n /** Array of options to display in the combobox */\n options: Array<T>\n /** Function to get the unique identifier from an option. */\n getOptionValue: (option: T) => string\n /** Function to get the display text from an option. */\n getOptionLabel: (option: T) => string\n /** Custom render function for options. If not provided, defaults to showing a checkmark and label */\n renderOption?: (option: T, isSelected: boolean) => React.ReactNode\n /** Placeholder text shown when no option is selected */\n placeholder?: string\n /** Placeholder text for the search input field */\n searchPlaceholder?: string\n /** Message shown when no options match the search query */\n emptyMessage?: string\n /** Additional CSS classes to apply to the combobox trigger */\n className?: string\n /** Additional CSS classes to apply to the popover content */\n contentClassName?: string\n /** Whether the combobox is disabled */\n disabled?: boolean\n /** Maximum height of the options list. Can be any valid CSS height value */\n maxHeight?: string | number\n /** Whether to close the dropdown when an option is selected. Defaults to `true` for single select and `false` for multi-select. */\n closeOnSelect?: boolean\n /** Whether the combobox is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the combobox has an error */\n error?: boolean | string\n /** Custom function to filter options based on search term */\n filterOptions?: (options: Array<T>, searchTerm: string) => Array<T>\n /** Callback function executed when the clear button is clicked. When provided, an X button will appear on hover to clear the selection. */\n onClear?: boolean | (() => void)\n /** Whether the selection can be cleared */\n clearable?: boolean\n /** Whether the combobox is inside a modal */\n modal?: boolean\n /** Placeholder text for the selected multiple options */\n selectedMultiplePlaceholder?: string\n /** Placeholder text for the multiple options */\n multipleOptionsPlaceholder?: string\n /** Special options that appear at the top with their own title. When selected, the combobox switches to single-select mode. */\n specialOptions?: Array<T>\n /** Title for the special options group */\n specialOptionsTitle?: string\n /** Container element to position the combobox relative to. */\n container?: HTMLElement\n /** Alignment of the dropdown relative to the trigger. Defaults to 'center'. */\n align?: 'start' | 'center' | 'end'\n /** Auto-focus the search input when the dropdown opens. */\n onOpenAutoFocus?: boolean\n}\n\nexport type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n /**\n * Async pagination function.\n * Note: Multiple selection is not supported with virtualization.\n */\n fetchPage?: (params: {\n page: number\n search?: string\n }) => Promise<{ items: Array<T>; hasNextPage: boolean; nextPage: number }>\n /** Prefetch the first page on mount (virtualized only), so data is ready before opening. */\n prefetch?: boolean\n}\n\nexport type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {\n multiple: true\n value?: Array<string>\n onChange: (value: Array<string>) => void\n /** Custom render function for the selected value(s) display. */\n renderLabel?: (selectedOptions: Array<T>, onRemove: (value: string) => void) => React.ReactNode\n /** fetchPage is not allowed with multiple selection */\n fetchPage?: never\n /** prefetch is not allowed with multiple selection */\n prefetch?: never\n}\n\nexport type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T>\n\n/**\n * A searchable combobox component with support for custom rendering, keyboard navigation, and search filtering.\n *\n * @example Basic usage\n * ```tsx\n * <Combobox<User>\n * options={users}\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * />\n * ```\n */\nexport const Combobox = <T extends object>(props: ComboboxProps<T>) => {\n const {\n id,\n options,\n getOptionValue,\n getOptionLabel,\n searchPlaceholder = 'Search...',\n emptyMessage = 'No results found.',\n className = 'w-60',\n contentClassName,\n disabled = false,\n maxHeight = '300px',\n renderOption,\n loading = false,\n loadingPlaceholder = 'Cargando...',\n error = false,\n multiple,\n onClear,\n modal = false,\n selectedMultiplePlaceholder = 'Selected',\n multipleOptionsPlaceholder = 'Options',\n specialOptions,\n specialOptionsTitle,\n container,\n align,\n onOpenAutoFocus = false,\n } = props\n\n const searchInputRef = useRef<HTMLInputElement>(null)\n\n const normalizedMaxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight\n const boundedListMaxHeight = `min(${normalizedMaxHeight}, max(120px, calc(var(--radix-popover-content-available-height, 100dvh) - 68px)))`\n\n const {\n open,\n setOpen,\n searchTerm,\n setSearchTerm,\n setIsHovered,\n hasNextPage,\n loadingMore,\n isVirtualized,\n filteredOptions,\n displayValue,\n hasValue,\n showClearButton,\n handleSelect,\n handleClear,\n loadNextPage,\n } = useCombobox(props)\n\n useEffect(() => {\n if (!open || !onOpenAutoFocus) return\n const timeoutId = globalThis.setTimeout(() => searchInputRef.current?.focus(), 0)\n return () => globalThis.clearTimeout(timeoutId)\n }, [open, onOpenAutoFocus])\n\n const hasMultipleRenderLabel = !!(multiple && 'renderLabel' in props && props.renderLabel)\n\n return (\n <div className=\"flex w-full flex-col gap-1\">\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <PopoverTrigger\n asChild\n onPointerDown={(event) => {\n event.stopPropagation()\n if (open) {\n setOpen(false)\n event.preventDefault()\n } else {\n setOpen(true)\n }\n }}\n onClick={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n >\n <ComboboxTrigger\n id={id}\n disabled={disabled}\n open={open}\n error={error}\n hasValue={hasValue}\n showClearButton={showClearButton}\n showClearIcon={!!onClear}\n isMultilineLabel={hasMultipleRenderLabel}\n displayValue={displayValue}\n className={className}\n onHoverChange={setIsHovered}\n onClear={handleClear}\n />\n </PopoverTrigger>\n <PopoverContent\n className={cn('overflow-hidden p-0', contentClassName)}\n container={container}\n side=\"bottom\"\n align={align}\n onOpenAutoFocus={onOpenAutoFocus ? (event) => event.preventDefault() : undefined}\n >\n <Command shouldFilter={false}>\n <CommandInput\n ref={searchInputRef}\n placeholder={searchPlaceholder}\n disabled={loading}\n value={searchTerm}\n onValueChange={setSearchTerm}\n />\n {isVirtualized ? (\n <VirtualizedComboboxList\n localOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n value={props.value as string}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n hasNextPage={hasNextPage}\n loadingMore={loadingMore}\n onLoadMore={loadNextPage}\n />\n ) : (\n <StaticComboboxList\n filteredOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n multiple={!!multiple}\n value={props.value}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n selectedMultiplePlaceholder={selectedMultiplePlaceholder}\n multipleOptionsPlaceholder={multipleOptionsPlaceholder}\n options={options}\n specialOptions={specialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n )}\n </Command>\n </PopoverContent>\n </PopoverRoot>\n {typeof error === 'string' && <span className=\"text-error-500 text-sm\">{error}</span>}\n </div>\n )\n}\n"],"names":[],"mappings":";;;;;;;;;;AAkHO,MAAM,QAAA,GAAW,CAAmB,KAAA,KAA4B;AACrE,EAAA,MAAM;AAAA,IACJ,EAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,iBAAA,GAAoB,WAAA;AAAA,IACpB,YAAA,GAAe,mBAAA;AAAA,IACf,SAAA,GAAY,MAAA;AAAA,IACZ,gBAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,SAAA,GAAY,OAAA;AAAA,IACZ,YAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,kBAAA,GAAqB,aAAA;AAAA,IACrB,KAAA,GAAQ,KAAA;AAAA,IACR,QAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA,GAAQ,KAAA;AAAA,IACR,2BAAA,GAA8B,UAAA;AAAA,IAC9B,0BAAA,GAA6B,SAAA;AAAA,IAC7B,cAAA;AAAA,IACA,mBAAA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gBACL,WAAA,EAAa,iBAAA;AAAA,gBACb,QAAA,EAAU,OAAA;AAAA,gBACV,KAAA,EAAO,UAAA;AAAA,gBACP,aAAA,EAAe;AAAA;AAAA,aACjB;AAAA,YACC,aAAA,mBACC,GAAA;AAAA,cAAC,uBAAA;AAAA,cAAA;AAAA,gBACC,YAAA,EAAc,eAAA;AAAA,gBACd,OAAA;AAAA,gBACA,kBAAA;AAAA,gBACA,YAAA;AAAA,gBACA,OAAO,KAAA,CAAM,KAAA;AAAA,gBACb,cAAA;AAAA,gBACA,cAAA;AAAA,gBACA,YAAA;AAAA,gBACA,YAAA;AAAA,gBACA,SAAA,EAAW,oBAAA;AAAA,gBACX,WAAA;AAAA,gBACA,WAAA;AAAA,gBACA,UAAA,EAAY;AAAA;AAAA,aACd,mBAEA,GAAA;AAAA,cAAC,kBAAA;AAAA,cAAA;AAAA,gBACC,eAAA;AAAA,gBACA,OAAA;AAAA,gBACA,kBAAA;AAAA,gBACA,YAAA;AAAA,gBACA,QAAA,EAAU,CAAC,CAAC,QAAA;AAAA,gBACZ,OAAO,KAAA,CAAM,KAAA;AAAA,gBACb,cAAA;AAAA,gBACA,cAAA;AAAA,gBACA,YAAA;AAAA,gBACA,YAAA;AAAA,gBACA,SAAA,EAAW,oBAAA;AAAA,gBACX,2BAAA;AAAA,gBACA,0BAAA;AAAA,gBACA,OAAA;AAAA,gBACA,cAAA;AAAA,gBACA;AAAA;AAAA;AACF,WAAA,EAEJ;AAAA;AAAA;AACF,KAAA,EACF,CAAA;AAAA,IACC,OAAO,KAAA,KAAU,QAAA,wBAAa,MAAA,EAAA,EAAK,SAAA,EAAU,0BAA0B,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EAChF,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ComboboxTrigger: import('react').ForwardRefExoticComponent<Readonly<{
|
|
2
|
+
id?: string;
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
open: boolean;
|
|
5
|
+
error?: boolean | string;
|
|
6
|
+
hasValue: boolean;
|
|
7
|
+
showClearButton: unknown;
|
|
8
|
+
showClearIcon: boolean;
|
|
9
|
+
isMultilineLabel: boolean;
|
|
10
|
+
displayValue: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
onHoverChange: (hovered: boolean) => void;
|
|
13
|
+
onClear: (event: React.MouseEvent) => void;
|
|
14
|
+
}> & import('react').RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { CaretDown } from '@phosphor-icons/react/dist/ssr/CaretDown';
|
|
3
|
+
import { X } from '@phosphor-icons/react/dist/ssr/X';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import { cn } from '../../lib/utils.js';
|
|
6
|
+
import { Button, buttonVariants } from '../Button/Button.js';
|
|
7
|
+
|
|
8
|
+
const ComboboxTrigger = forwardRef(
|
|
9
|
+
({
|
|
10
|
+
id,
|
|
11
|
+
disabled,
|
|
12
|
+
open,
|
|
13
|
+
error,
|
|
14
|
+
hasValue,
|
|
15
|
+
showClearButton,
|
|
16
|
+
showClearIcon,
|
|
17
|
+
isMultilineLabel,
|
|
18
|
+
displayValue,
|
|
19
|
+
className,
|
|
20
|
+
onHoverChange,
|
|
21
|
+
onClear,
|
|
22
|
+
...rest
|
|
23
|
+
}, ref) => /* @__PURE__ */ jsxs(
|
|
24
|
+
Button,
|
|
25
|
+
{
|
|
26
|
+
ref,
|
|
27
|
+
id,
|
|
28
|
+
type: "button",
|
|
29
|
+
disabled,
|
|
30
|
+
variant: "text",
|
|
31
|
+
className: cn(
|
|
32
|
+
buttonVariants({ variant: "input", size: "lg" }),
|
|
33
|
+
"relative flex justify-between rounded-lg",
|
|
34
|
+
isMultilineLabel ? "h-auto min-h-12" : "h-12",
|
|
35
|
+
open && "border-neutral-950",
|
|
36
|
+
disabled && "cursor-not-allowed",
|
|
37
|
+
error && "border-error-400 focus-visible:border-error-700",
|
|
38
|
+
className
|
|
39
|
+
),
|
|
40
|
+
"aria-expanded": open,
|
|
41
|
+
"aria-haspopup": "listbox",
|
|
42
|
+
onMouseEnter: () => onHoverChange(true),
|
|
43
|
+
onMouseLeave: () => onHoverChange(false),
|
|
44
|
+
...rest,
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx("span", { className: cn("block", !hasValue && "text-neutral-300", !isMultilineLabel && "truncate"), children: displayValue }),
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
48
|
+
CaretDown,
|
|
49
|
+
{
|
|
50
|
+
className: cn(
|
|
51
|
+
"h-4 w-4 shrink-0 opacity-50 transition-opacity duration-150",
|
|
52
|
+
showClearButton ? "opacity-0" : "opacity-50"
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
showClearIcon && hasValue && /* @__PURE__ */ jsx(
|
|
57
|
+
X,
|
|
58
|
+
{
|
|
59
|
+
"data-testid": "clear-button",
|
|
60
|
+
className: cn(
|
|
61
|
+
"absolute right-4 z-10 h-4 w-4 shrink-0 cursor-pointer transition-opacity duration-150",
|
|
62
|
+
showClearButton ? "opacity-100 hover:opacity-70" : "opacity-0"
|
|
63
|
+
),
|
|
64
|
+
onClick: onClear
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
ComboboxTrigger.displayName = "ComboboxTrigger";
|
|
72
|
+
|
|
73
|
+
export { ComboboxTrigger };
|
|
74
|
+
//# sourceMappingURL=ComboboxTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComboboxTrigger.js","sources":["../../../src/components/Combobox/ComboboxTrigger.tsx"],"sourcesContent":["import { CaretDown } from '@phosphor-icons/react/dist/ssr/CaretDown'\nimport { X } from '@phosphor-icons/react/dist/ssr/X'\nimport { forwardRef } from 'react'\n\nimport { cn } from '../../lib/utils'\nimport { Button, buttonVariants } from '../Button'\n\ntype ComboboxTriggerProps = Readonly<{\n id?: string\n disabled?: boolean\n open: boolean\n error?: boolean | string\n hasValue: boolean\n showClearButton: unknown\n showClearIcon: boolean\n isMultilineLabel: boolean\n displayValue: React.ReactNode\n className?: string\n onHoverChange: (hovered: boolean) => void\n onClear: (event: React.MouseEvent) => void\n}>\n\nexport const ComboboxTrigger = forwardRef<HTMLButtonElement, ComboboxTriggerProps>(\n (\n {\n id,\n disabled,\n open,\n error,\n hasValue,\n showClearButton,\n showClearIcon,\n isMultilineLabel,\n displayValue,\n className,\n onHoverChange,\n onClear,\n ...rest\n },\n ref,\n ) => (\n <Button\n ref={ref}\n id={id}\n type=\"button\"\n disabled={disabled}\n variant=\"text\"\n className={cn(\n buttonVariants({ variant: 'input', size: 'lg' }),\n 'relative flex justify-between rounded-lg',\n isMultilineLabel ? 'h-auto min-h-12' : 'h-12',\n open && 'border-neutral-950',\n disabled && 'cursor-not-allowed',\n error && 'border-error-400 focus-visible:border-error-700',\n className,\n )}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n onMouseEnter={() => onHoverChange(true)}\n onMouseLeave={() => onHoverChange(false)}\n {...rest}\n >\n <span className={cn('block', !hasValue && 'text-neutral-300', !isMultilineLabel && 'truncate')}>\n {displayValue}\n </span>\n <CaretDown\n className={cn(\n 'h-4 w-4 shrink-0 opacity-50 transition-opacity duration-150',\n showClearButton ? 'opacity-0' : 'opacity-50',\n )}\n />\n {showClearIcon && hasValue && (\n <X\n data-testid=\"clear-button\"\n className={cn(\n 'absolute right-4 z-10 h-4 w-4 shrink-0 cursor-pointer transition-opacity duration-150',\n showClearButton ? 'opacity-100 hover:opacity-70' : 'opacity-0',\n )}\n onClick={onClear}\n />\n )}\n </Button>\n ),\n)\n\nComboboxTrigger.displayName = 'ComboboxTrigger'\n"],"names":[],"mappings":";;;;;;;AAsBO,MAAM,eAAA,GAAkB,UAAA;AAAA,EAC7B,CACE;AAA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oBAChB,GAAA;AAAA,UAAC,CAAA;AAAA,UAAA;AAAA,YACC,aAAA,EAAY,cAAA;AAAA,YACZ,SAAA,EAAW,EAAA;AAAA,cACT,uFAAA;AAAA,cACA,kBAAkB,8BAAA,GAAiC;AAAA,aACrD;AAAA,YACA,OAAA,EAAS;AAAA;AAAA;AACX;AAAA;AAAA;AAIR;AAEA,eAAA,CAAgB,WAAA,GAAc,iBAAA;;;;"}
|
|
@@ -64,7 +64,7 @@ const StaticComboboxList = ({
|
|
|
64
64
|
/* @__PURE__ */ jsx(CommandSeparator, { className: "!mx-[10px]" })
|
|
65
65
|
] }) : null,
|
|
66
66
|
!specialOptions && multiple && isArrayValue && regularSelectedOptions.length > 0 && /* @__PURE__ */ jsx(CommandGroup, { heading: selectedMultiplePlaceholder, children: regularSelectedOptions.map(renderListOption) }),
|
|
67
|
-
/* @__PURE__ */ jsx(CommandGroup, { heading: groupHeading, children: optionsToShow.map(renderListOption) })
|
|
67
|
+
optionsToShow.length > 0 && /* @__PURE__ */ jsx(CommandGroup, { heading: groupHeading, children: optionsToShow.map(renderListOption) })
|
|
68
68
|
] })
|
|
69
69
|
}
|
|
70
70
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticComboboxList.js","sources":["../../../src/components/Combobox/StaticComboboxList.tsx"],"sourcesContent":["import { CheckSquare } from '@phosphor-icons/react/dist/ssr/CheckSquare'\nimport { Square } from '@phosphor-icons/react/dist/ssr/Square'\nimport { useMemo } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { StaticComboboxListProps } from './types'\n\nexport const StaticComboboxList = <T extends object>({\n filteredOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n multiple,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n selectedMultiplePlaceholder,\n multipleOptionsPlaceholder,\n options,\n specialOptions,\n specialOptionsTitle,\n}: StaticComboboxListProps<T>) => {\n const isArrayValue = Array.isArray(value)\n const selectedValues = useMemo(() => (multiple && isArrayValue ? value : []), [multiple, isArrayValue, value])\n\n const isOptionSelected = (optionValue: string) =>\n multiple ? selectedValues.includes(optionValue) : value === optionValue\n\n const regularOptions = useMemo(() => {\n return filteredOptions.filter(\n (option) => !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [filteredOptions, specialOptions, getOptionValue])\n\n const regularSelectedOptions = useMemo(() => {\n if (!multiple || !isArrayValue) return []\n\n return options.filter(\n (option) =>\n selectedValues.includes(getOptionValue(option)) &&\n !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [options, selectedValues, specialOptions, getOptionValue, multiple, isArrayValue])\n\n const optionsToShow = useMemo(() => {\n if (specialOptions) return regularOptions\n\n if (!multiple || !isArrayValue) return regularOptions\n\n return regularOptions.filter((option) => !selectedValues.includes(getOptionValue(option)))\n }, [regularOptions, specialOptions, selectedValues, getOptionValue, multiple, isArrayValue])\n\n const groupHeading = !specialOptions && multiple ? multipleOptionsPlaceholder : undefined\n\n const renderListOption = (option: T) => {\n const optionValue = getOptionValue(option)\n const selected = isOptionSelected(optionValue)\n\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, selected)\n ) : (\n <>\n {selected ? <CheckSquare className=\"mr-2 !h-6 !w-6\" /> : <Square className=\"mr-2 !h-6 !w-6\" />}\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n )\n }\n\n return (\n <CommandList\n style={{ maxHeight }}\n className=\"overflow-auto overscroll-contain\"\n onWheel={(event) => event.stopPropagation()}\n >\n {loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">{loadingPlaceholder}</div>\n ) : (\n <>\n {filteredOptions.length === 0 &&\n regularOptions.length === 0 &&\n (!specialOptions || specialOptions.length === 0) && <CommandEmpty>{emptyMessage}</CommandEmpty>}\n\n {specialOptions?.length && specialOptionsTitle ? (\n <>\n <CommandGroup heading={specialOptionsTitle}>{specialOptions.map(renderListOption)}</CommandGroup>\n\n <CommandSeparator className=\"!mx-[10px]\" />\n </>\n ) : null}\n\n {!specialOptions && multiple && isArrayValue && regularSelectedOptions.length > 0 && (\n <CommandGroup heading={selectedMultiplePlaceholder}>\n {regularSelectedOptions.map(renderListOption)}\n </CommandGroup>\n )}\n\n <CommandGroup heading={groupHeading}>{optionsToShow.map(renderListOption)}</CommandGroup>\n </>\n )}\n </CommandList>\n )\n}\n"],"names":[],"mappings":";;;;;;;AASO,MAAM,qBAAqB,CAAmB;AAAA,EACnD,eAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,2BAAA;AAAA,EACA,0BAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAA,KAAkC;AAChC,EAAA,MAAM,YAAA,GAAe,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AACxC,EAAA,MAAM,cAAA,GAAiB,OAAA,CAAQ,MAAO,QAAA,IAAY,YAAA,GAAe,KAAA,GAAQ,EAAC,EAAI,CAAC,QAAA,EAAU,YAAA,EAAc,KAAK,CAAC,CAAA;AAE7G,EAAA,MAAM,gBAAA,GAAmB,CAAC,WAAA,KACxB,QAAA,GAAW,eAAe,QAAA,CAAS,WAAW,IAAI,KAAA,KAAU,WAAA;AAE9D,EAAA,MAAM,cAAA,GAAiB,QAAQ,MAAM;AACnC,IAAA,OAAO,eAAA,CAAgB,MAAA;AAAA,MACrB,CAAC,MAAA,KAAW,CAAC,cAAA,EAAgB,IAAA,CAAK,CAAC,OAAA,KAAY,cAAA,CAAe,OAAO,CAAA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AAA,EAAA,EAAiB,SAAA,EAAU,YAAA,EAAa;AAAA,SAAA,EAC3C,CAAA,GACE,IAAA;AAAA,QAEH,CAAC,cAAA,IAAkB,QAAA,IAAY,YAAA,IAAgB,uBAAuB,MAAA,GAAS,CAAA,oBAC9E,GAAA,CAAC,YAAA,EAAA,EAAa,OAAA,EAAS,2BAAA,EACpB,QAAA,EAAA,sBAAA,CAAuB,GAAA,CAAI,gBAAgB,CAAA,EAC9C,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"StaticComboboxList.js","sources":["../../../src/components/Combobox/StaticComboboxList.tsx"],"sourcesContent":["import { CheckSquare } from '@phosphor-icons/react/dist/ssr/CheckSquare'\nimport { Square } from '@phosphor-icons/react/dist/ssr/Square'\nimport { useMemo } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { StaticComboboxListProps } from './types'\n\nexport const StaticComboboxList = <T extends object>({\n filteredOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n multiple,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n selectedMultiplePlaceholder,\n multipleOptionsPlaceholder,\n options,\n specialOptions,\n specialOptionsTitle,\n}: StaticComboboxListProps<T>) => {\n const isArrayValue = Array.isArray(value)\n const selectedValues = useMemo(() => (multiple && isArrayValue ? value : []), [multiple, isArrayValue, value])\n\n const isOptionSelected = (optionValue: string) =>\n multiple ? selectedValues.includes(optionValue) : value === optionValue\n\n const regularOptions = useMemo(() => {\n return filteredOptions.filter(\n (option) => !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [filteredOptions, specialOptions, getOptionValue])\n\n const regularSelectedOptions = useMemo(() => {\n if (!multiple || !isArrayValue) return []\n\n return options.filter(\n (option) =>\n selectedValues.includes(getOptionValue(option)) &&\n !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [options, selectedValues, specialOptions, getOptionValue, multiple, isArrayValue])\n\n const optionsToShow = useMemo(() => {\n if (specialOptions) return regularOptions\n\n if (!multiple || !isArrayValue) return regularOptions\n\n return regularOptions.filter((option) => !selectedValues.includes(getOptionValue(option)))\n }, [regularOptions, specialOptions, selectedValues, getOptionValue, multiple, isArrayValue])\n\n const groupHeading = !specialOptions && multiple ? multipleOptionsPlaceholder : undefined\n\n const renderListOption = (option: T) => {\n const optionValue = getOptionValue(option)\n const selected = isOptionSelected(optionValue)\n\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, selected)\n ) : (\n <>\n {selected ? <CheckSquare className=\"mr-2 !h-6 !w-6\" /> : <Square className=\"mr-2 !h-6 !w-6\" />}\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n )\n }\n\n return (\n <CommandList\n style={{ maxHeight }}\n className=\"overflow-auto overscroll-contain\"\n onWheel={(event) => event.stopPropagation()}\n >\n {loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">{loadingPlaceholder}</div>\n ) : (\n <>\n {filteredOptions.length === 0 &&\n regularOptions.length === 0 &&\n (!specialOptions || specialOptions.length === 0) && <CommandEmpty>{emptyMessage}</CommandEmpty>}\n\n {specialOptions?.length && specialOptionsTitle ? (\n <>\n <CommandGroup heading={specialOptionsTitle}>{specialOptions.map(renderListOption)}</CommandGroup>\n\n <CommandSeparator className=\"!mx-[10px]\" />\n </>\n ) : null}\n\n {!specialOptions && multiple && isArrayValue && regularSelectedOptions.length > 0 && (\n <CommandGroup heading={selectedMultiplePlaceholder}>\n {regularSelectedOptions.map(renderListOption)}\n </CommandGroup>\n )}\n\n {optionsToShow.length > 0 && (\n <CommandGroup heading={groupHeading}>{optionsToShow.map(renderListOption)}</CommandGroup>\n )}\n </>\n )}\n </CommandList>\n )\n}\n"],"names":[],"mappings":";;;;;;;AASO,MAAM,qBAAq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,gBAAgB,CAAA,EAAE;AAAA,OAAA,EAE9E;AAAA;AAAA,GAEJ;AAEJ;;;;"}
|
|
@@ -32,7 +32,7 @@ const VirtualizedComboboxList = ({
|
|
|
32
32
|
});
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
hasTriggeredRef.current = false;
|
|
35
|
-
}, [totalCount]);
|
|
35
|
+
}, [totalCount, loadingMore]);
|
|
36
36
|
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
37
37
|
useEffect(() => {
|
|
38
38
|
if (virtualItems.length === 0 || !hasNextPage || loadingMore || loading || hasTriggeredRef.current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedComboboxList.js","sources":["../../../src/components/Combobox/VirtualizedComboboxList.tsx"],"sourcesContent":["import { Check } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport { useRef, useEffect } from 'react'\n\nimport { CommandEmpty, CommandItem } from '../Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { VirtualizedComboboxListProps } from './types'\n\nexport const VirtualizedComboboxList = <T extends object>({\n localOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n hasNextPage,\n loadingMore,\n onLoadMore,\n}: VirtualizedComboboxListProps<T>) => {\n const parentRef = useRef<HTMLDivElement>(null)\n const hasTriggeredRef = useRef(false)\n\n const totalCount = localOptions.length\n const PREFETCH_THRESHOLD = 25\n\n const rowVirtualizer = useVirtualizer({\n count: totalCount,\n getScrollElement: () => parentRef.current,\n estimateSize: () => 40,\n overscan: 10,\n })\n\n useEffect(() => {\n hasTriggeredRef.current = false\n }, [totalCount])\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n\n useEffect(() => {\n if (virtualItems.length === 0 || !hasNextPage || loadingMore || loading || hasTriggeredRef.current) {\n return\n }\n\n const lastVisibleItem = virtualItems.at(-1)\n const itemsFromEnd = totalCount - (lastVisibleItem?.index ?? 0)\n\n if (itemsFromEnd <= PREFETCH_THRESHOLD) {\n hasTriggeredRef.current = true\n onLoadMore()\n }\n }, [virtualItems, totalCount, hasNextPage, loadingMore, loading, onLoadMore])\n\n if (loading && localOptions.length === 0) {\n return (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">{loadingPlaceholder}</div>\n )\n }\n\n if (localOptions.length === 0 && !loading && !loadingMore) {\n return <CommandEmpty>{emptyMessage}</CommandEmpty>\n }\n\n const getItemAtIndex = (index: number) => {\n const option = localOptions[index]\n const isSelected = value === getOptionValue(option)\n return { option, isSelected }\n }\n\n return (\n <div\n ref={parentRef}\n className=\"overflow-auto overscroll-contain\"\n style={{ maxHeight }}\n onWheel={(event) => event.stopPropagation()}\n >\n <div style={{ height: `${rowVirtualizer.getTotalSize()}px`, position: 'relative' }}>\n {rowVirtualizer.getVirtualItems().map((virtualRow) => {\n const { option, isSelected } = getItemAtIndex(virtualRow.index)\n const optionValue = getOptionValue(option)\n\n return (\n <div\n key={optionValue}\n data-index={virtualRow.index}\n ref={(el) => {\n if (el) rowVirtualizer.measureElement(el)\n }}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n <CommandItem value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, isSelected)\n ) : (\n <>\n <Check className={`mr-2 h-4 w-4 ${isSelected ? 'opacity-100' : 'opacity-0'}`} />\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n </div>\n )\n })}\n </div>\n {loadingMore && (\n <div className=\"flex items-center justify-center py-2 text-sm text-neutral-500\">{loadingPlaceholder}</div>\n )}\n </div>\n )\n}\n"],"names":[],"mappings":";;;;;;;AASO,MAAM,0BAA0B,CAAmB;AAAA,EACxD,YAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA,KAAuC;AACrC,EAAA,MAAM,SAAA,GAAY,OAAuB,IAAI,CAAA;AAC7C,EAAA,MAAM,eAAA,GAAkB,OAAO,KAAK,CAAA;AAEpC,EAAA,MAAM,aAAa,YAAA,CAAa,MAAA;AAChC,EAAA,MAAM,kBAAA,GAAqB,EAAA;AAE3B,EAAA,MAAM,iBAAiB,cAAA,CAAe;AAAA,IACpC,KAAA,EAAO,UAAA;AAAA,IACP,gBAAA,EAAkB,MAAM,SAAA,CAAU,OAAA;AAAA,IAClC,cAAc,MAAM,EAAA;AAAA,IACpB,QAAA,EAAU;AAAA,GACX,CAAA;AAED,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,eAAA,CAAgB,OAAA,GAAU,KAAA;AAAA,EAC5B,CAAA,EAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"VirtualizedComboboxList.js","sources":["../../../src/components/Combobox/VirtualizedComboboxList.tsx"],"sourcesContent":["import { Check } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport { useRef, useEffect } from 'react'\n\nimport { CommandEmpty, CommandItem } from '../Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { VirtualizedComboboxListProps } from './types'\n\nexport const VirtualizedComboboxList = <T extends object>({\n localOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n hasNextPage,\n loadingMore,\n onLoadMore,\n}: VirtualizedComboboxListProps<T>) => {\n const parentRef = useRef<HTMLDivElement>(null)\n const hasTriggeredRef = useRef(false)\n\n const totalCount = localOptions.length\n const PREFETCH_THRESHOLD = 25\n\n const rowVirtualizer = useVirtualizer({\n count: totalCount,\n getScrollElement: () => parentRef.current,\n estimateSize: () => 40,\n overscan: 10,\n })\n\n useEffect(() => {\n hasTriggeredRef.current = false\n }, [totalCount, loadingMore])\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n\n useEffect(() => {\n if (virtualItems.length === 0 || !hasNextPage || loadingMore || loading || hasTriggeredRef.current) {\n return\n }\n\n const lastVisibleItem = virtualItems.at(-1)\n const itemsFromEnd = totalCount - (lastVisibleItem?.index ?? 0)\n\n if (itemsFromEnd <= PREFETCH_THRESHOLD) {\n hasTriggeredRef.current = true\n onLoadMore()\n }\n }, [virtualItems, totalCount, hasNextPage, loadingMore, loading, onLoadMore])\n\n if (loading && localOptions.length === 0) {\n return (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">{loadingPlaceholder}</div>\n )\n }\n\n if (localOptions.length === 0 && !loading && !loadingMore) {\n return <CommandEmpty>{emptyMessage}</CommandEmpty>\n }\n\n const getItemAtIndex = (index: number) => {\n const option = localOptions[index]\n const isSelected = value === getOptionValue(option)\n return { option, isSelected }\n }\n\n return (\n <div\n ref={parentRef}\n className=\"overflow-auto overscroll-contain\"\n style={{ maxHeight }}\n onWheel={(event) => event.stopPropagation()}\n >\n <div style={{ height: `${rowVirtualizer.getTotalSize()}px`, position: 'relative' }}>\n {rowVirtualizer.getVirtualItems().map((virtualRow) => {\n const { option, isSelected } = getItemAtIndex(virtualRow.index)\n const optionValue = getOptionValue(option)\n\n return (\n <div\n key={optionValue}\n data-index={virtualRow.index}\n ref={(el) => {\n if (el) rowVirtualizer.measureElement(el)\n }}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n <CommandItem value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, isSelected)\n ) : (\n <>\n <Check className={`mr-2 h-4 w-4 ${isSelected ? 'opacity-100' : 'opacity-0'}`} />\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n </div>\n )\n })}\n </div>\n {loadingMore && (\n <div className=\"flex items-center justify-center py-2 text-sm text-neutral-500\">{loadingPlaceholder}</div>\n )}\n </div>\n )\n}\n"],"names":[],"mappings":";;;;;;;AASO,MAAM,0BAA0B,CAAmB;AAAA,EACxD,YAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA,KAAuC;AACrC,EAAA,MAAM,SAAA,GAAY,OAAuB,IAAI,CAAA;AAC7C,EAAA,MAAM,eAAA,GAAkB,OAAO,KAAK,CAAA;AAEpC,EAAA,MAAM,aAAa,YAAA,CAAa,MAAA;AAChC,EAAA,MAAM,kBAAA,GAAqB,EAAA;AAE3B,EAAA,MAAM,iBAAiB,cAAA,CAAe;AAAA,IACpC,KAAA,EAAO,UAAA;AAAA,IACP,gBAAA,EAAkB,MAAM,SAAA,CAAU,OAAA;AAAA,IAClC,cAAc,MAAM,EAAA;AAAA,IACpB,QAAA,EAAU;AAAA,GACX,CAAA;AAED,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,eAAA,CAAgB,OAAA,GAAU,KAAA;AAAA,EAC5B,CAAA,EAAG,CAAC,UAAA,EAAY,WAAW,CAAC,CAAA;AAE5B,EAAA,MAAM,YAAA,GAAe,eAAe,eAAA,EAAgB;AAEpD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,YAAA,CAAa,WAAW,CAAA,IAAK,CAAC,eAAe,WAAA,IAAe,OAAA,IAAW,gBAAgB,OAAA,EAAS;AAClG,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,eAAA,GAAkB,YAAA,CAAa,EAAA,CAAG,EAAE,CAAA;AAC1C,IAAA,MAAM,YAAA,GAAe,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,EAAI,SAAA,EAAU,kEAAkE,QAAA,EAAA,kBAAA,EAAmB;AAAA;AAAA;AAAA,GAExG;AAEJ;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useComboboxOpenState } from './useComboboxOpenState';
|
|
2
|
+
export { useComboboxSelection } from './useComboboxSelection';
|
|
3
|
+
export { useDebouncedState } from './useDebouncedState';
|
|
4
|
+
export { useDisplayValue } from './useDisplayValue';
|
|
5
|
+
export { usePaginatedOptions } from './usePaginatedOptions';
|
|
6
|
+
export { useSelectedCache } from './useSelectedCache';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useComboboxOpenState } from './useComboboxOpenState.js';
|
|
2
|
+
export { useComboboxSelection } from './useComboboxSelection.js';
|
|
3
|
+
export { useDebouncedState } from './useDebouncedState.js';
|
|
4
|
+
export { useDisplayValue } from './useDisplayValue.js';
|
|
5
|
+
export { usePaginatedOptions } from './usePaginatedOptions.js';
|
|
6
|
+
export { useSelectedCache } from './useSelectedCache.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useDebouncedState } from './useDebouncedState.js';
|
|
3
|
+
|
|
4
|
+
function useComboboxOpenState() {
|
|
5
|
+
const [open, setOpenRaw] = useState(false);
|
|
6
|
+
const { value: searchTerm, debouncedValue: debouncedSearchTerm, setValue: setSearchTerm } = useDebouncedState("");
|
|
7
|
+
const setOpen = useCallback(
|
|
8
|
+
(next) => {
|
|
9
|
+
setOpenRaw(next);
|
|
10
|
+
if (!next) setSearchTerm("");
|
|
11
|
+
},
|
|
12
|
+
[setSearchTerm]
|
|
13
|
+
);
|
|
14
|
+
return { open, setOpen, searchTerm, debouncedSearchTerm, setSearchTerm };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { useComboboxOpenState };
|
|
18
|
+
//# sourceMappingURL=useComboboxOpenState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComboboxOpenState.js","sources":["../../../../src/components/Combobox/hooks/useComboboxOpenState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\n\nimport { useDebouncedState } from './useDebouncedState'\n\nexport function useComboboxOpenState() {\n const [open, setOpenRaw] = useState(false)\n const { value: searchTerm, debouncedValue: debouncedSearchTerm, setValue: setSearchTerm } = useDebouncedState('')\n\n const setOpen = useCallback(\n (next: boolean) => {\n setOpenRaw(next)\n if (!next) setSearchTerm('')\n },\n [setSearchTerm],\n )\n\n return { open, setOpen, searchTerm, debouncedSearchTerm, setSearchTerm }\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,oBAAA,GAAuB;AACrC,EAAA,MAAM,CAAC,IAAA,EAAM,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AACzC,EAAA,MAAM,EAAE,OAAO,UAAA,EAAY,cAAA,EAAgB,qBAAqB,QAAA,EAAU,aAAA,EAAc,GAAI,iBAAA,CAAkB,EAAE,CAAA;AAEhH,EAAA,MAAM,OAAA,GAAU,WAAA;AAAA,IACd,CAAC,IAAA,KAAkB;AACjB,MAAA,UAAA,CAAW,IAAI,CAAA;AACf,MAAA,IAAI,CAAC,IAAA,EAAM,aAAA,CAAc,EAAE,CAAA;AAAA,IAC7B,CAAA;AAAA,IACA,CAAC,aAAa;AAAA,GAChB;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,UAAA,EAAY,qBAAqB,aAAA,EAAc;AACzE;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComboboxProps } from '../Combobox';
|
|
2
|
+
export declare function useComboboxSelection<T extends object>(props: ComboboxProps<T>, setOpen: (open: boolean) => void): {
|
|
3
|
+
handleSelect: (currentValue: string) => void;
|
|
4
|
+
handleRemove: (valueToRemove: string) => void;
|
|
5
|
+
handleClear: (event: React.MouseEvent) => void;
|
|
6
|
+
hasValue: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
function useComboboxSelection(props, setOpen) {
|
|
4
|
+
const { multiple, clearable = true, onClear, specialOptions } = props;
|
|
5
|
+
const closeOnSelect = props.closeOnSelect ?? !props.multiple;
|
|
6
|
+
const handleSelect = (currentValue) => {
|
|
7
|
+
if (multiple) {
|
|
8
|
+
const { onChange } = props;
|
|
9
|
+
const value = Array.isArray(props.value) ? props.value : [];
|
|
10
|
+
const isRemoving = value.includes(currentValue);
|
|
11
|
+
if (specialOptions && specialOptions.length > 0) {
|
|
12
|
+
onChange(isRemoving ? [] : [currentValue]);
|
|
13
|
+
} else {
|
|
14
|
+
if (isRemoving && !clearable && value.length === 1) return;
|
|
15
|
+
onChange(isRemoving ? value.filter((val) => val !== currentValue) : [...value, currentValue]);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
const { value, onChange } = props;
|
|
19
|
+
onChange(clearable && currentValue === value ? "" : currentValue);
|
|
20
|
+
}
|
|
21
|
+
if (closeOnSelect) setOpen(false);
|
|
22
|
+
};
|
|
23
|
+
const handleRemove = (valueToRemove) => {
|
|
24
|
+
if (props.multiple) {
|
|
25
|
+
const { onChange } = props;
|
|
26
|
+
const value = Array.isArray(props.value) ? props.value : [];
|
|
27
|
+
if (!clearable && value.length === 1) return;
|
|
28
|
+
onChange(value.filter((val) => val !== valueToRemove));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handleClear = (event) => {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
event.stopPropagation();
|
|
34
|
+
if (multiple) {
|
|
35
|
+
if (clearable) props.onChange([]);
|
|
36
|
+
} else {
|
|
37
|
+
props.onChange("");
|
|
38
|
+
}
|
|
39
|
+
if (typeof onClear === "function") onClear();
|
|
40
|
+
};
|
|
41
|
+
const hasValue = useMemo(() => {
|
|
42
|
+
if (multiple) return Array.isArray(props.value) && props.value.length > 0;
|
|
43
|
+
return !!props.value;
|
|
44
|
+
}, [props.value, multiple]);
|
|
45
|
+
return { handleSelect, handleRemove, handleClear, hasValue };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { useComboboxSelection };
|
|
49
|
+
//# sourceMappingURL=useComboboxSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComboboxSelection.js","sources":["../../../../src/components/Combobox/hooks/useComboboxSelection.ts"],"sourcesContent":["import { useMemo } from 'react'\n\nimport type { ComboboxProps } from '../Combobox'\n\nexport function useComboboxSelection<T extends object>(props: ComboboxProps<T>, setOpen: (open: boolean) => void) {\n const { multiple, clearable = true, onClear, specialOptions } = props\n const closeOnSelect = props.closeOnSelect ?? !props.multiple\n\n const handleSelect = (currentValue: string) => {\n if (multiple) {\n const { onChange } = props\n const value = Array.isArray(props.value) ? props.value : []\n const isRemoving = value.includes(currentValue)\n\n if (specialOptions && specialOptions.length > 0) {\n onChange(isRemoving ? [] : [currentValue])\n } else {\n if (isRemoving && !clearable && value.length === 1) return\n onChange(isRemoving ? value.filter((val) => val !== currentValue) : [...value, currentValue])\n }\n } else {\n const { value, onChange } = props\n onChange(clearable && currentValue === value ? '' : currentValue)\n }\n\n if (closeOnSelect) setOpen(false)\n }\n\n const handleRemove = (valueToRemove: string) => {\n if (props.multiple) {\n const { onChange } = props\n const value = Array.isArray(props.value) ? props.value : []\n if (!clearable && value.length === 1) return\n onChange(value.filter((val) => val !== valueToRemove))\n }\n }\n\n const handleClear = (event: React.MouseEvent) => {\n event.preventDefault()\n event.stopPropagation()\n\n if (multiple) {\n if (clearable) props.onChange([])\n } else {\n props.onChange('')\n }\n\n if (typeof onClear === 'function') onClear()\n }\n\n const hasValue = useMemo(() => {\n if (multiple) return Array.isArray(props.value) && props.value.length > 0\n return !!props.value\n }, [props.value, multiple])\n\n return { handleSelect, handleRemove,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|
|
3
|
+
function useDebouncedState(initial, delay = 300) {
|
|
4
|
+
const [value, setImmediateValue] = useState(initial);
|
|
5
|
+
const [debouncedValue, setDebouncedValue] = useState(initial);
|
|
6
|
+
const timerRef = useRef(null);
|
|
7
|
+
const setValue = useCallback(
|
|
8
|
+
(next) => {
|
|
9
|
+
setImmediateValue(next);
|
|
10
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
11
|
+
timerRef.current = setTimeout(() => setDebouncedValue(next), delay);
|
|
12
|
+
},
|
|
13
|
+
[delay]
|
|
14
|
+
);
|
|
15
|
+
return { value, debouncedValue, setValue };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useDebouncedState };
|
|
19
|
+
//# sourceMappingURL=useDebouncedState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebouncedState.js","sources":["../../../../src/components/Combobox/hooks/useDebouncedState.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react'\n\nexport function useDebouncedState<T>(initial: T, delay: number = 300) {\n const [value, setImmediateValue] = useState<T>(initial)\n const [debouncedValue, setDebouncedValue] = useState<T>(initial)\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const setValue = useCallback(\n (next: T) => {\n setImmediateValue(next)\n if (timerRef.current) clearTimeout(timerRef.current)\n timerRef.current = setTimeout(() => setDebouncedValue(next), delay)\n },\n [delay],\n )\n\n return { value, debouncedValue, setValue }\n}\n"],"names":[],"mappings":";;AAEO,SAAS,iBAAA,CAAqB,OAAA,EAAY,KAAA,GAAgB,GAAA,EAAK;AACpE,EAAA,MAAM,CAAC,KAAA,EAAO,iBAAiB,CAAA,GAAI,SAAY,OAAO,CAAA;AACtD,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CAAA,GAAI,SAAY,OAAO,CAAA;AAC/D,EAAA,MAAM,QAAA,GAAW,OAA6C,IAAI,CAAA;AAElE,EAAA,MAAM,QAAA,GAAW,WAAA;AAAA,IACf,CAAC,IAAA,KAAY;AACX,MAAA,iBAAA,CAAkB,IAAI,CAAA;AACtB,MAAA,IAAI,QAAA,CAAS,OAAA,EAAS,YAAA,CAAa,QAAA,CAAS,OAAO,CAAA;AACnD,MAAA,QAAA,CAAS,UAAU,UAAA,CAAW,MAAM,iBAAA,CAAkB,IAAI,GAAG,KAAK,CAAA;AAAA,IACpE,CAAA;AAAA,IACA,CAAC,KAAK;AAAA,GACR;AAEA,EAAA,OAAO,EAAE,KAAA,EAAO,cAAA,EAAgB,QAAA,EAAS;AAC3C;;;;"}
|