mirror of
https://github.com/tabler/tabler.git
synced 2026-10-12 05:06:55 +04:00
28 lines
874 B
Plaintext
28 lines
874 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
|
|
class?: string
|
|
}
|
|
|
|
const { value, unit = '%', class: className } = Astro.props
|
|
|
|
const amount = Number(value)
|
|
if (Number.isNaN(amount)) {
|
|
throw new Error(`Trending: value "${value}" is not a number`)
|
|
}
|
|
|
|
const trendingColor = amount > 0 ? 'green' : amount === 0 ? 'secondary' : '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>
|