Cards cardnotification
Notification Card
Toast-like card for app notifications and alerts.
Live Preview
Deployment Succeeded Just now
Production build v2.4.0 completed in 34s and deployed across 32 edge locations.
Usage
Copy and paste this code into your Astro page:
astro
---
import { NotificationCard } from 'astro-component-kit';
---
<NotificationCard title="Updates Available" message="Version 2.0 is ready." type="info" /> ---
import { NotificationCard } from 'astro-component-kit';
---
<NotificationCard title="Updates Available" message="Version 2.0 is ready." type="info" /> Manual Installation
If you are not using the npm package, create a new file and paste the following code: src/components/lib/NotificationCard.astro:
astro
---
/**
* NotificationCard — Toast notification card for alerts, build statuses, and system messages with SVG status icons.
*
* @param {string} title - The notification headline. Default is 'Deployment Succeeded'.
* @param {string} message - The notification detail text.
* @param {'info'|'warning'|'success'|'error'} type - Notification severity style variant. Default is 'success'.
* @param {string} time - Relative time indicator (e.g. 'Just now'). Default is 'Just now'.
* @param {string} actionText - Optional action link text. Default is undefined.
* @param {string} actionHref - Destination URL for action. Default is '#'.
* @param {boolean} dismissible - Whether to render a close/dismiss action button. Default is false.
*/
interface Props {
title?: string;
message?: string;
type?: 'info' | 'warning' | 'success' | 'error';
time?: string;
actionText?: string;
actionHref?: string;
dismissible?: boolean;
}
const {
title = 'Deployment Succeeded',
message = 'Production build v2.4.0 completed in 34s and deployed across 32 edge locations.',
type = 'success',
time = 'Just now',
actionText,
actionHref = '#',
dismissible = false,
} = Astro.props;
const config = {
success: {
color: '#10b981',
bg: 'rgba(16, 185, 129, 0.12)',
border: 'rgba(16, 185, 129, 0.3)',
},
info: {
color: '#3b82f6',
bg: 'rgba(59, 130, 246, 0.12)',
border: 'rgba(59, 130, 246, 0.3)',
},
warning: {
color: '#f59e0b',
bg: 'rgba(245, 158, 11, 0.12)',
border: 'rgba(245, 158, 11, 0.3)',
},
error: {
color: '#ef4444',
bg: 'rgba(239, 68, 68, 0.12)',
border: 'rgba(239, 68, 68, 0.3)',
},
};
const current = config[type] || config.info;
---
<div class={`notify-card notify-card--${type}`} role="alert" style={`--status-color: ${current.color}; --status-bg: ${current.bg}; --status-border: ${current.border};`}>
<div class="notify-card__icon-wrap" aria-hidden="true">
{type === 'success' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
<polyline points="22 4 12 14.01 9 11.01"></polyline>
</svg>
)}
{type === 'info' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
)}
{type === 'warning' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
<line x1="12" y1="9" x2="12" y2="13"></line>
<line x1="12" y1="17" x2="12.01" y2="17"></line>
</svg>
)}
{type === 'error' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="15" y1="9" x2="9" y2="15"></line>
<line x1="9" y1="9" x2="15" y2="15"></line>
</svg>
)}
</div>
<div class="notify-card__content">
<div class="notify-card__header">
<strong class="notify-card__title">{title}</strong>
<span class="notify-card__time">{time}</span>
</div>
<p class="notify-card__message">{message}</p>
{actionText && (
<a href={actionHref} class="notify-card__action">
<span>{actionText}</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="5" y1="12" x2="19" y2="12"></line>
<polyline points="12 5 19 12 12 19"></polyline>
</svg>
</a>
)}
</div>
{dismissible && (
<button class="notify-card__close" type="button" aria-label="Dismiss notification">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
)}
</div>
<style>
.notify-card {
display: flex;
align-items: flex-start;
gap: var(--sp-4, 1rem);
padding: var(--sp-4, 1rem);
background: rgba(15, 23, 42, 0.85);
backdrop-filter: blur(16px);
border-radius: var(--r-md, 14px);
border: 1px solid var(--status-border);
box-shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.6), 0 0 16px -6px var(--status-color);
max-width: 380px;
box-sizing: border-box;
position: relative;
transition: transform 0.2s ease;
}
.notify-card:hover {
transform: translateY(-2px);
}
.notify-card__icon-wrap {
width: 34px;
height: 34px;
border-radius: 8px;
background: var(--status-bg);
border: 1px solid var(--status-border);
color: var(--status-color);
display: grid;
place-items: center;
flex-shrink: 0;
}
.notify-card__content {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.notify-card__header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5rem;
}
.notify-card__title {
font-size: 0.92rem;
font-weight: 700;
color: var(--c-text-1, #f8fafc);
}
.notify-card__time {
font-size: 0.72rem;
color: var(--c-text-3, #64748b);
white-space: nowrap;
}
.notify-card__message {
margin: 0;
font-size: 0.82rem;
color: var(--c-text-2, #94a3b8);
line-height: 1.45;
}
.notify-card__action {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 0.78rem;
font-weight: 700;
color: var(--status-color);
text-decoration: none;
margin-top: 0.2rem;
transition: opacity 0.2s ease;
}
.notify-card__action:hover {
opacity: 0.8;
}
.notify-card__close {
background: none;
border: none;
color: var(--c-text-3, #64748b);
cursor: pointer;
padding: 2px;
display: grid;
place-items: center;
border-radius: 4px;
transition: color 0.2s ease;
margin-left: -4px;
}
.notify-card__close:hover {
color: var(--c-text-1, #f8fafc);
}
</style> ---
/**
* NotificationCard — Toast notification card for alerts, build statuses, and system messages with SVG status icons.
*
* @param {string} title - The notification headline. Default is 'Deployment Succeeded'.
* @param {string} message - The notification detail text.
* @param {'info'|'warning'|'success'|'error'} type - Notification severity style variant. Default is 'success'.
* @param {string} time - Relative time indicator (e.g. 'Just now'). Default is 'Just now'.
* @param {string} actionText - Optional action link text. Default is undefined.
* @param {string} actionHref - Destination URL for action. Default is '#'.
* @param {boolean} dismissible - Whether to render a close/dismiss action button. Default is false.
*/
interface Props {
title?: string;
message?: string;
type?: 'info' | 'warning' | 'success' | 'error';
time?: string;
actionText?: string;
actionHref?: string;
dismissible?: boolean;
}
const {
title = 'Deployment Succeeded',
message = 'Production build v2.4.0 completed in 34s and deployed across 32 edge locations.',
type = 'success',
time = 'Just now',
actionText,
actionHref = '#',
dismissible = false,
} = Astro.props;
const config = {
success: {
color: '#10b981',
bg: 'rgba(16, 185, 129, 0.12)',
border: 'rgba(16, 185, 129, 0.3)',
},
info: {
color: '#3b82f6',
bg: 'rgba(59, 130, 246, 0.12)',
border: 'rgba(59, 130, 246, 0.3)',
},
warning: {
color: '#f59e0b',
bg: 'rgba(245, 158, 11, 0.12)',
border: 'rgba(245, 158, 11, 0.3)',
},
error: {
color: '#ef4444',
bg: 'rgba(239, 68, 68, 0.12)',
border: 'rgba(239, 68, 68, 0.3)',
},
};
const current = config[type] || config.info;
---
<div class={`notify-card notify-card--${type}`} role="alert" style={`--status-color: ${current.color}; --status-bg: ${current.bg}; --status-border: ${current.border};`}>
<div class="notify-card__icon-wrap" aria-hidden="true">
{type === 'success' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
<polyline points="22 4 12 14.01 9 11.01"></polyline>
</svg>
)}
{type === 'info' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
)}
{type === 'warning' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
<line x1="12" y1="9" x2="12" y2="13"></line>
<line x1="12" y1="17" x2="12.01" y2="17"></line>
</svg>
)}
{type === 'error' && (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="15" y1="9" x2="9" y2="15"></line>
<line x1="9" y1="9" x2="15" y2="15"></line>
</svg>
)}
</div>
<div class="notify-card__content">
<div class="notify-card__header">
<strong class="notify-card__title">{title}</strong>
<span class="notify-card__time">{time}</span>
</div>
<p class="notify-card__message">{message}</p>
{actionText && (
<a href={actionHref} class="notify-card__action">
<span>{actionText}</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="5" y1="12" x2="19" y2="12"></line>
<polyline points="12 5 19 12 12 19"></polyline>
</svg>
</a>
)}
</div>
{dismissible && (
<button class="notify-card__close" type="button" aria-label="Dismiss notification">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
)}
</div>
<style>
.notify-card {
display: flex;
align-items: flex-start;
gap: var(--sp-4, 1rem);
padding: var(--sp-4, 1rem);
background: rgba(15, 23, 42, 0.85);
backdrop-filter: blur(16px);
border-radius: var(--r-md, 14px);
border: 1px solid var(--status-border);
box-shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.6), 0 0 16px -6px var(--status-color);
max-width: 380px;
box-sizing: border-box;
position: relative;
transition: transform 0.2s ease;
}
.notify-card:hover {
transform: translateY(-2px);
}
.notify-card__icon-wrap {
width: 34px;
height: 34px;
border-radius: 8px;
background: var(--status-bg);
border: 1px solid var(--status-border);
color: var(--status-color);
display: grid;
place-items: center;
flex-shrink: 0;
}
.notify-card__content {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.notify-card__header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5rem;
}
.notify-card__title {
font-size: 0.92rem;
font-weight: 700;
color: var(--c-text-1, #f8fafc);
}
.notify-card__time {
font-size: 0.72rem;
color: var(--c-text-3, #64748b);
white-space: nowrap;
}
.notify-card__message {
margin: 0;
font-size: 0.82rem;
color: var(--c-text-2, #94a3b8);
line-height: 1.45;
}
.notify-card__action {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 0.78rem;
font-weight: 700;
color: var(--status-color);
text-decoration: none;
margin-top: 0.2rem;
transition: opacity 0.2s ease;
}
.notify-card__action:hover {
opacity: 0.8;
}
.notify-card__close {
background: none;
border: none;
color: var(--c-text-3, #64748b);
cursor: pointer;
padding: 2px;
display: grid;
place-items: center;
border-radius: 4px;
transition: color 0.2s ease;
margin-left: -4px;
}
.notify-card__close:hover {
color: var(--c-text-1, #f8fafc);
}
</style>
Quick Info
- Category
- Cards
- Filename
NotificationCard.astro- Dependencies
- None — pure Astro + CSS
- Tags
- cardnotification