Examples

A compact inline indicator that conveys change direction and magnitude using a directional arrow and formatted text. Positive values render in green, negative in red, and values within the neutral threshold in muted gray.

Positive / Negative / Neutral

13% 7% 0% 0%

Inverted Colors (lower-is-better metrics)

e.g. bounce rate, RTO — a decrease is good, an increase is bad

5% 4% 0%

Hide Arrow

18% 5% 0%

Custom Format — Currency Delta

+$42.50 -$18.75

Custom Format — Basis Points

+25.0 bps -10.0 bps

CSS Variable Theming

9% 3%

Documentation

A compact inline indicator that conveys change direction and magnitude using a directional arrow and formatted text. Positive values are rendered in green, negative in red, and values within the neutral threshold in muted gray. Supports inverted color semantics for lower-is-better metrics (e.g. bounce rate, RTO), an optional arrow-hide mode for text-only display, a configurable neutral threshold, and a custom format function for full control over the displayed text.

Usage

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

<DeltaIndicator value={12.5} />

Negative and Neutral

<DeltaIndicator value={-7.3} />
<DeltaIndicator value={0} />

Neutral Threshold

Values whose absolute magnitude is at or below neutralThreshold are treated as neutral and rendered in the muted color without an arrow.

<!-- 0.4 is within ±0.5 — treated as neutral -->
<DeltaIndicator value={0.4} neutralThreshold={0.5} />

Inverted Colors

Use invertColors for lower-is-better metrics where a decrease is "good" (green) and an increase is "bad" (red).

<!-- Bounce rate dropped 5.2% — good, renders green -->
<DeltaIndicator value={-5.2} invertColors />

<!-- Bounce rate rose 3.8% — bad, renders red -->
<DeltaIndicator value={3.8} invertColors />

Hide Arrow

<DeltaIndicator value={18} hideArrow />

Custom Format

Pass a format function (value: number) => string to control the displayed text. The raw (signed) value is passed; use Math.abs inside if you want to suppress the sign.

<script>
  const currencyFormat = (v: number) => `${v >= 0 ? '+' : '-'}$${Math.abs(v).toFixed(2)}`;
</script>

<DeltaIndicator value={42.5} format={currencyFormat} />

Animated Value

Set animateValue to roll the displayed text through AnimatedNumber on every change, instead of swapping it as plain text. The formatted STRING (the output of format, or the default ${Math.round(Math.abs(value))}%) is what animates — not the raw value — so a custom format still rolls, without DeltaIndicator having to know how to reproduce it.

<script>
  let churn = $state(4.2);
</script>

<DeltaIndicator value={churn} animateValue />
<button onclick={() => (churn = 6.8)}>+2.6</button>

Theming with Classes

Define a class in your CSS that sets DeltaIndicator CSS variables and pass it via classes:

/* app.css */
.delta-large {
  --delta-indicator-font-size: 18px;
  --delta-indicator-arrow-size: 14px;
  --delta-indicator-gap: 5px;
}
<DeltaIndicator value={9.1} classes="delta-large" />

Props

Prop Type Required Default Description
value number Yes - The change amount. Its sign determines direction: positive → up, negative → down. When the absolute value is ≤ neutralThreshold, direction is neutral.
format (value: number) => string No v => Math.round(Math.abs(v)) + '%' Custom formatter for the displayed text. Receives the raw signed value. Default shows the rounded absolute value followed by a percent sign.
invertColors boolean No false Swaps the up/down color tone for lower-is-better metrics. When true, an upward change renders in red and a downward change renders in green.
hideArrow boolean No false Hides the directional triangle arrow, rendering only the formatted text string.
neutralThreshold number No 0 Absolute values at or below this threshold are classified as neutral (muted color, no arrow). Useful for suppressing noise on near-zero changes.
animateValue boolean No false Rolls the displayed text through AnimatedNumber instead of swapping it as plain text. Animates the formatter's output string, so a custom format still animates.
testId string No - Value for the data-pw attribute on the root element, used for end-to-end testing selectors.
classes string No - CSS class string applied to the root element. Useful for theming via class-scoped CSS variable overrides.

CSS Variables

Override these custom properties to theme the component.

Variable Default CSS Property Description
--delta-indicator-gap 2px gap Space between the arrow icon and the text label.
--delta-indicator-font-size 13px font-size Font size of the indicator text.
--delta-indicator-font-weight 600 font-weight Font weight of the indicator text.
--delta-indicator-positive-color #1a9d6f color Color used when the tone is positive (value up, or value down + invertColors).
--delta-indicator-negative-color #e5484d color Color used when the tone is negative (value down, or value up + invertColors).
--delta-indicator-neutral-color #8a8a8a color Color used when the value is within the neutral threshold.
--delta-indicator-arrow-size 9px width, height Size of the directional triangle arrow SVG.
--delta-indicator-arrow-stroke-width 2 stroke-width Stroke width of the arrow SVG.

Web Component

Tag: <sui-delta-indicator>

<sui-delta-indicator value="12.5"></sui-delta-indicator>
<sui-delta-indicator value="-7.3" invert-colors></sui-delta-indicator>
<sui-delta-indicator value="18" hide-arrow></sui-delta-indicator>
<sui-delta-indicator value="0.4" neutral-threshold="0.5"></sui-delta-indicator>
<sui-delta-indicator value="12.5" animate-value></sui-delta-indicator>

Passing a custom format function via the web component requires setting the property programmatically:

const el = document.querySelector('sui-delta-indicator');
el.format = (v) => `${v >= 0 ? '+' : ''}${v.toFixed(1)} bps`;