@symply.io/basic-components 1.5.7-beta.1 → 1.5.8-alpha.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/DataTable/types.d.ts +1 -0
- package/DataTable/useTable.js +16 -7
- package/README.md +7 -6
- package/package.json +1 -1
package/DataTable/types.d.ts
CHANGED
@@ -48,6 +48,7 @@ export declare type UserTableReturns<RowProps extends KvProps, ExtendedProps ext
|
|
48
48
|
footers: Array<TableFooterCellProps<RowProps, ExtendedProps>>;
|
49
49
|
columns: Array<TableBodyCellProps<RowProps, ExtendedProps>>;
|
50
50
|
rows: Array<RowProps>;
|
51
|
+
onResetSorting: () => void;
|
51
52
|
};
|
52
53
|
export declare type TableHeaderProps<RowProps extends KvProps, ExtendedProps extends KvProps> = {
|
53
54
|
headers: Array<TableHeaderCellProps<RowProps, ExtendedProps>>;
|
package/DataTable/useTable.js
CHANGED
@@ -30,12 +30,15 @@ function useTable(props) {
|
|
30
30
|
if (!columns) {
|
31
31
|
throw new Error('"columns" is required but got null or undefined');
|
32
32
|
}
|
33
|
-
var
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
var initialSortingProps = useMemo(function () {
|
34
|
+
var sortBy = (initialState || {}).sortBy;
|
35
|
+
var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
|
36
|
+
return {
|
37
|
+
accessor: accessor || "",
|
38
|
+
order: !!accessor ? order || "NONE" : "NONE"
|
39
|
+
};
|
40
|
+
}, [initialState]);
|
41
|
+
var _a = useState(initialSortingProps), sortingProps = _a[0], setSortingProps = _a[1];
|
39
42
|
var handleSort = useCallback(function (_a) {
|
40
43
|
var accessor = _a.accessor;
|
41
44
|
if (!disableSortBy) {
|
@@ -56,6 +59,12 @@ function useTable(props) {
|
|
56
59
|
setSortingProps(__assign({}, newSortingProps));
|
57
60
|
}
|
58
61
|
}, [disableSortBy, onSort, sortingProps]);
|
62
|
+
var onResetSorting = useCallback(function () {
|
63
|
+
if (onSort) {
|
64
|
+
onSort(__assign({}, initialSortingProps));
|
65
|
+
}
|
66
|
+
setSortingProps(__assign({}, initialSortingProps));
|
67
|
+
}, [initialSortingProps, onSort]);
|
59
68
|
var renderSortingSymbol = useCallback(function (accessor) {
|
60
69
|
var field = sortingProps.accessor, order = sortingProps.order;
|
61
70
|
if (accessor !== field || order === "NONE") {
|
@@ -89,6 +98,6 @@ function useTable(props) {
|
|
89
98
|
}) }, col), rest);
|
90
99
|
});
|
91
100
|
}, [columns, rest, rows]);
|
92
|
-
return { headers: headers, footers: footers, columns: cols, rows: rows };
|
101
|
+
return { headers: headers, footers: footers, columns: cols, rows: rows, onResetSorting: onResetSorting };
|
93
102
|
}
|
94
103
|
export default useTable;
|
package/README.md
CHANGED
@@ -359,12 +359,13 @@ import DataTable, { useDataTable } from '@symply.io/basic-components/DataTable';
|
|
359
359
|
|
360
360
|
<h5>Hook Returns</h5>
|
361
361
|
|
362
|
-
| Name
|
363
|
-
|
|
364
|
-
| columns
|
365
|
-
| footers
|
366
|
-
| headers
|
367
|
-
| rows
|
362
|
+
| Name | Type | Description |
|
363
|
+
| -------------- | ----------------------------- | ------------------------------------------------------------ |
|
364
|
+
| columns | Array\<TableBodyCellProps\> | The cells for the body. |
|
365
|
+
| footers | Array\<TableFooterCellProps> | The cells for the footer. |
|
366
|
+
| headers | Array\<TableHeaderCellProps\> | The cells for the header. |
|
367
|
+
| rows | Array<RowProps\> | The rows for the table. |
|
368
|
+
| onResetSorting | func | An one-key function for resetting sorting to the initial state. |
|
368
369
|
|
369
370
|
<h5>Component Props</h5>
|
370
371
|
|