Morphos
Feedback

Alert

A static inline notification with live region support.

Interactive example

Installation

npm install @morphos/feedback
pnpm add @morphos/feedback
yarn add @morphos/feedback
bun add @morphos/feedback

Import

import { Alert } from '@morphos/feedback'

Usage

@Component()
class MyComponent extends StatelessComponent {
  render() {
    return (
      <Alert variant="info" title="Note">
        Your session will expire in 10 minutes.
      </Alert>
    )
  }
}

Props

PropTypeDefaultDescription
variant'info' | 'warning' | 'error' | 'success''info'Visual and semantic variant
live'polite' | 'assertive''assertive' for error, 'polite' otherwisearia-live value
titlestringBold heading rendered before children
childrenChildrenAlert message body
classstringCSS class on the root element
idstringid on the root element

data-* attributes

AttributeElementWhen present
data-variantRootAlways — set to the variant string

Accessibility

Alert renders as role="alert" with aria-live and aria-atomic="true". Screen readers announce the content automatically when it is added to the DOM.

  • polite — waits for the user to finish their current interaction (info, success, warning)
  • assertive — interrupts immediately (error)

Styling example

.morphos-alert {
  display: flex;
  flex-direction: column;
  gap: var(--morphos-space-1);
  padding: var(--morphos-space-3) var(--morphos-space-4);
  border: 1px solid var(--morphos-color-info);
  border-radius: var(--morphos-radius-md);
  background: var(--morphos-color-info-bg);
  color: var(--morphos-color-text);
}

.morphos-alert > strong {
  font-weight: 600;
}

.morphos-alert[data-variant="success"] {
  border-color: var(--morphos-color-success);
  background: var(--morphos-color-success-bg);
}

.morphos-alert[data-variant="warning"] {
  border-color: var(--morphos-color-warning);
  background: var(--morphos-color-warning-bg);
}

.morphos-alert[data-variant="error"] {
  border-color: var(--morphos-color-danger);
  background: var(--morphos-color-danger-bg);
}

Apply class="morphos-alert" to Alert to use this recipe.

Alert is for static notifications already present in the layout. For dismissible or auto-expiring notifications, use Toast.

On this page