Detail

The <smart-detail> component renders a single model field value by delegating to a sub-component chosen by FieldType. It selects a sub-component based on the FieldType from an internal baseMap and an optional extendMap injected via DETAIL_FIELD_COMPONENTS_TOKEN. It renders the label (via ModelLabelPipe), the value (NgComponentOutlet on the selected sub-component), or a skeleton when item() returns undefined.


Usage

<smart-detail [type]="type" [options]="firstNameOptions" />
<smart-detail [type]="type" [options]="emailOptions" />

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

DetailComponent (<smart-detail>)

Main wrapper component. Selects a sub-component from baseMap (or extendMap override) based on options().options.type and renders it via NgComponentOutlet. Shows a skeleton placeholder while item() is undefined.

DetailBaseComponent (abstract)

Abstract base directive for all detail sub-components. Provides:

  • options: InputSignal<IDetailOptions<T>> — field configuration
  • cssClass: InputSignal<string> (alias class) — external CSS classes
  • afterSetOptionsHandler() — hook invoked via effect on options change
  • Effect that calls ChangeDetectorRef.detectChanges() when options change

Default Sub-Components

FieldTypeSub-componentSelectorDescription
textDetailTextComponentsmart-detail-textSanitized HTML via ListCellPipe, fallback for unknown types
emailDetailEmailComponentsmart-detail-emailLink mailto:
enumDetailEnumComponentsmart-detail-enumSingle value or array with translate
flagDetailFlagComponentsmart-detail-flagInline SVG ✓ / ✗
colorDetailColorComponentsmart-detail-colorRectangle with background-color
addressDetailAddressComponentsmart-detail-addressIAddress (street, number, zip, city)
objectDetailObjectComponentsmart-detail-objectNested model via DETAILS_COMPONENT_TOKEN
arrayDetailArrayComponentsmart-detail-arrayArray of nested models
dateRangeDetailDateRangeComponentsmart-detail-date-rangestart – end
phoneNumberPlDetailPhoneNumberPlComponentsmart-detail-phone-number-plLink tel:48... as badge
imageDetailImageComponentsmart-detail-image<img> via FileService.getUrl(item[key].id)
logoDetailLogoComponentsmart-detail-logo<img> with item[key] as URL
videoDetailVideoComponentsmart-detail-video<video controls> via FileService
attachmentDetailAttachmentComponentsmart-detail-attachmentNative <button> Tailwind — download via FileService
pdfDetailPdfComponentsmart-detail-pdfNative <button> Tailwind — show via FileService

API

DetailComponent Inputs

InputTypeDefaultDescription
optionsInputSignal<IDetailOptions<T> | undefined>requiredField configuration
typeInputSignal<any>requiredModel class (used by ModelLabelPipe)
classInputSignal<string>''Classes forwarded to the field sub-component (cssClass input, alias class); the host is display: contents

IDetailOptions

FieldTypeDefaultDescription
keystringrequiredThe field key.
itemSignal<T>-The record. While it is missing or returns nothing, the wrapper shows a skeleton instead of the value.
optionsIFieldOptionsrequiredThe field's @Field options: type picks the sub-component (text when unset or unmapped), info adds an info tooltip.
cellPipeICellPipe<T>-Formats the value. Read by the text and phoneNumberPl sub-components (standard and preset).
loadingSignal<boolean>-Not read by the built-in implementations; available to a custom implementation.

IFieldOptions comes from @smartsoft001/models (the @Field decorator options); the wrapper reads its type and info.

DETAIL_FIELD_COMPONENTS_TOKEN

InjectionToken<Partial<Record<FieldTypeDef, Type<DetailBaseComponent<any>>>>> — allows substituting a sub-component for any field type.

Maps are merged ({ ...baseMap, ...extendMap }), so only selected types need to be overridden.

HTML in text fields

The text sub-component and its preset bind the value through [innerHTML] WITHOUT TrustHtmlPipe, so Angular's sanitizer runs on every value, including one returned by a cellPipe. Scripts, event handlers (onerror, onload), <iframe>, <svg> and javascript: URLs are removed, while basic formatting (<b>, <em>, <a href="https://...">) survives.

The sanitizer also strips inline style attributes, for example the colours and alignment the rich-text editor writes. A consumer who needs raw HTML for a field it trusts can return SafeHtml from its own cellPipe (ICellPipe.transform is typed as string, so cast the result). A tested version, TrustedDescriptionCellPipe, lives in docs/examples/angular/src/components/detail/trusted-html.example.ts.

Preline field presets

