Image.tsx 794 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from "react"
  2. interface ImageProps {
  3. src: string
  4. alt: string
  5. width?: string
  6. height?: string
  7. caption?: string
  8. }
  9. export function Image({ src, alt, width, height, caption }: ImageProps) {
  10. const imgStyle: React.CSSProperties = {
  11. maxWidth: "100%",
  12. height: "auto",
  13. }
  14. if (width) imgStyle.width = width
  15. if (height) imgStyle.height = height
  16. return (
  17. <figure style={{ margin: "1.5rem 0", maxWidth: "100%", overflow: "hidden" }}>
  18. <img src={src} alt={alt} style={imgStyle} />
  19. {caption && (
  20. <figcaption
  21. style={{
  22. display: "table-caption",
  23. captionSide: "bottom",
  24. fontStyle: "italic",
  25. textAlign: "center",
  26. marginTop: "0.5rem",
  27. color: "var(--gray-600, #6b7280)",
  28. }}>
  29. {caption}
  30. </figcaption>
  31. )}
  32. </figure>
  33. )
  34. }