Examples

A flexible metric card for displaying KPIs. Supports a single value with a delta badge, or multiple metric rows with per-row headings, tooltips, deltas, and breakdown grids. Additional header slots allow tooltips, checkboxes, and custom right-aligned content.

Basic — Value + Delta

Total Orders
8,610
+12.5%
RTO Rate
11.8%
-2.3%
Avg Order Value
₹1,240
0%

Primary-only animation

animatePrimary animates ONE value per card. With primary="auto" the card measures its own rendered slots and takes the largest that is actually a metric — here the 44px subtitle, not the 18px rows beneath it. The identifier row is never animated whatever the setting, because it is not a metric.

Total Sales
PREPAID
36000
COD
24000
60000
Anomaly source
ACCOUNT
Shinchan Store GA4 (987654321)
demo-store.myshopify.com

With Subtitle

Checkout Conversion
68.4%
+3.1%
vs last 30 days

With Title Tooltip

Net Revenue
₹10.9Cr
+5.7%

With Header Checkbox

Include Returns
With returns
₹10.9Cr
+5.7%

Header Without Title

A checkbox-only header renders even when no title is set.

Include returns
₹10.9Cr
+5.7%

Clickable Card With Checkbox

Toggling the checkbox does not trigger the card's click action. Card clicks: 0

View Report
Live data
68.4%
+3.1%
0

Multi-Row — Revenue Breakdown

Revenue Overview
Gross Revenue
₹12.4Cr
8%
Net Revenue
₹10.9Cr
6%
after RTO
RTO Rate
12.1%
2%

Horizontal Rows (sections side by side)

Revenue Overview
Gross Revenue
₹12.4Cr
8%
Net Revenue
₹10.9Cr
6%
after RTO
RTO Rate
12.1%
2%

Multi-Row with Breakdown Grid

Conversion Metrics
Checkout Conversion
68.4%
3%
By Device
Mobile
71.2%
4%
Desktop
63.8%
2%
Tablet
58.1%
1%

Multi-Row With Subtitle

The subtitle (e.g. a date-comparison label) renders below the metric rows. It must not be suppressed when rows are present.

Revenue Overview
Gross Revenue
₹12.4Cr
8%
Net Revenue
₹10.9Cr
6%
after RTO
RTO Rate
12.1%
2%
Today vs Yesterday

Multi-Row With Per-Row Subtitles

Each row can carry its own comparison-period label, independent of the card-level subtitle — e.g. when different rows compare against different baselines.

Revenue Overview
Gross Revenue
₹12.4Cr
8%
Today vs Yesterday
Net Revenue
₹10.9Cr
6%
This Week vs Last Week

Row Additional Content Stays Inline By Default

By default, additionalContent renders inline alongside the value/delta, wrapping only if it does not fit — e.g. a short unit suffix like the ones this card renders.

Success Rate
--
%

Row Additional Content Forces Its Own Line (additionalContentBreak)

Setting additionalContentBreak forces additionalContent onto its own line below the value/delta, even with plenty of horizontal room to fit inline.

Wide Row
Revenue
₹12.4Cr
8%
short

Row Value Tint (valueVariant)

Order Health
Delivered
98.4%
RTO Risk
12.1%

Row Value & Heading Typography Override

--statcard-row-value-font-size/--statcard-row-value-font-weight and --statcard-row-heading-font-size/--statcard-row-heading-font-weight let a single row's value and heading render at a size/weight that differs from the card-level default and from its sibling rows — scoped via the row's own testId. The third row sets no override and keeps today's shared card-level typography.

Mixed Weight Rows
Primary KPI
₹1.23Cr
8%
Secondary Metric
₹340k
3%
Untouched Row
₹98k
1%

Row Order Override (title → subtitle → value)

A row's heading, value line, and subtitle render in that markup order by default. --statcard-row-heading-order, --statcard-row-subtitle-order, and --statcard-row-value-line-order let a single row rearrange its own sub-elements — e.g. title → subtitle → value — scoped via the row's own testId, mirroring the card-level --statcard-header-order/--statcard-subtitle-order/ --statcard-value-row-order pattern. The second row sets no override and keeps today's default heading → value → subtitle order.

Reordered Rows
Gross Revenue
₹12.4Cr
8%
Today vs Yesterday
Net Revenue
₹10.9Cr
6%
This Week vs Last Week

