Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

quick-dash-select.tsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
  2. import { breakpoints, IconButton } from 'components/shared'
  3. import Tooltip from 'components/tooltip'
  4. import { memo } from 'react'
  5. import state, { useSelector } from 'state'
  6. import { DashStyle } from 'types'
  7. import {
  8. DropdownContent,
  9. Item,
  10. DashDottedIcon,
  11. DashSolidIcon,
  12. DashDashedIcon,
  13. } from '../shared'
  14. const dashes = {
  15. [DashStyle.Solid]: <DashSolidIcon />,
  16. [DashStyle.Dashed]: <DashDashedIcon />,
  17. [DashStyle.Dotted]: <DashDottedIcon />,
  18. }
  19. function changeDashStyle(
  20. e: Event & { currentTarget: { value: DashStyle } }
  21. ): void {
  22. state.send('CHANGED_STYLE', { dash: e.currentTarget.value })
  23. }
  24. function QuickdashSelect(): JSX.Element {
  25. const dash = useSelector((s) => s.values.selectedStyle.dash)
  26. return (
  27. <DropdownMenu.Root dir="ltr">
  28. <DropdownMenu.Trigger as={IconButton} bp={breakpoints}>
  29. <Tooltip label="Dash">{dashes[dash]}</Tooltip>
  30. </DropdownMenu.Trigger>
  31. <DropdownContent sideOffset={8} direction="vertical">
  32. {Object.keys(DashStyle).map((dashStyle: DashStyle) => (
  33. <DropdownMenu.DropdownMenuItem
  34. as={Item}
  35. key={dashStyle}
  36. isActive={dash === dashStyle}
  37. onSelect={changeDashStyle}
  38. value={dashStyle}
  39. >
  40. {dashes[dashStyle]}
  41. </DropdownMenu.DropdownMenuItem>
  42. ))}
  43. </DropdownContent>
  44. </DropdownMenu.Root>
  45. )
  46. }
  47. export default memo(QuickdashSelect)