index.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. type Props = {
  3. shape: string;
  4. width: number;
  5. height: number;
  6. bdcolor: string;
  7. bdwidth: number;
  8. transparency: number;
  9. fcolor?: string;
  10. ftransparency?: number;
  11. };
  12. const SvgShapeElement: React.FC<Props> = ({
  13. shape,
  14. width,
  15. height,
  16. bdcolor,
  17. bdwidth,
  18. transparency,
  19. fcolor,
  20. ftransparency,
  21. }: Props) => (
  22. <svg
  23. viewBox={`0 0 ${width} ${height}`}
  24. >
  25. {shape === 'Circle' ? (
  26. <ellipse
  27. cx="50%"
  28. cy="50%"
  29. rx={(width - bdwidth) / 2}
  30. ry={(height - bdwidth) / 2}
  31. stroke={bdcolor}
  32. strokeWidth={bdwidth}
  33. strokeOpacity={transparency}
  34. fill={fcolor}
  35. fillOpacity={ftransparency}
  36. />
  37. ) : null}
  38. {shape === 'Square' ? (
  39. <rect
  40. x={bdwidth / 2}
  41. y={bdwidth / 2}
  42. width={`${width - bdwidth}px`}
  43. height={`${height - bdwidth}px`}
  44. stroke={bdcolor}
  45. strokeWidth={bdwidth}
  46. strokeOpacity={transparency}
  47. fill={fcolor}
  48. fillOpacity={ftransparency}
  49. />
  50. ) : null}
  51. </svg>
  52. );
  53. export default SvgShapeElement;