react-lookup-select 1.0.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/dist/index.cjs +1604 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +1567 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +873 -0
- package/package.json +75 -0
- package/readme.md +274 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Selection mode: single or multiple
|
|
6
|
+
*/
|
|
7
|
+
type SelectMode = 'single' | 'multiple';
|
|
8
|
+
/**
|
|
9
|
+
* Theme types
|
|
10
|
+
*/
|
|
11
|
+
type Theme = 'default' | 'dark' | 'minimal' | 'compact';
|
|
12
|
+
/**
|
|
13
|
+
* Size variants
|
|
14
|
+
*/
|
|
15
|
+
type Size = 'small' | 'medium' | 'large';
|
|
16
|
+
/**
|
|
17
|
+
* Grid column definition
|
|
18
|
+
* @template T - Data type
|
|
19
|
+
*/
|
|
20
|
+
type ColumnDef<T> = {
|
|
21
|
+
/** Data field (string is also supported) */
|
|
22
|
+
key: keyof T | string;
|
|
23
|
+
/** Column title */
|
|
24
|
+
title: string;
|
|
25
|
+
/** Optional width */
|
|
26
|
+
width?: number | string;
|
|
27
|
+
/** Can trigger server/client sort */
|
|
28
|
+
sortable?: boolean;
|
|
29
|
+
/** Custom cell render function */
|
|
30
|
+
render?: (row: T, index: number) => ReactNode;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Query state - pagination, search and sorting information
|
|
34
|
+
*/
|
|
35
|
+
type QueryState = {
|
|
36
|
+
/** Page number */
|
|
37
|
+
page: number;
|
|
38
|
+
/** Page size */
|
|
39
|
+
pageSize: number;
|
|
40
|
+
/** Search text */
|
|
41
|
+
search?: string;
|
|
42
|
+
/** Sort column */
|
|
43
|
+
sortBy?: string;
|
|
44
|
+
/** Sort direction */
|
|
45
|
+
sortDir?: 'asc' | 'desc';
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* DataSource function return result
|
|
49
|
+
* @template T - Data type
|
|
50
|
+
*/
|
|
51
|
+
type DataSourceResult<T> = {
|
|
52
|
+
/** Row data */
|
|
53
|
+
rows: T[];
|
|
54
|
+
/** Total record count */
|
|
55
|
+
total: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Server-side data source function
|
|
59
|
+
* @template T - Data type
|
|
60
|
+
*/
|
|
61
|
+
type DataSourceFn<T> = (q: QueryState) => Promise<DataSourceResult<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* Value mapping functions
|
|
64
|
+
* @template T - Data type
|
|
65
|
+
*/
|
|
66
|
+
type ValueMapper<T> = {
|
|
67
|
+
/** ID getter function */
|
|
68
|
+
getId: (row: T) => string | number;
|
|
69
|
+
/** Text getter function - e.g: (r) => `${r.name} ${r.surname}` */
|
|
70
|
+
getText: (row: T) => string;
|
|
71
|
+
/** Optional: disable check */
|
|
72
|
+
getDisabled?: (row: T) => boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Return value shape
|
|
76
|
+
*/
|
|
77
|
+
type ReturnShape = 'id-text' | 'row' | 'custom';
|
|
78
|
+
/**
|
|
79
|
+
* Custom return value mapping
|
|
80
|
+
* @template T - Data type
|
|
81
|
+
*/
|
|
82
|
+
type ReturnMap<T> = {
|
|
83
|
+
/** Custom mapping function - e.g: (r) => ({ id: r.userId, label: `${r.name} ${r.surname}` }) */
|
|
84
|
+
map: (row: T) => any;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* i18n text translations - Comprehensive multilingual support
|
|
88
|
+
*/
|
|
89
|
+
type i18nStrings = {
|
|
90
|
+
/** Trigger placeholder - "Please select" */
|
|
91
|
+
triggerPlaceholder?: string;
|
|
92
|
+
/** Search placeholder - "Search" */
|
|
93
|
+
searchPlaceholder?: string;
|
|
94
|
+
/** Confirm button - "Apply" */
|
|
95
|
+
confirmText?: string;
|
|
96
|
+
/** Cancel button - "Cancel" */
|
|
97
|
+
cancelText?: string;
|
|
98
|
+
/** Modal title - "Select Record" */
|
|
99
|
+
modalTitle?: string;
|
|
100
|
+
/** Empty state text - "No records found" */
|
|
101
|
+
emptyText?: string;
|
|
102
|
+
/** Loading text - "Loading..." */
|
|
103
|
+
loadingText?: string;
|
|
104
|
+
/** Error state prefix - "Error:" */
|
|
105
|
+
errorPrefix?: string;
|
|
106
|
+
/** Selected count - "{n} selected" */
|
|
107
|
+
selectedCount?: (n: number) => string;
|
|
108
|
+
/** Clear button - "Clear" */
|
|
109
|
+
clearText?: string;
|
|
110
|
+
/** Select all checkbox aria-label */
|
|
111
|
+
selectAllLabel?: string;
|
|
112
|
+
/** Row selection checkbox aria-label */
|
|
113
|
+
selectRowLabel?: (rowText: string) => string;
|
|
114
|
+
/** Sort button aria-label */
|
|
115
|
+
sortColumnLabel?: (columnTitle: string) => string;
|
|
116
|
+
/** Modal close button aria-label */
|
|
117
|
+
closeModalLabel?: string;
|
|
118
|
+
/** Pagination info - "Page {current} / {total}" */
|
|
119
|
+
paginationInfo?: (current: number, total: number) => string;
|
|
120
|
+
/** Total record count - "{total} records" */
|
|
121
|
+
totalRecords?: (total: number) => string;
|
|
122
|
+
/** Page size selector - "Show {size} records" */
|
|
123
|
+
pageSize?: (size: number) => string;
|
|
124
|
+
/** First page - "First" */
|
|
125
|
+
firstPage?: string;
|
|
126
|
+
/** Last page - "Last" */
|
|
127
|
+
lastPage?: string;
|
|
128
|
+
/** Previous page - "Previous" */
|
|
129
|
+
previousPage?: string;
|
|
130
|
+
/** Next page - "Next" */
|
|
131
|
+
nextPage?: string;
|
|
132
|
+
/** Search result info - "{count} results found" */
|
|
133
|
+
searchResults?: (count: number) => string;
|
|
134
|
+
/** Clear filters - "Clear filters" */
|
|
135
|
+
clearFilters?: string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Component overrides - preserves headless core
|
|
139
|
+
*/
|
|
140
|
+
type ComponentsOverrides = {
|
|
141
|
+
/** Custom trigger component */
|
|
142
|
+
Trigger?: React.ComponentType<any>;
|
|
143
|
+
/** Custom modal component */
|
|
144
|
+
Modal?: React.ComponentType<any>;
|
|
145
|
+
/** Custom grid component */
|
|
146
|
+
Grid?: React.ComponentType<any>;
|
|
147
|
+
/** Custom checkbox component */
|
|
148
|
+
Checkbox?: React.ComponentType<any>;
|
|
149
|
+
/** Custom icon component */
|
|
150
|
+
Icon?: React.ComponentType<any>;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* CSS class names - class override for each part
|
|
154
|
+
*/
|
|
155
|
+
type ClassNames = {
|
|
156
|
+
/** Root container class */
|
|
157
|
+
root?: string;
|
|
158
|
+
/** Trigger class */
|
|
159
|
+
trigger?: string;
|
|
160
|
+
/** Modal class */
|
|
161
|
+
modal?: string;
|
|
162
|
+
/** Header class */
|
|
163
|
+
header?: string;
|
|
164
|
+
/** Footer class */
|
|
165
|
+
footer?: string;
|
|
166
|
+
/** Grid class */
|
|
167
|
+
grid?: string;
|
|
168
|
+
/** Row class */
|
|
169
|
+
row?: string;
|
|
170
|
+
/** Cell class */
|
|
171
|
+
cell?: string;
|
|
172
|
+
/** Selected item chip/tag class */
|
|
173
|
+
tag?: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Inline style injection areas
|
|
177
|
+
*/
|
|
178
|
+
type Styles = Partial<{
|
|
179
|
+
/** Root container styles */
|
|
180
|
+
root: React.CSSProperties;
|
|
181
|
+
/** Trigger styles */
|
|
182
|
+
trigger: React.CSSProperties;
|
|
183
|
+
/** Modal styles */
|
|
184
|
+
modal: React.CSSProperties;
|
|
185
|
+
/** Header styles */
|
|
186
|
+
header: React.CSSProperties;
|
|
187
|
+
/** Footer styles */
|
|
188
|
+
footer: React.CSSProperties;
|
|
189
|
+
/** Grid styles */
|
|
190
|
+
grid: React.CSSProperties;
|
|
191
|
+
/** Row styles */
|
|
192
|
+
row: React.CSSProperties;
|
|
193
|
+
/** Cell styles */
|
|
194
|
+
cell: React.CSSProperties;
|
|
195
|
+
/** Tag styles */
|
|
196
|
+
tag: React.CSSProperties;
|
|
197
|
+
}>;
|
|
198
|
+
/**
|
|
199
|
+
* Theme tokens - can be bridged with CSS variables
|
|
200
|
+
*/
|
|
201
|
+
type ThemeTokens = Partial<{
|
|
202
|
+
/** Primary color */
|
|
203
|
+
colorPrimary: string;
|
|
204
|
+
/** Background color */
|
|
205
|
+
colorBg: string;
|
|
206
|
+
/** Text color */
|
|
207
|
+
colorText: string;
|
|
208
|
+
/** Border radius */
|
|
209
|
+
borderRadius: string | number;
|
|
210
|
+
/** Spacing multiplier */
|
|
211
|
+
spacing: number;
|
|
212
|
+
}>;
|
|
213
|
+
/**
|
|
214
|
+
* Main LookupSelect component props interface
|
|
215
|
+
* @template T - Data type
|
|
216
|
+
*/
|
|
217
|
+
type LookupSelectProps<T> = {
|
|
218
|
+
/** Selection mode - default: 'single' */
|
|
219
|
+
mode?: SelectMode;
|
|
220
|
+
/** Client-side data array */
|
|
221
|
+
data?: T[];
|
|
222
|
+
/** Server-side data source function */
|
|
223
|
+
dataSource?: DataSourceFn<T>;
|
|
224
|
+
/** Grid columns definition */
|
|
225
|
+
columns: ColumnDef<T>[];
|
|
226
|
+
/** ID/text/disabled generator */
|
|
227
|
+
mapper: ValueMapper<T>;
|
|
228
|
+
/** Controlled value */
|
|
229
|
+
value?: T | T[] | null;
|
|
230
|
+
/** Uncontrolled initial value */
|
|
231
|
+
defaultValue?: T | T[] | null;
|
|
232
|
+
/** Value change callback - according to return shape */
|
|
233
|
+
onChange?: (val: any) => void;
|
|
234
|
+
/** Return value format - 'id-text' (default) | 'row' | 'custom' */
|
|
235
|
+
returnShape?: ReturnShape;
|
|
236
|
+
/** Custom return mapping - only for 'custom' */
|
|
237
|
+
returnMap?: ReturnMap<T>;
|
|
238
|
+
/** Controlled modal state */
|
|
239
|
+
open?: boolean;
|
|
240
|
+
/** Uncontrolled modal initial state */
|
|
241
|
+
defaultOpen?: boolean;
|
|
242
|
+
/** Modal state change callback */
|
|
243
|
+
onOpenChange?: (open: boolean) => void;
|
|
244
|
+
/** Modal title - i18n.modalTitle override */
|
|
245
|
+
modalTitle?: string;
|
|
246
|
+
/** Trigger icon override */
|
|
247
|
+
icon?: ReactNode;
|
|
248
|
+
/** Completely custom trigger render function */
|
|
249
|
+
renderTrigger?: (selected: T | T[] | null) => ReactNode;
|
|
250
|
+
/** Row-based selection constraint function */
|
|
251
|
+
selectableRow?: (row: T) => boolean;
|
|
252
|
+
/** Is virtualization active for large data? */
|
|
253
|
+
virtualization?: boolean;
|
|
254
|
+
/** Fixed row height for virtual grid (px) - default: 40 */
|
|
255
|
+
virtualRowHeight?: number;
|
|
256
|
+
/** Number of extra rows to render outside visible area - default: 5 */
|
|
257
|
+
virtualOverscan?: number;
|
|
258
|
+
/** Virtual container height (px) - default: 400 */
|
|
259
|
+
virtualContainerHeight?: number;
|
|
260
|
+
/** Virtualization threshold - activates with more items than this number - default: 100 */
|
|
261
|
+
virtualThreshold?: number;
|
|
262
|
+
/** Page size - default 20 */
|
|
263
|
+
pageSize?: number;
|
|
264
|
+
/** Predefined theme */
|
|
265
|
+
variant?: Theme;
|
|
266
|
+
/** Size variant */
|
|
267
|
+
size?: Size;
|
|
268
|
+
/** CSS class names */
|
|
269
|
+
classNames?: ClassNames;
|
|
270
|
+
/** Inline styles */
|
|
271
|
+
styles?: Styles;
|
|
272
|
+
/** Theme tokens */
|
|
273
|
+
theme?: ThemeTokens;
|
|
274
|
+
/** Low level component overrides */
|
|
275
|
+
components?: ComponentsOverrides;
|
|
276
|
+
/** Text translations */
|
|
277
|
+
i18n?: i18nStrings;
|
|
278
|
+
/** Search/sort/page change callback */
|
|
279
|
+
onQueryChange?: (q: QueryState) => void;
|
|
280
|
+
/** "Apply" button callback */
|
|
281
|
+
onConfirm?: (val: any) => void;
|
|
282
|
+
/** Modal close callback */
|
|
283
|
+
onCancel?: () => void;
|
|
284
|
+
/** Modal internal selection change callback */
|
|
285
|
+
onSelectionChange?: (rows: T[]) => void;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* LookupSelect - Headless React lookup select component with modal and grid
|
|
290
|
+
*/
|
|
291
|
+
declare function LookupSelect<T = any>(props: LookupSelectProps<T>): react_jsx_runtime.JSX.Element;
|
|
292
|
+
|
|
293
|
+
export { type ClassNames, type ColumnDef, type ComponentsOverrides, type DataSourceFn, type DataSourceResult, LookupSelect, type LookupSelectProps, type QueryState, type ReturnMap, type ReturnShape, type SelectMode, type Styles, type ThemeTokens, type ValueMapper, type i18nStrings };
|