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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
import { ArrowRightIcon, ChevronDownIcon, RepeatIcon } from '@chakra-ui/icons'
import {
Text,
Box,
Flex,
IconButton,
StackDivider,
Tooltip,
VStack,
MenuButton,
Menu,
Portal,
MenuList,
MenuOptionGroup,
MenuItemOption,
Button,
MenuItem,
} from '@chakra-ui/react'
import React from 'react'
import { ColorMenu } from './ColorMenu'
import { colorList, initialVisuals } from './config'
export interface ColorsPanelProps {
visuals: typeof initialVisuals
setVisualsCallback: any
highlightColor: string
setHighlightColor: any
}
export const ColorsPanel = (props: ColorsPanelProps) => {
const { visuals, setVisualsCallback, highlightColor, setHighlightColor } = props
return (
<VStack
spacing={2}
justifyContent="flex-start"
divider={<StackDivider borderColor="gray.500" />}
align="stretch"
color="gray.800"
>
<Box>
<Flex alignItems="center" justifyContent="space-between">
<Text>Nodes</Text>
<Tooltip label="Shuffle node colors">
<IconButton
aria-label="Shuffle node colors"
size="sm"
icon={<RepeatIcon />}
variant="ghost"
onClick={() => {
const arr = visuals.nodeColorScheme ?? []
setVisualsCallback({
...visuals,
//shuffle that guy
//definitely thought of this myself
nodeColorScheme: arr
.map((x: any) => [Math.random(), x])
.sort(([a], [b]) => a - b)
.map(([_, x]) => x),
})
}}
/>
</Tooltip>
<Tooltip label="Cycle node colors">
<IconButton
aria-label="Shift node colors"
icon={<ArrowRightIcon />}
size="sm"
variant="ghost"
onClick={() => {
const arr = visuals.nodeColorScheme ?? []
setVisualsCallback({
...visuals,
nodeColorScheme: [...arr.slice(1, arr.length), arr[0]],
})
}}
/>
</Tooltip>
<Menu isLazy placement="right" closeOnSelect={false} matchWidth>
<MenuButton
width={20}
as={Button}
colorScheme=""
color="black"
rightIcon={<ChevronDownIcon />}
>
<Flex height={6} width={6} flexDirection="column" flexWrap="wrap">
{visuals.nodeColorScheme.map((color) => (
<Box key={color} bgColor={color} flex="1 1 8px" borderRadius="2xl"></Box>
))}
</Flex>
</MenuButton>
<Portal>
{' '}
<MenuList minW={10} zIndex="popover" bgColor="gray.200">
<MenuOptionGroup
width={500}
type="checkbox"
defaultValue={visuals.nodeColorScheme}
onChange={(colors) => {
if (!colors.length) {
return
}
setVisualsCallback({ ...visuals, nodeColorScheme: colors })
}}
>
{colorList.map((color) => (
<MenuItemOption
key={color}
isChecked={visuals.nodeColorScheme.some((c) => c === color)}
value={color}
isDisabled={
visuals.nodeColorScheme.length === 1 && visuals.nodeColorScheme[0] === color
}
>
<Box justifyContent="space-between" alignItems="center" display="flex">
<Box bgColor={color} borderRadius="sm" height={6} width={6}></Box>
</Box>
</MenuItemOption>
))}
</MenuOptionGroup>
</MenuList>
</Portal>
</Menu>
</Flex>
<Flex alignItems="center" justifyContent="space-between">
<Text>Links</Text>
<Menu isLazy placement="right">
<MenuButton as={Button} colorScheme="" color="black" rightIcon={<ChevronDownIcon />}>
<Box>
{visuals.linkColorScheme ? (
<Box
bgColor={visuals.linkColorScheme}
borderRadius="sm"
height={6}
width={6}
></Box>
) : (
<Flex height={6} width={6} flexDirection="column" flexWrap="wrap">
{visuals.nodeColorScheme.map((color) => (
<Box key={color} bgColor={color} flex="1 1 8px" borderRadius="2xl"></Box>
))}
</Flex>
)}
</Box>
</MenuButton>
<Portal>
{' '}
<MenuList minW={10} zIndex="popover" bgColor="gray.200">
<MenuItem
onClick={() => setVisualsCallback({ ...visuals, linkColorScheme: '' })}
justifyContent="space-between"
alignItems="center"
display="flex"
>
<Flex height={6} width={6} flexDirection="column" flexWrap="wrap">
{visuals.nodeColorScheme.map((color) => (
<Box key={color} bgColor={color} flex="1 1 8px" borderRadius="2xl"></Box>
))}
</Flex>
</MenuItem>
{colorList.map((color) => (
<MenuItem
key={color}
onClick={() =>
setVisualsCallback({
...visuals,
linkColorScheme: color,
})
}
justifyContent="space-between"
alignItems="center"
display="flex"
>
<Box bgColor={color} borderRadius="sm" height={6} width={6}></Box>
</MenuItem>
))}
</MenuList>
</Portal>
</Menu>
</Flex>
<Flex alignItems="center" justifyContent="space-between">
<Text>Accent</Text>
<Menu isLazy placement="right">
<MenuButton as={Button} colorScheme="" color="black" rightIcon={<ChevronDownIcon />}>
{<Box bgColor={highlightColor} borderRadius="sm" height={6} width={6}></Box>}
</MenuButton>
<Portal>
{' '}
<MenuList minW={10} zIndex="popover" bgColor="gray.200">
{colorList.map((color) => (
<MenuItem
key={color}
onClick={() => setHighlightColor(color)}
justifyContent="space-between"
alignItems="center"
display="flex"
>
<Box bgColor={color} borderRadius="sm" height={6} width={6}></Box>
</MenuItem>
))}
</MenuList>
</Portal>
</Menu>
</Flex>
<ColorMenu
colorList={colorList}
label="Link highlight"
setVisuals={setVisualsCallback}
value="linkHighlight"
visValue={visuals.linkHighlight}
/>
<ColorMenu
colorList={colorList}
label="Node highlight"
setVisuals={setVisualsCallback}
value="nodeHighlight"
visValue={visuals.nodeHighlight}
/>
<ColorMenu
colorList={colorList}
label="Background"
setVisuals={setVisualsCallback}
value="backgroundColor"
visValue={visuals.backgroundColor}
/>
<ColorMenu
colorList={colorList}
label="Emacs node"
setVisuals={setVisualsCallback}
value="emacsNodeColor"
visValue={visuals.emacsNodeColor}
/>
</Box>
</VStack>
)
}
|