-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switch.js
44 lines (42 loc) · 1.2 KB
/
Switch.js
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
import React, { useState } from "react";
export const Switch = ({
primaryBackground = "orange",
secondaryBackground = "green",
primaryDotColour = "#fff",
secondaryDotColour = "#fff",
width = "100px",
vertical = "false",
height = "40px",
}) => {
const [toggled, setToggled] = useState(false);
return (
<div style={{transform: vertical ? "" : "rotate(90deg)" , display:"inline-block" }}>
<div
onClick={() => setToggled(!toggled)}
style={{
width: width,
color: "#fff",
height: height,
background: toggled ? secondaryBackground : primaryBackground,
borderRadius: "30px",
position: "relative",
}}
>
<div
style={{
background: "#fff",
width: "30px",
height: "30px",
backgroundColor: toggled ? primaryDotColour : secondaryDotColour,
borderRadius: "100%",
position: "absolute",
top: "5px",
left: "5px",
transition: "0.5s all ease",
transform: toggled ? "translateX(60px)" : "",
}}
></div>
</div>
</div>
);
};