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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
  2. import { IconButton } from 'components/shared'
  3. import Tooltip from 'components/tooltip'
  4. import state, { useSelector } from 'state'
  5. import { DashStyle } from 'types'
  6. import {
  7. DropdownContent,
  8. Item,
  9. DashDottedIcon,
  10. DashSolidIcon,
  11. DashDashedIcon,
  12. } from '../shared'
  13. const dashes = {
  14. [DashStyle.Solid]: <DashSolidIcon />,
  15. [DashStyle.Dashed]: <DashDashedIcon />,
  16. [DashStyle.Dotted]: <DashDottedIcon />,
  17. }
  18. export default function QuickdashSelect() {
  19. const dash = useSelector((s) => s.values.selectedStyle.dash)
  20. return (
  21. <DropdownMenu.Root>
  22. <DropdownMenu.Trigger
  23. as={IconButton}
  24. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  25. >
  26. <Tooltip label="Dash">{dashes[dash]}</Tooltip>
  27. </DropdownMenu.Trigger>
  28. <DropdownContent sideOffset={8} direction="vertical">
  29. <DashItem isActive={dash === DashStyle.Solid} dash={DashStyle.Solid} />
  30. <DashItem
  31. isActive={dash === DashStyle.Dashed}
  32. dash={DashStyle.Dashed}
  33. />
  34. <DashItem
  35. isActive={dash === DashStyle.Dotted}
  36. dash={DashStyle.Dotted}
  37. />
  38. </DropdownContent>
  39. </DropdownMenu.Root>
  40. )
  41. }
  42. function DashItem({ dash, isActive }: { isActive: boolean; dash: DashStyle }) {
  43. return (
  44. <Item
  45. as={DropdownMenu.DropdownMenuItem}
  46. isActive={isActive}
  47. onSelect={() => state.send('CHANGED_STYLE', { dash })}
  48. >
  49. {dashes[dash]}
  50. </Item>
  51. )
  52. }