From c8f33e8e6977ba3c39fae3bf04eac1797631a44d Mon Sep 17 00:00:00 2001 From: nflnkr Date: Mon, 3 Jun 2024 17:20:27 +0300 Subject: [PATCH] replace native colorpicker with custom --- package.json | 1 + src/ui_kit/CircleColorPicker.tsx | 65 ++++++++++++++++++-------------- yarn.lock | 5 +++ 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index f95c8746..e3b42b47 100755 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "notistack": "^3.0.1", "react": "^18.2.0", "react-beautiful-dnd": "^13.1.1", + "react-colorful": "^5.6.1", "react-cytoscapejs": "^2.0.0", "react-dnd": "^16.0.1", "react-dnd-html5-backend": "^16.0.1", diff --git a/src/ui_kit/CircleColorPicker.tsx b/src/ui_kit/CircleColorPicker.tsx index 770d9bb0..6d7a7e2e 100644 --- a/src/ui_kit/CircleColorPicker.tsx +++ b/src/ui_kit/CircleColorPicker.tsx @@ -1,5 +1,6 @@ -import { ButtonBase } from "@mui/material"; -import { startTransition, useRef } from "react"; +import { ButtonBase, Popover } from "@mui/material"; +import { startTransition, useState } from "react"; +import { HexAlphaColorPicker } from "react-colorful"; interface Props { color: string; @@ -7,35 +8,43 @@ interface Props { } export default function CircleColorPicker({ color, onChange }: Props) { - const inputRef = useRef(null); + const [anchorEl, setAnchorEl] = useState(null); return ( - inputRef.current?.click()} - sx={{ - aspectRatio: 1, - height: "22px", - width: "22px", - minWidth: "22px", - borderRadius: "50%", - backgroundColor: color, - border: "1px solid #4D4D4D", - }} - > - { - startTransition(() => { - onChange(e.target.value); - }); - }} - style={{ - opacity: 0, - cursor: "pointer", + <> + setAnchorEl(event.currentTarget)} + sx={{ + aspectRatio: 1, + height: "22px", + width: "22px", + minWidth: "22px", + borderRadius: "50%", + backgroundColor: color, + border: "1px solid #4D4D4D", }} /> - + setAnchorEl(null)} + anchorOrigin={{ + vertical: "bottom", + horizontal: "right", + }} + slotProps={{ + paper: { + sx: { + p: "20px", + }, + style: { + backgroundColor: color, + }, + }, + }} + > + startTransition(() => onChange(color))} /> + + ); } diff --git a/yarn.lock b/yarn.lock index 4425f12f..a1d8c20a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9486,6 +9486,11 @@ react-beautiful-dnd@^13.1.1: redux "^4.0.4" use-memo-one "^1.1.1" +react-colorful@^5.6.1: + version "5.6.1" + resolved "https://registry.yarnpkg.com/react-colorful/-/react-colorful-5.6.1.tgz#7dc2aed2d7c72fac89694e834d179e32f3da563b" + integrity sha512-1exovf0uGTGyq5mXQT0zgQ80uvj2PCwvF8zY1RN9/vbJVSjSo3fsB/4L3ObbF7u70NduSiK4xu4Y6q1MHoUGEw== + react-cytoscapejs@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/react-cytoscapejs/-/react-cytoscapejs-2.0.0.tgz#fdc2547626df0678acfbb48e73a437ddc1687b01"