index.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const generateShape = (): React.ReactNode => {
  23. switch (shape) {
  24. case 'Circle':
  25. return (
  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. );
  38. case 'Square': {
  39. const indent = bdwidth / 2;
  40. return (
  41. <rect
  42. x={indent}
  43. y={indent}
  44. width={`${width - bdwidth}px`}
  45. height={`${height - bdwidth}px`}
  46. stroke={bdcolor}
  47. strokeWidth={bdwidth}
  48. strokeOpacity={transparency}
  49. fill={fcolor}
  50. fillOpacity={ftransparency}
  51. />
  52. );
  53. }
  54. default: {
  55. return {};
  56. }
  57. }
  58. };
  59. return (
  60. <svg
  61. viewBox={`0 0 ${width} ${height}`}
  62. >
  63. {generateShape()}
  64. </svg>
  65. );
  66. };
  67. export default SvgShapeElement;