ഉള്ളടക്കത്തിലേക്ക് പോകുക
ബീറ്റ · പരീക്ഷണാത്മകംReact 19പിയർ ഡിപൻഡൻസികളില്ല

Alert

A message that stays in the page — neither interrupting like a dialog nor leaving like a toast.

ബീറ്റ കമ്പോണന്റുകൾ മാറാൻ സാധ്യതയുണ്ട്; അവ നിങ്ങളുടെ കോഡ് തകരാറിലാക്കിയേക്കാം. സ്വന്തം ഉത്തരവാദിത്തത്തിൽ ഉപയോഗിക്കുക, ബഗ് ട്രാക്കർ വഴി അഭിപ്രായം അറിയിക്കുക.

ഈ പേജ് ഇതുവരെ വിവർത്തനം ചെയ്തിട്ടില്ല, അതിനാൽ ഇംഗ്ലീഷ് പതിപ്പാണ് താഴെ കാണിക്കുന്നത്.
ഈ പേജിൽ

Installation

npx gbs-add-block@latest -a Alert -beta

The block copies the alert folder into your project, along with the small shared folder that every component imports. You own the code and can change it freely. There are no peer dependencies other than React.

Requirements

  • React 19 and @types/react 19
  • TypeScript target ES2022 or newer, with "jsx": "react-jsx"
  • Browsers from 2024 or newer (the styles use light-dark() and color-mix())

Import the stylesheet once, for example in your global CSS:

css
@import "../components/alert/styles.css";

or in your root layout / entry file:

ts
import "@/components/alert/styles.css";

An Alert is a message that sits in the layout and stays there: a trial ending, a record that is read-only, the summary above a form that failed validation.

Set the --gbs-* variables on :root to theme every component at once, the grid included. Each component's own variables fall back to them, and then to the built-in palette, so components look identical out of the box.

Default

Live preview

Quick Start

tsx
import { Alert } from "@/components/alert";
 
<Alert variant="warning" title="Your trial ends in 3 days">
  After that the workspace becomes read-only. <a href="/billing">Add a card</a>{" "}
  to keep it.
</Alert>;

The component has no state of its own and no "use client" — a plain Alert renders in a Server Component. Only onDismiss needs a client component around it.

Which one to reach for

Interrupts?LivesDismissed byUse it for
DialogYes, blocks the pageTop layerAcknowledging itA decision that has to happen before anything else
ToastNo, and it leavesA cornerItself, after a few secondsConfirming something that already happened
AlertNo, and it staysIn the layoutUsually nothingThe state a page or section is in

Your Dialog already covers the modal case — dialog.alert({ … }). This is the third row.

Props Table

Accepts every <div> attribute, plus:

PropTypeDefaultDescription
variant"info" | "success" | "warning" | "danger" | "neutral""info"Sets the colour, the glyph and how loudly it announces itself.
size"sm" | "md""md"sm is one line, for an inline note.
titleReactNodeThe headline.
descriptionReactNodeThe message. children does the same and is the better place for links.
iconReactNode | falsethe variant'sReplace the glyph, or drop it.
actionsReactNodeButtons under the message.
onDismiss() => voidShows a close button. The alert does not hide itself — remove it in the handler.
classNamesPartial<Record<AlertSlot, string>>root icon content title description actions dismiss
localeTextPartial<AlertLocaleText>dismiss

How loudly it speaks

An alert that appears after the page has loaded is news, and a screen reader has to be told whether it is worth interrupting for:

VariantRoleEffect
danger, warningalertCuts into whatever is being read.
info, success, neutralstatusWaits for a pause.

"Your card was declined" earns the interruption; "240 rows imported" does not.

An alert that was on the page from the start announces nothing either way — a live region only speaks when its contents change — so it is read in its turn like any other text.

Mount the alert when the thing happens, rather than keeping a hidden one and revealing it with CSS. A live region announces a change to its contents, and a node that was always there with `display: none` may not count as a change at all.

Styling and Theming

All rules are in the CSS components layer, so utility classes passed through className override them.

CSS variables

Override them on .al-root, on :root, or through style. Each falls back to the shared --gbs-* of the same name, then to the DataGrid's --dg-* when that stylesheet is loaded, and finally to the built-in palette.

VariableUsed for
--al-accentThe bar, the glyph and links. Set by variant.
--al-bgWhat the tint is mixed into.
--al-px, --al-pyPadding (set by size).
--al-radiusCorner radius.

The background is color-mix(in oklab, var(--al-accent) 7%, var(--al-bg)), so a themed accent tints the banner without a second variable to keep in step. Colour is never the only signal: there is a glyph, a heavier start border and the text itself.

Data attributes

ElementAttributes
Root (.al-root)data-variant, data-size

Next.js

There is no "use client" in this component and no state, so it renders in a Server Component — useful for the banner on a page that is server-rendered from a record's own state.

onDismiss is a function, so an alert that can be dismissed needs a client component around it.

Notes

  • A dismissible alert that comes back on the next render will not announce itself twice unless it is actually remounted.
  • Keep the message short enough to read at a glance; an alert with three paragraphs is a page, not a banner.