MediaObject

The <smart-media-object> component provides a flexible media-object layout wrapper with an InjectionToken-based extension mechanism. It pairs an image with adjacent body content (the classic media object pattern) and renders a default MediaObjectStandardComponent which can be replaced via MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN.


Usage

<smart-media-object
  [mediaUrl]="avatarUrl"
  mediaAlt="Portrait of Lindsay Walton"
  [options]="options"
>
  <h4>Lindsay Walton</h4>
  <p>Joined the design systems team in March.</p>
</smart-media-object>

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Components

MediaObjectComponent (<smart-media-object>)

Main wrapper component. Renders MediaObjectStandardComponent by default. When MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet. Projects body content into the standard via <ng-content />.

MediaObjectStandardComponent (<smart-media-object-standard>)

Default concrete implementation. Renders an <img> and a .smart-media-object-body slot inside a wrapper <div>. The wrapper exposes data-position and data-alignment attributes derived from options for CSS styling.

MediaObjectBaseComponent (abstract)

Abstract base directive for extending custom media-object implementations. Declares mediaUrl (required), mediaAlt (required), options, and cssClass.

API

Inputs

InputTypeDefaultDescription
mediaUrlInputSignal<string>requiredImage URL
mediaAltInputSignal<string>requiredImage alt text
optionsInputSignal<IMediaObjectOptions | undefined>undefinedLayout configuration
classInputSignal<string>''External CSS classes (alias for cssClass)

Content Projection

The wrapper projects body content via <ng-content /> into the .smart-media-object-body slot of the standard component, or into the default <ng-content /> of a component registered through MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN (MediaObjectPresetComponent renders it in its body).

IMediaObjectOptions

FieldTypeDefaultDescription
alignment'top' | 'center' | 'bottom' | 'stretched'-Vertical alignment of the image against the body; the standard exposes it as data-alignment (only when set), the preset aligns the row.
position'left' | 'right''left'Side of the image; the standard exposes it as data-position, the preset reverses the row for 'right'.
responsivebooleanfalsePreset only: stacks the image above the body on small screens.
nestedbooleanfalsePreset only: the spacing of a media object nested in another one.
widebooleanfalsePreset only: a wider image (w-32).

MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN

InjectionToken from @smartsoft001/angular that allows replacing the default MediaObjectStandardComponent with a custom implementation. Provide a Type<MediaObjectBaseComponent> in your application or component providers; provideSmartPresets() provides MediaObjectPresetComponent for it together with every other preset.

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ViewEncapsulation,
} from '@angular/core';

import {
  IMediaObjectOptions,
  MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN,
  MediaObjectBaseComponent,
  MediaObjectComponent,
} from '@smartsoft001/angular';

/**
 * A custom media object built on `MediaObjectBaseComponent`.
 *
 * The base contributes the `mediaUrl`, `mediaAlt`, `options` and `class`
 * inputs; the implementation owns the markup around them and projects the
 * body that `<smart-media-object>` receives.
 */
