@symply.io/basic-components 1.5.7 → 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.
@@ -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>>;
@@ -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 sortBy = (initialState || {}).sortBy;
34
- var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
35
- var _b = useState({
36
- accessor: accessor || "",
37
- order: !!accessor ? order || "NONE" : "NONE"
38
- }), sortingProps = _b[0], setSortingProps = _b[1];
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 | 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. |
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.5.7",
3
+ "version": "1.5.8-alpha.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",