-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathindex.js
More file actions
163 lines (150 loc) · 5.37 KB
/
index.js
File metadata and controls
163 lines (150 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React, { useRef, useEffect, useState } from "react";
import { Link } from "gatsby";
import {
Container,
ContentWrapper,
ImageWrapper,
ImageWrapperTwo,
SvgRandomWrapper,
} from "./style.js";
import cursor from "./images/cursor.svg";
import person1 from "./images/cursor-1.svg";
import person2 from "./images/cursor-2.svg";
import person3 from "./images/cursor-3.svg";
import person4 from "./images/cursor-4.svg";
import wave from "./images/wave.svg";
const Features = (props) => {
const containerRef = useRef(null);
const [waveStart, setWaveStart] = useState(false);
function getPerson(index) {
const persons = [person1, person2, person3, person4];
return persons[index];
}
useEffect(() => {
if (props.cursor !== undefined) {
const container = containerRef.current;
const moveRandomly = (element) => {
const rect = container.getBoundingClientRect();
const maxX = rect.width - element.clientWidth - 50;
const maxY = rect.height - element.clientHeight - 50;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * (maxY + 1));
element.style.transition = "transform 3s ease";
element.style.transform = `translate(${randomX}px, ${randomY}px)`;
setTimeout(() => {
element.style.transition = "";
}, 3000);
};
const setInitialRandomPosition = (element) => {
const rect = container.getBoundingClientRect();
const maxX = rect.width - element.clientWidth - 50;
const maxY = rect.height - element.clientHeight - 50;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * maxY);
element.style.transform = `translate(${randomX}px, ${randomY}px)`;
};
const person1Element = container.querySelector(".person1");
const person2Element = container.querySelector(".person2");
setInitialRandomPosition(person1Element);
setInitialRandomPosition(person2Element);
const movePersonsRandomly = () => {
moveRandomly(person1Element);
setTimeout(() => {
moveRandomly(person2Element);
}, 3000);
};
movePersonsRandomly();
const intervalId = setInterval(movePersonsRandomly, 6000);
return () => clearInterval(intervalId);
}
}, [props.cursor]);
function mouseEnterEvent() {
setWaveStart(true);
setTimeout(() => {
setWaveStart(false);
}, 1000);
}
function mouseLeaveEvent() {
setWaveStart(false);
}
const style = {
cursor: props.show_custom_cursor ? `url(${cursor}), auto` : "",
};
return (
<Container
style={style}
onMouseEnter={mouseEnterEvent}
onMouseLeave={mouseLeaveEvent}
>
<ContentWrapper>
<h2>{props.title}</h2>
<p className="text">{props.desc}</p>
{props.redirectLink ? <Link to={props.redirectLink}>Learn more →</Link>
: (<div className="small-card-container">
{props.redirectLinkWithImage.map((item) => (
<Link key={item.text} className="small-card" to={item.redirect}>
<img src={item.image} width={40} alt={item.alt} />
<span>{item.text}</span>
</Link>
))}
</div>)}
</ContentWrapper>
{props.animationOne ? (
<ImageWrapper ref={containerRef}>
<SvgRandomWrapper
className="person1"
style={{ display: props.cursor ? "none" : "" }}
>
{waveStart && (
<img
src={wave}
alt=""
aria-hidden="true"
style={{ position: "absolute" }}
className="waveAnimation"
/>
)}
<img src={getPerson(props.cursor * 2)} alt="" aria-hidden="true" />
</SvgRandomWrapper>
<SvgRandomWrapper
className="person2"
style={{ display: props.cursor ? "none" : "" }}
>
<img src={getPerson(props.cursor * 2 + 1)} alt="" aria-hidden="true" />
</SvgRandomWrapper>
<Link to={props.redirectLink ? props.redirectLink : props.redirectLinkWithImage[0].redirect}>
<img src={props.imgLink} alt={`${props.title || "Feature"} illustration`} />
</Link>
</ImageWrapper>
) : (
<ImageWrapperTwo ref={containerRef}>
<SvgRandomWrapper
className="person1"
style={{ display: props.cursor ? "none" : "" }}
>
{waveStart && (
<img
src={wave}
alt=""
aria-hidden="true"
style={{ position: "absolute" }}
className="waveAnimation"
/>
)}
<img src={getPerson(props.cursor * 2)} alt="" aria-hidden="true" />
</SvgRandomWrapper>
<SvgRandomWrapper
className="person2"
style={{ display: props.cursor ? "none" : "" }}
>
<img src={getPerson(props.cursor * 2 + 1)} alt="" aria-hidden="true" />
</SvgRandomWrapper>
<Link to={props.redirectLink ? props.redirectLink : props.redirectLinkWithImage[0].redirect}>
<img src={props.imgLink} alt={`${props.title || "Feature"} illustration`} />
</Link>
</ImageWrapperTwo>
)}
</Container>
);
};
export default Features;