Last active
November 24, 2019 16:42
-
-
Save ac205/ef6ccb59fa7912c28af27be578b4bcc4 to your computer and use it in GitHub Desktop.
RBG Color Changer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.outsideContainer { | |
height: 90vh; | |
padding: 5vh; | |
margin: auto; | |
} | |
.container { | |
background: rgb(248, 248, 248); | |
width: 50%; | |
margin: auto; | |
text-align: center; | |
box-shadow: 2px 2px 5px black; | |
border-radius: 10px; | |
font-family: Cambria, Cochin, Georgia, Times, "Times New Roman", serif; | |
padding: 20px; | |
} | |
.colorOutput { | |
padding: 50px; | |
box-shadow: 2px 2px 5px black; | |
border-radius: 10px; | |
width: 2.5em; | |
height: 2.5em; | |
margin: auto; | |
} | |
input[type="text"] { | |
background: none; | |
height: 1.5em; | |
font-family: Cambria, Cochin, Georgia, Times, "Times New Roman", serif; | |
} | |
.icon { | |
font-size: 1.5em; | |
margin: 5px; | |
} | |
.slidecontainer { | |
width: 75%; | |
margin: 10px auto; | |
} | |
.slider { | |
-webkit-appearance: none; | |
width: 100%; | |
height: 25px; | |
background: #d3d3d3; | |
outline: none; | |
opacity: 0.7; | |
-webkit-transition: 0.2s; | |
transition: opacity 0.2s; | |
border-radius: 10px; | |
} | |
.slider:hover { | |
opacity: 1; | |
} | |
.slider::-webkit-slider-thumb { | |
-webkit-appearance: none; | |
appearance: none; | |
width: 25px; | |
height: 25px; | |
background: black; | |
cursor: pointer; | |
border-radius: 10px; | |
} | |
.slider::-moz-range-thumb { | |
width: 25px; | |
height: 25px; | |
background: black; | |
cursor: pointer; | |
border-radius: 10px; | |
} | |
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) { | |
.container { | |
width: 80%; | |
height: 80%; | |
} | |
} | |
@media only screen and (max-width: 500px) { | |
.container { | |
width: 80%; | |
height: 80%; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import "./App.css"; | |
function App() { | |
const [copied, setCopied] = useState(false); | |
const [colors, setColors] = useState({ | |
color1: 0, | |
color2: 0, | |
color3: 255 | |
}); | |
const currentColor = { | |
background: | |
"rgb(" + | |
colors.color1 + | |
", " + | |
colors.color2 + | |
", " + | |
colors.color3 + | |
" )" | |
}; | |
const fontColor = { | |
color: | |
"rgb(" + | |
colors.color1 + | |
", " + | |
colors.color2 + | |
", " + | |
colors.color3 + | |
" )" | |
}; | |
const handleSlider = e => { | |
setCopied(false); | |
const { value, id } = e.target; | |
setColors({ ...colors, [id]: value }); | |
}; | |
const copyColor = () => { | |
var copyText = document.getElementById("colorCopy"); | |
copyText.select(); | |
copyText.setSelectionRange(0, 99999); | |
document.execCommand("copy"); | |
setCopied(true); | |
}; | |
const rgbToHex = rgb => { | |
let hex = Number(rgb).toString(16); | |
if (hex.length < 2) { | |
hex = "0" + hex; | |
} | |
return hex; | |
}; | |
const fullColorHex = (r, g, b) => { | |
let red = rgbToHex(r); | |
let green = rgbToHex(g); | |
let blue = rgbToHex(b); | |
return red + green + blue; | |
}; | |
return ( | |
<div className="outsideContainer" style={currentColor}> | |
<div className="container"> | |
<h2 style={fontColor}>RGB Color Chooser</h2> | |
<div className="colorOutput" style={currentColor} /> | |
{copied ? ( | |
<h6 id="copied">Color Copied to Clipboard</h6> | |
) : ( | |
<h6 id="copied">Select Color</h6> | |
)} | |
<input | |
id="colorCopy" | |
type="text" | |
value={"#"+ fullColorHex(colors.color1, colors.color2, colors.color3)} | |
/> | |
<i | |
className="fa fa-copy icon" | |
onClick={copyColor} | |
style={fontColor} | |
/> | |
<br /> | |
<input | |
id="colorCopy" | |
type="text" | |
value={currentColor.background} | |
/> | |
<i | |
className="fa fa-copy icon" | |
onClick={copyColor} | |
style={fontColor} | |
/> | |
<div className="slidecontainer"> | |
R | |
<input | |
type="range" | |
min="0" | |
max="255" | |
className="slider" | |
id="color1" | |
onChange={handleSlider} | |
value={colors.color1} | |
/> | |
G | |
<input | |
type="range" | |
min="0" | |
max="255" | |
className="slider" | |
id="color2" | |
onChange={handleSlider} | |
value={colors.color2} | |
/> | |
B | |
<input | |
type="range" | |
min="0" | |
max="255" | |
className="slider" | |
id="color3" | |
onChange={handleSlider} | |
value={colors.color3} | |
/> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" rel="stylesheet" > | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="theme-color" content="#000000" /> | |
<meta | |
name="description" | |
content="Web site created using create-react-app" | |
/> | |
<link rel="apple-touch-icon" href="logo192.png" /> | |
<!-- | |
manifest.json provides metadata used when your web app is installed on a | |
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | |
--> | |
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | |
<!-- | |
Notice the use of %PUBLIC_URL% in the tags above. | |
It will be replaced with the URL of the `public` folder during the build. | |
Only files inside the `public` folder can be referenced from the HTML. | |
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | |
work correctly both with client-side routing and a non-root public URL. | |
Learn how to configure a non-root public URL by running `npm run build`. | |
--> | |
<title>React App</title> | |
</head> | |
<body> | |
<noscript>You need to enable JavaScript to run this app.</noscript> | |
<div id="root"></div> | |
<!-- | |
This HTML file is a template. | |
If you open it directly in the browser, you will see an empty page. | |
You can add webfonts, meta tags, or analytics to this file. | |
The build step will place the bundled scripts into the <body> tag. | |
To begin the development, run `npm start` or `yarn start`. | |
To create a production bundle, use `npm run build` or `yarn build`. | |
--> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment