schummar-table 0.4.2 → 0.5.0-beta-1
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/assets/tableTheme.0eb513b0.js +215 -0
- package/dist/assets/tableTheme.0eb513b0.js.map +1 -0
- package/dist/assets/tableTheme.65fea986.js +214 -0
- package/dist/assets/tableTheme.65fea986.js.map +1 -0
- package/dist/assets/vendor.a5ec605d.js +2475 -0
- package/dist/assets/vendor.a5ec605d.js.map +1 -0
- package/dist/assets/vendor.c9c3328b.js +2464 -0
- package/dist/assets/vendor.c9c3328b.js.map +1 -0
- package/dist/cjs/mui4Theme.js +7 -0
- package/dist/cjs/mui4Theme.js.map +1 -0
- package/dist/cjs/mui5Theme.js +7 -0
- package/dist/cjs/mui5Theme.js.map +1 -0
- package/dist/cjs/schummar-table.js +1042 -0
- package/dist/cjs/schummar-table.js.map +1 -0
- package/dist/esm/mui4Theme.js +6 -0
- package/dist/esm/mui4Theme.js.map +1 -0
- package/dist/esm/mui5Theme.js +6 -0
- package/dist/esm/mui5Theme.js.map +1 -0
- package/dist/esm/schummar-table.js +1041 -0
- package/dist/esm/schummar-table.js.map +1 -0
- package/dist/{cjs → types}/components/cell.d.ts +1 -1
- package/dist/types/components/columnHeader.d.ts +7 -0
- package/dist/{cjs → types}/components/columnSelection.d.ts +0 -0
- package/dist/types/components/dateFilter.d.ts +8 -0
- package/dist/types/components/datePicker.d.ts +16 -0
- package/dist/types/components/expandControl.d.ts +6 -0
- package/dist/{cjs → types}/components/export.d.ts +0 -0
- package/dist/types/components/filterControl.d.ts +2 -0
- package/dist/types/components/formControlLabel.d.ts +5 -0
- package/dist/types/components/resizeHandle.d.ts +1 -0
- package/dist/{cjs → types}/components/row.d.ts +1 -1
- package/dist/{cjs → types}/components/selectComponent.d.ts +0 -0
- package/dist/types/components/selectFilter.d.ts +8 -0
- package/dist/{cjs → types}/components/sortComponent.d.ts +0 -0
- package/dist/types/components/spinnner.d.ts +3 -0
- package/dist/{cjs → types/components}/table.d.ts +1 -4
- package/dist/types/components/textFilter.d.ts +5 -0
- package/dist/{cjs → types}/components/virtualized.d.ts +0 -0
- package/dist/types/hooks/useFilter.d.ts +5 -0
- package/dist/types/hooks/useTheme.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/{cjs → types}/internalState/calcItems.d.ts +0 -0
- package/dist/{cjs → types}/internalState/calcProps.d.ts +0 -0
- package/dist/{cjs → types}/internalState/cleanupState.d.ts +0 -0
- package/dist/{cjs → types}/internalState/filterColumns.d.ts +0 -0
- package/dist/{cjs → types}/internalState/syncSelections.d.ts +0 -0
- package/dist/{cjs → types}/internalState/tableStateStorage.d.ts +1 -1
- package/dist/{cjs → types}/internalState/useTableState.d.ts +0 -0
- package/dist/{cjs → types}/misc/csvExport.d.ts +0 -0
- package/dist/types/misc/debounce.d.ts +4 -0
- package/dist/types/misc/deepPartial.d.ts +3 -0
- package/dist/{cjs → types}/misc/helpers.d.ts +2 -1
- package/dist/{cjs → types}/misc/queue.d.ts +1 -1
- package/dist/{cjs → types}/misc/textMatch.d.ts +0 -0
- package/dist/types/misc/throttle.d.ts +4 -0
- package/dist/types/theme/defaultClasses.d.ts +15 -0
- package/dist/types/theme/defaultColors.d.ts +2 -0
- package/dist/types/theme/defaultIcons.d.ts +2 -0
- package/dist/types/theme/defaultTexts.d.ts +2 -0
- package/dist/types/theme/defaultTheme/badge.d.ts +2 -0
- package/dist/types/theme/defaultTheme/button.d.ts +2 -0
- package/dist/types/theme/defaultTheme/checkbox.d.ts +2 -0
- package/dist/types/theme/defaultTheme/iconButton.d.ts +2 -0
- package/dist/types/theme/defaultTheme/index.d.ts +2 -0
- package/dist/types/theme/defaultTheme/popover.d.ts +4 -0
- package/dist/types/theme/defaultTheme/textField.d.ts +2 -0
- package/dist/types/theme/mui4Theme/index.d.ts +8 -0
- package/dist/types/theme/mui5Theme/index.d.ts +8 -0
- package/dist/types/theme/tableTheme.d.ts +11 -0
- package/dist/types/theme/useCssVariables.d.ts +9 -0
- package/dist/types/types.d.ts +285 -0
- package/package.json +77 -38
- package/dist/cjs/components/cell.js +0 -31
- package/dist/cjs/components/columnSelection.js +0 -37
- package/dist/cjs/components/defaultFilterComponent.d.ts +0 -22
- package/dist/cjs/components/defaultFilterComponent.js +0 -91
- package/dist/cjs/components/expandComponent.d.ts +0 -5
- package/dist/cjs/components/expandComponent.js +0 -38
- package/dist/cjs/components/export.js +0 -48
- package/dist/cjs/components/filterComponent.d.ts +0 -5
- package/dist/cjs/components/filterComponent.js +0 -25
- package/dist/cjs/components/row.js +0 -51
- package/dist/cjs/components/selectComponent.js +0 -61
- package/dist/cjs/components/sortComponent.js +0 -52
- package/dist/cjs/components/textFilterComponent.d.ts +0 -11
- package/dist/cjs/components/textFilterComponent.js +0 -70
- package/dist/cjs/components/useCommonClasses.d.ts +0 -1
- package/dist/cjs/components/useCommonClasses.js +0 -49
- package/dist/cjs/components/virtualized.js +0 -98
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/internalState/calcItems.js +0 -85
- package/dist/cjs/internalState/calcProps.js +0 -89
- package/dist/cjs/internalState/cleanupState.js +0 -43
- package/dist/cjs/internalState/filterColumns.js +0 -10
- package/dist/cjs/internalState/syncSelections.js +0 -22
- package/dist/cjs/internalState/tableStateStorage.js +0 -74
- package/dist/cjs/internalState/useTableState.js +0 -62
- package/dist/cjs/misc/csvExport.js +0 -15
- package/dist/cjs/misc/helpers.js +0 -91
- package/dist/cjs/misc/queue.js +0 -42
- package/dist/cjs/misc/textMatch.js +0 -23
- package/dist/cjs/misc/throttle.d.ts +0 -1
- package/dist/cjs/misc/throttle.js +0 -30
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/table.js +0 -80
- package/dist/cjs/types.d.ts +0 -146
- package/dist/cjs/types.js +0 -2
- package/dist/esm/components/cell.d.ts +0 -6
- package/dist/esm/components/cell.js +0 -28
- package/dist/esm/components/columnSelection.d.ts +0 -2
- package/dist/esm/components/columnSelection.js +0 -33
- package/dist/esm/components/defaultFilterComponent.d.ts +0 -22
- package/dist/esm/components/defaultFilterComponent.js +0 -86
- package/dist/esm/components/expandComponent.d.ts +0 -5
- package/dist/esm/components/expandComponent.js +0 -34
- package/dist/esm/components/export.d.ts +0 -2
- package/dist/esm/components/export.js +0 -44
- package/dist/esm/components/filterComponent.d.ts +0 -5
- package/dist/esm/components/filterComponent.js +0 -21
- package/dist/esm/components/row.d.ts +0 -7
- package/dist/esm/components/row.js +0 -47
- package/dist/esm/components/selectComponent.d.ts +0 -5
- package/dist/esm/components/selectComponent.js +0 -57
- package/dist/esm/components/sortComponent.d.ts +0 -4
- package/dist/esm/components/sortComponent.js +0 -48
- package/dist/esm/components/textFilterComponent.d.ts +0 -11
- package/dist/esm/components/textFilterComponent.js +0 -65
- package/dist/esm/components/useCommonClasses.d.ts +0 -1
- package/dist/esm/components/useCommonClasses.js +0 -46
- package/dist/esm/components/virtualized.d.ts +0 -6
- package/dist/esm/components/virtualized.js +0 -94
- package/dist/esm/index.d.ts +0 -7
- package/dist/esm/index.js +0 -4
- package/dist/esm/internalState/calcItems.d.ts +0 -3
- package/dist/esm/internalState/calcItems.js +0 -81
- package/dist/esm/internalState/calcProps.d.ts +0 -2
- package/dist/esm/internalState/calcProps.js +0 -85
- package/dist/esm/internalState/cleanupState.d.ts +0 -3
- package/dist/esm/internalState/cleanupState.js +0 -39
- package/dist/esm/internalState/filterColumns.d.ts +0 -3
- package/dist/esm/internalState/filterColumns.js +0 -6
- package/dist/esm/internalState/syncSelections.d.ts +0 -3
- package/dist/esm/internalState/syncSelections.js +0 -18
- package/dist/esm/internalState/tableStateStorage.d.ts +0 -11
- package/dist/esm/internalState/tableStateStorage.js +0 -70
- package/dist/esm/internalState/useTableState.d.ts +0 -3
- package/dist/esm/internalState/useTableState.js +0 -58
- package/dist/esm/misc/csvExport.d.ts +0 -7
- package/dist/esm/misc/csvExport.js +0 -11
- package/dist/esm/misc/helpers.d.ts +0 -14
- package/dist/esm/misc/helpers.js +0 -77
- package/dist/esm/misc/queue.d.ts +0 -6
- package/dist/esm/misc/queue.js +0 -38
- package/dist/esm/misc/textMatch.d.ts +0 -2
- package/dist/esm/misc/textMatch.js +0 -18
- package/dist/esm/misc/throttle.d.ts +0 -1
- package/dist/esm/misc/throttle.js +0 -26
- package/dist/esm/table.d.ts +0 -11
- package/dist/esm/table.js +0 -73
- package/dist/esm/types.d.ts +0 -146
- package/dist/esm/types.js +0 -1
package/dist/cjs/types.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
import { Filter } from './components/filterComponent';
|
|
3
|
-
import { CsvExportOptions } from './misc/csvExport';
|
|
4
|
-
import { TableStateStorage } from './internalState/tableStateStorage';
|
|
5
|
-
export declare type Sort = {
|
|
6
|
-
columnId: string | number;
|
|
7
|
-
direction: SortDirection;
|
|
8
|
-
};
|
|
9
|
-
export declare type SortDirection = 'asc' | 'desc';
|
|
10
|
-
export declare type Id = string | number;
|
|
11
|
-
export declare type KeyOfType<T, S> = {
|
|
12
|
-
[K in keyof T]: T[K] extends S ? K : never;
|
|
13
|
-
}[keyof T];
|
|
14
|
-
export declare type TableProps<T> = {
|
|
15
|
-
items?: T[];
|
|
16
|
-
id: ((item: T) => Id) | KeyOfType<T, Id>;
|
|
17
|
-
parentId?: ((item: T) => Id | undefined) | KeyOfType<T, Id | undefined>;
|
|
18
|
-
hasDeferredChildren?: (item: T) => boolean;
|
|
19
|
-
columns: Column<T, any>[] | ((col: <V>(value: (item: T) => V, column: Omit<Column<T, V>, 'value'>) => Column<T, V>) => Column<T, any>[]);
|
|
20
|
-
rowAction?: ReactNode | ((item: T, index: number) => ReactNode);
|
|
21
|
-
defaultSort?: Sort[];
|
|
22
|
-
sort?: Sort[];
|
|
23
|
-
onSortChange?: (sort: Sort[]) => void;
|
|
24
|
-
defaultSelection?: Set<Id>;
|
|
25
|
-
selection?: Set<Id>;
|
|
26
|
-
onSelectionChange?: (selection: Set<Id>) => void;
|
|
27
|
-
selectSyncChildren?: boolean;
|
|
28
|
-
revealFiltered?: boolean;
|
|
29
|
-
defaultExpanded?: Set<Id>;
|
|
30
|
-
expanded?: Set<Id>;
|
|
31
|
-
onExpandedChange?: (expanded: Set<Id>) => void;
|
|
32
|
-
expandOnlyOne?: boolean;
|
|
33
|
-
defaultHiddenColumns?: Set<Id>;
|
|
34
|
-
hiddenColumns?: Set<Id>;
|
|
35
|
-
onHiddenColumnsChange?: (hiddenColumns: Set<Id>) => void;
|
|
36
|
-
defaultWidth?: string;
|
|
37
|
-
fullWidth?: boolean | 'left' | 'right';
|
|
38
|
-
stickyHeader?: boolean;
|
|
39
|
-
virtual?: boolean | {
|
|
40
|
-
rowHeight?: number;
|
|
41
|
-
initalRowHeight?: number;
|
|
42
|
-
throttleScroll?: number;
|
|
43
|
-
overscan?: number;
|
|
44
|
-
overscanBottom?: number;
|
|
45
|
-
overscanTop?: number;
|
|
46
|
-
};
|
|
47
|
-
text?: {
|
|
48
|
-
deselectAll?: ReactNode;
|
|
49
|
-
exportTitle?: ReactNode;
|
|
50
|
-
exportCopy?: ReactNode;
|
|
51
|
-
exportDownload?: ReactNode;
|
|
52
|
-
};
|
|
53
|
-
classes?: {
|
|
54
|
-
table?: string;
|
|
55
|
-
headerCell?: string;
|
|
56
|
-
cell?: string | ((item: T, index: number) => string | undefined);
|
|
57
|
-
evenCell?: string;
|
|
58
|
-
oddCell?: string;
|
|
59
|
-
};
|
|
60
|
-
wrapCell?: (cell: ReactNode, item: T) => ReactNode;
|
|
61
|
-
debug?: (...output: any) => void;
|
|
62
|
-
enableSelection?: boolean;
|
|
63
|
-
enableColumnSelection?: boolean;
|
|
64
|
-
enableExport?: boolean | {
|
|
65
|
-
copy?: boolean | CsvExportOptions;
|
|
66
|
-
download?: boolean | CsvExportOptions;
|
|
67
|
-
};
|
|
68
|
-
storeState?: {
|
|
69
|
-
storage: TableStateStorage;
|
|
70
|
-
id?: string;
|
|
71
|
-
include?: {
|
|
72
|
-
sort?: boolean;
|
|
73
|
-
selection?: boolean;
|
|
74
|
-
expanded?: boolean;
|
|
75
|
-
hiddenColumns?: boolean;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export declare type InternalTableProps<T> = Omit<TableProps<T>, 'id' | 'parentId' | 'columns' | 'enableSelection' | 'enableColumnSelection' | 'enableExport'> & {
|
|
80
|
-
id: (item: T) => Id;
|
|
81
|
-
parentId?: (item: T) => Id | undefined;
|
|
82
|
-
columns: InternalColumn<T, unknown>[];
|
|
83
|
-
enableSelection: boolean;
|
|
84
|
-
enableColumnSelection: boolean;
|
|
85
|
-
enableExport: {
|
|
86
|
-
copy?: CsvExportOptions;
|
|
87
|
-
download?: CsvExportOptions;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export declare type TableItem<T = unknown> = T & {
|
|
91
|
-
id: Id;
|
|
92
|
-
parentId?: Id;
|
|
93
|
-
children: TableItem<T>[];
|
|
94
|
-
};
|
|
95
|
-
export declare type Column<T, V> = {
|
|
96
|
-
id?: string;
|
|
97
|
-
header?: ReactNode;
|
|
98
|
-
value: (item: T) => V;
|
|
99
|
-
renderCell?: (value: V, item: T) => ReactNode;
|
|
100
|
-
exportCell?: (value: V, item: T) => string | number;
|
|
101
|
-
sortBy?: ((value: V, item: T) => unknown) | ((value: V) => unknown)[];
|
|
102
|
-
filterComponent?: ReactNode;
|
|
103
|
-
defaultFilter?: Filter<V>;
|
|
104
|
-
filter?: Filter<V>;
|
|
105
|
-
onFilterChange?: (filter?: Filter<T>) => void;
|
|
106
|
-
cannotHide?: boolean;
|
|
107
|
-
width?: string;
|
|
108
|
-
justifyContent?: CSSProperties['justifyContent'];
|
|
109
|
-
classes?: {
|
|
110
|
-
headerCell?: string;
|
|
111
|
-
cell?: string | ((item: T, index: number) => string | undefined);
|
|
112
|
-
evenCell?: string;
|
|
113
|
-
oddCell?: string;
|
|
114
|
-
};
|
|
115
|
-
/** If the column definition changes, supply parameters that it depends on. If not set, the column will not update */
|
|
116
|
-
dependencies?: any[];
|
|
117
|
-
};
|
|
118
|
-
export declare type InternalColumn<T, V> = Required<Omit<Column<T, V>, 'id'> & {
|
|
119
|
-
id: Id;
|
|
120
|
-
}, 'header' | 'stringValue' | 'sortBy' | 'renderValue' | 'renderCell' | 'exportCell'>;
|
|
121
|
-
declare type Required<T, S> = T & {
|
|
122
|
-
[P in keyof T as P extends S ? P : never]-?: T[P];
|
|
123
|
-
};
|
|
124
|
-
export declare type Rows<T, V> = [{
|
|
125
|
-
value: V;
|
|
126
|
-
item: T;
|
|
127
|
-
}, ...{
|
|
128
|
-
value: V;
|
|
129
|
-
item: T;
|
|
130
|
-
}[]];
|
|
131
|
-
export declare type InternalTableState<T> = {
|
|
132
|
-
props: InternalTableProps<T>;
|
|
133
|
-
sort: Sort[];
|
|
134
|
-
selection: Set<Id>;
|
|
135
|
-
expanded: Set<Id>;
|
|
136
|
-
rowHeights: Map<Id, number>;
|
|
137
|
-
filters: Map<Id, Filter<unknown> | undefined>;
|
|
138
|
-
hiddenColumns: Set<Id>;
|
|
139
|
-
activeColumns: InternalColumn<T, unknown>[];
|
|
140
|
-
items: TableItem<T>[];
|
|
141
|
-
itemsById: Map<Id, TableItem<T>>;
|
|
142
|
-
activeItems: TableItem<T>[];
|
|
143
|
-
activeItemsById: Map<Id, TableItem<T>>;
|
|
144
|
-
lastSelectedId?: Id;
|
|
145
|
-
};
|
|
146
|
-
export {};
|
package/dist/cjs/types.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { useColumnContext, useTableContext } from '..';
|
|
4
|
-
import { c } from '../misc/helpers';
|
|
5
|
-
import { calcClassName } from './row';
|
|
6
|
-
import { useCommonClasses } from './useCommonClasses';
|
|
7
|
-
export const Cell = memo(function Cell({ itemId, rowIndex }) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
const commonClasses = useCommonClasses();
|
|
10
|
-
const state = useTableContext();
|
|
11
|
-
const columnId = useColumnContext();
|
|
12
|
-
const column = state.useState((state) => state.activeColumns.find((column) => column.id === columnId), [columnId]);
|
|
13
|
-
const item = state.useState((state) => state.activeItemsById.get(itemId), [itemId]);
|
|
14
|
-
const classes = state.useState('props.classes');
|
|
15
|
-
let wrapCell = state.useState('props.wrapCell');
|
|
16
|
-
if (!column || !item)
|
|
17
|
-
return null;
|
|
18
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render cell', itemId, columnId);
|
|
19
|
-
const className = c(calcClassName(classes, item, rowIndex), calcClassName(column === null || column === void 0 ? void 0 : column.classes, item, rowIndex));
|
|
20
|
-
const content = column.renderCell(column.value(item), item);
|
|
21
|
-
if (!wrapCell && typeof content === 'string') {
|
|
22
|
-
wrapCell = (content) => (_jsx("div", Object.assign({ className: c(commonClasses.cell, className) }, { children: _jsx("span", Object.assign({ className: c(commonClasses.text) }, { children: content }), void 0) }), void 0));
|
|
23
|
-
}
|
|
24
|
-
else if (!wrapCell) {
|
|
25
|
-
wrapCell = (content) => _jsx("div", Object.assign({ className: c(commonClasses.cell, className) }, { children: content }), void 0);
|
|
26
|
-
}
|
|
27
|
-
return _jsx(_Fragment, { children: wrapCell(content, item) }, void 0);
|
|
28
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Checkbox, FormControlLabel, IconButton, makeStyles, Popover } from '@material-ui/core';
|
|
3
|
-
import { Settings } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { useTableContext } from '../table';
|
|
6
|
-
const useClasses = makeStyles((theme) => ({
|
|
7
|
-
list: {
|
|
8
|
-
padding: theme.spacing(2),
|
|
9
|
-
display: 'grid',
|
|
10
|
-
},
|
|
11
|
-
}));
|
|
12
|
-
export function ColumnSelection() {
|
|
13
|
-
const classes = useClasses();
|
|
14
|
-
const [anchor, setAnchor] = useState(null);
|
|
15
|
-
const state = useTableContext();
|
|
16
|
-
const columns = state.useState('props.columns');
|
|
17
|
-
const hiddenColumns = state.useState('hiddenColumns');
|
|
18
|
-
const toggle = (column) => {
|
|
19
|
-
const { props: { hiddenColumns: controlledHiddenColumns, onHiddenColumnsChange }, } = state.getState();
|
|
20
|
-
const newValue = new Set(hiddenColumns);
|
|
21
|
-
if (hiddenColumns.has(column.id))
|
|
22
|
-
newValue.delete(column.id);
|
|
23
|
-
else
|
|
24
|
-
newValue.add(column.id);
|
|
25
|
-
if (!controlledHiddenColumns) {
|
|
26
|
-
state.update((state) => {
|
|
27
|
-
state.hiddenColumns = newValue;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
onHiddenColumnsChange === null || onHiddenColumnsChange === void 0 ? void 0 : onHiddenColumnsChange(newValue);
|
|
31
|
-
};
|
|
32
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ color: "inherit", size: "small", onClick: (e) => setAnchor(e.currentTarget) }, { children: _jsx(Settings, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'left' } }, { children: _jsx("div", Object.assign({ className: classes.list }, { children: columns.map((column) => (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: !hiddenColumns.has(column.id), onChange: () => toggle(column), disabled: column.cannotHide }, void 0), label: column.header }, column.id))) }), void 0) }), void 0)] }, void 0));
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Filter } from './filterComponent';
|
|
3
|
-
export declare class DefaultFilter<T, O> implements Filter<T> {
|
|
4
|
-
readonly values: Set<O>;
|
|
5
|
-
readonly filter: (item: T) => boolean;
|
|
6
|
-
constructor(values: Set<O>, filter: (item: T) => boolean);
|
|
7
|
-
}
|
|
8
|
-
declare type UnwrapArray<O> = O extends Array<infer S> ? S : O;
|
|
9
|
-
export declare function DefaultFilterComponent<V>(props: {
|
|
10
|
-
options?: UnwrapArray<V>[];
|
|
11
|
-
compare?: (a: UnwrapArray<V>, b: UnwrapArray<V>) => boolean;
|
|
12
|
-
stringValue?: (value: UnwrapArray<V>) => string;
|
|
13
|
-
render?: (value: UnwrapArray<V>) => ReactNode;
|
|
14
|
-
}): JSX.Element;
|
|
15
|
-
export declare function DefaultFilterComponent<T, V, O>(props: {
|
|
16
|
-
filterBy?: (value: V, item: T) => O | O[];
|
|
17
|
-
options?: O[];
|
|
18
|
-
compare?: (a: O, b: O) => boolean;
|
|
19
|
-
stringValue?: (value: O) => string;
|
|
20
|
-
render?: (value: O) => ReactNode;
|
|
21
|
-
}): JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Checkbox, FormControlLabel, IconButton, makeStyles, TextField } from '@material-ui/core';
|
|
3
|
-
import { Clear, Search } from '@material-ui/icons';
|
|
4
|
-
import { useCallback, useState } from 'react';
|
|
5
|
-
import { asString, defaultEquals, flatMap, orderBy, uniq } from '../misc/helpers';
|
|
6
|
-
import { useColumnContext, useTableContext } from '../table';
|
|
7
|
-
export class DefaultFilter {
|
|
8
|
-
constructor(values, filter) {
|
|
9
|
-
this.values = values;
|
|
10
|
-
this.filter = filter;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const useClasses = makeStyles((theme) => ({
|
|
14
|
-
view: {
|
|
15
|
-
padding: theme.spacing(2),
|
|
16
|
-
display: 'grid',
|
|
17
|
-
'& > :first-child': {
|
|
18
|
-
marginBottom: theme.spacing(2),
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
export function DefaultFilterComponent({ filterBy: _filterBy, options: _options, compare = defaultEquals, stringValue = asString, render = stringValue, }) {
|
|
23
|
-
var _a;
|
|
24
|
-
const classes = useClasses();
|
|
25
|
-
const state = useTableContext();
|
|
26
|
-
const columnId = useColumnContext();
|
|
27
|
-
const filterBy = useCallback((value, item) => {
|
|
28
|
-
const values = _filterBy ? _filterBy(value, item) : value;
|
|
29
|
-
return values instanceof Array ? values : [values];
|
|
30
|
-
}, [_filterBy]);
|
|
31
|
-
const { text, options, filter } = state.useState((state) => {
|
|
32
|
-
const column = state.activeColumns.find((column) => column.id === columnId);
|
|
33
|
-
const _filter = state.filters.get(columnId);
|
|
34
|
-
const filter = _filter instanceof DefaultFilter ? _filter : undefined;
|
|
35
|
-
let options = _options !== null && _options !== void 0 ? _options : orderBy(uniq(flatMap(state.items, (item) => (column ? filterBy(column.value(item), item) : []))));
|
|
36
|
-
if (filter)
|
|
37
|
-
options = options.concat([...filter.values].filter((value) => !options.includes(value)));
|
|
38
|
-
return { text: state.props.text, options, filter };
|
|
39
|
-
}, [_options, columnId, filterBy]);
|
|
40
|
-
const [input, setInput] = useState('');
|
|
41
|
-
const filtered = options.filter((option) => !input || stringValue(option).toLowerCase().includes(input.toLowerCase()));
|
|
42
|
-
function toggle(value) {
|
|
43
|
-
var _a;
|
|
44
|
-
const column = state.getState().activeColumns.find((column) => column.id === columnId);
|
|
45
|
-
if (!column)
|
|
46
|
-
return;
|
|
47
|
-
const newValues = new Set(filter === null || filter === void 0 ? void 0 : filter.values);
|
|
48
|
-
if (newValues === null || newValues === void 0 ? void 0 : newValues.has(value))
|
|
49
|
-
newValues.delete(value);
|
|
50
|
-
else
|
|
51
|
-
newValues === null || newValues === void 0 ? void 0 : newValues.add(value);
|
|
52
|
-
const newFilter = newValues.size === 0
|
|
53
|
-
? undefined
|
|
54
|
-
: new DefaultFilter(newValues, (item) => {
|
|
55
|
-
const itemValues = filterBy(column.value(item), item);
|
|
56
|
-
return [...newValues].some((value) => itemValues.some((itemValue) => compare(value, itemValue)));
|
|
57
|
-
});
|
|
58
|
-
if (!column.filter) {
|
|
59
|
-
state.update((state) => {
|
|
60
|
-
if (newFilter)
|
|
61
|
-
state.filters.set(column.id, newFilter);
|
|
62
|
-
else
|
|
63
|
-
state.filters.delete(column.id);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
(_a = column.onFilterChange) === null || _a === void 0 ? void 0 : _a.call(column, newFilter);
|
|
67
|
-
}
|
|
68
|
-
function deselectAll() {
|
|
69
|
-
var _a;
|
|
70
|
-
const column = state.getState().activeColumns.find((column) => column.id === columnId);
|
|
71
|
-
if (!column)
|
|
72
|
-
return;
|
|
73
|
-
if (!column.filter) {
|
|
74
|
-
state.update((state) => {
|
|
75
|
-
state.filters.delete(column.id);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
(_a = column.onFilterChange) === null || _a === void 0 ? void 0 : _a.call(column);
|
|
79
|
-
}
|
|
80
|
-
return (_jsxs("div", Object.assign({ className: classes.view }, { children: [_jsx(TextField, { value: input, onChange: (e) => setInput(e.target.value), InputProps: {
|
|
81
|
-
endAdornment: input ? (_jsx(IconButton, Object.assign({ onClick: () => setInput('') }, { children: _jsx(Clear, {}, void 0) }), void 0)) : (_jsx(Search, {}, void 0)),
|
|
82
|
-
} }, void 0), _jsx(Button, Object.assign({ variant: "outlined", onClick: deselectAll, disabled: !filter }, { children: (_a = text === null || text === void 0 ? void 0 : text.deselectAll) !== null && _a !== void 0 ? _a : 'Deselect all' }), void 0), filtered.map((value, index) => {
|
|
83
|
-
var _a;
|
|
84
|
-
return (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: (_a = filter === null || filter === void 0 ? void 0 : filter.values.has(value)) !== null && _a !== void 0 ? _a : false, onChange: () => toggle(value) }, void 0), label: render(value) }, index));
|
|
85
|
-
})] }), void 0));
|
|
86
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton } from '@material-ui/core';
|
|
3
|
-
import { ChevronRight } from '@material-ui/icons';
|
|
4
|
-
import { getAncestors } from '../misc/helpers';
|
|
5
|
-
import { useTableContext } from '../table';
|
|
6
|
-
export function ExpandComponent({ itemId }) {
|
|
7
|
-
const state = useTableContext();
|
|
8
|
-
const isExpanded = state.useState((state) => state.expanded.has(itemId), [itemId]);
|
|
9
|
-
function toggle() {
|
|
10
|
-
const { props: { expanded: controlledExpanded, expandOnlyOne, onExpandedChange }, expanded, activeItemsById, } = state.getState();
|
|
11
|
-
const newExpanded = new Set(expanded);
|
|
12
|
-
if (expandOnlyOne)
|
|
13
|
-
newExpanded.clear();
|
|
14
|
-
if (isExpanded)
|
|
15
|
-
newExpanded.delete(itemId);
|
|
16
|
-
else {
|
|
17
|
-
newExpanded.add(itemId);
|
|
18
|
-
const item = activeItemsById.get(itemId);
|
|
19
|
-
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
20
|
-
newExpanded.add(ancestor);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
onExpandedChange === null || onExpandedChange === void 0 ? void 0 : onExpandedChange(newExpanded);
|
|
24
|
-
if (!controlledExpanded) {
|
|
25
|
-
state.update((state) => {
|
|
26
|
-
state.expanded = newExpanded;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return (_jsx(IconButton, Object.assign({ size: "small", onClick: toggle }, { children: _jsx(ChevronRight, { style: {
|
|
31
|
-
transition: 'all 500ms',
|
|
32
|
-
transform: isExpanded ? 'rotate3d(0, 0, 1, 90deg)' : 'none',
|
|
33
|
-
} }, void 0) }), void 0));
|
|
34
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Button, IconButton, makeStyles, Popover, Typography } from '@material-ui/core';
|
|
3
|
-
import { AssignmentReturn, CloudDownload } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { csvExport } from '../misc/csvExport';
|
|
6
|
-
import { useTableContext } from '../table';
|
|
7
|
-
const useClasses = makeStyles((theme) => ({
|
|
8
|
-
dialog: {
|
|
9
|
-
padding: theme.spacing(2),
|
|
10
|
-
display: 'grid',
|
|
11
|
-
justifyItems: 'stretch',
|
|
12
|
-
'& > *': {
|
|
13
|
-
justifyContent: 'start',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
export function Export() {
|
|
18
|
-
const classes = useClasses();
|
|
19
|
-
const [anchor, setAnchor] = useState(null);
|
|
20
|
-
const state = useTableContext();
|
|
21
|
-
const textTitle = state.useState('props.text.exportTitle');
|
|
22
|
-
const textCopy = state.useState('props.text.exportCopy');
|
|
23
|
-
const textDownload = state.useState('props.text.exportDownload');
|
|
24
|
-
const generate = (options) => {
|
|
25
|
-
const { activeColumns, activeItems } = state.getState();
|
|
26
|
-
const data = [
|
|
27
|
-
activeColumns.map((column) => String(column.id)),
|
|
28
|
-
...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item))),
|
|
29
|
-
];
|
|
30
|
-
return csvExport(data, options);
|
|
31
|
-
};
|
|
32
|
-
const copy = () => {
|
|
33
|
-
navigator.clipboard.writeText(generate(state.getState().props.enableExport.copy));
|
|
34
|
-
};
|
|
35
|
-
const download = () => {
|
|
36
|
-
const a = document.createElement('a');
|
|
37
|
-
a.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(generate(state.getState().props.enableExport.download));
|
|
38
|
-
a.download = 'export.csv';
|
|
39
|
-
document.body.appendChild(a);
|
|
40
|
-
a.click();
|
|
41
|
-
document.body.removeChild(a);
|
|
42
|
-
};
|
|
43
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ color: "inherit", size: "small", onClick: (e) => setAnchor(e.currentTarget) }, { children: _jsx(CloudDownload, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'left' } }, { children: _jsxs("div", Object.assign({ className: classes.dialog }, { children: [_jsx(Typography, Object.assign({ variant: "caption" }, { children: textTitle !== null && textTitle !== void 0 ? textTitle : 'Export' }), void 0), _jsx(Button, Object.assign({ startIcon: _jsx(AssignmentReturn, {}, void 0), fullWidth: true, onClick: copy }, { children: textCopy !== null && textCopy !== void 0 ? textCopy : 'In die Zwischenablage' }), void 0), _jsx(Button, Object.assign({ startIcon: _jsx(CloudDownload, {}, void 0), fullWidth: true, onClick: download }, { children: textDownload !== null && textDownload !== void 0 ? textDownload : 'Herunterladen' }), void 0)] }), void 0) }), void 0)] }, void 0));
|
|
44
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton, makeStyles, Popover } from '@material-ui/core';
|
|
3
|
-
import { ArrowDropDown, FilterList } from '@material-ui/icons';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { useColumnContext, useTableContext } from '../table';
|
|
6
|
-
const useClasses = makeStyles((theme) => ({
|
|
7
|
-
active: {
|
|
8
|
-
background: theme.palette.primary.main,
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
export function FilterComponent() {
|
|
12
|
-
const state = useTableContext();
|
|
13
|
-
const columnId = useColumnContext();
|
|
14
|
-
const classes = useClasses();
|
|
15
|
-
const isActive = state.useState((state) => !!state.filters.get(columnId), [columnId]);
|
|
16
|
-
const filterComponent = state.useState((state) => { var _a; return (_a = state.activeColumns.find((column) => column.id === columnId)) === null || _a === void 0 ? void 0 : _a.filterComponent; });
|
|
17
|
-
const [anchor, setAnchor] = useState(null);
|
|
18
|
-
if (!filterComponent)
|
|
19
|
-
return null;
|
|
20
|
-
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ size: "small", color: "inherit", onClick: (e) => setAnchor(e.currentTarget), className: isActive ? classes.active : undefined }, { children: isActive ? _jsx(FilterList, {}, void 0) : _jsx(ArrowDropDown, {}, void 0) }), void 0), _jsx(Popover, Object.assign({ open: !!anchor, onClose: () => setAnchor(null), anchorEl: anchor, anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' } }, { children: filterComponent }), void 0)] }, void 0));
|
|
21
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Id, InternalColumn } from '../types';
|
|
3
|
-
export declare function calcClassName<T>(classes: InternalColumn<any, any>['classes'] | undefined, item: T, index: number): string;
|
|
4
|
-
export declare const Row: React.MemoExoticComponent<(<T>({ itemId, rowIndex }: {
|
|
5
|
-
itemId: Id;
|
|
6
|
-
rowIndex: number;
|
|
7
|
-
}) => JSX.Element | null)>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useEffect, useRef } from 'react';
|
|
3
|
-
import { c, getAncestors } from '../misc/helpers';
|
|
4
|
-
import { ColumnContext, useTableContext } from '../table';
|
|
5
|
-
import { Cell } from './cell';
|
|
6
|
-
import { ExpandComponent } from './expandComponent';
|
|
7
|
-
import { SelectComponent } from './selectComponent';
|
|
8
|
-
import { useCommonClasses } from './useCommonClasses';
|
|
9
|
-
export function calcClassName(classes, item, index) {
|
|
10
|
-
return c((classes === null || classes === void 0 ? void 0 : classes.cell) instanceof Function ? classes.cell(item, index) : classes === null || classes === void 0 ? void 0 : classes.cell, (classes === null || classes === void 0 ? void 0 : classes.evenCell) === undefined ? undefined : { [classes.evenCell]: index % 2 === 0 }, (classes === null || classes === void 0 ? void 0 : classes.oddCell) === undefined ? undefined : { [classes.oddCell]: index % 2 === 1 });
|
|
11
|
-
}
|
|
12
|
-
export const Row = memo(function Row({ itemId, rowIndex }) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const commonClasses = useCommonClasses();
|
|
15
|
-
const state = useTableContext();
|
|
16
|
-
const divRef = useRef(null);
|
|
17
|
-
const { className, indent, hasChildren, hasDeferredChildren, columnIds, enableSelection, rowAction } = state.useState((state) => {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
const item = state.activeItemsById.get(itemId);
|
|
20
|
-
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
21
|
-
return {
|
|
22
|
-
className: calcClassName(state.props.classes, item, index),
|
|
23
|
-
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
24
|
-
hasChildren: !!(item === null || item === void 0 ? void 0 : item.children.length),
|
|
25
|
-
hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) === null || _b === void 0 ? void 0 : _b.call(_a, item)),
|
|
26
|
-
columnIds: state.activeColumns.map((column) => column.id),
|
|
27
|
-
enableSelection: state.props.enableSelection,
|
|
28
|
-
rowAction: state.props.rowAction instanceof Function ? (item ? state.props.rowAction(item, index) : null) : state.props.rowAction,
|
|
29
|
-
};
|
|
30
|
-
}, [itemId]);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
const div = divRef.current;
|
|
33
|
-
if (!div)
|
|
34
|
-
return;
|
|
35
|
-
const o = new ResizeObserver(() => {
|
|
36
|
-
if (!document.contains(div))
|
|
37
|
-
return;
|
|
38
|
-
state.update((state) => {
|
|
39
|
-
state.rowHeights.set(itemId, div.offsetHeight);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
o.observe(div);
|
|
43
|
-
return () => o.disconnect();
|
|
44
|
-
}, [divRef.current]);
|
|
45
|
-
(_b = (_a = state.getState().props).debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'render row', itemId);
|
|
46
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: c(commonClasses.cellFill, className), ref: divRef }, void 0), _jsxs("div", Object.assign({ className: c(commonClasses.cell, commonClasses.firstCell, className) }, { children: [_jsx("div", { style: { width: indent * 20 } }, void 0), enableSelection && _jsx(SelectComponent, { itemId: itemId }, void 0), (hasChildren || hasDeferredChildren) && _jsx(ExpandComponent, { itemId: itemId }, void 0), rowAction] }), void 0), columnIds.map((columnId) => (_jsx(ColumnContext.Provider, Object.assign({ value: columnId }, { children: _jsx(Cell, { itemId: itemId, rowIndex: rowIndex }, void 0) }), columnId))), _jsx("div", { className: c(commonClasses.cellFill, className) }, void 0)] }, void 0));
|
|
47
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Checkbox, makeStyles } from '@material-ui/core';
|
|
3
|
-
import { getAncestors, getDescendants } from '../misc/helpers';
|
|
4
|
-
import { useTableContext } from '../table';
|
|
5
|
-
const useClasses = makeStyles({
|
|
6
|
-
justifiedCheckbox: {
|
|
7
|
-
justifySelf: 'start',
|
|
8
|
-
color: 'inherit',
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
export function SelectComponent({ itemId }) {
|
|
12
|
-
const classes = useClasses();
|
|
13
|
-
const state = useTableContext();
|
|
14
|
-
const isSelected = state.useState((state) => {
|
|
15
|
-
const itemIds = itemId ? [itemId] : [...state.activeItemsById.keys()];
|
|
16
|
-
return state.activeItemsById.size > 0 && itemIds.every((itemId) => state.selection.has(itemId));
|
|
17
|
-
}, [itemId]);
|
|
18
|
-
function toggle(e) {
|
|
19
|
-
const mouseEvent = e.nativeEvent;
|
|
20
|
-
const { activeItems, activeItemsById, lastSelectedId, selection, props: { selectSyncChildren, selection: controlledSelection, onSelectionChange }, } = state.getState();
|
|
21
|
-
let range;
|
|
22
|
-
if (mouseEvent.shiftKey && itemId) {
|
|
23
|
-
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
24
|
-
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
25
|
-
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const item = itemId ? activeItemsById.get(itemId) : undefined;
|
|
29
|
-
range = item ? [item] : activeItems;
|
|
30
|
-
}
|
|
31
|
-
const newSelection = new Set(selection);
|
|
32
|
-
for (const item of range) {
|
|
33
|
-
if (isSelected)
|
|
34
|
-
newSelection.delete(item.id);
|
|
35
|
-
else
|
|
36
|
-
newSelection.add(item.id);
|
|
37
|
-
}
|
|
38
|
-
if (selectSyncChildren && isSelected) {
|
|
39
|
-
for (const ancestor of getAncestors(activeItemsById, ...range)) {
|
|
40
|
-
newSelection.delete(ancestor);
|
|
41
|
-
}
|
|
42
|
-
for (const descendant of getDescendants(...range)) {
|
|
43
|
-
newSelection.delete(descendant);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelection);
|
|
47
|
-
if (!controlledSelection) {
|
|
48
|
-
state.update((state) => {
|
|
49
|
-
state.selection = newSelection;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
state.update((state) => {
|
|
53
|
-
state.lastSelectedId = itemId;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return _jsx(Checkbox, { className: classes.justifiedCheckbox, checked: isSelected, onChange: toggle }, void 0);
|
|
57
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Badge, makeStyles } from '@material-ui/core';
|
|
3
|
-
import { ArrowDownward, ArrowUpward } from '@material-ui/icons';
|
|
4
|
-
import { useColumnContext, useTableContext } from '../table';
|
|
5
|
-
const useClasses = makeStyles({
|
|
6
|
-
sortView: {
|
|
7
|
-
userSelect: 'none',
|
|
8
|
-
display: 'grid',
|
|
9
|
-
gridTemplateColumns: 'minmax(0, 1fr) max-content',
|
|
10
|
-
alignItems: 'center',
|
|
11
|
-
cursor: 'pointer',
|
|
12
|
-
'& > div': {
|
|
13
|
-
overflow: 'hidden',
|
|
14
|
-
textOverflow: 'ellipsis',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
empty: {
|
|
18
|
-
width: 20,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
export function SortComponent({ children }) {
|
|
22
|
-
const classes = useClasses();
|
|
23
|
-
const state = useTableContext();
|
|
24
|
-
const columnId = useColumnContext();
|
|
25
|
-
const { direction, index } = state.useState((state) => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const index = (_a = state.sort.findIndex((s) => s.columnId === columnId)) !== null && _a !== void 0 ? _a : -1;
|
|
28
|
-
return {
|
|
29
|
-
direction: (_b = state.sort[index]) === null || _b === void 0 ? void 0 : _b.direction,
|
|
30
|
-
index: index >= 0 && state.sort.length > 1 ? index + 1 : undefined,
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
function toggle(e) {
|
|
34
|
-
const { props: { sort: controlledSort, onSortChange }, } = state.getState();
|
|
35
|
-
const newDirection = direction === 'asc' ? 'desc' : 'asc';
|
|
36
|
-
const newSort = (e.getModifierState('Control') ? state.getState().sort.filter((s) => s.columnId !== columnId) : []).concat({
|
|
37
|
-
columnId,
|
|
38
|
-
direction: newDirection,
|
|
39
|
-
});
|
|
40
|
-
onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newSort);
|
|
41
|
-
if (!controlledSort) {
|
|
42
|
-
state.update((state) => {
|
|
43
|
-
state.sort = newSort;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return (_jsxs("div", Object.assign({ className: classes.sortView, onClick: toggle }, { children: [_jsx("div", { children: children }, void 0), _jsx(Badge, Object.assign({ badgeContent: index }, { children: direction === 'asc' ? (_jsx(ArrowUpward, { fontSize: "small" }, void 0)) : direction === 'desc' ? (_jsx(ArrowDownward, { fontSize: "small" }, void 0)) : (_jsx("div", { className: classes.empty }, void 0)) }), void 0)] }), void 0));
|
|
48
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Filter } from './filterComponent';
|
|
3
|
-
export declare class TextFilter<T> implements Filter<T> {
|
|
4
|
-
readonly query: string;
|
|
5
|
-
readonly filter: (item: T) => boolean;
|
|
6
|
-
constructor(query: string, filter: (item: T) => boolean);
|
|
7
|
-
}
|
|
8
|
-
export declare function TextFilterComponent<T, V>({ filterBy, compare, }: {
|
|
9
|
-
filterBy?: (value: V, item: T) => string;
|
|
10
|
-
compare?: (a: string, b: string) => boolean;
|
|
11
|
-
}): JSX.Element;
|