Info

The <smart-info> component provides a small info icon that toggles a popover with a short tooltip text. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. It renders a default InfoStandardComponent which can be replaced via INFO_STANDARD_COMPONENT_TOKEN.


Usage

<span>Email address</span>
<smart-info [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

InfoComponent (<smart-info>)

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

InfoStandardComponent (<smart-info-standard>)

Default concrete implementation. Renders:

  • a small SVG info icon (button),
  • a popover shown while isOpen() is true,
  • Tailwind-styled container with smart:dark:* dark-mode classes,
  • a document:click listener that closes the popover on outside click.

InfoPresetComponent (<smart-info-preset>)

Styled variation that extends InfoBaseComponent and is a drop-in replacement for InfoStandardComponent. Register it via INFO_STANDARD_COMPONENT_TOKEN (or register every preset at once with provideSmartPresets()) to restyle every <smart-info>, or use the <smart-info-preset> selector directly. It renders the Preline Tooltip look: a circular icon toggle plus a small tooltip bubble. Visibility is driven by Angular hover/focus ((mouseenter)/(mouseleave) + (focus)/(blur)) using the inherited isOpen signal and @if — Preline's JS plugin is not installed. It keeps the translated Preline visual classes and renders role="tooltip" with aria-describedby wiring on the toggle. All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal to the preset (not exported).

The preset adds one input of its own, placement, described in the API section. It is only available on the <smart-info-preset> selector: the <smart-info> wrapper forwards options and class only, so a preset registered through the token always opens its tooltip on 'top'.

The preset declares cssClass without the class alias, so on the <smart-info-preset> selector bind it as [cssClass]; on <smart-info> pass class as usual (the wrapper forwards it to whichever implementation it renders).

InfoBaseComponent (abstract)

Abstract base directive for extending custom info implementations. Exposes options, cssClass (input alias class), the isOpen signal, and toggle()/open()/close() methods.

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<IInfoOptions>requiredInfo configuration
classInputSignal<string>''External CSS classes (alias for cssClass)

InfoPresetComponent (the <smart-info-preset> selector only) adds one input.

InputTypeDefaultDescription
placement'top' | 'bottom' | 'left' | 'right''top'Side of the toggle the tooltip opens on.

IInfoOptions

FieldTypeDefaultDescription
textstringrequiredThe text of the popover, rendered through TranslatePipe (it may be a translation key).

INFO_STANDARD_COMPONENT_TOKEN

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

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ElementRef,
  HostListener,
  inject,
  ViewEncapsulation,
} from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';

