Карточки cardstats
Data Stat Card
Компактная карточка статистики для отображения ключевых метрик с иконкой.
Живое превью
Total Revenue
$124,590
+14.2% vs last month
Использование
Скопируйте и вставьте этот код на вашу страницу Astro:
astro
---
import { DataStatCard } from 'astro-component-kit';
---
<StatCard label="Total Revenue" value="$124,590" change="+14.2%" trend="up" icon="revenue" timeframe="vs last month" /> ---
import { DataStatCard } from 'astro-component-kit';
---
<StatCard label="Total Revenue" value="$124,590" change="+14.2%" trend="up" icon="revenue" timeframe="vs last month" /> Ручная установка
Если вы не используете пакет npm, создайте файл и вставьте следующий код: src/components/lib/DataStatCard.astro:
astro
---
/**
* StatCard — Metric highlight card featuring delta trends, values, and SVG iconography.
*
* @param {string} label - Metric description (default: 'Total Revenue').
* @param {string} value - Formatted metric figure (default: '$124,590').
* @param {string} change - Delta percentage string (default: '+14.2%').
* @param {'up' | 'down' | 'neutral'} trend - Direction of the change (default: 'up').
* @param {string} timeframe - Comparison timeframe (default: 'vs last month').
* @param {'revenue' | 'users' | 'activity' | 'growth'} icon - Icon preset (default: 'revenue').
* @param {string} className - Optional additional CSS class.
*/
interface Props {
label?: string;
value?: string;
change?: string;
trend?: 'up' | 'down' | 'neutral';
timeframe?: string;
icon?: 'revenue' | 'users' | 'activity' | 'growth';
className?: string;
}
const {
label = 'Total Revenue',
value = '$124,590',
change = '+14.2%',
trend = 'up',
timeframe = 'vs last month',
icon = 'revenue',
className = '',
} = Astro.props;
---
<div class:list={['stat-card', `stat-card--${trend}`, className]}>
<div class="stat-card__top">
<span class="stat-card__label">{label}</span>
<div class="stat-card__icon" aria-hidden="true">
{icon === 'revenue' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="1" x2="12" y2="23" />
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
</svg>
)}
{icon === 'users' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
<circle cx="9" cy="7" r="4" />
<path d="M23 21v-2a4 4 0 0 0-3-3.87" />
<path d="M16 3.13a4 4 0 0 1 0 7.75" />
</svg>
)}
{icon === 'activity' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
</svg>
)}
{icon === 'growth' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="20" x2="18" y2="10" />
<line x1="12" y1="20" x2="12" y2="4" />
<line x1="6" y1="20" x2="6" y2="14" />
</svg>
)}
</div>
</div>
<div class="stat-card__value-row">
<span class="stat-card__value">{value}</span>
</div>
<div class="stat-card__bottom">
<span class:list={['stat-badge', `stat-badge--${trend}`]}>
{trend === 'up' && (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="18 15 12 9 6 15" />
</svg>
)}
{trend === 'down' && (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9" />
</svg>
)}
<span>{change}</span>
</span>
{timeframe && <span class="stat-card__timeframe">{timeframe}</span>}
</div>
</div>
<style>
.stat-card {
position: relative;
width: 100%;
max-width: 320px;
padding: 1.5rem;
border-radius: var(--r-xl, 20px);
background: rgba(18, 22, 34, 0.65);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
color: var(--c-text-1, #f8fafc);
display: flex;
flex-direction: column;
gap: 0.75rem;
transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
transform: translateY(-3px);
border-color: rgba(99, 102, 241, 0.3);
box-shadow: 0 20px 40px -12px rgba(99, 102, 241, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.stat-card__top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
}
.stat-card__label {
font-size: 0.85rem;
font-weight: 500;
color: var(--c-text-3, #94a3b8);
}
.stat-card__icon {
width: 36px;
height: 36px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(99, 102, 241, 0.12);
border: 1px solid rgba(99, 102, 241, 0.2);
color: var(--c-primary-light, #818cf8);
flex-shrink: 0;
}
.stat-card__value-row {
display: flex;
align-items: baseline;
}
.stat-card__value {
font-size: 2rem;
font-weight: 800;
letter-spacing: -0.03em;
color: #ffffff;
line-height: 1.1;
}
.stat-card__bottom {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
margin-top: 0.25rem;
}
.stat-badge {
display: inline-flex;
align-items: center;
gap: 0.2rem;
padding: 0.2rem 0.5rem;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 700;
}
.stat-badge--up {
background: rgba(34, 197, 94, 0.12);
color: #4ade80;
border: 1px solid rgba(34, 197, 94, 0.25);
}
.stat-badge--down {
background: rgba(239, 68, 68, 0.12);
color: #f87171;
border: 1px solid rgba(239, 68, 68, 0.25);
}
.stat-badge--neutral {
background: rgba(148, 163, 184, 0.12);
color: #94a3b8;
border: 1px solid rgba(148, 163, 184, 0.25);
}
.stat-card__timeframe {
font-size: 0.78rem;
color: var(--c-text-3, #64748b);
}
</style> ---
/**
* StatCard — Metric highlight card featuring delta trends, values, and SVG iconography.
*
* @param {string} label - Metric description (default: 'Total Revenue').
* @param {string} value - Formatted metric figure (default: '$124,590').
* @param {string} change - Delta percentage string (default: '+14.2%').
* @param {'up' | 'down' | 'neutral'} trend - Direction of the change (default: 'up').
* @param {string} timeframe - Comparison timeframe (default: 'vs last month').
* @param {'revenue' | 'users' | 'activity' | 'growth'} icon - Icon preset (default: 'revenue').
* @param {string} className - Optional additional CSS class.
*/
interface Props {
label?: string;
value?: string;
change?: string;
trend?: 'up' | 'down' | 'neutral';
timeframe?: string;
icon?: 'revenue' | 'users' | 'activity' | 'growth';
className?: string;
}
const {
label = 'Total Revenue',
value = '$124,590',
change = '+14.2%',
trend = 'up',
timeframe = 'vs last month',
icon = 'revenue',
className = '',
} = Astro.props;
---
<div class:list={['stat-card', `stat-card--${trend}`, className]}>
<div class="stat-card__top">
<span class="stat-card__label">{label}</span>
<div class="stat-card__icon" aria-hidden="true">
{icon === 'revenue' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="1" x2="12" y2="23" />
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
</svg>
)}
{icon === 'users' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
<circle cx="9" cy="7" r="4" />
<path d="M23 21v-2a4 4 0 0 0-3-3.87" />
<path d="M16 3.13a4 4 0 0 1 0 7.75" />
</svg>
)}
{icon === 'activity' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
</svg>
)}
{icon === 'growth' && (
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="20" x2="18" y2="10" />
<line x1="12" y1="20" x2="12" y2="4" />
<line x1="6" y1="20" x2="6" y2="14" />
</svg>
)}
</div>
</div>
<div class="stat-card__value-row">
<span class="stat-card__value">{value}</span>
</div>
<div class="stat-card__bottom">
<span class:list={['stat-badge', `stat-badge--${trend}`]}>
{trend === 'up' && (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="18 15 12 9 6 15" />
</svg>
)}
{trend === 'down' && (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9" />
</svg>
)}
<span>{change}</span>
</span>
{timeframe && <span class="stat-card__timeframe">{timeframe}</span>}
</div>
</div>
<style>
.stat-card {
position: relative;
width: 100%;
max-width: 320px;
padding: 1.5rem;
border-radius: var(--r-xl, 20px);
background: rgba(18, 22, 34, 0.65);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
color: var(--c-text-1, #f8fafc);
display: flex;
flex-direction: column;
gap: 0.75rem;
transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
transform: translateY(-3px);
border-color: rgba(99, 102, 241, 0.3);
box-shadow: 0 20px 40px -12px rgba(99, 102, 241, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.stat-card__top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
}
.stat-card__label {
font-size: 0.85rem;
font-weight: 500;
color: var(--c-text-3, #94a3b8);
}
.stat-card__icon {
width: 36px;
height: 36px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(99, 102, 241, 0.12);
border: 1px solid rgba(99, 102, 241, 0.2);
color: var(--c-primary-light, #818cf8);
flex-shrink: 0;
}
.stat-card__value-row {
display: flex;
align-items: baseline;
}
.stat-card__value {
font-size: 2rem;
font-weight: 800;
letter-spacing: -0.03em;
color: #ffffff;
line-height: 1.1;
}
.stat-card__bottom {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
margin-top: 0.25rem;
}
.stat-badge {
display: inline-flex;
align-items: center;
gap: 0.2rem;
padding: 0.2rem 0.5rem;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 700;
}
.stat-badge--up {
background: rgba(34, 197, 94, 0.12);
color: #4ade80;
border: 1px solid rgba(34, 197, 94, 0.25);
}
.stat-badge--down {
background: rgba(239, 68, 68, 0.12);
color: #f87171;
border: 1px solid rgba(239, 68, 68, 0.25);
}
.stat-badge--neutral {
background: rgba(148, 163, 184, 0.12);
color: #94a3b8;
border: 1px solid rgba(148, 163, 184, 0.25);
}
.stat-card__timeframe {
font-size: 0.78rem;
color: var(--c-text-3, #64748b);
}
</style>
Краткая информация
- Категория
- Карточки
- Имя файла
DataStatCard.astro- Зависимости
- Нет — чистый Astro + CSS
- Теги
- cardstats