Skip to content

HyToast

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

A toast notification component for displaying transient messages with auto-dismiss.

Key Features:

  • Multiple semantic variants (info, success, warning, danger)
  • Auto-dismiss with configurable duration
  • Pause timer on hover and window focus loss
  • Optional dismiss button
  • 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 toast is announced on updates
  • Keyboard accessible dismiss button
  • High contrast mode support
  • Reduced motion support

Examples

Basic Usage

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

With Title

html
<hy-toast variant="info" open label="New Update"> A new version is available. </hy-toast>

Custom Duration

html
<hy-toast variant="warning" open duration="10000"> Session expiring in 5 minutes. </hy-toast>

Persistent Toast (no auto-dismiss)

html
<hy-toast variant="danger" open duration="0" dismissible>
  Connection lost. Please check your network.
</hy-toast>

With Action

html
<hy-toast variant="info" open>
  File deleted.
  <hy-button slot="action" size="small">Undo</hy-button>
</hy-toast>

Viewport Positioning (top-right corner)

html
<hy-toast variant="success" open anchor-vertical="top" anchor-horizontal="right">
  Settings saved successfully.
</hy-toast>

Viewport Positioning (bottom-center)

html
<hy-toast variant="info" open anchor-vertical="bottom" anchor-horizontal="center">
  New message received.
</hy-toast>

API

Properties

PropertyAttributeTypeDefaultDescription
variantvariant'info' | 'success' | 'warning' | 'danger''info'Visual style variant determining the toast's color scheme and semantic meaning.
emphasisemphasis'solid' | 'soft' | 'outlined''soft'Visual chrome weight on top of the role.
dismissibledismissiblebooleantrueWhether the toast can be dismissed by the user. When true, a close button is displayed.
openopenbooleanfalseWhether the toast is currently visible. Set to true to show the toast, 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 | undefinedTitle/label for the toast. Displayed as a heading above the message.
durationdurationnumber5000Auto-dismiss duration in milliseconds. Set to 0 or Infinity to disable auto-dismiss.
pauseOnHoverpause-on-hoverbooleantrueWhether to pause the auto-dismiss timer when hovering over the toast.
pauseOnFocusLosspause-on-focus-lossbooleantrueWhether to pause the auto-dismiss timer when the window loses focus.
anchorVerticalanchor-vertical'top' | 'bottom'undefined (no viewport positioning)Vertical anchor position for viewport positioning. When set, the toast uses fixed positioning relative to the viewport. Combine with anchorHorizontal to position in any of 6 screen locations.
anchorHorizontalanchor-horizontal'left' | 'center' | 'right'undefined (no viewport positioning)Horizontal anchor position for viewport positioning. When set, the toast uses fixed positioning relative to the viewport. Combine with anchorVertical to position in any of 6 screen locations.

Events

EventDetailDescription
showFired when the toast becomes visible. Detail: { source: HyVisibilitySource }
hideFired when the toast is hidden. Detail: { source: HyVisibilitySource }
request-closeFired before hiding; cancelable to prevent close. Detail: { source: HyVisibilitySource }

Slots

SlotDescription
defaultThe main toast message content
titleOptional title displayed above the message (alternative to label prop)
iconCustom icon to replace the default variant icon
actionOptional action buttons or links

CSS Parts

PartDescription
baseThe toast'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-toast-background-info-tint-subtleInfo variant background
--hy-toast-background-danger-tint-subtleDanger variant background
--hy-toast-background-success-tint-subtleSuccess variant background
--hy-toast-background-warning-tint-subtleWarning variant background
--hy-toast-border-info-restInfo variant border color
--hy-toast-border-danger-restDanger variant border color
--hy-toast-border-success-restSuccess variant border color
--hy-toast-border-warning-restWarning variant border color
--hy-toast-foreground-info-restInfo variant text/icon color
--hy-toast-foreground-danger-restDanger variant text/icon color
--hy-toast-foreground-default-restMessage text color
--hy-toast-foreground-success-restSuccess variant text/icon color
--hy-toast-foreground-warning-restWarning variant text/icon color
--hy-toast-gapGap between main toast sections
--hy-toast-gap-contentGap between content elements (title/message)
--hy-toast-gap-actionGap between action items
--hy-toast-action-background-info-tint-lightSlotted action's info hover / pressed tint (the button's background-info-tint-light hook, re-pointed inside the toast)
--hy-toast-action-background-info-tint-strongSlotted action's info pressed tint (the button's background-info-tint-strong hook, re-pointed inside the toast)
--hy-toast-action-background-success-tint-lightSlotted action's success hover / pressed tint (the button's background-success-tint-light hook, re-pointed inside the toast)
--hy-toast-action-background-success-tint-strongSlotted action's success pressed tint (the button's background-success-tint-strong hook, re-pointed inside the toast)
--hy-toast-action-background-warning-tint-lightSlotted action's warning hover / pressed tint (the button's background-warning-tint-light hook, re-pointed inside the toast)
--hy-toast-action-background-warning-tint-strongSlotted action's warning pressed tint (the button's background-warning-tint-strong hook, re-pointed inside the toast)
--hy-toast-action-background-danger-tint-lightSlotted action's danger hover / pressed tint (the button's background-danger-tint-light hook, re-pointed inside the toast)
--hy-toast-action-background-danger-tint-strongSlotted action's danger pressed tint (the button's background-danger-tint-strong hook, re-pointed inside the toast)
--hy-toast-paddingPadding inside the toast
--hy-toast-radiusBorder radius of the toast
--hy-toast-close-radiusClose button border radius
--hy-toast-strokeBorder width
--hy-toast-close-hover-backgroundClose button hover background
--hy-toast-shadowBox shadow for the toast
--hy-toast-icon-sizeSize of the toast icon
--hy-toast-font-familyFont family override for toast message
--hy-toast-min-widthMinimum width of the toast
--hy-toast-max-widthMaximum width of the toast
--hy-toast-background-info-restInfo variant solid-emphasis fill
--hy-toast-background-danger-restDanger variant solid-emphasis fill
--hy-toast-background-success-restSuccess variant solid-emphasis fill
--hy-toast-background-warning-restWarning variant solid-emphasis fill
--hy-toast-foreground-on-info-restText/icon color on the info solid fill
--hy-toast-foreground-on-danger-restText/icon color on the danger solid fill
--hy-toast-foreground-on-success-restText/icon color on the success solid fill
--hy-toast-foreground-on-warning-restText/icon color on the warning solid fill
--hy-toast-hover-durationClose-button hover transition duration
--hy-toast-hover-easingClose-button hover transition easing

Methods

show()

Shows the toast programmatically.

hide()

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

Parameters:

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

Built with Lit. Documented with VitePress.