File tree 3 files changed +80
-1
lines changed
3 files changed +80
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ RGL is React-only and does not require jQuery.
58
58
1 . [ Scaled Containers] ( https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html )
59
59
1 . [ Allow Overlap] ( https://react-grid-layout.github.io/react-grid-layout/examples/19-allow-overlap.html )
60
60
1 . [ All Resizable Handles] ( https://react-grid-layout.github.io/react-grid-layout/examples/20-resizable-handles.html )
61
+ 1 . [ Single Row Horizontal] ( https://react-grid-layout.github.io/react-grid-layout/examples/21-horizontal.html )
61
62
62
63
#### Projects Using React-Grid-Layout
63
64
Original file line number Diff line number Diff line change @@ -174,5 +174,12 @@ module.exports = [
174
174
paragraphs : [
175
175
"This shows a grid with all resizable handles enabled. See the prop `resizableHandles` on the grid and grid items in the README."
176
176
]
177
- }
177
+ } ,
178
+ {
179
+ title : "Single Row Horizontal" ,
180
+ source : "horizontal" ,
181
+ paragraphs : [
182
+ "This demonstrates how to constrain the elements to a single row."
183
+ ]
184
+ } ,
178
185
] ;
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import _ from "lodash" ;
3
+ import RGL , { WidthProvider } from "react-grid-layout" ;
4
+
5
+ const ReactGridLayout = WidthProvider ( RGL ) ;
6
+
7
+ export default class Horizontal extends React . PureComponent {
8
+ static defaultProps = {
9
+ className : "layout" ,
10
+ items : 5 ,
11
+ rowHeight : 5 ,
12
+ onLayoutChange : function ( ) { } ,
13
+ cols : 12 ,
14
+ compactType : "horizontal" ,
15
+ maxRows : 1 ,
16
+ allowOverlap : false
17
+ } ;
18
+
19
+ constructor ( props ) {
20
+ super ( props ) ;
21
+
22
+ const layout = this . generateLayout ( ) ;
23
+ this . state = { layout } ;
24
+ }
25
+
26
+ generateDOM ( ) {
27
+ return _ . map ( _ . range ( this . props . items ) , function ( i ) {
28
+ return (
29
+ < div key = { i } >
30
+ < span className = "text" > { i } </ span >
31
+ </ div >
32
+ ) ;
33
+ } ) ;
34
+ }
35
+
36
+ generateLayout ( ) {
37
+ const p = this . props ;
38
+ return _ . map ( new Array ( p . items ) , function ( item , i ) {
39
+ const y = 5 ;
40
+ return {
41
+ x : ( i * 2 ) % 12 ,
42
+ y : Math . floor ( i / 6 ) * y ,
43
+ w : 2 ,
44
+ h : y ,
45
+ i : i . toString ( )
46
+ } ;
47
+ } ) ;
48
+ }
49
+
50
+ onLayoutChange ( layout ) {
51
+ this . props . onLayoutChange ( layout ) ;
52
+ }
53
+
54
+ render ( ) {
55
+ return (
56
+ < ReactGridLayout
57
+ layout = { this . state . layout }
58
+ onLayoutChange = { this . onLayoutChange }
59
+ useCSSTransforms = { true }
60
+ allowOverlap = { true }
61
+ { ...this . props }
62
+ >
63
+ { this . generateDOM ( ) }
64
+ </ ReactGridLayout >
65
+ ) ;
66
+ }
67
+ }
68
+
69
+ if ( process . env . STATIC_EXAMPLES === true ) {
70
+ import ( "../test-hook.jsx" ) . then ( fn => fn . default ( Horizontal ) ) ;
71
+ }
You can’t perform that action at this time.
0 commit comments