summaryrefslogtreecommitdiff
path: root/components/Tweaks/Visual/ColorMenu.tsx
blob: a792f12c2e5aac77e96319eab5fa4e675f11ec8c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { ChevronDownIcon } from '@chakra-ui/icons'
import {
  Text,
  Box,
  Button,
  Flex,
  Menu,
  MenuButton,
  MenuItem,
  MenuList,
  Portal,
  PopoverTrigger,
  PopoverContent,
  Popover,
} from '@chakra-ui/react'
import React, { useCallback } from 'react'
import { initialVisuals } from '../../config'

export interface ColorMenuProps {
  label: string
  colorList: string[]
  value: string
  visValue: string
  setVisuals?: any
  noEmpty?: boolean
}

export const ColorMenu = (props: ColorMenuProps) => {
  const { label, colorList, value, visValue, setVisuals, noEmpty } = props

  const clickCallback = useCallback(
    (color) =>
      setVisuals((curr: typeof initialVisuals) => {
        return {
          ...curr,
          [value]: color,
        }
      }),
    [],
  )
  return (
    <Flex alignItems="center" justifyContent="space-between">
      <Text>{label}</Text>
      <Popover isLazy placement="right">
        <PopoverTrigger>
          <Button colorScheme="" color="black" rightIcon={<ChevronDownIcon />}>
            {<Box bgColor={visValue} borderRadius="sm" height={6} width={6}></Box>}
          </Button>
        </PopoverTrigger>
        <Portal>
          <PopoverContent zIndex="tooltip" maxW={36} position="relative">
            <Flex flexWrap="wrap" bgColor="gray.200">
              {!noEmpty && (
                <Box
                  onClick={() => clickCallback('')}
                  justifyContent="space-between"
                  alignItems="center"
                  display="flex"
                  m={1}
                >
                  <Box
                    height={6}
                    width={6}
                    borderColor="gray.600"
                    borderRadius="xl"
                    borderWidth={1}
                  ></Box>
                </Box>
              )}
              {colorList.map((color: string) => (
                <Box
                  m={1}
                  key={color}
                  onClick={() => clickCallback(color)}
                  justifyContent="space-between"
                  alignItems="center"
                  display="flex"
                >
                  <Box bgColor={color} borderRadius="xl" height={6} width={6}></Box>
                </Box>
              ))}
            </Flex>
          </PopoverContent>
        </Portal>
      </Popover>
    </Flex>
  )
}