mirror of
https://github.com/tabler/tabler.git
synced 2026-10-21 07:14:30 +04:00
- stat cards on the homepage card pattern, 90-day requests chart, readable 5xx chart - Trending gets a color override; avatar-sm icon-size lowered to 1.25rem in core
30 lines
993 B
Plaintext
30 lines
993 B
Plaintext
---
|
|
import Icon from './Icon.astro'
|
|
|
|
interface Props {
|
|
/** a number, or a signed string such as "+9.5" that is rendered as written */
|
|
value: number | string
|
|
unit?: string | undefined
|
|
/** overrides the sign-based color, e.g. "red" for a rising error rate */
|
|
color?: string | undefined
|
|
class?: string
|
|
}
|
|
|
|
const { value, unit = '%', color, class: className } = Astro.props
|
|
|
|
const amount = Number(value)
|
|
if (Number.isNaN(amount)) {
|
|
throw new Error(`Trending: value "${value}" is not a number`)
|
|
}
|
|
|
|
const trendingColor = color ?? (amount > 0 ? 'green' : amount === 0 ? 'muted' : 'red')
|
|
const trendingIcon = amount > 0 ? 'arrow-up' : amount === 0 ? 'minus' : 'arrow-down'
|
|
|
|
const classes = [`text-${trendingColor} d-inline-flex align-items-center lh-1`, className]
|
|
---
|
|
|
|
<span class:list={classes}>
|
|
<span class="visually-hidden">{amount > 0 ? 'Increased by' : amount < 0 ? 'Decreased by' : 'No change,'} </span>{value}{unit}
|
|
<Icon name={trendingIcon} class="ms-0" size="sm" />
|
|
</span>
|