@@ -10,38 +10,73 @@ import { cx } from "cva";
10
10
import { useState } from "react" ;
11
11
12
12
export default function Features ( props : FeaturesProps ) {
13
- const [ videoReplay , setVideoReplay ] = useState (
13
+ const [ interactionState , setInteractionState ] = useState (
14
14
props . features ?. reduce ( ( o , key ) => ( { ...o , [ key . _key ! ] : false } ) , { } ) ||
15
15
{ } ,
16
16
) ;
17
- const getSides = ( index : number ) => {
18
- return {
19
- right : true ,
20
- left : index === 1 || index === 3 || index === 4 ,
21
- bottom : index === 3 || index === 4 || index === 5 ,
22
- top : index === 1 || index === 2 || index === 3 ,
23
- } ;
24
- } ;
25
17
26
- const getMobileSides = ( index : number ) => {
27
- return {
28
- right : true ,
29
- left : true ,
30
- bottom : index === 5 ,
31
- top : true ,
32
- } ;
33
- } ;
18
+ const getSides = ( index : number ) => ( {
19
+ right : true ,
20
+ left : index === 1 || index === 3 || index === 4 ,
21
+ bottom : index === 3 || index === 4 || index === 5 ,
22
+ top : index === 1 || index === 2 || index === 3 ,
23
+ } ) ;
24
+
25
+ const getMobileSides = ( index : number ) => ( {
26
+ right : true ,
27
+ left : true ,
28
+ bottom : index === 5 ,
29
+ top : true ,
30
+ } ) ;
34
31
35
32
function handleInteraction ( _key : string ) {
36
- setVideoReplay ( ( prev ) => ( { ...prev , [ _key ] : true } ) ) ;
33
+ setInteractionState ( ( prev ) => ( { ...prev , [ _key ] : true } ) ) ;
37
34
setTimeout ( ( ) => {
38
- setVideoReplay ( ( prev ) => ( { ...prev , [ _key ] : false } ) ) ;
35
+ setInteractionState ( ( prev ) => ( { ...prev , [ _key ] : false } ) ) ;
39
36
} , 1000 ) ;
40
37
}
41
38
39
+ const renderBackground = (
40
+ background : any ,
41
+ replay : boolean ,
42
+ isDark : boolean ,
43
+ ) => {
44
+ if ( ! background ) return null ;
45
+
46
+ const version = isDark ? background . dark : background . light ;
47
+
48
+ if ( version ?. type === "video" && version . asset ) {
49
+ return (
50
+ < MuxVideo
51
+ replay = { replay }
52
+ playOnView
53
+ className = { isDark ? "hidden dark:block" : "dark:hidden" }
54
+ video = { version . asset }
55
+ />
56
+ ) ;
57
+ }
58
+
59
+ if ( version ?. type === "image" && version . image ) {
60
+ return (
61
+ < img
62
+ className = {
63
+ isDark
64
+ ? "hidden dark:block w-full h-auto"
65
+ : "dark:hidden w-full h-auto"
66
+ }
67
+ src = { version . image . asset ?. url }
68
+ alt = ""
69
+ />
70
+ ) ;
71
+ }
72
+
73
+ return null ;
74
+ } ;
75
+
42
76
return (
43
77
< >
44
- < div className = "hidden w-full px-6 py-[60px] lg:grid lg:grid-cols-2 lg:px-20 lg:py-[80px] " >
78
+ { /* Desktop */ }
79
+ < div className = "hidden w-full px-6 py-[60px] lg:grid lg:grid-cols-2 lg:px-20 lg:py-[80px]" >
45
80
{ props ?. features ?. map ( ( feature , index ) => {
46
81
const size = index === 2 ? "large" : "small" ;
47
82
return (
@@ -53,27 +88,21 @@ export default function Features(props: FeaturesProps) {
53
88
) }
54
89
>
55
90
< div
56
- className = { cx ( "absolute z-10" , {
91
+ className = { cx ( "absolute z-10" , {
57
92
"left-0 top-0 w-full" : size === "small" ,
58
93
"right-0 top-1/2 my-auto w-1/2 -translate-y-1/2 transform" :
59
94
size !== "small" ,
60
95
} ) }
61
96
>
62
- { feature . bgVideo ?. dark ?. asset && (
63
- < MuxVideo
64
- replay = { videoReplay [ feature . _key ! ] }
65
- playOnView
66
- className = "hidden dark:block"
67
- video = { feature . bgVideo ?. dark ?. asset }
68
- />
97
+ { renderBackground (
98
+ feature . background ,
99
+ interactionState [ feature . _key ! ] ,
100
+ true ,
69
101
) }
70
- { feature . bgVideo ?. light ?. asset && (
71
- < MuxVideo
72
- replay = { videoReplay [ feature . _key ! ] }
73
- playOnView
74
- className = "dark:hidden"
75
- video = { feature . bgVideo ?. light . asset }
76
- />
102
+ { renderBackground (
103
+ feature . background ,
104
+ interactionState [ feature . _key ! ] ,
105
+ false ,
77
106
) }
78
107
< div className = "absolute bottom-0 h-1/4 w-full bg-gradient-to-t from-white dark:from-background-dark" />
79
108
</ div >
@@ -84,7 +113,7 @@ export default function Features(props: FeaturesProps) {
84
113
>
85
114
< div
86
115
className = { cx (
87
- "flex h-[600px] flex-col items-start p-l lg:p-xl" ,
116
+ "flex h-[600px] flex-col items-start p-l lg:p-xl" ,
88
117
size === "small"
89
118
? "justify-end lg:h-[586px]"
90
119
: "max-w-[460px] justify-center lg:h-[590px]" ,
@@ -127,9 +156,9 @@ export default function Features(props: FeaturesProps) {
127
156
} ) }
128
157
</ div >
129
158
159
+ { /* Mobile */ }
130
160
< div className = "grid w-full grid-cols-2 px-6 py-[60px] lg:hidden lg:px-20 lg:py-[80px]" >
131
161
{ props ?. features ?. map ( ( feature , index ) => {
132
- // const { cleaned: size } = vercelStegaSplit(feature?.size || "");
133
162
return (
134
163
< div key = { feature . _key } className = { cx ( "col-span-2" ) } >
135
164
< GradientBorderBox
@@ -142,21 +171,15 @@ export default function Features(props: FeaturesProps) {
142
171
) }
143
172
>
144
173
< div className = { cx ( "-mt-l w-full sm:-mx-l" , { } ) } >
145
- { feature . bgVideo ?. dark ?. asset && (
146
- < MuxVideo
147
- replay = { videoReplay [ feature . _key ! ] }
148
- playOnView
149
- className = "hidden dark:block"
150
- video = { feature . bgVideo ?. dark ?. asset }
151
- />
174
+ { renderBackground (
175
+ feature . background ,
176
+ interactionState [ feature . _key ! ] ,
177
+ true ,
152
178
) }
153
- { feature . bgVideo ?. light ?. asset && (
154
- < MuxVideo
155
- replay = { videoReplay [ feature . _key ! ] }
156
- playOnView
157
- className = "dark:hidden"
158
- video = { feature . bgVideo ?. light . asset }
159
- />
179
+ { renderBackground (
180
+ feature . background ,
181
+ interactionState [ feature . _key ! ] ,
182
+ false ,
160
183
) }
161
184
</ div >
162
185
{ feature ?. tag ? (
0 commit comments