Skip to Content
CodeUI

Alert

@codeui/solid v0.3.0

A message inside the page that reports a status.

When to use

Use Alert for a message beside the affected snippet or export control. It stays in the page until your application removes it.

When to choose another component

Use Toast for a temporary notification outside the document flow. Use Text for a static hint that does not need an alert announcement.

Live demo

alert/basic.tsx
import { Alert } from "@codeui/solid";

export default function Demo() {
	return (
		<Alert tone="warning" showIcon title="Unsaved snippet">
			Save your snippet before you close the editor.
		</Alert>
	);
}

Anatomy

Tap a part to outline it in the demo.

  1. 01Actionalert-actionclasses.action
  2. 02Descriptionalert-descriptionclasses.description
  3. 03Iconalert-iconclasses.icon
  4. 04Rootalertclasses.root
  5. 05Titlealert-titleclasses.title
ExportRendersclasses keydata-cuiRole
Actiondivactionalert-actionNone
Descriptiondivdescriptionalert-descriptionNone
Iconspaniconalert-iconNone
Rootdivrootalertalert
Titledivtitlealert-titleNone

Variants

Tones

alert/tones.tsx
import { Alert, Stack } from "@codeui/solid";

export default function Demo() {
	return (
		<Stack gap="3">
			<Alert tone="neutral" showIcon fluid>
				Your snippet stays on this device.
			</Alert>
			<Alert tone="info" showIcon fluid>
				PNG export supports transparent backgrounds.
			</Alert>
			<Alert tone="success" showIcon fluid>
				Your snippet was saved.
			</Alert>
			<Alert tone="warning" showIcon fluid>
				Your snippet has unsaved changes.
			</Alert>
			<Alert tone="danger" showIcon fluid>
				Export failed. Check your connection and retry.
			</Alert>
		</Stack>
	);
}

The tones are neutral, info, success, warning, and danger. The default is neutral.

Icons

alert/icons.tsx
import { Alert, icons, Stack } from "@codeui/solid";

export default function Demo() {
	return (
		<Stack gap="3">
			<Alert tone="info" showIcon>
				PNG export is available.
			</Alert>
			<Alert tone="info" showIcon={false}>
				PNG export is available.
			</Alert>
			<Alert showIcon icon={<icons.CheckIcon />}>
				Your snippet was saved.
			</Alert>
		</Stack>
	);
}

showIcon defaults to false. With showIcon, a status tone gets its tone icon. Neutral needs a custom icon.

Width

alert/fluid.tsx
import { Alert, Stack } from "@codeui/solid";

export default function Demo() {
	return (
		<Stack gap="3">
			<div>
				<Alert fluid={false}>Unsaved snippet</Alert>
			</div>
			<Alert fluid>Unsaved snippet</Alert>
		</Stack>
	);
}

fluid defaults to false for inline width. fluid={true} fills the available width.

Ready API

Alert

Alert renders Root, an optional Icon and Title, Description, and an optional Action. description takes precedence over children. title, description, and action accept JSX.

Prop

Type

Native attributes pass through to the root.

Styled parts API

Import the parts from @codeui/solid/alert/parts. The root wraps Kobalte alert.

Action

Wrapper for your buttons or links. It does not add interaction.

Prop

Type

Description

Message wrapper. It is not a Kobalte Description primitive.

Prop

Type

Icon

Decorative icon wrapper with aria-hidden="true".

Prop

Type

Root

Styled Kobalte Alert root with tone and fluid.

Prop

Type

Title

Title wrapper. It does not render a heading element.

Prop

Type

Styles export

alertStyles

alertStyles is typed as AlertStyles. Call root() for the class and set data-tone and, for a fluid alert, data-fluid.

Accessibility

Keyboard

KeyAction
TabMove to a focusable action you provide.
Shift+TabMove to the previous focusable control.
Enter or SpaceActivate a supplied button.

The alert itself has no keyboard commands.

ARIA

Kobalte Root renders role="alert", an assertive live region. The role applies to every tone, including neutral. Color does not change announcement urgency. Icon is decorative. Title and Description are plain wrappers, without automatic heading or ARIA label relationships.

Focus

Mounting or removing the component does not move focus. There is no open or close focus cycle. If an action removes the alert while focused, your application must move focus to the next useful control.

SSR notes

The component renders inline on the server. It has no portal or client-only effect. Use the same initial props on the server and client. No request-shared state is created by the kit wrapper.

Theming hooks

The component reads these theme variables.

  • --cui-action-brand-soft-base
  • --cui-action-brand-soft-text
  • --cui-action-caution-base
  • --cui-action-caution-text
  • --cui-action-danger-base
  • --cui-action-danger-text
  • --cui-action-neutral-base
  • --cui-action-neutral-text
  • --cui-action-success-base
  • --cui-action-success-text
  • --cui-font-family-sans
  • --cui-font-line-height-normal
  • --cui-font-size-caption
  • --cui-font-size-md
  • --cui-font-weight-semibold
  • --cui-radius-sm
  • --cui-space-2
  • --cui-space-3

Defaults come from the kit theme. See Color, Typography, Space and shape, and Motion.

Composition examples

alert/actions.tsx
import { Alert, Button } from "@codeui/solid";
import { createSignal } from "solid-js";

export default function Demo() {
	const [saved, setSaved] = createSignal(false);
	return (
		<Alert
			tone="info"
			showIcon
			fluid
			title={
				<span>
					Export <code>snippet.png</code>
				</span>
			}
			description={
				<span>
					{saved() ? (
						"Export settings saved."
					) : (
						<>
							Keep the background <strong>transparent</strong>.
						</>
					)}
				</span>
			}
			action={
				<Button variant="secondary" onClick={() => setSaved(true)}>
					Save settings
				</Button>
			}
		/>
	);
}

Title and description contain JSX. The action button saves the example settings and updates the description. Alert has no built-in close button, timeout, or open state.

Use Toast for a temporary notification outside the document flow. Use Text for a static hint that does not need an alert announcement.

On this page