react-lookup-select 1.0.3 → 1.0.5
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/LICENSE +21 -0
- package/dist/index.cjs +128 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -1
- package/dist/index.d.ts +152 -1
- package/dist/index.js +129 -42
- package/dist/index.js.map +1 -1
- package/dist/styles.css +49 -59
- package/package.json +1 -1
- package/readme.md +162 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Onur Altuntaş
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -217,6 +217,7 @@ function useLookupSelectState(props) {
|
|
|
217
217
|
return new QueryManager({ pageSize });
|
|
218
218
|
}, [pageSize]);
|
|
219
219
|
const [currentSelections, setCurrentSelections] = (0, import_react.useState)([]);
|
|
220
|
+
const [backupSelections, setBackupSelections] = (0, import_react.useState)([]);
|
|
220
221
|
const resolveValueToRows = (0, import_react.useCallback)(
|
|
221
222
|
(valueToResolve) => {
|
|
222
223
|
if (!valueToResolve || !data) return [];
|
|
@@ -256,15 +257,19 @@ function useLookupSelectState(props) {
|
|
|
256
257
|
const newState = selectionManager.toggleRow(row);
|
|
257
258
|
const selectedRows = selectionManager.getSelectedRows();
|
|
258
259
|
setCurrentSelections(selectedRows);
|
|
259
|
-
|
|
260
|
+
if (!modalOpen) {
|
|
261
|
+
onSelectionChange?.(selectedRows);
|
|
262
|
+
}
|
|
260
263
|
},
|
|
261
|
-
[selectionManager, onSelectionChange]
|
|
264
|
+
[selectionManager, onSelectionChange, modalOpen]
|
|
262
265
|
);
|
|
263
266
|
const clearSelections = (0, import_react.useCallback)(() => {
|
|
264
267
|
selectionManager.clearSelection();
|
|
265
268
|
setCurrentSelections([]);
|
|
266
|
-
|
|
267
|
-
|
|
269
|
+
if (!modalOpen) {
|
|
270
|
+
onSelectionChange?.([]);
|
|
271
|
+
}
|
|
272
|
+
}, [selectionManager, onSelectionChange, modalOpen]);
|
|
268
273
|
const isRowSelected = (0, import_react.useCallback)(
|
|
269
274
|
(row) => {
|
|
270
275
|
return selectionManager.isRowSelected(row);
|
|
@@ -314,17 +319,24 @@ function useLookupSelectState(props) {
|
|
|
314
319
|
]);
|
|
315
320
|
const cancelSelection = (0, import_react.useCallback)(() => {
|
|
316
321
|
selectionManager.clearSelection();
|
|
317
|
-
|
|
322
|
+
for (const row of backupSelections) {
|
|
323
|
+
selectionManager.toggleRow(row);
|
|
324
|
+
}
|
|
325
|
+
setCurrentSelections([...backupSelections]);
|
|
318
326
|
onCancel?.();
|
|
319
327
|
handleModalOpenChange(false);
|
|
320
|
-
}, [selectionManager, onCancel, handleModalOpenChange]);
|
|
328
|
+
}, [selectionManager, backupSelections, onCancel, handleModalOpenChange]);
|
|
321
329
|
const getCurrentQuery = (0, import_react.useCallback)(() => {
|
|
322
330
|
return queryManager.getState();
|
|
323
331
|
}, [queryManager]);
|
|
332
|
+
const openModal = (0, import_react.useCallback)(() => {
|
|
333
|
+
setBackupSelections([...currentSelections]);
|
|
334
|
+
handleModalOpenChange(true);
|
|
335
|
+
}, [currentSelections, handleModalOpenChange]);
|
|
324
336
|
return {
|
|
325
337
|
// Modal state
|
|
326
338
|
modalOpen,
|
|
327
|
-
openModal
|
|
339
|
+
openModal,
|
|
328
340
|
closeModal: () => handleModalOpenChange(false),
|
|
329
341
|
// Selection state
|
|
330
342
|
currentSelections,
|
|
@@ -1292,6 +1304,12 @@ function LookupSelect(props) {
|
|
|
1292
1304
|
size = "medium",
|
|
1293
1305
|
icon,
|
|
1294
1306
|
renderTrigger,
|
|
1307
|
+
renderModal,
|
|
1308
|
+
renderGrid,
|
|
1309
|
+
renderHeader,
|
|
1310
|
+
renderFooter,
|
|
1311
|
+
renderSearch,
|
|
1312
|
+
renderPagination,
|
|
1295
1313
|
modalTitle,
|
|
1296
1314
|
classNames,
|
|
1297
1315
|
styles,
|
|
@@ -1455,7 +1473,7 @@ function LookupSelect(props) {
|
|
|
1455
1473
|
virtualThreshold
|
|
1456
1474
|
]
|
|
1457
1475
|
);
|
|
1458
|
-
const
|
|
1476
|
+
const renderGridComponent = import_react5.default.useCallback(() => {
|
|
1459
1477
|
const commonGridProps = {
|
|
1460
1478
|
data: currentData,
|
|
1461
1479
|
columns,
|
|
@@ -1506,6 +1524,96 @@ function LookupSelect(props) {
|
|
|
1506
1524
|
shouldUseVirtualization,
|
|
1507
1525
|
virtualizationConfig
|
|
1508
1526
|
]);
|
|
1527
|
+
const renderModalContent = () => {
|
|
1528
|
+
const defaultContent = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1529
|
+
renderSearch ? renderSearch({
|
|
1530
|
+
value: searchValue,
|
|
1531
|
+
onChange: handleSearchChange,
|
|
1532
|
+
placeholder: texts.searchPlaceholder,
|
|
1533
|
+
loading,
|
|
1534
|
+
onClear: () => handleSearchChange("")
|
|
1535
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1536
|
+
SearchInput,
|
|
1537
|
+
{
|
|
1538
|
+
value: searchValue,
|
|
1539
|
+
onChange: handleSearchChange,
|
|
1540
|
+
placeholder: texts.searchPlaceholder
|
|
1541
|
+
}
|
|
1542
|
+
),
|
|
1543
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "lookup-select__modal-content", children: [
|
|
1544
|
+
renderGrid ? renderGrid({
|
|
1545
|
+
data: currentData,
|
|
1546
|
+
columns,
|
|
1547
|
+
selectedIds: currentSelections.map(mapper.getId),
|
|
1548
|
+
onRowSelect: toggleRowSelection,
|
|
1549
|
+
onSelectAll: mode === "multiple" ? () => {
|
|
1550
|
+
const allIds = currentData.map(mapper.getId);
|
|
1551
|
+
const selectedIds = currentSelections.map(mapper.getId);
|
|
1552
|
+
if (allIds.length === selectedIds.length) {
|
|
1553
|
+
clearSelections();
|
|
1554
|
+
} else {
|
|
1555
|
+
currentData.forEach((row) => {
|
|
1556
|
+
if (!isRowSelected(row)) {
|
|
1557
|
+
toggleRowSelection(row);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
} : void 0,
|
|
1562
|
+
onClearAll: clearSelections,
|
|
1563
|
+
loading,
|
|
1564
|
+
error,
|
|
1565
|
+
mode,
|
|
1566
|
+
mapper,
|
|
1567
|
+
virtualization: shouldUseVirtualization ? virtualizationConfig : void 0,
|
|
1568
|
+
selectableRow,
|
|
1569
|
+
onSortChange: handleSortChange,
|
|
1570
|
+
sortBy: getCurrentQuery().sortBy,
|
|
1571
|
+
sortDir: getCurrentQuery().sortDir
|
|
1572
|
+
}) : renderGridComponent(),
|
|
1573
|
+
dataSource && !renderPagination && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1574
|
+
Pagination,
|
|
1575
|
+
{
|
|
1576
|
+
currentPage,
|
|
1577
|
+
totalCount,
|
|
1578
|
+
pageSize: optimizedPageSize,
|
|
1579
|
+
onPageChange: handlePageChange
|
|
1580
|
+
}
|
|
1581
|
+
),
|
|
1582
|
+
dataSource && renderPagination && renderPagination({
|
|
1583
|
+
currentPage,
|
|
1584
|
+
totalPages: Math.ceil(totalCount / optimizedPageSize),
|
|
1585
|
+
onPageChange: handlePageChange,
|
|
1586
|
+
pageSize: optimizedPageSize,
|
|
1587
|
+
onPageSizeChange: (newSize) => {
|
|
1588
|
+
},
|
|
1589
|
+
totalCount,
|
|
1590
|
+
loading
|
|
1591
|
+
})
|
|
1592
|
+
] }),
|
|
1593
|
+
renderFooter ? renderFooter({
|
|
1594
|
+
selectedCount: currentSelections.length,
|
|
1595
|
+
totalCount,
|
|
1596
|
+
onConfirm: confirmSelection,
|
|
1597
|
+
onCancel: cancelSelection,
|
|
1598
|
+
currentPage,
|
|
1599
|
+
totalPages: Math.ceil(totalCount / optimizedPageSize),
|
|
1600
|
+
onPageChange: handlePageChange,
|
|
1601
|
+
pageSize: optimizedPageSize,
|
|
1602
|
+
loading,
|
|
1603
|
+
mode
|
|
1604
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1605
|
+
ModalFooter,
|
|
1606
|
+
{
|
|
1607
|
+
onConfirm: confirmSelection,
|
|
1608
|
+
onCancel: cancelSelection,
|
|
1609
|
+
confirmText: texts.confirmText,
|
|
1610
|
+
cancelText: texts.cancelText,
|
|
1611
|
+
selectedCount: currentSelections.length
|
|
1612
|
+
}
|
|
1613
|
+
)
|
|
1614
|
+
] });
|
|
1615
|
+
return defaultContent;
|
|
1616
|
+
};
|
|
1509
1617
|
const getThemeClasses = () => {
|
|
1510
1618
|
const classes = ["lookup-select"];
|
|
1511
1619
|
if (variant && variant !== "default") {
|
|
@@ -1553,7 +1661,17 @@ function LookupSelect(props) {
|
|
|
1553
1661
|
onRemoveTag: (item) => toggleRowSelection(item)
|
|
1554
1662
|
}
|
|
1555
1663
|
),
|
|
1556
|
-
|
|
1664
|
+
renderModal ? renderModal({
|
|
1665
|
+
isOpen: modalOpen,
|
|
1666
|
+
onClose: cancelSelection,
|
|
1667
|
+
children: renderModalContent(),
|
|
1668
|
+
title: modalTitle || texts.modalTitle,
|
|
1669
|
+
loading,
|
|
1670
|
+
error,
|
|
1671
|
+
query: getCurrentQuery(),
|
|
1672
|
+
selectedCount: currentSelections.length,
|
|
1673
|
+
totalCount
|
|
1674
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1557
1675
|
Modal,
|
|
1558
1676
|
{
|
|
1559
1677
|
isOpen: modalOpen,
|
|
@@ -1561,38 +1679,7 @@ function LookupSelect(props) {
|
|
|
1561
1679
|
title: modalTitle || texts.modalTitle,
|
|
1562
1680
|
className: classNames?.modal,
|
|
1563
1681
|
style: styles?.modal,
|
|
1564
|
-
children:
|
|
1565
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1566
|
-
SearchInput,
|
|
1567
|
-
{
|
|
1568
|
-
value: searchValue,
|
|
1569
|
-
onChange: handleSearchChange,
|
|
1570
|
-
placeholder: texts.searchPlaceholder
|
|
1571
|
-
}
|
|
1572
|
-
),
|
|
1573
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "lookup-select__modal-content", children: [
|
|
1574
|
-
renderGrid(),
|
|
1575
|
-
dataSource && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1576
|
-
Pagination,
|
|
1577
|
-
{
|
|
1578
|
-
currentPage,
|
|
1579
|
-
totalCount,
|
|
1580
|
-
pageSize: optimizedPageSize,
|
|
1581
|
-
onPageChange: handlePageChange
|
|
1582
|
-
}
|
|
1583
|
-
)
|
|
1584
|
-
] }),
|
|
1585
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1586
|
-
ModalFooter,
|
|
1587
|
-
{
|
|
1588
|
-
onConfirm: confirmSelection,
|
|
1589
|
-
onCancel: cancelSelection,
|
|
1590
|
-
confirmText: texts.confirmText,
|
|
1591
|
-
cancelText: texts.cancelText,
|
|
1592
|
-
selectedCount: currentSelections.length
|
|
1593
|
-
}
|
|
1594
|
-
)
|
|
1595
|
-
]
|
|
1682
|
+
children: renderModalContent()
|
|
1596
1683
|
}
|
|
1597
1684
|
)
|
|
1598
1685
|
] });
|