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 821B

1234567891011121314151617181920212223242526272829303132
  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 Rectangle from "./shapes/rectangle"
  7. /*
  8. Gets the shape from the current page's shapes, using the
  9. provided ID. Depending on the shape's type, return the
  10. component for that type.
  11. */
  12. function Shape({ id }: { id: string }) {
  13. const shape = useSelector((state) => {
  14. const { currentPageId, document } = state.data
  15. return document.pages[currentPageId].shapes[id]
  16. })
  17. switch (shape.type) {
  18. case ShapeType.Dot:
  19. return <Dot {...shape} />
  20. case ShapeType.Circle:
  21. return <Circle {...shape} />
  22. case ShapeType.Rectangle:
  23. return <Rectangle {...shape} />
  24. default:
  25. return null
  26. }
  27. }
  28. export default memo(Shape)