Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding different color code in colorPicker #192

Open
wants to merge 2 commits into
base: PROD
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions src/components/BrandSection/ColorCardBtn/ColorCardBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import React, { useState } from "react"
import classes from "./style.module.css"
import { Block } from "baseui/block"
import Icons from "~/components/Icons"
import BrandColorPicker from "../ColorPicker/BrandColorPicker"

const ColorCardBtn = ({ Width, Height, ColorCode, HandleOnClick }: any) => {
const ColorCardBtn = ({ ColorCode, index, handleDelete, handleEdit, type }: any) => {
const [isHover, setIsHover] = useState(false)
const [openPopup, setOpenPopup] = useState(false)
const [isEdit, setIsEdit] = useState(false)

const handleCloseEdit = () => {
setIsEdit(false)
}


return (
<Block className={classes.brandColorCardBtn}>
<span
Expand All @@ -17,15 +25,46 @@ const ColorCardBtn = ({ Width, Height, ColorCode, HandleOnClick }: any) => {
setOpenPopup(false)
}}
>
{isHover && <span className={classes.menuBtn} onClick={() => setOpenPopup(!openPopup)}><Icons.KebabMenu /></span>}
{isHover && (
<span className={classes.menuBtn} onClick={() => setOpenPopup(!openPopup)}>
<Icons.KebabMenu />
</span>
)}

{openPopup && <div className={classes.displayPopupOption}>
<span className={classes.popupOption}>Copy Color Code</span>
<span className={classes.popupOption}>Edit</span>
<span className={classes.popupOption}>Delete</span>
</div>}
{openPopup && (
<div className={classes.displayPopupOption}>
<span
onClick={() => {
navigator.clipboard.writeText(ColorCode)
setOpenPopup(false)
}}
className={classes.popupOption}
>
Copy Color Code
</span>
<span onClick={() => setIsEdit(!isEdit)} className={classes.popupOption}>Edit</span>
<span
onClick={() => {
handleDelete(index)
setOpenPopup(false)
}}
className={classes.popupOption}
>
Delete
</span>
</div>
)}
</span>
<h4 className={classes.ColorHashCode}>{ColorCode ? ColorCode.toUpperCase() : "#F259E8"}</h4>

{isEdit && <div
id={`popup`}
onMouseLeave={() => setIsEdit(false)}
style={{ position: "absolute", top: "-13rem", left: "136px", zIndex: "1" }}
>
<BrandColorPicker index={index} handleAddColor={handleEdit} close={handleCloseEdit} type={type} />
</div>}

</Block>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/BrandSection/ColorCardBtn/style.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.brandColorCardBtn {
position: relative;
width: 120px;
height: 120px;
display: flex;
Expand Down
193 changes: 159 additions & 34 deletions src/components/BrandSection/ColorPicker/BrandColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import { Block } from "baseui/block"
import { useState } from "react"
import classes from "./style.module.css"
import { RgbaColorPicker } from "react-colorful"
import { throttle } from "lodash"
import { RgbaColorPicker, HslaColorPicker } from "react-colorful"
import { Button } from "baseui/button"
import Icons from "~/components/Icons"
import { rgbaTohex } from "~/utils/colorConverter"

const BrandColorPicker = ({ isOpen, handleClose, inputColor, handleChangeColor }: any) => {
const [color, setColor] = useState(inputColor)
const BrandColorPicker = ({ type, handleAddColor, close, index }: any) => {
const [color, setColor] = useState({ r: 0, g: 0, b: 0, a: 1 })
const [hexColor, setHexColor] = useState("#000000")
const [opacity, setOpacity] = useState('100%')
const close = () => {
handleClose()
const [hslaColor, setHslaColor] = useState({ h: 270, s: 0, l: 0, a: 1 })
const [opacity, setOpacity] = useState("100%")
const [selectedColorFormat, setSelectedColorFormat] = useState("Hex")

const handleColorFormatChange = (event: any) => {
setSelectedColorFormat(event.target.value)
}
const updateObjectFill = throttle((color: string) => {
handleChangeColor(color)
setColor(color)
close()
}, 1000)

function rgba2hex() {
var hex = '#' +
(parseInt(`${color?.r}`, 10) | (1 << 8)).toString(16).slice(1) +
(parseInt(`${color?.g}`, 10) | (1 << 8)).toString(16).slice(1) +
(parseInt(`${color?.b}`, 10) | (1 << 8)).toString(16).slice(1)

const rgba2hex = async () => {
var hex = rgbaTohex(color.r, color.g, color.b, color.a)
setHexColor(hex)
setOpacity(`${Math.round(color?.a * 100)}%`)
}
Expand All @@ -46,13 +41,19 @@ const BrandColorPicker = ({ isOpen, handleClose, inputColor, handleChangeColor }
<div className={classes.modal}>
<Block className={classes.colorPickerSection}>
<div className="brand-hex-color-picker">
{
{(selectedColorFormat === 'Hex' || selectedColorFormat === 'Rgba' || selectedColorFormat === 'Css') ?
<RgbaColorPicker
onChange={(color) => {
setColor(color)
rgba2hex()
}}
/>
:
<HslaColorPicker
onChange={(hslaColor: any) => {
setHslaColor(hslaColor)
}}
/>
}
</div>
<span style={{ position: "absolute", marginTop: "-30px" }}>
Expand All @@ -61,30 +62,154 @@ const BrandColorPicker = ({ isOpen, handleClose, inputColor, handleChangeColor }

<div className={classes.colorValuesInput}>
<div className={classes.selectColorCodeCon}>
<select id="colorFormat" className={classes.selectColorCont}>
<option value="Hex">Hex</option>
<option value="Hex">Hex</option>
<select id="colorFormat" className={classes.selectColorCont} onChange={handleColorFormatChange}>
<option value="Hex">HEX</option>
<option value="Rgba">RGB</option>
<option value="Hsla">HSL</option>
<option value="Css">CSS</option>
</select>
<div className={classes.selectDownArrow}>
<Icons.DownArrow width="10px" height="10px" color="#696974" />
</div>
</div>

<div className={classes.inputPercentage}>
<input
className={classes.colorPickerInputField}
onChange={(e) => {
setColor(e.target.value)
}}
value={hexColor}
/>
<input className={classes.colorPercentageInputField} value={opacity} />
</div>
{selectedColorFormat === "Hex" && (
<div className={classes.inputPercentage}>
<input
className={classes.colorPickerInputField}
onChange={(e) => {
setHexColor(e.target.value)
}}
value={hexColor}
/>

<input className={classes.colorPercentageInputField} value={opacity} />
</div>
)}

{selectedColorFormat === "Rgba" && (
<Block className={classes.multiValueInputFieldsCon}>
<div className={classes.valueContainer}>
<label>R</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="255"
value={color?.r}
// onChange={(e) => setColor((prev) => ({ ...prev, r: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>G</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="255"
value={color?.g}
// onChange={(e) => setColor((prev) => ({ ...prev, g: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>B</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="255"
value={color?.b}
// onChange={(e) => setColor((prev) => ({ ...prev, b: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>A</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="255"
value={color?.a}
// onChange={(e) => setColor((prev) => ({ ...prev, a: e.target.value }))}
/>
</div>
</Block>
)}

{selectedColorFormat === "Hsla" && (
<Block className={classes.multiValueInputFieldsCon}>
<div className={classes.valueContainer}>
<label>H</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="360"
value={hslaColor.h}
// onChange={(e) => setHslaColor((prev) => ({ ...prev, h: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>S</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="360"
value={hslaColor.s}
// onChange={(e) => setHslaColor((prev) => ({ ...prev, s: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>L</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="360"
value={hslaColor.l}
// onChange={(e) => setHslaColor((prev) => ({ ...prev, l: e.target.value }))}
/>
</div>

<div className={classes.valueContainer}>
<label>A</label>
<input
className={classes.colorSingleValInput}
type="number"
id="red-input"
min="0"
max="360"
value={hslaColor.a}
// onChange={(e) => setHslaColor((prev) => ({ ...prev, a: e.target.value }))}
/>
</div>
</Block>
)}

{selectedColorFormat === "Css" &&
<input className={classes.cssInput} value={`rgba(${color.r} ${color.g} ${color.b} ${color.a})`} />
}
</div>

<Block className="w-100 mt-3" style={{ height: '38px' }}>
<Block className="w-100 mt-3" style={{ height: "38px" }}>
<Button
onClick={() => updateObjectFill(color)}
onClick={() => {
handleAddColor(index, hexColor, type)
close()
}}
$colors={{ backgroundColor: "#6729F3", color: "#fff" }}
className="w-100 h-100 p-5 mt-5 d-inline-block"
>
Expand Down
30 changes: 29 additions & 1 deletion src/components/BrandSection/ColorPicker/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ select {
display: flex;
position: absolute;
top: 0;
right: 14px;
right: 8px;
align-items: center;
/* justify-content: center; */
height: 100%;
Expand Down Expand Up @@ -158,3 +158,31 @@ select {
cursor: pointer;
border-radius: 4px;
}
.multiValueInputFieldsCon {
display: flex;
gap: 8px;
}
.valueContainer {
display: flex;
gap: 4px;
justify-content: center;
align-items: center;
}

.colorSingleValInput {
display: flex;
border: 1px solid black;
max-width: 36px;
text-align: center;
padding: 4px 0 4px;
outline: none;
border-radius: 5px;
}
.cssInput {
width: 70%;
padding: 0.5rem;
background-color: transparent;
border-radius: 8px;
border: 1px solid black;
outline: none;
}
Loading