Notification

The <smart-notification> component displays a transient or persistent message — title, optional description, optional icon/avatar, optional dismiss control, and zero or more action buttons. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract NotificationBaseComponent defines the shared API — title (required), description, iconName, avatarUrl, actions, dismissible, options, cssClass (alias class), plus dismissed and actionClick outputs and the dismiss() / invokeAction() helper methods. NotificationStandardComponent is a barebones placeholder concrete implementation. NotificationComponent is the public wrapper that renders NotificationStandardComponent by default and accepts a custom replacement via NOTIFICATION_STANDARD_COMPONENT_TOKEN.


Usage

@if (visible()) {
  <smart-notification
    title="Successfully saved!"
    description="Anyone with a link can now view this file."
    [actions]="actions"
    [dismissible]="true"
    [options]="options"
    (actionClick)="onActionClick($event)"
    (dismissed)="onDismissed()"
  />
}

@if (lastAction()) {
  <p>Last action: {{ lastAction() }}</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

NotificationComponent (<smart-notification>)

Main wrapper component. Renders NotificationStandardComponent by default. When NOTIFICATION_STANDARD_COMPONENT_TOKEN is provided (or provideSmartPresets() registers the preset), renders the injected component via NgComponentOutlet, forwarding its inputs and re-emitting its dismissed and actionClick outputs. It has no open state: render it while the notification should be visible and remove it on (dismissed).

NotificationStandardComponent (<smart-notification-standard>)

Barebones placeholder concrete implementation. Renders a <div role="status"> with aria-live (defaulting to polite, overridable via options.ariaLive), an <h3> for the title, an optional <p> for the description, an optional close button when dismissible is true, and one <button> per action with a data-variant attribute. It does not render iconName or avatarUrl. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.

NotificationPresetComponent (<smart-notification-preset>)

Styled toast variation that extends NotificationBaseComponent and is a drop-in replacement for NotificationStandardComponent. Register it via NOTIFICATION_STANDARD_COMPONENT_TOKEN (or with provideSmartPresets()) to restyle every <smart-notification>, or use the <smart-notification-preset> selector directly. It renders the translated Preline toast looks as a card (bg-white/dark:bg-gray-800, border, rounded-xl, shadow-lg), with the layout selected through options.variant (default 'simple'):

  • simple — leading icon glyph (when iconName is set) plus the title message and optional description; it does not render actions.
  • condensed — inline single-row title with the action links and close button pushed to the end (ms-auto); no description or icon.
  • with-actions-below / with-avatar — icon (or avatar image for with-avatar) + heading + description, with text-link styled actions below; the close button is absolutely positioned.
  • with-buttons-below / with-split-buttons — same layout but actions render as solid/bordered buttons (per action.variant); with-split-buttons makes each button grow to fill the row.

dismissible renders a close button that calls dismiss(); each action calls invokeAction(action.id). Open/close visibility is Angular-driven via the dismissed output — no Preline JS runtime is used. All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal to the preset (not exported).

NotificationPresetComponent declares cssClass without the class alias: bind it as [cssClass] on the <smart-notification-preset> selector, or pass class on <smart-notification> (the wrapper forwards it).

NotificationBaseComponent (abstract)

Abstract base directive for extending custom notification implementations. Exposes the inputs/outputs listed below and provides dismiss() (emits dismissed) and invokeAction(actionId) (emits actionClick with an INotificationActionClick payload { actionId }, exported from @smartsoft001/angular) helper methods.

API

Inputs

InputTypeDefaultDescription
titleInputSignal<string> (required)-Headline text
descriptionInputSignal<string | undefined>-Optional supporting text
iconNameInputSignal<string | undefined>-Preset only: a glyph (text, e.g. an emoji) before the text (not in the condensed and with-avatar looks)
avatarUrlInputSignal<string | undefined>-Preset only: the image of the with-avatar look
actionsInputSignal<INotificationAction[]>[]Action buttons (not rendered by the preset's simple look)
dismissibleInputSignal<boolean>falseWhen true, renders a close button
optionsInputSignal<INotificationOptions | undefined>-Optional configuration (variant, ariaLive)
classInputSignal<string>''External CSS classes (alias for cssClass)

Outputs

OutputPayloadDescription
dismissedvoidEmitted when the user dismisses
actionClickINotificationActionClick ({ actionId: string })Emitted when an action button is clicked

INotificationAction

FieldTypeDefaultDescription
idstringrequiredEchoed back as actionId in the actionClick payload.
labelstringrequiredButton text.
variant'primary' | 'secondary''primary'The standard exposes it as data-variant; the preset styles the action by it.

INotificationOptions

FieldTypeDefaultDescription
variantSmartNotificationVariant'simple'Preset only: the toast look (simple, condensed, with-actions-below, with-avatar, with-split-buttons, with-buttons-below).
ariaLive'polite' | 'assertive''polite'The aria-live of the role="status" container; assertive for errors.

NOTIFICATION_STANDARD_COMPONENT_TOKEN

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

Extending the base class

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

import {
  INotificationAction,
  INotificationOptions,
  NOTIFICATION_STANDARD_COMPONENT_TOKEN,
  NotificationBaseComponent,
  NotificationComponent,
} from '@smartsoft001/angular';

/**
 * A custom notification built on `NotificationBaseComponent`.
 *
 * The base contributes every input plus the `dismiss()` and
 * `invokeAction(id)` helpers, which already emit the `dismissed` and
 * `actionClick` outputs - the implementation only decides the markup.
 */
@Component({
  selector: 'docs-custom-notification',
  template: `
    <section
      role="status"
      [attr.aria-live]="options()?.ariaLive ?? 'polite'"
      [class]="containerClasses()"
    >
      @if (avatarUrl()) {
        <img class="docs-notification__avatar" [src]="avatarUrl()" alt="" />
      } @else if (iconName()) {
        <span class="docs-notification__icon" aria-hidden="true">{{
          iconName()
        }}</span>
      }

      <div class="docs-notification__body">
        <h3 class="docs-notification__title">{{ title() }}</h3>
        @if (description()) {
          <p class="docs-notification__description">{{ description() }}</p>
        }

        @if (actions().length) {
          <div class="docs-notification__actions">
            @for (action of actions(); track action.id) {
              <button
                type="button"
                class="docs-notification__action"
                [attr.data-variant]="action.variant ?? 'primary'"
                (click)="invokeAction(action.id)"
              >
                {{ action.label }}
              </button>
            }
          </div>
        }
      </div>

      @if (dismissible()) {
        <button
          type="button"
          class="docs-notification__dismiss"
          aria-label="Close"
          (click)="dismiss()"
        >
          &times;
        </button>
      }
    </section>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomNotificationComponent extends NotificationBaseComponent {
  containerClasses = computed(() => {
    const classes = ['docs-notification'];
    const variant = this.options()?.variant;
    if (variant) classes.push(`docs-notification--${variant}`);
    const extra = this.cssClass();
    if (extra) classes.push(extra);
    return classes.join(' ');
  });
}

/**
 * Registering the implementation against
 * `NOTIFICATION_STANDARD_COMPONENT_TOKEN` makes every `<smart-notification>`
 * in this injector render it instead of the standard variation. The wrapper
 * forwards the `dismissed` and `actionClick` outputs of the custom
 * notification, so the consumer keeps listening on `<smart-notification>`.
 */
@Component({
  selector: 'docs-notification-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [NotificationComponent],
  providers: [
    {
      provide: NOTIFICATION_STANDARD_COMPONENT_TOKEN,
      useValue: CustomNotificationComponent,
    },
  ],
  template: `
    <smart-notification
      title="App notifications"
      description="Notifications may include alerts, sounds and icon badges."
      [avatarUrl]="avatarUrl"
      [actions]="actions"
      [dismissible]="true"
      [options]="options"
    />
  `,
})
export class NotificationCustomExampleComponent {
  avatarUrl =
    'https://images.unsplash.com/photo-1568602471122-7832951cc4c5?auto=format&fit=facearea&facepad=2&w=300&h=300&q=80';

  actions: INotificationAction[] = [
    { id: 'deny', label: "Don't allow", variant: 'secondary' },
    { id: 'allow', label: 'Allow', variant: 'primary' },
  ];

  options: INotificationOptions = {
    variant: 'with-actions-below',
    ariaLive: 'polite',
  };
}

Accessibility

  • The container uses role="status" so assistive technologies announce it as a live region.
  • aria-live defaults to 'polite' (announced after the user finishes their current task) and can be raised to 'assertive' via options.ariaLive for time-critical messages.
  • The dismiss button carries aria-label="Close" since its visible content is the × glyph.
  • Custom implementations should preserve role="status" and aria-live to keep this contract.

Toasts from code

ToastService (provided by SharedServicesModule) shows short messages at the bottom of the screen. While it has toasts it mounts one host at the end of <body>: a stack fixed to the bottom of the viewport (centred, right-aligned from sm, above the modals), every toast rendered through <smart-notification>. The implementation registered for NOTIFICATION_STANDARD_COMPONENT_TOKEN (the preset with provideSmartPresets()) therefore restyles the toasts too; the standard one renders them unstyled. A toast shows its title as the heading with the message under it, or the message alone, and its buttons as the notification's actions. It closes itself after duration ms, on its close button, or once the handler of one of its buttons ran. ErrorService.log(error) and the file inputs report their errors through it.

MemberWhat it does
info(options: IToastOptions): Promise<void>Shows an info toast, announced politely (aria-live="polite").
error(options: IToastOptions): Promise<void>Shows an error toast, announced assertively (aria-live="assertive"), unless an error lock is held.
dismiss(id: number): voidCloses a toast.
addLockError() / removeLockError()Holds / releases an error lock, counted in the static ToastService.lockError (never below zero). While a lock is held, error toasts are swallowed, e.g. during a sign-out that makes requests fail.
toasts: Signal<IToast[]>The toasts shown, oldest first (IToast adds id and type: 'error' | 'info' to the options).
IToastOptions fieldTypeDefaultDescription
titlestring-The heading; the message goes under it.
messagestringrequiredThe text; the heading when there is no title.
durationnumber2000Milliseconds before the toast closes itself; a missing, zero or negative value means 2000.
buttonsIToastButton[]-{ text, position: 'start' | 'end', handler }: a click runs handler, then closes the toast. position is kept for compatibility; the actions keep the given order.

A toast without buttons renders in the simple notification variant, a message with buttons in condensed, and a title with a message and buttons in with-actions-below, which keeps the message under the title.

Source

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

SmartNotification renders one notification panel: a title, an optional description, an icon glyph or avatar, action buttons (actions, reported through onActionClick({ actionId })) and a close button (dismissible, reported through onDismissed). It has no open state: render it while it should be visible and remove it on onDismissed. The toasts of useToastService().info(...) / .error(...) are rendered by the toast host of SmartProvider through this component, so registering a notification implementation restyles them too.


Usage

import { useState } from 'react';

import {
  INotificationAction,
  INotificationActionClick,
  INotificationOptions,
  SmartNotification,
} from '@smartsoft001/react';

const actions: INotificationAction[] = [
  { id: 'undo', label: 'Undo', variant: 'primary' },
];

// The preset's `simple` look has no room for actions: show them below.
const options: INotificationOptions = { variant: 'with-actions-below' };

export function NotificationUsageExample() {
  const [visible, setVisible] = useState(true);
  const [lastAction, setLastAction] = useState<string | null>(null);

  const onActionClick = ({ actionId }: INotificationActionClick) =>
    setLastAction(actionId);

  return (
    <>
      {/* The notification has no open state: remove it on onDismissed. */}
      {visible && (
        <SmartNotification
          title="Successfully saved!"
          description="Anyone with a link can now view this file."
          actions={actions}
          dismissible
          options={options}
          onActionClick={onActionClick}
          onDismissed={() => setVisible(false)}
        />
      )}

      {lastAction && <p>Last action: {lastAction}</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.

ExportKindWhat it is
SmartNotificationcomponentRenders the implementation registered as components.notification on SmartProvider, SmartNotificationStandard by default.
SmartNotificationPresetcomponentStyled notification (toast) variation (preset).
SmartNotificationStandardcomponentThe default notification rendering.
useNotificationhookThe behaviour every notification variant shares: dismiss() reports onDismissed and invokeAction(id) reports onActionClick.

The preset's class helpers (getNotificationContainerClasses, getNotificationTitleClasses, getNotificationMessageClasses, getNotificationDescriptionClasses, getNotificationIconClasses, getNotificationAvatarClasses, getNotificationCloseClasses, getNotificationActionsRowClasses, getNotificationActionClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartNotificationProps

PropTypeDefaultDescription
titlestringrequiredThe main line.
description?string—A second line.
iconName?string—A glyph (text, e.g. an emoji) shown before the text by the preset.
avatarUrl?string—Image shown by the preset with-avatar variant.
actions?INotificationAction[][]Action buttons (not rendered by the preset's simple variant).
dismissible?booleanfalseShows the close button, which reports onDismissed.
options?INotificationOptions—Variant and live-region politeness.
className?string—Classes on the root element.
onDismissed?() => void—Called when the close button is clicked; remove the notification here.
onActionClick?(value: INotificationActionClick) => void—Called with the id of the clicked action.

INotificationOptions

FieldTypeDefaultDescription
variant?SmartNotificationVariant'simple'Preset look: simple, condensed, with-actions-below, with-avatar, with-split-buttons, with-buttons-below.
ariaLive?'polite' | 'assertive''polite'assertive for errors.

INotificationActionClick

Payload of onActionClick.

FieldTypeDefaultDescription
actionIdstringrequiredThe id of the clicked action.

INotificationAction

FieldTypeDefaultDescription
idstringrequiredReported as actionId.
labelstringrequiredButton text.
variant?'primary' | 'secondary''primary'primary or secondary look; the standard exposes it as data-variant, the preset styles the action by it.
  • SmartNotificationVariant: 'simple' \| 'condensed' \| 'with-actions-below' \| 'with-avatar' \| 'with-split-buttons' \| 'with-buttons-below'

Toasts from code

ToastService keeps a queue of toasts that the toast host of SmartProvider (SmartToastHost, part of SmartOverlays) renders at the bottom of the screen through SmartNotification. A toast closes itself after duration ms (2000 by default), on its close button, or once the handler of one of its buttons ran. Errors are announced assertively, infos politely.

See react-components-overlays for the hosts and the full IToastOptions (buttons, durations, the error lock).

Replacing the Implementation

SmartNotification renders the component registered under the 'notification' key of SmartProvider's components, and SmartNotificationStandard when nothing is registered there. Every SmartNotification below the provider then renders the registered component, which receives the same props.

SmartNotificationPreset is the styled (preset) implementation: register it under the 'notification' key of SmartProvider's components, render it directly in place of SmartNotification, 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 useNotification hook

The behaviour every notification variant shares: dismiss() reports onDismissed and invokeAction(id) reports onActionClick. The notification does not hide itself; its owner removes it.

ReturnsTypeDescription
dismiss() => void | undefinedReports onDismissed.
invokeAction(actionId: string) => void | undefinedReports onActionClick({ actionId }).
import {
  INotificationAction,
  INotificationOptions,
  SmartNotification,
  SmartNotificationProps,
  SmartProvider,
  useNotification,
} from '@smartsoft001/react';

/**
 * A custom notification built on `useNotification`: the hook provides
 * `dismiss()` and `invokeAction(id)`, which already report `onDismissed` and
 * `onActionClick` - the implementation only decides the markup.
 */
export function CustomNotification(props: SmartNotificationProps) {
  const {
    title,
    description,
    iconName,
    avatarUrl,
    actions = [],
    dismissible = false,
    options,
    className,
  } = props;
  const { dismiss, invokeAction } = useNotification(props);

  const classes = [
    'docs-notification',
    options?.variant && `docs-notification--${options.variant}`,
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <section
      role="status"
      aria-live={options?.ariaLive ?? 'polite'}
      className={classes}
    >
      {avatarUrl ? (
        <img className="docs-notification__avatar" src={avatarUrl} alt="" />
      ) : iconName ? (
        <span className="docs-notification__icon" aria-hidden="true">
          {iconName}
        </span>
      ) : null}

      <div className="docs-notification__body">
        <h3 className="docs-notification__title">{title}</h3>
        {description && (
          <p className="docs-notification__description">{description}</p>
        )}

        {actions.length > 0 && (
          <div className="docs-notification__actions">
            {actions.map((action) => (
              <button
                key={action.id}
                type="button"
                className="docs-notification__action"
                data-variant={action.variant ?? 'primary'}
                onClick={() => invokeAction(action.id)}
              >
                {action.label}
              </button>
            ))}
          </div>
        )}
      </div>

      {dismissible && (
        <button
          type="button"
          className="docs-notification__dismiss"
          aria-label="Close"
          onClick={dismiss}
        >
          &times;
        </button>
      )}
    </section>
  );
}

// A module constant: a new object on every render would change the context.
const components = { notification: CustomNotification };

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

const actions: INotificationAction[] = [
  { id: 'deny', label: "Don't allow", variant: 'secondary' },
  { id: 'allow', label: 'Allow', variant: 'primary' },
];

const options: INotificationOptions = {
  variant: 'with-actions-below',
  ariaLive: 'polite',
};

/**
 * Every `SmartNotification` below this provider, and every toast of
 * `ToastService`, renders `CustomNotification` instead of the standard
 * rendering.
 */
export function NotificationCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartNotification
        title="App notifications"
        description="Notifications may include alerts, sounds and icon badges."
        avatarUrl={avatarUrl}
        actions={actions}
        dismissible
        options={options}
      />
    </SmartProvider>
  );
}

Registered as components={{ notification: CustomNotification }}, it also renders the toasts of ToastService.

Styling

  • SmartNotificationStandard is unstyled semantic markup (no classes); SmartNotificationPreset renders the six toast looks with smart:dark: variants and labels itself with a useId()-based id.

Source

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