@dojo-ng/alert
v0.1.2
Published
Dojo NG alert (inline status banner) web component
Readme
@dojo-ng/alert
<dj-alert> — An inline status banner.
Part of Dojo NG, a framework-agnostic web component library built on Lit. BSD-3-Clause.
It sits in the page flow, next to the content it concerns. For a short message that floats and goes away, use dj-snackbar. For a full-page outcome, use dj-result.
Install
npm install @dojo-ng/alertUsage
Import the package to register the custom element, then use the tag.
Each variant has a default glyph and live-region role.
<dj-alert variant="info">Heads up — a new version is available.</dj-alert>
<dj-alert variant="success">Your changes were saved.</dj-alert>
<dj-alert variant="warning">Your trial ends in 3 days.</dj-alert>
<dj-alert variant="danger">Payment failed. Update your card.</dj-alert>Showing and closing
- An alert in markup shows by default (
openis true). close()hides it and emitsdj-close. A closed alert takes no space.- Add
closablefor a close button. Its label is the localizedclosemessage.
Variants
infoandsuccessannounce politely (role="status").warninganddangerannounce immediately (role="alert").- Each variant has a default icon. Replace it with the
iconslot. - Colors come from the theme's semantic scales. To change one alert, set
--dj-alert-background,--dj-alert-color, and--dj-alert-accent-coloron it.
Properties
↻ marks an attribute reflected to the DOM; a dash means the property is set in JavaScript only.
| Property | Attribute | Type | Default |
|---|---|---|---|
| variant | variant ↻ | AlertVariant | "info" |
| closable | closable | boolean | false |
| open | open ↻ | boolean | true |
Slots
- default slot: The message.
icon: Replaces the default variant glyph.
CSS parts
baseiconmessageclose
Events
dj-close: After the alert closes.
Methods
close(): Close the alert: hides it and emitsdj-closeonce. No-op if already closed.
CSS custom properties
--dj-alert-background: Banner background; defaults to the variant's--dj-color-*-100. Defaultper-variant tint.--dj-alert-color: Text color; defaults to the variant's--dj-color-*-700. Defaultper-variant ink.--dj-alert-accent-color: Icon + leading-border color; defaults to the variant's--dj-color-*-600. Defaultper-variant accent.--dj-alert-radius: Corner radius. Defaultvar(--dj-input-border-radius-medium).
Examples
Closable, with a custom icon
closable adds a dismiss button; the icon slot replaces the glyph. Listen for dj-close.
<dj-alert variant="success" closable>
<svg slot="icon" viewBox="0 0 24 24" width="20" height="20"><path d="M20 6L9 17l-5-5" fill="none" stroke="currentColor" stroke-width="2"/></svg>
Deploy finished.
</dj-alert>Theming
Styled with Dojo NG --dj-* design tokens and exposes ::part() hooks for targeted overrides.
Accessibility and i18n
Follows the project's WCAG 2.2 AA and localization conventions.
More
Live, interactive examples are at play.dojo-ng.com. For the full API reference, theming, accessibility, and localization guides, see the Dojo NG documentation.
