Skip to content

Commit

Permalink
On-hover will show hexcode
Browse files Browse the repository at this point in the history
  • Loading branch information
cksharma11 committed Jan 21, 2021
1 parent d7f11fc commit 77df33a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/components/ColorBox/ColorBox.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import React, { useState } from "react";
import Clipboard from "react-clipboard.js";
import React, { useState } from 'react';
import Clipboard from 'react-clipboard.js';

const ColorBox = ({ hexCode, colorName }) => {
const [status, setStatus] = useState(colorName);
const [activeClass, setActiveClass] = useState('div-colorbox');
const setCopySuccess = () => {
setStatus("Copied");
setStatus('Copied');
setActiveClass('copied');
setTimeout(() => {
setStatus(colorName);
setActiveClass('div-colorbox');
}, 1000);
};

return (
<Clipboard
data-clipboard-text={hexCode}
style={{ background: "none", border: "none", fontFamily: "inherit" }}
style={{ background: 'none', border: 'none', fontFamily: 'inherit' }}
>
<div
id={hexCode}
className="div-colorbox"
className={activeClass}
data-hover={hexCode}
style={{ background: `${hexCode}` }}
onClick={setCopySuccess}
>
Expand Down
25 changes: 23 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ html,
body {
padding: 0;
margin: 0;
font-family: "Cinzel", serif;
font-family: 'Cinzel', serif;
}

.div-header {
Expand Down Expand Up @@ -31,7 +31,8 @@ body {
background: white;
}

.div-colorbox {
.div-colorbox,
.copied {
width: 250px;
height: 180px;
display: flex;
Expand All @@ -49,6 +50,20 @@ body {
transition: transform 0.1s;
transform: scale(1.1);
box-shadow: 0px 0px 10px gray;
font-size: 0;
}

.copied:hover {
cursor: pointer;
transition: transform 0.1s;
transform: scale(1.1);
box-shadow: 0px 0px 10px gray;
font-size: 20px;
}

.div-colorbox:hover:before {
font-size: 20px;
content: attr(data-hover);
}

.div-color-container {
Expand All @@ -71,3 +86,9 @@ body {
button:focus {
outline: none;
}

.color-box {
background: 'none';
border: 'none';
font-family: 'inherit';
}

0 comments on commit 77df33a

Please sign in to comment.