You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

quick-dash-select.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { memo } from 'react'
  2. import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
  3. import { DropdownMenuIconTriggerButton } from 'components/shared'
  4. import state, { useSelector } from 'state'
  5. import { DashStyle } from 'types'
  6. import {
  7. DashDrawIcon,
  8. DashDottedIcon,
  9. DashSolidIcon,
  10. DashDashedIcon,
  11. StyleDropdownContent,
  12. StyleDropdownItem,
  13. } from './shared'
  14. const dashes = {
  15. [DashStyle.Draw]: <DashDrawIcon />,
  16. [DashStyle.Solid]: <DashSolidIcon />,
  17. [DashStyle.Dashed]: <DashDashedIcon />,
  18. [DashStyle.Dotted]: <DashDottedIcon />,
  19. }
  20. function changeDashStyle(dash: DashStyle): void {
  21. state.send('CHANGED_STYLE', { dash })
  22. }
  23. function QuickdashSelect(): JSX.Element {
  24. const dash = useSelector((s) => s.values.selectedStyle.dash)
  25. return (
  26. <DropdownMenu.Root dir="ltr">
  27. <DropdownMenuIconTriggerButton label="Dash">
  28. {dashes[dash]}
  29. </DropdownMenuIconTriggerButton>
  30. <DropdownMenu.Content sideOffset={8}>
  31. <DropdownMenu.DropdownMenuRadioGroup
  32. as={StyleDropdownContent}
  33. direction="vertical"
  34. value={dash}
  35. onValueChange={changeDashStyle}
  36. >
  37. {Object.keys(DashStyle).map((dashStyle: DashStyle) => (
  38. <DropdownMenu.DropdownMenuRadioItem
  39. as={StyleDropdownItem}
  40. key={dashStyle}
  41. isActive={dash === dashStyle}
  42. value={dashStyle}
  43. >
  44. {dashes[dashStyle]}
  45. </DropdownMenu.DropdownMenuRadioItem>
  46. ))}
  47. </DropdownMenu.DropdownMenuRadioGroup>
  48. </DropdownMenu.Content>
  49. </DropdownMenu.Root>
  50. )
  51. }
  52. export default memo(QuickdashSelect)