Skip to content

Image

Image

An <img> with Wave fit, shape, shadow and border options.

alt is required: a description of the image, or alt="" for a decorative image. Without it screen readers may announce the file name, so JavaScript code that leaves it out gets a development warning.

Examples

Default

Placeholder image
export const Default: Story = {
  args: {
    src: placeholder(200, 200),
    alt: 'Placeholder image',
    width: 200,
    height: 200,
  },
};

Circular

Circular image
export const Circular: Story = {
  args: {
    src: placeholder(150, 150),
    alt: 'Circular image',
    shape: 'circular',
    width: 150,
    height: 150,
  },
};

Rounded

Rounded image
export const Rounded: Story = {
  args: {
    alt: 'Rounded image',
    shape: 'rounded',
  },
};

With Shadow

Image with shadow
export const WithShadow: Story = {
  args: {
    alt: 'Image with shadow',
    shadow: true,
  },
};

Bordered

Image with border
export const Bordered: Story = {
  args: {
    alt: 'Image with border',
    bordered: true,
  },
};

Decorative

export const Decorative: Story = {
  args: {
    alt: '',
  },
};

Block

Block image
export const Block: Story = {
  args: {
    src: placeholder(600, 200),
    alt: 'Block image',
    block: true,
    width: 600,
    height: 200,
  },
};

Fit Modes

Fit none
none
Fit center
center
Fit contain
contain
Fit cover
cover
Fit default
default
export const FitModes: Story = {
  args: {
    src: placeholder(200, 100),
    width: 100,
    height: 100,
  },
  render: (args) => (
    <div className="flex gap-4">
      {(['none', 'center', 'contain', 'cover', 'default'] as const).map((fit) => (
        <figure key={fit} className="m-0 flex flex-col items-center gap-1">
          <div className="size-[100px] border border-wave-border">
            <Image {...args} alt={`Fit ${fit}`} fit={fit} />
          </div>
          <figcaption className="text-wave-caption-1 text-wave-foreground">{fit}</figcaption>
        </figure>
      ))}
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
altstringYes

Text alternative of the image, required. Describe what the image shows, or pass alt="" when it is decorative (it then is hidden from assistive technology). JavaScript code that leaves it out gets a development warning.

fit'none' | 'center' | 'contain' | 'cover' | 'default'No'default'

How the image fits its box: 'default' (fills it, keeping the aspect ratio through an automatic height), 'none' (not scaled, top-left corner in view), 'center' (not scaled, middle in view), 'contain' or 'cover'. See ImageFit.

shape'circular' | 'square' | 'rounded'No'square'

Shape of the image border radius.

shadowbooleanNofalse

Whether to apply a shadow to the image.

blockbooleanNofalse

Whether the image is displayed as a block element filling the width of its parent. Otherwise it is inline and never wider than its parent. With the default fit the height follows the width (the aspect ratio is kept); with another fit the box keeps its height.

borderedbooleanNofalse

Whether to show a border around the image.

refReact.Ref<HTMLImageElement>No

Ref to the <img> element.

Any other prop is passed to the element it renders (HTMLImageElement).

Stable class names

PartClass
rootwave-image