@pushwoosh/smart-components-kit 1.0.59 → 1.0.60
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/Table/hooks/index.d.ts
CHANGED
package/Table/hooks/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DataTableParams, DataTableContextSyncType } from '../types';
|
|
2
|
+
export type DataTableContextSyncProps<I, P extends DataTableParams> = {
|
|
3
|
+
getItems: (params: P) => I[];
|
|
4
|
+
params: P;
|
|
5
|
+
onChangeParams: (params: P) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function useDataTableContextSync<I, P extends DataTableParams = DataTableParams>({ getItems, params, onChangeParams, }: DataTableContextSyncProps<I, P>): DataTableContextSyncType<I, P>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
export function useDataTableContextSync({
|
|
3
|
+
getItems,
|
|
4
|
+
params,
|
|
5
|
+
onChangeParams
|
|
6
|
+
}) {
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
const items = getItems(params);
|
|
9
|
+
return {
|
|
10
|
+
data: {
|
|
11
|
+
items,
|
|
12
|
+
totalPages: Math.ceil(items.length / params.perPage) || 1,
|
|
13
|
+
total: items.length
|
|
14
|
+
},
|
|
15
|
+
params,
|
|
16
|
+
onChangeParams: onChangeParams
|
|
17
|
+
};
|
|
18
|
+
}, [getItems, params, onChangeParams]);
|
|
19
|
+
}
|
package/Table/types.d.ts
CHANGED
|
@@ -18,3 +18,8 @@ export type DataTableContextType<T, P extends DataTableParams> = {
|
|
|
18
18
|
params: P;
|
|
19
19
|
onChangeParams: (params: P) => void;
|
|
20
20
|
};
|
|
21
|
+
export type DataTableContextSyncType<T, P extends DataTableParams> = {
|
|
22
|
+
data: DataTableData<T>;
|
|
23
|
+
params: P;
|
|
24
|
+
onChangeParams: (params: P) => void;
|
|
25
|
+
};
|
package/package.json
CHANGED