|
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 | + }; |
3 | 20 |
|
4 |
| -function App() { |
5 | 21 | return (
|
6 | 22 | <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 | + }} |
17 | 97 | >
|
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> |
21 | 109 | </div>
|
22 | 110 | );
|
23 | 111 | }
|
24 |
| - |
25 |
| -export default App; |
|
0 commit comments