diff --git a/src/components/BrandSection/ColorCardBtn/ColorCardBtn.tsx b/src/components/BrandSection/ColorCardBtn/ColorCardBtn.tsx index 9b613545..321787b9 100644 --- a/src/components/BrandSection/ColorCardBtn/ColorCardBtn.tsx +++ b/src/components/BrandSection/ColorCardBtn/ColorCardBtn.tsx @@ -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 ( { setOpenPopup(false) }} > - {isHover && setOpenPopup(!openPopup)}>} + {isHover && ( + setOpenPopup(!openPopup)}> + + + )} - {openPopup &&
- Copy Color Code - Edit - Delete -
} + {openPopup && ( +
+ { + navigator.clipboard.writeText(ColorCode) + setOpenPopup(false) + }} + className={classes.popupOption} + > + Copy Color Code + + setIsEdit(!isEdit)} className={classes.popupOption}>Edit + { + handleDelete(index) + setOpenPopup(false) + }} + className={classes.popupOption} + > + Delete + +
+ )}

{ColorCode ? ColorCode.toUpperCase() : "#F259E8"}

+ + {isEdit &&
setIsEdit(false)} + style={{ position: "absolute", top: "-13rem", left: "136px", zIndex: "1" }} + > + +
} +
) } diff --git a/src/components/BrandSection/ColorCardBtn/style.module.css b/src/components/BrandSection/ColorCardBtn/style.module.css index 102ef6ec..ce75ab41 100644 --- a/src/components/BrandSection/ColorCardBtn/style.module.css +++ b/src/components/BrandSection/ColorCardBtn/style.module.css @@ -1,4 +1,5 @@ .brandColorCardBtn { + position: relative; width: 120px; height: 120px; display: flex; diff --git a/src/components/BrandSection/ColorPicker/BrandColorPicker.tsx b/src/components/BrandSection/ColorPicker/BrandColorPicker.tsx index 77cb9507..85fe116e 100644 --- a/src/components/BrandSection/ColorPicker/BrandColorPicker.tsx +++ b/src/components/BrandSection/ColorPicker/BrandColorPicker.tsx @@ -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)}%`) } @@ -46,13 +41,19 @@ const BrandColorPicker = ({ isOpen, handleClose, inputColor, handleChangeColor }
- { + {(selectedColorFormat === 'Hex' || selectedColorFormat === 'Rgba' || selectedColorFormat === 'Css') ? { setColor(color) rgba2hex() }} /> + : + { + setHslaColor(hslaColor) + }} + /> }
@@ -61,30 +62,154 @@ const BrandColorPicker = ({ isOpen, handleClose, inputColor, handleChangeColor }
- + + + +
-
- { - setColor(e.target.value) - }} - value={hexColor} - /> - -
+ {selectedColorFormat === "Hex" && ( +
+ { + setHexColor(e.target.value) + }} + value={hexColor} + /> + + +
+ )} + + {selectedColorFormat === "Rgba" && ( + +
+ + setColor((prev) => ({ ...prev, r: e.target.value }))} + /> +
+ +
+ + setColor((prev) => ({ ...prev, g: e.target.value }))} + /> +
+ +
+ + setColor((prev) => ({ ...prev, b: e.target.value }))} + /> +
+ +
+ + setColor((prev) => ({ ...prev, a: e.target.value }))} + /> +
+
+ )} + + {selectedColorFormat === "Hsla" && ( + +
+ + setHslaColor((prev) => ({ ...prev, h: e.target.value }))} + /> +
+ +
+ + setHslaColor((prev) => ({ ...prev, s: e.target.value }))} + /> +
+ +
+ + setHslaColor((prev) => ({ ...prev, l: e.target.value }))} + /> +
+ +
+ + setHslaColor((prev) => ({ ...prev, a: e.target.value }))} + /> +
+
+ )} + + {selectedColorFormat === "Css" && + + }
- +