Skip to main content

Media Object

The Media Object is an image or an icon (media) on the left, with descriptive content (a title and a subtitle or description) on the right. Compose MediaObject.Media and MediaObject.Content as direct children of MediaObject.Root.

When to use

  • Put an avatar beside a name and a body in a comment thread.
  • Put an icon beside a label and secondary text in a compact list item or a notification row.
  • Build feature lists, profile cards, and attachment previews.
  • Leave out the media when it is decorative and adds no information. Use a plain block instead.
  • Prefer Card for a raised box with a border, or for a complex layout with many regions. You can also build your own flex or grid layout for that.
  • Prefer Choice when the thing beside the text is a checkbox, a radio, or a switch.

Composition

Compose the parts of a MediaObject together to build your own:

MediaObject.Root├── MediaObject.Media└── MediaObject.Content

Polymorphism

Each part accepts an asChild prop. When true, the part renders its single child instead of its default <div>, forwarding its styling and props onto that child. Render MediaObject.Root as an <a> to make the whole row a link.

Spacing & alignment

Default gap is gap-4; override by passing a different gap-* class to MediaObject.Root. Use standard flex utilities (items-start, items-center, etc.) to align media and content vertically.

The media object pattern

MediaObject is a small layout primitive for the media object pattern: media on one side, and descriptive content on the other. Use it for each two-up row, so you do not write the same flexbox again.

API Reference

MediaObject.Root

The MediaObject is an image/icon (media) to the left, with descriptive content (title and subtitle/description) to the right. Root container for all MediaObject.Root sub-components.

All props from div, plus:

PropTypeDefaultDescription
asChildbooleanfalseUse the asChild prop to compose the MediaObject styling and functionality onto alternative element types or your own React components.

MediaObject.Media

The container for an image or icon to display in the media slot of the MediaObject.

All props from div, plus:

PropTypeDefaultDescription
asChildbooleanfalseUse the asChild prop to compose the MediaObject.Media styling and functionality onto alternative element types or your own React components.

MediaObject.Content

The container for the content slot of a MediaObject.

All props from div, plus:

PropTypeDefaultDescription
asChildbooleanfalseUse the asChild prop to compose the MediaObject.Content styling and functionality onto alternative element types or your own React components.