@Component({
  selector: 'docs-custom-media-object',
  template: `
    <article
      [class]="containerClasses()"
      [attr.data-alignment]="options()?.alignment ?? 'top'"
      [attr.data-position]="options()?.position ?? 'left'"
    >
      <img
        class="docs-media-object__media"
        [src]="mediaUrl()"
        [alt]="mediaAlt()"
        width="64"
        height="64"
      />

      <!-- The content of <smart-media-object> is projected here. -->
      <div class="docs-media-object__body">
        <ng-content />
      </div>
    </article>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomMediaObjectComponent extends MediaObjectBaseComponent {
  containerClasses = computed(() =>
    [
      'docs-media-object',
      this.options()?.wide ? 'docs-media-object--wide' : '',
      this.options()?.nested ? 'docs-media-object--nested' : '',
      this.cssClass(),
    ]
      .filter(Boolean)
      .join(' '),
  );
}

/**
 * Registering the implementation against
 * `MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN` makes every `<smart-media-object>`
 * in this injector render it instead of the standard variation.
 */
@Component({
  selector: 'docs-media-object-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MediaObjectComponent],
  providers: [
    {
      provide: MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN,
      useValue: CustomMediaObjectComponent,
    },
  ],
  template: `
    <smart-media-object
      [mediaUrl]="mediaUrl"
      mediaAlt="Portrait of Lindsay Walton"
      [options]="options"
      class="docs-media-object--demo"
    >
      <h3 class="docs-media-object__title">Lindsay Walton</h3>
      <p class="docs-media-object__text">
        Front-end developer, joined the design systems team in March.
      </p>
    </smart-media-object>
  `,
})
export class MediaObjectCustomExampleComponent {
  mediaUrl =
    'https://images.unsplash.com/photo-1568602471122-7832951cc4c5?auto=format&fit=facearea&facepad=2&w=300&h=300&q=80';

  options: IMediaObjectOptions = {
    alignment: 'center',
    position: 'right',
  };
}

Preset

MediaObjectPresetComponent (selector smart-media-object-preset) is a styled, drop-in replacement for the standard component. It extends MediaObjectStandardComponent and reuses its inputs, so registering it through the token (or with provideSmartPresets()) restyles every <smart-media-object>. It declares cssClass without the class alias: on the <smart-media-object-preset> selector bind [cssClass]; on <smart-media-object> pass class as usual.

Look: a flex row (smart:flex smart:gap-4) with a rounded, cover-fitted thumbnail (smart:size-16 smart:rounded-lg smart:object-cover smart:shrink-0) beside small, muted body text (smart:text-sm smart:text-gray-700 smart:dark:text-gray-300). All utilities are smart:-prefixed and dark-mode aware.

IMediaObjectOptions drives every variant (no new fields):

  • position: 'right' reverses the row (smart:flex-row-reverse).
  • alignment: 'top' | 'center' | 'bottom' maps to smart:items-start | items-center | items-end; 'stretched' instead makes the media fill the row height (smart:self-stretch smart:h-auto).
  • responsive: true stacks into a column on mobile then rows out from sm (smart:flex-col smart:sm:flex-row, reversed when position: 'right').
  • nested: true tightens the gap to smart:gap-3 and indents with smart:mt-4.
  • wide: true widens the thumbnail to smart:w-32 (keeping a smart:h-16 height).

data-role hooks (root, media, body) and the data-position / data-alignment attributes are exposed for testing and targeting; the smart-media-object-body marker class is preserved for content projection parity with the standard component.

Register it as the standard replacement by providing it for MEDIA_OBJECT_STANDARD_COMPONENT_TOKEN.

The class recipes are internal to the preset (not exported).

Gaps: the media is always an <img> (no icon/video slot), and wide uses a fixed w-32/h-16 footprint rather than an intrinsic aspect ratio.

Source

The component lives in packages/shared/angular/src/lib/components/media-object and is documented for Claude Code by the angular-components-media-object skill.

SmartMediaObject lays an image (mediaUrl / mediaAlt) beside a body (children), the classic comment / list-entry layout. options.position puts the image left (default) or right, options.alignment aligns it to the body, and responsive, nested and wide adjust the layout in the preset. The standard rendering exposes position and alignment as data-* attributes.


Usage

import { IMediaObjectOptions, SmartMediaObject } from '@smartsoft001/react';

const avatarUrl = 'https://i.pravatar.cc/128?u=lindsay.walton';

const options: IMediaObjectOptions = {
  alignment: 'center',
};

export function MediaObjectUsageExample() {
  return (
    <SmartMediaObject
      mediaUrl={avatarUrl}
      mediaAlt="Portrait of Lindsay Walton"
      options={options}
    >
      <h4>Lindsay Walton</h4>
      <p>Joined the design systems team in March.</p>
    </SmartMediaObject>
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartMediaObjectcomponentRenders the implementation registered as components['media-object'] on SmartProvider, SmartMediaObjectStandard by default.
SmartMediaObjectPresetcomponentStyled media-object variation (preset).
SmartMediaObjectStandardcomponentThe default media-object rendering: the media <img> and a .smart-media-object-body holding children.

The preset's class helpers (getMediaObjectRootClasses, getMediaObjectMediaClasses, getMediaObjectBodyClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartMediaObjectProps

PropTypeDefaultDescription
mediaUrlstringrequiredImage URL.
mediaAltstringrequiredImage alt text.
options?IMediaObjectOptions—Layout options.
className?string—Classes on the root element.
children?ReactNode—The body content, beside the media.

IMediaObjectOptions

FieldTypeDefaultDescription
alignment?'top' | 'center' | 'bottom' | 'stretched'—Vertical alignment of the image against the body (data-alignment).
position?'left' | 'right''left'Side of the image (data-position).
responsive?booleanfalsePreset: stacks the image above the body on small screens.
nested?booleanfalsePreset: spacing for a media object nested in another one.
wide?booleanfalsePreset: a larger image footprint.

Replacing the Implementation

SmartMediaObject renders the component registered under the 'media-object' key of SmartProvider's components, and SmartMediaObjectStandard when nothing is registered there. Every SmartMediaObject below the provider then renders the registered component, which receives the same props.

SmartMediaObjectPreset is the styled (preset) implementation: register it under the 'media-object' key of SmartProvider's components, render it directly in place of SmartMediaObject, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.

import {
  IMediaObjectOptions,
  SmartMediaObject,
  SmartMediaObjectProps,
  SmartProvider,
} from '@smartsoft001/react';

/**
 * A custom media object: it receives the props of `SmartMediaObject`
 * (`mediaUrl`, `mediaAlt`, `options`, `className` and the body as `children`)
 * and owns the markup around them.
 */
export function CustomMediaObject({
  mediaUrl,
  mediaAlt,
  options,
  className,
  children,
}: SmartMediaObjectProps) {
  const classes = [
    'docs-media-object',
    options?.wide && 'docs-media-object--wide',
    options?.nested && 'docs-media-object--nested',
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <article
      className={classes}
      data-alignment={options?.alignment ?? 'top'}
      data-position={options?.position ?? 'left'}
    >
      <img
        className="docs-media-object__media"
        src={mediaUrl}
        alt={mediaAlt}
        width={64}
        height={64}
      />
      <div className="docs-media-object__body">{children}</div>
    </article>
  );
}

// A module constant: a new object on every render would change the context.
const components = { 'media-object': CustomMediaObject };

const mediaUrl =
  'https://images.unsplash.com/photo-1568602471122-7832951cc4c5?auto=format&fit=facearea&facepad=2&w=300&h=300&q=80';

const options: IMediaObjectOptions = {
  alignment: 'center',
  position: 'right',
};

/**
 * Every `SmartMediaObject` below this provider renders `CustomMediaObject`
 * instead of the standard rendering.
 */
export function MediaObjectCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartMediaObject
        mediaUrl={mediaUrl}
        mediaAlt="Portrait of Lindsay Walton"
        options={options}
        className="docs-media-object--demo"
      >
        <h3 className="docs-media-object__title">Lindsay Walton</h3>
        <p className="docs-media-object__text">
          Front-end developer, joined the design systems team in March.
        </p>
      </SmartMediaObject>
    </SmartProvider>
  );
}

Styling

  • SmartMediaObjectStandard renders the <img> and a .smart-media-object-body with data-position / data-alignment and no layout styles; SmartMediaObjectPreset keeps those hooks and adds the flex layout and a rounded thumbnail.

Source

The component lives in packages/shared/react/src/lib/components/media-object and is documented for Claude Code by the react-components-media-object skill.