Fifteen field types ship a Preline-styled preset (Detail<Field>PresetComponent, selector smart-detail-<field>-preset) alongside the default sub-component, living in <field>/preset/:

FieldTypePresetLook
emailDetailEmailPresetComponentmailto: link, blue + hover:underline, envelope icon
enumDetailEnumPresetComponentValues as soft blue badges (reuses badge preset recipes)
flagDetailFlagPresetComponentSoft badge — green ✓ / red ✗ (reuses badge preset recipes)
colorDetailColorPresetComponentsize-6 rounded swatch + monospace hex code
addressDetailAddressPresetComponentMulti-line text-sm block with pin icon
dateRangeDetailDateRangePresetComponentstart – end as two soft gray chips
phoneNumberPlDetailPhoneNumberPlPresetComponenttel: link styled as a soft blue badge
logoDetailLogoPresetComponent<img> max-h-10 object-contain
imageDetailImagePresetComponent150×150 preview, rounded-xl, border + shadow-2xs
videoDetailVideoPresetComponent<video controls> framed rounded-xl border + shadow-2xs
attachmentDetailAttachmentPresetComponentFile chip: icon, file name (fileName/name), download
pdfDetailPdfPresetComponentFile chip: red PDF icon, file name, show button
textDetailTextPresetComponenttext-sm typography, text-pretty; em-dash when empty
objectDetailObjectPresetComponentCard envelope around the untouched nested details
arrayDetailArrayPresetComponentspace-y-2 stack of item cards; em-dash when empty

Apply them all by providing the ready-made partial map DETAIL_PRESET_FIELD_COMPONENTS for DETAIL_FIELD_COMPONENTS_TOKEN, or register every preset of the library at once with provideSmartPresets().

Notes on the preset map:

  • The map is partial — all other field types keep their standard components (maps merge over baseMap). Registering text in the map does NOT change the fallback for unmapped/unknown types — the map is keyed per FieldType, so those still fall back to the standard DetailTextComponent.
  • Unlike their standard components, the text and array presets render an em-dash placeholder when the value is empty (the standard components collapse to nothing).
  • The presets have a fixed look; IDetailOptions carries no per-field style channel (deliberate, matches the fidelity-gap deferral from the Preline group).

Extending the base class

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

import {
  DetailBaseComponent,
  DetailComponent,
  DETAIL_FIELD_COMPONENTS_TOKEN,
  IDetailOptions,
} from '@smartsoft001/angular';
import { Field, FieldType, Model } from '@smartsoft001/models';

/**
 * A custom renderer for one detail field, built on `DetailBaseComponent`.
 *
 * The base supplies the `options` input (key, item signal, field metadata) and
 * the `class` input, and re-runs `afterSetOptionsHandler()` whenever the
 * options change. Everything else is the implementation's own template.
 */
@Component({
  selector: 'docs-custom-detail-text',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `<p [class]="classes()">{{ value() }}</p>`,
})
export class CustomDetailTextComponent extends DetailBaseComponent<
  Record<string, unknown>
> {
  value = computed(() => {
    const options = this.options();
    const item = options?.item?.();
    if (!options || !item) return '';
    return String(item[options.key] ?? '');
  });

  // `cssClass` comes from the base (alias `class`): smart-detail forwards the
  // consumer's class to the field component.
  classes = computed(() =>
    ['docs-detail-text', this.cssClass()].filter(Boolean).join(' '),
  );
}

@Model({})
class ApplicantModel {
  @Field({ details: true, type: FieldType.text })
  name = 'Margot Foster';
}

/**
 * `<smart-detail>` chooses the renderer from the field's `type`, so a custom
 * implementation is registered per FieldType through
 * `DETAIL_FIELD_COMPONENTS_TOKEN`. Entries are merged over the built-in map,
 * so only the listed types change.
 */
@Component({
  selector: 'docs-detail-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DetailComponent],
  providers: [
    {
      provide: DETAIL_FIELD_COMPONENTS_TOKEN,
      useValue: { [FieldType.text]: CustomDetailTextComponent },
    },
  ],
  template: `
    <smart-detail
      [type]="type"
      [options]="options"
      [class]="'docs-detail-text--demo'"
    />
  `,
})
export class DetailCustomExampleComponent {
  type = ApplicantModel;

  options: IDetailOptions<ApplicantModel> = {
    key: 'name',
    options: { type: FieldType.text },
    item: signal(new ApplicantModel()),
  };
}

Source

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

