tldraw/components/style-panel/dash-picker.tsx

43 lines
1,003 B
TypeScript
Raw Normal View History

import {
Group,
Item,
DashDashedIcon,
DashDottedIcon,
DashSolidIcon,
2021-06-03 12:06:39 +00:00
} from '../shared'
import * as RadioGroup from '@radix-ui/react-radio-group'
2021-06-01 21:49:32 +00:00
import { DashStyle } from 'types'
import state, { useSelector } from 'state'
import { memo } from 'react'
2021-06-01 21:49:32 +00:00
function handleChange(dash: string) {
state.send('CHANGED_STYLE', { dash })
2021-06-01 21:49:32 +00:00
}
const dashes = {
[DashStyle.Solid]: <DashSolidIcon />,
[DashStyle.Dashed]: <DashDashedIcon />,
[DashStyle.Dotted]: <DashDottedIcon />,
2021-06-01 21:49:32 +00:00
}
function DashPicker(): JSX.Element {
const dash = useSelector((s) => s.values.selectedStyle.dash)
2021-06-01 21:49:32 +00:00
return (
<Group name="Dash" onValueChange={handleChange}>
{Object.keys(DashStyle).map((dashStyle: DashStyle) => (
<RadioGroup.RadioGroupItem
as={Item}
key={dashStyle}
isActive={dash === dashStyle}
value={dashStyle}
>
{dashes[dashStyle]}
</RadioGroup.RadioGroupItem>
))}
2021-06-01 21:49:32 +00:00
</Group>
)
}
export default memo(DashPicker)