CngxCloseButton
projects/common/interactive/close-button/close-button.ts
Import#
import { CngxCloseButton } from '@cngx/common/interactive'
Description#
Shared close/dismiss button molecule.
Composes the native <button> shell with an optional projected icon
and the CNGX_CLOSE_ICON DI swap; owns ARIA wiring, focus ring,
density, and a default X glyph as the projection fallback.
Used internally by CngxAlert, CngxToastOutlet, and CngxPopoverPanel.
Can also be used standalone by consumers for dialogs, drawers, chips, etc.
All visual properties are CSS Custom Properties - density is controlled
via the feedback.density() SCSS mixin or direct overrides.
Standalone
<cngx-close-button label="Close dialog" (click)="close()" />Inside a component (click handled by parent)
<cngx-close-button label="Close" />Metadata#
Relationships
Used by5
Depends on1
Default visuals for CngxCloseButton. The host carries
.cngx-close-button and renders with display: contents so the
inner .cngx-close-button__btn carries the box; the glyph projects
into .cngx-close-button__icon. Idle state is muted via opacity;
hover lifts to full opacity plus a subtle neutral wash.
State modifiers
State is driven by pseudo-classes on the inner button rather than host modifier classes:
:hover- opacity to--cngx-close-button-hover-opacityplus--cngx-close-button-hover-bgwash:focus-visible- outline via--cngx-close-button-focus-outline- offset, opacity forced to 1
:active- opacity to--cngx-close-button-active-opacity
Slots
.cngx-close-button__btn- the actual focusable<button>.cngx-close-button__icon- projected glyph (defaults to a 16px box)
Inheritance
Layout tokens cascade through the foundation:
--cngx-close-button-padding->--cngx-space-sm--cngx-close-button-radius->--cngx-radius-sm--cngx-close-button-color- direct (defaults tocurrentColor)
Dark mode
Three hooks flip the hover wash from oklch(0 0 0 / 0.04) to
oklch(1 0 0 / 0.06) so the subtle hover surface stays visible
against a dark page:
prefers-color-scheme: dark[data-color-scheme="dark"].darkclass
A matching [data-color-scheme="light"] / .light block pins the
light value so explicit-light overrides win over the media query.
Index#
Layout
State / Idle
State / Active
Surface
Layout
<length>32pxMinimum hit-target size of the button (both axes).
<length>8pxPadding shorthand. Falls back to --cngx-space-sm.
State / Idle
<number>0.5Resting opacity. The hover state lifts to full opacity.
Motion
<time>150msTransition duration for opacity / background changes.
State / Hover
<color>oklch(0 0 0 / 0.04)Background tint applied on hover - a subtle neutral overlay.
inherits: true so the :root dark-mode override reaches the
inner <button> on hover.
State / Focus
*2px solid currentColorFocus-ring outline shorthand.
State / Active
<number>0.8Opacity applied during the active (pressed) state.