Rect.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { memo } from "react";
  2. import styled, { css } from "styled-components";
  3. const StyledShape = styled.div`
  4. ${({ width, height }) => css`
  5. width: ${width}px;
  6. height: ${height}px;
  7. box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px,
  8. rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
  9. display: flex;
  10. justify-content: center;
  11. align-items: center;
  12. position: relative;
  13. & svg {
  14. position: absolute;
  15. top: 0;
  16. left: 0;
  17. right: 0;
  18. bottom: 0;
  19. }
  20. & span {
  21. z-index: 0;
  22. }
  23. `}
  24. `;
  25. const Rect = ({
  26. width = 50,
  27. height = 50,
  28. color = "#ccc",
  29. text = "",
  30. textColor = "#000",
  31. fontSize = "16",
  32. }) => {
  33. return (
  34. <StyledShape width={width} height={height}>
  35. <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  36. <rect
  37. x="0"
  38. y="0"
  39. width="100"
  40. height="100"
  41. style={{
  42. fill: color,
  43. }}
  44. />
  45. </svg>
  46. {text && (
  47. <span
  48. style={{
  49. textColor,
  50. fontSize: fontSize + "px",
  51. }}
  52. >
  53. {text}
  54. </span>
  55. )}
  56. </StyledShape>
  57. );
  58. };
  59. export default memo(Rect);