@@ -4,7 +4,7 @@ import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
4
4
import _ from "lodash" ;
5
5
import { ConstructorToView , deferAction } from "lowcoder-core" ;
6
6
import { HintPlaceHolder , ScrollBar , pageItemRender } from "lowcoder-design" ;
7
- import { RefObject , useContext , useEffect , useMemo , useRef } from "react" ;
7
+ import { RefObject , useContext , createContext , useMemo , useRef } from "react" ;
8
8
import ReactResizeDetector from "react-resize-detector" ;
9
9
import styled from "styled-components" ;
10
10
import { checkIsMobile } from "util/commonUtils" ;
@@ -40,21 +40,34 @@ const BodyWrapper = styled.div<{ $autoHeight: boolean }>`
40
40
height: ${ ( props ) => ( props . $autoHeight ? "100%" : "calc(100% - 32px)" ) } ;
41
41
` ;
42
42
43
- const FlexWrapper = styled . div `
43
+ const FlexWrapper = styled . div `
44
44
height: 100%;
45
45
display: flex;
46
46
align-items: center;
47
47
justify-content: center;
48
+ flex-wrap: 'wrap'};
48
49
` ;
49
50
50
- const ContainerInListView = ( props : ContainerBaseProps ) => {
51
+ const ListOrientationWrapper = styled . div < { $isHorizontal : boolean , $autoHeight : boolean } > `
52
+ height: ${ ( props ) => ( props . $autoHeight ? "auto" : "100%" ) } ;
53
+ display: flex;
54
+ flex-direction: ${ ( props ) => ( props . $isHorizontal ? "row" : "column" ) } ;
55
+ height: 100%;
56
+ ` ;
57
+
58
+ const MinHorizontalWidthContext = createContext ( 0 ) ;
59
+
60
+ const ContainerInListView = ( props : ContainerBaseProps ) => {
61
+ const minHorizontalWidth = useContext ( MinHorizontalWidthContext ) ;
51
62
return (
52
- < InnerGrid
53
- { ...props }
54
- emptyRows = { 15 }
55
- containerPadding = { [ 4 , 4 ] }
56
- hintPlaceholder = { HintPlaceHolder }
57
- />
63
+ < div style = { { width : minHorizontalWidth > 0 ? `${ minHorizontalWidth } px` : "100%" } } >
64
+ < InnerGrid
65
+ { ...props }
66
+ emptyRows = { 15 }
67
+ containerPadding = { [ 4 , 4 ] }
68
+ hintPlaceholder = { HintPlaceHolder }
69
+ />
70
+ </ div >
58
71
) ;
59
72
} ;
60
73
@@ -66,9 +79,10 @@ type ListItemProps = {
66
79
scrollContainerRef ?: RefObject < HTMLDivElement > ;
67
80
minHeight ?: string ;
68
81
unMountFn ?: ( ) => void ;
82
+ minHorizontalWidth : number ;
69
83
} ;
70
84
71
- function ListItem ( props : ListItemProps ) {
85
+ function ListItem ( { minHorizontalWidth , ... props } : ListItemProps ) {
72
86
const { itemIdx, offset, containerProps, autoHeight, scrollContainerRef, minHeight } = props ;
73
87
74
88
// disable the unmount function to save user's state with pagination
@@ -80,23 +94,25 @@ function ListItem(props: ListItemProps) {
80
94
// }, []);
81
95
82
96
return (
83
- < ContainerInListView
84
- layout = { containerProps . layout }
85
- items = { gridItemCompToGridItems ( containerProps . items ) }
86
- positionParams = { containerProps . positionParams }
87
- // all layout changes should only reflect on the commonContainer
88
- dispatch = { itemIdx === offset ? containerProps . dispatch : _ . noop }
89
- style = { { height : "100%" , backgroundColor : "transparent" , flex : "auto" } }
90
- autoHeight = { autoHeight }
91
- isDroppable = { itemIdx === offset }
92
- isDraggable = { itemIdx === offset }
93
- isResizable = { itemIdx === offset }
94
- isSelectable = { itemIdx === offset }
95
- scrollContainerRef = { scrollContainerRef }
96
- overflow = { "hidden" }
97
- minHeight = { minHeight }
98
- enableGridLines = { true }
99
- />
97
+ < MinHorizontalWidthContext . Provider value = { minHorizontalWidth } >
98
+ < ContainerInListView
99
+ layout = { containerProps . layout }
100
+ items = { gridItemCompToGridItems ( containerProps . items ) }
101
+ positionParams = { containerProps . positionParams }
102
+ // all layout changes should only reflect on the commonContainer
103
+ dispatch = { itemIdx === offset ? containerProps . dispatch : _ . noop }
104
+ style = { { height : "100%" , backgroundColor : "transparent" , flex : "auto" } }
105
+ autoHeight = { autoHeight }
106
+ isDroppable = { itemIdx === offset }
107
+ isDraggable = { itemIdx === offset }
108
+ isResizable = { itemIdx === offset }
109
+ isSelectable = { itemIdx === offset }
110
+ scrollContainerRef = { scrollContainerRef }
111
+ overflow = { "hidden" }
112
+ minHeight = { minHeight }
113
+ enableGridLines = { true }
114
+ />
115
+ </ MinHorizontalWidthContext . Provider >
100
116
) ;
101
117
}
102
118
@@ -126,6 +142,8 @@ export function ListView(props: Props) {
126
142
) ;
127
143
const autoHeight = useMemo ( ( ) => children . autoHeight . getView ( ) , [ children . autoHeight ] ) ;
128
144
const scrollbars = useMemo ( ( ) => children . scrollbars . getView ( ) , [ children . scrollbars ] ) ;
145
+ const horizontal = useMemo ( ( ) => children . horizontal . getView ( ) , [ children . horizontal ] ) ;
146
+ const minHorizontalWidth = useMemo ( ( ) => children . minHorizontalWidth . getView ( ) , [ children . minHorizontalWidth ] ) ;
129
147
const noOfColumns = useMemo (
130
148
( ) => Math . max ( 1 , children . noOfColumns . getView ( ) ) ,
131
149
[ children . noOfColumns ]
@@ -163,7 +181,8 @@ export function ListView(props: Props) {
163
181
key = { rowIdx }
164
182
style = { {
165
183
height : rowHeight ,
166
- // border: "0.5px solid #d9d9d9"
184
+ width : 100 / noOfColumns + "%" ,
185
+ minWidth : minHorizontalWidth ,
167
186
} }
168
187
>
169
188
< FlexWrapper >
@@ -198,6 +217,7 @@ export function ListView(props: Props) {
198
217
scrollContainerRef = { ref }
199
218
minHeight = { minHeight }
200
219
unMountFn = { unMountFn }
220
+ minHorizontalWidth = { horizontal ? minHorizontalWidth : 0 }
201
221
/>
202
222
) ;
203
223
} ) }
@@ -214,10 +234,11 @@ export function ListView(props: Props) {
214
234
return (
215
235
< BackgroundColorContext . Provider value = { style . background } >
216
236
< ListViewWrapper $style = { style } $paddingWidth = { paddingWidth } >
237
+
217
238
< BodyWrapper ref = { ref } $autoHeight = { autoHeight } >
218
239
< ScrollBar style = { { height : autoHeight ? "auto" : "100%" , margin : "0px" , padding : "0px" } } hideScrollbar = { ! scrollbars } >
219
240
< > { < ReactResizeDetector onResize = { ( width ?: number , height ?: number ) => { if ( height ) setListHeight ( height ) ; } } observerOptions = { { box : "border-box" } } >
220
- < div style = { { height : autoHeight ? "auto" : "100%" } } > { renders } </ div >
241
+ < ListOrientationWrapper $isHorizontal = { horizontal } $ autoHeight= { autoHeight } > { renders } </ ListOrientationWrapper >
221
242
</ ReactResizeDetector > } </ >
222
243
</ ScrollBar >
223
244
</ BodyWrapper >
0 commit comments