@cloudwick/astral-ui 8.0.0 → 8.1.0
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/README.md +1 -1
- package/dist/components/button/reloadButton.d.ts +20 -0
- package/dist/components/emptyState/emptyStateVariants.d.ts +3 -3
- package/dist/components/multiSelectTransfer/index.d.ts +1 -1
- package/dist/components/multiSelectTransfer/multiSelectTransfer.d.ts +5 -4
- package/dist/components/multiSelectTransfer/multiSelectTransferDropdown.d.ts +21 -3
- package/dist/components/multiSelectTransfer/multiSelectTransferModal.d.ts +16 -4
- package/dist/components/multiSelectTransfer/multiSelectTransferTrigger.d.ts +26 -0
- package/dist/components/multiSelectTransfer/multiSelectTransferVariants.d.ts +18 -0
- package/dist/components/multiSelectTransfer/types.d.ts +84 -2
- package/dist/components/multiSelectTransfer/useMultiSelectTransferDraft.d.ts +24 -0
- package/dist/components/multiSelectTransfer/useMultiSelectTransferOptionSource.d.ts +56 -0
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/select.d.ts +5 -6
- package/dist/components/select/selectComponents.d.ts +2 -18
- package/dist/components/select/selectMenu.d.ts +12 -0
- package/dist/components/select/selectVariants.d.ts +6 -0
- package/dist/components/select/types.d.ts +129 -15
- package/dist/components/select/useSelectOptionSource.d.ts +39 -0
- package/dist/components/select/useSelectOutsideClose.d.ts +16 -0
- package/dist/components/select/utils.d.ts +2 -1
- package/dist/components/transferList/index.d.ts +1 -1
- package/dist/components/transferList/transferList.d.ts +2 -5
- package/dist/components/transferList/transferListPanel.d.ts +14 -1
- package/dist/components/transferList/transferListPanelHeader.d.ts +29 -0
- package/dist/components/transferList/transferListVariants.d.ts +9 -0
- package/dist/components/transferList/types.d.ts +86 -10
- package/dist/components/transferList/useTransferList.d.ts +1 -1
- package/dist/components/transferList/useTransferListPanelKeys.d.ts +28 -0
- package/dist/components/transferList/useTransferListSource.d.ts +49 -0
- package/dist/css/index.min.css +1 -1
- package/dist/hooks/index.d.ts +7 -1
- package/dist/hooks/useAsyncOptions.d.ts +85 -0
- package/dist/hooks/useAsyncOptionsReducer.d.ts +75 -0
- package/dist/hooks/useAvailableProjection.d.ts +20 -0
- package/dist/hooks/useFilterQuery.d.ts +28 -0
- package/dist/hooks/useIgnoredPropWarning.d.ts +5 -0
- package/dist/hooks/useInfiniteScroll.d.ts +11 -2
- package/dist/hooks/useOnValueChange.d.ts +6 -0
- package/dist/hooks/usePrefetchBaseline.d.ts +22 -0
- package/dist/index.cjs.js +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +5 -5
- package/dist/utils/devWarn.d.ts +5 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/mergeUnique.d.ts +6 -0
- package/dist/utils/resolveLoadErrors.d.ts +20 -0
- package/dist/utils/resolveReloadControls.d.ts +23 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ReactNode, ReactElement, MutableRefObject, RefObject } from "react";
|
|
1
|
+
import type { ChangeEvent, FocusEvent, KeyboardEvent, ReactNode, ReactElement, MutableRefObject, RefObject } from "react";
|
|
2
2
|
import type { Props as ReactSelectProps, GroupBase } from "react-select";
|
|
3
|
+
import type { TLoadOptions, TPrefetch } from "@hooks";
|
|
3
4
|
import { type TIconType } from "../adpIcon";
|
|
4
5
|
/**
|
|
5
6
|
* Available sizes for the Select component
|
|
@@ -23,10 +24,19 @@ export interface IOption {
|
|
|
23
24
|
isFixed?: boolean;
|
|
24
25
|
isDisabled?: boolean;
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Async option source. Page one only: a resolved page that reports `hasMore` is dev-warned, and no
|
|
29
|
+
* further page is ever requested.
|
|
30
|
+
*/
|
|
31
|
+
export type TSelectLoadOptions = TLoadOptions<IOption>;
|
|
32
|
+
/** Latest input modality. Drives which signal shows an option's full-text overlay. */
|
|
33
|
+
export type TSelectInteractionMode = "pointer" | "keyboard";
|
|
34
|
+
/** Options as react-select accepts them — sync mode may carry groups; async mode never does. */
|
|
35
|
+
export type TSelectOptions<Group extends GroupBase<IOption> = GroupBase<IOption>> = readonly (IOption | Group)[];
|
|
26
36
|
/**
|
|
27
37
|
* Props for the Select component
|
|
28
38
|
*/
|
|
29
|
-
export interface ISelectProps<IsMulti extends boolean = false, Group extends GroupBase<IOption> = GroupBase<IOption>> extends Omit<ReactSelectProps<IOption, IsMulti, Group>, "options" | "value" | "className" | "inputValue" | "onInputChange" | "isSearchable"> {
|
|
39
|
+
export interface ISelectProps<IsMulti extends boolean = false, Group extends GroupBase<IOption> = GroupBase<IOption>> extends Omit<ReactSelectProps<IOption, IsMulti, Group>, "options" | "value" | "className" | "inputValue" | "onInputChange" | "isSearchable" | "isLoading" | "filterOption"> {
|
|
30
40
|
/** Unique id for the select input */
|
|
31
41
|
id?: string;
|
|
32
42
|
/** Custom className for wrapper */
|
|
@@ -35,7 +45,7 @@ export interface ISelectProps<IsMulti extends boolean = false, Group extends Gro
|
|
|
35
45
|
label?: ReactNode;
|
|
36
46
|
/** Select size variant */
|
|
37
47
|
size?: TSelectSize;
|
|
38
|
-
/** Options or groups to render */
|
|
48
|
+
/** Options or groups to render. Ignored (dev warning) when `loadOptions` is set — seed with `initialOptions` instead. */
|
|
39
49
|
options?: ReactSelectProps<IOption, IsMulti, Group>["options"];
|
|
40
50
|
/** Current value of the select */
|
|
41
51
|
value?: ReactSelectProps<IOption, IsMulti, Group>["value"];
|
|
@@ -67,6 +77,83 @@ export interface ISelectProps<IsMulti extends boolean = false, Group extends Gro
|
|
|
67
77
|
onReload?: () => void;
|
|
68
78
|
/** Spins the select reload button. */
|
|
69
79
|
isReloading?: boolean;
|
|
80
|
+
/** Seeds/re-syncs dropdown search; semi-controlled — pair with onFilterChange. Applies in both modes. */
|
|
81
|
+
filterValue?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Debounced search-query callback; also called with "" when the component clears search.
|
|
84
|
+
*
|
|
85
|
+
* Without `loadOptions`: switches off local filtering — `options` is treated as already filtered
|
|
86
|
+
* for the query — and the fetch, loading state, and response ordering are the consumer's
|
|
87
|
+
* responsibility.
|
|
88
|
+
*
|
|
89
|
+
* With `loadOptions`: notification-only, for analytics or `filterValue` syncing.
|
|
90
|
+
*/
|
|
91
|
+
onFilterChange?: (query: string) => void;
|
|
92
|
+
/** Debounce for the search query, in both sync and `loadOptions` mode. Set to 0 to disable. @default 300 */
|
|
93
|
+
filterDebounceMs?: number;
|
|
94
|
+
/** Replaces option list with loader. OR-ed with the loader's own state, so it still applies in async mode. @default false */
|
|
95
|
+
isLoading?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Custom client-side match, replacing the shared `matchesQuery` default.
|
|
98
|
+
*
|
|
99
|
+
* @deprecated Use `onFilterChange` instead, which does the same job without a second filtering axis:
|
|
100
|
+
* it hands you the query and treats `options` as already filtered, so your predicate lives in your own
|
|
101
|
+
* `useMemo` rather than in a react-select callback. Pair with `filterDebounceMs={0}` to keep filtering
|
|
102
|
+
* synchronous. Ignored entirely when filtering is already delegated (`onFilterChange`/`loadOptions`),
|
|
103
|
+
* and scheduled for removal in the next major.
|
|
104
|
+
*
|
|
105
|
+
* ```tsx
|
|
106
|
+
* const visible = useMemo(() => all.filter(( o ) => myMatch( o, query )), [ all, query ]);
|
|
107
|
+
* <Select options={visible} onFilterChange={setQuery} filterDebounceMs={0} />
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
filterOption?: ReactSelectProps<IOption, IsMulti, Group>["filterOption"];
|
|
111
|
+
/**
|
|
112
|
+
* Server-side option source. When provided, `Select` owns the option list, the request lifecycle and
|
|
113
|
+
* the loading state; `options` is ignored (dev warning) and `onFilterChange` becomes
|
|
114
|
+
* notification-only. Responsible for mapping the payload to `IOption` — envelopes and domain
|
|
115
|
+
* filtering are the consumer's business. Options are stored exactly as returned, so extra fields
|
|
116
|
+
* survive. A fresh inline arrow is fine: the loader is read through a ref.
|
|
117
|
+
*
|
|
118
|
+
* Page one only: `cursor` / `hasMore` / `total` in the result are ignored.
|
|
119
|
+
*/
|
|
120
|
+
loadOptions?: TSelectLoadOptions;
|
|
121
|
+
/**
|
|
122
|
+
* Seed rows for a list you already have — an SSR payload, a route loader, a warm cache. They paint on the
|
|
123
|
+
* first frame, so there is no loader to sit through, and they stay put while the baseline fetch revalidates
|
|
124
|
+
* over them. They do not suppress that fetch: pair with `prefetch="never"` if the seed is the whole list
|
|
125
|
+
* until the user types. A *search* replaces them, since seed rows are not results for a query; clearing it
|
|
126
|
+
* brings them back until a fetched baseline lands. Async mode only — ignored (dev warning) without
|
|
127
|
+
* `loadOptions`, where the rows belong in `options`.
|
|
128
|
+
*/
|
|
129
|
+
initialOptions?: readonly IOption[];
|
|
130
|
+
/**
|
|
131
|
+
* When to fetch the unfiltered baseline.
|
|
132
|
+
* - `"open"` — on first menu open. Right for forms with several server-filtered Selects, where paying
|
|
133
|
+
* for menus the user may never open is the worse trade.
|
|
134
|
+
* - `"mount"` — at render, before any interaction. Use when the list is near-certain to be needed and
|
|
135
|
+
* a visible-but-empty Select would read as broken.
|
|
136
|
+
* - `"never"` — no baseline at all; fetch only once the user types. For heavy lists.
|
|
137
|
+
*
|
|
138
|
+
* Async mode only — ignored (dev warning) without `loadOptions`, where `options` are already on screen
|
|
139
|
+
* and there is nothing to fetch.
|
|
140
|
+
* @default "open"
|
|
141
|
+
*/
|
|
142
|
+
prefetch?: TPrefetch;
|
|
143
|
+
/** Clearing the search revalidates the cached baseline instead of just restoring it. Costs one request per menu close. @default false */
|
|
144
|
+
refetchOnClear?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Identity of the option set, for dependent selects. When it changes, cached results are dropped and
|
|
147
|
+
* the list is repopulated — immediately if the menu is open, otherwise on next open. Compose several
|
|
148
|
+
* parents into one scalar: ``optionsKey={`${domainId}|${accessType}`}``. Does NOT clear the selection.
|
|
149
|
+
*/
|
|
150
|
+
optionsKey?: string | number;
|
|
151
|
+
/** Shown in the menu when `loadOptions` rejects. @default "Couldn't load options." */
|
|
152
|
+
loadErrorMessage?: ReactNode;
|
|
153
|
+
/** Shows the menu's reload button in async mode, wired to re-run the current query. @default false */
|
|
154
|
+
showReloadButton?: boolean;
|
|
155
|
+
/** Notified when a load rejects (the component renders `loadErrorMessage` and swallows it). */
|
|
156
|
+
onLoadError?: (error: unknown) => void;
|
|
70
157
|
}
|
|
71
158
|
/**
|
|
72
159
|
* Per-render option config for the SelectOption component. react-select keys custom components by
|
|
@@ -77,8 +164,19 @@ export interface ISelectProps<IsMulti extends boolean = false, Group extends Gro
|
|
|
77
164
|
* `useIsTruncated` measurement (and the hover-expand affordance) from flickering.
|
|
78
165
|
*/
|
|
79
166
|
export interface ISelectOptionContext {
|
|
80
|
-
/**
|
|
81
|
-
|
|
167
|
+
/**
|
|
168
|
+
* In-progress multi-select draft, as a value Set. Drives checkboxes / Select All while the
|
|
169
|
+
* committed value drives the control. A Set rather than the array: every option row tests its own
|
|
170
|
+
* membership, so an array would make one menu render O(options x draft).
|
|
171
|
+
*/
|
|
172
|
+
draftValues?: ReadonlySet<IOption["value"]>;
|
|
173
|
+
/**
|
|
174
|
+
* Checked state of the Select All row: every option the query currently leaves VISIBLE is in the
|
|
175
|
+
* draft. Resolved on the Select, which is the only place that knows the visible set — react-select
|
|
176
|
+
* hands each option its unfiltered `options` array, so deriving it here would report unchecked
|
|
177
|
+
* even with every visible row ticked.
|
|
178
|
+
*/
|
|
179
|
+
areAllSelected?: boolean;
|
|
82
180
|
/** Toggle a single option in the multi-select draft. */
|
|
83
181
|
onToggleDraftOption?: (option: IOption) => void;
|
|
84
182
|
/** Toggle Select All / Deselect All on the multi-select draft (shared with the keyboard path). */
|
|
@@ -95,21 +193,29 @@ export interface ISelectOptionContext {
|
|
|
95
193
|
* they're navigating by keyboard. Without this, react-select's `isFocused` - which lingers on the
|
|
96
194
|
* last-focused option after the pointer leaves, and is also set by mouse hover - keeps an
|
|
97
195
|
* overlay visible after the mouse has moved away (and shows two at once mid-transition).
|
|
196
|
+
*
|
|
197
|
+
* State on the Select, not a shared ref: this decides what an option renders, and writing a ref
|
|
198
|
+
* schedules no re-render. Setting the mode it already holds is a no-op React bails out of, so
|
|
199
|
+
* hovering along a list costs a render only at a genuine modality switch.
|
|
98
200
|
*/
|
|
99
|
-
|
|
201
|
+
interactionMode: TSelectInteractionMode;
|
|
202
|
+
/** Records the modality the user just used. See {@link ISelectOptionContext.interactionMode}. */
|
|
203
|
+
onInteractionMode: (mode: TSelectInteractionMode) => void;
|
|
100
204
|
}
|
|
101
205
|
/**
|
|
102
|
-
*
|
|
103
|
-
* routing these through context lets SelectMenu keep a module-level identity - so react-select never
|
|
104
|
-
* remounts it and the search input keeps its focus, caret, and scroll position across keystrokes -
|
|
105
|
-
* while still re-rendering with current values whenever they change. (A component closing over these
|
|
106
|
-
* directly would freeze them at first render, since its identity must never change.)
|
|
206
|
+
* Per-instance menu config via context (keeps SelectMenu's stable identity).
|
|
107
207
|
*/
|
|
108
208
|
export interface ISelectMenuContext {
|
|
109
209
|
/** Current search text (controls react-select's inputValue). */
|
|
110
210
|
filterQuery: string;
|
|
111
|
-
/**
|
|
112
|
-
|
|
211
|
+
/** Updates the query and (debounced) notifies `onFilterChange`. */
|
|
212
|
+
onFilterInput: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
213
|
+
/** Marks Backspace/Delete held; defer debounce until keyup. */
|
|
214
|
+
onFilterKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
215
|
+
/** On Backspace/Delete release, starts the deferred debounce. */
|
|
216
|
+
onFilterKeyUp: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
217
|
+
/** On blur during hold, flush deferred debounce. */
|
|
218
|
+
onFilterBlur: (e: FocusEvent<HTMLInputElement>) => void;
|
|
113
219
|
/** Placeholder for the search input. */
|
|
114
220
|
searchPlaceholder: string;
|
|
115
221
|
/** Optional custom footer rendered below the option list. */
|
|
@@ -122,6 +228,14 @@ export interface ISelectMenuContext {
|
|
|
122
228
|
searchContainerClass: string;
|
|
123
229
|
/** tv() class for the search input. */
|
|
124
230
|
searchInputClass: string;
|
|
231
|
+
/** tv() class for the loader shown in place of the option list. */
|
|
232
|
+
loaderClass: string;
|
|
233
|
+
/** Replaces the option list with the loader. */
|
|
234
|
+
isLoading?: boolean;
|
|
235
|
+
/** Replaces the option list when set (async load failure). */
|
|
236
|
+
loadError?: ReactNode;
|
|
237
|
+
/** tv() class for the error container. */
|
|
238
|
+
errorClass: string;
|
|
125
239
|
/** Ref to the search input; focused when the menu opens. */
|
|
126
240
|
searchInputRef: RefObject<HTMLInputElement>;
|
|
127
241
|
/** Captures the menu's (possibly portaled) DOM node for the outside-click check. */
|
|
@@ -134,8 +248,8 @@ export interface ISelectMenuContext {
|
|
|
134
248
|
isReloading?: boolean;
|
|
135
249
|
/** Reload-button tooltip / aria-label. */
|
|
136
250
|
reloadTooltip?: string;
|
|
137
|
-
/**
|
|
138
|
-
|
|
251
|
+
/** Records the input modality (see {@link ISelectOptionContext.interactionMode}); set to "keyboard" here. */
|
|
252
|
+
onInteractionMode: (mode: TSelectInteractionMode) => void;
|
|
139
253
|
}
|
|
140
254
|
export interface IOptionLabelOverlayProps {
|
|
141
255
|
anchorRef: RefObject<HTMLElement>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { GroupBase } from "react-select";
|
|
3
|
+
import { type TPrefetch } from "@hooks";
|
|
4
|
+
import type { IOption, TSelectLoadOptions, TSelectOptions } from "./types";
|
|
5
|
+
interface IUseSelectOptionSourceArgs<Group extends GroupBase<IOption>> {
|
|
6
|
+
options?: TSelectOptions<Group>;
|
|
7
|
+
loadOptions?: TSelectLoadOptions;
|
|
8
|
+
initialOptions?: readonly IOption[];
|
|
9
|
+
prefetch?: TPrefetch;
|
|
10
|
+
refetchOnClear?: boolean;
|
|
11
|
+
optionsKey?: string | number;
|
|
12
|
+
loadErrorMessage?: ReactNode;
|
|
13
|
+
showReloadButton?: boolean;
|
|
14
|
+
onLoadError?: (error: unknown) => void;
|
|
15
|
+
/** Consumer-owned loading flag; OR-ed with the async loader rather than replaced by it. */
|
|
16
|
+
isLoading?: boolean;
|
|
17
|
+
onReload?: () => void;
|
|
18
|
+
isReloading?: boolean;
|
|
19
|
+
onFilterChange?: (query: string) => void;
|
|
20
|
+
}
|
|
21
|
+
interface ISelectOptionSource<Group extends GroupBase<IOption>> {
|
|
22
|
+
options: TSelectOptions<Group>;
|
|
23
|
+
isServerFiltered: boolean;
|
|
24
|
+
/** Loader instead of rows (SelectMenu's `isLoading`). */
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
isReloading?: boolean;
|
|
27
|
+
onReload?: () => void;
|
|
28
|
+
/** Hand to `useFilterQuery`; notifies the consumer AND drives the async source. */
|
|
29
|
+
onFilterQueryChange: (query: string) => void;
|
|
30
|
+
ensureDefaults: () => void;
|
|
31
|
+
loadError?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* All of `Select`'s option-source policy: async vs sync mode detection, value precedence between the
|
|
35
|
+
* consumer's own flags and the loader's derived ones, default messages, and the dev warnings for the
|
|
36
|
+
* two footguns a type-level XOR cannot express against react-select's generics.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSelectOptionSource<Group extends GroupBase<IOption>>({ options, loadOptions, initialOptions, prefetch, refetchOnClear, optionsKey, loadErrorMessage, showReloadButton, onLoadError, isLoading, onReload, isReloading, onFilterChange }: IUseSelectOptionSourceArgs<Group>): ISelectOptionSource<Group>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MutableRefObject } from "react";
|
|
2
|
+
interface IUseSelectOutsideCloseArgs {
|
|
3
|
+
/** Only while the menu is open is a listener attached. */
|
|
4
|
+
menuOpen: boolean;
|
|
5
|
+
/** The menu's (possibly portaled) DOM node, so clicks inside it are not "outside". */
|
|
6
|
+
menuNodeRef: MutableRefObject<HTMLDivElement | null>;
|
|
7
|
+
/** Commits the multi-select draft, then closes. */
|
|
8
|
+
commitAndClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Closes the dropdown on interaction outside the component. react-select's own outside-click
|
|
12
|
+
* handling relies on its input being focused (it is not — focus lives in the dropdown search input),
|
|
13
|
+
* so Select handles it here instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useSelectOutsideClose({ menuOpen, menuNodeRef, commitAndClose }: IUseSelectOutsideCloseArgs): void;
|
|
16
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type StylesConfig, type GroupBase } from "react-select";
|
|
2
2
|
import { type TSelectSize, type IOption } from "./types";
|
|
3
|
+
export declare const SELECT_ALL_VALUE = "select-all";
|
|
3
4
|
export declare const getSelectableOptions: (options: readonly (IOption | GroupBase<IOption>)[]) => IOption[];
|
|
4
|
-
export declare const areAllSelectableSelected: (
|
|
5
|
+
export declare const areAllSelectableSelected: (selectable: readonly IOption[], draftValues: ReadonlySet<IOption["value"]>) => boolean;
|
|
5
6
|
export declare const reactSelectCustomStyles: <IsMulti extends boolean, Group extends GroupBase<IOption>>(error: boolean, size: TSelectSize, multiSelect: boolean) => StylesConfig<IOption, IsMulti, Group>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { TransferList } from "./transferList";
|
|
2
2
|
export { transferListVariants } from "./transferListVariants";
|
|
3
|
-
export type { ITransferListProps, ITransferListItem, TTransferListValue, TTransferPanel } from "./types";
|
|
3
|
+
export type { ITransferListProps, ITransferListItem, TTransferListValue, TTransferPanel, TTransferListLoadOptions, TTransferListPrefetch } from "./types";
|
|
@@ -4,9 +4,6 @@ import type { ITransferListProps } from "./types";
|
|
|
4
4
|
* A fully-controlled two-panel transfer list. Move items between the Available
|
|
5
5
|
* and Selected panels via checkboxes + arrow controls or native drag-and-drop.
|
|
6
6
|
* Rendering and ownership of any surrounding chrome (modal, footer) is left to
|
|
7
|
-
* the consumer.
|
|
7
|
+
* the consumer. The forwarded ref lands on the wrapper `<div>`.
|
|
8
8
|
*/
|
|
9
|
-
export declare
|
|
10
|
-
export declare namespace TransferList {
|
|
11
|
-
var displayName: string;
|
|
12
|
-
}
|
|
9
|
+
export declare const TransferList: React.ForwardRefExoticComponent<ITransferListProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -18,8 +18,21 @@ interface ITransferListPanelProps {
|
|
|
18
18
|
hasMore?: boolean;
|
|
19
19
|
onLoadMore?: () => void;
|
|
20
20
|
isLoadingMore?: boolean;
|
|
21
|
+
/** Loader REPLACES the rows (a search/refresh fetch, not a page append). */
|
|
22
|
+
isLoading?: boolean;
|
|
23
|
+
/** Replaces the rows when set: the panel's source failed to load. */
|
|
24
|
+
loadError?: React.ReactNode;
|
|
25
|
+
/** Shown under the loaded rows when a page append failed; renders a retry button. */
|
|
26
|
+
loadMoreError?: React.ReactNode;
|
|
27
|
+
/** Fired by the retry button under `loadMoreError`. */
|
|
28
|
+
onRetryLoadMore?: () => void;
|
|
29
|
+
/** Label for that retry button. */
|
|
30
|
+
retryLabel?: string;
|
|
31
|
+
/** Server-side total; the header count becomes "(loaded of total)". */
|
|
32
|
+
totalCount?: number;
|
|
21
33
|
selectAllChecked: boolean;
|
|
22
34
|
selectAllIndeterminate: boolean;
|
|
35
|
+
/** Search-visible, non-disabled row count — the scope the select-all checkbox acts on. */
|
|
23
36
|
selectAllCount: number;
|
|
24
37
|
onToggleSelectAll: () => void;
|
|
25
38
|
moveLabel: string;
|
|
@@ -44,7 +57,7 @@ interface ITransferListPanelProps {
|
|
|
44
57
|
* One panel of the transfer list: header (title, count, optional reload),
|
|
45
58
|
* optional search + header slot, and a scrollable list of rows or an empty state.
|
|
46
59
|
*/
|
|
47
|
-
export declare function TransferListPanel({ panel, title, items, reorderable, disabled, emptyText, searchable, searchValue, searchPlaceholder, onSearchChange, headerSlot, reloadTooltip, onReload, isReloading, hasMore, onLoadMore, isLoadingMore, selectAllChecked, selectAllIndeterminate, selectAllCount, onToggleSelectAll, moveLabel, moveCount, moveDisabled, moveIconSide, onMove, isChecked, onToggle, onRemove, onMoveUp, onMoveDown, dropIndex, showDropOverlay, onItemDragStart, onItemDragEnd, onItemDragOver, onListDragOver, onListDrop }: ITransferListPanelProps): React.ReactElement;
|
|
60
|
+
export declare function TransferListPanel({ panel, title, items, reorderable, disabled, emptyText, searchable, searchValue, searchPlaceholder, onSearchChange, headerSlot, reloadTooltip, onReload, isReloading, hasMore, onLoadMore, isLoadingMore, isLoading, loadError, loadMoreError, onRetryLoadMore, retryLabel, totalCount, selectAllChecked, selectAllIndeterminate, selectAllCount, onToggleSelectAll, moveLabel, moveCount, moveDisabled, moveIconSide, onMove, isChecked, onToggle, onRemove, onMoveUp, onMoveDown, dropIndex, showDropOverlay, onItemDragStart, onItemDragEnd, onItemDragOver, onListDragOver, onListDrop }: ITransferListPanelProps): React.ReactElement;
|
|
48
61
|
export declare namespace TransferListPanel {
|
|
49
62
|
var displayName: string;
|
|
50
63
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TTransferPanel } from "./types";
|
|
3
|
+
interface ITransferListPanelHeaderProps {
|
|
4
|
+
panel: TTransferPanel;
|
|
5
|
+
title: React.ReactNode;
|
|
6
|
+
/** Rows currently loaded in this panel. */
|
|
7
|
+
count: number;
|
|
8
|
+
/** Server-side total; the count becomes "(loaded of total)" when it exceeds `count`. */
|
|
9
|
+
totalCount?: number;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
searchable: boolean;
|
|
12
|
+
searchValue: string;
|
|
13
|
+
searchPlaceholder: string;
|
|
14
|
+
onSearchChange: (query: string) => void;
|
|
15
|
+
headerSlot?: React.ReactNode;
|
|
16
|
+
reloadTooltip?: string;
|
|
17
|
+
onReload?: () => void;
|
|
18
|
+
isReloading?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The non-interactive chrome above a transfer-list panel's listbox: title + count, the optional
|
|
22
|
+
* reload button, the search input, and the consumer's header slot. It shares no state with the
|
|
23
|
+
* listbox below it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function TransferListPanelHeader({ panel, title, count, totalCount, disabled, searchable, searchValue, searchPlaceholder, onSearchChange, headerSlot, reloadTooltip, onReload, isReloading }: ITransferListPanelHeaderProps): React.ReactElement;
|
|
26
|
+
export declare namespace TransferListPanelHeader {
|
|
27
|
+
var displayName: string;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -54,6 +54,9 @@ export declare const transferListVariants: import("tailwind-variants").TVReturnT
|
|
|
54
54
|
emptyWrap: string;
|
|
55
55
|
emptyText: string;
|
|
56
56
|
loaderRow: string;
|
|
57
|
+
replaceLoader: string;
|
|
58
|
+
panelError: string;
|
|
59
|
+
loadMoreErrorRow: string;
|
|
57
60
|
row: string;
|
|
58
61
|
dragHandle: string;
|
|
59
62
|
badge: string;
|
|
@@ -121,6 +124,9 @@ export declare const transferListVariants: import("tailwind-variants").TVReturnT
|
|
|
121
124
|
emptyWrap: string;
|
|
122
125
|
emptyText: string;
|
|
123
126
|
loaderRow: string;
|
|
127
|
+
replaceLoader: string;
|
|
128
|
+
panelError: string;
|
|
129
|
+
loadMoreErrorRow: string;
|
|
124
130
|
row: string;
|
|
125
131
|
dragHandle: string;
|
|
126
132
|
badge: string;
|
|
@@ -188,6 +194,9 @@ export declare const transferListVariants: import("tailwind-variants").TVReturnT
|
|
|
188
194
|
emptyWrap: string;
|
|
189
195
|
emptyText: string;
|
|
190
196
|
loaderRow: string;
|
|
197
|
+
replaceLoader: string;
|
|
198
|
+
panelError: string;
|
|
199
|
+
loadMoreErrorRow: string;
|
|
191
200
|
row: string;
|
|
192
201
|
dragHandle: string;
|
|
193
202
|
badge: string;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { TLoadOptions, TPrefetch } from "@hooks";
|
|
3
|
+
/**
|
|
4
|
+
* `TPrefetch` minus `"open"`: the panel's list is always visible, so it has no open event to hang a
|
|
5
|
+
* fetch on. Narrowed rather than redefined, so the family shares one vocabulary.
|
|
6
|
+
*/
|
|
7
|
+
export type TTransferListPrefetch = Exclude<TPrefetch, "open">;
|
|
2
8
|
/**
|
|
3
9
|
* Which of the two panels an item or action belongs to.
|
|
4
10
|
*/
|
|
@@ -10,9 +16,8 @@ export type TTransferPanel = "available" | "selected";
|
|
|
10
16
|
*/
|
|
11
17
|
export type TTransferListValue = string | number;
|
|
12
18
|
/**
|
|
13
|
-
* A single transferable item.
|
|
14
|
-
*
|
|
15
|
-
* structurally compatible.
|
|
19
|
+
* A single transferable item. The shape composing components alias rather than redeclare, so an
|
|
20
|
+
* option and a transfer-list item stay structurally identical.
|
|
16
21
|
*/
|
|
17
22
|
export interface ITransferListItem {
|
|
18
23
|
value: TTransferListValue;
|
|
@@ -21,9 +26,14 @@ export interface ITransferListItem {
|
|
|
21
26
|
searchValue?: string;
|
|
22
27
|
isDisabled?: boolean;
|
|
23
28
|
}
|
|
29
|
+
/** Async source for the available panel. Paged: `cursor`, `hasMore` and `total` are all honoured. */
|
|
30
|
+
export type TTransferListLoadOptions = TLoadOptions<ITransferListItem>;
|
|
24
31
|
export interface ITransferListProps {
|
|
25
|
-
/**
|
|
26
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Items in the available (left) panel. Controlled. Optional and **ignored** (with a dev warning)
|
|
34
|
+
* when `loadAvailableOptions` is set — in that mode the component owns the available pool.
|
|
35
|
+
*/
|
|
36
|
+
availableItems?: ITransferListItem[];
|
|
27
37
|
/** Items in the selected (right) panel. Order is preserved when reorderable. Controlled. */
|
|
28
38
|
selectedItems: ITransferListItem[];
|
|
29
39
|
/** Fired on every move/reorder with the next available + selected arrays. */
|
|
@@ -34,9 +44,19 @@ export interface ITransferListProps {
|
|
|
34
44
|
selectedPanelTitle?: ReactNode;
|
|
35
45
|
/** Show the per-panel search inputs. @default true */
|
|
36
46
|
searchable?: boolean;
|
|
37
|
-
/** Controlled search term for the available panel. */
|
|
47
|
+
/** Controlled search term for the available panel. Overridden when `loadAvailableOptions` is set. */
|
|
38
48
|
availableSearchTerm?: string;
|
|
39
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Controlled-search change handler for the available panel. Fires on every keystroke (no built-in
|
|
51
|
+
* debounce).
|
|
52
|
+
*
|
|
53
|
+
* Without `loadAvailableOptions`: switches off the panel's local filtering — `availableItems` is
|
|
54
|
+
* treated as already filtered for the query — so the debounce, the fetch, the loading state, the
|
|
55
|
+
* response ordering, and subtracting `selectedItems` from the result are the consumer's
|
|
56
|
+
* responsibility.
|
|
57
|
+
*
|
|
58
|
+
* With `loadAvailableOptions`: notification-only, for analytics.
|
|
59
|
+
*/
|
|
40
60
|
onAvailableSearchChange?: (query: string) => void;
|
|
41
61
|
/** Controlled search term for the selected panel. */
|
|
42
62
|
selectedSearchTerm?: string;
|
|
@@ -60,12 +80,68 @@ export interface ITransferListProps {
|
|
|
60
80
|
onReload?: () => void;
|
|
61
81
|
/** Spins the reload icon and disables the button. */
|
|
62
82
|
isReloading?: boolean;
|
|
63
|
-
/** More available items can be loaded (drives the infinite-scroll sentinel). */
|
|
83
|
+
/** More available items can be loaded (drives the infinite-scroll sentinel). Ignored when `loadAvailableOptions` is set. */
|
|
64
84
|
hasMoreAvailable?: boolean;
|
|
65
|
-
/** Fired when the available list sentinel scrolls into view. */
|
|
85
|
+
/** Fired when the available list sentinel scrolls into view. Ignored when `loadAvailableOptions` is set. */
|
|
66
86
|
onLoadMoreAvailable?: () => void;
|
|
67
|
-
/** Renders a loader row at the bottom of the available list. */
|
|
87
|
+
/** Renders a loader row at the bottom of the available list. Ignored when `loadAvailableOptions` is set. */
|
|
68
88
|
isLoadingMoreAvailable?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Loader REPLACES the available rows (a search/refresh fetch, not a page append). OR-ed with the
|
|
91
|
+
* loader's own state, so it still applies in async mode. @default false
|
|
92
|
+
*/
|
|
93
|
+
isLoadingAvailable?: boolean;
|
|
94
|
+
/** Replaces the available rows when set: the available source failed to load. Ignored in async mode — use `loadErrorMessage`. */
|
|
95
|
+
availableLoadError?: ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Shown under the loaded rows when a page append failed; renders a retry button. Ignored in async
|
|
98
|
+
* mode — use `loadMoreErrorMessage`.
|
|
99
|
+
*/
|
|
100
|
+
availableLoadMoreError?: ReactNode;
|
|
101
|
+
/** Fired by the retry button under `availableLoadMoreError`. Ignored when `loadAvailableOptions` is set. */
|
|
102
|
+
onRetryLoadMoreAvailable?: () => void;
|
|
103
|
+
/** Label for that retry button. @default "Retry" */
|
|
104
|
+
retryLabel?: string;
|
|
105
|
+
/** Server-side total for the available panel; the header count becomes "(loaded of total)". Takes precedence over the loader's own total. */
|
|
106
|
+
availableTotalCount?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Async source for the available panel. When provided, the component owns that panel's pool, paging,
|
|
109
|
+
* request lifecycle and loading/error state; `availableItems` is ignored (dev warning) and the
|
|
110
|
+
* panel's search becomes server-driven. `selectedItems` stays controlled — the consumer owns the
|
|
111
|
+
* selection — and `onChange` still fires with both arrays.
|
|
112
|
+
*/
|
|
113
|
+
loadAvailableOptions?: TTransferListLoadOptions;
|
|
114
|
+
/**
|
|
115
|
+
* Seed rows for a pool you already have — an SSR payload, a route loader, a warm cache. They paint on the
|
|
116
|
+
* first frame, so the panel is never briefly empty, and they stay put while the mount fetch revalidates over
|
|
117
|
+
* them. They go through the same pool-minus-`selectedItems` projection as fetched rows. They do not suppress
|
|
118
|
+
* that fetch: pair with `prefetch="never"` if the seed is the whole pool until the user searches. Seed rows
|
|
119
|
+
* carry no cursor, so nothing pages until a real page lands. A *search* replaces them, since seed rows are
|
|
120
|
+
* not results for a query. Async mode only — ignored (dev warning) without `loadAvailableOptions`, where the
|
|
121
|
+
* rows belong in `availableItems`.
|
|
122
|
+
*/
|
|
123
|
+
initialAvailableOptions?: readonly ITransferListItem[];
|
|
124
|
+
/**
|
|
125
|
+
* When to fetch the unfiltered available list. `"mount"` fires at render — the panel has no
|
|
126
|
+
* open/close, so mount is the only trigger it has. `"never"` defers everything until the user
|
|
127
|
+
* searches, for a heavy list that should stay untouched otherwise.
|
|
128
|
+
*
|
|
129
|
+
* Async mode only — ignored (dev warning) without `loadAvailableOptions`, where `availableItems` are
|
|
130
|
+
* already on screen and there is nothing to fetch. @default "mount"
|
|
131
|
+
*/
|
|
132
|
+
prefetch?: TTransferListPrefetch;
|
|
133
|
+
/** Clearing the available search revalidates the cached baseline instead of just restoring it. @default false */
|
|
134
|
+
refetchOnClear?: boolean;
|
|
135
|
+
/** Identity of the available option set. A change drops cached pages and repopulates. Does NOT clear the selection. */
|
|
136
|
+
optionsKey?: string | number;
|
|
137
|
+
/** Debounce for the available panel's search when it is server-driven. @default 300 */
|
|
138
|
+
availableFilterDebounceMs?: number;
|
|
139
|
+
/** Shown in place of the available rows when the loader rejects. @default "Couldn't load options." */
|
|
140
|
+
loadErrorMessage?: ReactNode;
|
|
141
|
+
/** Shown under the loaded rows when a page append rejects. @default "Couldn't load more." */
|
|
142
|
+
loadMoreErrorMessage?: ReactNode;
|
|
143
|
+
/** Notified when a load rejects (the component renders the message and swallows it). */
|
|
144
|
+
onLoadError?: (error: unknown) => void;
|
|
69
145
|
/** Disable all interaction. */
|
|
70
146
|
disabled?: boolean;
|
|
71
147
|
/** Empty-state copy for the available panel. @default "No Data Found!" */
|
|
@@ -16,7 +16,7 @@ interface IDragState {
|
|
|
16
16
|
export declare function useTransferList({ availableItems, selectedItems, onChange }: IUseTransferListArgs): {
|
|
17
17
|
isChecked: (panel: TTransferPanel, value: TTransferListValue) => boolean;
|
|
18
18
|
toggleCheck: (panel: TTransferPanel, value: TTransferListValue) => void;
|
|
19
|
-
setPanelChecked: (panel: TTransferPanel, values: TTransferListValue[]) => void;
|
|
19
|
+
setPanelChecked: (panel: TTransferPanel, values: TTransferListValue[], checked: boolean) => void;
|
|
20
20
|
moveRight: (values: TTransferListValue[]) => void;
|
|
21
21
|
moveLeft: (values: TTransferListValue[]) => void;
|
|
22
22
|
transferToSelected: (value: TTransferListValue, insertIndex?: number) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KeyboardEvent } from "react";
|
|
2
|
+
import type { ITransferListItem, TTransferListValue } from "./types";
|
|
3
|
+
interface IUseTransferListPanelKeysArgs {
|
|
4
|
+
items: ITransferListItem[];
|
|
5
|
+
activeIndex: number;
|
|
6
|
+
setActiveIndex: (index: number) => void;
|
|
7
|
+
moveActive: (direction: 1 | -1) => void;
|
|
8
|
+
firstEnabledIndex: (from: number, direction: 1 | -1) => number;
|
|
9
|
+
reorderable: boolean;
|
|
10
|
+
onToggle: (value: TTransferListValue) => void;
|
|
11
|
+
onRemove?: (value: TTransferListValue) => void;
|
|
12
|
+
onMoveUp?: (index: number) => void;
|
|
13
|
+
onMoveDown?: (index: number) => void;
|
|
14
|
+
setIsFocused: (focused: boolean) => void;
|
|
15
|
+
/**
|
|
16
|
+
* The rows the arrow keys are addressing are about to be replaced (a search fetch is in flight, or
|
|
17
|
+
* an error has taken the list's place), so every key is swallowed. The single place this gate is
|
|
18
|
+
* expressed.
|
|
19
|
+
*/
|
|
20
|
+
isBlocked: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The listbox key handler for one transfer-list panel: arrow/Home/End navigation over
|
|
24
|
+
* `aria-activedescendant`, Enter/Space to toggle, Delete/Backspace to remove, and Alt+Arrow to
|
|
25
|
+
* reorder.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useTransferListPanelKeys({ items, activeIndex, setActiveIndex, moveActive, firstEnabledIndex, reorderable, onToggle, onRemove, onMoveUp, onMoveDown, setIsFocused, isBlocked }: IUseTransferListPanelKeysArgs): (e: KeyboardEvent<HTMLDivElement>) => void;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ITransferListItem, TTransferListLoadOptions, TTransferListPrefetch } from "./types";
|
|
3
|
+
interface IUseTransferListSourceArgs {
|
|
4
|
+
availableItems?: ITransferListItem[];
|
|
5
|
+
/** Controlled by the consumer in every mode — the selection is the whole point of the component. */
|
|
6
|
+
selectedItems: ITransferListItem[];
|
|
7
|
+
loadAvailableOptions?: TTransferListLoadOptions;
|
|
8
|
+
initialAvailableOptions?: readonly ITransferListItem[];
|
|
9
|
+
prefetch?: TTransferListPrefetch;
|
|
10
|
+
refetchOnClear?: boolean;
|
|
11
|
+
optionsKey?: string | number;
|
|
12
|
+
availableFilterDebounceMs?: number;
|
|
13
|
+
loadErrorMessage?: ReactNode;
|
|
14
|
+
loadMoreErrorMessage?: ReactNode;
|
|
15
|
+
onLoadError?: (error: unknown) => void;
|
|
16
|
+
hasMoreAvailable?: boolean;
|
|
17
|
+
onLoadMoreAvailable?: () => void;
|
|
18
|
+
isLoadingMoreAvailable?: boolean;
|
|
19
|
+
isLoadingAvailable?: boolean;
|
|
20
|
+
availableLoadError?: ReactNode;
|
|
21
|
+
availableLoadMoreError?: ReactNode;
|
|
22
|
+
onRetryLoadMoreAvailable?: () => void;
|
|
23
|
+
availableTotalCount?: number;
|
|
24
|
+
availableSearchTerm?: string;
|
|
25
|
+
onAvailableSearchChange?: (query: string) => void;
|
|
26
|
+
}
|
|
27
|
+
interface ITransferListSource {
|
|
28
|
+
/** The available pool: derived from the loaded pages in async mode, the prop otherwise. */
|
|
29
|
+
availableItems: ITransferListItem[];
|
|
30
|
+
hasMoreAvailable: boolean;
|
|
31
|
+
onLoadMoreAvailable?: () => void;
|
|
32
|
+
isLoadingMoreAvailable: boolean;
|
|
33
|
+
isLoadingAvailable: boolean;
|
|
34
|
+
availableLoadError?: ReactNode;
|
|
35
|
+
availableLoadMoreError?: ReactNode;
|
|
36
|
+
onRetryLoadMoreAvailable?: () => void;
|
|
37
|
+
availableTotalCount?: number;
|
|
38
|
+
/** In async mode these make the panel's search controlled and server-driven. */
|
|
39
|
+
availableSearchTerm?: string;
|
|
40
|
+
onAvailableSearchChange?: (query: string) => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `TransferList`'s available-panel source. In async mode it owns a `useAsyncOptions` instance, a
|
|
44
|
+
* debounced `useFilterQuery` for the panel's search (which is a raw `onChange` otherwise), the
|
|
45
|
+
* mount/`optionsKey` prefetch, and the pool → available projection. Without a loader every value is
|
|
46
|
+
* the corresponding prop, unchanged.
|
|
47
|
+
*/
|
|
48
|
+
export declare function useTransferListSource({ availableItems, selectedItems, loadAvailableOptions, initialAvailableOptions, prefetch, refetchOnClear, optionsKey, availableFilterDebounceMs, loadErrorMessage, loadMoreErrorMessage, onLoadError, hasMoreAvailable, onLoadMoreAvailable, isLoadingMoreAvailable, isLoadingAvailable, availableLoadError, availableLoadMoreError, onRetryLoadMoreAvailable, availableTotalCount, availableSearchTerm, onAvailableSearchChange }: IUseTransferListSourceArgs): ITransferListSource;
|
|
49
|
+
export {};
|