@symply.io/basic-components 1.1.4 → 1.2.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/Autocomplete/index.js +2 -2
- package/Autocomplete/types.d.ts +1 -0
- package/AutocompleteWithFilter/index.js +2 -2
- package/AutocompleteWithFilter/types.d.ts +1 -0
- package/DataTable/index.d.ts +1 -0
- package/DataTable/index.js +1 -0
- package/README.md +8 -67
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/package.json +1 -1
- package/BasicTable/TableBody.d.ts +0 -4
- package/BasicTable/TableBody.js +0 -50
- package/BasicTable/TableBodyRow.d.ts +0 -3
- package/BasicTable/TableBodyRow.js +0 -54
- package/BasicTable/TableFooter.d.ts +0 -3
- package/BasicTable/TableFooter.js +0 -45
- package/BasicTable/TableHeader.d.ts +0 -3
- package/BasicTable/TableHeader.js +0 -48
- package/BasicTable/index.d.ts +0 -5
- package/BasicTable/index.js +0 -88
- package/BasicTable/types.d.ts +0 -83
- package/BasicTable/types.js +0 -1
- package/BasicTable/useScroll.d.ts +0 -9
- package/BasicTable/useScroll.js +0 -76
- package/BasicTable/useTable.d.ts +0 -3
- package/BasicTable/useTable.js +0 -94
package/Autocomplete/index.js
CHANGED
@@ -27,10 +27,10 @@ import TextField from "@mui/material/TextField";
|
|
27
27
|
import useInteractions from "./useInteractions";
|
28
28
|
import useCustomTheme from "../useCustomTheme";
|
29
29
|
function CustomAutocomplete(props) {
|
30
|
-
var size = props.size, value = props.value, options = props.options, multiple = props.multiple, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, rest = __rest(props, ["size", "value", "options", "multiple", "primaryColor", "secondaryColor", "onChange", "required"]);
|
30
|
+
var size = props.size, value = props.value, options = props.options, multiple = props.multiple, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, limitTags = props.limitTags, rest = __rest(props, ["size", "value", "options", "multiple", "primaryColor", "secondaryColor", "onChange", "required", "limitTags"]);
|
31
31
|
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
32
32
|
var _a = useInteractions(), inputValue = _a.inputValue, onInputChange = _a.onInputChange;
|
33
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, options: options, multiple: multiple, onChange: function (_, val) {
|
33
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, limitTags: limitTags !== null && limitTags !== void 0 ? limitTags : -1, options: options, multiple: multiple, onChange: function (_, val) {
|
34
34
|
onChange(val);
|
35
35
|
}, isOptionEqualToValue: function (opt, val) { return opt.label === val.label; }, value: value, inputValue: inputValue, onInputChange: onInputChange, renderInput: function (params) { return (_jsx(TextField, __assign({}, params, rest, { required: required, size: size, inputProps: __assign(__assign({}, params.inputProps), { required: required && (Array.isArray(value) ? value.length === 0 : !value) }) }))); } }) })));
|
36
36
|
}
|
package/Autocomplete/types.d.ts
CHANGED
@@ -8,6 +8,7 @@ export declare type AutocompleteOptionType<T = {
|
|
8
8
|
export declare type AutocompleteValueType<T, multiple extends boolean | undefined> = multiple extends false | undefined ? AutocompleteOptionType<T> | null : Array<AutocompleteOptionType<T>>;
|
9
9
|
export interface AutocompleteProps<T, multiple extends boolean | undefined> extends Omit<TextFieldProps, "onChange" | "value"> {
|
10
10
|
multiple?: multiple;
|
11
|
+
limitTags?: number;
|
11
12
|
options: Array<AutocompleteOptionType<T>>;
|
12
13
|
value: AutocompleteValueType<T, multiple>;
|
13
14
|
primaryColor?: CSSProperties["color"];
|
@@ -31,7 +31,7 @@ import useCustomTheme from "../useCustomTheme";
|
|
31
31
|
var icon = _jsx(CheckBoxOutlineBlankIcon, { fontSize: "small" });
|
32
32
|
var checkedIcon = _jsx(CheckBoxIcon, { fontSize: "small" });
|
33
33
|
function AutocompleteWithFilter(props) {
|
34
|
-
var size = props.size, value = props.value, options = props.options, multiple = props.multiple, disableCloseOnSelect = props.disableCloseOnSelect, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, rest = __rest(props, ["size", "value", "options", "multiple", "disableCloseOnSelect", "primaryColor", "secondaryColor", "onChange", "required"]);
|
34
|
+
var size = props.size, value = props.value, options = props.options, multiple = props.multiple, disableCloseOnSelect = props.disableCloseOnSelect, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, onChange = props.onChange, required = props.required, limitTags = props.limitTags, rest = __rest(props, ["size", "value", "options", "multiple", "disableCloseOnSelect", "primaryColor", "secondaryColor", "onChange", "required", "limitTags"]);
|
35
35
|
var filter = createFilterOptions({
|
36
36
|
ignoreCase: true,
|
37
37
|
ignoreAccents: true,
|
@@ -39,7 +39,7 @@ function AutocompleteWithFilter(props) {
|
|
39
39
|
stringify: function (option) { return option.label; }
|
40
40
|
});
|
41
41
|
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
42
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, limitTags: 1, options: options, multiple: multiple, filterOptions: filter, onChange: function (_, val) {
|
42
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Autocomplete, { size: size, fullWidth: true, limitTags: limitTags !== null && limitTags !== void 0 ? limitTags : -1, options: options, multiple: multiple, filterOptions: filter, onChange: function (_, val) {
|
43
43
|
onChange(val);
|
44
44
|
}, value: value, disableCloseOnSelect: disableCloseOnSelect || multiple, getOptionLabel: function (option) {
|
45
45
|
return option.label || "";
|
@@ -8,6 +8,7 @@ export interface AutocompleteWithFilterProps<T, multiple extends boolean | undef
|
|
8
8
|
value: AutocompleteWithFilterlValueType<T, multiple>;
|
9
9
|
options: Array<AutocompleteWithFilterOptionType<T>>;
|
10
10
|
disableCloseOnSelect?: boolean;
|
11
|
+
limitTags?: number;
|
11
12
|
multiple?: multiple;
|
12
13
|
primaryColor?: CSSProperties["color"];
|
13
14
|
secondaryColor?: CSSProperties["color"];
|
package/DataTable/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { DataTableProps, KvProps } from "./types";
|
2
2
|
declare function DataTable<RowProps extends KvProps, ExtendedProps extends KvProps>(props: DataTableProps<RowProps, ExtendedProps>): JSX.Element;
|
3
3
|
export default DataTable;
|
4
|
+
export * from "./types";
|
4
5
|
export { default as useDataTable } from "./useTable";
|
package/DataTable/index.js
CHANGED
@@ -57,4 +57,5 @@ function DataTable(props) {
|
|
57
57
|
} }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, stickyHeader: stickyHeader, size: dense ? "small" : "medium" }, { children: [_jsx(TableHeader, { headers: headers, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onCustomizeRowBgColor: onCustomizeRowBgColor, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible }), footers.length > 0 ? (_jsx(TableFooter, { footers: footers, noData: rows.length === 0, leftShadowVisible: leftShadowVisible, rightShadowVisible: rightShadowVisible })) : (_jsx(_Fragment, {}))] })) })) })));
|
58
58
|
}
|
59
59
|
export default DataTable;
|
60
|
+
export * from "./types";
|
60
61
|
export { default as useDataTable } from "./useTable";
|
package/README.md
CHANGED
@@ -15,7 +15,6 @@
|
|
15
15
|
- [Autocomplete](#autocomplete)
|
16
16
|
- [AutocompleteWithFilter](#autocompletewithfilter)
|
17
17
|
- [BasicModal](#basicmodal)
|
18
|
-
- [BasicTable [⚠️Deprecated]](#basictable)
|
19
18
|
- [BreadCrumbs](#breadcrumbs)
|
20
19
|
- [CheckBox](#checkbox)
|
21
20
|
- [CheckBoxGroup](#checkboxgroup)
|
@@ -127,12 +126,13 @@ import Autocomplete from '@symply.io/basic-components/Autocomplete';
|
|
127
126
|
|
128
127
|
<h5>Props</h5>
|
129
128
|
|
130
|
-
| Name
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
| Name | Type | Default | Required | Description |
|
130
|
+
| --------- | ---------------------- | ------- | -------- | ------------------------------------------------------------ |
|
131
|
+
| limitTags | number | -1 | false | The maximum number of tags that will be visible when not focused. Set `-1` to disable the limit. |
|
132
|
+
| multiple | bool | false | false | If `true`, `value` must be an array and the menu will support multiple selections. |
|
133
|
+
| onChange | func | | true | Callback fired when the `Input` value is changed.<br />**Signature:**<br/>`function(value: Array<IOption|string>|IOption|string|null) => void`<br/>*value:* The value of the `Input` element. |
|
134
|
+
| options | Array<IOption\|string> | | true | Array of suggestion options. |
|
135
|
+
| value | string | | true | The value of the `Input` element. |
|
136
136
|
|
137
137
|
|
138
138
|
|
@@ -162,6 +162,7 @@ import AutocompleteWithFilter from '@symply.io/basic-components/AutocompleteWith
|
|
162
162
|
| Name | Type | Default | Required | Description |
|
163
163
|
| -------------------- | ---------------------- | ------- | -------- | ------------------------------------------------------------ |
|
164
164
|
| disableCloseOnSelect | bool | false | false | If `true`, the popup won't close when a value is selected. |
|
165
|
+
| limitTags | number | -1 | false | The maximum number of tags that will be visible when not focused. Set `-1` to disable the limit. |
|
165
166
|
| multiple | bool | false | false | If `true`, `value` must be an array and the menu will support multiple selections. |
|
166
167
|
| onChange | func | | true | Callback fired when the `Input` value is changed.<br />**Signature:**<br/>`function(value: Array<IOption|string>|IOption|string|null) => void`<br/>*value:* The value of the `Input` element. |
|
167
168
|
| options | Array<IOption\|string> | | true | Array of suggestion options. |
|
@@ -203,66 +204,6 @@ import BasicModal from '@symply.io/basic-components/BasicModal';
|
|
203
204
|
|
204
205
|
|
205
206
|
|
206
|
-
<h3>BasicTable</h3>
|
207
|
-
|
208
|
-
Reusable table component
|
209
|
-
|
210
|
-
⚠️ This component will be deprecated in the next release. Please use [`DataTable`](#datatable) instead.
|
211
|
-
|
212
|
-
<h5>Import</h5>
|
213
|
-
|
214
|
-
```tsx
|
215
|
-
import { BasicTable, useTable } from '@symply.io/basic-components';
|
216
|
-
// or
|
217
|
-
import BasicTable, { useTable } from '@symply.io/basic-components/BasicTable';
|
218
|
-
```
|
219
|
-
|
220
|
-
<h5>Column Props (IColumn)</h5>
|
221
|
-
|
222
|
-
| Name | Type | Default | Required | Description |
|
223
|
-
| ----------- | --------------------------- | ------- | -------- | ----------------------------------------------------- |
|
224
|
-
| accessor | string | | true | The key of the column, it should be unique. |
|
225
|
-
| align | "left" \|"center" \|"right" | | false | The alignment of the column. |
|
226
|
-
| Body | ReactElement | | true | The component to render the column body cell. |
|
227
|
-
| canBeFrozen | bool | | false | If true, the column can be frozen |
|
228
|
-
| canSort | bool | | false | If true, the column can be sortable. |
|
229
|
-
| Header | ReactElement | | true | The component to render the column header cell. |
|
230
|
-
| headerTip | string | | false | The tip title text when the mouse is over the header. |
|
231
|
-
| Footer | ReactElement | | false | The component to render the column footer cell. |
|
232
|
-
| minWidth | number | 120 | false | The minimum width of cells. |
|
233
|
-
| width | number | | false | The fixed width of cells. |
|
234
|
-
|
235
|
-
<h5>Hook Props</h5>
|
236
|
-
|
237
|
-
| Name | Type | Default | Required | Description |
|
238
|
-
| ------------- | -------------------------- | ------- | -------- | ------------------------------------------- |
|
239
|
-
| columns | Array\<IColumn\> | | true | table columns |
|
240
|
-
| data | Array<{ [name]: unknown }> | | true | table data/rows |
|
241
|
-
| disableSortBy | bool | | false | If true, the whole table can't be sortable. |
|
242
|
-
| initialState | { sortBy?: SortByProps } | | false | Set the initial states |
|
243
|
-
| onSort | func | | false | The function for sorting rows. |
|
244
|
-
|
245
|
-
<h5>Hook Returns</h5>
|
246
|
-
|
247
|
-
| Name | Type | Description |
|
248
|
-
| ------- | -------------------- | ------------------------- |
|
249
|
-
| headers | Array\<IHeader\> | The cells for the header. |
|
250
|
-
| columns | Array\<IBodyColumn\> | The cells for the body. |
|
251
|
-
| footers | Array\<IFooter> | The cells for the footer. |
|
252
|
-
| rows | Array<IRow\> | The rows for the table. |
|
253
|
-
|
254
|
-
<h5>Component Props</h5>
|
255
|
-
|
256
|
-
| Name | Type | Default | Required | Description |
|
257
|
-
| ---------- | -------------------- | ---------- | -------- | ----------------------------------------- |
|
258
|
-
| headers | Array\<IHeader\> | | true | The cells for the header. (from the hook) |
|
259
|
-
| columns | Array\<IBodyColumn\> | | true | The cells for the body. (from the hook) |
|
260
|
-
| footers | Array\<IFooter> | [] | false | The cells for the footer. (from the hook) |
|
261
|
-
| noDataText | string | 'No Data!' | false | The text when no data rendered. |
|
262
|
-
| rows | Array<IRow\> | | true | The rows for the table. (from the hook) |
|
263
|
-
|
264
|
-
|
265
|
-
|
266
207
|
<h3>BreadCrumbs</h3>
|
267
208
|
|
268
209
|
A list of links that help a user visualize a page's location within the hierarchical structure of a website, and allow navigation up to any of its "ancestors".
|
package/index.d.ts
CHANGED
@@ -2,7 +2,6 @@ export * from "./AlertDialog";
|
|
2
2
|
export * from "./Autocomplete";
|
3
3
|
export * from "./AutocompleteWithFilter";
|
4
4
|
export * from "./BasicModal";
|
5
|
-
export * from "./BasicTable";
|
6
5
|
export * from "./BreadCrumbs";
|
7
6
|
export * from "./CheckBox";
|
8
7
|
export * from "./Copyright";
|
@@ -31,7 +30,6 @@ export { default as AlertDialog } from "./AlertDialog";
|
|
31
30
|
export { default as Autocomplete } from "./Autocomplete";
|
32
31
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
33
32
|
export { default as BasicModal } from "./BasicModal";
|
34
|
-
export { default as BasicTable } from "./BasicTable";
|
35
33
|
export { default as BreadCrumbs } from "./BreadCrumbs";
|
36
34
|
export { default as Copyright } from "./Copyright";
|
37
35
|
export { default as DataTable } from "./DataTable";
|
package/index.js
CHANGED
@@ -2,7 +2,6 @@ export * from "./AlertDialog";
|
|
2
2
|
export * from "./Autocomplete";
|
3
3
|
export * from "./AutocompleteWithFilter";
|
4
4
|
export * from "./BasicModal";
|
5
|
-
export * from "./BasicTable";
|
6
5
|
export * from "./BreadCrumbs";
|
7
6
|
export * from "./CheckBox";
|
8
7
|
export * from "./Copyright";
|
@@ -31,7 +30,6 @@ export { default as AlertDialog } from "./AlertDialog";
|
|
31
30
|
export { default as Autocomplete } from "./Autocomplete";
|
32
31
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
33
32
|
export { default as BasicModal } from "./BasicModal";
|
34
|
-
export { default as BasicTable } from "./BasicTable";
|
35
33
|
export { default as BreadCrumbs } from "./BreadCrumbs";
|
36
34
|
export { default as Copyright } from "./Copyright";
|
37
35
|
export { default as DataTable } from "./DataTable";
|
package/package.json
CHANGED
package/BasicTable/TableBody.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
-
import { forwardRef } from "react";
|
14
|
-
import Grid from "@mui/material/Grid";
|
15
|
-
import useTheme from "@mui/material/styles/useTheme";
|
16
|
-
import TableBodyRow from "./TableBodyRow";
|
17
|
-
function BasicTableBody(props, ref) {
|
18
|
-
var rows = props.rows, columns = props.columns, rowHeight = props.rowHeight, forFrozen = props.forFrozen, noDataText = props.noDataText, onRowClick = props.onRowClick;
|
19
|
-
var theme = useTheme();
|
20
|
-
return (_jsx(Grid, __assign({ item: true, sx: {
|
21
|
-
maxHeight: "41vh",
|
22
|
-
overflowY: "auto",
|
23
|
-
display: "block",
|
24
|
-
minWidth: "100%",
|
25
|
-
scrollbarWidth: forFrozen ? "none" : "initial",
|
26
|
-
"&::-webkit-scrollbar": {
|
27
|
-
width: forFrozen ? 0 : "initial"
|
28
|
-
}
|
29
|
-
} }, { children: _jsx("div", __assign({ ref: ref }, { children: rows.length > 0 ? (rows.map(function (row, index) {
|
30
|
-
return (_jsx(TableBodyRow, { row: row, rows: rows, rowHeight: rowHeight, forFrozen: forFrozen, columns: columns, onRowClick: onRowClick }, "BasicTable_".concat(index)));
|
31
|
-
})) : (_jsx(Grid, __assign({ container: true, justifyContent: "space-around", alignItems: "center", wrap: "nowrap", sx: {
|
32
|
-
height: rowHeight || theme.spacing(7.5),
|
33
|
-
borderBottomWidth: "thin",
|
34
|
-
borderBottomColor: "#e5e5e5",
|
35
|
-
borderBottomStyle: "solid",
|
36
|
-
padding: theme.spacing(0.5, 0),
|
37
|
-
minHeight: theme.spacing(5),
|
38
|
-
"& :nth-of-last-type(1)": {
|
39
|
-
borderBottom: "none"
|
40
|
-
},
|
41
|
-
"& input": {
|
42
|
-
fontSize: "0.9rem",
|
43
|
-
fontWeight: 600
|
44
|
-
}
|
45
|
-
} }, { children: _jsx(Grid, __assign({ item: true, xs: 4, md: 3, lg: 2, textAlign: "center", sx: {
|
46
|
-
paddingLeft: theme.spacing(0.625),
|
47
|
-
paddingRight: theme.spacing(0.625)
|
48
|
-
} }, { children: noDataText })) }))) })) })));
|
49
|
-
}
|
50
|
-
export default forwardRef(BasicTableBody);
|
@@ -1,54 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
-
import { cloneElement } from "react";
|
14
|
-
import colorAlpha from "color-alpha";
|
15
|
-
import Grid from "@mui/material/Grid";
|
16
|
-
import useTheme from "@mui/material/styles/useTheme";
|
17
|
-
function BasicTableBodyRow(props) {
|
18
|
-
var row = props.row, rows = props.rows, columns = props.columns, forFrozen = props.forFrozen, rowHeight = props.rowHeight, onRowClick = props.onRowClick;
|
19
|
-
var theme = useTheme();
|
20
|
-
return (_jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
|
21
|
-
height: rowHeight || theme.spacing(7.5),
|
22
|
-
borderBottomWidth: "thin",
|
23
|
-
borderBottomColor: "#e5e5e5",
|
24
|
-
borderBottomStyle: "solid",
|
25
|
-
padding: theme.spacing(0.5, 0),
|
26
|
-
minHeight: theme.spacing(5),
|
27
|
-
"&:hover": {
|
28
|
-
cursor: !forFrozen && onRowClick ? "pointer" : "default",
|
29
|
-
backgroundColor: !forFrozen && onRowClick
|
30
|
-
? colorAlpha(theme.palette.primary.main, 0.1)
|
31
|
-
: "initial"
|
32
|
-
},
|
33
|
-
"& :nth-of-last-type(1)": {
|
34
|
-
borderBottom: "none"
|
35
|
-
},
|
36
|
-
"& input": {
|
37
|
-
fontSize: "0.9rem",
|
38
|
-
fontWeight: 600
|
39
|
-
}
|
40
|
-
}, onClick: onRowClick
|
41
|
-
? function () {
|
42
|
-
onRowClick(row);
|
43
|
-
}
|
44
|
-
: undefined }, { children: columns.map(function (col) {
|
45
|
-
var accessor = col.accessor, Cell = col.Cell, _a = col.minWidth, minWidth = _a === void 0 ? "120px!important" : _a, width = col.width, _b = col.align, align = _b === void 0 ? "center" : _b;
|
46
|
-
return (_jsx(Grid, __assign({ item: true, textAlign: align, sx: {
|
47
|
-
minWidth: minWidth,
|
48
|
-
width: width,
|
49
|
-
paddingLeft: theme.spacing(0.625),
|
50
|
-
paddingRight: theme.spacing(0.625)
|
51
|
-
} }, { children: cloneElement(Cell, { column: col, rows: rows, row: row }) }), accessor));
|
52
|
-
}) })));
|
53
|
-
}
|
54
|
-
export default BasicTableBodyRow;
|
@@ -1,45 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
13
|
-
import { cloneElement } from "react";
|
14
|
-
import Grid from "@mui/material/Grid";
|
15
|
-
import useTheme from "@mui/material/styles/useTheme";
|
16
|
-
function BasicTableFooter(props) {
|
17
|
-
var footers = props.footers;
|
18
|
-
var theme = useTheme();
|
19
|
-
return footers && footers.length > 0 ? (_jsx(Grid, __assign({ item: true, sx: {
|
20
|
-
backgroundColor: "#eaf0f6",
|
21
|
-
padding: theme.spacing(1.5, 0),
|
22
|
-
height: theme.spacing(6.25)
|
23
|
-
} }, { children: _jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
|
24
|
-
lineHeight: "24px",
|
25
|
-
minWidth: "100%",
|
26
|
-
"& span": {
|
27
|
-
color: "#172b4d",
|
28
|
-
fontSize: "1rem",
|
29
|
-
fontWeight: 600
|
30
|
-
}
|
31
|
-
} }, { children: footers.map(function (footer) {
|
32
|
-
var accessor = footer.accessor, Cell = footer.Cell, _a = footer.minWidth, minWidth = _a === void 0 ? "120px!important" : _a, width = footer.width, _b = footer.align, align = _b === void 0 ? "center" : _b;
|
33
|
-
return (_jsx(Grid, __assign({ item: true, textAlign: align, sx: {
|
34
|
-
minWidth: minWidth,
|
35
|
-
width: width,
|
36
|
-
paddingLeft: theme.spacing(0.625),
|
37
|
-
paddingRight: theme.spacing(0.625),
|
38
|
-
whiteSpace: "nowrap",
|
39
|
-
textOverflow: "ellipsis",
|
40
|
-
overflow: "hidden",
|
41
|
-
userSelect: "none"
|
42
|
-
} }, { children: cloneElement(Cell) }), accessor));
|
43
|
-
}) })) }))) : (_jsx(_Fragment, {}));
|
44
|
-
}
|
45
|
-
export default BasicTableFooter;
|
@@ -1,48 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
13
|
-
import { cloneElement } from "react";
|
14
|
-
import Grid from "@mui/material/Grid";
|
15
|
-
import useTheme from "@mui/material/styles/useTheme";
|
16
|
-
function BasicTableHeader(props) {
|
17
|
-
var headers = props.headers;
|
18
|
-
var theme = useTheme();
|
19
|
-
return headers && headers.length > 0 ? (_jsx(Grid, __assign({ item: true, sx: {
|
20
|
-
backgroundColor: "#eaf0f6",
|
21
|
-
padding: theme.spacing(1.5, 0),
|
22
|
-
height: theme.spacing(6.25)
|
23
|
-
} }, { children: _jsx(Grid, __assign({ container: true, justifyContent: "space-evenly", alignItems: "center", wrap: "nowrap", sx: {
|
24
|
-
lineHeight: "24px",
|
25
|
-
minWidth: "100%",
|
26
|
-
"& span": {
|
27
|
-
color: "#172b4d",
|
28
|
-
fontSize: "1rem",
|
29
|
-
fontWeight: 600
|
30
|
-
}
|
31
|
-
} }, { children: headers.map(function (header) {
|
32
|
-
var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, _b = header.minWidth, minWidth = _b === void 0 ? "120px!important" : _b, width = header.width, title = header.title, onSort = header.onSort, _c = header.canSort, canSort = _c === void 0 ? false : _c;
|
33
|
-
return (_jsx(Grid, __assign({ item: true, title: title, textAlign: align, sx: {
|
34
|
-
minWidth: minWidth,
|
35
|
-
width: width,
|
36
|
-
paddingLeft: theme.spacing(0.625),
|
37
|
-
paddingRight: theme.spacing(0.625),
|
38
|
-
whiteSpace: "nowrap",
|
39
|
-
textOverflow: "ellipsis",
|
40
|
-
overflow: "hidden",
|
41
|
-
userSelect: "none",
|
42
|
-
cursor: canSort ? "pointer" : "default"
|
43
|
-
}, onClick: function () {
|
44
|
-
onSort({ field: accessor });
|
45
|
-
} }, { children: cloneElement(Cell) }), accessor));
|
46
|
-
}) })) }))) : (_jsx(_Fragment, {}));
|
47
|
-
}
|
48
|
-
export default BasicTableHeader;
|
package/BasicTable/index.d.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
import { BasicTableProps, KvProps } from "./types";
|
2
|
-
declare function BasicTable<RowProps extends KvProps, ExtraProps extends KvProps>(props: BasicTableProps<RowProps, ExtraProps>): JSX.Element;
|
3
|
-
export default BasicTable;
|
4
|
-
export * from "./types";
|
5
|
-
export { default as useTable } from "./useTable";
|
package/BasicTable/index.js
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
-
import { useMemo, useEffect } from "react";
|
14
|
-
import Grid from "@mui/material/Grid";
|
15
|
-
import TableContainer from "@mui/material/TableContainer";
|
16
|
-
import useMediaQuery from "@mui/material/useMediaQuery";
|
17
|
-
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
18
|
-
import useCustomTheme from "../useCustomTheme";
|
19
|
-
import useScroll from "./useScroll";
|
20
|
-
import TableBody from "./TableBody";
|
21
|
-
import TableHeader from "./TableHeader";
|
22
|
-
import TableFooter from "./TableFooter";
|
23
|
-
function BasicTable(props) {
|
24
|
-
var _a;
|
25
|
-
var _b = props.columns, columns = _b === void 0 ? [] : _b, _c = props.rows, rows = _c === void 0 ? [] : _c, _d = props.headers, headers = _d === void 0 ? [] : _d, _e = props.footers, footers = _e === void 0 ? [] : _e, _f = props.noDataText, noDataText = _f === void 0 ? "No Data!" : _f, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rowHeight = props.rowHeight, onRowClick = props.onRowClick;
|
26
|
-
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
27
|
-
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
28
|
-
var fronzenColsCount = useMemo(function () { var _a; return (_a = columns.filter(function (col) { return col.canBeFrozen; })) === null || _a === void 0 ? void 0 : _a.length; }, [columns]);
|
29
|
-
var canFreeze = useMemo(function () { return isUpMd && (rows === null || rows === void 0 ? void 0 : rows.length) > 0 && fronzenColsCount > 0; }, [fronzenColsCount, isUpMd, rows.length]);
|
30
|
-
var _g = useScroll({
|
31
|
-
canFreeze: canFreeze
|
32
|
-
}), frozenWidth = _g.frozenWidth, setFrozenWidth = _g.setFrozenWidth, fixedRef = _g.fixedRef, dynamicRef = _g.dynamicRef;
|
33
|
-
useEffect(function () {
|
34
|
-
if (columns) {
|
35
|
-
var frozenCols = columns.filter(function (col) { return col.canBeFrozen; });
|
36
|
-
var initialFrozenWidth_1 = frozenCols.reduce(function (width, col) { return width + (col.minWidth || 120); }, 1);
|
37
|
-
setFrozenWidth(function (fw) {
|
38
|
-
if (fw !== initialFrozenWidth_1) {
|
39
|
-
return initialFrozenWidth_1;
|
40
|
-
}
|
41
|
-
return fw;
|
42
|
-
});
|
43
|
-
}
|
44
|
-
}, [columns, fixedRef, fronzenColsCount, setFrozenWidth]);
|
45
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(TableContainer, __assign({ sx: (_a = {
|
46
|
-
borderWidth: "thin",
|
47
|
-
borderColor: "#e5e5e5",
|
48
|
-
borderStyle: "solid",
|
49
|
-
borderRadius: "4px",
|
50
|
-
borderCollapse: "unset !important",
|
51
|
-
margin: theme.spacing(2, 0, 3, 0),
|
52
|
-
width: "100%"
|
53
|
-
},
|
54
|
-
_a[theme.breakpoints.up("sm")] = {
|
55
|
-
minWidth: "600px"
|
56
|
-
},
|
57
|
-
_a.position = "relative",
|
58
|
-
_a.transition = "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
59
|
-
_a) }, { children: _jsxs(Grid, __assign({ container: true, direction: "row", justifyContent: "flex-start", alignItems: "center", wrap: "nowrap" }, { children: [canFreeze && (_jsx(Grid, __assign({ id: "frozenContainer", item: true, sx: {
|
60
|
-
top: 0,
|
61
|
-
left: 0,
|
62
|
-
position: "absolute",
|
63
|
-
zIndex: 999,
|
64
|
-
backgroundColor: "Menu",
|
65
|
-
boxShadow: "6px 0 6px -4px rgba(0,0,0,0.15)"
|
66
|
-
} }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { headers: headers.filter(function (header) { return header.canBeFrozen; }) }), _jsx(TableBody, { forFrozen: true, rows: rows, ref: fixedRef, rowHeight: rowHeight, onRowClick: onRowClick
|
67
|
-
? function (row) {
|
68
|
-
onRowClick(row);
|
69
|
-
}
|
70
|
-
: undefined, columns: columns.filter(function (col) { return col.canBeFrozen; }) }), _jsx(TableFooter, { footers: footers.filter(function (footer) { return footer.canBeFrozen; }) })] })) }))), _jsx(Grid, __assign({ item: true, style: {
|
71
|
-
width: "100%",
|
72
|
-
marginLeft: canFreeze ? frozenWidth || 0 : 0,
|
73
|
-
overflow: "auto"
|
74
|
-
} }, { children: _jsxs(Grid, __assign({ container: true, direction: "column", justifyContent: "center" }, { children: [_jsx(TableHeader, { headers: headers.filter(function (header) {
|
75
|
-
return isUpMd ? !header.canBeFrozen : true;
|
76
|
-
}) }), _jsx(TableBody, { rows: rows, ref: dynamicRef, rowHeight: rowHeight, noDataText: noDataText, columns: columns.filter(function (col) {
|
77
|
-
return isUpMd ? !col.canBeFrozen : true;
|
78
|
-
}), onRowClick: onRowClick
|
79
|
-
? function (row) {
|
80
|
-
onRowClick(row);
|
81
|
-
}
|
82
|
-
: undefined }), _jsx(TableFooter, { footers: footers.filter(function (footer) {
|
83
|
-
return isUpMd ? !footer.canBeFrozen : true;
|
84
|
-
}) })] })) }))] })) })) })));
|
85
|
-
}
|
86
|
-
export default BasicTable;
|
87
|
-
export * from "./types";
|
88
|
-
export { default as useTable } from "./useTable";
|
package/BasicTable/types.d.ts
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
import { ReactElement, CSSProperties } from "react";
|
2
|
-
export declare type KvProps = Record<string, unknown>;
|
3
|
-
interface SortByProps {
|
4
|
-
id: string;
|
5
|
-
desc: boolean;
|
6
|
-
}
|
7
|
-
interface InitialStateProps {
|
8
|
-
sortBy?: SortByProps;
|
9
|
-
}
|
10
|
-
export interface SortingProps {
|
11
|
-
field: string;
|
12
|
-
isSorted?: boolean;
|
13
|
-
descending?: boolean;
|
14
|
-
}
|
15
|
-
export interface UseScrollProps {
|
16
|
-
canFreeze?: boolean;
|
17
|
-
}
|
18
|
-
export declare type ColumnBaseProps = {
|
19
|
-
Header: ReactElement;
|
20
|
-
headerTip?: string;
|
21
|
-
Body: ReactElement;
|
22
|
-
Footer?: ReactElement;
|
23
|
-
align?: "left" | "center" | "right";
|
24
|
-
accessor: string;
|
25
|
-
canSort?: boolean;
|
26
|
-
canBeFrozen?: boolean;
|
27
|
-
minWidth?: number;
|
28
|
-
width?: number;
|
29
|
-
};
|
30
|
-
export declare type UseTableBaseProps<RowProps extends KvProps> = {
|
31
|
-
data: Array<RowProps>;
|
32
|
-
columns: Array<ColumnBaseProps>;
|
33
|
-
initialState?: InitialStateProps;
|
34
|
-
disableSortBy?: boolean;
|
35
|
-
onSort?: (props: SortingProps) => unknown;
|
36
|
-
};
|
37
|
-
export declare type UseTableProps<RowProps extends KvProps, ExtraProps extends KvProps> = UseTableBaseProps<RowProps> & ExtraProps;
|
38
|
-
export declare type HeaderProps<RowProps extends KvProps, ExtraProps extends KvProps> = ColumnBaseProps & Omit<UseTableProps<RowProps, ExtraProps>, keyof UseTableBaseProps<RowProps>> & {
|
39
|
-
Cell: ReactElement;
|
40
|
-
title: string;
|
41
|
-
canSort?: boolean;
|
42
|
-
onSort: (props: SortingProps) => unknown;
|
43
|
-
};
|
44
|
-
export declare type FooterProps<RowProps extends KvProps, ExtraProps extends KvProps> = ColumnBaseProps & Omit<UseTableProps<RowProps, ExtraProps>, keyof UseTableBaseProps<RowProps>> & {
|
45
|
-
Cell: ReactElement;
|
46
|
-
};
|
47
|
-
export declare type ColumnProps<RowProps extends KvProps, ExtraProps extends KvProps> = ColumnBaseProps & Omit<UseTableProps<RowProps, ExtraProps>, keyof UseTableBaseProps<RowProps>>;
|
48
|
-
export declare type ColumnWithCellProps<RowProps extends KvProps, ExtraProps extends KvProps> = ColumnProps<RowProps, ExtraProps> & {
|
49
|
-
Cell: ReactElement;
|
50
|
-
};
|
51
|
-
export declare type UserTableReturns<RowProps extends KvProps, ExtraProps extends KvProps> = {
|
52
|
-
headers: Array<HeaderProps<RowProps, ExtraProps>>;
|
53
|
-
footers: Array<FooterProps<RowProps, ExtraProps>>;
|
54
|
-
columns: Array<ColumnWithCellProps<RowProps, ExtraProps>>;
|
55
|
-
rows: Array<RowProps>;
|
56
|
-
};
|
57
|
-
export interface BasicTableHeaderProps<RowProps extends KvProps, ExtraProps extends KvProps> {
|
58
|
-
headers: Array<HeaderProps<RowProps, ExtraProps>>;
|
59
|
-
}
|
60
|
-
export interface BasicTableFooterProps<RowProps extends KvProps, ExtraProps extends KvProps> {
|
61
|
-
footers: Array<FooterProps<RowProps, ExtraProps>>;
|
62
|
-
}
|
63
|
-
export interface BasicTableBodyProps<RowProps extends KvProps, ExtraProps extends KvProps> {
|
64
|
-
columns: Array<ColumnWithCellProps<RowProps, ExtraProps>>;
|
65
|
-
rows: Array<RowProps>;
|
66
|
-
noDataText?: string;
|
67
|
-
forFrozen?: boolean;
|
68
|
-
rowHeight?: CSSProperties["height"];
|
69
|
-
onRowClick?: (row: RowProps) => unknown;
|
70
|
-
}
|
71
|
-
export interface BasicTableBodyRowProps<RowProps extends KvProps, ExtraProps extends KvProps> {
|
72
|
-
columns: Array<ColumnWithCellProps<RowProps, ExtraProps>>;
|
73
|
-
rows: Array<RowProps>;
|
74
|
-
row: RowProps;
|
75
|
-
forFrozen?: boolean;
|
76
|
-
rowHeight?: CSSProperties["height"];
|
77
|
-
onRowClick?: (row: RowProps) => unknown;
|
78
|
-
}
|
79
|
-
export declare type BasicTableProps<RowProps extends KvProps, ExtraProps extends KvProps> = BasicTableHeaderProps<RowProps, ExtraProps> & Omit<BasicTableBodyProps<RowProps, ExtraProps>, "forFrozen"> & Partial<BasicTableFooterProps<RowProps, ExtraProps>> & {
|
80
|
-
primaryColor?: CSSProperties["color"];
|
81
|
-
secondaryColor?: CSSProperties["color"];
|
82
|
-
};
|
83
|
-
export {};
|
package/BasicTable/types.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,9 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import { UseScrollProps } from "./types";
|
3
|
-
declare function useScroll(props: UseScrollProps): {
|
4
|
-
frozenWidth: number;
|
5
|
-
setFrozenWidth: import("react").Dispatch<import("react").SetStateAction<number>>;
|
6
|
-
fixedRef: import("react").RefObject<HTMLDivElement>;
|
7
|
-
dynamicRef: import("react").RefObject<HTMLDivElement>;
|
8
|
-
};
|
9
|
-
export default useScroll;
|
package/BasicTable/useScroll.js
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import { useState, useCallback, useEffect, useRef } from "react";
|
2
|
-
import useTheme from "@mui/material/styles/useTheme";
|
3
|
-
import useMediaQuery from "@mui/material/useMediaQuery";
|
4
|
-
function useScroll(props) {
|
5
|
-
var canFreeze = props.canFreeze;
|
6
|
-
var theme = useTheme();
|
7
|
-
var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
|
8
|
-
var _a = useState(0), frozenWidth = _a[0], setFrozenWidth = _a[1];
|
9
|
-
var fixedRef = useRef(null);
|
10
|
-
var dynamicRef = useRef(null);
|
11
|
-
var resetFrozenWidth = useCallback(function () {
|
12
|
-
setFrozenWidth(function (fw) {
|
13
|
-
var _a, _b;
|
14
|
-
if (fw !== ((_a = fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth)) {
|
15
|
-
return ((_b = fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth) || fw;
|
16
|
-
}
|
17
|
-
return fw;
|
18
|
-
});
|
19
|
-
}, [fixedRef]);
|
20
|
-
var onFixedScroll = useCallback(function (event) {
|
21
|
-
if (isUpMd && (dynamicRef === null || dynamicRef === void 0 ? void 0 : dynamicRef.current)) {
|
22
|
-
var targetDiv = event.target;
|
23
|
-
dynamicRef.current.scrollTop = targetDiv.scrollTop;
|
24
|
-
resetFrozenWidth();
|
25
|
-
}
|
26
|
-
}, [dynamicRef, isUpMd, resetFrozenWidth]);
|
27
|
-
var onDynamicScroll = useCallback(function (event) {
|
28
|
-
if (isUpMd && (fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current)) {
|
29
|
-
var targetDiv = event.target;
|
30
|
-
fixedRef.current.scrollTop = targetDiv.scrollTop;
|
31
|
-
resetFrozenWidth();
|
32
|
-
}
|
33
|
-
}, [fixedRef, isUpMd, resetFrozenWidth]);
|
34
|
-
var removeEventFixed = useCallback(function () {
|
35
|
-
if (fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current) {
|
36
|
-
fixedRef.current.removeEventListener("scroll", onFixedScroll);
|
37
|
-
}
|
38
|
-
}, [fixedRef, onFixedScroll]);
|
39
|
-
var removeEventDynamic = useCallback(function () {
|
40
|
-
if (dynamicRef === null || dynamicRef === void 0 ? void 0 : dynamicRef.current) {
|
41
|
-
dynamicRef.current.removeEventListener("scroll", onDynamicScroll);
|
42
|
-
}
|
43
|
-
}, [dynamicRef, onDynamicScroll]);
|
44
|
-
var bindEventFixed = useCallback(function () {
|
45
|
-
removeEventDynamic();
|
46
|
-
if (fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current) {
|
47
|
-
fixedRef.current.addEventListener("scroll", onFixedScroll);
|
48
|
-
}
|
49
|
-
}, [fixedRef, onFixedScroll, removeEventDynamic]);
|
50
|
-
var bindEventDynamic = useCallback(function () {
|
51
|
-
removeEventFixed();
|
52
|
-
if (dynamicRef === null || dynamicRef === void 0 ? void 0 : dynamicRef.current) {
|
53
|
-
dynamicRef.current.addEventListener("scroll", onDynamicScroll);
|
54
|
-
}
|
55
|
-
}, [dynamicRef, onDynamicScroll, removeEventFixed]);
|
56
|
-
useEffect(function () {
|
57
|
-
if (canFreeze) {
|
58
|
-
if (fixedRef === null || fixedRef === void 0 ? void 0 : fixedRef.current) {
|
59
|
-
fixedRef.current.addEventListener("mouseover", bindEventFixed);
|
60
|
-
}
|
61
|
-
if (dynamicRef === null || dynamicRef === void 0 ? void 0 : dynamicRef.current) {
|
62
|
-
dynamicRef.current.addEventListener("mouseover", bindEventDynamic);
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}, [
|
66
|
-
bindEventDynamic,
|
67
|
-
bindEventFixed,
|
68
|
-
canFreeze,
|
69
|
-
dynamicRef,
|
70
|
-
fixedRef,
|
71
|
-
onDynamicScroll,
|
72
|
-
onFixedScroll
|
73
|
-
]);
|
74
|
-
return { frozenWidth: frozenWidth, setFrozenWidth: setFrozenWidth, fixedRef: fixedRef, dynamicRef: dynamicRef };
|
75
|
-
}
|
76
|
-
export default useScroll;
|
package/BasicTable/useTable.d.ts
DELETED
package/BasicTable/useTable.js
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
-
var t = {};
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
-
t[p] = s[p];
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
-
t[p[i]] = s[p[i]];
|
20
|
-
}
|
21
|
-
return t;
|
22
|
-
};
|
23
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
-
import { cloneElement, useState, useMemo, useCallback } from "react";
|
25
|
-
function useTable(props) {
|
26
|
-
var data = props.data, columns = props.columns, initialState = props.initialState, disableSortBy = props.disableSortBy, onSort = props.onSort, rest = __rest(props, ["data", "columns", "initialState", "disableSortBy", "onSort"]);
|
27
|
-
if (!data) {
|
28
|
-
throw new Error('"data" is required but got null or undefined');
|
29
|
-
}
|
30
|
-
if (!columns) {
|
31
|
-
throw new Error('"columns" is required but got null or undefined');
|
32
|
-
}
|
33
|
-
var sortBy = (initialState || {}).sortBy;
|
34
|
-
var _a = sortBy || {}, id = _a.id, desc = _a.desc;
|
35
|
-
var _b = useState({
|
36
|
-
field: id || "",
|
37
|
-
isSorted: !!id,
|
38
|
-
descending: desc || false
|
39
|
-
}), sortingProps = _b[0], setSortingProps = _b[1];
|
40
|
-
var handleSort = useCallback(function (_a) {
|
41
|
-
var field = _a.field;
|
42
|
-
if (!disableSortBy) {
|
43
|
-
var newSortingProps = __assign({}, sortingProps);
|
44
|
-
if (field !== sortingProps.field || !sortingProps.isSorted) {
|
45
|
-
newSortingProps = { field: field, isSorted: true, descending: false };
|
46
|
-
}
|
47
|
-
else if (!sortingProps.descending) {
|
48
|
-
newSortingProps = __assign(__assign({}, sortingProps), { descending: true });
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
newSortingProps = __assign(__assign({}, sortingProps), { isSorted: false });
|
52
|
-
}
|
53
|
-
if (onSort) {
|
54
|
-
onSort(__assign({}, newSortingProps));
|
55
|
-
}
|
56
|
-
setSortingProps(__assign({}, newSortingProps));
|
57
|
-
}
|
58
|
-
}, [disableSortBy, onSort, sortingProps]);
|
59
|
-
var renderSortingSymbol = useCallback(function (accessor) {
|
60
|
-
var field = sortingProps.field, isSorted = sortingProps.isSorted, descending = sortingProps.descending;
|
61
|
-
if (accessor !== field || !isSorted) {
|
62
|
-
return "";
|
63
|
-
}
|
64
|
-
if (!descending) {
|
65
|
-
return "↑";
|
66
|
-
}
|
67
|
-
return "↓";
|
68
|
-
}, [sortingProps]);
|
69
|
-
var rows = useMemo(function () { return data.map(function (d) { return (__assign({}, d)); }); }, [data]);
|
70
|
-
var cols = useMemo(function () {
|
71
|
-
return columns.map(function (col) {
|
72
|
-
var Body = col.Body;
|
73
|
-
return __assign(__assign({ Cell: cloneElement(Body || _jsx(_Fragment, {}), { column: col }) }, col), rest);
|
74
|
-
});
|
75
|
-
}, [columns, rest]);
|
76
|
-
var headers = useMemo(function () {
|
77
|
-
return columns.map(function (col) {
|
78
|
-
var Header = col.Header, accessor = col.accessor, canSort = col.canSort, headerTip = col.headerTip;
|
79
|
-
var canSortBy = canSort && !disableSortBy;
|
80
|
-
return __assign(__assign({ Cell: (_jsxs(_Fragment, { children: [cloneElement(Header || _jsx(_Fragment, {}), { column: col }), canSortBy && renderSortingSymbol(accessor)] })), title: "".concat(headerTip || "").concat(canSortBy ? " (Click to sort)" : ""), canSort: canSortBy, onSort: canSortBy ? handleSort : function () { } }, col), rest);
|
81
|
-
});
|
82
|
-
}, [columns, disableSortBy, handleSort, renderSortingSymbol, rest]);
|
83
|
-
var footers = useMemo(function () {
|
84
|
-
return columns.map(function (col) {
|
85
|
-
var Footer = col.Footer;
|
86
|
-
return __assign(__assign({ Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
|
87
|
-
column: col,
|
88
|
-
rows: rows
|
89
|
-
}) }, col), rest);
|
90
|
-
});
|
91
|
-
}, [columns, rest, rows]);
|
92
|
-
return { headers: headers, footers: footers, columns: cols, rows: rows };
|
93
|
-
}
|
94
|
-
export default useTable;
|