Details
The <smart-details> component renders a list of model fields decorated with @Field({ details: true }). It is a wrapper that delegates to DetailsStandardComponent by default and can be replaced via DETAILS_STANDARD_COMPONENT_TOKEN.
Usage
<smart-details [options]="options" />
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
DetailsComponent (<smart-details>)
Main wrapper. Renders DetailsStandardComponent by default. When DETAILS_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet, passing options and the class value as inputs (under class when the component keeps the base's alias, cssClass when it redeclares the input).
DetailsStandardComponent (<smart-details-standard>)
Default concrete implementation. Generic Tailwind-styled <dl> placeholder that iterates over fields and renders each via <smart-detail>.
DetailsBaseComponent (abstract)
Abstract base directive. Extend it to build custom details implementations. It exposes:
fields: the fields ofoptions.typemarked@Field({ details }), without those whosedetails.permissionsthe user lacks and those whoseenabledspecification (details.enabled, else the field'senabled) the item fails; a specification can refer to the outermost details' item as$roottype:options.typeitem: aSignalofoptions.item()converted to an instance ofoptions.typeloading:options.loadingcellPipe: aWritableSignalofoptions.cellPipe(nullwithout one)componentFactories:options.componentFactories(nullwithout them), created in the#topTpl/#bottomTplview containers of the template
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IDetailsOptions<T> | undefined> | undefined | Details configuration |
class | InputSignal<string> | '' | Classes on the container (cssClass input, alias class) |
IDetailsOptions
| Field | Type | Default | Description |
|---|---|---|---|
type | any | required | The @Model class whose details fields are shown. |
item | Signal<T> | required | The record (a plain object is converted to type); while it returns nothing the fields show skeletons. |
cellPipe | ICellPipe<T> | - | Formats the values of the text and phoneNumberPl fields (see angular-components-detail). |
componentFactories | IDetailsComponentFactories<T> | - | Components created above (top) and below (bottom) the fields. |
loading | Signal<boolean> | - | Passed to every <smart-detail>; not read by the built-in implementations; available to a custom implementation. |
title | string | - | Not read by <smart-details>; DetailsPage uses it as the title of its pageOptions(). |
itemHandler | ((id: string) => void) | null | - | Not read by <smart-details>; DetailsPage turns it into a forward button of its pageOptions(). |
removeHandler | ((item: T) => void) | null | - | Not read by <smart-details>; DetailsPage turns it into a remove button of its pageOptions(). |
IDetailsComponentFactories<T> has two optional fields, top and bottom, each a Type<any> created without inputs.
DETAILS_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default DetailsStandardComponent with a custom implementation. Provide a Type<DetailsBaseComponent<T>>. There is no details preset: the field values follow the detail field components (DETAIL_PRESET_FIELD_COMPONENTS, registered by provideSmartPresets()).
Extending the base class
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import {
DetailsBaseComponent,
DetailsComponent,
DETAILS_STANDARD_COMPONENT_TOKEN,
IDetailsOptions,
} from '@smartsoft001/angular';
import { Field, Model } from '@smartsoft001/models';
@Model({})
class ApplicantModel {
id = 'applicant-1';
@Field({ details: true })
name = 'Margot Foster';
@Field({ details: true })
position = 'Backend Developer';
}
/**
* A custom details layout built on `DetailsBaseComponent`.
*
* The base reads the `@Field({ details: ... })` metadata off the model class
* given in `options.type` and exposes the result as `fields`, alongside the
* `item` and `loading` signals taken from the options. A custom implementation
* decides only how a row looks — here a flat definition list instead of the
* grid of the standard variation.
*/
@Component({
selector: 'docs-custom-details',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<dl class="docs-details">
@for (field of fields; track field.key) {
<div class="docs-details__row">
<dt>{{ field.key }}</dt>
<dd>{{ display(field.key) }}</dd>
</div>
}
</dl>
`,
})
export class CustomDetailsComponent extends DetailsBaseComponent<ApplicantModel> {
// `item` is a signal of the model instance, so values are read by field key.
display(key: string): string {
const item = this.item?.() as Record<string, unknown> | undefined;
return String(item?.[key] ?? '');
}
}
/**
* Registering the implementation against `DETAILS_STANDARD_COMPONENT_TOKEN`
* makes every `<smart-details>` in this injector render it instead of the
* standard variation.
*/
@Component({
selector: 'docs-details-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [DetailsComponent],
providers: [
{
provide: DETAILS_STANDARD_COMPONENT_TOKEN,
useValue: CustomDetailsComponent,
},
],
template: `<smart-details [options]="options" />`,
})
export class DetailsCustomExampleComponent {
options: IDetailsOptions<ApplicantModel> = {
type: ApplicantModel,
item: signal(new ApplicantModel()),
};
}
Details in a modal
DetailsPage (SharedPagesModule) renders <smart-details> of its value input full width, with the application style (StyleService.init) applied to its element; without a value it renders nothing. pageOptions() gives the page options for a page layout around it: the title (default details), a trash button for removeHandler and an arrow-forward-outline button for itemHandler; both call their handler with the current item and close the modal through ModalService.dismiss(). The page layout moved out of the library (FRA-121), so the page does not render these buttons itself.
The [smartDetails] directive (DetailsDirective) opens a component in a modal on click, through ModalService (see angular-components-modal), with its params as the value input. It emits smartDetailsShowed once the modal is open and smartDetailsDismissed once it is closed; the browser's back button (HardwareService.onBackButtonClick, the window's popstate) closes the modal as well. showDetailsModal(services, options, callbacks) does the same from code, and is what <smart-list> uses for its details option (see angular-components-list).
[smartDetails] field | Type | Default | Description |
|---|---|---|---|
component | any | required | Rendered in the modal, e.g. DetailsPage. |
params | any | required | Its value input, e.g. an IDetailsOptions. |
mode | 'bottom' | 'default' | 'bottom' | Passed to ModalService.show as mode; 'bottom' opens a bottom sheet. |
IDetailsOptions.item is a signal, so the page shows skeletons until the item is loaded and the fields once it is.
Field Rendering
Each field is rendered via <smart-detail>. The actual rendering of a single field by FieldType (text, email, address, image, attachment, …) is dispatched inside <smart-detail> itself. See the angular-components-detail skill for per-field details.
Source
The component lives in packages/shared/angular/src/lib/components/details and is documented for Claude Code by the angular-components-details skill.
SmartDetails shows a record read-only. It reads the fields of options.type marked @Field({ details: ... }), leaves out those whose details.permissions the user lacks and those whose enabled specification the item fails, converts options.item to an instance of the type, and renders one SmartDetail per field (a description list), between the optional componentFactories.top and bottom components. CRUD item pages render it in their details mode. SmartDetailsPage and useDetailsModal show the same view in a modal.
Usage
import { Field, FieldType, Model } from '@smartsoft001/models';
import { IDetailsOptions, SmartDetails } from '@smartsoft001/react';
// Each label is the `MODEL.<key>` translation: the library's dictionary
// already has `firstName`, `lastName` and `email`.
@Model({})
class Applicant {
id = 'applicant-1';
@Field({ details: true })
firstName = 'Margot';
@Field({ details: true })
lastName = 'Foster';
@Field({ details: true, type: FieldType.email })
email = 'margot.foster@example.com';
}
const options: IDetailsOptions<Applicant> = {
type: Applicant,
item: new Applicant(),
};
export function DetailsUsageExample() {
return <SmartDetails options={options} />;
}
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 |
|---|---|---|
SmartDetails | component | Renders the implementation registered as components.details on SmartProvider, SmartDetailsStandard by default. |
SmartDetailsStandard | component | The default details rendering: a description list with a <SmartDetail> per field, between the componentFactories.top and componentFactories.bottom components. |
useDetailsModal | hook | Returns a handler for an element's onClick that opens options.component in a modal with { value: options.params } as props (e.g. SmartDetailsPage with IDetailsOptions), and resolves once the modal is closed. |
useDetails | hook | The logic every details variant shares: - fields: the fields of options.type marked @Field({ details }), without those whose details.permissions the user lacks and those whose enabled specification (details.enabled, else the field's enabled) the item fails; a specification can refer to the outermost details' item as $root; - item: options.item as an instance of options.type (a plain API object is converted); - loading, cellPipe and componentFactories from the options. |
Props and Types
SmartDetailsProps<T extends IEntity<string> = any>
| Prop | Type | Default | Description |
|---|---|---|---|
options? | IDetailsOptions<T> | — | The model type, the record and the extras. |
className? | string | — | Classes on the root element. |
IDetailsModalOptions
What useDetailsModal opens: a component and its params.
| Field | Type | Default | Description |
|---|---|---|---|
component | ComponentType<any> | required | Rendered in the modal, with params as its value prop. |
params | any | required | Passed to the component as its value prop. |
mode? | 'bottom' | 'default' | 'bottom' | Passed to ModalService.show; 'bottom' opens a bottom sheet (the bottom-sheet variant) with the smart-modal-bottom class. |
IDetailsOptions<T extends IEntity<string>>
| Field | Type | Default | Description |
|---|---|---|---|
title? | string | — | Not rendered by SmartDetails; useDetailsPageOptions uses it as a page title. |
cellPipe? | ICellPipe<T> | — | Formats the values of text-like fields (see react-components-detail). |
type | any | required | The @Model class whose details fields are shown. |
item | T | null | undefined | required | The record (a plain API object is converted to type); without one the fields show skeletons. |
loading? | boolean | — | Passed to every SmartDetail; not read by the built-in implementations; available to a custom implementation. |
itemHandler? | ((id: string) => void) | null | — | Not rendered by SmartDetails; useDetailsPageOptions turns it into a "go to item" button. |
removeHandler? | ((item: T) => void) | null | — | Not rendered by SmartDetails; useDetailsPageOptions turns it into a remove button. |
componentFactories? | IDetailsComponentFactories<T> | — | Components rendered above (top) and below (bottom) the fields. |
UseDetailsModalCallbacks
Callbacks of useDetailsModal.
| Field | Type | Default | Description |
|---|---|---|---|
onShowed? | () => void | — | Once the modal is open. |
onDismissed? | () => void | — | Once the modal is closed. |
SmartDetailsField
A field useDetails shows.
| Field | Type | Default | Description |
|---|---|---|---|
key | string | required | The field key. |
options | IFieldOptions | required | The field's @Field options. |
ICellPipe<T>
Formats a value: transform(item, key, translate?) returns text (sanitised) 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. |
IDetailsComponentFactories<T>
| Field | Type | Default | Description |
|---|---|---|---|
top? | ComponentType<any> | — | Rendered above the fields (no props). |
bottom? | ComponentType<any> | — | Rendered below the fields (no props). |
Which fields are shown
- Fields with
details: trueordetails: { ... }in@Field, in declaration order. details.permissions: the field is left out when the signed-in user has none of them (AuthService.expectPermissions).details.enabled(else the field'senabled): a specification evaluated against the item; a nested details view can refer to the outermost item as$root.
In a modal
SmartList opens the same page for its details option, with the item loaded after the modal opened (see react-components-list). useDetailsModal({ component, params, mode? }, { onShowed?, onDismissed? }) returns a click handler that opens component in a modal through ModalService, with { value: params } as its props, and resolves once the modal closed. SmartDetailsPage is the component made for it: it renders SmartDetails of value full width, with the application style applied. useDetailsPageOptions(value) returns page options (title, a remove button for removeHandler, a forward button for itemHandler) for a page layout of your own around it.
Replacing the Implementation
SmartDetails renders the component registered under the 'details' key of SmartProvider's components, and SmartDetailsStandard when nothing is registered there. Every SmartDetails below the provider then renders the registered component, which receives the same props.
There is no preset for this component: register a component of your own that takes SmartDetailsProps, as shown below, as components={{ details: MyDetails }}. Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
Hooks
useDetailsModal
Returns a handler for an element's onClick that opens options.component in a modal with { value: options.params } as props (e.g. SmartDetailsPage with IDetailsOptions), and resolves once the modal is closed. Without options or options.component it does nothing.
useDetails
The logic every details variant shares:
fields: the fields ofoptions.typemarked@Field({ details }), without those whosedetails.permissionsthe user lacks and those whoseenabledspecification (details.enabled, else the field'senabled) the item fails; a specification can refer to the outermost details' item as$root;item:options.itemas an instance ofoptions.type(a plain API object is converted);loading,cellPipeandcomponentFactoriesfrom the options. The item becomes theDetailsServiceroot while rendering, before nested details evaluate their specifications (the service keeps the first root, so the outermost details win; React effects would run the innermost first).
| Returns | Type | Description |
|---|---|---|
fields | SmartDetailsField[] | null | The fields to show (null before they are resolved). |
type | any | options.type. |
item | T | null | undefined | The record as an instance of options.type. |
loading | boolean | undefined | options.loading. |
cellPipe | ICellPipe<T> | null | options.cellPipe, null without one. |
componentFactories | IDetailsComponentFactories<T> | null | options.componentFactories, null without them. |
import { Field, Model } from '@smartsoft001/models';
import {
IDetailsOptions,
SmartDetails,
SmartDetailsProps,
SmartProvider,
useDetails,
} from '@smartsoft001/react';
/**
* A custom details layout built on `useDetails`.
*
* The hook reads the `@Field({ details: ... })` metadata off the model class
* given in `options.type` and returns the result as `fields`, alongside the
* `item` and `loading` taken from the options. A custom implementation decides
* only how a row looks: here a flat definition list instead of the grid of the
* standard rendering.
*/
export function CustomDetails(props: SmartDetailsProps) {
const { fields, item } = useDetails(props);
return (
<dl className={['docs-details', props.className].filter(Boolean).join(' ')}>
{fields?.map((field) => (
<div key={field.key} className="docs-details__row">
<dt>{field.key}</dt>
{/* `item` is the model instance, so values are read by field key. */}
<dd>{String(item?.[field.key] ?? '')}</dd>
</div>
))}
</dl>
);
}
@Model({})
class ApplicantModel {
id = 'applicant-1';
@Field({ details: true })
name = 'Margot Foster';
@Field({ details: true })
position = 'Backend Developer';
}
// A module constant: a new object on every render would change the context.
const components = { details: CustomDetails };
const options: IDetailsOptions<ApplicantModel> = {
type: ApplicantModel,
item: new ApplicantModel(),
};
// Every <SmartDetails> below the provider renders CustomDetails.
export function DetailsCustomExample() {
return (
<SmartProvider components={components}>
<SmartDetails options={options} />
</SmartProvider>
);
}
Registered as components={{ details: CardDetails }}, it also renders nested object / array details and the details mode of CRUD item pages.
Styling
SmartDetailsStandardis a divided description list with a top border andsmart:dark:variants; the field values follow the registered detail field components (DETAIL_PRESET_FIELD_COMPONENTSfor the preset look).
Source
The component lives in packages/shared/react/src/lib/components/details and is documented for Claude Code by the react-components-details skill.