SmartDetail shows one field of a model instance read-only: the field's label (the label provider's, or MODEL.<key> translated), its info tooltip, and the value rendered by the detail component of the field's FieldType, or a skeleton while there is no item yet. SmartDetails renders one SmartDetail per field marked details, so most applications use it indirectly; render it yourself to place single fields. Detail components are resolved from detailFieldComponents on SmartProvider over the library's own (DETAIL_PRESET_FIELD_COMPONENTS gives the styled set); a type without one renders SmartDetailText.


Usage

import { Field, FieldType, Model } from '@smartsoft001/models';
import { IDetailOptions, SmartDetail } from '@smartsoft001/react';

// Each label is the `MODEL.<key>` translation: the library's dictionary
// already has `firstName` and `email`.
@Model({})
class ApplicantModel {
  id = 'applicant-1';

  @Field({ details: true, type: FieldType.text })
  firstName = 'Margot';

  @Field({ details: true, type: FieldType.email })
  email = 'margot@example.com';
}

const applicant = new ApplicantModel();

const firstNameOptions: IDetailOptions<ApplicantModel> = {
  key: 'firstName',
  options: { type: FieldType.text },
  item: applicant,
};

const emailOptions: IDetailOptions<ApplicantModel> = {
  key: 'email',
  options: { type: FieldType.email },
  item: applicant,
};

export function DetailUsageExample() {
  return (
    <>
      <SmartDetail type={ApplicantModel} options={firstNameOptions} />
      <SmartDetail type={ApplicantModel} options={emailOptions} />
    </>
  );
}

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
SmartDetailcomponentThe label of a field and its value, rendered by the detail component of the field type, with the field's info tooltip and a skeleton while there is no item yet.
SmartDetailTextcomponentThe text detail: the value of the field, or what options.cellPipe makes of it, rendered as HTML.
useDetailhookWhat every detail field shares: the item, the key of the field and its value, unwrapped from options.
useDetailCellValuehookThe value a text-like detail renders: the list cell of key in item, the cell pipe's result (or the raw value), translated when it is a string.
getDefaultDetailFieldComponentsfunctionThe library's detail component of every FieldType that has one.
DETAIL_PRESET_FIELD_COMPONENTSconstThe preset detail components, keyed by FieldType.
SmartDetail<Type> / SmartDetail<Type>PresetcomponentThe standard and preset detail component of each field type (see Field types below), e.g. SmartDetailEmail, SmartDetailEmailPreset.
useDetailAddresshookThe address of an address field (null without one) and its building[/flat] part.
useDetailArrayhookchildOptions: the SmartDetails options of each element of an array field, typed by the element's class.
useDetailAttachmenthookfileName (fileName or name of the file, null without either) and download(), which opens the file through the file service.
useDetailEnumhookvalues: the value of an enum field, or each of its values when it is an array, as strings.
useDetailImagehookimageUrl: the file service URL of the file in an image field, null without one.
useDetailObjecthookchildOptions: the SmartDetails options of the nested object of an object field, null without one.
useDetailPdfhookfileName and show(), which opens the PDF through the file service.
useDetailVideohookurl: the file service URL of the video in the field, null without one.

Props and Types

SmartDetailProps<T = any>

PropTypeDefaultDescription
optionsIDetailOptions<T> | undefinedrequiredThe field to show: key, item, field options and cell pipe.
typeanyrequiredThe model class, for the label (useModelLabel).
className?string—Forwarded to the field component.

SmartDetailFieldProps<T = any>

The props of every detail field component: options and className.

PropTypeDefaultDescription
options?IDetailOptions<T>—The detail options SmartDetail received.
className?string—The className of SmartDetail.

IDetailOptions<T>

FieldTypeDefaultDescription
keystringrequiredThe field key.
item?T | null—The record; null / undefined shows a skeleton.
optionsIFieldOptionsrequiredThe field's @Field options (getModelFieldOptions(instance, key), or the options of getModelFieldsWithOptions).
cellPipe?ICellPipe<T>—Formats the value; read by the text and phoneNumberPl details (standard and preset).
loading?boolean—Not read by the built-in implementations; available to a custom implementation (useDetail returns it).

ICellPipe<T>

Formats a value: transform(item, key, translate?) returns text (sanitised before it is rendered as HTML) or trustHtml(html) (rendered as is).

FieldTypeDefaultDescription
transform(value: T, columnName: string, translate?: (val: string) => string) => string | SmartTrustedHtmlrequiredThe text of a cell. Markup in it is sanitised before it is rendered; return trustHtml(html) to render markup you vouch for as is.
  • SmartDetailFieldComponents: Partial< Record<FieldTypeDef, ComponentType<SmartDetailFieldProps<any>>> > — Detail components by FieldType.

