Image Text B

Picture with text.

Preview

Orange
Tasty Orange

Sweet and yummy

Orange
Tasty Lemon

Sweet and yummy

Code

import styles from "./image-text-b.module.css"; type Props = { className?: string; imageSrc?: string; imageClassName?: string; imageSize?: "small" | "medium" | "large"; alt?: string; textContent?: React.ReactNode; rounded?: "none" | "small" | "medium" | "large"; // Put additional variants here, then define them in the CSS variant?: "default" | "dark"; }; export default function ImageTextB({ className, imageClassName, imageSrc, imageSize, alt, textContent, rounded, variant, }: Props) { return ( <div className={[ className, styles["wrapper"], rounded && styles[`r-${rounded}`], variant && styles[`variant-${variant}`], ].join(" ")} > <div className={styles["image-wrapper"]}> {/* If you use Next.js, replace 'img' with 'Image' element */} <img className={[ styles["image"], imageSize && styles[`is-${imageSize}`], imageClassName, ].join(" ")} src={imageSrc} alt={alt || "Image"} width={360} height={360} loading="lazy" /> </div> {textContent && ( <div className={styles["text-content"]}> <div className={styles["text-wrapper"]}> {typeof textContent === "string" ? ( <p>{textContent}</p> ) : ( <>{textContent}</> )} </div> </div> )} </div> ); }

Design

Figma design file:

Documentation

Properties

Props of the component:

  • className (string): Specifies the CSS class of the component.
  • imageSrc (string): Specifies the URL of the image.
  • imageClassName (string): Specifies the CSS class of the image.
  • imageSize ("small" | "medium" | "large"): Specifies the size of the image.
  • alt (string): Specifies the text that will be used as the alt attribute of the image.
  • textContent (string or ReactNode): Specifies the text content.
  • rounded ("none" | "small" | "medium" | "large"): Specifies the border radius of the images.
  • variant ("default" | "dark" or a customized value): Specifies the color or theme variant of the component. Check out the "Sample CSS customization" below for an example of how to use it.
Sample CSS customization
.variant-dark{ --fg-color: #424242; } .variant-dark .text-wrapper{ width: 100%; text-shadow: 0px 0.25rem 0.5rem rgba(255, 255, 255, 0.2) ; }