Divider

The <smart-divider> component provides a flexible divider/separator wrapper with an InjectionToken-based extension mechanism. It renders a default DividerStandardComponent which can be replaced via DIVIDER_STANDARD_COMPONENT_TOKEN.


Usage

<smart-divider
  [options]="options"
  [title]="title"
  [actionLabel]="actionLabel"
  (actionClick)="onAddMember()"
/>
<p>Add member clicks: {{ addClicks() }}</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

DividerComponent (<smart-divider>)

Main wrapper component. Renders DividerStandardComponent by default. When DIVIDER_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet.

DividerStandardComponent (<smart-divider-standard>)

Default concrete implementation. Renders a <div role="separator"> host with optional title, label, action button, or a plain <hr /> when none of these are provided.

DividerPresetComponent (<smart-divider-preset>)

Styled variation that extends DividerBaseComponent and is a drop-in replacement for DividerStandardComponent. Register it for DIVIDER_STANDARD_COMPONENT_TOKEN to restyle every <smart-divider> (or every preset at once with provideSmartPresets()), or use the <smart-divider-preset> selector directly. It translates Preline's divider patterns to smart:-prefixed Tailwind (with explicit dark: variants), one per variant:

  • plain: an <hr>, when there is no content and no variant
  • with-label, with-icon, with-title: the content (label, else title; title first for with-title, in Preline's uppercase muted "Or" style) with connecting line(s) placed by options.position (default center); iconName is shown before it
  • with-button: only the actionLabel button (with iconName before its text) on the line; label and title are not shown
  • with-toolbar: the content (label, else title), a line, then the actionLabel button; options.position does not apply

When options.variant is omitted the variant is inferred from the inputs: actionLabel → with-button, title → with-title, iconName → with-icon, label → with-label, otherwise the plain <hr>.

The preset declares cssClass without the class alias, so bind [cssClass] when you use the <smart-divider-preset> selector directly; class on <smart-divider> reaches it through the wrapper. iconName has no icon-font dependency: it is rendered as the text content of a size-4 icon slot, so an icon font (e.g. Material Icons) gets the correct sizing. The class recipes are internal (not exported from @smartsoft001/angular).

DividerBaseComponent (abstract)

Abstract base directive for extending custom divider implementations. It declares the inputs and the output below (cssClass with the class alias).

API

Inputs

InputTypeDefaultDescription
labelInputSignal<string | undefined>undefinedShort text on the line (standard: a <span>)
iconNameInputSignal<string | undefined>undefinedIcon text before the content or the action. Preset only: the standard does not render it
titleInputSignal<string | undefined>undefinedHeading on the line (standard: an <h3>)
actionLabelInputSignal<string | undefined>undefinedRenders a button with this text that emits actionClick
optionsInputSignal<IDividerOptions | undefined>undefinedVariant and position
classInputSignal<string>''Classes on the root element (cssClass input, alias class)

Outputs

OutputTypeDescription
actionClickOutputEmitterRef<void>Emitted when the action button is clicked

IDividerOptions

FieldTypeDefaultDescription
variantSmartDividerVariantinferred'with-label', 'with-icon', 'with-title', 'with-button' or 'with-toolbar'. Preset only; the standard ignores it.
position'left' | 'center' | 'right''center'Where the content sits on the line (preset, except with-toolbar). The standard only writes it to the data-position attribute of its root, for your own CSS.

DIVIDER_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default DividerStandardComponent with a custom implementation. Provide a Type<DividerBaseComponent> to override. The wrapper passes the inputs it has on and re-emits the implementation's actionClick.

Extending the base class

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

import {
  DividerBaseComponent,
  DividerComponent,
  DIVIDER_STANDARD_COMPONENT_TOKEN,
} from '@smartsoft001/angular';

/**
 * A custom divider built on `DividerBaseComponent`.
 *
 * The base contributes the `label`, `iconName`, `title`, `actionLabel`,
 * `options` and `class` inputs plus the `actionClick` output. Which of them an
 * implementation honours is up to its template.
 */
@Component({
  selector: 'docs-custom-divider',
  template: `
    <div role="separator" [class]="containerClasses()">
      @if (title()) {
        <h3 class="docs-divider__title">{{ title() }}</h3>
      } @else if (label()) {
        <span class="docs-divider__label">{{ label() }}</span>
      }
      @if (actionLabel()) {
        <button type="button" (click)="actionClick.emit()">
          {{ actionLabel() }}
        </button>
      }
    </div>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomDividerComponent extends DividerBaseComponent {
  // `cssClass` comes from the base (alias `class`): the wrapper hands the
  // consumer's class to it under that name.
  containerClasses = computed(() =>
    ['docs-divider', this.cssClass()].filter(Boolean).join(' '),
  );
}

/**
 * Registering the implementation against `DIVIDER_STANDARD_COMPONENT_TOKEN`
 * makes every `<smart-divider>` in this injector render it instead of the
 * standard variation. The wrapper re-emits the implementation's `actionClick`,
 * so `(actionClick)` on `<smart-divider>` keeps working.
 */
@Component({
  selector: 'docs-divider-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DividerComponent],
  providers: [
    {
      provide: DIVIDER_STANDARD_COMPONENT_TOKEN,
      useValue: CustomDividerComponent,
    },
  ],
  template: `
    <smart-divider
      [title]="'Team members'"
      [actionLabel]="'Add member'"
      (actionClick)="addClicks.update((count) => count + 1)"
    />
  `,
})
export class DividerCustomExampleComponent {
  addClicks = signal(0);
}

Source

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

SmartDivider separates sections. Without content it is a plain <hr />; with label, title, iconName or actionLabel it renders that content on the line (the action as a button reporting onActionClick). options.position places the content left, centre (default) or right, and options.variant picks the arrangement in the preset (inferred from the given props when omitted).


Usage

import { useState } from 'react';

import { IDividerOptions, SmartDivider } from '@smartsoft001/react';

// The preset draws the title, a line and the action in one row.
const options: IDividerOptions = { variant: 'with-toolbar' };

export function DividerUsageExample() {
  const [addClicks, setAddClicks] = useState(0);

  return (
    <>
      <SmartDivider
        options={options}
        title="Team members"
        actionLabel="Add member"
        onActionClick={() => setAddClicks((count) => count + 1)}
      />
      <p>Add member clicks: {addClicks}</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
SmartDividercomponentRenders the implementation registered as components.divider on SmartProvider, SmartDividerStandard by default.
SmartDividerPresetcomponentStyled divider variation (preset).
SmartDividerStandardcomponentThe default divider rendering: the title, the label and the action button, or an <hr /> when there is none of them.

The preset's class helpers (getDividerContainerClasses, getDividerIconClasses, getDividerActionClasses, getDividerToolbarClasses, getDividerToolbarLineClasses, getDividerPlainClasses, DIVIDER_PLAIN_HR, DIVIDER_TOOLBAR_LINE, DIVIDER_TOOLBAR_CONTAINER, DIVIDER_ICON_CLASSES, DIVIDER_ACTION_BUTTON) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartDividerProps

PropTypeDefaultDescription
label?string—Short text on the line.
iconName?string—An icon on the line (rendered by the preset; the standard ignores it).
title?string—A heading on the line.
actionLabel?string—Renders a button with this text that calls onActionClick.
options?IDividerOptions—Variant and position.
className?string—Classes on the root element.
onActionClick?() => void—The action button was clicked.

IDividerOptions

FieldTypeDefaultDescription
variant?SmartDividerVariantinferredwith-label, with-icon, with-title, with-button (only the action button on the line: label and title are not shown) or with-toolbar (label or title, a line, then the action). Preset only; inferred from the props when omitted (action, title, icon, label, in that order).
position?'left' | 'center' | 'right''center'Where the content sits on the line (preset, except with-toolbar). The standard only writes it to the data-position attribute of its root, for your own CSS.
  • SmartDividerVariant: 'with-label' \| 'with-icon' \| 'with-title' \| 'with-button' \| 'with-toolbar'

Replacing the Implementation

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

SmartDividerPreset is the styled (preset) implementation: register it under the 'divider' key of SmartProvider's components, render it directly in place of SmartDivider, 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.

import {
  SmartDivider,
  SmartDividerProps,
  SmartProvider,
} from '@smartsoft001/react';

/**
 * A custom divider taking `SmartDividerProps`.
 *
 * `SmartDivider` passes every prop on: `label`, `iconName`, `title`,
 * `actionLabel`, `options`, `className` and the `onActionClick` callback.
 * Which of them an implementation honours is up to its markup.
 */
export function CustomDivider({
  label,
  title,
  actionLabel,
  className,
  onActionClick,
}: SmartDividerProps) {
  return (
    <div
      role="separator"
      className={['docs-divider', className].filter(Boolean).join(' ')}
    >
      {title ? (
        <h3 className="docs-divider__title">{title}</h3>
      ) : (
        label && <span className="docs-divider__label">{label}</span>
      )}
      {actionLabel && (
        <button type="button" onClick={() => onActionClick?.()}>
          {actionLabel}
        </button>
      )}
    </div>
  );
}

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

// Every <SmartDivider> below the provider renders CustomDivider.
export function DividerCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartDivider title="Team members" actionLabel="Add member" />
    </SmartProvider>
  );
}

Styling

  • SmartDividerStandard renders the title, label and action button, or an <hr /> when none is given; it does not render iconName.
  • SmartDividerPreset draws the connecting lines around the content per position, with smart:dark: variants; with-toolbar draws the content, a line and the action in one row.

Source

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