Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

selected.tsx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import styled from 'styles'
  2. import { useSelector } from 'state'
  3. import { deepCompareArrays, getPage } from 'utils/utils'
  4. import { getShapeUtils } from 'lib/shape-utils'
  5. import useShapeEvents from 'hooks/useShapeEvents'
  6. import { useRef } from 'react'
  7. export default function Selected() {
  8. const currentPageShapeIds = useSelector(({ data }) => {
  9. return Array.from(data.selectedIds.values())
  10. }, deepCompareArrays)
  11. const isSelecting = useSelector((s) => s.isIn('selecting'))
  12. if (!isSelecting) return null
  13. return (
  14. <g>
  15. {currentPageShapeIds.map((id) => (
  16. <ShapeOutline key={id} id={id} />
  17. ))}
  18. </g>
  19. )
  20. }
  21. export function ShapeOutline({ id }: { id: string }) {
  22. const rIndicator = useRef<SVGUseElement>(null)
  23. const shape = useSelector(({ data }) => getPage(data).shapes[id])
  24. const events = useShapeEvents(id, rIndicator)
  25. if (!shape) return null
  26. const transform = `
  27. rotate(${shape.rotation * (180 / Math.PI)},
  28. ${getShapeUtils(shape).getCenter(shape)})
  29. translate(${shape.point})
  30. `
  31. return (
  32. <SelectIndicator
  33. ref={rIndicator}
  34. as="use"
  35. href={'#' + id}
  36. transform={transform}
  37. isLocked={shape.isLocked}
  38. {...events}
  39. />
  40. )
  41. }
  42. const SelectIndicator = styled('path', {
  43. zStrokeWidth: 3,
  44. strokeLineCap: 'round',
  45. strokeLinejoin: 'round',
  46. stroke: '$selected',
  47. fill: 'transparent',
  48. pointerEvents: 'none',
  49. paintOrder: 'stroke fill markers',
  50. variants: {
  51. isLocked: {
  52. true: {
  53. zDash: 2,
  54. },
  55. false: {},
  56. },
  57. variant: {},
  58. },
  59. })