@fto-consult/expo-ui 6.24.2 → 6.25.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/app.config.json +1 -1
- package/babel.config.alias.js +2 -1
- package/babel.config.js +1 -1
- package/electron/utils/env.js +80 -0
- package/expo-ui-path.js +2 -2
- package/index.js +14 -13
- package/is-local-dev.js +5 -0
- package/metro.config.js +3 -2
- package/package.json +7 -4
- package/readChart.txt +4 -1
- package/src/App.js +3 -3
- package/src/components/Datagrid/Accordion/Row.js +74 -100
- package/src/components/Datagrid/Accordion/ToogleRow.js +9 -0
- package/src/components/Datagrid/Accordion/index.js +30 -35
- package/src/components/Datagrid/Actions/index.js +12 -44
- package/src/components/Datagrid/Checkbox.js +4 -7
- package/src/components/Datagrid/Common/Common.js +121 -152
- package/src/components/Datagrid/Dashboard/index.js +2 -2
- package/src/components/Datagrid/IndexComponent.js +8 -13
- package/src/components/Datagrid/Table/index.js +53 -51
- package/src/components/Datagrid/Test/index.js +10 -3
- package/src/components/Datagrid/events/evx.js +7 -0
- package/src/components/Datagrid/events/index.js +11 -0
- package/src/components/Datagrid/hooks/Provider.js +6 -0
- package/src/components/Datagrid/hooks/context.js +5 -0
- package/src/components/Datagrid/hooks/index.js +104 -0
- package/src/components/Datagrid/utils.js +8 -5
- package/src/components/Dialog/Dialog.js +13 -12
- package/src/components/Dialog/DialogContent.js +11 -0
- package/src/components/KeyboardAvoidingView/index.js +7 -3
- package/src/components/Label/index.js +8 -4
- package/src/components/List/Common.js +5 -3
- package/src/components/List/FlashList.js +13 -13
- package/src/components/List/Virtuoso/index.js +68 -10
- package/src/components/List/Virtuoso/index.native.js +6 -1
- package/src/components/Table/Header/Cell/index.js +10 -0
- package/src/components/Table/Header/Cell/index.native.js +7 -0
- package/src/components/Table/Header/index.js +34 -0
- package/src/components/Table/List/index.js +3 -1
- package/src/components/Table/List/index.native.js +2 -1
- package/src/components/Table/Row/Cell/Content.js +16 -0
- package/src/components/Table/Row/Cell/Content.native.js +15 -0
- package/src/components/Table/Row/Cell/index.js +30 -0
- package/src/components/Table/Row/RowWrapper.js +7 -0
- package/src/components/Table/Row/RowWrapper.native.js +11 -0
- package/src/components/Table/Row/index.js +38 -0
- package/src/components/Table/RowTemplate/index.js +10 -0
- package/src/components/Table/RowTemplate/index.web.js +9 -0
- package/src/components/Table/ScrollNative/index.js +7 -0
- package/src/components/Table/ScrollNative/index.native.js +8 -0
- package/src/components/Table/VirtuosoTable/index.js +5 -0
- package/src/components/Table/VirtuosoTable/index.native.js +3 -0
- package/src/components/Table/hooks.js +84 -0
- package/src/components/Table/index.js +92 -250
- package/src/components/Table/styles.js +104 -0
- package/src/components/Table/utils.js +1 -0
- package/src/context/Provider.js +16 -2
- package/src/layouts/AppBar/index.js +11 -10
- package/src/layouts/Screen/ScreenWithoutAuthContainer.js +14 -6
- package/src/navigation/Drawer/items/index.js +2 -1
- package/src/navigation/index.js +11 -3
- package/src/screens/Help/About.js +1 -1
- package/src/screens/Help/openLibraries.js +1 -1
- package/src/test-screens/Home.js +4 -1
- package/webpack.config.js +4 -2
- package/src/components/Table/Cell.js +0 -24
- package/src/components/Table/FiltersOrFooters.js +0 -18
- package/src/components/Table/Header.js +0 -25
- package/src/components/Table/Row.js +0 -21
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
import {Virtuoso,VirtuosoGrid} from "react-virtuoso/dist/index.mjs";
|
|
5
|
+
import {Virtuoso,VirtuosoGrid,TableVirtuoso} from "react-virtuoso/dist/index.mjs";
|
|
6
6
|
import React from "$react";
|
|
7
7
|
import PropTypes from "prop-types";
|
|
8
8
|
import {defaultObj,classNames,defaultNumber,isObj,isDOMElement,isNumber,uniqid,isNonNullString,defaultStr} from "$cutils";
|
|
@@ -10,6 +10,9 @@ import { View } from "react-native";
|
|
|
10
10
|
import {useList} from "../hooks";
|
|
11
11
|
import theme,{grid} from "$theme";
|
|
12
12
|
import Dimensions from "$cdimensions";
|
|
13
|
+
import { StyleSheet } from "react-native";
|
|
14
|
+
import {isMobileNative} from "$cplatform";
|
|
15
|
+
import {addClassName,removeClassName} from "$cutils/dom";
|
|
13
16
|
|
|
14
17
|
const propTypes = {
|
|
15
18
|
...defaultObj(Virtuoso.propTypes),
|
|
@@ -29,18 +32,29 @@ const propTypes = {
|
|
|
29
32
|
isScrolling : PropTypes.func,
|
|
30
33
|
};
|
|
31
34
|
/***@see : https://virtuoso.dev/virtuoso-api-reference/ */
|
|
32
|
-
const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,components,itemProps,windowWidth,numColumns,responsive,testID,renderItem,onEndReached,onLayout,onContentSizeChange,onScroll,isScrolling,estimatedItemSize,onEndReachedThreshold,containerProps,style,autoSizedStyle,...props},ref)=>{
|
|
33
|
-
|
|
35
|
+
const VirtuosoListComponent = React.forwardRef(({onRender,id,fixedHeaderContent,rowProps,renderTable,listClassName,components,itemProps,windowWidth,numColumns,responsive,testID,renderItem,onEndReached,onLayout,onContentSizeChange,onScroll,isScrolling,estimatedItemSize,onEndReachedThreshold,containerProps,style,autoSizedStyle,...props},ref)=>{
|
|
36
|
+
if(renderTable){
|
|
37
|
+
responsive = false;
|
|
38
|
+
}
|
|
39
|
+
const Component = React.useMemo(()=>renderTable ? TableVirtuoso : responsive?VirtuosoGrid:Virtuoso,[responsive,renderTable]);
|
|
34
40
|
const context = useList(props);
|
|
35
41
|
itemProps = defaultObj(itemProps);
|
|
36
42
|
const items = context.items;
|
|
43
|
+
renderTable ? rowProps = defaultObj(rowProps) : null;
|
|
37
44
|
const r2 = {};
|
|
45
|
+
if(renderTable){
|
|
46
|
+
r2.fixedHeaderContent = fixedHeaderContent;
|
|
47
|
+
}
|
|
38
48
|
Object.map(Component.propTypes,(_,i)=>{
|
|
39
49
|
if(i in props){
|
|
40
50
|
r2[i] = props[i];
|
|
41
51
|
}
|
|
42
52
|
});
|
|
43
53
|
containerProps = defaultObj(containerProps);
|
|
54
|
+
const idRef = React.useRef(defaultStr(id,uniqid("virtuoso-list-id")));
|
|
55
|
+
id = idRef.current;
|
|
56
|
+
const containerId = `${id}-container`;
|
|
57
|
+
const headId = `${id}-table-head`;
|
|
44
58
|
testID = defaultStr(testID,containerProps.testID,"RN_VirtuosoListComponent");
|
|
45
59
|
const listIdRef = React.useRef(uniqid("virtuoso-list-id"));
|
|
46
60
|
const listId = listIdRef.current;
|
|
@@ -48,7 +62,10 @@ const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,componen
|
|
|
48
62
|
const sizeRef = React.useRef({width:0,height:0});
|
|
49
63
|
const listSize = sizeRef.current;
|
|
50
64
|
const isValid = ()=> listRef.current;
|
|
51
|
-
const listStyle = {height:'100%',width:"100%",overflowX:
|
|
65
|
+
const listStyle = {height:'100%',width:"100%",overflowX:renderTable?"auto":"hidden",maxWidth:"100%"};
|
|
66
|
+
if(renderTable){
|
|
67
|
+
listStyle.borderCollapse ="collapse";
|
|
68
|
+
}
|
|
52
69
|
r2["data-test-id"] = testID+"_ListContent";
|
|
53
70
|
if(isObj(estimatedItemSize)){
|
|
54
71
|
if(isNumber(estimatedItemSize.width)){
|
|
@@ -95,12 +112,34 @@ const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,componen
|
|
|
95
112
|
},100)
|
|
96
113
|
}
|
|
97
114
|
}
|
|
115
|
+
const scrolledTopRef = React.useRef(0);
|
|
116
|
+
const updateTableHeadCss = ()=>{
|
|
117
|
+
const newScrollTop = scrolledTopRef.current;
|
|
118
|
+
const head = document.querySelector(`#${headId}`);
|
|
119
|
+
if(!head || typeof newScrollTop !='number') return;
|
|
120
|
+
const scrolled = newScrollTop > 50
|
|
121
|
+
head.style.background = !scrolled ? "transparent":theme.isDark()? theme.Colors.lighten(theme.surfaceBackgroundColor):theme.Colors.darken(theme.surfaceBackgroundColor);
|
|
122
|
+
head.style.border = !scrolled ? "none" : `1px solid ${theme.colors.divider}`
|
|
123
|
+
}
|
|
98
124
|
React.useEffect(()=>{
|
|
125
|
+
const handleScroll = (e)=>{
|
|
126
|
+
if(!isDOMElement(e?.target)) return;
|
|
127
|
+
const target = e?.target;
|
|
128
|
+
const container = document.querySelector(`#${containerId}`);
|
|
129
|
+
if(!container) return;
|
|
130
|
+
if(container !== target && !container.contains(target)) return;
|
|
131
|
+
if(!target.hasAttribute("data-virtuoso-scroller")) return;
|
|
132
|
+
scrolledTopRef.current = typeof target?.scrollTop =="number"? target.scrollTop : undefined;
|
|
133
|
+
updateTableHeadCss();
|
|
134
|
+
}
|
|
135
|
+
window.addEventListener('scroll', handleScroll,true);
|
|
99
136
|
return ()=>{
|
|
100
137
|
React.setRef(ref,null);
|
|
138
|
+
window.removeEventListener('scroll', handleScroll,true);
|
|
101
139
|
}
|
|
102
140
|
},[]);
|
|
103
141
|
React.useOnRender((a,b,c)=>{
|
|
142
|
+
updateTableHeadCss();
|
|
104
143
|
if(onRender && onRender(a,b,c));
|
|
105
144
|
},Math.max(Array.isArray(items) && items.length/10 || 0,500));
|
|
106
145
|
const listP = responsive ? {
|
|
@@ -112,7 +151,7 @@ const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,componen
|
|
|
112
151
|
},
|
|
113
152
|
defaultItemHeight : typeof estimatedItemSize=='number' && estimatedItemSize || undefined,
|
|
114
153
|
};
|
|
115
|
-
return <View {...containerProps} {...props} style={[{flex:1},containerProps.style,style,autoSizedStyle,{minWidth:'100%',height:'100%',maxWidth:'100%'}]} onLayout={onLayout} testID={testID}>
|
|
154
|
+
return <View {...containerProps} {...props} id={containerId} className={classNames("virtuoso-list-container",renderTable&& "virtuoso-list-container-render-table")} style={[{flex:1},containerProps.style,style,autoSizedStyle,{minWidth:'100%',height:'100%',maxWidth:'100%'}]} onLayout={onLayout} testID={testID}>
|
|
116
155
|
<Component
|
|
117
156
|
{...r2}
|
|
118
157
|
{...listP}
|
|
@@ -131,15 +170,24 @@ const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,componen
|
|
|
131
170
|
}
|
|
132
171
|
}}
|
|
133
172
|
onScroll={(e) => onScroll && onScroll(normalizeEvent(e))}
|
|
134
|
-
isScrolling = {(isC,
|
|
173
|
+
isScrolling = {(isC,)=>{
|
|
135
174
|
if(typeof isScrolling =='function'){
|
|
136
175
|
return isScrolling(isC);
|
|
137
176
|
}
|
|
177
|
+
if(!renderTable) return;
|
|
138
178
|
}}
|
|
139
179
|
components = {{
|
|
140
|
-
Item : responsive ? function(props){return <ItemContainer {...props} style={[itemProps.style,props.style]} numColumns={numColumns}/>} : undefined,
|
|
141
|
-
|
|
180
|
+
Item : renderTable ? undefined : responsive ? function(props){return <ItemContainer {...props} style={[itemProps.style,props.style]} numColumns={numColumns}/>} : undefined,
|
|
181
|
+
...(renderTable ? {
|
|
182
|
+
TableRow: TableRowComponent,
|
|
183
|
+
}:{}),
|
|
142
184
|
...defaultObj(components),
|
|
185
|
+
...(renderTable ? {
|
|
186
|
+
TableHead : React.forwardRef((props,ref)=>{
|
|
187
|
+
const restProps = {id:headId,className:classNames(props.className,"virtuoso-list-render-table-thead")};
|
|
188
|
+
return <thead ref={ref} {...props} {...restProps}/>
|
|
189
|
+
})
|
|
190
|
+
} : {})
|
|
143
191
|
}}
|
|
144
192
|
/>
|
|
145
193
|
</View>
|
|
@@ -147,7 +195,10 @@ const VirtuosoListComponent = React.forwardRef(({onRender,listClassName,componen
|
|
|
147
195
|
|
|
148
196
|
VirtuosoListComponent.propTypes = {
|
|
149
197
|
...propTypes,
|
|
198
|
+
fixedHeaderContent : PropTypes.func,//la fonction rendant le contenu fixe du tableau
|
|
199
|
+
renderTable : PropTypes.bool,//si le composant Table sera rendu
|
|
150
200
|
numColumns : PropTypes.number,
|
|
201
|
+
rowProps : PropTypes.object,//les props du TableRow, lorsque le rendu est de type table
|
|
151
202
|
items : PropTypes.oneOfType([
|
|
152
203
|
PropTypes.object,
|
|
153
204
|
PropTypes.array,
|
|
@@ -202,7 +253,7 @@ const normalizeEvent = (e)=>{
|
|
|
202
253
|
},[windowWidth,numColumns]);
|
|
203
254
|
const style = width && {width} || grid.col(windowWidth);
|
|
204
255
|
const dataIntex = "index" in props ? props.index : "data-index" in props ? props["data-index"] : ""
|
|
205
|
-
const dataItemIndex = props["data-item-index"];
|
|
256
|
+
const dataItemIndex = "data-item-index" in props ? props["data-item-index"] : "";
|
|
206
257
|
if(isObj(style)){
|
|
207
258
|
style.paddingRight = style.paddingLeft = style.paddingHorizontal = undefined;
|
|
208
259
|
}
|
|
@@ -232,4 +283,11 @@ const normalizeEvent = (e)=>{
|
|
|
232
283
|
.${gridClassName}{display:flex;flex-direction:row;align-items:flex-start;flex-wrap:wrap;justify-content:flex-start;};
|
|
233
284
|
`;
|
|
234
285
|
document.body.appendChild(style);
|
|
235
|
-
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export const TableRowComponent = ({testID,style,...props}) => {
|
|
289
|
+
const index = props['data-index'];
|
|
290
|
+
const isOdd = typeof index =='number' ? index%2 > 0 : false;
|
|
291
|
+
testID = defaultStr(testID,"_VirtuosoTableRow_"+index);
|
|
292
|
+
return <tr data-test-id={testID} {...props} style={StyleSheet.flatten(style)} className={classNames(props.className,"virtuoso-table-row",`table-row-${isOdd?"odd":"even"}`)}/>
|
|
293
|
+
};
|
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
export {default} from "$ecomponents/List/FlashList";
|
|
5
|
+
export {default} from "$ecomponents/List/FlashList";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const TableRowComponent = ({children}) => {
|
|
9
|
+
return children;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "$react";
|
|
2
|
+
import {classNames} from "$cutils";
|
|
3
|
+
import theme from "$theme";
|
|
4
|
+
|
|
5
|
+
import { StyleSheet } from "react-native";
|
|
6
|
+
const TableHeaderCellComponent = React.forwardRef(({columnDef,className,width,style,children,...props},ref)=>{
|
|
7
|
+
return <th ref={ref} className={classNames(className,"table-header-cell")} children={children} style={StyleSheet.flatten([style])}/>
|
|
8
|
+
});
|
|
9
|
+
TableHeaderCellComponent.displayName = "TableTableHeaderCellComponent";
|
|
10
|
+
export default TableHeaderCellComponent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import View from "$ecomponents/View";
|
|
2
|
+
import React from "$react";
|
|
3
|
+
const TableHeaderCellComponent = React.forwardRef(({width,style,...props},ref)=>{
|
|
4
|
+
return <View ref={ref} {...props} style={[style,width && {width}]}/>
|
|
5
|
+
});
|
|
6
|
+
TableHeaderCellComponent.displayName = "TableTableHeaderCellComponent";
|
|
7
|
+
export default TableHeaderCellComponent;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2023 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import Cell from "./Cell";
|
|
6
|
+
import React from "$react";
|
|
7
|
+
import { View } from "react-native";
|
|
8
|
+
import PropTypes from "prop-types";
|
|
9
|
+
import { StyleSheet } from "react-native";
|
|
10
|
+
import {isMobileNative} from "$cplatform";
|
|
11
|
+
import {classNames} from "$cutils";
|
|
12
|
+
const isNative = isMobileNative();
|
|
13
|
+
const Component = isNative ? View : "tr";
|
|
14
|
+
import theme from "$theme";
|
|
15
|
+
|
|
16
|
+
export default function RowHeaderComponent({visible,className,children:cChildren,...rest}){
|
|
17
|
+
const children = React.useMemo(()=>{
|
|
18
|
+
return cChildren;
|
|
19
|
+
},[cChildren]);
|
|
20
|
+
const rP = isNative ? rest : {className:classNames(className,"table-footer-or-header-row")}
|
|
21
|
+
if(!isNative && !visible) return null;
|
|
22
|
+
//const backgroundColor = theme.isDark()? theme.Colors.lighten(theme.surfaceBackgroundColor):theme.Colors.darken(theme.surfaceBackgroundColor);
|
|
23
|
+
return <Component {...rP} style={StyleSheet.flatten([rest.style,!visible && {height:0,opacity:0,display:'none'}])}>
|
|
24
|
+
{children}
|
|
25
|
+
</Component>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
RowHeaderComponent.propTypes = {
|
|
29
|
+
visible : PropTypes.bool,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {Cell};
|
|
33
|
+
|
|
34
|
+
RowHeaderComponent.Cell = Cell;
|
|
@@ -12,4 +12,6 @@ const AutoSizeVerticalList = React.forwardRef(({testID,autoSizerProps,...props},
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
AutoSizeVerticalList.displayName = "AutoSizeVerticalListComponent";
|
|
15
|
-
export default AutoSizeVerticalList;
|
|
15
|
+
export default AutoSizeVerticalList;
|
|
16
|
+
|
|
17
|
+
export * from "$ecomponents/List/Virtuoso";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {default} from "$ecomponents/List/
|
|
1
|
+
export {default} from "$ecomponents/List/Virtuoso";
|
|
2
|
+
export * from "$ecomponents/List/Virtuoso";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2023 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {classNames} from "$cutils";
|
|
6
|
+
import { StyleSheet } from "react-native";
|
|
7
|
+
import Label from "$ecomponents/Label";
|
|
8
|
+
|
|
9
|
+
function TableCellContentComponent({children,style,...rest}){
|
|
10
|
+
return (<td {...rest} className={classNames(rest.className,"table-row-cell")} style={StyleSheet.flatten([style])}>
|
|
11
|
+
{children}
|
|
12
|
+
</td>);
|
|
13
|
+
}
|
|
14
|
+
//const TableCellContentComponent = React.memo(TableCellContentComponent);;
|
|
15
|
+
export default TableCellContentComponent;
|
|
16
|
+
TableCellContentComponent.displayName = "TableCellContentComponent";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2023 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import View from "$ecomponents/View";
|
|
6
|
+
import { StyleSheet } from "react-native";
|
|
7
|
+
|
|
8
|
+
function TableCellContentComponent({children,style,colSpan,...rest}){
|
|
9
|
+
return (<View testID={"RN_TableRowCellContentComponent"} {...rest} style={style}>
|
|
10
|
+
{children}
|
|
11
|
+
</View>);
|
|
12
|
+
}
|
|
13
|
+
//const TableCellContentComponent = React.memo(TableCellContentComponent);;
|
|
14
|
+
export default TableCellContentComponent;
|
|
15
|
+
TableCellContentComponent.displayName = "TableCellContentComponent";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "$react";
|
|
2
|
+
import CellContent from "./Content";
|
|
3
|
+
import { useTable } from "../../hooks";
|
|
4
|
+
import {defaultObj} from "$cutils";
|
|
5
|
+
import Label from "$ecomponents/Label";
|
|
6
|
+
import styles from "../../styles";
|
|
7
|
+
const TableRowCellComponent = React.forwardRef(({children,columnDef,rowData,colSpan,isSectionListHeader,rowIndex,style,...rest},ref)=>{
|
|
8
|
+
if(isSectionListHeader){
|
|
9
|
+
return <CellContent colSpan={colSpan} ref={ref} style={[styles.sectionListHeader,style]} >
|
|
10
|
+
{children}
|
|
11
|
+
</CellContent>
|
|
12
|
+
}
|
|
13
|
+
const {renderCell} = useTable();
|
|
14
|
+
const {content,containerProps} = React.useMemo(()=>{
|
|
15
|
+
const rArgs = {...rest,columnDef,rowData,rowIndex,containerProps : {}};
|
|
16
|
+
const r = typeof renderCell =='function' && renderCell (rArgs) || children;
|
|
17
|
+
return {
|
|
18
|
+
content : r && React.isValidElement(r,true)? r : children,
|
|
19
|
+
containerProps : defaultObj(rArgs.containerProps)
|
|
20
|
+
}
|
|
21
|
+
},[children]);
|
|
22
|
+
return (<CellContent ref={ref} {...containerProps} style={[style,containerProps.style]} >
|
|
23
|
+
{columnDef.isSelectableColumnName ? content : <Label testID="RN_TableRowCell" style={[styles.cell]}>{content}</Label>}
|
|
24
|
+
</CellContent>);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
TableRowCellComponent.displayName = "TableRowCellComponent";
|
|
29
|
+
|
|
30
|
+
export default TableRowCellComponent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import View from "$ecomponents/View";
|
|
3
|
+
import styles from "../styles";
|
|
4
|
+
|
|
5
|
+
const TableRowWrapperComponent = forwardRef(({children,colSpan,...props},ref)=>{
|
|
6
|
+
return <View ref={ref} {...props} style={[styles.row,props.style]} children={children}/>
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
TableRowWrapperComponent.displayName = "TableRowWrapperComponent";
|
|
10
|
+
|
|
11
|
+
export default TableRowWrapperComponent;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright 2023 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import Cell from "./Cell";
|
|
6
|
+
import PropTypes from "prop-types";
|
|
7
|
+
import {isObj} from "$cutils";
|
|
8
|
+
import styles from "../styles";
|
|
9
|
+
import {useTable} from "../hooks";
|
|
10
|
+
import RowWrapper from "./RowWrapper";
|
|
11
|
+
import React from "$react";
|
|
12
|
+
import theme from "$theme";
|
|
13
|
+
export default function TableRowComponent({cells,rowKey,rowData,index,...rest}){
|
|
14
|
+
const {visibleColsNames,renderItem,renderSectionHeader,columns} = useTable();
|
|
15
|
+
const content = React.useMemo(()=>{
|
|
16
|
+
if(rowData.isSectionListHeader && typeof renderSectionHeader ==='function'){
|
|
17
|
+
return <RowWrapper style={[styles.row,theme.styles.pv1]}>
|
|
18
|
+
<Cell isSectionListHeader colSpan={visibleColsNames.length}>{renderSectionHeader({isSectionListHeader:true,rowData,item:rowData,index,rowIndex:index,isTable:true,rowKey})}</Cell>
|
|
19
|
+
</RowWrapper>
|
|
20
|
+
}
|
|
21
|
+
return visibleColsNames.map((columnField,cIndex)=>{
|
|
22
|
+
const columnDef = columns[columnField];
|
|
23
|
+
if(!isObj(columnDef)) return null;
|
|
24
|
+
return <Cell rowData={rowData} rowKey={rowKey} children={rowData[columnField]} rowIndex={index} columnDef={columnDef} index={cIndex} key={columnField} columnField={columnField}/>
|
|
25
|
+
});
|
|
26
|
+
},[rowKey,index,JSON.stringify(visibleColsNames)]);
|
|
27
|
+
return <RowWrapper style={[styles.row]}>
|
|
28
|
+
{content}
|
|
29
|
+
</RowWrapper>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
TableRowComponent.propTypes = {
|
|
33
|
+
rowData : PropTypes.object.isRequired,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {Cell};
|
|
37
|
+
|
|
38
|
+
TableRowComponent.Cell = Cell;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScrollView } from "react-native";
|
|
2
|
+
import React from "$react";
|
|
3
|
+
const TableScrollViewNative = React.forwardRef(({children,...props},ref)=>{
|
|
4
|
+
return <ScrollView {...props} children={children} ref={ref}/>
|
|
5
|
+
});
|
|
6
|
+
TableScrollViewNative.displayName = "TableScrollViewNative";
|
|
7
|
+
|
|
8
|
+
export default TableScrollViewNative;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native"
|
|
2
|
+
import {classNames} from "$cutils";
|
|
3
|
+
export default function VirtuosoTableComponent({style,className,...props}){
|
|
4
|
+
return <table{...props} className={classNames(className,"virtuoso-table-component")} style={StyleSheet.flatten([{ borderCollapse: 'separate',width:"100%" },style])} />
|
|
5
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React,{useMemo,useContext,createContext} from "$react";
|
|
2
|
+
import {defaultStr,isObj} from "$cutils";
|
|
3
|
+
import {DEFAULT_COLUMN_WIDTH} from "./utils";
|
|
4
|
+
import Label from "$ecomponents/Label";
|
|
5
|
+
import HeaderCell from "./Header/Cell";
|
|
6
|
+
import { StyleSheet } from "react-native";
|
|
7
|
+
import styles from "./styles";
|
|
8
|
+
import theme from "$theme";
|
|
9
|
+
|
|
10
|
+
export const usePrepareColumns = ({columns,sortedColumn,forceRender,testID,renderFooterCell,renderHeaderCell,renderFilterCell,columnsWidths,headerCellContainerProps,colsWidths,columnProps,footers,footerCellContainerProps,filterCellContainerProps})=>{
|
|
11
|
+
return useMemo(()=>{
|
|
12
|
+
testID = defaultStr(testID,"RN_TableColumns")
|
|
13
|
+
const cols = {},headers = {},footers = {},filters = {},visibleColsNames = [],columnsVisibilities=[],columnsNames = [];
|
|
14
|
+
let hasFooters = false;
|
|
15
|
+
columnProps = defaultObj(columnProps);
|
|
16
|
+
let columnIndex = 0;
|
|
17
|
+
const widths = defaultObj(columnsWidths,colsWidths);
|
|
18
|
+
headerCellContainerProps = defaultObj(headerCellContainerProps);
|
|
19
|
+
footerCellContainerProps = defaultObj(footerCellContainerProps);
|
|
20
|
+
filterCellContainerProps = defaultObj(filterCellContainerProps);
|
|
21
|
+
Object.map(columns,(columnDef,field)=>{
|
|
22
|
+
if(!isObj(columnDef)) return;
|
|
23
|
+
const columnField = defaultStr(columnDef.field,field);
|
|
24
|
+
let {visible,width,type,style} = columnDef;
|
|
25
|
+
visible = typeof visible =='boolean'? visible : true;
|
|
26
|
+
type = defaultStr(type,"text").toLowerCase().trim();
|
|
27
|
+
width = defaultDecimal(widths[columnField],width,DEFAULT_COLUMN_WIDTH);
|
|
28
|
+
const colArgs = {width,type,columnDef,containerProps:{},columnField,index:columnIndex,columnIndex};
|
|
29
|
+
const content = typeof renderHeaderCell =='function'? renderHeaderCell(colArgs) : defaultVal(columnDef.text,columnDef.label,columnField);
|
|
30
|
+
const hContainerProps = defaultObj(colArgs.containerProps);
|
|
31
|
+
if(!React.isValidElement(content,true)){
|
|
32
|
+
console.error(content," is not valid element of header ",columnDef," it could not be render on table");
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const rArgs = {columnDef,width};
|
|
36
|
+
headers[columnField] = <HeaderCell {...rArgs} testID={testID+"_HeaderCell_"+columnField} {...headerCellContainerProps} {...hContainerProps} key={columnField} style={[styles.headerItem,styles.headerItemOrCell,headerCellContainerProps.style,hContainerProps.style,style]}>
|
|
37
|
+
<Label splitText numberOfLines={1} style={[theme.styles.w100,theme.styles.h100,{maxHeight:70},width&&{width}]} textBold primary>{content}</Label>
|
|
38
|
+
</HeaderCell>;
|
|
39
|
+
if(typeof renderFilterCell =='function'){
|
|
40
|
+
const filterCell = renderFilterCell(colArgs);
|
|
41
|
+
filters[columnField] = <HeaderCell {...rArgs} testID={testID+"_Filter_Cell_"+columnField} {...filterCellContainerProps} key={columnField} style={[styles.headerItem,styles.headerItemOrCell,styles.filterCell,filterCellContainerProps.style,styles.cell,style]}>
|
|
42
|
+
{React.isValidElement(filterCell)? filterCell : null}
|
|
43
|
+
</HeaderCell>
|
|
44
|
+
}
|
|
45
|
+
if(typeof renderFooterCell ==='function') {
|
|
46
|
+
const footerProps = {...colArgs,containerProps:{}};
|
|
47
|
+
let cellFooter = renderFooterCell(footerProps);
|
|
48
|
+
let fContainerProps = {};
|
|
49
|
+
if(!React.isValidElement(cellFooter,true) && isObj(cellFooter)){
|
|
50
|
+
fContainerProps = isObj(cellFooter.containerProps)? cellFooter.containerProps : {};
|
|
51
|
+
cellFooter = React.isValidElement(cellFooter.children)? cellFooter.children : React.isValidElement(cellFooter.content)? cellFooter.content : null;
|
|
52
|
+
} else if(isObj(footerProps.containerProps)){
|
|
53
|
+
fContainerProps = footerProps.containerProps;
|
|
54
|
+
}
|
|
55
|
+
cellFooter = React.isValidElement(cellFooter,true)? cellFooter : null;
|
|
56
|
+
if(!hasFooters && cellFooter){
|
|
57
|
+
hasFooters = true;
|
|
58
|
+
}
|
|
59
|
+
footers[columnField] = <HeaderCell {...rArgs} testID={testID+"_Footer_Cell_"+columnField} key={columnField} style={[styles.headerItem,styles.headerItemOrCell,footerCellContainerProps.style,style]}>
|
|
60
|
+
<Label primary children={cellFooter}/>
|
|
61
|
+
</HeaderCell>
|
|
62
|
+
}
|
|
63
|
+
columnsVisibilities.push(visible);
|
|
64
|
+
if(visible){
|
|
65
|
+
visibleColsNames.push(columnField);
|
|
66
|
+
}
|
|
67
|
+
columnsNames.push(columnField);
|
|
68
|
+
cols[columnField] = {
|
|
69
|
+
...columnDef,
|
|
70
|
+
width,
|
|
71
|
+
index : columnIndex,
|
|
72
|
+
field : columnField,
|
|
73
|
+
visible,
|
|
74
|
+
columnField,
|
|
75
|
+
};
|
|
76
|
+
columnIndex++;
|
|
77
|
+
});
|
|
78
|
+
return {columns:cols,columnsNames,headers,columnsVisibilities,visibleColsNames,hasFooters,footers,filters};
|
|
79
|
+
},[columns,sortedColumn,footers,forceRender]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const TableContext = createContext(null);
|
|
83
|
+
|
|
84
|
+
export const useTable = ()=> useContext(TableContext);
|