Synertech Web/ui v0.57.5 Site Storybook

Documentation / Charts

StatCard

Server-compatible@synertech/uiOpen in Storybook

A single value, its variation and, optionally, the curve that led there (a Sparkline fed by trend). It is the right form for one figure: a one-bar chart is not one. StatCardGroup lines several tiles up on a grid, at equal width and height.

The variation’s colour crosses its direction with goodWhen: a falling cost is good news (goodWhen: "down"), a session count may be neither ("neutral"). Colour never carries the meaning alone: an arrow and a signed value say the same thing without it.

No hooks: StatCard and StatCardGroup render on the server.

Examples

Basic usage

A number is formatted automatically; delta.value is a ratio (0.124 = +12.4%).

Open in a tab
import { StatCard } from "@synertech/ui";

export function Basic() {
  return (
    <StatCard
      label="Revenu mensuel"
      value={38400}
      format={(value) => `${value.toLocaleString("fr-FR")} €`}
      delta={{ value: 0.124, period: "vs mois dernier" }}
    />
  );
}

Which way is good

goodWhen decides the colour: green for rising revenue as for a falling cost.

Open in a tab
import { StatCard, StatCardGroup } from "@synertech/ui";

export function GoodWhen() {
  return (
    <StatCardGroup columns={3}>
      <StatCard label="Revenu" value={38400} delta={{ value: 0.124 }} />
      <StatCard label="Coût serveur" value={4200} delta={{ value: -0.18, goodWhen: "down" }} />
      <StatCard label="Sessions" value={9340} delta={{ value: 0.06, goodWhen: "neutral" }} />
    </StatCardGroup>
  );
}

With trend and icon

trend draws a sparkline under the value; icon and footer complete the tile.

Open in a tab
import { StatCard, StatCardGroup } from "@synertech/ui";

const revenueTrend = [28100, 29400, 30200, 29800, 32600, 34100, 35900, 38400];

const UsersIcon = () => (
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M17 20h5v-2a4 4 0 00-5-3.87M9 20H2v-2a4 4 0 015-3.87m6-4.13a4 4 0 11-8 0 4 4 0 018 0zm6 2a3 3 0 11-6 0 3 3 0 016 0z"
    />
  </svg>
);

export function WithTrend() {
  return (
    <StatCardGroup columns={2}>
      <StatCard
        label="Revenu mensuel"
        value={38400}
        delta={{ value: 0.071, period: "vs mois dernier" }}
        trend={revenueTrend}
        size="lg"
      />
      <StatCard
        label="Clients actifs"
        value={1284}
        icon={<UsersIcon />}
        delta={{ value: 0.031, period: "sur 30 jours" }}
        footer="Dont 112 nouveaux ce mois-ci"
        size="lg"
      />
    </StatCardGroup>
  );
}

Dashboard KPI row

Four tiles on a responsive grid, with a loading state while the request runs.

Open in a tab
import { StatCard, StatCardGroup } from "@synertech/ui";

const revenueTrend = [28100, 29400, 30200, 29800, 32600, 34100, 35900, 38400];

const costTrend = [5100, 4900, 4950, 4700, 4600, 4400, 4300, 4200];

export function KpiRow() {
  const loading = false;

  return (
    <StatCardGroup columns={4}>
      <StatCard
        label="Revenu"
        value={38400}
        delta={{ value: 0.124 }}
        trend={revenueTrend}
        loading={loading}
      />
      <StatCard
        label="Coût serveur"
        value={4200}
        delta={{ value: -0.18, goodWhen: "down" }}
        trend={costTrend}
        loading={loading}
      />
      <StatCard
        label="Taux de conversion"
        value="3,8 %"
        delta={{ value: 0.4, format: (value) => `+${value.toLocaleString("fr-FR")} pt` }}
        loading={loading}
      />
      <StatCard
        label="Tickets ouverts"
        value={27}
        delta={{ value: 0, period: "stable" }}
        loading={loading}
      />
    </StatCardGroup>
  );
}

Frameless variant

variant="plain" removes the border and padding to fit the tiles into another surface.

Open in a tab
import { StatCard, StatCardGroup } from "@synertech/ui";

export function Plain() {
  return (
    <div className="rounded-lg border border-gray-200 p-4 dark:border-gray-700">
      <StatCardGroup columns={3}>
        <StatCard variant="plain" label="Revenu" value={38400} delta={{ value: 0.124 }} />
        <StatCard variant="plain" label="Clients" value={1284} delta={{ value: 0.031 }} />
        <StatCard
          variant="plain"
          label="Taux d’attrition"
          value="2,1 %"
          delta={{ value: -0.093, goodWhen: "down" }}
        />
      </StatCardGroup>
    </div>
  );
}

API reference

Components

StatCard

ComponentServer-compatible

A single value with its variation, and optionally the shape that led to it.

This is the right form for one number — a one-bar bar chart is not. No hooks, so it renders on the server.

import { StatCard } from "@synertech/ui";

Props — StatCardProps

PropTypeDefaultDescription
label• ReactNode —
value• ReactNode —

A number is formatted; anything else is rendered as given.

delta StatCardDelta —
format (value: number) => string —

Formats a numeric value. Defaults to grouped, then compact past 10 000.

icon ReactNode —
loading boolean false
locale string —

BCP 47 tag the value and the variation are written in. Defaults to the language of the runtime. This component renders on the server and reads no context: the locale of UILabelsProvider does not reach it.

size ChartSize "md"
trend readonly (number | null | undefined)[] —

Values behind the sparkline. Left out, no sparkline is drawn.

trendColor string —
variant "card" | "plain" "card"

plain drops the border and the padding, for a tile inside another surface.

+ 278 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

StatCardGroup

ComponentServer-compatible

A row of stat tiles that share their edges and baselines.

A grid rather than a flex row: the tiles keep the same width and the same height whatever they hold, so the row reads as one object.

import { StatCardGroup } from "@synertech/ui";

Props — StatCardGroupProps

PropTypeDefaultDescription
columns 1 | 2 | 3 | 4 4

Columns from the sm breakpoint up. Below it, the tiles stack.

+ 279 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

StatCardDelta

Interface
interface StatCardDelta
FieldTypeDefaultDescription
value• number —

A ratio by default: 0.124 reads as "+12.4 %".

direction StatCardDeltaDirection —

Overrides the direction, which is otherwise the sign of the variation as it is written: one that rounds to "0%" is flat.

format (value: number) => string —

Replaces the default signed percentage.

goodWhen StatCardDeltaTone —

Defaults to up: a rise is good news.

period ReactNode —

What the comparison is against — "vs last month".

type StatCardDeltaDirection = "up" | "down" | "flat"

Which way is the good way. A falling cost is good news.

type StatCardDeltaTone = "up" | "down" | "neutral"