@gearbox-protocol/ui-kit 3.14.0-next.25 → 3.14.0-next.26
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/cjs/hooks/index.cjs +1 -1
- package/dist/cjs/hooks/use-filter.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/index.js +50 -47
- package/dist/esm/hooks/use-filter.js +63 -29
- package/dist/esm/index.js +225 -222
- package/dist/types/hooks/use-filter.d.ts +46 -0
- package/package.json +1 -1
|
@@ -23,6 +23,52 @@ export type SortSetterFunction<T> = (field: T, startFromSort?: SortType) => void
|
|
|
23
23
|
* Hook for managing sort state
|
|
24
24
|
*/
|
|
25
25
|
export declare function useSort<T>(initialState?: FilterSortField<T> | null): readonly [FilterSortField<T> | null, SortSetterFunction<T>];
|
|
26
|
+
/**
|
|
27
|
+
* Ordered list of active sort keys. The first entry is the primary sort key,
|
|
28
|
+
* the second is the tie-breaker, and so on. An empty array means "no sort".
|
|
29
|
+
*/
|
|
30
|
+
export type MultiSortField<T> = ReadonlyArray<FilterSortField<T>>;
|
|
31
|
+
/** Resolved sort state for a single column inside a {@link MultiSortField}. */
|
|
32
|
+
export interface MultiSortFieldState {
|
|
33
|
+
/** Sort direction for this field, or `undefined` when the field is inactive. */
|
|
34
|
+
sort: SortType | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* 1-based position of the field within the active sort keys, or `undefined`
|
|
37
|
+
* when the field is inactive. Use it to render a priority badge (1, 2, …).
|
|
38
|
+
*/
|
|
39
|
+
priority: number | undefined;
|
|
40
|
+
}
|
|
41
|
+
export type MultiSortSetterFunction<T> = (field: T, startFromSort?: SortType) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the direction and priority of a single field within a multi-sort.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* const { sort, priority } = getSortForFields("type", state);
|
|
48
|
+
* <HeadCell sortDirection={sort} sortPriority={state.length > 1 ? priority : undefined} />
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const getSortForFields: <T>(field: T, state: MultiSortField<T> | null) => MultiSortFieldState;
|
|
52
|
+
/**
|
|
53
|
+
* Pure reducer behind {@link useMultiSort}. Each field cycles through three
|
|
54
|
+
* states on successive clicks: `startFromSort` → the opposite direction →
|
|
55
|
+
* removed. Clicking a brand-new field makes it the primary key (existing keys
|
|
56
|
+
* become tie-breakers) and the lowest-priority key is dropped once `maxFields`
|
|
57
|
+
* is reached.
|
|
58
|
+
*/
|
|
59
|
+
export declare function nextMultiSortState<T>(prev: MultiSortField<T>, field: T, startFromSort?: SortType, maxFields?: number): MultiSortField<T>;
|
|
60
|
+
export interface UseMultiSortOptions {
|
|
61
|
+
/** Maximum number of simultaneously active sort keys. Defaults to `2`. */
|
|
62
|
+
maxFields?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hook for managing sort state across multiple fields (e.g. sort by `type`,
|
|
66
|
+
* then by `apy`). Mirrors {@link useSort} but keeps an ordered list of keys.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useMultiSort<T>(initialState?: MultiSortField<T> | null, { maxFields }?: UseMultiSortOptions): readonly [MultiSortField<T>, MultiSortSetterFunction<T>, {
|
|
69
|
+
readonly removeSortField: (field: T) => void;
|
|
70
|
+
readonly resetSort: () => void;
|
|
71
|
+
}];
|
|
26
72
|
interface GeneralRangeFilterState {
|
|
27
73
|
state: FilterRange | null;
|
|
28
74
|
}
|