1
- import {
2
- EuiPanel ,
3
- EuiText ,
4
- useEuiOverflowScroll ,
5
- useEuiTheme ,
6
- } from '@elastic/eui' ;
7
- import { cx } from '@emotion/css' ;
1
+ import { EuiText , useEuiOverflowScroll , useEuiTheme } from '@elastic/eui' ;
8
2
import { css } from '@emotion/react' ;
9
3
import Head from 'next/head' ;
10
- import {
11
- CSSProperties ,
12
- MouseEvent ,
13
- ReactNode ,
14
- TouchEvent ,
15
- forwardRef ,
16
- useMemo ,
17
- useRef ,
18
- useState ,
19
- } from 'react' ;
4
+ import { useMemo , useRef , useState } from 'react' ;
20
5
import { Responsive , WidthProvider } from 'react-grid-layout' ;
21
- import { useLogger } from '../logger ' ;
6
+ import { GridItem } from '../grid-item ' ;
22
7
23
8
const Grid : React . FC = ( ) : JSX . Element => {
24
- const { logger } = useLogger ( 'component:grid' ) ;
25
-
26
- logger . info ( 'rendering' ) ;
27
-
28
9
const { euiTheme } = useEuiTheme ( ) ;
29
10
30
11
const gridLayoutStyles = css `
@@ -57,6 +38,15 @@ const Grid: React.FC = (): JSX.Element => {
57
38
58
39
/**
59
40
* Define the initial layout state.
41
+ *
42
+ * TODO save the layout on changes
43
+ * TODO load the layout according to user's preferences
44
+ * TODO create an item per game window that is open (e.g. Room, Spells, etc)
45
+ * and one of the properties should be the game window's title
46
+ * and one of the properties should be the game window's text
47
+ * Probably make the property another component to encapsulate use of rxjs
48
+ * and then exposes a property that is the text so that when that changes
49
+ * then the grid item will rerender.
60
50
*/
61
51
const [ layout , setLayout ] = useState ( [
62
52
{ i : 'a' , x : 0 , y : 0 , w : 3 , h : 2 } ,
@@ -72,47 +62,20 @@ const Grid: React.FC = (): JSX.Element => {
72
62
*/
73
63
const children = useMemo ( ( ) => {
74
64
return layout . map ( ( item ) => {
75
- /**
76
- * How to use custom components a react-grid-layout children.
77
- * https://github.com/react-grid-layout/react-grid-layout/tree/master?tab=readme-ov-file#custom-child-components-and-draggable-handles
78
- * https://stackoverflow.com/questions/67053157/react-grid-layout-error-draggablecore-not-mounted-on-dragstart
79
- */
80
-
81
- interface ReactGridLayoutItemProps {
82
- style ?: CSSProperties ;
83
- className ?: string ;
84
- onMouseDown ?: ( e : MouseEvent < HTMLDivElement > ) => void ;
85
- onMouseUp ?: ( e : MouseEvent < HTMLDivElement > ) => void ;
86
- onTouchEnd ?: ( e : TouchEvent < HTMLDivElement > ) => void ;
87
- children ?: ReactNode ;
88
- }
89
-
90
- const MyGridItem = forwardRef < HTMLDivElement , ReactGridLayoutItemProps > (
91
- ( props , ref ) => {
92
- const { style, className, children, ...otherProps } = props ;
93
-
94
- return (
95
- < EuiPanel
96
- panelRef = { ref }
97
- hasBorder = { true }
98
- grow = { false }
99
- style = { style }
100
- className = { cx ( className ) }
101
- { ...otherProps }
102
- >
103
- < EuiText css = { gridItemTextStyles } > { item . i } </ EuiText >
104
- { children }
105
- </ EuiPanel >
106
- ) ;
107
- }
65
+ return (
66
+ < GridItem key = { item . i } ref = { useRef ( null ) } >
67
+ < EuiText css = { gridItemTextStyles } > { item . i } </ EuiText >
68
+ </ GridItem >
108
69
) ;
109
-
110
- MyGridItem . displayName = 'MyGridItem' ;
111
-
112
- return < MyGridItem key = { item . i } ref = { useRef ( null ) } /> ;
113
70
} ) ;
114
71
} , [ layout . length ] ) ;
115
72
73
+ /**
74
+ * When resize horizontally or vertically, this is the number
75
+ * of pixels the grid item will grow or shrink.
76
+ */
77
+ const resizeIncrement = 30 ;
78
+
116
79
return (
117
80
< >
118
81
< Head >
@@ -123,8 +86,8 @@ const Grid: React.FC = (): JSX.Element => {
123
86
css = { gridLayoutStyles }
124
87
layouts = { { lg : layout } }
125
88
breakpoints = { { lg : 1200 } }
126
- cols = { { lg : 30 } }
127
- rowHeight = { 30 }
89
+ cols = { { lg : resizeIncrement } }
90
+ rowHeight = { resizeIncrement }
128
91
isBounded = { true }
129
92
isDraggable = { true }
130
93
isDroppable = { true }
0 commit comments