Stats
The <smart-stats> component renders a list of statistic cards (label/value pairs with optional previous value, change indicator, trend, icon, and action slot). It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract StatsBaseComponent defines the shared API — optional IStatsOptions and cssClass (alias class). StatsStandardComponent is a barebones placeholder concrete implementation. StatsComponent is the public wrapper that renders StatsStandardComponent by default and accepts a custom replacement via STATS_STANDARD_COMPONENT_TOKEN.
Usage
<smart-stats [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
StatsComponent (<smart-stats>)
Main wrapper component. Renders StatsStandardComponent by default. When STATS_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it the options and class inputs.
StatsStandardComponent (<smart-stats-standard>)
Barebones placeholder concrete implementation. Renders a wrapper <div> containing an optional <h3 class="title"> and a <dl> with one <div class="item"> per item (with aria-label from the item's ariaLabel). Each item renders an optional icon (iconTpl in <div class="icon">), label (<dt class="label">), value (<dd class="value">), optional previous value (<dd class="previous">), optional change with data-trend attribute (<dd class="change">), and optional action template (actionTpl in <div class="action">). The external cssClass is applied to the root wrapper. It does not read columns and does not include any visual styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.
StatsPresetComponent (<smart-stats-preset>)
Styled variation that extends StatsBaseComponent and is a drop-in replacement for StatsStandardComponent. Register it via STATS_STANDARD_COMPONENT_TOKEN (or every preset at once with provideSmartPresets()) to restyle every <smart-stats>, or use the <smart-stats-preset> selector directly. Renders the Preline "Three-Column Stats with Primary Accent" look: a responsive grid of stat blocks, each with an optional leading icon (iconTpl), a label heading, the big primary-accent value (with an optional inline change badge coloured by trend — green for up, red for down, gray for neutral/unset), an optional muted previousValue sub-line, and an optional actionTpl. Column count comes from options.columns (default 3); an optional options.title renders as a heading above the grid. All classes are smart:-prefixed Tailwind with explicit dark: variants. The class recipes are internal to the preset and not exported.
StatsPresetComponentdeclarescssClassasinput<string>('')without theclassalias. Bind it as[cssClass]when using the<smart-stats-preset>selector directly, or just passclasson<smart-stats>(the wrapper forwards it).
StatsBaseComponent (abstract)
Abstract base directive for extending custom stats implementations. Exposes options as an InputSignal<IStatsOptions | undefined> and cssClass as an InputSignal<string> (with alias class).
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IStatsOptions | undefined> | - | Optional configuration (title, items, columns) |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
IStatsOptions
| Field | Type | Default | Description |
|---|---|---|---|
title | string | - | Heading above the stats (<h3> in the standard, <h2> in the preset). |
items | IStatItem[] | required | The figures. |
columns | 1 | 2 | 3 | 4 | 3 | Preset only: the number of grid columns on wide screens (the grid collapses on small ones). The standard ignores it. |
IStatItem
A part of an item is rendered only when its field is set.
| Field | Type | Default | Description |
|---|---|---|---|
label | string | required | What the figure is. |
value | string | number | required | The figure. |
previousValue | string | number | - | A muted sub-line (previous value or context text). |
change | string | - | The change text (e.g. +4.75%). |
trend | 'up' | 'down' | 'neutral' | - | The standard exposes it as data-trend on the change; the preset colours the change badge green, red or gray. |
iconTpl | TemplateRef<unknown> | - | Leading icon. |
actionTpl | TemplateRef<unknown> | - | An action (e.g. "View all"). |
ariaLabel | string | - | Accessible name of the item. |
STATS_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default StatsStandardComponent with a custom implementation. Provide a component class extending StatsBaseComponent under STATS_STANDARD_COMPONENT_TOKEN; every <smart-stats> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
ViewEncapsulation,
} from '@angular/core';
import {
IStatsOptions,
STATS_STANDARD_COMPONENT_TOKEN,
StatsBaseComponent,
StatsComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-stats',
template: `
<div [class]="containerClasses()" [attr.data-columns]="columns()">
@if (options()?.title) {
<h3 class="docs-stats__title">{{ options()!.title }}</h3>
}
<dl class="docs-stats__grid">
@for (item of options()?.items ?? []; track $index) {
<div
class="docs-stats__item"
[attr.aria-label]="item.ariaLabel ?? null"
>
<dt class="docs-stats__label">{{ item.label }}</dt>
<dd class="docs-stats__value">{{ item.value }}</dd>
@if (
item.previousValue !== undefined && item.previousValue !== null
) {
<dd class="docs-stats__previous">{{ item.previousValue }}</dd>
}
@if (item.change) {
<dd
class="docs-stats__change"
[attr.data-trend]="item.trend ?? null"
>
{{ item.change }}
</dd>
}
</div>
}
</dl>
</div>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomStatsComponent extends StatsBaseComponent {
columns = computed(() => this.options()?.columns ?? 3);
containerClasses = computed(() =>
['docs-stats', this.cssClass()].filter(Boolean).join(' '),
);
}
@Component({
selector: 'docs-stats-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [StatsComponent],
// The token swaps the standard stats for the custom one everywhere below this
// component, so consumers keep writing `<smart-stats>`.
providers: [
{
provide: STATS_STANDARD_COMPONENT_TOKEN,
useValue: CustomStatsComponent,
},
],
template: `<smart-stats [options]="options" />`,
})
export class StatsCustomExampleComponent {
options: IStatsOptions = {
title: 'By the numbers',
columns: 3,
items: [
{
label: 'Accuracy rate',
value: '99.95%',
previousValue: 'in fulfilling orders',
change: '+0.4% this quarter',
trend: 'up',
},
{
label: 'Startup businesses',
value: '2,000+',
previousValue: 'partner with us',
},
{
label: 'Happy customers',
value: '85%',
previousValue: 'this year alone',
},
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/stats and is documented for Claude Code by the angular-components-stats skill.
SmartStats shows key figures: each item has a label, a big value, and optionally a previousValue line, a change text coloured by trend (up, down, neutral), an icon and an action. SmartStatsStandard is an unstyled title and <dl> (the change carries data-trend); SmartStatsPreset renders a responsive grid of stat blocks with options.columns (3 by default).
Usage
import { IStatsOptions, SmartStats } from '@smartsoft001/react';
const options: IStatsOptions = {
title: 'Last 30 days',
items: [
{
label: 'Total subscribers',
value: '71,897',
previousValue: '70,946',
change: '12%',
trend: 'up',
},
{ label: 'Avg. open rate', value: '58.16%', previousValue: '56.14%' },
{ label: 'Avg. click rate', value: '24.57%', previousValue: '28.62%' },
],
};
export function StatsUsageExample() {
return <SmartStats 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.
| Export | Kind | What it is |
|---|---|---|
SmartStats | component | Renders the implementation registered as components.stats on SmartProvider, SmartStatsStandard by default. |
SmartStatsPreset | component | Styled stats variation (preset). |
SmartStatsStandard | component | The default stats rendering: an unstyled title and a <dl> with one item per stat (icon, label, value, previous value, change tagged with data-trend, action). |
The preset's class helpers (getStatsContainerClasses, getStatsGridClasses, getStatsTitleClasses, getStatsLabelClasses, getStatsValueClasses, getStatsSubClasses, getStatsIconWrapClasses, getStatsActionClasses, getStatsChangeClasses) are exported too, with the type SmartStatsColumns (1 | 2 | 3 | 4, the argument of getStatsGridClasses), for a custom implementation that wants the preset look.
Props and Types
SmartStatsProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | IStatsOptions | — | Title, items and columns. |
className? | string | — | Classes on the root element. |
IStatsOptions
| Field | Type | Default | Description |
|---|---|---|---|
title? | string | — | Heading above the stats. |
items | IStatItem[] | required | The figures. |
columns? | 1 | 2 | 3 | 4 | 3 | Preset: number of columns (3 by default). |
IStatItem
| Field | Type | Default | Description |
|---|---|---|---|
label | string | required | What the figure is. |
value | string | number | required | The figure. |
previousValue? | string | number | — | A muted sub-line (previous value or context text). |
change? | string | — | The change text (e.g. +4.75%). |
trend? | 'up' | 'down' | 'neutral' | — | Colours the change: up, down or neutral (data-trend in the standard). |
iconTpl? | ReactNode | — | Leading icon. |
actionTpl? | ReactNode | — | An action (e.g. "View all"). |
ariaLabel? | string | — | Accessible name of the item. |
Replacing the Implementation
SmartStats renders the component registered under the 'stats' key of SmartProvider's components, and SmartStatsStandard when nothing is registered there. Every SmartStats below the provider then renders the registered component, which receives the same props.
SmartStatsPreset is the styled (preset) implementation: register it under the 'stats' key of SmartProvider's components, render it directly in place of SmartStats, 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 {
IStatsOptions,
SmartProvider,
SmartStats,
SmartStatsProps,
} from '@smartsoft001/react';
// The stats block has no behaviour hook: an implementation only renders its
// props.
export function CustomStats({ options, className }: SmartStatsProps) {
const containerClasses = ['docs-stats', className].filter(Boolean).join(' ');
return (
<div className={containerClasses} data-columns={options?.columns ?? 3}>
{options?.title && <h3 className="docs-stats__title">{options.title}</h3>}
<dl className="docs-stats__grid">
{(options?.items ?? []).map((item) => (
<div
key={item.label}
className="docs-stats__item"
aria-label={item.ariaLabel}
>
<dt className="docs-stats__label">{item.label}</dt>
<dd className="docs-stats__value">{item.value}</dd>
{item.previousValue !== undefined &&
item.previousValue !== null && (
<dd className="docs-stats__previous">{item.previousValue}</dd>
)}
{item.change && (
<dd className="docs-stats__change" data-trend={item.trend}>
{item.change}
</dd>
)}
</div>
))}
</dl>
</div>
);
}
// A module constant: a new object on every render would change the context.
const components = { stats: CustomStats };
const options: IStatsOptions = {
title: 'By the numbers',
columns: 3,
items: [
{
label: 'Accuracy rate',
value: '99.95%',
previousValue: 'in fulfilling orders',
change: '+0.4% this quarter',
trend: 'up',
},
{
label: 'Startup businesses',
value: '2,000+',
previousValue: 'partner with us',
},
{
label: 'Happy customers',
value: '85%',
previousValue: 'this year alone',
},
],
};
// Every <SmartStats> below the provider renders CustomStats.
export function StatsCustomExample() {
return (
<SmartProvider components={components}>
<SmartStats options={options} />
</SmartProvider>
);
}
Styling
- The preset colours the change badge by
trendand carriessmart:dark:variants; the standard rendering is unstyled.
Source
The component lives in packages/shared/react/src/lib/components/stats and is documented for Claude Code by the react-components-stats skill.