Blocks / Delta badge

Delta badge

A change said by an arrow, a sign and a word; the tone only repeats it.

import { DeltaBadge, dashboardRatio, dashboardDeltaWay } from "@forgeron/ui";
/01 → Default
€48.2kup, +12.4%Bettervs last month37up, +9%Worseopen tickets18 daysdown, −14%Better31.4%unchanged, ±0%FlatNew—No comparison
import { DeltaBadge } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
      <DeltaBadge value="€48.2k" delta={0.124} hint="vs last month" />
      <DeltaBadge value="37" delta={0.09} better="down" hint="open tickets" />
      <DeltaBadge value="18 days" delta={-0.14} better="down" />
      <DeltaBadge value="31.4%" delta={0} />
      <DeltaBadge value="New" delta={null} />
    </div>
  );
}
/02 → Compact
up, +12.4%, Betterdown, −6%, Worseunchanged, ±0%, Flat
// Without the word, it is still read aloud: "up, Better".
import { DeltaBadge } from "@forgeron/ui";

export default function Compact() {
  return (
    <div style={{ display: "flex", gap: 12 }}>
      <DeltaBadge size="sm" showWord={false} delta={0.124} />
      <DeltaBadge size="sm" showWord={false} delta={-0.06} />
      <DeltaBadge size="sm" showWord={false} delta={0} />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
deltanumber | null—A ratio: 0.12 reads +12%. null: nothing to compare with.
better"up" | "down""up"Which way is good news: down for open tickets.
format(delta: number) => string+12.4%Writes the delta.
valueReactNode—The figure it belongs to.
hintReactNode—What it was compared with: vs last month.
showWordbooleantrueBetter, Worse or Flat after the sign. Off, it is still read aloud.
size"sm" | "md""md"Of the badge.
classNamestring—Extra classes.