Command palette

@yasinsensoy/native

React Native · Components

Stat

Metric (KPI) card for dashboards: name, large value, change vs the previous period, description and trend chart.

6 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Monthly revenue
$0
12.4% increasevs last month

Code

import { Stat } from "@yasinsensoy/native";

<Stat label="Monthly revenue" format="currency" changeLabel="vs last month" animate value={48230} previousValue={42900}
  sparkline={[32, 35, 31, 38, 42, 40, 47]} />

Events

  1. Events appear here when you interact with the preview.

Dashboard grid

Revenue
$48,230
12.4% increase
New members
1,284
2% decreasethis week
Error rate
1.2%
18% decrease
Target: below 1%
Response time
182ms
No change

Import

import { Stat, statChange } from "@yasinsensoy/native";

Stat

component

Metric (KPI) card for dashboards: name, large value, change vs the previous period, description and trend chart. Calculations and formatting are the same as the web Stat; screen readers read the change as e.g. "12.5% increase".

Stat({ label, value, format, prefix, suffix, previousValue, change: changeProp, changeFormat, changeLabel, higherIsBetter, description, icon, sparkline, sparklineType, sparklineColor, animate, loading, action, variant: variantProp, effect, size: sizeProp, locale: localeProp, currency: currencyProp, style, }: StatProps): JSX.Element

Examples

<Stat label="Revenue" value={48230} format="currency" previousValue={42900}
  changeLabel="vs last month" sparkline={[31, 35, 33, 40, 44, 42, 48]} />

statChange

function

Computes the change ratio and direction.

statChange(value: number, previousValue: number): {
    change: number

Direction of a change.

type StatTrend = "up" | "down" | "flat"

Value format: "number", "compact", "percent", "currency", Intl options or a function.

type StatFormat = ChartFormat

Appearance: card a bordered card, plain without a frame.

type StatVariant = "card" | "plain"

StatProps

interface

Stat props.

NameTypeDefaultDescription
labelReactNodeName of the metric (e.g. "Monthly revenue").
valuenumber | ReactNodeValue. A number is written per format, locale-aware.
format?StatFormat"number"Format of a numeric value.
prefix?ReactNodePrefix before the value (e.g. "≈").
suffix?ReactNodeUnit after the value (e.g. "pcs").
previousValue?numberValue of the previous period; when given the change ratio is computed.
change?numberChange ratio: 0.125 = a 12.5% increase. Computed from previousValue if omitted.
changeFormat?StatFormat"percent"Format of the change.
changeLabel?ReactNodePeriod written next to the change (e.g. "vs last month").
higherIsBetter?booleantrueIs an increase good? false for metrics like cost or error count.
description?ReactNodeDescription under the value.
icon?IconPropIcon next to the label.
sparkline?readonly (number | null | undefined)[]Data of the trend chart.
sparklineType?"line" | "area" | "bar""area"Chart type.
sparklineColor?ChartColorChart color; based on the trend if omitted.
animate?booleanfalseCount up whenever the number changes. Off when "reduce motion" is on.
loading?booleanPlaceholder while loading.
action?ReactNodeAction in the top right corner.
variant?StatVariant | (string & {})"card"Appearance: one of the built-in variants or a name added via appearance.variants.stat.
effect?EffectPropEffect or effects ("lift", "glow", "beam"…). Defaults to appearance.defaults.stat.effect. See BuiltinEffect.
size?"sm" | "md" | "lg""md"Size.
locale?string{@link UIProvider} `localeLocale.
currency?string{@link UIProvider} `currencyCurrency.
style?StyleProp<ViewStyle>Container style.