Field types

FieldTypeStandardPreset
text (and every type without its own)SmartDetailText: the value, or the cell pipe's result, translated when a string, as sanitised HTMLSmartDetailTextPreset (em dash when empty)
emailSmartDetailEmail: a mailto: linkSmartDetailEmailPreset
phoneNumberPlSmartDetailPhoneNumberPl: a tel: link with the 48 prefixSmartDetailPhoneNumberPlPreset
enumSmartDetailEnum: the translated value(s), comma-separatedSmartDetailEnumPreset (a badge each)
flagSmartDetailFlag: a check or an x-markSmartDetailFlagPreset
colorSmartDetailColor: a colour barSmartDetailColorPreset (swatch and code)
dateRangeSmartDetailDateRange: start – endSmartDetailDateRangePreset
addressSmartDetailAddress: street and building / flat, zip code and citySmartDetailAddressPreset
image / logoSmartDetailImage (the uploaded file's URL) / SmartDetailLogo (the URL in the field)…Preset
pdf / video / attachmentSmartDetailPdf (show button) / SmartDetailVideo (mp4 player) / SmartDetailAttachment (download button)…Preset
objectSmartDetailObject: the nested object's own SmartDetailsSmartDetailObjectPreset (in a card)
arraySmartDetailArray: a SmartDetails per elementSmartDetailArrayPreset (a card each)

File-based details (image, pdf, video, attachment) build their URLs with the file service: give SmartProvider a fileServiceConfig.

Sanitised HTML

Text details render the value as HTML sanitised with DOMPurify. A cell pipe that returns trustHtml(html) opts out for markup you vouch for (trustHtml, sanitizeHtml and toInnerHtml are exported from @smartsoft001/react).

Replacing the Implementation

SmartDetail has no single registry key: its field components come from detailFieldComponents on SmartProvider, merged over the library's map. Register the preset set, or a component of your own for one type.

SMART_PRESET_COMPONENTS registers DETAIL_PRESET_FIELD_COMPONENTS together with the other presets. The object and array details render nested objects through SmartDetails, so the details registry key applies to them too.

Hooks

useDetail

What every detail field shares: the item, the key of the field and its value, unwrapped from options.

ReturnsTypeDescription
itemNonNullable<T> | nulloptions.item, null without one.
keystring | nulloptions.key.
valueanyitem[key].
cellPipeICellPipe<T> | nulloptions.cellPipe, null without one.
fieldOptionsIFieldOptions | nulloptions.options.
loadingboolean | undefinedoptions.loading.

useDetailCellValue

The value a text-like detail renders: the list cell of key in item, the cell pipe's result (or the raw value), translated when it is a string.

import { Field, FieldType, Model } from '@smartsoft001/models';
import {
  IDetailOptions,
  SmartDetail,
  SmartDetailFieldProps,
  SmartProvider,
  useDetail,
} from '@smartsoft001/react';

/**
 * A custom renderer for one detail field, built on `useDetail`.
 *
 * The hook unwraps the item, the field key and its value from `options`;
 * `SmartDetail` passes the consumer's `className` on. Everything else is the
 * implementation's own markup.
 */
export function CustomDetail(props: SmartDetailFieldProps) {
  const { value } = useDetail(props);

  return (
    <p
      className={['docs-detail-text', props.className]
        .filter(Boolean)
        .join(' ')}
    >
      {String(value ?? '')}
    </p>
  );
}

@Model({})
class ApplicantModel {
  @Field({ details: true, type: FieldType.text })
  name = 'Margot Foster';
}

// <SmartDetail> picks the renderer by the field's `type`, so a custom one is
// registered per FieldType through `detailFieldComponents`. The entries are
// merged over the built-in map, so only the listed types change. A module
// constant: a new object on every render would change the context.
const detailFieldComponents = { [FieldType.text]: CustomDetail };

const options: IDetailOptions<ApplicantModel> = {
  key: 'name',
  options: { type: FieldType.text },
  item: new ApplicantModel(),
};

export function DetailCustomExample() {
  return (
    <SmartProvider detailFieldComponents={detailFieldComponents}>
      <SmartDetail
        type={ApplicantModel}
        options={options}
        className="docs-detail-text--demo"
      />
    </SmartProvider>
  );
}

Styling

  • SmartDetail renders the label in a muted smart:text-sm span and a pulsing skeleton without an item, with smart:dark: variants; className reaches the field component.

Source

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