@cngx/ui
v0.3.0
Published
Organism layer (layout, overlay, feedback, stepper, tabs) for the CNGX Angular component library. Material opt-in (mat-stepper, mat-tabs, material).
Maintainers
Readme
@cngx/ui
Finished, styled Angular components that compose headless directives from
@cngx/common with opinionated rendering. These are the "organism" layer -
ready to drop into an application without additional template work.
Components
CngxMatPaginator
[cngxMatPaginator] bridge that adopts an existing <mat-paginator> in place -
the signal-native CngxPaginate brain (headless, @cngx/common) takes over its
state with no DOM rewrite.
<mat-paginator
cngxMatPaginator
#pg="cngxMatPaginator"
[total]="items().length"
[pageSizeOptions]="[5, 10, 25]"
></mat-paginator>
<ul>
@for (item of items().slice(pg.paginate.range()[0], pg.paginate.range()[1]); track item.id) {
<li>{{ item.label }}</li>
}
</ul>Inputs: total, cngxPageIndex, cngxPageSize, state (forwarded to the composed brain), pageSizeOptions (number[])
CngxSpeakButton
Ready-made speaker button that connects to CngxSpeak (headless,
@cngx/common) via [speakRef].
<span [cngxSpeak]="text" #tts="cngxSpeak">{{ text }}</span>
<cngx-speak-button [speakRef]="tts" />Inputs: speakRef (required, CngxSpeak instance)
CSS Custom Properties:
| Variable | Default | Description |
|-|-|-|
| --cngx-speak-btn-size | 28px | Button width and height |
| --cngx-speak-btn-icon-size | 14px | SVG icon size |
| --cngx-speak-btn-radius | 4px | Border radius |
| --cngx-speak-btn-border-width | 1px | Border width |
| --cngx-speak-btn-bg | --cngx-surface / #fff | Background color |
| --cngx-speak-btn-color | --cngx-text-secondary / #666 | Icon color |
| --cngx-speak-btn-active-color | --cngx-accent / #f5a623 | Icon color while speaking or on hover |
| --cngx-speak-btn-transition | 0.15s | Color transition duration |
Material theme: @use '@cngx/themes/material/speak-button-theme'
CngxSkeletonContainer
Skeleton loading container with built-in placeholder repetition. Wraps the
headless CngxSkeleton atom with template projection so the consumer doesn't
need @if/@for boilerplate.
<cngx-skeleton [loading]="loading()" [count]="3">
<ng-template cngxSkeletonPlaceholder let-i let-last="last">
<div class="skeleton-card" [style.width]="last ? '60%' : '100%'"></div>
</ng-template>
<app-real-content />
</cngx-skeleton>Inputs: loading (boolean), shimmer (boolean, respects prefers-reduced-motion), count (number)
Template: project <ng-template cngxSkeletonPlaceholder> for loading state; default <ng-content> for loaded state. Context: $implicit (index), index, count, first, last.
CSS Classes: cngx-skeleton, cngx-skeleton--loading, cngx-skeleton--shimmer
Selector: cngx-skeleton -- exportAs "cngxSkeletonContainer"
CngxStatCard
Card-framed KPI tile. One <cngx-stat-card [state]="s"> renders the whole
dashboard metric: card surface, the four coordinated stat slots, an inline
visualisation and a footer, with the async view switch derived from [state].
The stat slots are the existing cngxStat* atoms from @cngx/common/data, not
copies. They resolve CNGX_STAT at their declaration site, so the card hosts
the shared CngxStatCoordinator brain and re-points the token at it - the same
shape CngxIncrementalList uses for CNGX_PAGINATOR_HOST. The tile therefore
carries one accessible name in reading order instead of four fragments.
<cngx-stat-card [state]="revenue" live="polite">
<span cngxStatLabel>Revenue</span>
<cngx-metric cngxStatValue [value]="1.2" unit="M EUR" />
<cngx-delta cngxStatDelta [value]="5.3" />
<span cngxStatCaption>vs. last quarter</span>
<cngx-sparkline cngxStatCardViz [data]="trend()" />
</cngx-stat-card>Inputs: state (CngxAsyncState<unknown>), loadingTreatment
('auto' | 'spinner' | 'skeleton'), live ('off' | 'polite' | 'assertive'),
busyLabel, errorText, staleText
Slots: cngxStatLabel / cngxStatValue / cngxStatDelta /
cngxStatCaption (re-exported), plus cngxStatCardViz and cngxStatCardFooter
With loadingTreatment="auto" the tile picks spinner vs skeleton from the
latency it observed. The threshold is never hardcoded - it comes from
CNGX_LOADING_CONFIG, so one provideLoadingConfig(...) retunes every tile.
Config: provideStatCardConfig / provideStatCardConfigAt /
injectStatCardConfig, features withStatCardAriaLabels and
withStatCardLoadingTreatment
Selector: cngx-stat-card -- entry @cngx/ui/stat-card
CngxChartPanel
Dashboard housing for a chart: title, subtitle, header actions, legend
placement and footer. role="group" plus an aria-labelledby pointing at the
projected title makes the region announce as one named unit rather than
dropping the user into an unlabelled SVG.
The panel frames a projected cngx-chart and never duplicates its machine. The
chart keeps owning its data async envelope, its view switch and its SR data
table; panel-level [state] drives header chrome only. aria-busy sits on the
header, not on the group - on the region it would hold back the chart's own live
announcements and claim a stable chart is updating.
<cngx-chart-panel [state]="rangeSwitch" legendPosition="bottom">
<h3 cngxChartPanelTitle>Revenue by quarter</h3>
<span cngxChartPanelSubtitle>EUR, net</span>
<button cngxChartPanelActions type="button">Change range</button>
<cngx-chart [data]="series" [state]="chartState">
<svg:g cngxLine [data]="series"></svg:g>
</cngx-chart>
<cngx-chart-legend [items]="legend" />
</cngx-chart-panel>Inputs: state (CngxAsyncState<unknown>), legendPosition
('top' | 'bottom' | 'none')
Slots: cngxChartPanelTitle, cngxChartPanelSubtitle,
cngxChartPanelActions, cngxChartPanelFooter
The legend slot matches the bare cngx-chart-legend tag; a legend wrapped in an
element of your own lands in the body instead.
Config: provideChartPanelConfig / provideChartPanelConfigAt /
injectChartPanelConfig, features withChartPanelAriaLabels and
withChartPanelLegendPosition
Selector: cngx-chart-panel -- entry @cngx/ui/chart-panel
CngxActionButton
Action button organism with built-in async status communication, on the cngx
button core. button[cngxActionButton] sits on the native <button>: it
co-hosts CngxAsyncClick as a host directive, takes the CngxButton axes
(variant through the selector, tone, size) and disabled /
disabledReason, and adds status labels or templates, optional toast
integration and a state property for downstream feedback consumers. The
labels sit stacked in one cell, so the button keeps the width of its widest
label in every state.
<!-- Minimal -->
<button cngxActionButton tone="primary" [action]="save">Save</button>
<!-- With template slots -->
<button cngxActionButton [action]="save">
Save
<ng-template cngxPending>Saving...</ng-template>
<ng-template cngxSucceeded>Saved!</ng-template>
<ng-template cngxFailed let-err>{{ err }} - retry?</ng-template>
</button>
<!-- With toast feedback -->
<button cngxActionButton [action]="save" toastSuccess="Saved" toastError="Save failed">
Save
</button>
<!-- Downstream state binding -->
<button cngxActionButton [action]="save" #btn="cngxActionButton">Save</button>
<cngx-alert [state]="btn.state" severity="error" title="Details" />Inputs:
| Input | Type | Default | Description |
|-|-|-|-|
| action | AsyncAction | required | Async action to execute on click (the host directive's cngxAsyncClick) |
| feedbackDuration | number | 2000 | Duration in ms to show feedback state |
| showDelay | number | CNGX_LOADING_CONFIG.showDelay (120 ms) | Delay before the busy visual shows |
| minDwell | number | CNGX_LOADING_CONFIG.minDwell (400 ms) | Minimum time the busy visual stays once shown |
| cngxActionButton | CngxButtonVariant | solid | Emphasis, bound through the selector; falls through group and config |
| tone | CngxButtonTone | neutral | Intent |
| size | CngxButtonSize | md | Size; md is the form-control row |
| disabled | boolean | false | Rendered as aria-disabled; the button stays focusable, clicks are swallowed |
| disabledReason | string | -- | Referenced through aria-describedby while disabled |
| cngxDescribedBy | string \| null | null | Extra ids for aria-describedby |
| type | 'button' \| 'submit' \| 'reset' | 'button' | Native type |
| pendingLabel | string | -- | Text while pending (when no cngxPending template); shown after the show delay and held for the dwell past the run, so a fast run never flashes it; without one the idle label stays under the spinner |
| succeededLabel | string | -- | Text after success (when no cngxSucceeded template) |
| failedLabel | string | -- | Text after failure (when no cngxFailed template) |
| succeededAnnouncement | string | -- | SR announcement on success (falls back to the rendered result cell, then succeededLabel) |
| failedAnnouncement | string | -- | SR announcement on failure (falls back to the rendered result cell, then failedLabel) |
| announce | 'auto' \| 'always' \| 'never' | 'auto' | Speaks the outcome unless a shown toast already covers it; 'always' also next to a toast, 'never' never |
| externalState | CngxAsyncState<unknown> | -- | External state override for visual status |
| toastSuccess | string | -- | Toast message on success (requires CngxToaster) |
| toastError | string | -- | Toast message on error (requires CngxToaster) |
| toastErrorDetail | boolean | false | Append error message to error toast |
| toastSuccessDuration | number | withToasts({ defaultDuration }), else 5000 | Success toast duration in ms |
| toastErrorDuration | number \| 'persistent' | 'persistent' | Error toast duration |
State producer: readonly state: CngxAsyncState<unknown> -- the effective
lifecycle state (internal or external). Bind to any [state] consumer.
Outputs: (settled) from CngxAsyncClick, once per own run; (outcome)
from CngxActionStatusBrain, once per own settle and once per [externalState]
success / error edge.
Toast integration: The co-hosted CngxActionToast (also exported from
@cngx/ui/action-button for ejected hosts) owns the toast inputs. When
toastSuccess or toastError is set and CngxToaster is provided (via
provideFeedback(withToasts()) or provideToasts()), it shows one toast per
own settle and per [externalState] edge. If CngxToaster is not provided,
toast inputs are silently ignored. Do not combine with [cngxToastOn] on the same
element -- a dev-mode warning is emitted if both are active.
Template directives: cngxPending, cngxSucceeded, cngxFailed (project <ng-template> for each state)
CSS Classes: cngx-button, cngx-action-button; data-variant / data-tone / data-size / data-status on the host
Selector: button[cngxActionButton] -- exportAs "cngxActionButton"
CngxSidenav
Declarative sidebar organism with dual-sidebar support, responsive mode
switching, a collapsible rail (composed CngxSidebar), resize handle, and keyboard shortcut toggle.
<cngx-sidenav-layout>
<cngx-sidenav position="start" [(opened)]="navOpen" mode="side"
[resizable]="true" shortcut="mod+b" width="240px">
<cngx-nav-header>Workspace</cngx-nav-header>
<a cngxNavLink [active]="true">Dashboard</a>
<a cngxNavLink>Settings</a>
<cngx-nav-footer>v1.0</cngx-nav-footer>
</cngx-sidenav>
<cngx-sidenav-content>
<router-outlet />
</cngx-sidenav-content>
</cngx-sidenav-layout>Modes: 'auto' (default; follows the layout width class), 'over' (overlay + backdrop), 'side' (docked; [(collapsed)] rests it as a rail that peeks on hover, or hides it with collapsedAs="hidden")
CngxSidenav inputs:
| Input | Type | Default | Description |
|-|-|-|-|
| ariaLabel | string | - | Accessible label for the complementary landmark |
| position | 'start' \| 'end' | 'start' | Logical position (flips in RTL) |
| mode | SidenavMode | 'auto' | Interaction mode |
| width | string (model) | '280px' | Panel width, two-way [(width)] for resize |
| miniWidth | string | derived | Width of the collapsed rail; unbound, derived from the nav row tokens |
| collapsed | boolean (model) | false | Rest a docked rail collapsed, two-way [(collapsed)] |
| collapsedAs | 'rail' \| 'hidden' | 'rail' | How a collapsed rail rests |
| expandOnHover | boolean | true | Peek a collapsed rail on hover |
| modality | 'page' \| 'contained' \| 'none' | 'page' | How far an open overlay takes over the page |
| tooltip | boolean | config, else true | Label tooltip on the collapsed rail; unbound, withNavRailTooltip applies |
| resizable | boolean | false | Show drag handle for user resize |
| minWidth | string | '120px' | Min width constraint during resize |
| maxWidth | string | '600px' | Max width constraint during resize |
| shortcut | string | - | Keyboard shortcut, e.g. 'mod+b' (mod = Cmd on Mac, Ctrl elsewhere) |
CngxSidenav signals: opened (model), expanded (full nav shown), widthClass, effectiveMode, resizing, isOverlay
Methods: open(), close(), toggle()
Slots: CngxNavHeader, CngxNavFooter from @cngx/common/interactive (projected above and below the body; skinned by cngx-nav.css)
Layout: CngxSidenavLayout (container, width class, backdrop), CngxSidenavContent (main area)
CSS Custom Properties:
| Variable | Default | Description |
|-|-|-|
| --cngx-sidenav-width | 280px | Panel width |
| --cngx-sidenav-mini-width | derived from the row tokens | Collapsed rail width |
| --cngx-sidenav-bg | --cngx-color-surface (Material bridge: surface-container) | Background |
| --cngx-sidenav-color | --cngx-color-text (Material bridge: on-surface) | Text color |
| --cngx-sidenav-border-color | --cngx-color-border (Material bridge: outline-variant) | Border color |
| --cngx-sidenav-padding | density-dependent | Header/footer block padding |
| --cngx-sidenav-z-index | 2 | Stacking of the rail over the content |
| --cngx-sidenav-row-gap | half of --cngx-space-xs (Material 3 bridge: 0) | Gap between body rows |
| --cngx-nav-header-bg | M3 surface-container-low | Header background (nav atom token) |
| --cngx-nav-footer-bg | M3 surface-container-low | Footer background (nav atom token) |
| --cngx-sidenav-backdrop-bg | M3 scrim | Backdrop color |
| --cngx-sidenav-backdrop-opacity | 0.5 | Backdrop opacity |
| --cngx-sidenav-transition-duration | 0.25s | Animation duration |
| --cngx-sidenav-resize-handle-width | 4px | Resize handle hit area |
| --cngx-sidenav-resize-handle-color | M3 primary | Handle highlight color |
| --cngx-sidenav-expanded-shadow | 12px shadow toward the content, deeper in a dark scheme or island | Peek shadow |
| --cngx-sidenav-overlay-shadow | --cngx-sidenav-expanded-shadow (Material 3 bridge: level 1) | Open overlay shadow |
Nav row theming (links and [cngxNavGroup] heads inside cngx-sidenav; the state fills, indicator, inset and ring colours are SET on the cngx-sidenav host, sidenav.theme() maps them onto M3 roles):
| Variable | Description |
|-|-|
| --cngx-nav-link-color | Default text color |
| --cngx-nav-link-hover-color | Hover text color |
| --cngx-nav-link-hover-bg | Hover fill (primary 6 % over transparent) |
| --cngx-nav-link-pressed-bg | Pressed fill (primary 12 %) |
| --cngx-nav-link-active-color | Active text color |
| --cngx-nav-link-active-bg | Active fill (primary 16 %; M3 secondary-container in the bridge) |
| --cngx-nav-link-active-hover-bg | Active row under the pointer (primary 22 %) |
| --cngx-nav-link-active-indicator-color | Inline-start bar on the active row (--cngx-color-primary-text; transparent in the M3 bridge) |
| --cngx-nav-link-active-indicator-size | Bar width (from --cngx-space-xs) |
| --cngx-nav-link-active-indicator-inset | Bar block inset (from --cngx-space-sm) |
| --cngx-nav-link-inset | Row inline inset from the rail edges (from --cngx-space-xs) |
| --cngx-nav-link-focus-outline-color | Outer focus ring (--cngx-color-text) |
| --cngx-nav-link-focus-inner-color | Inner focus ring (--cngx-sidenav-bg) |
| --cngx-nav-link-radius | Border radius (default 4px, 8px in the M3 bridge) |
| --cngx-nav-link-padding | Padding (from --cngx-space-sm / --cngx-space-md) |
Animated nav group expand/collapse:
Replace @if with a [cngxNavGroupContent] wrapper (@cngx/common/interactive) for
smooth height animation via the CSS grid-template-rows: 0fr/1fr trick (no
@angular/animations needed). The directive sets the .cngx-nav-group-content /
--open classes and makes the region inert while the group is closed, so collapsed
links leave the tab order and the accessibility tree. Do not set the classes by hand:
<button cngxNavGroup #group="cngxNavGroup" [controls]="'items'">Settings</button>
<div [cngxNavGroupContent]="group">
<div id="items" role="group">
<a cngxNavLink [depth]="1">General</a>
<a cngxNavLink [depth]="1">Security</a>
</div>
</div>Material theme: @use '@cngx/themes/material/sidenav-theme' - includes nav-link theme automatically
CngxNavRail (@cngx/ui/nav-rail)
A narrow, always-collapsed column of nav rows for apps whose primary
navigation never expands. Reach for CngxSidenav when the same navigation
also opens to full width. The rows are the nav atoms of
@cngx/common/interactive; the rail only sets their tokens and its width.
<cngx-nav-rail labelPlacement="below">
<a cngxNavLink routerLink="/inbox">
<cngx-icon cngxNavIcon><mat-icon>inbox</mat-icon></cngx-icon>
Inbox
</a>
</cngx-nav-rail>Inputs: labelPlacement ('end': icon only with a tooltip, default;
'below': icon over a short label), ariaLabel (unbound, the navRail
language-pack copy names the landmark).
Slots: cngx-nav-header / [cngxNavHeader] above the rows,
cngx-nav-footer / [cngxNavFooter] below them.
A nav group opens as a flyout beside its head; aria-expanded stays the one
state. See projects/ui/nav-rail/README.md.
Material theme: @use '@cngx/themes/material/nav-rail-theme' - rail surface, flyout and the rows
CngxToc (@cngx/ui/toc)
"On this page" navigation rail. Renders a <nav> of anchor links from a
CngxTocItem[] outline, tracks the most-visible section through an internal
CngxScrollSpy, and reflects it on aria-current inside the computed()
graph. Activating a link scrolls the section into view (honouring
prefers-reduced-motion) and moves focus to it.
<cngx-toc [items]="toc" contentRoot="#article"></cngx-toc>Inputs: items (required, CngxTocItem[]), contentRoot (scroll-container
selector, default viewport), rootMargin, threshold (forwarded to the spy).
Output: activated (the item whose link was clicked).
Slot: *cngxTocItem (context $implicit / active / depth).
Router sync: add [cngxTocRouterSync] on the same host to deep-link the
active section into the URL fragment (opt-in, CNGX_TOC contract token).
A toc is a navigation landmark of links, not a tree. Nesting is communicated
structurally (nested <ul>, indentation) so native tab order and link semantics
stay intact - the APG treeview pattern is deliberately not applied. Reach for
CngxSidenav instead when you need a collapsible primary-navigation rail with a
selection model; CngxToc is a passive reflection of scroll position.
Focus contract: to move focus to a scrolled-to section, CngxToc sets
tabindex="-1" on the target element only when it is not focusable by default
and carries no author-set tabindex; an author value is never overwritten.
Material theme: @use '@cngx/themes/material/toc-theme'
CngxToaster - Toast API (@cngx/ui/feedback)
Programmatic toast service. Not providedIn: 'root' - provide via
provideFeedback(withToasts()) or provideToasts().
ToastConfig
this.toaster.show({
message: 'Saved', // Required - sole text when title not set
title: 'Save successful', // Optional - bold primary text
description: 'Profile updated.', // Optional - secondary text below title
severity: 'success', // 'info' | 'success' | 'warning' | 'error'
duration: 5000, // ms or 'persistent'
action: { label: 'Undo', handler: () => this.undo() },
dismissible: true, // default: true
content: MyCustomToastBody, // Optional - component as toast body
contentInputs: { error: err }, // Inputs for the content component
});Layout rules:
messageonly (notitle): single-line text (backwards-compatible)title+description/message: two-line layout (title bold, description muted)title+content: title above custom componentcontentonly: custom component fills the body
A11y: Avoid focusable elements (<a>, <button>) inside content components
- they are unreachable inside a
role="status"live region.
Dedup: Toasts with same message + severity + title within dedupWindow (default
1000ms) are merged (count incremented). description is intentionally excluded from
dedup - same event with different context detail is still the same event.
Toast CSS Custom Properties
| Property | Default | Description |
|-|-|-|
| --cngx-toast-title-font-weight | 600 | Title font weight |
| --cngx-toast-title-color | inherit | Title text color |
| --cngx-toast-title-font-size | --cngx-toast-font-size | Title font size |
| --cngx-toast-description-color | #64748b | Description text color (muted) |
| --cngx-toast-description-font-size | 0.8125rem | Description font size |
| --cngx-toast-description-line-height | 1.4 | Description line height |
| --cngx-toast-description-max-lines | 3 | Line-clamp for description |
CngxAlert - Inline Alert Atom (@cngx/ui/feedback)
Inline alert with enter/exit animations, state-driven visibility, auto-dismiss with pause-on-hover/focus (WCAG 2.2.1), optional auto-collapse, and action buttons.
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
<!-- Static -->
<cngx-alert severity="warning" title="Unsaved changes" [dismissible]="true">
Your changes will be lost if you leave.
<button cngxAlertAction (click)="save()">Save now</button>
</cngx-alert>
<!-- State-driven -->
<cngx-alert [state]="saveState" severity="error" title="Save failed" [dismissible]="true">
{{ saveState.error() }}
</cngx-alert>
<!-- Boolean-driven -->
<cngx-alert [when]="showTip()" severity="info" title="Tip">
Press Ctrl+S to save.
</cngx-alert>
<!-- Collapsible (collapses body after delay, expands on hover/focus) -->
<cngx-alert [state]="state" severity="error" title="Errors"
[collapsible]="true" [collapseDelay]="3000">
Detailed error description...
</cngx-alert>Inputs:
| Input | Type | Default | Description |
|-|-|-|-|
| severity | AlertSeverity | 'info' | Visual style + ARIA role |
| title | string | -- | Bold title above content |
| dismissible | boolean | false | Show dismiss button |
| state | CngxAsyncState<unknown> | -- | State-driven visibility |
| when | boolean | -- | Boolean visibility trigger |
| autoDismissDelay | number | 5000 | Auto-dismiss delay for success state (ms) |
| collapsible | boolean | false | Enable auto-collapse |
| collapseDelay | number | autoDismissDelay | Delay before collapse (ms) |
Slot directives: CngxAlertAction (restricts to button, a), CngxAlertIcon (custom icon)
ARIA: role="alert" (error/warning), role="status" (info/success), aria-busy (loading),
aria-expanded (collapsible), aria-atomic="false" when CngxAlertAction is present.
Animation: CSS keyframes with prefers-reduced-motion support. Enter: ease-out 200ms.
Exit: ease-in 150ms. Icon pulse on enter (one-shot, 300ms).
Collapse: grid-template-rows: 1fr/0fr transition. Hover/focus expands, leave restarts timer.
CSS Custom Properties:
| Variable | Default | Description |
|-|-|-|
| --cngx-alert-gap | 12px | Gap between icon, body, dismiss |
| --cngx-alert-padding | 12px 16px | Alert padding |
| --cngx-alert-border-radius | 8px | Corner radius |
| --cngx-alert-icon-size | 20px | Default icon size |
| --cngx-alert-title-weight | 600 | Title font weight |
| --cngx-alert-enter-duration | 200ms | Enter animation duration |
| --cngx-alert-exit-duration | 150ms | Exit animation duration |
| --cngx-alert-collapse-duration | 200ms | Collapse transition duration |
| --cngx-alert-{severity}-bg | per severity | Background color |
| --cngx-alert-{severity}-border | per severity | Border color |
| --cngx-alert-{severity}-icon | per severity | Icon color |
CngxAlertStack + CngxAlerter - Scoped Alert System (@cngx/ui/feedback)
Scoped inline alert stacking with programmatic service. Each CngxAlertStack provides
its own CngxAlerter via viewProviders - nested stacks (e.g. in dialogs) are fully
isolated.
<!-- In a dialog -->
<dialog cngxDialog [submitAction]="save">
<header cngxDialogTitle>Edit User</header>
<cngx-alert-stack scope="user-form" [maxVisible]="5" />
<form>...</form>
</dialog>// In a child component inside the dialog
private readonly alerter = inject(CngxAlerter);
handleErrors(errors: string[]) {
this.alerter.dismissAll();
errors.forEach(e => this.alerter.show({ message: e, severity: 'error' }));
}For root-level injection (outside a stack), add withAlerts() to provideFeedback().
CngxAlertStack inputs:
| Input | Type | Default | Description |
|-|-|-|-|
| scope | string | -- | Scope filter for alerts |
| maxVisible | number | 5 | Max visible before overflow collapse |
| position | 'top' \| 'bottom' | 'top' | Where new alerts insert |
| reserveSpace | boolean | false | Reserve min-height to prevent layout shift |
| autoScroll | boolean | true | Scroll stack into view on new alert |
CngxAlerter API:
| Method | Returns | Description |
|-|-|-|
| show(config) | AlertRef | Show an alert |
| dismiss(id) | void | Dismiss by id |
| dismissAll(scope?) | void | Dismiss all (optionally filtered by scope) |
AlertConfig: message (required), severity, title, persistent (default true),
duration, dismissible (default true), scope.
Dedup: message + severity + scope within alertDedupWindow (default 1s).
ARIA: role="log" + aria-live="polite" on container. aria-expanded + aria-controls
on overflow button.
CngxAlertOn - State Bridge
<button [cngxAsyncClick]="save"
[cngxAlertOn]="saveState"
alertError="Save failed"
[alertErrorDetail]="true">
Save
</button>Inputs: cngxAlertOn (required CngxAsyncState), alertSuccess, alertError,
alertErrorDetail (boolean), alertScope.
CngxBanner + CngxBannerOutlet - Global Banner System (@cngx/ui/feedback)
System-level banners for session timeout, maintenance, offline status. Sticky top,
always persistent (no auto-dismiss), dedup by required id.
<!-- Once in app shell, above layout -->
<cngx-banner-outlet />
<div class="layout">...</div>private readonly banner = inject(CngxBanner);
this.banner.show({
message: 'Session expires in 5 minutes',
id: 'auth:session-timeout',
severity: 'warning',
action: {
label: 'Extend',
handler: () => this.extendSession(), // returns Promise<void>
},
});
// Update in-place (same id)
this.banner.update('auth:session-timeout', {
message: 'Session expires in 2 minutes',
severity: 'error',
});
// Dismiss when condition resolves
this.banner.dismiss('auth:session-timeout');Requires provideFeedback(withBanners()).
CngxBanner API:
| Method | Returns | Description |
|-|-|-|
| show(config) | BannerRef | Show or update (if id exists) |
| update(id, patch) | void | Patch an existing banner |
| dismiss(id) | void | Dismiss by id |
| dismissAll() | void | Dismiss all banners |
| executeAction(id) | Promise<void> | Execute the banner's action handler with async lifecycle |
BannerConfig: message (required), id (required), severity, dismissible
(default true), action ({ label, handler: () => void | Promise<void> }).
Async actions: When action.handler returns a Promise, the button shows aria-busy,
disables during execution. Success: banner dismissed. Error: banner stays open.
ID uniqueness: Caller's responsibility. Recommended prefix convention:
'auth:session-timeout', 'billing:payment-failed'.
ARIA: role="alert" (error/warning), role="status" (info/success).
aria-live="assertive" for error only, polite for others.
First-render: Banners present at initial render skip enter animation (no layout jump).
Layout: position: sticky; top: 0; z-index: 900 (below Material dialogs at 1000).
:empty hides the outlet completely (display: none).
CngxBannerTrigger - Declarative Banner
<cngx-banner-trigger
[when]="isOffline()"
message="You are offline."
id="net:offline"
severity="error" />Renders nothing. Shows banner when [when] is true, dismisses when false.
Dismissed on component destroy.
Inputs: when (required), message (required), id (required), severity,
dismissible, actionLabel, actionHandler.
CngxBannerOn - State Bridge
<div [cngxBannerOn]="connectionState"
bannerId="net:offline"
bannerError="Connection lost">
</div>Shows banner on error transition, auto-dismisses on success/idle.
Inputs: cngxBannerOn (required CngxAsyncState), bannerId (required),
bannerError, bannerSeverity (default 'error'), bannerErrorDetail (boolean).
Banner CSS Custom Properties
| Variable | Default | Description |
|-|-|-|
| --cngx-banner-z-index | 900 | Stacking order |
| --cngx-banner-gap | 12px | Gap between elements |
| --cngx-banner-padding | 10px 16px | Banner padding |
| --cngx-banner-font-size | 0.9375rem | Message font size |
| --cngx-banner-pending-opacity | 0.85 | Opacity during async action |
| --cngx-banner-{severity}-bg | per severity | Background |
| --cngx-banner-{severity}-border | per severity | Border |
| --cngx-banner-{severity}-icon | per severity | Icon color |
Material theme: Included in @use '@cngx/themes/material/feedback-theme' - theme($theme) covers alert, alert-stack, banner, toast, loading, and progress.