import {
  INFO_STANDARD_COMPONENT_TOKEN,
  IInfoOptions,
  InfoBaseComponent,
  InfoComponent,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-info',
  template: `
    <div [class]="containerClasses()">
      <button
        type="button"
        class="docs-info__trigger"
        aria-label="More information"
        [attr.aria-expanded]="isOpen()"
        (click)="toggle(); $event.stopPropagation()"
      >
        ?
      </button>
      @if (isOpen()) {
        <div class="docs-info__popover" role="tooltip">
          {{ options().text | translate }}
        </div>
      }
    </div>
  `,
  imports: [TranslatePipe],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomInfoComponent extends InfoBaseComponent {
  private readonly elementRef = inject(ElementRef);

  // `cssClass` (the `class` input) comes from InfoBaseComponent; the wrapper
  // forwards the class it receives to it.
  containerClasses = computed(() => {
    const classes = ['docs-info'];
    const extra = this.cssClass();
    if (extra) classes.push(extra);
    return classes.join(' ');
  });

  // InfoBaseComponent owns isOpen/toggle/open/close but does not close the
  // popover on an outside click - a custom implementation adds that itself.
  @HostListener('document:click', ['$event'])
  onDocumentClick(event: MouseEvent): void {
    if (!this.elementRef.nativeElement.contains(event.target)) {
      this.close();
    }
  }
}

@Component({
  selector: 'docs-info-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [InfoComponent],
  // The token swaps the standard info popover for the custom one everywhere
  // below this component, so consumers keep writing `<smart-info>`.
  providers: [
    { provide: INFO_STANDARD_COMPONENT_TOKEN, useValue: CustomInfoComponent },
  ],
  template: `
    <label class="docs-info__label">Email address</label>
    <smart-info [options]="options" class="docs-info--inline" />
  `,
})
export class InfoCustomExampleComponent {
  options: IInfoOptions = { text: 'Enter your primary email address.' };
}

Source

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

SmartInfo is a small info icon that reveals options.text in a popover. The standard rendering toggles the popover on click and closes it on a click anywhere else; the text goes through the provider's translations, so it may be a translation key. SmartInfoPreset is a hover / focus tooltip placed by placement. Form inputs and details show it automatically for fields with an info option.


Usage

import { IInfoOptions, SmartInfo } from '@smartsoft001/react';

const options: IInfoOptions = {
  text: 'We only use your email to send order updates.',
};

export function InfoUsageExample() {
  return (
    <>
      <span>Email address</span>
      <SmartInfo 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.

ExportKindWhat it is
SmartInfocomponentRenders the implementation registered as components.info on SmartProvider, SmartInfoStandard by default.
SmartInfoPresetcomponentStyled info / tooltip variation (preset).
SmartInfoStandardcomponentThe default info rendering: an info icon that toggles a popover with the translated options.text.
useInfohookThe behaviour every info variant shares: whether the text is shown, and the functions that show and hide it.

The preset's class helpers (getInfoContainerClasses, getInfoToggleClasses, getInfoTooltipClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartInfoProps

PropTypeDefaultDescription
optionsIInfoOptionsrequiredThe text to show.
className?string—Classes on the root element.

SmartInfoPresetProps

Props of SmartInfoPreset. Extends SmartInfoProps.

PropTypeDefaultDescription
placement?InfoPresetPlacement'top'Side of the toggle the tooltip opens on.

placement is only available when SmartInfoPreset is rendered directly: SmartInfoProps has no placement, so a preset registered under the info key always opens its tooltip on 'top'.

IInfoOptions

FieldTypeDefaultDescription
textstringrequiredThe text (translated by the standard rendering).
  • InfoPresetPlacement: 'top' \| 'bottom' \| 'left' \| 'right'

Replacing the Implementation

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

SmartInfoPreset is the styled (preset) implementation: register it under the 'info' key of SmartProvider's components, render it directly in place of SmartInfo, 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 useInfo hook

The behaviour every info variant shares: whether the text is shown, and the functions that show and hide it.

ReturnsTypeDescription
isOpenbooleanWhether the text is shown.
toggle() => voidShows or hides the text.
open() => voidShows the text.
close() => voidHides the text.
import { useEffect, useRef } from 'react';

import {
  cn,
  IInfoOptions,
  SmartInfo,
  SmartInfoProps,
  SmartProvider,
  useInfo,
  useTranslate,
} from '@smartsoft001/react';

export function CustomInfo({ options, className }: SmartInfoProps) {
  // useInfo owns the open state; the text goes through the provider's
  // translations, like in the standard info.
  const { isOpen, toggle, close } = useInfo();
  const t = useTranslate();
  const rootRef = useRef<HTMLDivElement>(null);

  // useInfo does not close the popover on an outside click: add it here.
  useEffect(() => {
    if (!isOpen) return undefined;

    const onDocumentClick = (event: MouseEvent) => {
      if (!rootRef.current?.contains(event.target as Node)) close();
    };

    document.addEventListener('click', onDocumentClick);

    return () => document.removeEventListener('click', onDocumentClick);
  }, [isOpen, close]);

  return (
    <div ref={rootRef} className={cn('docs-info', className)}>
      <button
        type="button"
        className="docs-info__trigger"
        aria-label="More information"
        aria-expanded={isOpen}
        onClick={toggle}
      >
        ?
      </button>
      {isOpen && (
        <div className="docs-info__popover" role="tooltip">
          {t(options.text)}
        </div>
      )}
    </div>
  );
}

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

const options: IInfoOptions = { text: 'Enter your primary email address.' };

export function InfoCustomExample() {
  // Every SmartInfo below the provider renders CustomInfo.
  return (
    <SmartProvider components={components}>
      <label className="docs-info__label">Email address</label>
      <SmartInfo options={options} />
    </SmartProvider>
  );
}

Styling

  • The preset tooltip carries role="tooltip" and sets aria-describedby on the toggle while shown; both renderings have smart:dark: variants.

Source

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