CngxActionButton
projects/ui/action-button/action-button.ts
Import#
import { CngxActionButton } from '@cngx/ui/action-button'
Description#
Action button organism with built-in status communication.
Coordinates between the CngxAsyncClick atom (mechanism, ARIA, lifecycle)
and the consumer (intent, styling, labels). Provides template projection
for pending/succeeded/failed states and an aria-live region for screen
reader announcements.
Uses display: contents - the host produces no DOM box. The inner <button>
carries the [cngxAsyncClick] directive directly.
For full control, use [cngxAsyncClick] directly on any element instead.
Minimal (covers 80% of cases)
<cngx-action-button [action]="save">Save</cngx-action-button>With string labels
<cngx-action-button [action]="save"
pendingLabel="Saving..." succeededLabel="Saved!" failedLabel="Failed">
Save
</cngx-action-button>With template slots
<cngx-action-button [action]="save">
Save Draft
<ng-template cngxPending><mat-spinner diameter="18" /> Saving...</ng-template>
<ng-template cngxSucceeded>Saved!</ng-template>
<ng-template cngxFailed let-err>{{ err }} - retry?</ng-template>
</cngx-action-button>With toast feedback
<cngx-action-button [action]="save" toastSuccess="Saved" toastError="Save failed">
Save
</cngx-action-button>Metadata#
Host#
Relationships
Index#
Inputs#
When false, clicks are ignored. Passed through to cngxAsyncClick.
trueCngxAsyncState | undefined Bind an external async state to derive visual status from.
When set, the button's status display follows externalState.status().
string | undefinedSR announcement on failure. Falls back to failedLabel, then 'Action failed'.
string | undefinedFallback text after failure (when no cngxFailed template is projected).
Duration in ms to show success/error feedback. Passed through to cngxAsyncClick.
2000string | undefinedFallback text while pending (when no cngxPending template is projected).
string | undefinedSR announcement on success. Falls back to succeededLabel, then 'Action succeeded'.
string | undefinedFallback text after success (when no cngxSucceeded template is projected).
Include the error detail message in the error toast body.
falsenumber | 'persistent'Duration for error toasts - 'persistent' means manual dismiss only.
'persistent'string | undefinedToast message on success. Requires CngxToaster (via provideFeedback(withToasts())
or provideToasts()). Silently ignored when toaster is not provided.
toastSuccessDuration should be >= feedbackDuration to avoid rapid re-fire
on repeated clicks that floods the SR announcement queue.
"button" | "submit" | "reset"Button type attribute. Defaults to 'button' to prevent accidental form submits.
'button'ActionButtonVariantVisual variant - sets CSS class cngx-action-button--{variant}.
'primary'Instance Properties#
CngxAsyncStateFull CngxAsyncState view of this button's effective lifecycle.
Reflects the external state when [externalState] is bound,
otherwise the inner CngxAsyncClick directive's state.
Bind to any state consumer: <cngx-alert [state]="btn.state" />.
buildAsyncStateView<unknown>({
status: this.effectiveStatus,
data: computed(() => undefined),
error: this.effectiveError,
lastUpdated: this.lastUpdatedState.asReadonly(),
})Default visuals for CngxActionButton. The component host carries
display: contents and renders a <button class="cngx-action-button cngx-action-button--{variant}"> inside. Token groups span Layout /
Surface / Motion plus per-variant and per-async-state buckets.
State modifiers
Async-commit state classes are set by cngxAsyncClick on the
<button> element, and the actual .cngx-async--* rules live in
@cngx/common/theming/components/cngx-async.css so they apply
globally (CngxPopoverAction and standalone usages reach them too).
The token surface reserved here:
--cngx-action-btn-pending-opacity- opacity +cursor: wait--cngx-action-btn-succeeded-bg / -color / -border- success tint--cngx-action-btn-failed-bg / -color / -border- failure tint
Variants
Three variants share the base shape (border, radius, padding, transition) and only repaint the surface:
--primary- filled brand surface, white text--secondary- transparent fill, brand text, border accent--ghost- text-only, hover state-layer for affordance
Pair with
@cngx/themes/material/action-button-theme- Material 3 primary / outline / error surfaces
Index#
State / Pending
State / Succeeded
State / Failed
Variant / Primary
Motion
*0.2s easeTransition shorthand for background-color / color / border-color / opacity transitions across all variants and async states.
Layout
*8px 16pxVertical + horizontal padding shorthand. Both axes can be re-driven individually by overriding with a one- or two-value shorthand.
.compact { --cngx-action-btn-padding: 4px 10px; }Surface
<color>oklch(0.87 0 0)Border color of the base (non-variant) .cngx-action-button rule.
Variant rules override this per appearance.
See: [[--cngx-color-border]]
<color>transparentBackground of the base rule. Variants override.
State / Pending
<number>0.7Opacity applied while cngxAsyncClick reports pending. Combined
with cursor: wait on the same state.
State / Succeeded
<color>oklch(0.95 0.04 145)Background tint after a successful async commit.
<color>oklch(0.5 0.15 145)Text color after a successful async commit.
<color>oklch(0.5 0.15 145)Border color after a successful async commit.
State / Failed
<color>oklch(0.95 0.025 25)Background tint after a failed async commit.
<color>oklch(0.45 0.15 25)Text color after a failed async commit.
<color>oklch(0.45 0.15 25)Border color after a failed async commit.
Variant / Ghost
<color>oklch(0 0 0 / 0.04)Hover state-layer for the ghost variant - subtle tint so the button is felt without competing with primary actions.
<color>oklch(0.34 0.005 290)Text color of the ghost variant.
Variant / Primary
<color>oklch(0.55 0.15 250)Background of the primary variant (filled).
Variant / Secondary
<color>transparentBackground of the secondary variant (outlined). Defaults to transparent so the surface beneath shines through.
<color>oklch(0.55 0.15 250)Text color of the secondary variant.
<color>oklch(0.55 0.005 290)Border color of the secondary variant.