Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Core

Alert

Message about the page or a task. warning and danger alerts are announced right away (role="alert"); the others are announced politely.

import { Alert } from "@stylhero/ui";

Example

Code
import { Alert, Button, Stack } from "@stylhero/ui";

function AlertExample() {
  return (
    <Stack gap={3}>
      <Alert title="Saved">Your build is saved to your account.</Alert>
      <Alert tone="success" variant="outlined">Payment received.</Alert>
      <Alert tone="warning" title="Price changed" action={<Button size="sm" variant="secondary">Review</Button>}>
        The GPU is $40 more than when you added it.
      </Alert>
      <Alert tone="danger" variant="filled" onClose={() => {}}>Couldn't reach the store.</Alert>
    </Stack>
  );
}

Props

PropTypeDefaultDescription
action ReactNode - A button on the right, e.g. <Button size="sm" variant="ghost">Undo</Button>.
icon ReactNode - Replace the default icon, or pass null for none.
onClose () => void - Shows a close button.
title ReactNode -
tone "info" | "success" | "warning" | "danger" "info"
variant "soft" | "outlined" | "filled" "soft" "filled" is the loud, solid version.

Also takes every <div> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.

Accessibility

  • warning and danger use role="alert" (announced right away); info and success use role="status" (announced when the reader is idle).

Generated from src/components/Alert.tsx. Something wrong or missing? Open an issue.