Command palette

@yasinsensoy/web

Web · Components

Alert

A message that needs attention within the page.

4 exports

Live example

Preview

Code

import { Alert } from "@yasinsensoy/web";

<Alert tone="danger" title="Payment failed">
  Check your card details and try again.
</Alert>

Events

  1. Events appear here when you interact with the preview.

Import

import { Alert } from "@yasinsensoy/web";

Alert

componentClient component

A message that needs attention within the page. Title, description, icon, action and close button are given with props.

Screen reader behavior: messages already visible when the page loads need no role. For messages that appear later and must be announced right away use role="alert", and role="status" for less urgent ones. For short notifications that come and go use toast.

Alert({ tone, variant: variantProp, effect, title, icon, action, onClose, classNames, className, children, ...props }: AlertProps): JSX.Element

Examples

<Alert tone="danger" title="Payment failed">
  Check your card details and try again.
</Alert>

<Alert tone="warning" variant="soft" title="Your trial is ending"
  action={<Button size="sm">Upgrade</Button>} onClose={close} />

<Alert icon="rocket" title="A new version is ready" />

Style of the alert box.

type AlertVariant = "outline" | "soft"

Classes that can be given to the inner parts of Alert.

NameTypeDescription
icon?stringIcon box.
title?stringTitle.
description?stringDescription (children).
action?stringAction area.

AlertProps

interface

Props of the Alert component.

Extends: Omit<ComponentProps<"div">, "title">

NameTypeDefaultDescription
tone?Tone"neutral"Color and default icon.
variant?AlertVariant | CustomVariant<"alert">"outline"Style: built-in or a custom style added with defineAppearance. Defaults to UIProvider appearance.defaults.alert.variant.
effect?EffectPropEffect or effects (e.g. "beam", ["border", "glow"]). The accent color comes from tone. See BuiltinEffect.
title?ReactNodeBold title.
icon?IconPropIcon left of the title: a name or an element. When omitted an icon matching the color is drawn; hidden with false.
action?ReactNodeAction shown on the right (below on mobile), e.g. a Button.
onClose?() => voidWhen given, a close (×) button appears at the top right and is called on click.
classNames?AlertClassNamesClasses added to the inner parts.