@@ -34,8 +34,23 @@ interface PropsType {
3434 total_width_size : number ;
3535 total_height_size : number ;
3636 seats : seatType [ ] ;
37+ isEdit ?: boolean ;
38+ onClickSeat ?: ( xPosition : number , yPosition : number ) => void ;
39+ selectedPosition ?: {
40+ x : number ;
41+ y : number ;
42+ } ;
3743}
3844
45+ const arr2Generator = ( x : number , y : number ) => {
46+ let arr = [ ] ;
47+ for ( let i = 0 ; i < x ; i ++ ) {
48+ arr [ i ] = [ ] ;
49+ for ( let j = 0 ; j < y ; j ++ ) arr [ i ] [ j ] = 0 ;
50+ }
51+ return arr ;
52+ } ;
53+
3954export const StudyRoom = ( {
4055 east_description,
4156 west_description,
@@ -44,6 +59,12 @@ export const StudyRoom = ({
4459 total_height_size,
4560 total_width_size,
4661 seats,
62+ isEdit = false ,
63+ onClickSeat = ( x , y ) => { } ,
64+ selectedPosition = {
65+ x : - 1 ,
66+ y : - 1 ,
67+ } ,
4768} : PropsType ) => {
4869 const arr2Generator = ( x : number , y : number ) => {
4970 let arr = [ ] ;
@@ -74,32 +95,64 @@ export const StudyRoom = ({
7495 { north_description }
7596 </ _NorthDirection >
7697 < _Room >
77- { arr . map ( ( seat , idx ) => (
98+ { arr . map ( ( seatY , y ) => (
7899 < _Seats >
79- { seat . map ( ( seat , idx ) => (
100+ { seatY . map ( ( seat , x ) => (
80101 < >
81102 { seat ? (
82103 seat . number ? (
83- < _Seat
84- display = "inline-block"
85- background = { seat . type . color || '#b1d0ff' }
86- color = "gray1"
87- size = "bodyS"
104+ < _SeatBlock
105+ isEdit = { isEdit }
106+ isSelected = {
107+ isEdit &&
108+ selectedPosition ?. x === x &&
109+ selectedPosition ?. y === y
110+ }
88111 >
89- { seat . type ? seat . type . name : seat . number }
90- </ _Seat >
112+ < _Seat
113+ onClick = { ( ) => isEdit && onClickSeat ( x , y ) }
114+ display = "inline-block"
115+ background = { seat . type . color || '#b1d0ff' }
116+ color = "gray1"
117+ size = "bodyS"
118+ >
119+ { seat . type ? seat . type . name : seat . number }
120+ </ _Seat >
121+ </ _SeatBlock >
91122 ) : (
92- < _Seat
93- display = "inline-block"
94- background = { 'gray4' }
95- color = "gray1"
96- size = "bodyS"
123+ < _SeatBlock
124+ isEdit = { isEdit }
125+ isSelected = {
126+ isEdit &&
127+ selectedPosition ?. x === x &&
128+ selectedPosition ?. y === y
129+ }
97130 >
98- 사용불가
99- </ _Seat >
131+ < _Seat
132+ onClick = { ( ) => isEdit && onClickSeat ( x , y ) }
133+ display = "inline-block"
134+ background = { 'gray4' }
135+ color = "gray1"
136+ size = "bodyS"
137+ >
138+ 사용불가
139+ </ _Seat >
140+ </ _SeatBlock >
100141 )
101142 ) : (
102- < _Seat background = { 'gray1' } />
143+ < _SeatBlock
144+ isEdit = { isEdit }
145+ isSelected = {
146+ isEdit &&
147+ selectedPosition ?. x === x &&
148+ selectedPosition ?. y === y
149+ }
150+ >
151+ < _Seat
152+ onClick = { ( ) => isEdit && onClickSeat ( x , y ) }
153+ background = { 'gray1' }
154+ />
155+ </ _SeatBlock >
103156 ) }
104157 </ >
105158 ) ) }
@@ -112,6 +165,19 @@ export const StudyRoom = ({
112165
113166const _Seats = styled . div `
114167 display: flex;
168+ overflow: hidden;
169+ ` ;
170+
171+ const _SeatBlock = styled . div < {
172+ isEdit : boolean ;
173+ isSelected : boolean ;
174+ } > `
175+ width: 100px;
176+ height: 100px;
177+ padding: 10px;
178+ border: 1px solid
179+ ${ ( { theme, isSelected, isEdit } ) =>
180+ isEdit ? ( isSelected ? theme . color . primary : theme . color . gray4 ) : 'none' } ;
115181` ;
116182
117183const _Seat = styled ( Text ) < { background : string } > `
@@ -120,7 +186,6 @@ const _Seat = styled(Text)<{ background: string }>`
120186 display: flex;
121187 justify-content: center;
122188 align-items: center;
123- margin: 10px;
124189 border-radius: 70%;
125190 background-color: ${ ( { background } ) => background } ;
126191` ;
0 commit comments