Modal
The <smart-modal> component provides a dialog overlay with title, description, an arbitrary projected body, and a list of action buttons. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract ModalBaseComponent defines the shared API — two-way open (ModelSignal<boolean>), optional title and description, actions (InputSignal<IModalAction[]>), optional IModalOptions, cssClass (alias class), actionClick and closed outputs, and invokeAction(actionId) / close() methods. ModalStandardComponent is a barebones placeholder concrete implementation. ModalComponent is the public wrapper that renders ModalStandardComponent by default and accepts a custom replacement via MODAL_STANDARD_COMPONENT_TOKEN.
Usage
<smart-button [options]="openButton">Deactivate account</smart-button>
<smart-modal
[(open)]="open"
title="Deactivate account"
description="Once the account is deactivated all of its data will be permanently removed."
[actions]="actions"
[options]="options"
(actionClick)="onActionClick($event)"
(closed)="onClosed()"
/>
<p>Last action: {{ lastAction() ?? 'none' }}</p>
<p>Closed by the user: {{ closedCount() }}</p>
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
ModalComponent (<smart-modal>)
Main wrapper component. Renders ModalStandardComponent by default. When MODAL_STANDARD_COMPONENT_TOKEN is provided (or provideSmartPresets() registers the preset), renders the injected component via NgComponentOutlet and forwards its inputs, its projected content, the actionClick and closed outputs and the open model changes. A footer action keeps the modal open: set open to false in the (actionClick) handler.
ModalStandardComponent (<smart-modal-standard>)
Barebones placeholder concrete implementation. Renders a native <dialog [open] role="dialog" aria-modal="true"> containing an optional <h2 id="smart-modal-title">, an optional <p> description, an <ng-content> slot for arbitrary body content, an optional dismiss <button> (when options.withDismiss is true), and a <footer> with one <button data-variant> per action. The dialog carries options.variant as data-variant. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token — except for the bottom-sheet variant, which it docks to the bottom of the viewport (see the Variants table).
ModalPresetComponent (<smart-modal-preset>)
Styled variation that extends ModalBaseComponent and is a drop-in replacement for ModalStandardComponent. Register it via MODAL_STANDARD_COMPONENT_TOKEN (or with provideSmartPresets()) to restyle every <smart-modal>, or use the <smart-modal-preset> selector directly. It renders a translated Preline overlay — a full-screen scrollable backdrop hosting a rounded-xl card with a header (title + optional dismiss ×), a body (description + projected content), and a footer of action buttons. The look is selected through options.variant (default 'centered'): centered/alert are vertically centered (alert is narrower), wide is a top-aligned large dialog, left-aligned-buttons left-aligns the footer, and bottom-sheet docks the card to the bottom of the viewport (see the Variants table). options.footerStyle: 'gray' tints the footer, and action buttons are styled by their variant (primary/secondary/danger). All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal to the preset (not exported).
Preline JS is NOT used. Open/close is driven entirely by the existing
openmodel signal +@if(noHSOverlay, nodata-hs-*). The component binds its own dismiss UX: clicking the backdrop and pressingEscapeboth callclose()(which setsopentofalseand emitsclosed). With preset modals stacked (a modal opened from a modal),Escapecloses only the one on top. The dialog ARIA contract is preserved (role="dialog",aria-modal="true",aria-labelledbywhentitleis set, elsearia-labelfromoptions.ariaLabel). The header dismiss×button is only shown whenoptions.withDismissistrue.
ModalPresetComponentdeclarescssClasswithout theclassalias (applied to the centering wrapper): bind it as[cssClass]on the<smart-modal-preset>selector, or passclasson<smart-modal>(the wrapper forwards it).
ModalBaseComponent (abstract)
Abstract base directive for extending custom modal implementations. Exposes open as a two-way ModelSignal<boolean>, title / description as optional InputSignal<string | undefined>, actions as InputSignal<IModalAction[]> (default []), options as InputSignal<IModalOptions | undefined>, cssClass as InputSignal<string> (with alias class), actionClick (payload IModalActionClick, exported from @smartsoft001/angular) and closed outputs, plus invokeAction(actionId) (emits actionClick) and close() (sets open to false and emits closed).
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
open | ModelSignal<boolean> | false | Visibility state (two-way bindable) |
title | InputSignal<string | undefined> | - | Dialog heading (also sets aria-labelledby) |
description | InputSignal<string | undefined> | - | Optional secondary description text |
actions | InputSignal<IModalAction[]> | [] | Action buttons rendered in the footer |
options | InputSignal<IModalOptions | undefined> | - | Optional configuration |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
Outputs
| Output | Payload | Description |
|---|---|---|
actionClick | IModalActionClick ({ actionId: string }) | Fired when a footer action is clicked |
closed | void | Fired when the dialog is dismissed/closed |
IModalAction
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as actionId by actionClick. |
label | string | required | Button text. |
variant | 'primary' | 'secondary' | 'danger' | 'primary' | The standard exposes it as data-variant on the button; the preset styles the button by it. |
IModalOptions
| Field | Type | Default | Description |
|---|---|---|---|
variant | SmartModalVariant | 'centered' | The layout, one of the variants in the Variants table. The preset styles each of them; the standard exposes it as data-variant and positions only bottom-sheet. |
withDismiss | boolean | false | Renders a close (×) button that calls close(). |
footerStyle | 'default' | 'gray' | 'default' | Preset only: gray gives the footer a gray background. |
ariaLabel | string | - | The aria-label of the dialog when there is no title. |
The default ModalStandardComponent consumes withDismiss and ariaLabel, exposes variant as data-variant on the dialog and positions the bottom-sheet variant; footerStyle is read by ModalPresetComponent only. A custom implementation receives every field.
Variants
SmartModalVariant (from @smartsoft001/angular) names the layouts of options.variant.
| Variant | ModalPresetComponent | ModalStandardComponent |
|---|---|---|
centered (default) | A card centred vertically, max-w-lg from sm. | The browser's dialog layout. |
wide | A top-aligned card, max-w-4xl from lg. | The browser's dialog layout. |
alert | A narrower centred card, max-w-md from sm. | The browser's dialog layout. |
left-aligned-buttons | Like centered, with the footer buttons aligned to the left. | The browser's dialog layout. |
bottom-sheet | A sheet docked to the bottom of the viewport: full width, centred under max-w-2xl with rounded top corners from sm, at most 85% of the viewport high with the body scrolling, padded by the bottom safe area. Same backdrop, Escape and close button as the others. | The <dialog> fixed to the bottom of the viewport (z-[80]), full width, max-w-2xl with rounded top corners from sm, at most 85% of the viewport high and scrolling. |
MODAL_STANDARD_COMPONENT_TOKEN
InjectionToken from @smartsoft001/angular that allows replacing the default ModalStandardComponent with a custom implementation. Provide a Type<ModalBaseComponent> in your application or component providers; provideSmartPresets() provides ModalPresetComponent for it together with every other preset.
Content projection
ModalStandardComponent accepts arbitrary body content via <ng-content> and the wrapper forwards its own <ng-content> into the standard. When a custom component is registered via the token, the wrapper passes the same content to the custom component's default <ng-content> slot (ModalPresetComponent renders it in its body), wrapped in one display: contents element: selectors on the slot's parent that target its direct children (space-y-*, divide-*, > *) do not reach the projected nodes.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
IModalAction,
IModalOptions,
MODAL_STANDARD_COMPONENT_TOKEN,
ModalBaseComponent,
ModalComponent,
} from '@smartsoft001/angular';
/**
* A custom modal built on `ModalBaseComponent`.
*
* The base contributes the `open` model plus the `invokeAction(id)` and
* `close()` helpers, which already emit `actionClick` and `closed`. The base
* binds no keyboard or backdrop listeners, so the implementation wires the
* backdrop click itself.
*/
@Component({
selector: 'docs-custom-modal',
template: `
@if (open()) {
<div class="docs-modal__backdrop" (click)="close()"></div>
<div
role="dialog"
aria-modal="true"
[attr.aria-label]="options()?.ariaLabel ?? title()"
[class]="containerClasses()"
>
@if (options()?.withDismiss) {
<button
type="button"
class="docs-modal__dismiss"
aria-label="Close"
(click)="close()"
>
×
</button>
}
@if (title()) {
<h2 class="docs-modal__title">{{ title() }}</h2>
}
@if (description()) {
<p class="docs-modal__description">{{ description() }}</p>
}
<!-- The content of <smart-modal> is projected here. -->
<div class="docs-modal__body">
<ng-content />
</div>
<footer [class]="footerClasses()">
@for (action of actions(); track action.id) {
<button
type="button"
class="docs-modal__action"
[attr.data-variant]="action.variant ?? 'primary'"
(click)="invokeAction(action.id)"
>
{{ action.label }}
</button>
}
</footer>
</div>
}
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomModalComponent extends ModalBaseComponent {
containerClasses = computed(() => {
const classes = ['docs-modal'];
const variant = this.options()?.variant;
if (variant) classes.push(`docs-modal--${variant}`);
const extra = this.cssClass();
if (extra) classes.push(extra);
return classes.join(' ');
});
footerClasses = computed(() =>
[
'docs-modal__footer',
`docs-modal__footer--${this.options()?.footerStyle ?? 'default'}`,
].join(' '),
);
}
/**
* Registering the implementation against `MODAL_STANDARD_COMPONENT_TOKEN`
* makes every `<smart-modal>` in this injector render it instead of the
* standard variation. The wrapper forwards its inputs, its content and the
* implementation's `actionClick`, `closed` and `open` changes.
*/
@Component({
selector: 'docs-modal-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ModalComponent],
providers: [
{ provide: MODAL_STANDARD_COMPONENT_TOKEN, useValue: CustomModalComponent },
],
template: `
<smart-modal
[open]="true"
title="Deactivate account"
description="Once the account is deactivated all of its data will be permanently removed."
[actions]="actions"
[options]="options"
(actionClick)="lastAction.set($event.actionId)"
>
<p>Your invoices stay available for 30 days.</p>
</smart-modal>
<p class="docs-modal__last-action">
Last action: {{ lastAction() ?? 'none' }}
</p>
`,
})
export class ModalCustomExampleComponent {
lastAction = signal<string | null>(null);
actions: IModalAction[] = [
{ id: 'cancel', label: 'Cancel', variant: 'secondary' },
{ id: 'deactivate', label: 'Deactivate', variant: 'danger' },
];
options: IModalOptions = {
variant: 'centered',
footerStyle: 'gray',
withDismiss: true,
};
}
Opening a component in a modal from code
ModalService.show(options) (provided by SharedServicesModule) creates options.component inside a <smart-modal> at the end of <body> and resolves with an IModal. The modal is the implementation registered for MODAL_STANDARD_COMPONENT_TOKEN (the preset with provideSmartPresets()) and shows its close button (withDismiss). props become the component's inputs (keys it does not declare as inputs are left out), and a component that declares a dismiss input gets the function that closes its modal. A component can also inject ModalService and call dismiss(data): it resolves to the service that opened it. The modals stack; ModalService.dismiss(data) closes the one opened last. Closing a modal restores the focus to the element focused before it opened.
| Option | Type | Default | Description |
|---|---|---|---|
component | any | required | The component rendered in the modal. |
props | any | - | Its inputs, by input name. |
mode | 'default' | 'bottom' | 'default' | 'bottom' opens the modal as a bottom sheet (the bottom-sheet variant, see the Variants table) and adds the smart-modal-bottom class for an application's own styling; the modal element carries data-mode. |
cssClass | string[] | - | Classes passed to the modal as class. |
backdropDismiss | boolean | true | false keeps the modal open on a click on its backdrop and on Escape; its close button and dismiss() still close it. |
injector | Injector | - | The injector the component resolves its dependencies from (e.g. the opener's inject(Injector)), the service's otherwise. |
IModal member | Type | Description |
|---|---|---|
dismiss(data?) | (data?: any) => void | Closes the modal. |
onDidDismiss() | () => Promise<{ data: any }> | Resolves once the modal is closed, with the data it was closed with; { data: null } for its close button, the backdrop or Escape. |
[smartDetails] and DetailsPage (see angular-components-details) open details through the same service, as a bottom sheet by default; so does the details option of <smart-list>.
Source
The component lives in packages/shared/angular/src/lib/components/modal and is documented for Claude Code by the angular-components-modal skill.
SmartModal is a dialog with a title, a description, a body (children) and footer buttons (actions). A footer button reports onActionClick({ actionId }) and keeps the modal open: close it yourself (set open to false). The open state is controlled (open + onOpenChange) or kept inside (defaultOpen); closing through the dismiss button, the backdrop or Escape calls onClosed. SmartModalStandard is a native <dialog> shown through its open attribute; SmartModalPreset is a styled overlay with five variants, one of them a bottom sheet (bottom-sheet), which the standard docks to the bottom of the viewport as well. The modal host of SmartProvider renders useModalService().show(...) requests through the same modal key.
Usage
import { useState } from 'react';
import {
IModalAction,
IModalActionClick,
IModalOptions,
SmartButton,
SmartModal,
} from '@smartsoft001/react';
const actions: IModalAction[] = [
{ id: 'cancel', label: 'Cancel', variant: 'secondary' },
{ id: 'deactivate', label: 'Deactivate', variant: 'danger' },
];
const options: IModalOptions = {
footerStyle: 'gray',
withDismiss: true,
};
export function ModalUsageExample() {
const [open, setOpen] = useState(false);
const [lastAction, setLastAction] = useState<string | null>(null);
const [closedCount, setClosedCount] = useState(0);
// A footer action keeps the modal open: close it here.
const onActionClick = ({ actionId }: IModalActionClick) => {
setLastAction(actionId);
setOpen(false);
};
return (
<>
<SmartButton options={{ click: () => setOpen(true) }}>
Deactivate account
</SmartButton>
<SmartModal
open={open}
onOpenChange={setOpen}
title="Deactivate account"
description="Once the account is deactivated all of its data will be permanently removed."
actions={actions}
options={options}
onActionClick={onActionClick}
onClosed={() => setClosedCount((count) => count + 1)}
/>
<p>Last action: {lastAction ?? 'none'}</p>
<p>Closed by the user: {closedCount}</p>
</>
);
}
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 |
|---|---|---|
SmartModal | component | Renders the implementation registered as components.modal on SmartProvider, SmartModalStandard by default. |
SmartModalPreset | component | Styled modal variation (preset). |
SmartModalStandard | component | The default modal rendering: a native <dialog> always in the DOM, shown through its open attribute (not showModal()). |
useModal | hook | The behaviour every modal variant shares: the open state, controlled through open / onOpenChange or kept internally from defaultOpen; invokeAction(id), which reports onActionClick without closing, and close(), which hides the modal and reports onClosed. |
The preset's class helpers (getModalWrapperClasses, getModalPanelClasses, getModalFooterClasses, getModalActionClasses, MODAL_BACKDROP, MODAL_HEADER, MODAL_TITLE, MODAL_DISMISS, MODAL_BODY, MODAL_DESCRIPTION) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartModalProps
| Prop | Type | Default | Description |
|---|---|---|---|
open? | boolean | — | Whether the modal is shown. Leave it undefined for an uncontrolled modal that starts from defaultOpen. |
defaultOpen? | boolean | false | Initial open of an uncontrolled modal. |
onOpenChange? | (open: boolean) => void | — | Called when the modal opens or closes. |
title? | string | — | Heading of the dialog. |
description? | string | — | Text under the heading. |
actions? | IModalAction[] | [] | Footer buttons; a click reports onActionClick and keeps the modal open. |
options? | IModalOptions | — | Variant, dismiss button, footer style and accessible name. |
className? | string | — | Classes on the dialog (the wrapper in the preset). |
onActionClick? | (value: IModalActionClick) => void | — | Called with the id of the clicked footer action; the modal stays open. |
onClosed? | () => void | — | Called after the modal closed itself (dismiss button, backdrop, Escape, native close). |
children? | ReactNode | — | The modal body. |
IModalOptions
| Field | Type | Default | Description |
|---|---|---|---|
variant? | SmartModalVariant | 'centered' | The layout, one of the variants in the Variants table; the standard exposes it as data-variant and positions only bottom-sheet. |
withDismiss? | boolean | — | Shows a close (×) button that closes the modal. |
footerStyle? | SmartModalFooterStyle | 'default' | Preset: gray gives the footer a gray background. |
ariaLabel? | string | — | Accessible name when there is no title. |
Variants
The values of SmartModalVariant, the layouts of options.variant.
| Variant | SmartModalPreset | SmartModalStandard |
|---|---|---|
centered (default) | A card centred vertically, max-w-lg from sm. | The browser's dialog layout. |
wide | A top-aligned card, max-w-4xl from lg. | The browser's dialog layout. |
alert | A narrower centred card, max-w-md from sm. | The browser's dialog layout. |
left-aligned-buttons | Like centered, with the footer buttons aligned to the left. | The browser's dialog layout. |
bottom-sheet | A sheet docked to the bottom of the viewport: full width, centred under max-w-2xl with rounded top corners from sm, at most 85% of the viewport high with the body scrolling, padded by the bottom safe area. Same backdrop, Escape and close button as the others. | The <dialog> fixed to the bottom of the viewport (z-[80]), full width, max-w-2xl with rounded top corners from sm, at most 85% of the viewport high and scrolling. |
IModalActionClick
Payload of onActionClick.
| Field | Type | Default | Description |
|---|---|---|---|
actionId | string | required | The id of the clicked action. |
IModalAction
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as actionId. |
label | string | required | Button text. |
variant? | SmartModalActionVariant | 'primary' | primary, secondary or danger; the standard exposes it as data-variant, the preset styles the button by it. |
Related types
SmartModalActionVariant:'primary' \| 'secondary' \| 'danger'SmartModalVariant:'centered' \| 'wide' \| 'alert' \| 'left-aligned-buttons' \| 'bottom-sheet'SmartModalFooterStyle:'default' \| 'gray'
Opening a component in a modal from code
useModalService().show({ component, props }) opens component inside a SmartModal with its close button, rendered by the modal host of SmartProvider (see react-components-overlays, which also describes mode, cssClass and backdropDismiss). mode: 'bottom' opens it as a bottom sheet (the bottom-sheet variant); SmartList opens its details that way. The component receives its props and a dismiss(data) prop; onDidDismiss() resolves with { data }, { data: null } when the modal closed itself. useModalService().dismiss(data) closes the modal opened last.
Replacing the Implementation
SmartModal renders the component registered under the 'modal' key of SmartProvider's components, and SmartModalStandard when nothing is registered there. Every SmartModal below the provider then renders the registered component, which receives the same props.
SmartModalPreset is the styled (preset) implementation: register it under the 'modal' key of SmartProvider's components, render it directly in place of SmartModal, 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.
The useModal hook
The behaviour every modal variant shares: the open state, controlled through open / onOpenChange or kept internally from defaultOpen; invokeAction(id), which reports onActionClick without closing, and close(), which hides the modal and reports onClosed.
| Returns | Type | Description |
|---|---|---|
open | boolean | The open state (controlled or internal). |
setOpen | (value: boolean) => void | Sets the state and calls onOpenChange. |
invokeAction | (actionId: string) => void | undefined | Reports onActionClick({ actionId }) without closing. |
close | () => void | Closes the modal, calls onOpenChange(false) and onClosed. |
import {
IModalAction,
IModalOptions,
SmartModal,
SmartModalProps,
SmartProvider,
useModal,
} from '@smartsoft001/react';
/**
* A custom modal built on `useModal`: the hook keeps the open state
* (controlled or from `defaultOpen`) and provides `invokeAction(id)` and
* `close()`, which already report `onActionClick` and `onClosed`. It binds no
* keyboard or backdrop listeners, so the implementation wires the backdrop
* click itself.
*/
export function CustomModal(props: SmartModalProps) {
const {
title,
description,
actions = [],
options,
className,
children,
} = props;
const { open, invokeAction, close } = useModal(props);
if (!open) return null;
const classes = [
'docs-modal',
options?.variant && `docs-modal--${options.variant}`,
className,
]
.filter(Boolean)
.join(' ');
return (
<>
<div className="docs-modal__backdrop" onClick={close} />
<div
role="dialog"
aria-modal="true"
aria-label={options?.ariaLabel ?? title}
className={classes}
>
{options?.withDismiss && (
<button
type="button"
className="docs-modal__dismiss"
aria-label="Close"
onClick={close}
>
×
</button>
)}
{title && <h2 className="docs-modal__title">{title}</h2>}
{description && (
<p className="docs-modal__description">{description}</p>
)}
{children}
<footer
className={`docs-modal__footer docs-modal__footer--${options?.footerStyle ?? 'default'}`}
>
{actions.map((action) => (
<button
key={action.id}
type="button"
className="docs-modal__action"
data-variant={action.variant ?? 'primary'}
onClick={() => invokeAction(action.id)}
>
{action.label}
</button>
))}
</footer>
</div>
</>
);
}
// A module constant: a new object on every render would change the context.
const components = { modal: CustomModal };
const actions: IModalAction[] = [
{ id: 'cancel', label: 'Cancel', variant: 'secondary' },
{ id: 'deactivate', label: 'Deactivate', variant: 'danger' },
];
const options: IModalOptions = {
variant: 'centered',
footerStyle: 'gray',
withDismiss: true,
};
/**
* Every `SmartModal` below this provider, and every modal opened through
* `ModalService.show`, renders `CustomModal` instead of the standard
* rendering.
*/
export function ModalCustomExample() {
return (
<SmartProvider components={components}>
<SmartModal
defaultOpen
title="Deactivate account"
description="Once the account is deactivated all of its data will be permanently removed."
actions={actions}
options={options}
/>
</SmartProvider>
);
}
Registered as components={{ modal: CustomModal }}, it renders both the SmartModals placed by hand and the modals of ModalService.show (which pass open, className from cssClass, options with withDismiss: true and, for mode: 'bottom', variant: 'bottom-sheet', onClosed and the component as children). Lay out the bottom-sheet variant as a bottom sheet so those modals keep their look.
Styling
SmartModalStandardis always in the DOM as a<dialog>and shown through itsopenattribute; its nativecloseevent closes the modal too. The dialog carriesoptions.variantasdata-variant, action buttons their owndata-variant. Only thebottom-sheetvariant is positioned (fixed to the bottom of the viewport, full width up tomax-w-2xl, at most 85% of the viewport high and scrolling);classNamecomes after its classes.SmartModalPresetrenders inline with afixedbackdrop over the viewport; a click on the backdrop itself or Escape closes it; with preset modals stacked, Escape closes only the one on top. Thebottom-sheetvariant docks the panel to the bottom of the viewport, with a max height and a scrolling body. It carriessmart:dark:variants.
Source
The component lives in packages/shared/react/src/lib/components/modal and is documented for Claude Code by the react-components-modal skill.