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.

shape.tsx 928B

1234567891011121314151617181920212223242526272829303132333435
  1. import { memo } from "react"
  2. import { useSelector } from "state"
  3. import { ShapeType } from "types"
  4. import Circle from "./shapes/circle"
  5. import Dot from "./shapes/dot"
  6. import Polyline from "./shapes/polyline"
  7. import Rectangle from "./shapes/rectangle"
  8. /*
  9. Gets the shape from the current page's shapes, using the
  10. provided ID. Depending on the shape's type, return the
  11. component for that type.
  12. */
  13. function Shape({ id }: { id: string }) {
  14. const shape = useSelector((state) => {
  15. const { currentPageId, document } = state.data
  16. return document.pages[currentPageId].shapes[id]
  17. })
  18. switch (shape.type) {
  19. case ShapeType.Dot:
  20. return <Dot {...shape} />
  21. case ShapeType.Circle:
  22. return <Circle {...shape} />
  23. case ShapeType.Rectangle:
  24. return <Rectangle {...shape} />
  25. case ShapeType.Polyline:
  26. return <Polyline {...shape} />
  27. default:
  28. return null
  29. }
  30. }
  31. export default memo(Shape)