DotShape.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import * as React from 'react'
  2. import { TLDotShape, TLDotShapeProps } from '@tldraw/core'
  3. import { SVGContainer, TLComponentProps } from '@tldraw/react'
  4. import { observer } from 'mobx-react-lite'
  5. import { CustomStyleProps, withClampedStyles } from './style-props'
  6. export interface DotShapeProps extends TLDotShapeProps, CustomStyleProps {
  7. type: 'dot'
  8. }
  9. export class DotShape extends TLDotShape<DotShapeProps> {
  10. static id = 'dot'
  11. static defaultProps: DotShapeProps = {
  12. id: 'dot',
  13. parentId: 'page',
  14. type: 'dot',
  15. point: [0, 0],
  16. radius: 4,
  17. stroke: '#000000',
  18. fill: 'var(--ls-secondary-background-color)',
  19. noFill: false,
  20. strokeType: 'line',
  21. strokeWidth: 2,
  22. opacity: 1,
  23. }
  24. ReactComponent = observer(({ events, isErasing }: TLComponentProps) => {
  25. const { radius, stroke, fill, strokeWidth, opacity } = this.props
  26. return (
  27. <SVGContainer {...events} opacity={isErasing ? 0.2 : opacity}>
  28. <circle className="tl-hitarea-fill" cx={radius} cy={radius} r={radius} />
  29. <circle
  30. cx={radius}
  31. cy={radius}
  32. r={radius}
  33. stroke={stroke}
  34. fill={fill}
  35. strokeWidth={strokeWidth}
  36. pointerEvents="none"
  37. />
  38. </SVGContainer>
  39. )
  40. })
  41. ReactIndicator = observer(() => {
  42. const { radius } = this.props
  43. return <circle cx={radius} cy={radius} r={radius} pointerEvents="all" />
  44. })
  45. validateProps = (props: Partial<DotShapeProps>) => {
  46. if (props.radius !== undefined) props.radius = Math.max(props.radius, 1)
  47. return withClampedStyles(this, props)
  48. }
  49. }