Skip to content

Commit 846a610

Browse files
add: gradient type
1 parent c6508f5 commit 846a610

File tree

3 files changed

+127
-51
lines changed

3 files changed

+127
-51
lines changed

β€Žsrc/App.cssβ€Ž

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
.App {
2-
text-align: center;
1+
* {
2+
font-family: sans-serif;
3+
margin: 1.5px;
4+
padding: 1.5px;
5+
border-radius: 5px;
6+
border: 1px solid rosybrown;
37
}
4-
5-
.App-logo {
6-
height: 40vmin;
7-
pointer-events: none;
8-
}
9-
10-
@media (prefers-reduced-motion: no-preference) {
11-
.App-logo {
12-
animation: App-logo-spin infinite 20s linear;
13-
}
8+
button{
9+
background: linear-gradient(to right, #fff700 , #ff0000);
1410
}
15-
16-
.App-header {
17-
background-color: #282c34;
18-
min-height: 100vh;
19-
display: flex;
20-
flex-direction: column;
21-
align-items: center;
22-
justify-content: center;
23-
font-size: calc(10px + 2vmin);
24-
color: white;
11+
input{
12+
width: 100px;
13+
min-width: 100%;
14+
min-height: 50%;
15+
margin-left: 0;
16+
background: linear-gradient(to left,blanchedalmond, palegoldenrod, palevioletred);
17+
margin-bottom: 10px;
2518
}
26-
27-
.App-link {
28-
color: #61dafb;
19+
body{
20+
background: rgb(131,58,180);
21+
background: linear-gradient(90deg, rgba(131,58,180,1) 0%, rgba(253,29,29,1) 50%, rgba(252,176,69,1) 100%);
2922
}
3023

31-
@keyframes App-logo-spin {
32-
from {
33-
transform: rotate(0deg);
34-
}
35-
to {
36-
transform: rotate(360deg);
37-
}
38-
}
24+
.color{
25+
display: flex;
26+
justify-content: space-between;
27+
}

β€Žsrc/App.jsβ€Ž

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,111 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import "./App.css";
2+
import { useState } from "react";
3+
export default function App() {
4+
const [leftColor, setLeftColor] = useState("#fff700");
5+
const [rightColor, setRightColor] = useState("#ff0000");
6+
7+
const [radialGradient, setRadialGradient] = useState(
8+
`radial-gradient(${leftColor} , ${rightColor})`
9+
);
10+
const [linearGradient, setLinearGradient] = useState(
11+
`linear-gradient(to right , ${leftColor} , ${rightColor})`
12+
);
13+
const [gradientType, setGradientType] = useState("radial");
14+
15+
const copyCode = () => {
16+
navigator.clipboard.writeText(
17+
`linear-gradient(to right, ${leftColor} , ${rightColor})`
18+
);
19+
};
320

4-
function App() {
521
return (
622
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
23+
<div
24+
className="container"
25+
style={{
26+
background:
27+
gradientType === "radial" ? radialGradient : linearGradient,
28+
height: "90vh",
29+
display: "flex",
30+
justifyContent: "space-around",
31+
alignItems: "center",
32+
}}
33+
>
34+
<div className="left-color">
35+
<input
36+
value={leftColor}
37+
onChange={(event) => {
38+
console.log(event.target.value);
39+
setLeftColor(event.target.value);
40+
setLinearGradient(
41+
`linear-gradient(to right, ${leftColor} , ${rightColor})`
42+
);
43+
setRadialGradient(
44+
`raidal-gradient(${leftColor} , ${rightColor})`
45+
);
46+
}}
47+
type="color"
48+
/>
49+
<div className="color" style={{ backgroundColor: "white" }}>
50+
<span>{leftColor}</span>
51+
<button
52+
onClick={() => {
53+
navigator.clipboard.writeText(leftColor);
54+
}}
55+
class="clip"
56+
>
57+
πŸ“‹
58+
</button>
59+
</div>
60+
</div>
61+
62+
<div className="right-color">
63+
<input
64+
value={rightColor}
65+
onChange={(event) => {
66+
setRightColor(event.target.value);
67+
setLinearGradient(
68+
`linear-gradient(to right, ${leftColor} , ${rightColor})`
69+
);
70+
setRadialGradient(
71+
`raidal-gradient(${leftColor} , ${rightColor})`
72+
);
73+
}}
74+
type="color"
75+
/>
76+
77+
<div className="color" style={{ backgroundColor: "white" }}>
78+
{" "}
79+
<span>{rightColor}</span>
80+
<button
81+
onClick={() => {
82+
navigator.clipboard.writeText(rightColor);
83+
}}
84+
class="clip"
85+
>
86+
πŸ“‹
87+
</button>{" "}
88+
</div>
89+
</div>
90+
</div>
91+
92+
<div style={{ textAlign: "center" }} className="panel">
93+
<button
94+
onClick={() => {
95+
setGradientType("linear");
96+
}}
1797
>
18-
Learn React
19-
</a>
20-
</header>
98+
Linear Gradient
99+
</button>
100+
<button onClick={copyCode}> Copy Gradient code </button>
101+
<button
102+
onClick={() => {
103+
setGradientType("radial");
104+
}}
105+
>
106+
Radial Gradient
107+
</button>
108+
</div>
21109
</div>
22110
);
23111
}
24-
25-
export default App;

β€Žsrc/index.cssβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ code {
1111
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1212
monospace;
1313
}
14+

0 commit comments

Comments
Β (0)