@pushwoosh/dumb-components 1.0.5 → 1.0.7
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/DropdownMenu/components/DropdownMenuItem/index.d.ts +1 -0
- package/DropdownMenu/index.d.ts +1 -1
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +5 -2
- package/Select/Select.d.ts +6 -0
- package/Select/Select.js +39 -0
- package/Select/constants.d.ts +1 -0
- package/Select/constants.js +1 -0
- package/Select/index.d.ts +3 -0
- package/Select/index.js +2 -0
- package/Select/styles.d.ts +6 -0
- package/Select/styles.js +31 -0
- package/Select/types.d.ts +15 -0
- package/Select/types.js +1 -0
- package/Table/assets/box.svg +1 -0
- package/Table/assets/error.svg +1 -0
- package/Table/assets/notfound.svg +1 -0
- package/Table/components/ClearableInput/ClearableInput.d.ts +3 -0
- package/Table/components/ClearableInput/ClearableInput.js +20 -0
- package/Table/components/ClearableInput/index.d.ts +1 -0
- package/Table/components/ClearableInput/index.js +1 -0
- package/Table/components/ClearableInput/styles.d.ts +14 -0
- package/Table/components/ClearableInput/styles.js +10 -0
- package/Table/components/ClearableInput/types.d.ts +5 -0
- package/Table/components/ClearableInput/types.js +1 -0
- package/Table/components/DataTable/DataTable.d.ts +4 -0
- package/Table/components/DataTable/DataTable.js +74 -0
- package/Table/components/DataTable/index.d.ts +1 -0
- package/Table/components/DataTable/index.js +1 -0
- package/Table/components/DataTable/types.d.ts +22 -0
- package/Table/components/DataTable/types.js +1 -0
- package/Table/components/DataTableGetContext/DataTableGetContext.d.ts +4 -0
- package/Table/components/DataTableGetContext/DataTableGetContext.js +8 -0
- package/Table/components/DataTableGetContext/index.d.ts +1 -0
- package/Table/components/DataTableGetContext/index.js +1 -0
- package/Table/components/DataTableGetContext/types.d.ts +5 -0
- package/Table/components/DataTableGetContext/types.js +1 -0
- package/Table/components/DataTableList/DataTableList.d.ts +3 -0
- package/Table/components/DataTableList/DataTableList.js +77 -0
- package/Table/components/DataTableList/index.d.ts +1 -0
- package/Table/components/DataTableList/index.js +1 -0
- package/Table/components/DataTableList/types.d.ts +4 -0
- package/Table/components/DataTableList/types.js +1 -0
- package/Table/components/DataTablePagination/DataTablePagination.d.ts +3 -0
- package/Table/components/DataTablePagination/DataTablePagination.js +33 -0
- package/Table/components/DataTablePagination/index.d.ts +1 -0
- package/Table/components/DataTablePagination/index.js +1 -0
- package/Table/components/DataTablePagination/types.d.ts +4 -0
- package/Table/components/DataTablePagination/types.js +1 -0
- package/Table/components/DataTableSearchInput/DataTableSearchInput.d.ts +3 -0
- package/Table/components/DataTableSearchInput/DataTableSearchInput.js +31 -0
- package/Table/components/DataTableSearchInput/index.d.ts +1 -0
- package/Table/components/DataTableSearchInput/index.js +1 -0
- package/Table/components/DataTableSearchInput/types.d.ts +3 -0
- package/Table/components/DataTableSearchInput/types.js +1 -0
- package/Table/components/DataTableSortableCell/DataTableSortableCell.d.ts +3 -0
- package/Table/components/DataTableSortableCell/DataTableSortableCell.js +25 -0
- package/Table/components/DataTableSortableCell/index.d.ts +1 -0
- package/Table/components/DataTableSortableCell/index.js +1 -0
- package/Table/components/DataTableSortableCell/types.d.ts +4 -0
- package/Table/components/DataTableSortableCell/types.js +1 -0
- package/Table/components/Loading/Loading.d.ts +2 -0
- package/Table/components/Loading/Loading.js +20 -0
- package/Table/components/Loading/index.d.ts +1 -0
- package/Table/components/Loading/index.js +1 -0
- package/Table/components/Loading/styles.d.ts +1 -0
- package/Table/components/Loading/styles.js +6 -0
- package/Table/components/TableList/TableList.d.ts +3 -0
- package/Table/components/TableList/TableList.js +15 -0
- package/Table/components/TableList/index.d.ts +1 -0
- package/Table/components/TableList/index.js +1 -0
- package/Table/components/TableList/types.d.ts +9 -0
- package/Table/components/TableList/types.js +1 -0
- package/Table/components/TablePagination/TablePagination.d.ts +3 -0
- package/Table/components/TablePagination/TablePagination.js +38 -0
- package/Table/components/TablePagination/index.d.ts +1 -0
- package/Table/components/TablePagination/index.js +1 -0
- package/Table/components/TablePagination/types.d.ts +9 -0
- package/Table/components/TablePagination/types.js +1 -0
- package/Table/context.d.ts +2 -0
- package/Table/context.js +2 -0
- package/Table/hooks/index.d.ts +2 -0
- package/Table/hooks/index.js +2 -0
- package/Table/hooks/useDataTableContext.d.ts +11 -0
- package/Table/hooks/useDataTableContext.js +23 -0
- package/Table/hooks/useDataTableParams.d.ts +10 -0
- package/Table/hooks/useDataTableParams.js +39 -0
- package/Table/index.d.ts +13 -0
- package/Table/index.js +12 -0
- package/Table/styles.d.ts +73 -0
- package/Table/styles.js +60 -0
- package/Table/types.d.ts +20 -0
- package/Table/types.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +14 -12
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { FontSize, FontWeight, Spacing } from '@pushwoosh/kit-constants';
|
|
3
|
+
import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import Box from '../../assets/box.svg';
|
|
5
|
+
import Error from '../../assets/error.svg';
|
|
6
|
+
import NotFound from '../../assets/notfound.svg';
|
|
7
|
+
import { DataTableContext } from '../../context';
|
|
8
|
+
import { LockedText } from '../../styles';
|
|
9
|
+
import { Loading } from '../Loading';
|
|
10
|
+
export function DataTableList({
|
|
11
|
+
renderItem
|
|
12
|
+
}) {
|
|
13
|
+
var _data$value, _data$value2;
|
|
14
|
+
const {
|
|
15
|
+
data,
|
|
16
|
+
params
|
|
17
|
+
} = useContext(DataTableContext);
|
|
18
|
+
if (data.loading || (_data$value = data.value) !== null && _data$value !== void 0 && (_data$value = _data$value.items) !== null && _data$value !== void 0 && _data$value.length) {
|
|
19
|
+
return data.value ? React.createElement(React.Fragment, null, data.value.items.map(renderItem)) : React.createElement(Loading, null);
|
|
20
|
+
}
|
|
21
|
+
if (!data.loading && data.error) {
|
|
22
|
+
return React.createElement(Horizontal, {
|
|
23
|
+
"$placeItems": "center",
|
|
24
|
+
"$padding": Spacing.S14
|
|
25
|
+
}, React.createElement(Horizontal, {
|
|
26
|
+
"$gap": 16
|
|
27
|
+
}, React.createElement("img", {
|
|
28
|
+
src: Error,
|
|
29
|
+
alt: "Request failed"
|
|
30
|
+
}), React.createElement(Vertical, {
|
|
31
|
+
"$alignContent": "center",
|
|
32
|
+
"$gap": 8
|
|
33
|
+
}, React.createElement(LockedText, {
|
|
34
|
+
"$fontWeight": FontWeight.MEDIUM,
|
|
35
|
+
"$maxWidth": "250px"
|
|
36
|
+
}, "Something went wrong"), React.createElement(LockedText, {
|
|
37
|
+
"$fontSize": FontSize.SMALL,
|
|
38
|
+
"$maxWidth": "250px"
|
|
39
|
+
}, "Give it another try or refresh the page to see if we can fix this glitch!"))));
|
|
40
|
+
}
|
|
41
|
+
const isFiltered = ((_data$value2 = data.value) === null || _data$value2 === void 0 ? void 0 : _data$value2.isFiltered) || params.search;
|
|
42
|
+
return isFiltered ? React.createElement(Horizontal, {
|
|
43
|
+
"$placeItems": "center",
|
|
44
|
+
"$padding": Spacing.S14
|
|
45
|
+
}, React.createElement(Horizontal, {
|
|
46
|
+
"$gap": 16
|
|
47
|
+
}, React.createElement("img", {
|
|
48
|
+
src: NotFound,
|
|
49
|
+
alt: "Not found"
|
|
50
|
+
}), React.createElement(Vertical, {
|
|
51
|
+
"$alignContent": "center",
|
|
52
|
+
"$gap": 8
|
|
53
|
+
}, React.createElement(LockedText, {
|
|
54
|
+
"$fontWeight": FontWeight.MEDIUM,
|
|
55
|
+
"$maxWidth": "250px"
|
|
56
|
+
}, "No match found"), React.createElement(LockedText, {
|
|
57
|
+
"$fontSize": FontSize.SMALL,
|
|
58
|
+
"$maxWidth": "250px"
|
|
59
|
+
}, "Please try using different search terms with a minimum of two characters.")))) : React.createElement(Horizontal, {
|
|
60
|
+
"$placeItems": "center",
|
|
61
|
+
"$padding": Spacing.S14
|
|
62
|
+
}, React.createElement(Horizontal, {
|
|
63
|
+
"$gap": 16
|
|
64
|
+
}, React.createElement("img", {
|
|
65
|
+
src: Box,
|
|
66
|
+
alt: "Empty box"
|
|
67
|
+
}), React.createElement(Vertical, {
|
|
68
|
+
"$alignContent": "center",
|
|
69
|
+
"$gap": 8
|
|
70
|
+
}, React.createElement(LockedText, {
|
|
71
|
+
"$fontWeight": FontWeight.MEDIUM,
|
|
72
|
+
"$maxWidth": "250px"
|
|
73
|
+
}, "This list is empty"), React.createElement(LockedText, {
|
|
74
|
+
"$fontSize": FontSize.SMALL,
|
|
75
|
+
"$maxWidth": "250px"
|
|
76
|
+
}, "Looks like there's nothing here yet. Time to create \u2014 let's bring this list to life!"))));
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableList } from './DataTableList';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableList } from './DataTableList';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { DataTableContext } from '../../context';
|
|
3
|
+
import { TablePagination } from '../TablePagination';
|
|
4
|
+
export function DataTablePagination({
|
|
5
|
+
allLimits,
|
|
6
|
+
children
|
|
7
|
+
}) {
|
|
8
|
+
var _data$value;
|
|
9
|
+
const {
|
|
10
|
+
data,
|
|
11
|
+
params,
|
|
12
|
+
onChangeParams
|
|
13
|
+
} = useContext(DataTableContext);
|
|
14
|
+
return React.createElement(TablePagination, {
|
|
15
|
+
activePage: params.page,
|
|
16
|
+
totalPages: ((_data$value = data.value) === null || _data$value === void 0 ? void 0 : _data$value.totalPages) || 1,
|
|
17
|
+
limit: params.perPage,
|
|
18
|
+
allLimits: allLimits,
|
|
19
|
+
onChangePage: page => {
|
|
20
|
+
onChangeParams({
|
|
21
|
+
...params,
|
|
22
|
+
page
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
onChangeLimit: perPage => {
|
|
26
|
+
onChangeParams({
|
|
27
|
+
...params,
|
|
28
|
+
page: 1,
|
|
29
|
+
perPage
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}, children);
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTablePagination } from './DataTablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTablePagination } from './DataTablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useRef, useState, useEffect, useContext } from 'react';
|
|
2
|
+
import { DataTableContext } from '../../context';
|
|
3
|
+
import { ClearableInput } from '../ClearableInput';
|
|
4
|
+
export function DataTableSearchInput(props) {
|
|
5
|
+
const context = useContext(DataTableContext);
|
|
6
|
+
const [inputValue, setInputValue] = useState(context.params.search);
|
|
7
|
+
const timeoutRef = useRef();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (inputValue !== context.params.search) {
|
|
10
|
+
setInputValue(context.params.search);
|
|
11
|
+
}
|
|
12
|
+
}, [context.params.search]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
13
|
+
return React.createElement(ClearableInput, {
|
|
14
|
+
...props,
|
|
15
|
+
value: inputValue,
|
|
16
|
+
onChange: value => {
|
|
17
|
+
setInputValue(value);
|
|
18
|
+
if (timeoutRef.current) {
|
|
19
|
+
clearTimeout(timeoutRef.current);
|
|
20
|
+
}
|
|
21
|
+
timeoutRef.current = setTimeout(() => {
|
|
22
|
+
context.onChangeParams({
|
|
23
|
+
...context.params,
|
|
24
|
+
search: value,
|
|
25
|
+
page: 1
|
|
26
|
+
});
|
|
27
|
+
timeoutRef.current = undefined;
|
|
28
|
+
}, 750);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSearchInput } from './DataTableSearchInput';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSearchInput } from './DataTableSearchInput';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { SortButton } from '../../../SortButton';
|
|
3
|
+
import { DataTableContext } from '../../context';
|
|
4
|
+
export function DataTableSortableCell(props) {
|
|
5
|
+
const {
|
|
6
|
+
name,
|
|
7
|
+
children
|
|
8
|
+
} = props;
|
|
9
|
+
const {
|
|
10
|
+
params,
|
|
11
|
+
onChangeParams
|
|
12
|
+
} = useContext(DataTableContext);
|
|
13
|
+
return React.createElement(SortButton, {
|
|
14
|
+
name: name,
|
|
15
|
+
order: params.order === name ? params.direction : null,
|
|
16
|
+
onClick: sortParams => {
|
|
17
|
+
onChangeParams({
|
|
18
|
+
...params,
|
|
19
|
+
order: sortParams.name,
|
|
20
|
+
direction: sortParams.order || 'asc',
|
|
21
|
+
page: 1
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, children);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSortableCell } from './DataTableSortableCell';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSortableCell } from './DataTableSortableCell';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
3
|
+
import { Wrapper } from './styles';
|
|
4
|
+
import { TextSkeleton } from '../../../Skeleton';
|
|
5
|
+
const Row = ({
|
|
6
|
+
width
|
|
7
|
+
}) => React.createElement(Horizontal, {
|
|
8
|
+
"$alignItems": "center",
|
|
9
|
+
"$padding": "0 24px"
|
|
10
|
+
}, React.createElement(TextSkeleton, {
|
|
11
|
+
width: width
|
|
12
|
+
}));
|
|
13
|
+
export const Loading = () => React.createElement(Wrapper, null, Array.from({
|
|
14
|
+
length: 4
|
|
15
|
+
}).map((_, index) =>
|
|
16
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
17
|
+
React.createElement(Row, {
|
|
18
|
+
key: index,
|
|
19
|
+
width: `${index % 2 ? 35 : 50}%`
|
|
20
|
+
})));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Loading } from './Loading';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Loading } from './Loading';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Wrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Color, FontSize } from '@pushwoosh/kit-constants';
|
|
3
|
+
export const Wrapper = styled.div.withConfig({
|
|
4
|
+
displayName: "Wrapper",
|
|
5
|
+
componentId: "sc-1xpxjq7-0"
|
|
6
|
+
})(["position:relative;font-size:", ";line-height:12px;background-color:", ";& > div{height:52px;border-bottom:1px solid ", ";& > div{transition:width 200ms linear;}}&:after{content:'';position:absolute;left:0;right:0;top:0;bottom:0;background-image:linear-gradient(to bottom,rgba(255,255,255,0),rgba(255,255,255,0.9));}"], FontSize.SMALL, Color.CLEAR, Color.DIVIDER);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Table } from '../../styles';
|
|
3
|
+
export function TableList(props) {
|
|
4
|
+
const {
|
|
5
|
+
columns,
|
|
6
|
+
items,
|
|
7
|
+
renderHead,
|
|
8
|
+
renderItem,
|
|
9
|
+
renderTableTop,
|
|
10
|
+
renderTableBottom
|
|
11
|
+
} = props;
|
|
12
|
+
return React.createElement(Table, {
|
|
13
|
+
columns: columns
|
|
14
|
+
}, renderTableTop === null || renderTableTop === void 0 ? void 0 : renderTableTop(), renderHead(), items.map(renderItem), renderTableBottom === null || renderTableBottom === void 0 ? void 0 : renderTableBottom());
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TableList } from './TableList';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TableList } from './TableList';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
3
|
+
import { NativeSelect } from '../../../native';
|
|
4
|
+
import { Pagination } from '../../../Pagination';
|
|
5
|
+
export function TablePagination(props) {
|
|
6
|
+
const {
|
|
7
|
+
activePage,
|
|
8
|
+
totalPages,
|
|
9
|
+
limit,
|
|
10
|
+
allLimits,
|
|
11
|
+
onChangePage,
|
|
12
|
+
onChangeLimit,
|
|
13
|
+
children
|
|
14
|
+
} = props;
|
|
15
|
+
return React.createElement(Horizontal, {
|
|
16
|
+
"$justifyContent": "space-between",
|
|
17
|
+
"$padding": 24
|
|
18
|
+
}, React.createElement(Horizontal, {
|
|
19
|
+
"$gap": 8,
|
|
20
|
+
"$alignItems": "center"
|
|
21
|
+
}, totalPages > 1 && React.createElement(Pagination, {
|
|
22
|
+
activePage: activePage,
|
|
23
|
+
totalPages: totalPages,
|
|
24
|
+
onChangePage: onChangePage
|
|
25
|
+
}), children), React.createElement(Horizontal, {
|
|
26
|
+
"$gap": 8,
|
|
27
|
+
"$alignItems": "center"
|
|
28
|
+
}, React.createElement("span", null, "Show on page:"), React.createElement(NativeSelect, {
|
|
29
|
+
name: "page",
|
|
30
|
+
value: limit,
|
|
31
|
+
onChange: event => {
|
|
32
|
+
onChangeLimit(Number(event.target.value));
|
|
33
|
+
}
|
|
34
|
+
}, allLimits.map(option => React.createElement("option", {
|
|
35
|
+
key: option,
|
|
36
|
+
value: option
|
|
37
|
+
}, option)))));
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TablePagination } from './TablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TablePagination } from './TablePagination';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react';
|
|
2
|
+
export type TablePaginationProps = PropsWithChildren<{
|
|
3
|
+
activePage: number;
|
|
4
|
+
totalPages: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
allLimits: number[];
|
|
7
|
+
onChangePage: (page: number) => void;
|
|
8
|
+
onChangeLimit: (limit: number) => void;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/Table/context.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DataTableParams, DataTableContextType } from '../types';
|
|
2
|
+
export type DataTableContextProps<I, P extends DataTableParams> = {
|
|
3
|
+
getItems: (params: P) => Promise<{
|
|
4
|
+
items: I[];
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
}>;
|
|
8
|
+
params: P;
|
|
9
|
+
onChangeParams: (params: P) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function useDataTableContext<I, P extends DataTableParams = DataTableParams>({ getItems, params, onChangeParams, }: DataTableContextProps<I, P>): DataTableContextType<I, P>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
import { useAsyncFn, usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
3
|
+
export function useDataTableContext({
|
|
4
|
+
getItems,
|
|
5
|
+
params,
|
|
6
|
+
onChangeParams
|
|
7
|
+
}) {
|
|
8
|
+
const getItemsPersistent = usePersistentFunction(getItems);
|
|
9
|
+
const [listAsync, reload] = useAsyncFn(() => getItemsPersistent(params), [params], {
|
|
10
|
+
loading: true
|
|
11
|
+
});
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
reload({
|
|
14
|
+
reset: true
|
|
15
|
+
});
|
|
16
|
+
}, [reload]);
|
|
17
|
+
return useMemo(() => ({
|
|
18
|
+
data: listAsync,
|
|
19
|
+
reload,
|
|
20
|
+
params,
|
|
21
|
+
onChangeParams: onChangeParams
|
|
22
|
+
}), [reload, params, listAsync, onChangeParams]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataTableParams } from '../types';
|
|
2
|
+
type UseDataTableParamsParams<P extends DataTableParams> = {
|
|
3
|
+
defaultOrder: string;
|
|
4
|
+
defaultDirection?: 'asc' | 'desc';
|
|
5
|
+
defaultPerPage?: number;
|
|
6
|
+
extend?: (obj: Record<string, string>, params: DataTableParams) => P;
|
|
7
|
+
};
|
|
8
|
+
type UseDataTableParamsReturn<P> = readonly [P, (params: P) => void];
|
|
9
|
+
export declare function useDataTableParams<P extends DataTableParams>({ defaultOrder, defaultDirection, defaultPerPage, extend, }: UseDataTableParamsParams<P>): UseDataTableParamsReturn<P>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react';
|
|
2
|
+
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
|
+
import { usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
4
|
+
function pickBy(obj) {
|
|
5
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => !!value));
|
|
6
|
+
}
|
|
7
|
+
export function useDataTableParams({
|
|
8
|
+
defaultOrder,
|
|
9
|
+
defaultDirection = 'asc',
|
|
10
|
+
defaultPerPage = 10,
|
|
11
|
+
extend
|
|
12
|
+
}) {
|
|
13
|
+
const history = useHistory();
|
|
14
|
+
const {
|
|
15
|
+
search: locationSearch
|
|
16
|
+
} = useLocation();
|
|
17
|
+
const extendRef = useRef(extend);
|
|
18
|
+
extendRef.current = extend;
|
|
19
|
+
const dataTableParams = useMemo(() => {
|
|
20
|
+
const searchParams = new URLSearchParams(locationSearch);
|
|
21
|
+
const obj = Object.fromEntries(searchParams);
|
|
22
|
+
// eslint-disable-next-line no-nested-ternary
|
|
23
|
+
const realOrderDirection = !obj.direction ? defaultDirection : obj.direction === 'asc' ? 'asc' : 'desc';
|
|
24
|
+
const params = {
|
|
25
|
+
search: obj.search ?? '',
|
|
26
|
+
order: obj.order || defaultOrder,
|
|
27
|
+
direction: realOrderDirection,
|
|
28
|
+
page: +obj.page || 1,
|
|
29
|
+
perPage: +obj.perPage || defaultPerPage
|
|
30
|
+
};
|
|
31
|
+
return extendRef.current ? extendRef.current(obj, params) : params;
|
|
32
|
+
}, [locationSearch, defaultDirection, defaultOrder, defaultPerPage]);
|
|
33
|
+
const changeDataTableParams = usePersistentFunction(params => {
|
|
34
|
+
history.push({
|
|
35
|
+
search: new URLSearchParams(pickBy(params)).toString()
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
return [dataTableParams, changeDataTableParams];
|
|
39
|
+
}
|
package/Table/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { ClearableInput } from './components/ClearableInput';
|
|
2
|
+
export { DataTable } from './components/DataTable';
|
|
3
|
+
export { DataTableList } from './components/DataTableList';
|
|
4
|
+
export { DataTableGetContext } from './components/DataTableGetContext';
|
|
5
|
+
export { DataTablePagination } from './components/DataTablePagination';
|
|
6
|
+
export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
7
|
+
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
8
|
+
export { Loading } from './components/Loading';
|
|
9
|
+
export { TableList } from './components/TableList';
|
|
10
|
+
export { TablePagination } from './components/TablePagination';
|
|
11
|
+
export { useDataTableContext, useDataTableParams } from './hooks';
|
|
12
|
+
export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, } from './styles';
|
|
13
|
+
export type { DataTableParams, DataTableData, DataTableContextType } from './types';
|
package/Table/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ClearableInput } from './components/ClearableInput';
|
|
2
|
+
export { DataTable } from './components/DataTable';
|
|
3
|
+
export { DataTableList } from './components/DataTableList';
|
|
4
|
+
export { DataTableGetContext } from './components/DataTableGetContext';
|
|
5
|
+
export { DataTablePagination } from './components/DataTablePagination';
|
|
6
|
+
export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
7
|
+
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
8
|
+
export { Loading } from './components/Loading';
|
|
9
|
+
export { TableList } from './components/TableList';
|
|
10
|
+
export { TablePagination } from './components/TablePagination';
|
|
11
|
+
export { useDataTableContext, useDataTableParams } from './hooks';
|
|
12
|
+
export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description } from './styles';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FontSize, FontWeight } from '@pushwoosh/kit-constants';
|
|
2
|
+
export declare const Table: import("styled-components").StyledComponent<"div", any, {
|
|
3
|
+
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
4
|
+
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
5
|
+
$gap?: string | number | undefined;
|
|
6
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
7
|
+
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
8
|
+
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
9
|
+
$margin?: string | number | undefined;
|
|
10
|
+
$padding?: string | number | undefined;
|
|
11
|
+
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
$gridAutoFlow: string;
|
|
14
|
+
} & {
|
|
15
|
+
columns: string;
|
|
16
|
+
width?: string | number;
|
|
17
|
+
}, "$gridAutoFlow">;
|
|
18
|
+
export declare const Td: import("styled-components").StyledComponent<"div", any, {
|
|
19
|
+
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
20
|
+
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
21
|
+
$gap?: string | number | undefined;
|
|
22
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
23
|
+
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
24
|
+
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
25
|
+
$margin?: string | number | undefined;
|
|
26
|
+
$padding?: string | number | undefined;
|
|
27
|
+
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
28
|
+
} & {
|
|
29
|
+
$padding: number;
|
|
30
|
+
} & {
|
|
31
|
+
$color?: string;
|
|
32
|
+
}, "$padding">;
|
|
33
|
+
export declare const ElementHover: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
34
|
+
export declare const Tr: import("styled-components").StyledComponent<"div", any, {
|
|
35
|
+
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
36
|
+
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
37
|
+
$gap?: string | number | undefined;
|
|
38
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
39
|
+
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
40
|
+
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
41
|
+
$margin?: string | number | undefined;
|
|
42
|
+
$padding?: string | number | undefined;
|
|
43
|
+
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
44
|
+
} & {
|
|
45
|
+
$gridAutoFlow: string;
|
|
46
|
+
} & {
|
|
47
|
+
$padding: string;
|
|
48
|
+
}, "$gridAutoFlow" | "$padding">;
|
|
49
|
+
export declare const Th: import("styled-components").StyledComponent<"div", any, {
|
|
50
|
+
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
51
|
+
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
52
|
+
$gap?: string | number | undefined;
|
|
53
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
54
|
+
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
55
|
+
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
56
|
+
$margin?: string | number | undefined;
|
|
57
|
+
$padding?: string | number | undefined;
|
|
58
|
+
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
59
|
+
} & {
|
|
60
|
+
$padding: number;
|
|
61
|
+
} & {
|
|
62
|
+
$color?: string;
|
|
63
|
+
}, "$padding">;
|
|
64
|
+
export declare const ItemDetailLink: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
65
|
+
export declare const ItemName: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
66
|
+
export declare const Description: import("styled-components").StyledComponent<"div", any, {
|
|
67
|
+
$maxLines?: number;
|
|
68
|
+
}, never>;
|
|
69
|
+
export declare const LockedText: import("styled-components").StyledComponent<"div", any, {
|
|
70
|
+
$fontSize?: FontSize;
|
|
71
|
+
$fontWeight?: FontWeight;
|
|
72
|
+
$maxWidth?: string;
|
|
73
|
+
}, never>;
|