2021-06-02 11:50:34 +00:00
|
|
|
import { IconButton } from 'components/shared'
|
2021-06-21 21:35:28 +00:00
|
|
|
import { strokes } from 'state/shape-styles'
|
2021-06-02 11:50:34 +00:00
|
|
|
import { ColorStyle } from 'types'
|
|
|
|
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
|
|
|
import { Square } from 'react-feather'
|
2021-06-03 12:06:39 +00:00
|
|
|
import { DropdownContent } from '../shared'
|
2021-06-28 12:13:34 +00:00
|
|
|
import { memo } from 'react'
|
|
|
|
import state from 'state'
|
2021-07-10 20:39:29 +00:00
|
|
|
import useTheme from 'hooks/useTheme'
|
2021-06-02 11:50:34 +00:00
|
|
|
|
2021-06-28 12:13:34 +00:00
|
|
|
function handleColorChange(
|
|
|
|
e: Event & { currentTarget: { value: ColorStyle } }
|
|
|
|
): void {
|
|
|
|
state.send('CHANGED_STYLE', { color: e.currentTarget.value })
|
|
|
|
}
|
|
|
|
|
|
|
|
function ColorContent(): JSX.Element {
|
2021-07-10 20:39:29 +00:00
|
|
|
const { theme } = useTheme()
|
|
|
|
|
2021-06-02 11:50:34 +00:00
|
|
|
return (
|
2021-06-03 16:13:23 +00:00
|
|
|
<DropdownContent sideOffset={8} side="bottom">
|
2021-07-10 20:39:29 +00:00
|
|
|
{Object.keys(strokes[theme]).map((color: ColorStyle) => (
|
2021-06-02 11:50:34 +00:00
|
|
|
<DropdownMenu.DropdownMenuItem
|
|
|
|
as={IconButton}
|
|
|
|
key={color}
|
|
|
|
title={color}
|
2021-06-28 12:13:34 +00:00
|
|
|
value={color}
|
|
|
|
onSelect={handleColorChange}
|
2021-06-02 11:50:34 +00:00
|
|
|
>
|
2021-07-10 20:39:29 +00:00
|
|
|
<Square fill={strokes[theme][color]} stroke="none" size="22" />
|
2021-06-02 11:50:34 +00:00
|
|
|
</DropdownMenu.DropdownMenuItem>
|
|
|
|
))}
|
|
|
|
</DropdownContent>
|
|
|
|
)
|
|
|
|
}
|
2021-06-28 12:13:34 +00:00
|
|
|
|
|
|
|
export default memo(ColorContent)
|