Alert

An inline status message.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrAlert } from 'ngwr/alert';

@Component({ imports: [WrAlert] })
export class MyComponent {}

Basic usage

Heads up

Your trial ends in 3 days.

<wr-alert title="Heads up" message="Your trial ends in 3 days." />

Types

info

Sample message

success

Sample message

warning

Sample message

danger

Sample message

neutral

Sample message

offline

Sample message

<wr-alert title="Info" type="info" />
<wr-alert title="Success" type="success" />
<wr-alert title="Warning" type="warning" />
<wr-alert title="Danger" type="danger" />
<wr-alert title="Neutral" type="neutral" />
<wr-alert title="Offline" type="offline" />

With title

Pair a title with a secondary message.

Update available

Version 2.0 is ready to install.

<wr-alert title="Update available" message="Version 2.0 is ready to install." type="info" />

Without title

Without a title, the message is the only line.

Your changes are live.

Connection lost.

<wr-alert message="Your changes are live." type="success" />
<wr-alert message="Connection lost." type="offline" />

Custom icon

iconName replaces the icon of the type.

What's new

Smarter search just landed.

<wr-alert iconName="sparkles" title="What's new" message="Smarter search just landed." />

Closable

closable adds a close button; (closed) fires when it hides the alert.

Saved

Your changes are live.

<wr-alert title="Saved" type="success" closable (closed)="onClose()" />

Without icon

[icon]="false" hides the icon.

Plain

No leading icon.

<wr-alert title="Plain" message="No leading icon." [icon]="false" />

API

NameDescriptionTypeDefault
closeLabelAccessible name. Falls back to alert.close, then 'Close alert'.string | nullnull
titleOptional headline shown at the top of the alert.string | nullnull
typeVisual variant.WrAlertType'info'
iconNameOverride the default per-type icon with any ngwr icon name.WrIconName | nullnull
messageOptional secondary message rendered below the title.string | nullnull
iconWhen true, renders a leading status icon matching the type. Pass false to hide. Ignored when iconName is set.booleantrue
closableWhen true, renders a close button.booleanfalse
(closed)Emitted when the user dismisses the alert via the close button. If the close button had focus, focus moves on to the next focusable element after the alert (or the one before it, when nothing follows) — unless a (closed) handler has placed it somewhere itself.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/alert's own element.

VariableDefaultDeclared on
--wr-alert-bgvar(--wr-color-info-soft).wr-alert +3 variant overrides
--wr-alert-body-gapvar(--wr-space-xs).wr-alert
--wr-alert-bordertransparent.wr-alert
--wr-alert-closevar(--wr-color-info).wr-alert +3 variant overrides
--wr-alert-close-paddingvar(--wr-space-xs).wr-alert
--wr-alert-close-radiusvar(--wr-border-radius-sm).wr-alert
--wr-alert-font-familyvar(--wr-font-family-base).wr-alert
--wr-alert-gapvar(--wr-space-md).wr-alert
--wr-alert-icon-margin-topvar(--wr-space-xs).wr-alert
--wr-alert-messagevar(--wr-color-on-surface).wr-alert +2 variant overrides
--wr-alert-message-font-sizevar(--wr-text-sm).wr-alert
--wr-alert-message-line-heightvar(--wr-text-sm-leading).wr-alert
--wr-alert-padding-xvar(--wr-space-lg).wr-alert
--wr-alert-padding-yvar(--wr-space-md).wr-alert
--wr-alert-radiusvar(--wr-border-radius-base).wr-alert
--wr-alert-titlevar(--wr-color-info-ink).wr-alert +3 variant overrides
--wr-alert-title-font-sizevar(--wr-text-sm).wr-alert
--wr-alert-title-font-weightvar(--wr-font-weight-semibold).wr-alert
--wr-alert-title-line-heightvar(--wr-text-sm-leading).wr-alert

Dependencies

Built onIcon

See also