With Custom Children (ProportionBar)

Payment Methods
8,610 orders
  • UPI 4,820 (61%)
  • Cards 2,150 (27%)
  • Wallets 870 (11%)

Interactive (clickable)

View Report
68.4%
+3.1%

With Footer Snippet

Total Orders
8,610
+12.5%

Documentation

A compact metric display card for dashboards. Shows a title label, a prominent value, an optional delta badge (with automatic positive/negative colour inference from the leading sign character), an optional subtitle, a footer snippet, and an optional custom value snippet for advanced rendering. For richer dashboards it also supports a multi-row layout (rows) with per-row deltas, tooltips, and a breakdown grid, plus a header that can carry a title tooltip, a checkbox, and arbitrary right-aligned content. All visual properties are controlled via CSS custom properties. When onclick is provided a native button provides the card action and Enter/Space keyboard support, while checkboxes and other controls remain its siblings without any API change for existing consumers that omit the prop. For a plain multi-field "label: value" detail view with no big-number or delta emphasis, use KeyValue instead.

Usage

<script>
  import { StatCard } from '@juspay/svelte-ui-components';
</script>

<StatCard title="Total Revenue" value="₹1.23Cr" delta="+12.5%" subtitle="vs last month" />

Negative Delta

<StatCard title="Refund Rate" value="3.2%" delta="-0.8%" subtitle="vs last week" />

Delta colour is inferred from the leading character: + → green (--statcard-delta-positive-color), - → red (--statcard-delta-negative-color), any other character → neutral grey (--statcard-delta-color).

Explicit Delta Polarity Override

<!-- Force green even when delta string has no leading sign -->
<StatCard title="Approval Rate" value="98.4%" delta="98.4%" deltaPositive={true} />
<script>
  import { StatCard } from '@juspay/svelte-ui-components';
</script>

