@@ -35,6 +35,7 @@ import {
35
35
} from './hooks'
36
36
import { ReachableBanner } from './ReachableBanner'
37
37
import { RobotOverflowMenu } from './RobotOverflowMenu'
38
+ import { useGetElementDOMRectProperty } from '../../organisms/ProtocolsLanding/useGetElementDOMRectProperty'
38
39
39
40
import type { DiscoveredRobot } from '../../redux/discovery/types'
40
41
@@ -45,6 +46,8 @@ const ROBOT_CARD_STYLE = css`
45
46
}
46
47
`
47
48
49
+ const ROBOT_CARD_WRAP_SIZE = 650
50
+
48
51
interface RobotCardProps {
49
52
robot : DiscoveredRobot
50
53
}
@@ -54,6 +57,25 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
54
57
const { name : robotName = null , local } = robot
55
58
const history = useHistory ( )
56
59
60
+ const robotCardRef = React . useRef ( null )
61
+ const { getElementProperty } = useGetElementDOMRectProperty < HTMLDivElement > (
62
+ robotCardRef
63
+ )
64
+ const [ robotCardWidth , setRobotCardWidth ] = React . useState < number | null > (
65
+ getElementProperty ( 'width' )
66
+ )
67
+
68
+ const handleResize = React . useCallback ( ( ) : void => {
69
+ setRobotCardWidth ( getElementProperty ( 'width' ) )
70
+ } , [ getElementProperty ] )
71
+
72
+ React . useEffect ( ( ) => {
73
+ window . addEventListener ( 'resize' , handleResize )
74
+ return ( ) => {
75
+ window . removeEventListener ( 'resize' , handleResize )
76
+ }
77
+ } , [ handleResize ] )
78
+
57
79
return robotName != null ? (
58
80
< Flex
59
81
alignItems = { ALIGN_CENTER }
@@ -66,6 +88,7 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
66
88
width = "100%"
67
89
onClick = { ( ) => history . push ( `/devices/${ robotName } ` ) }
68
90
cursor = "pointer"
91
+ ref = { robotCardRef }
69
92
>
70
93
< img
71
94
src = { OT2_PNG }
@@ -112,14 +135,20 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
112
135
) : null }
113
136
</ Flex >
114
137
{ robot . status === CONNECTABLE ? (
115
- < Flex flexDirection = { DIRECTION_ROW } >
116
- < Flex flex = "4" >
117
- < AttachedPipettes robotName = { robotName } />
118
- </ Flex >
119
- < Flex flex = "1" >
120
- < AttachedModules robotName = { robotName } />
121
- </ Flex >
122
- </ Flex >
138
+ < Box
139
+ display = "grid"
140
+ css = {
141
+ robotCardWidth == null || robotCardWidth >= ROBOT_CARD_WRAP_SIZE
142
+ ? { 'grid-template-columns' : '4fr 1fr' }
143
+ : { 'grid-template-rows' : '2fr 1fr' }
144
+ }
145
+ >
146
+ < AttachedPipettes
147
+ robotName = { robotName }
148
+ robotCardWidth = { robotCardWidth }
149
+ />
150
+ < AttachedModules robotName = { robotName } />
151
+ </ Box >
123
152
) : null }
124
153
</ Box >
125
154
< RobotOverflowMenu robot = { robot } alignSelf = { ALIGN_START } />
@@ -132,10 +161,10 @@ function AttachedModules(props: { robotName: string }): JSX.Element | null {
132
161
const { t } = useTranslation ( 'devices_landing' )
133
162
const attachedModules = useAttachedModules ( )
134
163
return attachedModules . length > 0 ? (
135
- < Flex
136
- flexDirection = { DIRECTION_COLUMN }
164
+ < Box
165
+ display = "grid"
166
+ gridTemplateRows = "1fr 1fr"
137
167
paddingRight = { SPACING . spacing4 }
138
- width = "100%"
139
168
>
140
169
< StyledText
141
170
as = "h6"
@@ -156,23 +185,29 @@ function AttachedModules(props: { robotName: string }): JSX.Element | null {
156
185
/>
157
186
) ) }
158
187
</ Flex >
159
- </ Flex >
188
+ </ Box >
160
189
) : (
161
190
< Flex width = "100%" > </ Flex >
162
191
)
163
192
}
164
- function AttachedPipettes ( props : { robotName : string } ) : JSX . Element {
165
- const { robotName } = props
193
+ function AttachedPipettes ( props : {
194
+ robotName : string
195
+ robotCardWidth : number | null
196
+ } ) : JSX . Element {
197
+ const { robotName, robotCardWidth } = props
166
198
const { t } = useTranslation ( 'devices_landing' )
167
199
const attachedPipettes = useAttachedPipettes ( )
200
+
168
201
return (
169
- < Flex flexDirection = { DIRECTION_ROW } width = "100%" >
170
- < Flex
171
- flex = "1"
172
- flexDirection = { DIRECTION_COLUMN }
173
- paddingRight = { SPACING . spacing4 }
174
- width = "100%"
175
- >
202
+ < Box
203
+ display = "grid"
204
+ css = {
205
+ robotCardWidth == null || robotCardWidth >= ROBOT_CARD_WRAP_SIZE
206
+ ? { 'grid-template-columns' : '1fr 1fr' }
207
+ : { 'grid-template-rows' : '1fr' }
208
+ }
209
+ >
210
+ < Box gridTemplateRows = "1fr 1fr" paddingRight = { SPACING . spacing4 } >
176
211
< StyledText
177
212
as = "h6"
178
213
textTransform = { TEXT_TRANSFORM_UPPERCASE }
@@ -184,13 +219,8 @@ function AttachedPipettes(props: { robotName: string }): JSX.Element {
184
219
< StyledText as = "p" id = { `RobotCard_${ robotName } _leftMountPipette` } >
185
220
{ attachedPipettes ?. left ?. modelSpecs . displayName ?? t ( 'empty' ) }
186
221
</ StyledText >
187
- </ Flex >
188
- < Flex
189
- flex = "1"
190
- flexDirection = { DIRECTION_COLUMN }
191
- paddingRight = { SPACING . spacing4 }
192
- width = "100%"
193
- >
222
+ </ Box >
223
+ < Box gridTemplateRows = "1fr 1fr" paddingRight = { SPACING . spacing4 } >
194
224
< StyledText
195
225
as = "h6"
196
226
textTransform = { TEXT_TRANSFORM_UPPERCASE }
@@ -202,8 +232,8 @@ function AttachedPipettes(props: { robotName: string }): JSX.Element {
202
232
< StyledText as = "p" id = { `RobotCard_${ robotName } _rightMountPipette` } >
203
233
{ attachedPipettes ?. right ?. modelSpecs . displayName ?? t ( 'empty' ) }
204
234
</ StyledText >
205
- </ Flex >
206
- </ Flex >
235
+ </ Box >
236
+ </ Box >
207
237
)
208
238
}
209
239
0 commit comments