Skip to content

Commit

Permalink
feat(ColorPicker): add Palette icon to indicate clickableness
Browse files Browse the repository at this point in the history
  • Loading branch information
dovalid committed Jul 9, 2024
1 parent 4fdc5db commit 27b83fc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/[guild]/EditGuild/components/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import {
FormControl,
FormLabel,
HStack,
Icon,
Input,
useColorModeValue,
VStack,
} from "@chakra-ui/react"
import { Palette } from "@phosphor-icons/react"
import Color from "color"
import { useThemeContext } from "components/[guild]/ThemeContext"
import FormErrorMessage from "components/common/FormErrorMessage"
import useDebouncedState from "hooks/useDebouncedState"
import { useEffect } from "react"
import { useEffect, useState } from "react"
import { Controller, useFormContext, useWatch } from "react-hook-form"

type Props = {
Expand All @@ -23,6 +26,7 @@ const ColorPicker = ({ fieldName }: Props): JSX.Element => {
setValue,
formState: { errors },
} = useFormContext()
const [isIconLight, setIsIconLight] = useState(false)

const pickedColor = useWatch({ name: fieldName })
const debouncedPickedColor = useDebouncedState(pickedColor, 300)
Expand All @@ -32,6 +36,8 @@ const ColorPicker = ({ fieldName }: Props): JSX.Element => {
useEffect(() => {
if (!CSS.supports("color", debouncedPickedColor)) return
setLocalThemeColor(debouncedPickedColor)
const color = Color(pickedColor)
setIsIconLight(color.isDark())
}, [debouncedPickedColor, setLocalThemeColor])

const borderColor = useColorModeValue("gray.300", "whiteAlpha.300")
Expand Down Expand Up @@ -75,6 +81,12 @@ const ColorPicker = ({ fieldName }: Props): JSX.Element => {
/>
)}
/>
<Icon
as={Palette}
pos="absolute"
pointerEvents={"none"}
color={isIconLight ? "whiteAlpha.800" : "blackAlpha.800"}
/>
</Flex>
<Input
maxWidth={40}
Expand Down

0 comments on commit 27b83fc

Please sign in to comment.