<StatCard title="Orders" value="1,482">
  {#snippet footer()}
    <a href="/orders">View all orders →</a>
  {/snippet}
</StatCard>

Custom Value Rendering

<script>
  import { StatCard } from '@juspay/svelte-ui-components';
</script>

<StatCard title="Conversion">
  {#snippet valueSnippet()}
    <strong style="color: #7c3aed;">68.2 %</strong>
  {/snippet}
</StatCard>

Themed Card

<div class="dark-stat">
  <StatCard title="GMV" value="₹8.4Cr" delta="+5.1%" subtitle="7-day rolling" />
</div>

<style>
  .dark-stat {
    --statcard-background: #1a1a2e;
    --statcard-border: 1px solid #2a2a3c;
    --statcard-color: #e5e7eb;
    --statcard-title-color: #9ca3af;
    --statcard-delta-positive-color: #4ade80;
    --statcard-delta-negative-color: #f87171;
  }
</style>

Interactive Card

<script>
  import { StatCard } from '@juspay/svelte-ui-components';

  const handleClick = (event: MouseEvent) => {
    console.log('stat card clicked', event);
  };
</script>

<StatCard
  title="Transactions"
  value="24,310"
  delta="+8.3%"
  onclick={handleClick}
  testId="transactions-stat-card"
/>

Multi-Row Layout

Pass rows to render several metrics stacked and divider-separated. Each row carries its own heading, a numeric change (rendered with DeltaIndicator, with invertChangeColors for lower-is-better metrics), an optional tooltip, and optional additionalContent.

<StatCard
  title="Revenue Overview"
  rows={[
    { heading: 'Gross Revenue', value: '₹12.4Cr', change: 8.2 },
    { heading: 'Net Revenue', value: '₹10.9Cr', change: 5.7, additionalContent: 'after RTO' },
    { heading: 'RTO Rate', value: '12.1%', change: -2.3, invertChangeColors: true }
  ]}
/>

Horizontal Rows

Set rowsDirection="row" to lay the sections side by side with vertical dividers (each section flexes to share the width equally) — useful for dashboard cards that show several related metrics in one row.

<StatCard
  title="Revenue Overview"
  rowsDirection="row"
  rows={[
    { heading: 'Gross Revenue', value: '₹12.4Cr', change: 8.2 },
    { heading: 'Net Revenue', value: '₹10.9Cr', change: 5.7 },
    { heading: 'RTO Rate', value: '12.1%', change: -2.3, invertChangeColors: true }
  ]}
/>

Breakdown Grid

A row can carry a breakdown array, rendered as a labelled grid beneath the row value.

<StatCard
  title="Conversion Metrics"
  rows={[
    {
      heading: 'Checkout Conversion',
      value: '68.4%',
      change: 3.1,
      breakdownHeading: 'By Device',
      breakdown: [
        { label: 'Mobile', value: '71.2%', change: 4.0 },
        { label: 'Desktop', value: '63.8%', change: 1.5 }
      ]
    }
  ]}
/>

Title Tooltip

<StatCard
  title="Net Revenue"
  value="₹10.9Cr"
  delta="+5.7%"
  tooltip={{ text: 'Revenue after returns and RTO deductions', position: 'top' }}
/>

Header Checkbox

The header renders even without a title. oncheckboxchange fires with the new checked state; drive checkbox.checked from your own state for a controlled checkbox. On an interactive card (onclick set), toggling the checkbox does not fire the card action, whether it is toggled by pointer or by Space/Enter.

checkbox.text is both the label shown beside the box and the checkbox's accessible name (see CheckListItem), so write it as a phrase that identifies what is being selected ("With returns", "Live data") rather than a bare "Select". The name does not depend on title, so a title-less card names its checkbox the same way.

<script>
  let withReturns = $state(false);
</script>

<StatCard
  title="Include Returns"
  value={withReturns ? '₹12.4Cr' : '₹10.9Cr'}
  checkbox={{ text: 'With returns', checked: withReturns }}
  oncheckboxchange={(checked) => (withReturns = checked)}
/>

Animated Values

Set animateValue to roll value (and, with rows, each row's value/comparisonValue plus every breakdown item's value) through AnimatedNumber instead of swapping the text outright. Every one of those fields is already a pre-formatted string, so nothing here surfaces the number behind it — '₹1.23Cr' → '₹1.45Cr' rolls the two digits that changed and leaves ₹, the decimal point and Cr in place. valueSnippet still takes full precedence when set, exactly as it does today.

<script>
  import { StatCard } from '@juspay/svelte-ui-components';

  let gmv = $state('₹1.23Cr');
</script>

<StatCard title="GMV" value={gmv} animateValue={true} />
<button onclick={() => (gmv = '₹1.45Cr')}>next value</button>

Header-Right Content & Children

<StatCard title="Payment Methods" value="8,610 orders">
  {#snippet headerRight()}
    <a href="/payments">Details →</a>
  {/snippet}
  <ProportionBar segments={paymentSegments} trackHeight="8px" />
</StatCard>

Props

Prop Type Required Default Description
title string No - Card heading label rendered above the value row.
value string No - Pre-formatted metric value string (e.g. "₹1.23Cr", "98.4%"). Ignored when valueSnippet is provided.
delta string No - Pre-formatted delta string (e.g. "+12.5%", "-3.2%"). Auto-infers deltaPositive from leading sign when deltaPositive is not set.
deltaPositive boolean No - Overrides automatic sign-based colour inference. true = positive (green), false = negative (red). Omit to let the leading sign decide.
subtitle string No - Secondary label rendered below the value row.
footer Snippet No - Snippet rendered in the card footer area, separated by a border-top line.
valueSnippet Snippet No - Replaces the string value with a custom snippet for advanced value rendering.
animateValue boolean No false Rolls value (and, with rows, each row's value/comparisonValue and every breakdown item's value) through AnimatedNumber's per-digit odometer instead of swapping the text outright. valueSnippet still wins outright when set. See Animated Values.
rows StatCardRow[] No - Multiple metric rows. When set, replaces the single value/delta row with a divider-separated column. Each row supports heading, comparisonValue (inline "/ ₹10L" denominator), change (number renders the delta with a "—" glyph at 0; null renders "N/A"; undefined renders nothing), invertChangeColors, tooltip, additionalContent, additionalContentBreak, valueVariant, subtitle, breakdownHeading, and a breakdown grid.
rowsDirection 'column' | 'row' No 'column' Layout direction for rows. 'column' stacks rows vertically with horizontal dividers; 'row' lays the sections side by side with vertical dividers, each section flexing to share the width equally.
tooltip StatCardTooltip No - Tooltip shown on the card title — { text, position?, testId? }.
checkbox { text: string; checked?: boolean } No - Renders a checkbox next to the title. The header is shown even when title is omitted. Pair with oncheckboxchange for a controlled checkbox.
headerRight Snippet No - Snippet rendered at the right edge of the header row.
children Snippet No - Default slot rendered inside the card body, after any rows (e.g. an embedded ProportionBar).
oncheckboxchange (checked: boolean) => void No - Fires with the new checked state when the header checkbox is toggled.
classes string No - Extra CSS class names appended to the root element. Useful for theming — define classes with CSS variable overrides and pass them to create variants.
testId string No - Value for the data-pw attribute on the root element. Used for Playwright test selectors.
onclick (event: MouseEvent) => void No - Click handler. When provided, the card root becomes interactive: role="button", tabindex="0", and Enter/Space keydown trigger the handler.

Row fields

rows[] entries accept the following, in addition to heading and value:

Field Type Description
subtitle string Secondary label below this row's value line. Independent of the card-level subtitle; both may be set, e.g. when rows compare against different baselines.
additionalContent string Trailing text on the value line (a unit, a caption).
additionalContentBreak boolean Forces additionalContent onto its own line below the value and delta. Without it the break is incidental to the container width, because the value line wraps.
valueVariant 'success' | 'warning' Tints this row's value text. Reads --statcard-value-success-color / --statcard-value-warning-color — see the note under CSS Variables.
comparisonValue string Inline denominator, e.g. / ₹10L.
change number | null number renders the delta (— at 0); null renders N/A; omit to render nothing.
invertChangeColors boolean Swaps the positive/negative colouring, for metrics where down is good.
tooltip StatCardTooltip Tooltip on the row heading — { text, position?, testId? }.
breakdownHeading string Heading above the breakdown grid.
breakdown StatCardBreakdownItem[] Grid of sub-metrics under the row.
testId string Renders as data-pw/testID on the row root. Also the CSS scoping anchor for per-row value/heading typography — see the note under CSS Variables.

Events

Event Type Description
onclick (event: MouseEvent) => void Fires when the card is clicked. When provided, the card gains role="button", tabindex="0", and keyboard support (Enter/Space). No-op if omitted.
oncheckboxchange (checked: boolean) => void Fires with the new checked state when the header checkbox is toggled. Interaction is stopped from propagating to the card's click action.

CSS Variables

Override these custom properties to theme the component.

Variable Default CSS Property Description
--statcard-gap 4px gap Vertical gap between card sections.
--statcard-padding 16px padding Inner padding of the card.
--statcard-background #ffffff background Background colour of the card.
--statcard-border 1px solid #e5e7eb border Border of the card.
--statcard-border-radius 8px border-radius Corner radius of the card.
--statcard-box-shadow none box-shadow Box shadow of the card.
--statcard-width auto width Width of the card.
--statcard-min-width 0 min-width Minimum width constraint.
--statcard-max-width none max-width Maximum width constraint.
--statcard-height auto height Height of the card.
--statcard-color inherit color Foreground text colour inherited by all child text.
--statcard-cursor default cursor Cursor on the card root. Overridden to pointer when onclick is provided.
--statcard-focus-outline 2px solid currentColor outline Focus ring on keyboard focus (interactive mode only).
--statcard-focus-outline-offset 2px outline-offset Offset of the focus ring from the card edge.
--statcard-title-font-size 12px font-size Font size of the title label.
--statcard-title-font-weight 500 font-weight Font weight of the title label.
--statcard-title-color #6b7280 color Colour of the title label.
--statcard-title-line-height 1.4 line-height Line height of the title label.
--statcard-title-white-space nowrap white-space White-space of the title label. Set to normal to allow wrapping.
--statcard-value-row-align baseline align-items Vertical alignment of value and delta within the value row.
--statcard-value-row-gap 8px gap Horizontal gap between value and delta in the value row.
--statcard-value-font-size 24px font-size Font size of the metric value.
--statcard-value-font-weight 600 font-weight Font weight of the metric value.
--statcard-value-color inherit color Colour of the metric value. Inherits card foreground by default.
--statcard-value-line-height 1.2 line-height Line height of the metric value.
--statcard-delta-font-size 13px font-size Font size of the delta badge.
--statcard-delta-font-weight 500 font-weight Font weight of the delta badge.
--statcard-delta-color #6b7280 color Colour of a neutral delta (no sign detected / deltaPositive not set).
--statcard-delta-line-height 1.4 line-height Line height of the delta badge.
--statcard-delta-positive-color #16a34a color Colour of a positive delta (+ prefix or deltaPositive={true}).
--statcard-delta-negative-color #dc2626 color Colour of a negative delta (- prefix or deltaPositive={false}).
--statcard-delta-na-color falls back to --statcard-delta-color color Colour of the "N/A" state rendered when a row's change is null.
--statcard-comparison-font-size 16px font-size Font size of the inline comparisonValue denominator ("/ ₹10L").
--statcard-comparison-font-weight 700 font-weight Font weight of the inline comparison denominator.
--statcard-comparison-color #c7c7c7 color Colour of the inline comparison denominator.
--statcard-comparison-line-height 1.4 line-height Line height of the inline comparison denominator.
--statcard-subtitle-font-size 12px font-size Font size of the subtitle label.
--statcard-subtitle-font-weight 400 font-weight Font weight of the subtitle label.
--statcard-subtitle-color #9ca3af color Colour of the subtitle label.
--statcard-subtitle-line-height 1.4 line-height Line height of the subtitle label.
--statcard-footer-margin-top 8px margin-top Top margin of the footer section.
--statcard-footer-padding-top 8px padding-top Top padding of the footer section (space between border and content).
--statcard-footer-border-top 1px solid #e5e7eb border-top Top border line separating the footer from the card body.
--statcard-header-gap 8px gap Gap between the header-left group and the header-right content.
--statcard-header-left-gap 8px gap Gap between the title, checkbox, and other header-left items.
--statcard-rows-gap 0px gap Gap between metric rows in the multi-row layout.
--statcard-row-gap 4px gap Vertical gap between a row's heading, value line, and breakdown.
--statcard-row-divider-height 1px height Thickness of the line between rows.
--statcard-row-divider-color #e5e7eb background Colour of the row divider line.
--statcard-row-divider-margin 8px 0 margin Spacing around the row divider line (vertical/column layout).
--statcard-row-divider-margin-horizontal 0 16px margin Spacing around the vertical divider when rowsDirection="row".
--statcard-row-heading-font-size 12px font-size Font size of a row heading.
--statcard-row-heading-font-weight 500 font-weight Font weight of a row heading.
--statcard-row-heading-color #6b7280 color Colour of a row heading.
--statcard-row-heading-line-height 1.4 line-height Line height of a row heading.
--statcard-row-heading-order 0 order Flex order of a row's heading wrap among its own sub-elements (heading, value line, subtitle).
--statcard-row-value-line-order 0 order Flex order of a row's value line among its own sub-elements.
--statcard-row-subtitle-order 0 order Flex order of a row's subtitle among its own sub-elements.
--statcard-breakdown-col-min 100px grid-template Minimum column width of the breakdown grid (auto-fill).
--statcard-breakdown-gap 8px gap Gap between breakdown items.
--statcard-children-margin-top 4px margin-top Top margin of the children slot content.
--statcard-value-success-color #16a34a color Value text colour when a row sets valueVariant="success".
--statcard-value-warning-color #f59e0b color Value text colour when a row sets valueVariant="warning".
--statcard-row-subtitle-font-size --statcard-subtitle-font-size font-size Font size of a per-row subtitle; falls back to the card-level subtitle size.
--statcard-row-subtitle-font-weight --statcard-subtitle-font-weight font-weight Font weight of a per-row subtitle.
--statcard-row-subtitle-color --statcard-subtitle-color color Colour of a per-row subtitle.
--statcard-row-subtitle-line-height --statcard-subtitle-line-height line-height Line height of a per-row subtitle.
--statcard-row-value-font-size --statcard-value-font-size font-size Font size of a single row's value; falls back to the card-level value size. Scoped to rows only — the single (non-rows) card value is unaffected.
--statcard-row-value-font-weight --statcard-value-font-weight font-weight Font weight of a single row's value; falls back to the card-level value weight.
--statcard-row-additional-flex-basis 100% flex-basis Width the additional content takes when additionalContentBreak is set.

valueVariant needs two tokens defined by the adopting app. Its defaults are this library's own green and amber, deliberately literal so the component renders correctly with no stylesheet at all. An app with its own semantic success and warning colours should point --statcard-value-success-color and --statcard-value-warning-color at them — otherwise the variant silently renders the library's colours, in both themes, with nothing failing.

Per-row typography is a CSS custom property, scoped through the row's own testId. --statcard-row-value-font-size/--statcard-row-value-font-weight and --statcard-row-heading-font-size/--statcard-row-heading-font-weight are ordinary CSS custom properties that inherit down from whatever element sets them — there is no StatCardRow field for the value itself. To make one row's value or heading render at a different size/weight than the rest of the card, give that row a testId and target it (the root .statcard-row element carries data-pw="<row.testId>"):

[data-pw='primary-kpi-row'] {
  --statcard-row-value-font-size: 20px;
  --statcard-row-value-font-weight: 700;
  --statcard-row-heading-font-size: 18px;
}

A row that does not set a matching selector falls back to the card-level value tokens (--statcard-value-font-size/--statcard-value-font-weight) exactly as before this pair of variables existed — an existing card with no such CSS renders byte-identically.

Per-row order is a CSS custom property too, scoped the same way. A row's heading wrap, value line, and subtitle render in that markup order by default — --statcard-row-heading-order, --statcard-row-value-line-order, and --statcard-row-subtitle-order all default to 0, so ties resolve to markup order and an untouched row is byte-identical to today. Set them on the same [data-pw="<row.testId>"] selector to rearrange a single row's sub-elements — e.g. title → subtitle → value:

[data-pw='primary-kpi-row'] {
  --statcard-row-subtitle-order: 1;
  --statcard-row-value-line-order: 2;
}

This mirrors the card-level --statcard-header-order/--statcard-subtitle-order/ --statcard-value-row-order hooks, which reorder the card's own top-level sections the same way. .statcard-row is already a display: flex; flex-direction: column container, so order applies with no other CSS needed.

Web Component

Tag: <sui-stat-card>

<sui-stat-card
  title="Total Revenue"
  value="₹1.23Cr"
  delta="+12.5%"
  subtitle="vs last month"
></sui-stat-card>

Complex props (rows, tooltip, checkbox, oncheckboxchange) are functions/objects/arrays and so are exposed as JS properties only (not HTML attributes); the headerRight and children snippets map to the header-right named slot and the default slot respectively. animateValue is a plain boolean and reflects to/from the animate-value attribute, the same as delta-positive:

<sui-stat-card title="GMV" value="₹1.23Cr" animate-value></sui-stat-card>

A JavaScript-assigned valueSnippet works before or after the element connects. Create it with the factory exported by the web-component entry, not with a separate svelte import: the standalone web-component bundle owns its own Svelte runtime, and snippets must use that same runtime.

import { createRawSnippet } from '@juspay/svelte-ui-components/wc';

const card = document.querySelector('sui-stat-card');
card.valueSnippet = createRawSnippet(() => ({
  render: () => '<strong>₹1.23Cr</strong>'
}));

When rows is non-empty, StatCard renders its row layout instead of the single-value area, so valueSnippet is intentionally not rendered. Prefer the value-snippet light-DOM slot when plain HTML is sufficient.

Web Component Events

oncheckboxchange is available as a JS property, and the same toggle also dispatches a checkboxchange DOM custom event (bubbles, composed) with detail set to the checkbox's new boolean checked state, for a consumer who only calls addEventListener:

const card = document.querySelector('sui-stat-card');
card.addEventListener('checkboxchange', (e) => console.log(e.detail));

onclick does NOT dispatch a matching DOM event — click is already HTMLElement's own native event, so card.addEventListener('click', ...) still sees only the real, natively-bubbled click, not a second synthetic one. Use card.onclick = (event) => ... instead.

Slots

Slot Name Maps to Snippet Description
value-snippet valueSnippet Rich-markup override for the value area; defaults to the plain value string.
<sui-stat-card id="revenue" title="Revenue Overview">
  <a slot="header-right" href="/payments">Details →</a>
</sui-stat-card>

<script>
  document.querySelector('#revenue').rows = [
    { heading: 'Gross Revenue', value: '₹12.4Cr', change: 8.2 },
    { heading: 'Net Revenue', value: '₹10.9Cr', change: 5.7 }
  ];
</script>