ferns-ui 0.45.2 → 0.45.3
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/dist/Common.d.ts +25 -0
- package/dist/Pagination.d.ts +9 -0
- package/dist/Pagination.js +16 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/Table.d.ts +1 -1
- package/dist/Table.js +20 -8
- package/dist/Table.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tableContext.d.ts +2 -18
- package/dist/tableContext.js +3 -1
- package/dist/tableContext.js.map +1 -1
- package/package.json +1 -1
- package/src/Common.ts +25 -0
- package/src/Pagination.tsx +43 -0
- package/src/Table.tsx +47 -16
- package/src/index.tsx +1 -0
- package/src/tableContext.tsx +5 -19
package/dist/Common.d.ts
CHANGED
|
@@ -1139,6 +1139,26 @@ export interface TableProps {
|
|
|
1139
1139
|
* If true, alternate rows will have a light gray background. Defaults to true.
|
|
1140
1140
|
*/
|
|
1141
1141
|
alternateRowBackground?: boolean;
|
|
1142
|
+
/**
|
|
1143
|
+
* Control sort outside of the Table
|
|
1144
|
+
*/
|
|
1145
|
+
sort?: ColumnSortInterface;
|
|
1146
|
+
/**
|
|
1147
|
+
* Set the page outside of the Table
|
|
1148
|
+
*/
|
|
1149
|
+
page?: number;
|
|
1150
|
+
/**
|
|
1151
|
+
* Set the page outside of the Table
|
|
1152
|
+
*/
|
|
1153
|
+
setPage?: (page: number) => void;
|
|
1154
|
+
/**
|
|
1155
|
+
* If true, the table will render a next page button. Defaults to true.
|
|
1156
|
+
*/
|
|
1157
|
+
more?: boolean;
|
|
1158
|
+
/**
|
|
1159
|
+
* Extra controls to render below the table next to pagination
|
|
1160
|
+
*/
|
|
1161
|
+
extraControls?: React.ReactElement;
|
|
1142
1162
|
}
|
|
1143
1163
|
export interface TableHeaderProps {
|
|
1144
1164
|
/**
|
|
@@ -1188,6 +1208,11 @@ export interface TableRowProps {
|
|
|
1188
1208
|
*/
|
|
1189
1209
|
color?: BoxColor;
|
|
1190
1210
|
}
|
|
1211
|
+
export type TableFilters = Record<string, string[]>;
|
|
1212
|
+
export type TableSearch = {
|
|
1213
|
+
search: string;
|
|
1214
|
+
field: string;
|
|
1215
|
+
};
|
|
1191
1216
|
export interface TableContextType {
|
|
1192
1217
|
columns: Array<number | string>;
|
|
1193
1218
|
hasDrawerContents: boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
interface PaginationControlProps {
|
|
3
|
+
shouldDisableBackButton: boolean;
|
|
4
|
+
shouldDisableNextButton: boolean;
|
|
5
|
+
page: number;
|
|
6
|
+
setPage: (page: number) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const PaginationControl: ({ shouldDisableBackButton, shouldDisableNextButton, page, setPage, }: PaginationControlProps) => ReactElement;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box } from "./Box";
|
|
3
|
+
import { Button } from "./Button";
|
|
4
|
+
import { Text } from "./Text";
|
|
5
|
+
export const PaginationControl = ({ shouldDisableBackButton, shouldDisableNextButton, page, setPage, }) => {
|
|
6
|
+
return (React.createElement(Box, { direction: "row", paddingY: 2 },
|
|
7
|
+
React.createElement(Box, null,
|
|
8
|
+
React.createElement(Button, { color: "blue", disabled: shouldDisableBackButton, text: "Prev Page", onClick: () => setPage(Number(page) - 1) })),
|
|
9
|
+
React.createElement(Box, { justifyContent: "center", paddingX: 4 },
|
|
10
|
+
React.createElement(Text, null,
|
|
11
|
+
"Page: ",
|
|
12
|
+
page)),
|
|
13
|
+
React.createElement(Box, null,
|
|
14
|
+
React.createElement(Button, { color: "blue", disabled: shouldDisableNextButton, text: "Next Page", onClick: () => setPage(Number(page) + 1) }))));
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pagination.js","sourceRoot":"","sources":["../src/Pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAS5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,uBAAuB,EACvB,uBAAuB,EACvB,IAAI,EACJ,OAAO,GACgB,EAAgB,EAAE;IACzC,OAAO,CACL,oBAAC,GAAG,IAAC,SAAS,EAAC,KAAK,EAAC,QAAQ,EAAE,CAAC;QAC9B,oBAAC,GAAG;YACF,oBAAC,MAAM,IACL,KAAK,EAAC,MAAM,EACZ,QAAQ,EAAE,uBAAuB,EACjC,IAAI,EAAC,WAAW,EAChB,OAAO,EAAE,GAAS,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAC9C,CACE;QACN,oBAAC,GAAG,IAAC,cAAc,EAAC,QAAQ,EAAC,QAAQ,EAAE,CAAC;YACtC,oBAAC,IAAI;;gBAAQ,IAAI,CAAQ,CACrB;QACN,oBAAC,GAAG;YACF,oBAAC,MAAM,IACL,KAAK,EAAC,MAAM,EACZ,QAAQ,EAAE,uBAAuB,EACjC,IAAI,EAAC,WAAW,EAChB,OAAO,EAAE,GAAS,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAC9C,CACE,CACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/Table.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React, { ReactElement } from "react";
|
|
2
2
|
import { TableProps } from "./Common";
|
|
3
|
-
export declare const Table: ({ children, columns, borderStyle, alternateRowBackground, maxHeight, stickyHeader, }: TableProps) => React.ReactElement;
|
|
3
|
+
export declare const Table: ({ children, columns, borderStyle, alternateRowBackground, maxHeight, stickyHeader, sort, page: propsPage, setPage: propsSetPage, more, extraControls, }: TableProps) => React.ReactElement;
|
package/dist/Table.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import React, { Children } from "react";
|
|
2
|
-
import { ScrollView } from "
|
|
2
|
+
import { ScrollView } from "react-native";
|
|
3
|
+
import { Box } from "./Box";
|
|
4
|
+
import { PaginationControl } from "./Pagination";
|
|
3
5
|
import { TableContextProvider } from "./tableContext";
|
|
4
|
-
export const Table = ({ children, columns, borderStyle, alternateRowBackground = true, maxHeight, stickyHeader = true, }) => {
|
|
6
|
+
export const Table = ({ children, columns, borderStyle, alternateRowBackground = true, maxHeight, stickyHeader = true, sort, page: propsPage, setPage: propsSetPage, more, extraControls, }) => {
|
|
5
7
|
const arrayChildren = Children.toArray(children);
|
|
6
|
-
|
|
8
|
+
// Check if any of the rows below have a drawerContents prop to see if we need to render space
|
|
9
|
+
// for the caret.
|
|
10
|
+
const [sortColumn, setSortColumn] = React.useState(sort);
|
|
11
|
+
const [page, setPage] = React.useState(propsPage !== null && propsPage !== void 0 ? propsPage : 1);
|
|
7
12
|
// Check if any of the rows below have a drawerContents prop to see if we need to render space
|
|
8
13
|
// for the caret.
|
|
9
14
|
const hasDrawerContents = arrayChildren.some((child) => {
|
|
@@ -24,10 +29,17 @@ export const Table = ({ children, columns, borderStyle, alternateRowBackground =
|
|
|
24
29
|
else {
|
|
25
30
|
width = "100%";
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const shouldPaginate = more || page > 1;
|
|
33
|
+
return (React.createElement(TableContextProvider, { alternateRowBackground: alternateRowBackground, borderStyle: borderStyle, columns: columns, hasDrawerContents: hasDrawerContents, page: page, setSortColumn: setSortColumn, sortColumn: sortColumn, stickyHeader: stickyHeader },
|
|
34
|
+
React.createElement(React.Fragment, null,
|
|
35
|
+
React.createElement(Box, { flex: "grow", maxWidth: "100%", width: width },
|
|
36
|
+
React.createElement(ScrollView, { horizontal: true, style: { width, maxWidth: "100%" } },
|
|
37
|
+
React.createElement(ScrollView, { stickyHeaderIndices: stickyHeader ? [0] : undefined, style: { width, maxWidth: "100%", flex: 1, maxHeight } }, Children.map(children, (child, index) => Boolean(child) &&
|
|
38
|
+
React.cloneElement(child, {
|
|
39
|
+
color: index % 2 === 1 && alternateRowBackground ? "lightGray" : "white",
|
|
40
|
+
}))))),
|
|
41
|
+
Boolean(shouldPaginate) && (React.createElement(Box, { alignItems: "center", borderTop: "gray", direction: "row", height: 60, paddingX: 8 },
|
|
42
|
+
React.createElement(PaginationControl, { page: propsPage !== null && propsPage !== void 0 ? propsPage : page, setPage: propsSetPage !== null && propsSetPage !== void 0 ? propsSetPage : setPage, shouldDisableBackButton: (propsPage !== null && propsPage !== void 0 ? propsPage : page) <= 1, shouldDisableNextButton: !more }),
|
|
43
|
+
Boolean(extraControls) && extraControls)))));
|
|
32
44
|
};
|
|
33
45
|
//# sourceMappingURL=Table.js.map
|
package/dist/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAe,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,QAAQ,EAAe,MAAM,OAAO,CAAC;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAC;AAEpD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,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Y,cAAZ,YAAY,GAAI,OAAO,EAChC,uBAAuB,EAAE,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,IAAI,CAAC,EACjD,uBAAuB,EAAE,CAAC,IAAI,GAC9B;gBACD,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,CACpC,CACP,CACA,CACkB,CACxB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,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AC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC"}
|
package/dist/tableContext.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
column: number | undefined;
|
|
4
|
-
direction: "asc" | "desc" | undefined;
|
|
5
|
-
}
|
|
6
|
-
interface TableContextType {
|
|
7
|
-
columns: Array<number | string>;
|
|
8
|
-
hasDrawerContents: boolean;
|
|
9
|
-
sortColumn?: ColumnSortInterface | undefined;
|
|
10
|
-
setSortColumn?: (sort: ColumnSortInterface | undefined) => void;
|
|
11
|
-
stickyHeader?: boolean;
|
|
12
|
-
borderStyle?: "sm" | "none";
|
|
13
|
-
alternateRowBackground?: boolean;
|
|
14
|
-
}
|
|
15
|
-
interface Props extends TableContextType {
|
|
16
|
-
children: React.ReactElement;
|
|
17
|
-
}
|
|
2
|
+
import { TableContextProviderProps, TableContextType } from "./Common";
|
|
18
3
|
export declare const Provider: React.Provider<TableContextType>;
|
|
19
|
-
export declare const TableContextProvider: ({ children, columns, hasDrawerContents, sortColumn, setSortColumn, stickyHeader, borderStyle, alternateRowBackground, }:
|
|
4
|
+
export declare const TableContextProvider: ({ children, columns, hasDrawerContents, sortColumn, setSortColumn, stickyHeader, borderStyle, alternateRowBackground, page, }: TableContextProviderProps) => React.ReactElement<typeof Provider>;
|
|
20
5
|
export declare function useTableContext(): TableContextType;
|
|
21
|
-
export {};
|
package/dist/tableContext.js
CHANGED
|
@@ -7,9 +7,10 @@ const TableContext = createContext({
|
|
|
7
7
|
stickyHeader: true,
|
|
8
8
|
borderStyle: "sm",
|
|
9
9
|
alternateRowBackground: true,
|
|
10
|
+
page: 1,
|
|
10
11
|
});
|
|
11
12
|
export const { Provider } = TableContext;
|
|
12
|
-
export const TableContextProvider = ({ children, columns, hasDrawerContents, sortColumn, setSortColumn, stickyHeader, borderStyle, alternateRowBackground, }) => {
|
|
13
|
+
export const TableContextProvider = ({ children, columns, hasDrawerContents, sortColumn, setSortColumn, stickyHeader, borderStyle, alternateRowBackground, page, }) => {
|
|
13
14
|
return (React.createElement(Provider, { value: {
|
|
14
15
|
columns,
|
|
15
16
|
alternateRowBackground,
|
|
@@ -18,6 +19,7 @@ export const TableContextProvider = ({ children, columns, hasDrawerContents, sor
|
|
|
18
19
|
sortColumn,
|
|
19
20
|
setSortColumn,
|
|
20
21
|
stickyHeader,
|
|
22
|
+
page,
|
|
21
23
|
} }, children));
|
|
22
24
|
};
|
|
23
25
|
export function useTableContext() {
|
package/dist/tableContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tableContext.js","sourceRoot":"","sources":["../src/tableContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAU,aAAa,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"tableContext.js","sourceRoot":"","sources":["../src/tableContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAU,aAAa,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AAIhE,MAAM,YAAY,GAA8B,aAAa,CAAmB;IAC9E,OAAO,EAAE,EAAE;IACX,iBAAiB,EAAE,KAAK;IACxB,UAAU,EAAE,SAAS;IACrB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,sBAAsB,EAAE,IAAI;IAC5B,IAAI,EAAE,CAAC;CACR,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAC,QAAQ,EAAC,GAAG,YAAY,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,IAAI,GACsB,EAAuC,EAAE;IACnE,OAAO,CACL,oBAAC,QAAQ,IACP,KAAK,EAAE;YACL,OAAO;YACP,sBAAsB;YACtB,WAAW;YACX,iBAAiB;YACjB,UAAU;YACV,aAAa;YACb,YAAY;YACZ,IAAI;SACL,IAEA,QAAQ,CACA,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,eAAe;IAC7B,MAAM,EACJ,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,WAAW,GACZ,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7B,OAAO;QACL,OAAO;QACP,iBAAiB;QACjB,aAAa;QACb,UAAU;QACV,YAAY;QACZ,sBAAsB;QACtB,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/Common.ts
CHANGED
|
@@ -2945,6 +2945,27 @@ export interface TableProps {
|
|
|
2945
2945
|
* If true, alternate rows will have a light gray background. Defaults to true.
|
|
2946
2946
|
*/
|
|
2947
2947
|
alternateRowBackground?: boolean;
|
|
2948
|
+
|
|
2949
|
+
/**
|
|
2950
|
+
* Control sort outside of the Table
|
|
2951
|
+
*/
|
|
2952
|
+
sort?: ColumnSortInterface;
|
|
2953
|
+
/**
|
|
2954
|
+
* Set the page outside of the Table
|
|
2955
|
+
*/
|
|
2956
|
+
page?: number;
|
|
2957
|
+
/**
|
|
2958
|
+
* Set the page outside of the Table
|
|
2959
|
+
*/
|
|
2960
|
+
setPage?: (page: number) => void;
|
|
2961
|
+
/**
|
|
2962
|
+
* If true, the table will render a next page button. Defaults to true.
|
|
2963
|
+
*/
|
|
2964
|
+
more?: boolean;
|
|
2965
|
+
/**
|
|
2966
|
+
* Extra controls to render below the table next to pagination
|
|
2967
|
+
*/
|
|
2968
|
+
extraControls?: React.ReactElement;
|
|
2948
2969
|
}
|
|
2949
2970
|
|
|
2950
2971
|
export interface TableHeaderProps {
|
|
@@ -2998,6 +3019,10 @@ export interface TableRowProps {
|
|
|
2998
3019
|
color?: BoxColor;
|
|
2999
3020
|
}
|
|
3000
3021
|
|
|
3022
|
+
export type TableFilters = Record<string, string[]>;
|
|
3023
|
+
|
|
3024
|
+
export type TableSearch = {search: string; field: string};
|
|
3025
|
+
|
|
3001
3026
|
export interface TableContextType {
|
|
3002
3027
|
columns: Array<number | string>;
|
|
3003
3028
|
hasDrawerContents: boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, {ReactElement} from "react";
|
|
2
|
+
|
|
3
|
+
import {Box} from "./Box";
|
|
4
|
+
import {Button} from "./Button";
|
|
5
|
+
import {Text} from "./Text";
|
|
6
|
+
|
|
7
|
+
interface PaginationControlProps {
|
|
8
|
+
shouldDisableBackButton: boolean;
|
|
9
|
+
shouldDisableNextButton: boolean;
|
|
10
|
+
page: number;
|
|
11
|
+
setPage: (page: number) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const PaginationControl = ({
|
|
15
|
+
shouldDisableBackButton,
|
|
16
|
+
shouldDisableNextButton,
|
|
17
|
+
page,
|
|
18
|
+
setPage,
|
|
19
|
+
}: PaginationControlProps): ReactElement => {
|
|
20
|
+
return (
|
|
21
|
+
<Box direction="row" paddingY={2}>
|
|
22
|
+
<Box>
|
|
23
|
+
<Button
|
|
24
|
+
color="blue"
|
|
25
|
+
disabled={shouldDisableBackButton}
|
|
26
|
+
text="Prev Page"
|
|
27
|
+
onClick={(): void => setPage(Number(page) - 1)}
|
|
28
|
+
/>
|
|
29
|
+
</Box>
|
|
30
|
+
<Box justifyContent="center" paddingX={4}>
|
|
31
|
+
<Text>Page: {page}</Text>
|
|
32
|
+
</Box>
|
|
33
|
+
<Box>
|
|
34
|
+
<Button
|
|
35
|
+
color="blue"
|
|
36
|
+
disabled={shouldDisableNextButton}
|
|
37
|
+
text="Next Page"
|
|
38
|
+
onClick={(): void => setPage(Number(page) + 1)}
|
|
39
|
+
/>
|
|
40
|
+
</Box>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
package/src/Table.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, {Children, ReactElement} from "react";
|
|
2
|
+
import {ScrollView} from "react-native";
|
|
2
3
|
import {DimensionValue} from "react-native/Libraries/StyleSheet/StyleSheetTypes";
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {Box} from "./Box";
|
|
6
|
+
import {ColumnSortInterface, TableProps} from "./Common";
|
|
7
|
+
import {PaginationControl} from "./Pagination";
|
|
8
|
+
import {TableContextProvider} from "./tableContext";
|
|
7
9
|
|
|
8
10
|
export const Table = ({
|
|
9
11
|
children,
|
|
@@ -12,10 +14,18 @@ export const Table = ({
|
|
|
12
14
|
alternateRowBackground = true,
|
|
13
15
|
maxHeight,
|
|
14
16
|
stickyHeader = true,
|
|
17
|
+
sort,
|
|
18
|
+
page: propsPage,
|
|
19
|
+
setPage: propsSetPage,
|
|
20
|
+
more,
|
|
21
|
+
extraControls,
|
|
15
22
|
}: TableProps): React.ReactElement => {
|
|
16
23
|
const arrayChildren = Children.toArray(children);
|
|
17
|
-
const [sortColumn, setSortColumn] = React.useState<ColumnSortInterface | undefined>(undefined);
|
|
18
24
|
|
|
25
|
+
// Check if any of the rows below have a drawerContents prop to see if we need to render space
|
|
26
|
+
// for the caret.
|
|
27
|
+
const [sortColumn, setSortColumn] = React.useState<ColumnSortInterface | undefined>(sort);
|
|
28
|
+
const [page, setPage] = React.useState<number>(propsPage ?? 1);
|
|
19
29
|
// Check if any of the rows below have a drawerContents prop to see if we need to render space
|
|
20
30
|
// for the caret.
|
|
21
31
|
const hasDrawerContents = arrayChildren.some((child) => {
|
|
@@ -36,28 +46,49 @@ export const Table = ({
|
|
|
36
46
|
width = "100%";
|
|
37
47
|
}
|
|
38
48
|
|
|
49
|
+
const shouldPaginate = more || page > 1;
|
|
50
|
+
|
|
39
51
|
return (
|
|
40
52
|
<TableContextProvider
|
|
41
53
|
alternateRowBackground={alternateRowBackground}
|
|
42
54
|
borderStyle={borderStyle}
|
|
43
55
|
columns={columns}
|
|
44
56
|
hasDrawerContents={hasDrawerContents}
|
|
57
|
+
page={page}
|
|
45
58
|
setSortColumn={setSortColumn}
|
|
46
59
|
sortColumn={sortColumn}
|
|
47
60
|
stickyHeader={stickyHeader}
|
|
48
61
|
>
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
<>
|
|
63
|
+
<Box flex="grow" maxWidth="100%" width={width}>
|
|
64
|
+
<ScrollView horizontal style={{width, maxWidth: "100%"}}>
|
|
65
|
+
<ScrollView
|
|
66
|
+
stickyHeaderIndices={stickyHeader ? [0] : undefined}
|
|
67
|
+
style={{width, maxWidth: "100%", flex: 1, maxHeight}}
|
|
68
|
+
>
|
|
69
|
+
{Children.map(
|
|
70
|
+
children,
|
|
71
|
+
(child, index) =>
|
|
72
|
+
Boolean(child) &&
|
|
73
|
+
React.cloneElement(child as any, {
|
|
74
|
+
color: index % 2 === 1 && alternateRowBackground ? "lightGray" : "white",
|
|
75
|
+
})
|
|
76
|
+
)}
|
|
77
|
+
</ScrollView>
|
|
78
|
+
</ScrollView>
|
|
79
|
+
</Box>
|
|
80
|
+
{Boolean(shouldPaginate) && (
|
|
81
|
+
<Box alignItems="center" borderTop="gray" direction="row" height={60} paddingX={8}>
|
|
82
|
+
<PaginationControl
|
|
83
|
+
page={propsPage ?? page}
|
|
84
|
+
setPage={propsSetPage ?? setPage}
|
|
85
|
+
shouldDisableBackButton={(propsPage ?? page) <= 1}
|
|
86
|
+
shouldDisableNextButton={!more}
|
|
87
|
+
/>
|
|
88
|
+
{Boolean(extraControls) && extraControls}
|
|
89
|
+
</Box>
|
|
90
|
+
)}
|
|
91
|
+
</>
|
|
61
92
|
</TableContextProvider>
|
|
62
93
|
);
|
|
63
94
|
};
|
package/src/index.tsx
CHANGED
package/src/tableContext.tsx
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import React, {Context, createContext, useContext} from "react";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
column: number | undefined;
|
|
5
|
-
direction: "asc" | "desc" | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface TableContextType {
|
|
9
|
-
columns: Array<number | string>;
|
|
10
|
-
hasDrawerContents: boolean;
|
|
11
|
-
sortColumn?: ColumnSortInterface | undefined;
|
|
12
|
-
setSortColumn?: (sort: ColumnSortInterface | undefined) => void;
|
|
13
|
-
stickyHeader?: boolean;
|
|
14
|
-
borderStyle?: "sm" | "none";
|
|
15
|
-
alternateRowBackground?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface Props extends TableContextType {
|
|
19
|
-
children: React.ReactElement;
|
|
20
|
-
}
|
|
3
|
+
import {TableContextProviderProps, TableContextType} from "./Common";
|
|
21
4
|
|
|
22
5
|
const TableContext: Context<TableContextType> = createContext<TableContextType>({
|
|
23
6
|
columns: [],
|
|
@@ -27,6 +10,7 @@ const TableContext: Context<TableContextType> = createContext<TableContextType>(
|
|
|
27
10
|
stickyHeader: true,
|
|
28
11
|
borderStyle: "sm",
|
|
29
12
|
alternateRowBackground: true,
|
|
13
|
+
page: 1,
|
|
30
14
|
});
|
|
31
15
|
|
|
32
16
|
export const {Provider} = TableContext;
|
|
@@ -40,7 +24,8 @@ export const TableContextProvider = ({
|
|
|
40
24
|
stickyHeader,
|
|
41
25
|
borderStyle,
|
|
42
26
|
alternateRowBackground,
|
|
43
|
-
|
|
27
|
+
page,
|
|
28
|
+
}: TableContextProviderProps): React.ReactElement<typeof Provider> => {
|
|
44
29
|
return (
|
|
45
30
|
<Provider
|
|
46
31
|
value={{
|
|
@@ -51,6 +36,7 @@ export const TableContextProvider = ({
|
|
|
51
36
|
sortColumn,
|
|
52
37
|
setSortColumn,
|
|
53
38
|
stickyHeader,
|
|
39
|
+
page,
|
|
54
40
|
}}
|
|
55
41
|
>
|
|
56
42
|
{children}
|