@akhatmirzo/ui

Alert

An inline, persistent message — 6 colors, 3 variants, an action slot, a close button and a banner mode.

Yangi versiya chiqdi
Sahifani yangilang — o'zgarishlar darhol kuchga kiradi.
Buyurtma qabul qilindi
Kuryer bugun 18:00 gacha qo'ng'iroq qiladi.
Maslahat
Tez qidirish uchun Ctrl + K ni bosing.
Qoralama saqlandi

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 Toast instead.
  • Match the color to the meaning: danger for errors, warning for warnings, success for success, info for 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.

Soft
Yumshoq fon — standart ko'rinish.
Outline
Rangli chegara va oddiy fon.
Solid
To'q fon — eng ko'p e'tibor tortadi.

Action and close

action renders on the right (it drops below the text on narrow screens). Pass onClose to show a ✕ button.

banner is for the top of a page: square corners, a bottom border only and centered content.

Bugun 23:00 dan 01:00 gacha texnik ishlar olib boriladi.
Sahifa kontenti

Props

Alert accepts every other <div> attribute (except color and title, which are used as props).

PropTypeDefaultDescription
color'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info''info'Color (meaning) and built-in icon
variant'soft' | 'outline' | 'solid''soft'Visual style
titleReactNode—Bold title
iconReactNode | false—Icon. Defaults to a built-in SVG for the color; false hides it
actionReactNode—Action on the right (below the text on narrow screens)
onClose() => void—Shows a ✕ button when set
bannerbooleanfalseTop-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: danger and warning get role="alert" (read out right away), the rest get role="status" (read politely). Pass your own role if 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 with Tab and works with Enter / Space. Change its label with labels.close.
  • Alerts present on page load may not be announced — role="alert" mainly helps with messages that appear later.

On this page