🚀 Ship faster with premium components 🚀
Search documentation v1.1.0

Stats

Display KPIs with supporting visuals

Source Report Issue
Command docs
How to add this block to your project
npm run add Stats

Use the Stats component to display key performance indicators (KPIs) such as sales, growth, or trends with supporting visuals like percentages, icons, and color indicators.

Sales $1,234 12%
Unlock code
How to use the Stats component in Astro
---
// Your import path to your icons might differ
import shoppingBag from '@icons/shopping-bag.svg?raw'
---
<Stats
label="Sales"
amount={1234}
percentage={12}
symbol="$"
button={{ text: 'Details', href: '/details' }}
icon={shoppingBag}
/>

The label and amount props are mandatory, the rest of the props are optional however. When setting the icon you can pass an SVG string or one of the icon types defined in the icon documentation page.

Percentages

Depending on the value of the percentage prop, the badge can be in one of three states; declining, stagnating, or increasing:

Negative percentage -$1,234 -12%
0 percentage $1,234 0%
Positive percentage $1,234 12%
Unlock code
Badge will react to the value of percentage
<Stats
label="Negative percentage"
symbol="$"
amount={-1234}
percentage={-12}
button={{ text: 'Details', href: '/details' }}
icon={shoppingBag}
/>

You can also pass a negative amount and it’ll be formatted in accordance with the symbol. If you want to emphasize directions, you can also specify a color prop and set the color of the amount as well:

Negative percentage -$1,234 -12%
0 percentage $1,234 0%
Positive percentage $1,234 12%
Unlock code
How to set the amount color
<Stats
label="Negative percentage"
symbol="$"
amount={-1234}
percentage={-12}
color="var(--w-color-alert)"
button={{ text: 'Details', href: '/details' }}
icon={shoppingBag}
/>

Action Button

The button prop can be configured with the same props as a Button component. It can function as a link or a button. You can configure themes using the theme property:

Theme set to secondary -$1,234 -12%
Theme set to warning $1,234 0%
Theme set to success $1,234 12%
Unlock code
How to customize button
<Stats
...
button={{ text: 'Details', href: '/details', theme: 'secondary' }}
/>

Card Configurations

The Stats component is based on the Card component, meaning you can use card-specific props to customize your stats by setting a card prop:

Last 30 days
Sales $1,234 12%
Unlock code
How to customize card
<Stats
...
card={{ title: 'Last 30 days', secondary: true }}
/>

API

Unlock code
Component API reference
type StatsProps = {
label: string
amount: number
percentage?: number
symbol?: string
color?: string
icon?: string
button?: ({
text?: string
icon?: string
} & ButtonProps)
card?: CardProps
className?: string
}
Please see the documentation of the Button component for the ButtonProps type, and the documentation of the Card component for the CardProps type.
PropPurpose
label Sets a label for the card.
amount Sets an amount displayed under the label.
percentage Sets a percentage badge displayed next to the amount.
symbol Sets a symbol, displayed in front of the amount.
color Sets the text color of the amount prop.
icon Sets an icon in the top-left corner of the card.
button.text Sets a button in the top-right corner of the card.
button.icon Sets an icon for the button.
card Pass a CardProps object to customize the card.
className Pass additional CSS classes for the Stats component.