tldraw/components/style-panel/quick-color-select.tsx

52 lines
1.6 KiB
TypeScript
Raw Normal View History

import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
import { breakpoints, IconButton } from 'components/shared'
2021-06-02 21:17:38 +00:00
import Tooltip from 'components/tooltip'
import { strokes } from 'state/shape-styles'
import state, { useSelector } from 'state'
import { BoxIcon, Item, DropdownContent } from '../shared'
2021-07-10 20:39:29 +00:00
import useTheme from 'hooks/useTheme'
import { ColorStyle } from 'types'
function handleColorChange(color: ColorStyle): void {
state.send('CHANGED_STYLE', { color })
}
2021-06-21 21:35:28 +00:00
export default function QuickColorSelect(): JSX.Element {
const color = useSelector((s) => s.values.selectedStyle.color)
2021-07-10 20:39:29 +00:00
const { theme } = useTheme()
return (
<DropdownMenu.Root dir="ltr">
<DropdownMenu.Trigger as={IconButton} bp={breakpoints}>
2021-06-02 21:17:38 +00:00
<Tooltip label="Color">
<BoxIcon
fill={strokes[theme][color]}
stroke={strokes[theme][color]}
/>
2021-06-02 21:17:38 +00:00
</Tooltip>
</DropdownMenu.Trigger>
<DropdownMenu.DropdownMenuRadioGroup
value={color}
as={DropdownContent}
onValueChange={handleColorChange}
sideOffset={8}
>
{Object.keys(strokes[theme]).map((colorStyle: ColorStyle) => (
<DropdownMenu.DropdownMenuRadioItem
as={Item}
key={colorStyle}
title={colorStyle}
value={colorStyle}
>
<BoxIcon
fill={strokes[theme][colorStyle]}
stroke={strokes[theme][colorStyle]}
/>
</DropdownMenu.DropdownMenuRadioItem>
))}
</DropdownMenu.DropdownMenuRadioGroup>
</DropdownMenu.Root>
)
}