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 configurationcssClass: InputSignal<string>(aliasclass) — external CSS classesafterSetOptionsHandler()— hook invoked via effect on options change- Effect that calls
ChangeDetectorRef.detectChanges()when options change
Default Sub-Components
| FieldType | Sub-component | Selector | Description |
|---|---|---|---|
text | DetailTextComponent | smart-detail-text | Sanitized HTML via ListCellPipe, fallback for unknown types |
email | DetailEmailComponent | smart-detail-email | Link mailto: |
enum | DetailEnumComponent | smart-detail-enum | Single value or array with translate |
flag | DetailFlagComponent | smart-detail-flag | Inline SVG ✓ / ✗ |
color | DetailColorComponent | smart-detail-color | Rectangle with background-color |
address | DetailAddressComponent | smart-detail-address | IAddress (street, number, zip, city) |
object | DetailObjectComponent | smart-detail-object | Nested model via DETAILS_COMPONENT_TOKEN |
array | DetailArrayComponent | smart-detail-array | Array of nested models |
dateRange | DetailDateRangeComponent | smart-detail-date-range | start – end |
phoneNumberPl | DetailPhoneNumberPlComponent | smart-detail-phone-number-pl | Link tel:48... as badge |
image | DetailImageComponent | smart-detail-image | <img> via FileService.getUrl(item[key].id) |
logo | DetailLogoComponent | smart-detail-logo | <img> with item[key] as URL |
video | DetailVideoComponent | smart-detail-video | <video controls> via FileService |
attachment | DetailAttachmentComponent | smart-detail-attachment | Native <button> Tailwind — download via FileService |
pdf | DetailPdfComponent | smart-detail-pdf | Native <button> Tailwind — show via FileService |
API
DetailComponent Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IDetailOptions<T> | undefined> | required | Field configuration |
type | InputSignal<any> | required | Model class (used by ModelLabelPipe) |
class | InputSignal<string> | '' | Classes forwarded to the field sub-component (cssClass input, alias class); the host is display: contents |
IDetailOptions
| Field | Type | Default | Description |
|---|---|---|---|
key | string | required | The field key. |
item | Signal<T> | - | The record. While it is missing or returns nothing, the wrapper shows a skeleton instead of the value. |
options | IFieldOptions | required | The field's @Field options: type picks the sub-component (text when unset or unmapped), info adds an info tooltip. |
cellPipe | ICellPipe<T> | - | Formats the value. Read by the text and phoneNumberPl sub-components (standard and preset). |
loading | Signal<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/:
| FieldType | Preset | Look |
|---|---|---|
email | DetailEmailPresetComponent | mailto: link, blue + hover:underline, envelope icon |
enum | DetailEnumPresetComponent | Values as soft blue badges (reuses badge preset recipes) |
flag | DetailFlagPresetComponent | Soft badge — green ✓ / red ✗ (reuses badge preset recipes) |
color | DetailColorPresetComponent | size-6 rounded swatch + monospace hex code |
address | DetailAddressPresetComponent | Multi-line text-sm block with pin icon |
dateRange | DetailDateRangePresetComponent | start – end as two soft gray chips |
phoneNumberPl | DetailPhoneNumberPlPresetComponent | tel: link styled as a soft blue badge |
logo | DetailLogoPresetComponent | <img> max-h-10 object-contain |
image | DetailImagePresetComponent | 150×150 preview, rounded-xl, border + shadow-2xs |
video | DetailVideoPresetComponent | <video controls> framed rounded-xl border + shadow-2xs |
attachment | DetailAttachmentPresetComponent | File chip: icon, file name (fileName/name), download |
pdf | DetailPdfPresetComponent | File chip: red PDF icon, file name, show button |
text | DetailTextPresetComponent | text-sm typography, text-pretty; em-dash when empty |
object | DetailObjectPresetComponent | Card envelope around the untouched nested details |
array | DetailArrayPresetComponent | space-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). Registeringtextin the map does NOT change the fallback for unmapped/unknown types — the map is keyed perFieldType, so those still fall back to the standardDetailTextComponent. - Unlike their standard components, the
textandarraypresets render an em-dash placeholder when the value is empty (the standard components collapse to nothing). - The presets have a fixed look;
IDetailOptionscarries 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.
| Export | Kind | What it is |
|---|---|---|
SmartDetail | component | The 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. |
SmartDetailText | component | The text detail: the value of the field, or what options.cellPipe makes of it, rendered as HTML. |
useDetail | hook | What every detail field shares: the item, the key of the field and its value, unwrapped from options. |
useDetailCellValue | hook | 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. |
getDefaultDetailFieldComponents | function | The library's detail component of every FieldType that has one. |
DETAIL_PRESET_FIELD_COMPONENTS | const | The preset detail components, keyed by FieldType. |
SmartDetail<Type> / SmartDetail<Type>Preset | component | The standard and preset detail component of each field type (see Field types below), e.g. SmartDetailEmail, SmartDetailEmailPreset. |
useDetailAddress | hook | The address of an address field (null without one) and its building[/flat] part. |
useDetailArray | hook | childOptions: the SmartDetails options of each element of an array field, typed by the element's class. |
useDetailAttachment | hook | fileName (fileName or name of the file, null without either) and download(), which opens the file through the file service. |
useDetailEnum | hook | values: the value of an enum field, or each of its values when it is an array, as strings. |
useDetailImage | hook | imageUrl: the file service URL of the file in an image field, null without one. |
useDetailObject | hook | childOptions: the SmartDetails options of the nested object of an object field, null without one. |
useDetailPdf | hook | fileName and show(), which opens the PDF through the file service. |
useDetailVideo | hook | url: the file service URL of the video in the field, null without one. |
Props and Types
SmartDetailProps<T = any>
| Prop | Type | Default | Description |
|---|---|---|---|
options | IDetailOptions<T> | undefined | required | The field to show: key, item, field options and cell pipe. |
type | any | required | The 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.
| Prop | Type | Default | Description |
|---|---|---|---|
options? | IDetailOptions<T> | — | The detail options SmartDetail received. |
className? | string | — | The className of SmartDetail. |
IDetailOptions<T>
| Field | Type | Default | Description |
|---|---|---|---|
key | string | required | The field key. |
item? | T | null | — | The record; null / undefined shows a skeleton. |
options | IFieldOptions | required | The 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).
| Field | Type | Default | Description |
|---|---|---|---|
transform | (value: T, columnName: string, translate?: (val: string) => string) => string | SmartTrustedHtml | required | The text of a cell. Markup in it is sanitised before it is rendered; return trustHtml(html) to render markup you vouch for as is. |
Related types
SmartDetailFieldComponents:Partial< Record<FieldTypeDef, ComponentType<SmartDetailFieldProps<any>>> >— Detail components byFieldType.
Field types
FieldType | Standard | Preset |
|---|---|---|
text (and every type without its own) | SmartDetailText: the value, or the cell pipe's result, translated when a string, as sanitised HTML | SmartDetailTextPreset (em dash when empty) |
email | SmartDetailEmail: a mailto: link | SmartDetailEmailPreset |
phoneNumberPl | SmartDetailPhoneNumberPl: a tel: link with the 48 prefix | SmartDetailPhoneNumberPlPreset |
enum | SmartDetailEnum: the translated value(s), comma-separated | SmartDetailEnumPreset (a badge each) |
flag | SmartDetailFlag: a check or an x-mark | SmartDetailFlagPreset |
color | SmartDetailColor: a colour bar | SmartDetailColorPreset (swatch and code) |
dateRange | SmartDetailDateRange: start – end | SmartDetailDateRangePreset |
address | SmartDetailAddress: street and building / flat, zip code and city | SmartDetailAddressPreset |
image / logo | SmartDetailImage (the uploaded file's URL) / SmartDetailLogo (the URL in the field) | …Preset |
pdf / video / attachment | SmartDetailPdf (show button) / SmartDetailVideo (mp4 player) / SmartDetailAttachment (download button) | …Preset |
object | SmartDetailObject: the nested object's own SmartDetails | SmartDetailObjectPreset (in a card) |
array | SmartDetailArray: a SmartDetails per element | SmartDetailArrayPreset (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.
| Returns | Type | Description |
|---|---|---|
item | NonNullable<T> | null | options.item, null without one. |
key | string | null | options.key. |
value | any | item[key]. |
cellPipe | ICellPipe<T> | null | options.cellPipe, null without one. |
fieldOptions | IFieldOptions | null | options.options. |
loading | boolean | undefined | options.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
SmartDetailrenders the label in a mutedsmart:text-smspan and a pulsing skeleton without an item, withsmart:dark:variants;classNamereaches 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.