您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

selected.tsx 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. <Indicator
  33. ref={rIndicator}
  34. as="use"
  35. href={'#' + id}
  36. transform={transform}
  37. isLocked={shape.isLocked}
  38. {...events}
  39. />
  40. )
  41. }
  42. const Indicator = styled('path', {
  43. zStrokeWidth: 1,
  44. strokeLineCap: 'round',
  45. strokeLinejoin: 'round',
  46. stroke: '$selected',
  47. fill: 'transparent',
  48. pointerEvents: 'all',
  49. variants: {
  50. isLocked: {
  51. true: {
  52. zDash: 2,
  53. },
  54. false: {},
  55. },
  56. },
  57. })