Skip to main content
cngx-src documentation

CngxAlert

ComponentPrimaryOnPushNo encapsulationv0.1.0WCAG AA

projects/ui/feedback/alert/alert.ts

Import#

import { CngxAlert } from '@cngx/ui/feedback'

Description#

Inline alert atom with enter/exit animations, state-driven visibility, auto-dismiss with pause-on-hover/focus, and optional auto-collapse.

Three visibility modes:

  • Static (no [state] or [when]): always visible
  • State-driven ([state]): auto-shows on error/success/loading, auto-hides on idle
  • Boolean-driven ([when]): visible when true, hidden when false

[state] takes precedence over [when].

https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/action-buttons https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/auto-collapse https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/boolean-trigger-when https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/closable https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/severities https://cngxjs.github.io/cngx/examples/#/ui/feedback/alert/state-driven-visibility

Metadata#

Host#

Relationships

Index#

Inputs#

autoDismissDelay#number | undefined
input()

Auto-dismiss delay in ms for success state or timed alerts. Set to undefined to disable auto-dismiss (persistent).

default 5000
closable#boolean
input()

Shows a dismiss button. Preferred over deprecated dismissible.

default false
collapseDelay#number | undefined
input()

Delay in ms before auto-collapsing. Defaults to autoDismissDelay.

collapsible#boolean
input()

Enables auto-collapse after collapseDelay. Visual only - SR reads full content.

default false
dismissible#boolean
input()

Shows a dismiss button.

default false
input()

Alert severity - determines visual style, default icon, and ARIA role.

default 'info'

Bind an async state - auto-shows on error/success/loading, auto-hides on idle.

title#string | undefined
input()

Optional title displayed above the content.

when#boolean | undefined
input()

Boolean visibility trigger. When set, controls alert visibility directly. [state] takes precedence over [when].

Outputs#

dismissed#void
output()

Emitted when the dismiss button is clicked.

HostBindings#

BindingExpression
[class.cngx-alert--info]severity() === "info"
[class.cngx-alert--success]severity() === "success"
[class.cngx-alert--warning]severity() === "warning"
[class.cngx-alert--error]severity() === "error"
[class.cngx-alert--hidden]visibilityPhase() === "hidden"
[class.cngx-alert--entering]visibilityPhase() === "entering"
[class.cngx-alert--visible]visibilityPhase() === "visible"
[class.cngx-alert--exiting]visibilityPhase() === "exiting"
[class.cngx-alert--collapsed]collapsed()
[attr.role]isVisible() ? ariaRole() : null
[attr.aria-atomic]isVisible() ? ariaAtomic() : null
[attr.aria-label]isVisible() ? (title() || null) : null
[attr.aria-expanded]collapsible() ? !collapsed() : null
[attr.aria-busy]isStateBusy() || null
[attr.hidden]!isVisible() || null

HostListeners#

EventHandler
(animationend)animationend()
(pointerenter)pointerenter()
(pointerleave)pointerleave()
(focusin)focusin()
(focusout)focusout()

Default visuals for CngxAlert. The host carries .cngx-alert and renders __icon, __body, __title, __collapsible, __actions, __action, and __dismiss children. Severity tokens use a tinted-surface family (--cngx-alert-{severity}-bg / border / icon) visually distinct from --cngx-color-{success / danger / warning / info} which are solid brand colors unsuitable for alert surfaces - brand-wide overrides target the severity tokens directly.

State modifiers

  • --collapsed - grid-row 1fr -> 0fr collapses the body slot; the host becomes clickable and tints on hover via --cngx-alert-collapsed-hover-bg
  • --hidden - display: none
  • --entering - 200ms enter animation + 300ms icon pulse
  • --exiting - 150ms exit animation

All animations short-circuit under prefers-reduced-motion.

Variants

Severity classes pin three tokens each:

  • --info - info bg / border / icon
  • --success - success bg / border / icon
  • --warning - warning bg / border / icon
  • --error - error bg / border / icon

Slots

  • .cngx-alert__icon - severity glyph; color follows --cngx-alert-icon-color
  • .cngx-alert__default-icon - SVG fallback when no custom icon is projected
  • .cngx-alert__title - bold header
  • .cngx-alert__collapsible - grid-rows body that collapses on --collapsed
  • .cngx-alert__actions - trailing action row, hidden when empty
  • .cngx-alert__action - projected [cngxAlertAction] button tinted by --cngx-alert-icon-color
  • .cngx-alert__dismiss - dismiss control

