@@ -17,43 +17,66 @@ import { HomeHeroUnitCredit } from "./HomeHeroUnitCredit"
17
17
import { createFragmentContainer , graphql } from "react-relay"
18
18
import { HomeHeroUnit_heroUnit$data } from "__generated__/HomeHeroUnit_heroUnit.graphql"
19
19
import { getInternalHref } from "Utils/url"
20
+ import { useTracking } from "react-tracking"
21
+ import { OwnerType } from "@artsy/cohesion"
22
+ import { ActionType } from "@artsy/cohesion"
23
+ import { ClickedHeroUnitGroup } from "@artsy/cohesion"
20
24
21
- interface HomeHeroUnitProps {
22
- heroUnit : HomeHeroUnit_heroUnit$data
25
+ export interface HomeHeroUnitBaseProps {
26
+ title : string
27
+ body : string
28
+ imageUrl ?: string | null
29
+ credit ?: string | null
30
+ label ?: string | null
31
+ link : {
32
+ desktop : {
33
+ text : string
34
+ url : string
35
+ }
36
+ mobile : {
37
+ text : string
38
+ url : string
39
+ }
40
+ }
23
41
index : number
24
42
onClick ?: ( ) => void
25
43
}
26
44
27
- export const HomeHeroUnit : React . FC < React . PropsWithChildren <
28
- HomeHeroUnitProps
29
- > > = props => {
30
- return (
31
- < Box width = "100%" height = "100%" >
32
- < Media at = "xs" >
33
- < HomeHeroUnitSmall { ...props } />
34
- </ Media >
45
+ const HomeHeroUnitBaseSmall : React . FC < HomeHeroUnitBaseProps > = ( {
46
+ title,
47
+ body,
48
+ imageUrl,
49
+ link,
50
+ index,
51
+ onClick,
52
+ } ) => {
53
+ const image = imageUrl ? cropped ( imageUrl , { width : 500 , height : 333 } ) : null
54
+ const href = getInternalHref ( link . mobile . url )
35
55
36
- < Media greaterThan = "xs" >
37
- < HomeHeroUnitLarge { ...props } />
38
- </ Media >
39
- </ Box >
40
- )
41
- }
56
+ const { trackEvent } = useTracking ( )
42
57
43
- const HomeHeroUnitSmall : React . FC < React . PropsWithChildren <
44
- HomeHeroUnitProps
45
- > > = ( { heroUnit, index, onClick } ) => {
46
- const imageUrl = heroUnit . image ?. imageURL
47
- const image = imageUrl && cropped ( imageUrl , { width : 500 , height : 333 } )
48
- const href = getInternalHref ( heroUnit . link . url )
58
+ const handleClick = ( ) => {
59
+ onClick ?.( )
60
+
61
+ const payload : ClickedHeroUnitGroup = {
62
+ action : ActionType . clickedHeroUnitGroup ,
63
+ context_module : "heroUnitsRail" ,
64
+ context_page_owner_type : OwnerType . home ,
65
+ destination_path : href ,
66
+ horizontal_slide_position : index ,
67
+ type : "thumbnail" ,
68
+ }
69
+
70
+ trackEvent ( payload )
71
+ }
49
72
50
73
return (
51
74
< RouterLink
52
- aria-label = { `${ heroUnit . title } - ${ heroUnit . body } ` }
75
+ aria-label = { `${ title } - ${ body } ` }
53
76
bg = "black5"
54
77
display = "block"
55
78
height = "100%"
56
- onClick = { onClick }
79
+ onClick = { handleClick }
57
80
textDecoration = "none"
58
81
to = { href }
59
82
width = "100%"
@@ -78,42 +101,66 @@ const HomeHeroUnitSmall: React.FC<React.PropsWithChildren<
78
101
79
102
< Box p = { 4 } >
80
103
< Text as = { index === 0 ? "h1" : "h2" } variant = "lg-display" lineClamp = { 3 } >
81
- { heroUnit . title }
104
+ { title }
82
105
</ Text >
83
106
84
107
< Spacer y = { 1 } />
85
108
86
109
< Text variant = "xs" color = "black60" lineClamp = { 4 } >
87
- { heroUnit . body }
110
+ { body }
88
111
</ Text >
89
112
90
113
< Spacer y = { 1 } />
91
114
92
- < Text variant = "xs" > { heroUnit . link . text } </ Text >
115
+ < Text variant = "xs" > { link . mobile . text } </ Text >
93
116
</ Box >
94
117
</ RouterLink >
95
118
)
96
119
}
97
120
98
- const HomeHeroUnitLarge : React . FC < React . PropsWithChildren <
99
- HomeHeroUnitProps
100
- > > = ( { heroUnit, index, onClick } ) => {
101
- const imageUrl = heroUnit . image ?. imageURL
102
- const image = imageUrl && cropped ( imageUrl , { width : 1270 , height : 500 } )
103
- const href = getInternalHref ( heroUnit . link . url )
104
-
121
+ const HomeHeroUnitBaseLarge : React . FC < HomeHeroUnitBaseProps > = ( {
122
+ title,
123
+ body,
124
+ imageUrl,
125
+ credit,
126
+ label,
127
+ link,
128
+ index,
129
+ onClick,
130
+ } ) => {
131
+ const image = imageUrl
132
+ ? cropped ( imageUrl , { width : 1270 , height : 500 } )
133
+ : null
134
+ const href = getInternalHref ( link . desktop . url )
105
135
const { theme } = useTheme ( )
106
136
107
137
const background =
108
138
theme . name === "light"
109
139
? "linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.1) 100%)"
110
140
: "linear-gradient(rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.1) 100%)"
111
141
142
+ const { trackEvent } = useTracking ( )
143
+
144
+ const handleClick = ( ) => {
145
+ onClick ?.( )
146
+
147
+ const payload : ClickedHeroUnitGroup = {
148
+ action : ActionType . clickedHeroUnitGroup ,
149
+ context_module : "heroUnitsRail" ,
150
+ context_page_owner_type : OwnerType . home ,
151
+ destination_path : href ,
152
+ horizontal_slide_position : index ,
153
+ type : "thumbnail" ,
154
+ }
155
+
156
+ trackEvent ( payload )
157
+ }
158
+
112
159
return (
113
160
< RouterLink
114
- aria-label = { `${ heroUnit . title } - ${ heroUnit . body } ` }
161
+ aria-label = { `${ title } - ${ body } ` }
115
162
display = "block"
116
- onClick = { onClick }
163
+ onClick = { handleClick }
117
164
textDecoration = "none"
118
165
to = { href }
119
166
>
@@ -128,13 +175,12 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
128
175
srcSet = { image . srcSet }
129
176
style = { { objectFit : "cover" } }
130
177
width = "100%"
131
- // LCP optimization
132
178
lazyLoad = { index > 0 }
133
179
fetchPriority = { index > 0 ? "auto" : "high" }
134
180
/>
135
181
) }
136
182
137
- { heroUnit . credit && (
183
+ { credit && (
138
184
< Box
139
185
position = "absolute"
140
186
bottom = { 0 }
@@ -145,7 +191,7 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
145
191
pt = { 6 }
146
192
background = { background }
147
193
>
148
- < HomeHeroUnitCredit > { heroUnit . credit } </ HomeHeroUnitCredit >
194
+ < HomeHeroUnitCredit > { credit } </ HomeHeroUnitCredit >
149
195
</ Box >
150
196
) }
151
197
</ Box >
@@ -161,10 +207,9 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
161
207
span = { 8 }
162
208
start = { 3 }
163
209
>
164
- { heroUnit . label && (
210
+ { label && (
165
211
< >
166
- < Text variant = "xs" > { heroUnit . label } </ Text >
167
-
212
+ < Text variant = "xs" > { label } </ Text >
168
213
< Spacer y = { 1 } />
169
214
</ >
170
215
) }
@@ -174,7 +219,7 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
174
219
lineClamp = { 3 }
175
220
variant = { [ "lg-display" , "xl" , "xl" ] }
176
221
>
177
- { heroUnit . title }
222
+ { title }
178
223
</ Text >
179
224
180
225
< Spacer y = { 2 } />
@@ -184,15 +229,15 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
184
229
lineClamp = { 4 }
185
230
variant = { [ "xs" , "sm-display" , "lg-display" ] }
186
231
>
187
- { heroUnit . body }
232
+ { body }
188
233
</ Text >
189
234
190
235
< Spacer y = { [ 2 , 2 , 4 ] } />
191
236
192
237
< GridColumns >
193
238
< Column span = { [ 12 , 12 , 6 ] } >
194
239
< Button variant = "secondaryBlack" width = "100%" tabIndex = { - 1 } >
195
- { heroUnit . link . text }
240
+ { link . desktop . text }
196
241
</ Button >
197
242
</ Column >
198
243
</ GridColumns >
@@ -204,6 +249,54 @@ const HomeHeroUnitLarge: React.FC<React.PropsWithChildren<
204
249
)
205
250
}
206
251
252
+ export const HomeHeroUnitBase : React . FC < HomeHeroUnitBaseProps > = props => {
253
+ return (
254
+ < Box width = "100%" height = "100%" >
255
+ < Media at = "xs" >
256
+ < HomeHeroUnitBaseSmall { ...props } />
257
+ </ Media >
258
+
259
+ < Media greaterThan = "xs" >
260
+ < HomeHeroUnitBaseLarge { ...props } />
261
+ </ Media >
262
+ </ Box >
263
+ )
264
+ }
265
+
266
+ interface HomeHeroUnitProps {
267
+ heroUnit : HomeHeroUnit_heroUnit$data
268
+ index : number
269
+ onClick ?: ( ) => void
270
+ }
271
+
272
+ export const HomeHeroUnit : React . FC < HomeHeroUnitProps > = ( {
273
+ heroUnit,
274
+ index,
275
+ onClick,
276
+ } ) => {
277
+ return (
278
+ < HomeHeroUnitBase
279
+ title = { heroUnit . title }
280
+ body = { heroUnit . body }
281
+ imageUrl = { heroUnit . image ?. imageURL }
282
+ credit = { heroUnit . credit }
283
+ label = { heroUnit . label }
284
+ link = { {
285
+ desktop : {
286
+ text : heroUnit . link . text ,
287
+ url : heroUnit . link . url ,
288
+ } ,
289
+ mobile : {
290
+ text : heroUnit . link . text ,
291
+ url : heroUnit . link . url ,
292
+ } ,
293
+ } }
294
+ index = { index }
295
+ onClick = { onClick }
296
+ />
297
+ )
298
+ }
299
+
207
300
export const HomeHeroUnitFragmentContainer = createFragmentContainer (
208
301
HomeHeroUnit ,
209
302
{
0 commit comments