index.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 width={width} height={height} viewBox={`0 0 ${width} ${height}`}>
  23. {shape === 'Circle' ? (
  24. <ellipse
  25. cx={width / 2}
  26. cy={height / 2}
  27. rx={(width - bdwidth) / 2}
  28. ry={(height - bdwidth) / 2}
  29. stroke={bdcolor}
  30. strokeWidth={bdwidth}
  31. strokeOpacity={transparency}
  32. fill={fcolor}
  33. fillOpacity={ftransparency}
  34. />
  35. ) : null}
  36. {shape === 'Square' ? (
  37. <rect
  38. x={bdwidth / 2}
  39. y={bdwidth / 2}
  40. width={`${width - bdwidth}px`}
  41. height={`${height - bdwidth}px`}
  42. stroke={bdcolor}
  43. strokeWidth={bdwidth}
  44. strokeOpacity={transparency}
  45. fill={fcolor}
  46. fillOpacity={ftransparency}
  47. />
  48. ) : null}
  49. </svg>
  50. );
  51. export default SvgShapeElement;