Dark mode

Three hooks swap every severity triplet plus the collapsed-hover and action-hover overlays (alpha-on-black flips to alpha-on-white):

  • prefers-color-scheme: dark
  • [data-color-scheme="dark"]
  • .dark class

Pair with

  • @cngx/themes/material/feedback-theme - Material 3 surface palette

Index#

Layout

--cngx-alert-gap#<length>
Default value 12px

Gap between the icon, body, and dismiss button.

--cngx-alert-padding#*
Default value 12px 16px

Padding shorthand inside the alert.

--cngx-alert-border-radius#<length>
Default value 8px

Corner radius.

--cngx-alert-icon-size#<length>
Default value 20px

Default icon size when no custom icon is projected.

--cngx-alert-title-gap#<length>
Default value 4px

Gap between the title and the body text.

--cngx-alert-actions-gap#<length>
Default value 8px

Gap above the actions slot.

Surface

--cngx-alert-border-color#<color>
Default value transparent

Border color - neutral by default; severity rules override.

--cngx-alert-bg#<color>
Default value oklch(0.98 0.005 250)

Background - neutral by default; severity rules override.

--cngx-alert-color#*
Default value currentColor

Text color - defaults to currentColor.

--cngx-alert-icon-color#*
Default value currentColor

Icon color override - defaults to currentColor and is pinned by each severity rule.

Variant / Info

--cngx-alert-info-bg#<color>
Default value oklch(0.96 0.025 250)

Background tint of the info severity.

--cngx-alert-info-border#<color>
Default value oklch(0.85 0.07 250)

Border color of the info severity.

--cngx-alert-info-icon#<color>
Default value oklch(0.62 0.2 250)

Icon color of the info severity.

Variant / Success

--cngx-alert-success-bg#<color>
Default value oklch(0.96 0.04 145)

Background tint of the success severity.

--cngx-alert-success-border#<color>
Default value oklch(0.85 0.1 145)

Border color of the success severity.

--cngx-alert-success-icon#<color>
Default value oklch(0.65 0.15 145)

Icon color of the success severity.

Variant / Warning

--cngx-alert-warning-bg#<color>
Default value oklch(0.97 0.04 80)

Background tint of the warning severity.

--cngx-alert-warning-border#<color>
Default value oklch(0.86 0.1 80)

Border color of the warning severity.

--cngx-alert-warning-icon#<color>
Default value oklch(0.72 0.18 70)

Icon color of the warning severity.

Variant / Error

--cngx-alert-error-bg#<color>
Default value oklch(0.96 0.025 25)

Background tint of the error severity.

--cngx-alert-error-border#<color>
Default value oklch(0.85 0.08 25)

Border color of the error severity.

--cngx-alert-error-icon#<color>
Default value oklch(0.62 0.22 25)

Icon color of the error severity.

Typography

--cngx-alert-title-weight#<number>
Default value 600

Font-weight of the title slot.

Motion

--cngx-alert-collapse-duration#<time>
Default value 200ms

Duration of the collapsed-state grid-row transition.

--cngx-alert-enter-duration#<time>
Default value 200ms

Duration of the enter animation.

--cngx-alert-exit-duration#<time>
Default value 150ms

Duration of the exit animation.

--cngx-alert-icon-pulse-duration#<time>
Default value 300ms

Duration of the icon-pulse animation that fires on enter.

--cngx-alert-enter-offset#<length>
Default value 8px

Vertical offset the alert translates from while entering.

--cngx-alert-exit-offset#<length>
Default value 8px

Vertical offset the alert translates to while exiting.

State / Collapsed

--cngx-alert-collapsed-hover-bg#<color>
Default value oklch(0 0 0 / 0.02)

Background tint applied on hover of a collapsed alert.

State / Action

--cngx-alert-action-bg#<color>
Default value transparent

Background of the projected action button. Defaults to transparent so the severity tint shows through; consumers can pin a filled accent.

--cngx-alert-action-radius#<length>
Default value 4px

Corner radius of the projected action button.

--cngx-alert-action-padding#*
Default value 4px 10px

Padding shorthand of the projected action button.

--cngx-alert-action-font-size#*
Default value 0.875rem

Font-size of the projected action button label.

--cngx-alert-action-font-weight#<number>
Default value 600

Font-weight of the projected action button label.

--cngx-alert-action-hover-bg#<color>
Default value oklch(0 0 0 / 0.04)

Background tint applied on hover of the projected action button.