Skip to content

HyAlert

Usage examples on this page are written for Lit / plain HTML (<hy-alert>). The same component ships as HyAlert in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

An alert component for displaying important messages to users with semantic variants.

Key Features:

  • Multiple semantic variants (info, success, warning, danger)
  • Optional dismiss button for closeable alerts
  • Automatic variant-appropriate icons
  • Custom icon support
  • Action slot for buttons/links
  • Accessible with proper ARIA live region attributes

Accessibility Features:

  • Semantic ARIA roles (role="alert" for danger, role="status" for others)
  • Visually-hidden variant labels announced by screen readers
  • aria-atomic ensures entire alert is announced on updates
  • Keyboard accessible dismiss button
  • High contrast mode support
  • Reduced motion support

Examples

Basic Usage

html
<hy-alert variant="info" open> This is an informational message. </hy-alert>

Dismissible Alert

html
<hy-alert variant="success" open dismissible> Your changes have been saved successfully. </hy-alert>

With Custom Icon

html
<hy-alert variant="warning" open icon="warning">
  Please review your input before continuing.
</hy-alert>

With Actions

html
<hy-alert variant="danger" open>
  <span slot="title">Error</span>
  Something went wrong. Please try again.
  <hy-button slot="action" size="small">Retry</hy-button>
</hy-alert>

Emphasis variants

html
<hy-alert variant="success" emphasis="solid" open>High-emphasis success</hy-alert>
<hy-alert variant="success" emphasis="soft" open>Default soft success</hy-alert>
<hy-alert variant="success" emphasis="outlined" open>Outlined success</hy-alert>

API

Properties

PropertyAttributeTypeDefaultDescription
variantvariant'info' | 'success' | 'warning' | 'danger''info'Visual style variant determining the alert's color scheme and semantic meaning.
emphasisemphasis'solid' | 'soft' | 'outlined''soft'Visual chrome weight on top of the role.
dismissibledismissiblebooleanfalseWhether the alert can be dismissed by the user. When true, a close button is displayed.
openopenbooleanfalseWhether the alert is currently visible. Set to true to show the alert, false to hide it.
iconiconstring | undefinedIcon name to display. If not provided, a variant-appropriate default icon is used. Set to empty string to hide the icon entirely.
labellabelstring | undefinedAccessible label for the alert. Used for ARIA attributes.

Events

EventDetailDescription
showFired when the alert becomes visible (does NOT bubble). Detail: { source: HyVisibilitySource }
hideFired when the alert is hidden (does NOT bubble). Detail: { source: HyVisibilitySource }
request-closeFired before hiding; cancelable to prevent close (does NOT bubble). Detail: { source: HyVisibilitySource }

Slots

SlotDescription
defaultThe main alert message content
titleOptional title displayed above the message
iconCustom icon to replace the default variant icon
actionOptional action buttons or links

CSS Parts

PartDescription
baseThe alert's base wrapper element
iconThe icon container
contentThe content wrapper (title + message)
titleThe title element
messageThe message element
actionThe action slot container
close-buttonThe dismiss button (when dismissible)

CSS Custom Properties

PropertyDescription
--hy-alert-radiusBorder radius of the alert
--hy-alert-paddingPadding inside the alert
--hy-alert-gapGap between alert elements
--hy-alert-gap-contentGap within content area
--hy-alert-gap-titleGap around the title
--hy-alert-action-background-info-tint-lightSlotted action's info hover / pressed tint (the button's background-info-tint-light hook, re-pointed inside the alert)
--hy-alert-action-background-info-tint-strongSlotted action's info pressed tint (the button's background-info-tint-strong hook, re-pointed inside the alert)
--hy-alert-action-background-success-tint-lightSlotted action's success hover / pressed tint (the button's background-success-tint-light hook, re-pointed inside the alert)
--hy-alert-action-background-success-tint-strongSlotted action's success pressed tint (the button's background-success-tint-strong hook, re-pointed inside the alert)
--hy-alert-action-background-warning-tint-lightSlotted action's warning hover / pressed tint (the button's background-warning-tint-light hook, re-pointed inside the alert)
--hy-alert-action-background-warning-tint-strongSlotted action's warning pressed tint (the button's background-warning-tint-strong hook, re-pointed inside the alert)
--hy-alert-action-background-danger-tint-lightSlotted action's danger hover / pressed tint (the button's background-danger-tint-light hook, re-pointed inside the alert)
--hy-alert-action-background-danger-tint-strongSlotted action's danger pressed tint (the button's background-danger-tint-strong hook, re-pointed inside the alert)
--hy-alert-strokeBorder width of the alert
--hy-alert-font-familyFont family override for alert message
--hy-alert-icon-sizeSize of the alert icon

Methods

show()

Shows the alert programmatically.

hide()

Hides the alert programmatically. Emits a cancelable request-close event first.

Parameters:

  • source - How the close was triggered (for event detail)

Built with Lit. Documented with VitePress.