@synerise/ds-table-new 0.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/CHANGELOG.md +10 -0
- package/LICENSE.md +21 -0
- package/README.md +153 -0
- package/dist/Table.const.d.ts +20 -0
- package/dist/Table.const.js +42 -0
- package/dist/Table.d.ts +3 -0
- package/dist/Table.js +51 -0
- package/dist/Table.styles.d.ts +15 -0
- package/dist/Table.styles.js +29 -0
- package/dist/Table.types.d.ts +359 -0
- package/dist/Table.types.js +1 -0
- package/dist/VirtualTable.d.ts +3 -0
- package/dist/VirtualTable.js +222 -0
- package/dist/components/BaseTable/BaseTable.d.ts +3 -0
- package/dist/components/BaseTable/BaseTable.js +114 -0
- package/dist/components/BaseTable/BaseTable.styles.d.ts +28 -0
- package/dist/components/BaseTable/BaseTable.styles.js +41 -0
- package/dist/components/Cell/Action/ActionCell.d.ts +3 -0
- package/dist/components/Cell/Action/ActionCell.js +16 -0
- package/dist/components/Cell/Action/ActionCell.styles.d.ts +5 -0
- package/dist/components/Cell/Action/ActionCell.styles.js +13 -0
- package/dist/components/Cell/Action/ActionCell.types.d.ts +13 -0
- package/dist/components/Cell/Action/ActionCell.types.js +1 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.d.ts +4 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.js +42 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.styles.d.ts +27 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.styles.js +49 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.types.d.ts +22 -0
- package/dist/components/Cell/AvatarLabel/AvatarLabel.types.js +1 -0
- package/dist/components/Cell/Copyable/Copyable.styles.d.ts +2 -0
- package/dist/components/Cell/Copyable/Copyable.styles.js +14 -0
- package/dist/components/Cell/Copyable/Copyable.types.d.ts +11 -0
- package/dist/components/Cell/Copyable/Copyable.types.js +1 -0
- package/dist/components/Cell/Copyable/CopyableCell.d.ts +4 -0
- package/dist/components/Cell/Copyable/CopyableCell.js +28 -0
- package/dist/components/Cell/Editable/EditableCell.d.ts +4 -0
- package/dist/components/Cell/Editable/EditableCell.js +30 -0
- package/dist/components/Cell/Editable/EditableCell.styles.d.ts +4 -0
- package/dist/components/Cell/Editable/EditableCell.styles.js +14 -0
- package/dist/components/Cell/Editable/EditableCell.types.d.ts +11 -0
- package/dist/components/Cell/Editable/EditableCell.types.js +1 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.d.ts +4 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.js +16 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.styles.d.ts +1 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.styles.js +8 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.types.d.ts +11 -0
- package/dist/components/Cell/FlagLabel/FlagLabelCell.types.js +1 -0
- package/dist/components/Cell/IconLabel/IconLabel.d.ts +4 -0
- package/dist/components/Cell/IconLabel/IconLabel.js +15 -0
- package/dist/components/Cell/IconLabel/IconLabel.styles.d.ts +3 -0
- package/dist/components/Cell/IconLabel/IconLabel.styles.js +9 -0
- package/dist/components/Cell/IconLabel/IconLabel.types.d.ts +13 -0
- package/dist/components/Cell/IconLabel/IconLabel.types.js +1 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.d.ts +4 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.js +19 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.styles.d.ts +4 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.styles.js +13 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.types.d.ts +16 -0
- package/dist/components/Cell/IconTooltipCell/IconTooltipCell.types.js +1 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.d.ts +4 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.js +11 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.styles.d.ts +3 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.styles.js +11 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.types.d.ts +7 -0
- package/dist/components/Cell/InputNumber/InputNumberCell.types.js +1 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.d.ts +5 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.js +33 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.styles.d.ts +3 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.styles.js +18 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.types.d.ts +22 -0
- package/dist/components/Cell/LabelsWithShowMore/LabelsWithShowMore.types.js +1 -0
- package/dist/components/Cell/LabelsWithShowMore/Modal/Modal.d.ts +4 -0
- package/dist/components/Cell/LabelsWithShowMore/Modal/Modal.js +37 -0
- package/dist/components/Cell/LabelsWithShowMore/Modal/Modal.types.d.ts +15 -0
- package/dist/components/Cell/LabelsWithShowMore/Modal/Modal.types.js +1 -0
- package/dist/components/Cell/Star/StarCell.d.ts +4 -0
- package/dist/components/Cell/Star/StarCell.js +25 -0
- package/dist/components/Cell/Star/StarCell.styles.d.ts +5 -0
- package/dist/components/Cell/Star/StarCell.styles.js +16 -0
- package/dist/components/Cell/Star/StarCell.types.d.ts +17 -0
- package/dist/components/Cell/Star/StarCell.types.js +1 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.d.ts +4 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.js +18 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.styles.d.ts +4 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.styles.js +13 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.types.d.ts +14 -0
- package/dist/components/Cell/StatusLabel/StatusLabel.types.js +1 -0
- package/dist/components/Cell/TagIcon/TagIcon.d.ts +4 -0
- package/dist/components/Cell/TagIcon/TagIcon.js +10 -0
- package/dist/components/Cell/TagIcon/TagIcon.styles.d.ts +3 -0
- package/dist/components/Cell/TagIcon/TagIcon.styles.js +9 -0
- package/dist/components/Cell/TagIcon/TagIcon.types.d.ts +11 -0
- package/dist/components/Cell/TagIcon/TagIcon.types.js +1 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.d.ts +3 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.js +26 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.styles.d.ts +5 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.styles.js +34 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.types.d.ts +9 -0
- package/dist/components/Cell/TagsGroup/TagsGroup.types.js +1 -0
- package/dist/components/Cell/index.d.ts +26 -0
- package/dist/components/Cell/index.js +28 -0
- package/dist/components/TableBody/TableBody.d.ts +3 -0
- package/dist/components/TableBody/TableBody.js +40 -0
- package/dist/components/TableBody/TableBody.styles.d.ts +2 -0
- package/dist/components/TableBody/TableBody.styles.js +15 -0
- package/dist/components/TableBody/TableBodySkeleton/TableBodySkeleton.d.ts +5 -0
- package/dist/components/TableBody/TableBodySkeleton/TableBodySkeleton.js +42 -0
- package/dist/components/TableBody/TableBodySkeleton/TableBodySkeleton.styles.d.ts +9 -0
- package/dist/components/TableBody/TableBodySkeleton/TableBodySkeleton.styles.js +30 -0
- package/dist/components/TableBody/TableCell/TableCell.d.ts +16 -0
- package/dist/components/TableBody/TableCell/TableCell.js +19 -0
- package/dist/components/TableBody/TableCell/TableCell.styles.d.ts +10 -0
- package/dist/components/TableBody/TableCell/TableCell.styles.js +18 -0
- package/dist/components/TableBody/TableEmptyBody/TableEmptyBody.d.ts +3 -0
- package/dist/components/TableBody/TableEmptyBody/TableEmptyBody.js +18 -0
- package/dist/components/TableBody/TableEmptyBody/TableEmptyBody.styles.d.ts +4 -0
- package/dist/components/TableBody/TableEmptyBody/TableEmptyBody.styles.js +23 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/ErrorItem.d.ts +8 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/ErrorItem.js +19 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/ErrorItem.styles.d.ts +1 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/ErrorItem.styles.js +8 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/InfiniteLoaderRow.d.ts +14 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/InfiniteLoaderRow.js +50 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/LoadingItem.d.ts +5 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/LoadingItem.js +10 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/LoadingItem.styles.d.ts +1 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/LoadingItem.styles.js +9 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/NoMoreItem.d.ts +5 -0
- package/dist/components/TableBody/TableRow/InfiniteLoaderRow/NoMoreItem.js +10 -0
- package/dist/components/TableBody/TableRow/TableRow.d.ts +5 -0
- package/dist/components/TableBody/TableRow/TableRow.js +29 -0
- package/dist/components/TableBody/TableRow/TableRow.styles.d.ts +7 -0
- package/dist/components/TableBody/TableRow/TableRow.styles.js +15 -0
- package/dist/components/TableBody/TableRow/TableRowVirtual.d.ts +5 -0
- package/dist/components/TableBody/TableRow/TableRowVirtual.js +88 -0
- package/dist/components/TableBody/TableRowSelection/TableRowSelection.d.ts +3 -0
- package/dist/components/TableBody/TableRowSelection/TableRowSelection.js +39 -0
- package/dist/components/TableColumns/TableColumnSorter/SortIcons/DefaultSortIcon.d.ts +5 -0
- package/dist/components/TableColumns/TableColumnSorter/SortIcons/DefaultSortIcon.js +19 -0
- package/dist/components/TableColumns/TableColumnSorter/SortIcons/StringSortIcon.d.ts +5 -0
- package/dist/components/TableColumns/TableColumnSorter/SortIcons/StringSortIcon.js +19 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.const.d.ts +4 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.const.js +8 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.d.ts +3 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.js +75 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.styles.d.ts +30 -0
- package/dist/components/TableColumns/TableColumnSorter/TableColumnSorter.styles.js +11 -0
- package/dist/components/TableColumns/TableColumns.d.ts +3 -0
- package/dist/components/TableColumns/TableColumns.js +28 -0
- package/dist/components/TableColumns/TableColumns.styles.d.ts +18 -0
- package/dist/components/TableColumns/TableColumns.styles.js +35 -0
- package/dist/components/TableHeader/TableCounter/TableCounter.d.ts +3 -0
- package/dist/components/TableHeader/TableCounter/TableCounter.js +33 -0
- package/dist/components/TableHeader/TableCounter/TableCounter.styles.d.ts +1 -0
- package/dist/components/TableHeader/TableCounter/TableCounter.styles.js +8 -0
- package/dist/components/TableHeader/TableHeader.d.ts +3 -0
- package/dist/components/TableHeader/TableHeader.js +103 -0
- package/dist/components/TableHeader/TableHeader.styles.d.ts +18 -0
- package/dist/components/TableHeader/TableHeader.styles.js +48 -0
- package/dist/components/TableHeader/TableHeaderSelection/TableHeaderSelection.d.ts +3 -0
- package/dist/components/TableHeader/TableHeaderSelection/TableHeaderSelection.js +123 -0
- package/dist/components/TableHeader/TableHeaderSelection/TableHeaderSelection.styles.d.ts +8 -0
- package/dist/components/TableHeader/TableHeaderSelection/TableHeaderSelection.styles.js +21 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.d.ts +3 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.js +50 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.styles.d.ts +4 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.styles.js +24 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.types.d.ts +10 -0
- package/dist/components/TableHeader/TableLimit/TableLimit.types.js +1 -0
- package/dist/components/TableHorizontalScroll/TableHorizontalScroll.d.ts +6 -0
- package/dist/components/TableHorizontalScroll/TableHorizontalScroll.js +41 -0
- package/dist/components/TableHorizontalScroll/TableHorizontalScroll.styles.d.ts +12 -0
- package/dist/components/TableHorizontalScroll/TableHorizontalScroll.styles.js +33 -0
- package/dist/components/TableHorizontalScrollBar/TableHorizontalScrollBar.d.ts +6 -0
- package/dist/components/TableHorizontalScrollBar/TableHorizontalScrollBar.js +11 -0
- package/dist/components/TableHorizontalScrollBar/TableHorizontalScrollBar.styles.d.ts +4 -0
- package/dist/components/TableHorizontalScrollBar/TableHorizontalScrollBar.styles.js +14 -0
- package/dist/components/TablePagination/TablePagination.d.ts +3 -0
- package/dist/components/TablePagination/TablePagination.js +19 -0
- package/dist/components/TablePagination/TablePagination.styles.d.ts +1 -0
- package/dist/components/TablePagination/TablePagination.styles.js +8 -0
- package/dist/contexts/SelectionContext.d.ts +4 -0
- package/dist/contexts/SelectionContext.js +10 -0
- package/dist/contexts/StickyContext.d.ts +8 -0
- package/dist/contexts/StickyContext.js +9 -0
- package/dist/contexts/TableContext.d.ts +11 -0
- package/dist/contexts/TableContext.js +13 -0
- package/dist/hooks/useColumnSizing.d.ts +23 -0
- package/dist/hooks/useColumnSizing.js +95 -0
- package/dist/hooks/useDefaultTexts.d.ts +2 -0
- package/dist/hooks/useDefaultTexts.js +95 -0
- package/dist/hooks/useInfiniteScroll.d.ts +13 -0
- package/dist/hooks/useInfiniteScroll.js +58 -0
- package/dist/hooks/useRowKey.d.ts +4 -0
- package/dist/hooks/useRowKey.js +27 -0
- package/dist/hooks/useScrollSync.d.ts +2 -0
- package/dist/hooks/useScrollSync.js +23 -0
- package/dist/hooks/useTable.d.ts +14 -0
- package/dist/hooks/useTable.js +168 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +50 -0
- package/dist/types/table.d.js +1 -0
- package/dist/types/table.d.ts +28 -0
- package/dist/utils/arrayToTrueMap.d.ts +1 -0
- package/dist/utils/arrayToTrueMap.js +7 -0
- package/dist/utils/calculatePixels.d.ts +1 -0
- package/dist/utils/calculatePixels.js +21 -0
- package/dist/utils/compareKeys.d.ts +1 -0
- package/dist/utils/compareKeys.js +16 -0
- package/dist/utils/getChildrenColumnName.d.ts +1 -0
- package/dist/utils/getChildrenColumnName.js +7 -0
- package/dist/utils/getDefaultSkeletonColumns.d.ts +2 -0
- package/dist/utils/getDefaultSkeletonColumns.js +58 -0
- package/dist/utils/getInfiniteScrollPadding.d.ts +2 -0
- package/dist/utils/getInfiniteScrollPadding.js +13 -0
- package/dist/utils/getIsRevealed.d.ts +5 -0
- package/dist/utils/getIsRevealed.js +9 -0
- package/dist/utils/getPaginationConfig.d.ts +10 -0
- package/dist/utils/getPaginationConfig.js +19 -0
- package/dist/utils/getRecordSelectionStatus.d.ts +5 -0
- package/dist/utils/getRecordSelectionStatus.js +13 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/isRecordSelectable.d.ts +2 -0
- package/dist/utils/isRecordSelectable.js +14 -0
- package/dist/utils/legacyColumnConfigAdapter.d.ts +3 -0
- package/dist/utils/legacyColumnConfigAdapter.js +113 -0
- package/dist/utils/processColumns.d.ts +3 -0
- package/dist/utils/processColumns.js +24 -0
- package/dist/utils/sort.d.ts +3 -0
- package/dist/utils/sort.js +14 -0
- package/package.json +76 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { DropdownMenu } from "@synerise/ds-dropdown";
|
|
4
|
+
import Icon, { OptionVerticalM } from "@synerise/ds-icon";
|
|
5
|
+
import Tooltip from "@synerise/ds-tooltip";
|
|
6
|
+
import { SELECTION_INVERT, SELECTION_ALL } from "../../../Table.const.js";
|
|
7
|
+
import { useSelectionContext } from "../../../contexts/SelectionContext.js";
|
|
8
|
+
import { useTableContext } from "../../../contexts/TableContext.js";
|
|
9
|
+
import { Selection, SelectionCheckbox, DropdownButton } from "./TableHeaderSelection.styles.js";
|
|
10
|
+
const TableHeaderSelection = ({
|
|
11
|
+
texts
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
table
|
|
15
|
+
} = useTableContext();
|
|
16
|
+
const selectionConfig = useSelectionContext();
|
|
17
|
+
const {
|
|
18
|
+
globalSelected,
|
|
19
|
+
globalSelectionOnChange,
|
|
20
|
+
limit: hasSelectionLimit
|
|
21
|
+
} = selectionConfig || {};
|
|
22
|
+
const hasGlobalSelection = globalSelectionOnChange !== void 0;
|
|
23
|
+
const isGlobalAllSelected = hasGlobalSelection && globalSelected;
|
|
24
|
+
const isAllSelected = table.getIsAllRowsSelected();
|
|
25
|
+
const isAnySelected = table.getIsSomeRowsSelected();
|
|
26
|
+
const allRecordsCount = table.getRowModel().rows.length;
|
|
27
|
+
const selectedRecordsCount = table.getFilteredSelectedRowModel().rows.length;
|
|
28
|
+
const selectableRecordsCount = table.getRowModel().rows.filter((row) => row.getCanSelect()).length;
|
|
29
|
+
const disabledBulkSelection = Boolean(allRecordsCount === 0 || selectableRecordsCount === 0 || hasSelectionLimit && selectedRecordsCount === 0);
|
|
30
|
+
const selectionTooltipTitle = useMemo(() => {
|
|
31
|
+
if (hasGlobalSelection) {
|
|
32
|
+
return isGlobalAllSelected ? texts.unselectGlobalAll : texts.selectGlobalAll;
|
|
33
|
+
}
|
|
34
|
+
return isAllSelected ? texts.unselectAll : texts.selectAllTooltip;
|
|
35
|
+
}, [hasGlobalSelection, isAllSelected, isGlobalAllSelected, texts.selectAllTooltip, texts.selectGlobalAll, texts.unselectAll, texts.unselectGlobalAll]);
|
|
36
|
+
const selectAll = useCallback(() => {
|
|
37
|
+
table.toggleAllRowsSelected(true);
|
|
38
|
+
}, [table]);
|
|
39
|
+
const unselectAll = useCallback(() => {
|
|
40
|
+
table.toggleAllRowsSelected(false);
|
|
41
|
+
}, [table]);
|
|
42
|
+
const selectGlobalAll = useCallback(() => {
|
|
43
|
+
unselectAll();
|
|
44
|
+
globalSelectionOnChange?.(true);
|
|
45
|
+
}, [unselectAll, globalSelectionOnChange]);
|
|
46
|
+
const unselectGlobalAll = useCallback(() => {
|
|
47
|
+
unselectAll();
|
|
48
|
+
globalSelectionOnChange?.(false);
|
|
49
|
+
}, [unselectAll, globalSelectionOnChange]);
|
|
50
|
+
const selectInvert = useCallback(() => {
|
|
51
|
+
table.setRowSelection((selectionState) => {
|
|
52
|
+
const inverted = {};
|
|
53
|
+
Object.keys(table.getRowModel().rowsById).forEach((id) => {
|
|
54
|
+
if (!selectionState[id]) {
|
|
55
|
+
inverted[id] = true;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return inverted;
|
|
59
|
+
});
|
|
60
|
+
}, [table]);
|
|
61
|
+
const dropdownDataSource = useMemo(() => {
|
|
62
|
+
const globalSelectionItem = hasGlobalSelection ? [isGlobalAllSelected ? {
|
|
63
|
+
onClick: unselectGlobalAll,
|
|
64
|
+
text: texts.unselectGlobalAll
|
|
65
|
+
} : {
|
|
66
|
+
onClick: selectGlobalAll,
|
|
67
|
+
text: texts.selectGlobalAll
|
|
68
|
+
}] : [];
|
|
69
|
+
const menuItems = selectionConfig?.selections?.filter(Boolean).flatMap((selectionMenuElement) => {
|
|
70
|
+
switch (selectionMenuElement) {
|
|
71
|
+
case SELECTION_ALL: {
|
|
72
|
+
const items = [];
|
|
73
|
+
if (!isAllSelected && !hasSelectionLimit) {
|
|
74
|
+
items.push({
|
|
75
|
+
onClick: selectAll,
|
|
76
|
+
text: texts.selectAll
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (isAnySelected) {
|
|
80
|
+
items.push({
|
|
81
|
+
onClick: unselectAll,
|
|
82
|
+
text: texts.unselectAll
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return items;
|
|
86
|
+
}
|
|
87
|
+
case SELECTION_INVERT: {
|
|
88
|
+
return !hasSelectionLimit ? {
|
|
89
|
+
onClick: selectInvert,
|
|
90
|
+
text: texts.selectInvert
|
|
91
|
+
} : [];
|
|
92
|
+
}
|
|
93
|
+
default: {
|
|
94
|
+
const sel = selectionMenuElement;
|
|
95
|
+
return {
|
|
96
|
+
...sel,
|
|
97
|
+
text: sel.label
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return [...globalSelectionItem, ...menuItems || []];
|
|
103
|
+
}, [hasGlobalSelection, isGlobalAllSelected, unselectGlobalAll, texts.unselectGlobalAll, texts.selectGlobalAll, texts.selectAll, texts.unselectAll, texts.selectInvert, selectGlobalAll, selectionConfig?.selections, isAllSelected, hasSelectionLimit, isAnySelected, selectAll, unselectAll, selectInvert]);
|
|
104
|
+
const handleBatchSelectionChange = useCallback(() => {
|
|
105
|
+
const isSelected = hasGlobalSelection ? isGlobalAllSelected : table.getIsAllRowsSelected();
|
|
106
|
+
if (hasGlobalSelection) {
|
|
107
|
+
isSelected ? unselectGlobalAll() : selectGlobalAll();
|
|
108
|
+
} else {
|
|
109
|
+
table.toggleAllRowsSelected(!isSelected);
|
|
110
|
+
}
|
|
111
|
+
}, [hasGlobalSelection, isGlobalAllSelected, selectGlobalAll, table, unselectGlobalAll]);
|
|
112
|
+
return selectionConfig ? /* @__PURE__ */ jsxs(Selection, { "data-popup-container": true, children: [
|
|
113
|
+
!hasSelectionLimit && /* @__PURE__ */ jsx(Tooltip, { title: selectionTooltipTitle, children: /* @__PURE__ */ jsx(SelectionCheckbox, { isOrphan: !selectionConfig.selections, disabled: disabledBulkSelection, "data-testid": "ds-table-batch-selection-button", checked: hasGlobalSelection ? isGlobalAllSelected : table.getIsAllRowsSelected(), indeterminate: table.getIsSomeRowsSelected(), onChange: handleBatchSelectionChange }) }),
|
|
114
|
+
selectionConfig.selections && /* @__PURE__ */ jsx(DropdownMenu, { disabled: disabledBulkSelection || dropdownDataSource?.length === 0, getPopupContainer: () => document.body, dataSource: dropdownDataSource || [], popoverProps: {
|
|
115
|
+
testId: "table-selection"
|
|
116
|
+
}, asChild: true, children: /* @__PURE__ */ jsx(DropdownButton, { isOrphan: !!hasSelectionLimit, disabled: disabledBulkSelection || dropdownDataSource?.length === 0, mode: "single-icon", type: "ghost", "data-testid": "ds-table-batch-selection-options", tooltipProps: {
|
|
117
|
+
title: texts.selectionOptionsTooltip
|
|
118
|
+
}, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(OptionVerticalM, {}) }) }) })
|
|
119
|
+
] }) : null;
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
TableHeaderSelection
|
|
123
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StyledButton } from '@synerise/ds-button';
|
|
2
|
+
type ExtraProps = {
|
|
3
|
+
isOrphan?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const DropdownButton: StyledButton<ExtraProps>;
|
|
6
|
+
export declare const SelectionCheckbox: import('styled-components').StyledComponent<(props: import('@synerise/ds-button').CheckboxButtonProps) => React.ReactElement, any, ExtraProps, never>;
|
|
7
|
+
export declare const Selection: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import Button, { Checkbox } from "@synerise/ds-button";
|
|
3
|
+
const DropdownButton = /* @__PURE__ */ styled(Button).withConfig({
|
|
4
|
+
displayName: "TableHeaderSelectionstyles__DropdownButton",
|
|
5
|
+
componentId: "sc-c6ltj0-0"
|
|
6
|
+
})(["", ""], (props) => !props.isOrphan && css(["&&&{border-top-left-radius:0;border-bottom-left-radius:0;}"]));
|
|
7
|
+
const SelectionCheckbox = /* @__PURE__ */ styled(Checkbox).withConfig({
|
|
8
|
+
displayName: "TableHeaderSelectionstyles__SelectionCheckbox",
|
|
9
|
+
componentId: "sc-c6ltj0-1"
|
|
10
|
+
})(["", ""], (props) => !props.isOrphan && css(["&&&{border-top-right-radius:0;border-bottom-right-radius:0;}"]));
|
|
11
|
+
const Selection = /* @__PURE__ */ styled.div.withConfig({
|
|
12
|
+
displayName: "TableHeaderSelectionstyles__Selection",
|
|
13
|
+
componentId: "sc-c6ltj0-2"
|
|
14
|
+
})(["display:flex;align-items:center;justify-content:flex-start;max-width:64px;margin-right:24px;border-radius:3px;&:hover{background-color:", ";}"], ({
|
|
15
|
+
theme
|
|
16
|
+
}) => theme.palette["grey-100"]);
|
|
17
|
+
export {
|
|
18
|
+
DropdownButton,
|
|
19
|
+
Selection,
|
|
20
|
+
SelectionCheckbox
|
|
21
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useDataFormat } from "@synerise/ds-core";
|
|
4
|
+
import InlineAlert from "@synerise/ds-inline-alert";
|
|
5
|
+
import { TableSkeleton } from "../../../Table.styles.js";
|
|
6
|
+
import { useTableContext } from "../../../contexts/TableContext.js";
|
|
7
|
+
import { Alert, Title, TableLimit as TableLimit$1, ItemsMenu } from "./TableLimit.styles.js";
|
|
8
|
+
function TableLimit({
|
|
9
|
+
texts,
|
|
10
|
+
itemsMenu,
|
|
11
|
+
selection,
|
|
12
|
+
isCounterLoading,
|
|
13
|
+
renderCustomCounter
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
formatValue
|
|
17
|
+
} = useDataFormat();
|
|
18
|
+
const {
|
|
19
|
+
table
|
|
20
|
+
} = useTableContext();
|
|
21
|
+
const {
|
|
22
|
+
limit
|
|
23
|
+
} = selection;
|
|
24
|
+
const selectedRows = table.getSelectedRowModel().rows.length;
|
|
25
|
+
const total = table.getRowCount();
|
|
26
|
+
const limitReachedInfo = useMemo(() => limit <= selectedRows && /* @__PURE__ */ jsx(Alert, { children: /* @__PURE__ */ jsx(InlineAlert, { type: "warning", message: texts.selectionLimitWarning }) }), [texts, selectedRows, limit]);
|
|
27
|
+
const selected = useMemo(() => {
|
|
28
|
+
const counterContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
|
+
/* @__PURE__ */ jsx("strong", { children: formatValue(total) }),
|
|
30
|
+
" ",
|
|
31
|
+
texts.totalItems
|
|
32
|
+
] });
|
|
33
|
+
return selectedRows > 0 ? /* @__PURE__ */ jsxs(Title, { children: [
|
|
34
|
+
/* @__PURE__ */ jsx("strong", { children: `${formatValue(selectedRows)} / ${formatValue(limit)}` }),
|
|
35
|
+
" ",
|
|
36
|
+
texts.selected
|
|
37
|
+
] }) : /* @__PURE__ */ jsx(Title, { children: isCounterLoading ? /* @__PURE__ */ jsx(TableSkeleton, { numberOfSkeletons: 1, size: "S", skeletonWidth: "100px" }) : /* @__PURE__ */ jsx(Fragment, { children: renderCustomCounter ? renderCustomCounter({
|
|
38
|
+
count: total,
|
|
39
|
+
content: counterContent
|
|
40
|
+
}) : counterContent }) });
|
|
41
|
+
}, [formatValue, renderCustomCounter, limit, texts.totalItems, texts.selected, isCounterLoading, selectedRows, total]);
|
|
42
|
+
return /* @__PURE__ */ jsxs(TableLimit$1, { children: [
|
|
43
|
+
selected,
|
|
44
|
+
limitReachedInfo,
|
|
45
|
+
selectedRows > 0 && /* @__PURE__ */ jsx(ItemsMenu, { children: itemsMenu })
|
|
46
|
+
] });
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
TableLimit
|
|
50
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const TableLimit: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
2
|
+
export declare const Title: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const Alert: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const ItemsMenu: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { macro } from "@synerise/ds-typography";
|
|
3
|
+
const TableLimit = /* @__PURE__ */ styled.div.withConfig({
|
|
4
|
+
displayName: "TableLimitstyles__TableLimit",
|
|
5
|
+
componentId: "sc-16p1ck3-0"
|
|
6
|
+
})(["display:flex;align-items:center;justify-content:flex-start;"]);
|
|
7
|
+
const Title = /* @__PURE__ */ styled.div.withConfig({
|
|
8
|
+
displayName: "TableLimitstyles__Title",
|
|
9
|
+
componentId: "sc-16p1ck3-1"
|
|
10
|
+
})(["", ";color:", ";strong{font-weight:500;}display:flex;align-items:center;gap:4px;"], macro.small, (props) => props.theme.palette["grey-700"]);
|
|
11
|
+
const Alert = /* @__PURE__ */ styled.div.withConfig({
|
|
12
|
+
displayName: "TableLimitstyles__Alert",
|
|
13
|
+
componentId: "sc-16p1ck3-2"
|
|
14
|
+
})(["position:relative;padding-left:16px;margin-left:16px;&::before{position:absolute;top:4px;left:0;content:'';display:flex;width:1px;height:16px;background:", ";}"], (props) => props.theme.palette["grey-200"]);
|
|
15
|
+
const ItemsMenu = /* @__PURE__ */ styled.div.withConfig({
|
|
16
|
+
displayName: "TableLimitstyles__ItemsMenu",
|
|
17
|
+
componentId: "sc-16p1ck3-3"
|
|
18
|
+
})(["padding-left:24px;"]);
|
|
19
|
+
export {
|
|
20
|
+
Alert,
|
|
21
|
+
ItemsMenu,
|
|
22
|
+
TableLimit,
|
|
23
|
+
Title
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { RequiredProps } from '@synerise/ds-utils';
|
|
3
|
+
import { CustomCounterFn, SelectionConfig, TableLimitTexts } from '../../../Table.types';
|
|
4
|
+
export type TableLimitProps<TData> = {
|
|
5
|
+
selection: RequiredProps<SelectionConfig<TData>, 'limit'>;
|
|
6
|
+
itemsMenu: ReactNode;
|
|
7
|
+
texts: TableLimitTexts;
|
|
8
|
+
isCounterLoading?: boolean;
|
|
9
|
+
renderCustomCounter?: CustomCounterFn;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
export declare const TableHorizontalScroll: React.ForwardRefExoticComponent<{
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
stickyLeft?: number;
|
|
5
|
+
stickyRight?: number;
|
|
6
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "stickyLeft" | "stickyRight"> & import('@synerise/ds-utils').DataAttributes & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useRef, useCallback } from "react";
|
|
3
|
+
import { useMergeRefs } from "@floating-ui/react";
|
|
4
|
+
import Scrollbar from "@synerise/ds-scrollbar";
|
|
5
|
+
import { useResizeObserver } from "@synerise/ds-utils";
|
|
6
|
+
import { HorizontalScrollContainer, LeftShadow, HorizontalScrollWrapper, RightShadow, ScrollbarWrapper } from "./TableHorizontalScroll.styles.js";
|
|
7
|
+
const TableHorizontalScroll = forwardRef(({
|
|
8
|
+
children,
|
|
9
|
+
stickyLeft = 0,
|
|
10
|
+
stickyRight = 0,
|
|
11
|
+
...rest
|
|
12
|
+
}, ref) => {
|
|
13
|
+
const [isMaxLeft, setIsMaxLeft] = useState(true);
|
|
14
|
+
const [isMaxRight, setIsMaxRight] = useState(true);
|
|
15
|
+
const wrapperRef = useRef(null);
|
|
16
|
+
const mergedRef = useMergeRefs([wrapperRef, ref]);
|
|
17
|
+
const calculateOffsets = useCallback((element) => {
|
|
18
|
+
if (element.scrollWidth === element.clientWidth) {
|
|
19
|
+
setIsMaxLeft(true);
|
|
20
|
+
setIsMaxRight(true);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setIsMaxLeft(element.scrollLeft === 0);
|
|
24
|
+
setIsMaxRight(element.scrollLeft + element.clientWidth >= element.scrollWidth);
|
|
25
|
+
}, []);
|
|
26
|
+
const handleScroll = useCallback((event) => {
|
|
27
|
+
calculateOffsets(event.currentTarget);
|
|
28
|
+
}, [calculateOffsets]);
|
|
29
|
+
useResizeObserver(wrapperRef, () => wrapperRef.current && calculateOffsets(wrapperRef.current));
|
|
30
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
31
|
+
/* @__PURE__ */ jsxs(HorizontalScrollContainer, { showLeftShadow: !isMaxLeft, showRightShadow: !isMaxRight, ...rest, children: [
|
|
32
|
+
/* @__PURE__ */ jsx(LeftShadow, { offset: stickyLeft }),
|
|
33
|
+
/* @__PURE__ */ jsx(HorizontalScrollWrapper, { ref: mergedRef, onScroll: handleScroll, children }),
|
|
34
|
+
/* @__PURE__ */ jsx(RightShadow, { offset: stickyRight })
|
|
35
|
+
] }),
|
|
36
|
+
/* @__PURE__ */ jsx(ScrollbarWrapper, { children: /* @__PURE__ */ jsx(Scrollbar, {}) })
|
|
37
|
+
] });
|
|
38
|
+
});
|
|
39
|
+
export {
|
|
40
|
+
TableHorizontalScroll
|
|
41
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const HorizontalScrollWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
2
|
+
export declare const LeftShadow: import('styled-components').StyledComponent<"div", any, {
|
|
3
|
+
offset: number;
|
|
4
|
+
}, never>;
|
|
5
|
+
export declare const RightShadow: import('styled-components').StyledComponent<"div", any, {
|
|
6
|
+
offset: number;
|
|
7
|
+
}, never>;
|
|
8
|
+
export declare const HorizontalScrollContainer: import('styled-components').StyledComponent<"div", any, {
|
|
9
|
+
showLeftShadow: boolean;
|
|
10
|
+
showRightShadow: boolean;
|
|
11
|
+
}, never>;
|
|
12
|
+
export declare const ScrollbarWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { hexToRgba } from "@synerise/ds-utils";
|
|
3
|
+
const HorizontalScrollWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
4
|
+
displayName: "TableHorizontalScrollstyles__HorizontalScrollWrapper",
|
|
5
|
+
componentId: "sc-16m24d3-0"
|
|
6
|
+
})(["overflow-x:auto;overflow-y:hidden;scrollbar-width:none;overscroll-behavior-y:auto;overscroll-behavior-x:contain;"]);
|
|
7
|
+
const LeftShadow = /* @__PURE__ */ styled.div.withConfig({
|
|
8
|
+
displayName: "TableHorizontalScrollstyles__LeftShadow",
|
|
9
|
+
componentId: "sc-16m24d3-1"
|
|
10
|
+
})(["position:absolute;top:0;left:", "px;width:10px;height:100%;box-shadow:inset 10px 0 8px -8px ", ";z-index:10;"], (props) => props.offset, ({
|
|
11
|
+
theme
|
|
12
|
+
}) => hexToRgba(theme.palette["grey-500"], 0.12));
|
|
13
|
+
const RightShadow = /* @__PURE__ */ styled.div.withConfig({
|
|
14
|
+
displayName: "TableHorizontalScrollstyles__RightShadow",
|
|
15
|
+
componentId: "sc-16m24d3-2"
|
|
16
|
+
})(["position:absolute;top:0;right:", "px;width:10px;height:100%;box-shadow:inset -10px 0 8px -8px ", ";z-index:10;"], (props) => props.offset, ({
|
|
17
|
+
theme
|
|
18
|
+
}) => hexToRgba(theme.palette["grey-500"], 0.12));
|
|
19
|
+
const HorizontalScrollContainer = /* @__PURE__ */ styled.div.withConfig({
|
|
20
|
+
displayName: "TableHorizontalScrollstyles__HorizontalScrollContainer",
|
|
21
|
+
componentId: "sc-16m24d3-3"
|
|
22
|
+
})(["position:relative;", "{", "}", "{", "}"], LeftShadow, (props) => props.showLeftShadow ? `display: block` : `display: none`, RightShadow, (props) => props.showRightShadow ? `display: block` : `display: none`);
|
|
23
|
+
const ScrollbarWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
24
|
+
displayName: "TableHorizontalScrollstyles__ScrollbarWrapper",
|
|
25
|
+
componentId: "sc-16m24d3-4"
|
|
26
|
+
})([""]);
|
|
27
|
+
export {
|
|
28
|
+
HorizontalScrollContainer,
|
|
29
|
+
HorizontalScrollWrapper,
|
|
30
|
+
LeftShadow,
|
|
31
|
+
RightShadow,
|
|
32
|
+
ScrollbarWrapper
|
|
33
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
type TableHorizontalScrollBarProps = {
|
|
3
|
+
contentRef?: (element: HTMLDivElement) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare const TableHorizontalScrollBar: ({ contentRef, }: TableHorizontalScrollBarProps) => React.JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import Scrollbar from "@synerise/ds-scrollbar";
|
|
3
|
+
import { ScrollbarWrapper, ScrollbarContent } from "./TableHorizontalScrollBar.styles.js";
|
|
4
|
+
const TableHorizontalScrollBar = ({
|
|
5
|
+
contentRef
|
|
6
|
+
}) => {
|
|
7
|
+
return /* @__PURE__ */ jsx(ScrollbarWrapper, { "data-testid": "ds-table-horizontal-scroll", children: /* @__PURE__ */ jsx(Scrollbar, { absolute: true, ref: contentRef, children: /* @__PURE__ */ jsx(ScrollbarContent, {}) }) });
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
TableHorizontalScrollBar
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { BaseTableWrapper } from "../BaseTable/BaseTable.styles.js";
|
|
3
|
+
const ScrollbarWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
4
|
+
displayName: "TableHorizontalScrollBarstyles__ScrollbarWrapper",
|
|
5
|
+
componentId: "sc-yrx622-0"
|
|
6
|
+
})(["position:sticky;bottom:10px;transform:translate(5px,24px);z-index:20;height:10px;margin-bottom:-10px;", ":hover &{.ps__rail-x{opacity:1;}}"], BaseTableWrapper);
|
|
7
|
+
const ScrollbarContent = /* @__PURE__ */ styled.div.withConfig({
|
|
8
|
+
displayName: "TableHorizontalScrollBarstyles__ScrollbarContent",
|
|
9
|
+
componentId: "sc-yrx622-1"
|
|
10
|
+
})(["width:var(--table-size);height:1px;pointer-events:none;"]);
|
|
11
|
+
export {
|
|
12
|
+
ScrollbarContent,
|
|
13
|
+
ScrollbarWrapper
|
|
14
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import Pagination from "@synerise/ds-pagination";
|
|
3
|
+
import { useTableContext } from "../../contexts/TableContext.js";
|
|
4
|
+
import { PaginationWrapper } from "./TablePagination.styles.js";
|
|
5
|
+
const TablePagination = ({
|
|
6
|
+
...rest
|
|
7
|
+
}) => {
|
|
8
|
+
const {
|
|
9
|
+
table
|
|
10
|
+
} = useTableContext();
|
|
11
|
+
return /* @__PURE__ */ jsx(PaginationWrapper, { "data-testid": "ds-table-pagination", children: /* @__PURE__ */ jsx(Pagination, { hideOnSinglePage: true, pageSize: table.getState().pagination.pageSize, total: table.getRowCount(), onShowSizeChange: (_current, size) => {
|
|
12
|
+
table.setPageSize(size);
|
|
13
|
+
}, onChange: (page) => {
|
|
14
|
+
table.setPageIndex(page - 1);
|
|
15
|
+
}, ...rest }) });
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
TablePagination
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PaginationWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
const PaginationWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
3
|
+
displayName: "TablePaginationstyles__PaginationWrapper",
|
|
4
|
+
componentId: "sc-npn86e-0"
|
|
5
|
+
})(["background:", ";padding:16px 24px;display:flex;justify-content:flex-end;&:empty{display:none;}"], (props) => props.theme.palette["grey-050"]);
|
|
6
|
+
export {
|
|
7
|
+
PaginationWrapper
|
|
8
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RowData } from '@tanstack/react-table';
|
|
2
|
+
import { SelectionConfig } from '../Table.types';
|
|
3
|
+
export declare const SelectionContext: import('react').Context<SelectionConfig<any> | undefined>;
|
|
4
|
+
export declare const useSelectionContext: <TData extends RowData>() => SelectionConfig<TData> | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const SelectionContext = createContext(void 0);
|
|
3
|
+
const useSelectionContext = () => {
|
|
4
|
+
const ctx = useContext(SelectionContext);
|
|
5
|
+
return ctx ? ctx : void 0;
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
SelectionContext,
|
|
9
|
+
useSelectionContext
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StickyData } from '../Table.types';
|
|
2
|
+
type StickyContextType = {
|
|
3
|
+
stickyData: StickyData;
|
|
4
|
+
setStickyData: React.Dispatch<React.SetStateAction<StickyData>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const StickyContext: import('react').Context<StickyContextType | null>;
|
|
7
|
+
export declare const useStickyContext: () => StickyContextType | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useReactTable } from '@tanstack/react-table';
|
|
2
|
+
import { Virtualizer } from '@tanstack/react-virtual';
|
|
3
|
+
type TableInstance<TData extends object> = ReturnType<typeof useReactTable<TData>>;
|
|
4
|
+
type TableContextType<TData extends object> = {
|
|
5
|
+
table: TableInstance<TData>;
|
|
6
|
+
rowVirtualizer?: Virtualizer<HTMLDivElement, Element>;
|
|
7
|
+
getScrollContainer: () => HTMLElement | null;
|
|
8
|
+
};
|
|
9
|
+
export declare const TableContext: import('react').Context<TableContextType<any> | null>;
|
|
10
|
+
export declare const useTableContext: <TData extends object>() => TableContextType<TData>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const TableContext = createContext(null);
|
|
3
|
+
const useTableContext = () => {
|
|
4
|
+
const ctx = useContext(TableContext);
|
|
5
|
+
if (!ctx) {
|
|
6
|
+
throw new Error("useTableContext must be used inside <TableProvider>");
|
|
7
|
+
}
|
|
8
|
+
return ctx;
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
TableContext,
|
|
12
|
+
useTableContext
|
|
13
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { ColumnSizingState } from '@tanstack/react-table';
|
|
3
|
+
type UseColumnSizingProps = {
|
|
4
|
+
columnWidths: {
|
|
5
|
+
id: string;
|
|
6
|
+
minWidth?: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
maxWidth?: number;
|
|
9
|
+
}[];
|
|
10
|
+
wrapperRef: MutableRefObject<HTMLDivElement | null>;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const useColumnSizing: ({ wrapperRef, columnWidths, enabled, }: UseColumnSizingProps) => {
|
|
14
|
+
columnSizing: ColumnSizingState;
|
|
15
|
+
setColumnSizing: import('react').Dispatch<import('react').SetStateAction<ColumnSizingState>>;
|
|
16
|
+
isColumnSizingReady: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare const calculateWidths: (columns: {
|
|
19
|
+
width?: number;
|
|
20
|
+
maxWidth?: number;
|
|
21
|
+
minWidth?: number;
|
|
22
|
+
}[], availableSpace: number) => number[];
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useState, useCallback, useLayoutEffect } from "react";
|
|
2
|
+
import { useDebounce, useResizeObserver } from "@synerise/ds-utils";
|
|
3
|
+
import { calculatePixels } from "../utils/calculatePixels.js";
|
|
4
|
+
const useColumnSizing = ({
|
|
5
|
+
wrapperRef,
|
|
6
|
+
columnWidths,
|
|
7
|
+
enabled = true
|
|
8
|
+
}) => {
|
|
9
|
+
const [columnSizing, setColumnSizing] = useState({});
|
|
10
|
+
const [isColumnSizingReady, setIsColumnSizingReady] = useState(!enabled);
|
|
11
|
+
const calc = useCallback((availableWidth) => {
|
|
12
|
+
if (!enabled) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const calculatedWidths = calculateWidths(columnWidths, availableWidth);
|
|
16
|
+
const sizing = {};
|
|
17
|
+
columnWidths.forEach((_col, index) => {
|
|
18
|
+
const colWidthId = `col-${index}`;
|
|
19
|
+
sizing[colWidthId] = calculatedWidths[index];
|
|
20
|
+
});
|
|
21
|
+
setColumnSizing(sizing);
|
|
22
|
+
setIsColumnSizingReady(true);
|
|
23
|
+
}, [columnWidths, enabled]);
|
|
24
|
+
const debouncedCalc = useDebounce(calc, 500);
|
|
25
|
+
const getContentWidth = useCallback((element) => {
|
|
26
|
+
const {
|
|
27
|
+
paddingLeft,
|
|
28
|
+
paddingRight
|
|
29
|
+
} = getComputedStyle(element);
|
|
30
|
+
return element.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight);
|
|
31
|
+
}, []);
|
|
32
|
+
const resizeHandler = useCallback(() => {
|
|
33
|
+
if (!enabled) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (wrapperRef.current?.clientWidth) {
|
|
37
|
+
debouncedCalc(getContentWidth(wrapperRef.current));
|
|
38
|
+
}
|
|
39
|
+
}, [enabled, debouncedCalc, getContentWidth, wrapperRef]);
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
if (!enabled) {
|
|
42
|
+
setColumnSizing({});
|
|
43
|
+
setIsColumnSizingReady(true);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (wrapperRef.current) {
|
|
47
|
+
calc(getContentWidth(wrapperRef.current));
|
|
48
|
+
}
|
|
49
|
+
}, [enabled, calc, getContentWidth, wrapperRef]);
|
|
50
|
+
useResizeObserver(wrapperRef, resizeHandler);
|
|
51
|
+
return {
|
|
52
|
+
columnSizing,
|
|
53
|
+
setColumnSizing,
|
|
54
|
+
isColumnSizingReady
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const calculateWidths = (columns, availableSpace) => {
|
|
58
|
+
let baseSum = 0;
|
|
59
|
+
let flexibleColumnCount = 0;
|
|
60
|
+
let noMaxColumnCount = 0;
|
|
61
|
+
const baseWidths = columns.map((column) => {
|
|
62
|
+
const baseWidth = calculatePixels(column.width || column.minWidth) || 0;
|
|
63
|
+
flexibleColumnCount += Number(!column.width);
|
|
64
|
+
noMaxColumnCount += Number(!column.width && !column.maxWidth);
|
|
65
|
+
baseSum += baseWidth;
|
|
66
|
+
return baseWidth;
|
|
67
|
+
});
|
|
68
|
+
if (!flexibleColumnCount) {
|
|
69
|
+
return baseWidths;
|
|
70
|
+
}
|
|
71
|
+
if (baseSum < availableSpace) {
|
|
72
|
+
const extraWidth = (availableSpace - baseSum) / flexibleColumnCount;
|
|
73
|
+
let interimSum = 0;
|
|
74
|
+
columns.forEach((column, index) => {
|
|
75
|
+
if (!column.width) {
|
|
76
|
+
const maxWidthAsNumber = calculatePixels(column.maxWidth);
|
|
77
|
+
baseWidths[index] = maxWidthAsNumber ? Math.min(maxWidthAsNumber, baseWidths[index] + extraWidth) : baseWidths[index] + extraWidth;
|
|
78
|
+
}
|
|
79
|
+
interimSum += baseWidths[index];
|
|
80
|
+
});
|
|
81
|
+
if (interimSum < availableSpace) {
|
|
82
|
+
const extraWidth2 = (availableSpace - interimSum) / noMaxColumnCount;
|
|
83
|
+
columns.forEach((column, index) => {
|
|
84
|
+
if (!column.width && !column.maxWidth) {
|
|
85
|
+
baseWidths[index] += extraWidth2;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return baseWidths;
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
calculateWidths,
|
|
94
|
+
useColumnSizing
|
|
95
|
+
};
|