Card

Flexible card container with injectable standard rendering. The <smart-card> wrapper renders CardStandardComponent by default (a neutral Tailwind placeholder with dark mode). Consumers can replace the standard with a custom variant via CARD_STANDARD_COMPONENT_TOKEN.


Usage

<smart-card [options]="options" [hasHeader]="true" [hasFooter]="true">
  <p>{{ seatsUsed() }} of {{ seatsTotal }} seats used</p>
  <div cardFooter>
    <smart-button [options]="inviteButton">Invite member</smart-button>
  </div>
</smart-card>

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.

Public API

Wrapper: smart-card

InputTypeDefaultDescription
optionsICardOptionsundefinedCard configuration
hasHeaderbooleanfalseRenders the header section. The [cardHeader] content and options.title show only while true.
hasFooterbooleanfalseRenders the footer section. The [cardFooter] content shows only while true.
classstring''Extra container class

ICardOptions

FieldTypeDefaultDescription
titlestringundefinedRendered as an <h3> at the start of the header, when hasHeader is true.
buttonsArray<IIconButtonOptions>undefinedDeprecated: not read by the built-in implementations (standard or preset); available to a custom implementation. Put actions in the [cardHeader] / [cardFooter] slots instead.
grayFooterbooleanundefinedGray background on the footer.
grayBodybooleanundefinedGray background on the body.

IIconButtonOptions (icon, text, handler, component, type, disabled$: Observable<boolean>, number) is shared with the page buttons; the card does not render it.

Content Projection

SelectorDescription
[cardHeader]Header content (with hasHeader set)
defaultBody content
[cardFooter]Footer content (with hasFooter set)

Architecture

Three-layer pattern mirroring <smart-button>:

  1. CardBaseComponent (@Directive()) — shared inputs (options, hasHeader, hasFooter, cssClass with the class alias, the optional headerTpl / footerTpl and the required bodyTpl, all TemplateRef<unknown>) and computed classes (sharedContainerClasses, headerClasses, bodyClasses, footerClasses). Handles divider, gray body/footer, and padding rules.
  2. CardStandardComponent (selector: smart-card-standard) — default concrete implementation extending the base. Neutral Tailwind style with dark mode (rounded-lg, bg-white, shadow-sm, dark:bg-gray-800/50, dark:outline-white/10).
  3. CardComponent (selector: smart-card) — wrapper. Uses inject(CARD_STANDARD_COMPONENT_TOKEN, { optional: true }) + *ngComponentOutlet to render the injected component, falling back to <smart-card-standard>. Content projection ([cardHeader], default, [cardFooter]) is wrapped in local <ng-template> refs and passed as inputs (headerTpl/bodyTpl/footerTpl) to the active component, together with options, hasHeader, hasFooter and class.

Extending the base class

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

import {
  CARD_STANDARD_COMPONENT_TOKEN,
  CardBaseComponent,
  CardComponent,
  ICardOptions,
} from '@smartsoft001/angular';

/**
 * A card of your own built on `CardBaseComponent`. `<smart-card>` hands its
 * `[cardHeader]`, default and `[cardFooter]` content over as the `headerTpl`,
 * `bodyTpl` and `footerTpl` templates.
 */
