1
1
import { useState } from "react" ;
2
- import {
3
- GridWrapper ,
4
- GridSection ,
5
- GridArea ,
6
- GridItem ,
7
- Alignment ,
8
- } from "react-align" ;
2
+ import { GridWrapper , GridSection , GridArea , GridItem , Alignment } from "react-align" ;
9
3
10
4
type Item = {
11
5
id : string ;
@@ -41,8 +35,7 @@ const ItemComponent = (item: Item, i: number) => (
41
35
index = { i }
42
36
key = { item . id }
43
37
extendable = { item . extendable }
44
- extended = { item . extended }
45
- >
38
+ extended = { item . extended } >
46
39
< div
47
40
style = { {
48
41
fontSize : "24px" ,
@@ -51,8 +44,7 @@ const ItemComponent = (item: Item, i: number) => (
51
44
background : "#ddd" ,
52
45
padding : "10px" ,
53
46
boxSizing : "border-box" ,
54
- } }
55
- >
47
+ } } >
56
48
{ item . id }
57
49
</ div >
58
50
</ GridItem >
@@ -74,14 +66,14 @@ function App() {
74
66
editing = { edit }
75
67
onMove = { ( ...args ) => {
76
68
console . log ( "move" , ...args ) ;
77
- setItems ( ( items ) => {
78
- const target = items . find ( ( i ) => i . id === args [ 0 ] ) ;
69
+ setItems ( items => {
70
+ const target = items . find ( i => i . id === args [ 0 ] ) ;
79
71
if ( ! target ) return items ;
80
- const sibilings = items . filter ( ( i ) => i . location === args [ 1 ] ) ;
72
+ const sibilings = items . filter ( i => i . location === args [ 1 ] ) ;
81
73
if ( args [ 1 ] === args [ 3 ] ) {
82
74
sibilings . splice (
83
- sibilings . findIndex ( ( i ) => i . id === args [ 0 ] ) ,
84
- 1
75
+ sibilings . findIndex ( i => i . id === args [ 0 ] ) ,
76
+ 1 ,
85
77
) ;
86
78
}
87
79
sibilings . splice ( args [ 2 ] , 0 , target ) ;
@@ -94,23 +86,22 @@ function App() {
94
86
} }
95
87
onAlignChange = { ( ...args ) => {
96
88
console . log ( "alignmentChange" , ...args ) ;
97
- setAlignments ( ( a ) => ( {
89
+ setAlignments ( a => ( {
98
90
...a ,
99
91
[ args [ 0 ] ] : args [ 1 ] ,
100
92
} ) ) ;
101
93
} }
102
94
onExtend = { ( ...args ) => {
103
95
console . log ( "extend" , ...args ) ;
104
- setItems ( ( items ) => {
105
- const target = items . find ( ( i ) => i . id === args [ 0 ] ) ;
96
+ setItems ( items => {
97
+ const target = items . find ( i => i . id === args [ 0 ] ) ;
106
98
if ( ! target ) return items ;
107
99
target . extended = args [ 1 ] ;
108
100
return [ ...items ] ;
109
101
} ) ;
110
- } }
111
- >
102
+ } } >
112
103
< GridSection >
113
- { [ "1" , "2" , "3" ] . map ( ( l ) => (
104
+ { [ "1" , "2" , "3" ] . map ( l => (
114
105
< GridArea
115
106
id = { l }
116
107
key = { l }
@@ -124,22 +115,19 @@ function App() {
124
115
background : l === "2" ? "blue" : "red" ,
125
116
border : `2px solid ${ background } ` ,
126
117
} }
127
- iconColor = { l === "2" ? "red" : "blue" }
128
- >
118
+ iconColor = { l === "2" ? "red" : "blue" } >
129
119
{ items
130
- . filter ( ( i ) => i . location === l )
120
+ . filter ( i => i . location === l )
131
121
. sort ( ( a , b ) => a . index - b . index )
132
122
. map ( ItemComponent ) }
133
123
</ GridArea >
134
124
) ) }
135
125
</ GridSection >
136
126
< GridSection stretch >
137
- { [ "4" , "5" , "6" ] . map ( ( l ) =>
127
+ { [ "4" , "5" , "6" ] . map ( l =>
138
128
l === "5" ? (
139
129
< div key = { l } style = { { flex : "auto" } } >
140
- < button onClick = { ( ) => setEdit ( ( e ) => ! e ) } >
141
- { edit ? "Finish" : "Start" } editing
142
- </ button >
130
+ < button onClick = { ( ) => setEdit ( e => ! e ) } > { edit ? "Finish" : "Start" } editing</ button >
143
131
</ div >
144
132
) : (
145
133
< GridArea
@@ -148,18 +136,17 @@ function App() {
148
136
align = { alignments [ l ] }
149
137
bottom = { l === "6" }
150
138
editorStyle = { { background : "red" } }
151
- iconColor = { "blue" }
152
- >
139
+ iconColor = { "blue" } >
153
140
{ items
154
- . filter ( ( i ) => i . location === l )
141
+ . filter ( i => i . location === l )
155
142
. sort ( ( a , b ) => a . index - b . index )
156
143
. map ( ItemComponent ) }
157
144
</ GridArea >
158
- )
145
+ ) ,
159
146
) }
160
147
</ GridSection >
161
148
< GridSection >
162
- { [ "7" , "8" , "9" ] . map ( ( l ) => (
149
+ { [ "7" , "8" , "9" ] . map ( l => (
163
150
< GridArea
164
151
id = { l }
165
152
key = { l }
@@ -168,10 +155,9 @@ function App() {
168
155
vertical = { l === "8" }
169
156
stretch = { l === "8" }
170
157
editorStyle = { { background : l === "8" ? "blue" : "red" } }
171
- iconColor = { l === "8" ? "red" : "blue" }
172
- >
158
+ iconColor = { l === "8" ? "red" : "blue" } >
173
159
{ items
174
- . filter ( ( i ) => i . location === l )
160
+ . filter ( i => i . location === l )
175
161
. sort ( ( a , b ) => a . index - b . index )
176
162
. map ( ItemComponent ) }
177
163
</ GridArea >
0 commit comments