Alert
An inline, persistent message — 6 colors, 3 variants, an action slot, a close button and a banner mode.
'use client';
import { Alert } from '@akhatmirzo/ui';
export default function AlertColors() {
return (
<div className="flex w-full max-w-xl flex-col gap-3">
<Alert title="Yangi versiya chiqdi">
Sahifani yangilang — o'zgarishlar darhol kuchga kiradi.
</Alert>
<Alert color="success" title="Buyurtma qabul qilindi">
Kuryer bugun 18:00 gacha qo'ng'iroq qiladi.
</Alert>
<Alert color="warning" title="Obuna 3 kundan keyin tugaydi">
To'lovni hozir qilsangiz, ma'lumotlaringiz saqlanib qoladi.
</Alert>
<Alert color="danger" title="To'lov o'tmadi">
Kartada mablag' yetarli emas. Boshqa kartani sinab ko'ring.
</Alert>
<Alert color="primary" title="Maslahat">
Tez qidirish uchun Ctrl + K ni bosing.
</Alert>
<Alert color="neutral" title="Qoralama saqlandi" />
</div>
);
}
Import
import { Alert } from '@akhatmirzo/ui';When to use
- For messages that should stay on the page — an expiring subscription, a failed payment, a form-level problem. An alert doesn't disappear by itself; it sits in the content flow.
- For short, temporary feedback — "Saved", "Copied" — use a
Toastinstead. - Match the color to the meaning:
dangerfor errors,warningfor warnings,successfor success,infofor information. Let the title state the problem — don't rely on color alone. - One action is enough — "Try again", "Pay now". If you need more, consider a
Dialog. - Your app controls dismissal — remove the alert yourself in
onClose.
Colors
color: info (default), neutral, primary, success, warning and danger. Each color has
a matching built-in icon: ⓘ, ✓, △, ⊗. Pass your own with icon, or icon={false} for none.
Variants
variant: soft (default) is a light background, outline is a colored border on the surface
color, and solid is a strong background that draws the most attention.
'use client';
import { Alert } from '@akhatmirzo/ui';
export default function AlertVariants() {
return (
<div className="flex w-full max-w-xl flex-col gap-3">
<Alert color="success" variant="soft" title="Soft">
Yumshoq fon — standart ko'rinish.
</Alert>
<Alert color="success" variant="outline" title="Outline">
Rangli chegara va oddiy fon.
</Alert>
<Alert color="success" variant="solid" title="Solid">
To'q fon — eng ko'p e'tibor tortadi.
</Alert>
</div>
);
}
Action and close
action renders on the right (it drops below the text on narrow screens). Pass onClose to show
a ✕ button.
'use client';
import { Alert, Button } from '@akhatmirzo/ui';
import { useState } from 'react';
export default function AlertActions() {
const [open, setOpen] = useState(true);
if (!open) {
return (
<Button size="sm" onClick={() => setOpen(true)}>
Xabarni qaytarish
</Button>
);
}
return (
<Alert
className="max-w-xl"
color="danger"
title="To'lov o'tmadi"
action={
<Button size="sm" variant="outline">
Qayta urinish
</Button>
}
onClose={() => setOpen(false)}
>
Bank to'lovni rad etdi. Karta ma'lumotlarini tekshiring.
</Alert>
);
}
Banner
banner is for the top of a page: square corners, a bottom border only and centered content.
'use client';
import { Alert, Button } from '@akhatmirzo/ui';
import { useState } from 'react';
export default function AlertBanner() {
const [open, setOpen] = useState(true);
return (
<div className="w-full overflow-hidden rounded-lg border border-border bg-surface">
{open && (
<Alert banner color="primary" onClose={() => setOpen(false)}>
Bugun 23:00 dan 01:00 gacha texnik ishlar olib boriladi.
</Alert>
)}
<div className="flex items-center justify-between gap-3 p-6 text-sm text-text-muted">
Sahifa kontenti
{!open && (
<Button size="sm" onClick={() => setOpen(true)}>
Qaytarish
</Button>
)}
</div>
</div>
);
}
Props
Alert accepts every other <div> attribute (except color and title, which are used as
props).
| Prop | Type | Default | Description |
|---|---|---|---|
color | 'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'info' | Color (meaning) and built-in icon |
variant | 'soft' | 'outline' | 'solid' | 'soft' | Visual style |
title | ReactNode | — | Bold title |
icon | ReactNode | false | — | Icon. Defaults to a built-in SVG for the color; false hides it |
action | ReactNode | — | Action on the right (below the text on narrow screens) |
onClose | () => void | — | Shows a ✕ button when set |
banner | boolean | false | Top-of-page mode: no radius, bottom border only, centered content |
labels | { close?: string } | { close: 'Yopish' } | aria-label of the ✕ button |
Data attributes
On the root: data-color, data-variant and data-banner (in banner mode). alertVariants is
exported too, so you can apply the styles to another element.
Accessibility
- The role follows the color:
dangerandwarninggetrole="alert"(read out right away), the rest getrole="status"(read politely). Pass your ownroleif you need to. - Color is never the only signal — the icon and title also tell the type. The icon is
aria-hidden. - The ✕ button is a real
<button>: it's reachable withTaband works withEnter/Space. Change its label withlabels.close. - Alerts present on page load may not be announced —
role="alert"mainly helps with messages that appear later.