@Component({
  selector: 'docs-flat-card',
  imports: [NgTemplateOutlet],
  template: `
    <article [class]="containerClasses()">
      @if (hasHeader()) {
        <header class="docs-card__header">
          @if (options()?.title; as title) {
            <h3>{{ title }}</h3>
          }
          <ng-container [ngTemplateOutlet]="headerTpl() ?? null" />
        </header>
      }
      <div class="docs-card__body">
        <ng-container [ngTemplateOutlet]="bodyTpl()" />
      </div>
      @if (hasFooter()) {
        <footer class="docs-card__footer">
          <ng-container [ngTemplateOutlet]="footerTpl() ?? null" />
        </footer>
      }
    </article>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FlatCardComponent extends CardBaseComponent {
  containerClasses = computed(() =>
    ['docs-card', this.cssClass()].filter(Boolean).join(' '),
  );
}

// Registering the token makes every <smart-card> in this injector render
// FlatCardComponent.
@Component({
  selector: 'docs-card-custom-example',
  imports: [CardComponent],
  providers: [
    { provide: CARD_STANDARD_COMPONENT_TOKEN, useValue: FlatCardComponent },
  ],
  template: `
    <smart-card [options]="options" [hasHeader]="true" [hasFooter]="true">
      <p>Pro plan, billed monthly.</p>
      <span cardFooter>Next invoice on 1 May</span>
    </smart-card>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CardCustomExampleComponent {
  options: ICardOptions = { title: 'Billing' };
}

CardPresetComponent (smart-card-preset)

Fully-styled, drop-in concrete implementation extending CardBaseComponent — a faithful translation of Preline's card (rounded-xl surface, shadow-2xs, bordered surface header/footer) into smart:-prefixed vanilla Tailwind with explicit dark: variants. Honours options.title, options.grayBody, and options.grayFooter, and renders the same headerTpl / bodyTpl / footerTpl slots as the base. It separates the sections with its own borders, not with the base's divider classes.

Use it directly via <smart-card-preset> (it takes the extra classes as class or [cssClass]), register it through CARD_STANDARD_COMPONENT_TOKEN ({ provide: CARD_STANDARD_COMPONENT_TOKEN, useValue: CardPresetComponent }) to restyle every <smart-card>, or register every preset at once with provideSmartPresets().

Tailwind Classes

All classes use smart: prefix. CardStandardComponent container: smart:overflow-hidden smart:rounded-lg smart:bg-white smart:shadow-sm. Dark mode: smart:dark:bg-gray-800/50 smart:dark:shadow-none smart:dark:outline smart:dark:-outline-offset-1 smart:dark:outline-white/10. Divider between the sections when hasHeader or hasFooter is set and neither grayBody nor grayFooter is: smart:divide-y smart:divide-gray-200 smart:dark:divide-white/10. Gray body/footer: smart:bg-gray-50 smart:dark:bg-gray-800/50.

Source

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

SmartCard is a panel with three sections: an optional header (header, plus options.title), the body (children) and an optional footer (footer). A section is rendered when its content is given, unless hasHeader / hasFooter force it. The wrapper hands the slots to the registered implementation as headerTpl / bodyTpl / footerTpl (SmartCardVariantProps), so a custom card receives nodes, not children.


Usage

import { useState } from 'react';

import { ICardOptions, SmartButton, SmartCard } from '@smartsoft001/react';

const options: ICardOptions = {
  title: 'Team members',
  grayFooter: true,
};

const seatsTotal = 10;

export function CardUsageExample() {
  const [seatsUsed, setSeatsUsed] = useState(4);

  return (
    <SmartCard
      options={options}
      hasHeader
      hasFooter
      footer={
        <SmartButton
          options={{ click: () => setSeatsUsed((used) => used + 1) }}
        >
          Invite member
        </SmartButton>
      }
    >
      <p>
        {seatsUsed} of {seatsTotal} seats used
      </p>
    </SmartCard>
  );
}

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
SmartCardcomponentRenders the implementation registered as components.card on SmartProvider, SmartCardStandard by default.
SmartCardPresetcomponentStyled card variation (preset).
SmartCardStandardcomponentThe default card rendering: a white panel with an optional header (with options.title), the body and an optional footer.
useCardhookThe behaviour every card variant shares: which sections are shown, and the classes of the container and the header, body and footer sections.
isCardSectionShownfunctionWhether a card section is rendered: flag when set, otherwise whether content renders anything (null, undefined, booleans and '' do not).

The preset's class helpers (getCardContainerClasses, getCardHeaderClasses, getCardBodyClasses, getCardFooterClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartCardProps

Props of <SmartCard>.

PropTypeDefaultDescription
options?ICardOptions—Title and the gray body / footer flags.
hasHeader?boolean—Renders the header section; by default, when header is given.
hasFooter?boolean—Renders the footer section; by default, when footer is given.
className?string—Classes on the card container.
header?ReactNode—The header content.
footer?ReactNode—The footer content.
children?ReactNode—The body content.

SmartCardVariantProps

Props of a card implementation (SmartCardStandard, SmartCardPreset or one registered as components.card): the wrapper passes header / children / footer as headerTpl / bodyTpl / footerTpl.

PropTypeDefaultDescription
options?ICardOptions—Title and the gray body / footer flags.
hasHeader?boolean—Renders the header section; by default, when headerTpl is given.
hasFooter?boolean—Renders the footer section; by default, when footerTpl is given.
className?string—Classes on the card container.
headerTpl?ReactNode—The header content (SmartCard's header).
bodyTpl?ReactNode—The body content (SmartCard's children).
footerTpl?ReactNode—The footer content (SmartCard's footer).

ICardOptions

FieldTypeDefaultDescription
title?string—Rendered in the header (the header is shown for it when hasHeader is set).
buttons?Array<IIconButtonOptions>—@deprecated Has never been rendered by any card variant (standard or preset). Put actions in the header or footer instead: pass them as the header / footer of SmartCard, which reach the variant as headerTpl / footerTpl.
grayFooter?boolean—Gray background on the footer.
grayBody?boolean—Gray background on the body.

IIconButtonOptions

An icon button description (used by ICardOptions.buttons, deprecated here, and by page buttons).

FieldTypeDefaultDescription
iconstringrequiredIdentifier of the button (page renderings use it as the React key; it is not drawn as an icon).
text?string—Label.
handler?() => void—Click handler.
component?any—Carried for implementations of your own; the library's renderings do not read it.
type?'default' | 'popover'—Carried for implementations of your own; the library's renderings do not read it.
disabled?boolean—Disables the button.
number?number—A count badge on the button.

Sections

  • The header is rendered when header is given, or when hasHeader is true (for example to show only options.title).
  • The footer is rendered when footer is given, or when hasFooter is true.
  • hasHeader={false} / hasFooter={false} hide a section even when content is given. isCardSectionShown(flag, content) is the rule (null, undefined, booleans and '' count as no content).
  • options.buttons is deprecated and never rendered: put actions into header or footer.

Replacing the Implementation

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

SmartCardPreset is the styled (preset) implementation: register it under the 'card' key of SmartProvider's components, render it directly in place of SmartCard, 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 useCard hook

The behaviour every card variant shares: which sections are shown, and the classes of the container and the header, body and footer sections.

ReturnsTypeDescription
showHeaderbooleanWhether the header section is rendered.
showFooterbooleanWhether the footer section is rendered.
sharedContainerClassesstring[]Classes of the card container.
headerClassesstringClasses of the header section.
bodyClassesstringClasses of the body section (gray with options.grayBody).
footerClassesstringClasses of the footer section (gray with options.grayFooter).
import {
  ICardOptions,
  SmartCard,
  SmartCardVariantProps,
  SmartProvider,
  useCard,
} from '@smartsoft001/react';

/**
 * A card of your own: `useCard` decides which sections are shown, and the
 * wrapper hands `header` / `children` / `footer` over as `headerTpl` /
 * `bodyTpl` / `footerTpl`.
 */
export function FlatCard(props: SmartCardVariantProps) {
  const { options, className, headerTpl, bodyTpl, footerTpl } = props;
  const { showHeader, showFooter } = useCard(props);

  return (
    <article className={['docs-card', className].filter(Boolean).join(' ')}>
      {showHeader && (
        <header className="docs-card__header">
          {options?.title && <h3>{options.title}</h3>}
          {headerTpl}
        </header>
      )}
      <div className="docs-card__body">{bodyTpl}</div>
      {showFooter && <footer className="docs-card__footer">{footerTpl}</footer>}
    </article>
  );
}

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

const options: ICardOptions = { title: 'Billing' };

// Every <SmartCard> below the provider renders FlatCard.
export function CardCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartCard
        options={options}
        hasHeader
        footer={<span>Next invoice on 1 May</span>}
      >
        <p>Pro plan, billed monthly.</p>
      </SmartCard>
    </SmartProvider>
  );
}

Register it as components={{ card: FlatCard }}: SmartCard keeps taking header / children / footer and passes them on as headerTpl / bodyTpl / footerTpl.

Styling

  • SmartCardStandard is a white panel with dark-mode variants; SmartCardPreset adds the rounded shadow-2xs surface with bordered header and footer.
  • className is appended to the container.

Source

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