CngxChip
projects/common/display/chip/chip.component.ts
Import#
import { CngxChip } from '@cngx/common/display'
Description#
Chip / tag molecule - a small, self-contained pill rendering projected content plus an optional close affordance.
Why this exists.
Multi-value triggers (CngxMultiSelect today; CngxMultiCombobox,
CngxTagInput, toolbar filter-chips tomorrow) all want the same pill
surface and the same remove interaction. Inlining <span>/<button>
pairs per consumer (a) duplicates ARIA wiring and (b) defeats
atomic-decompose: ejecting a parent component drags a block of raw
markup into the consumer's source instead of a clean molecule.
Responsibilities (intentionally narrow).
- Render projected
<ng-content>as the chip label. - Render a close button when
removable()is true, emit(remove)on click. - Provide a stable DOM id for ARIA wiring (auto-generated or consumer-supplied).
Non-responsibilities.
- Selection state - parent tracks which value(s) are picked.
- Commit/async behaviour - remove simply fires an event; the parent decides whether to write state directly or route through a commit flow. This keeps the chip usable from any level of the stack.
Metadata#
Host#
Relationships
Used by6
Index#
Inputs#
string | nullOptional DOM id. When unset, a stable auto-id (cngx-chip-N) is
applied so aria-describedby / aria-labelledby hooks from the
parent can reference the chip.
nullWhether the close button is rendered. Typed as boolean - bind a
signal getter ([removable]="!select.disabled()") if the flag
needs to react to upstream state.
falseOutputs#
HostBindings#
| Binding | Expression |
|---|---|
[attr.id] | resolvedId() |
Default visuals for CngxChip - a single pill. The host carries
.cngx-chip and renders a prefix / label / optional remove button
in an inline-flex row. The unkeyed surface carries a primary-tinted
fill so a plain chip reads as accented out of the box. Layout for
a CONTAINER of multiple chips (gap, flex-wrap) lives on the
consumer wrapper, not here.
State modifiers
Interactive treatment only activates on selectable / removable chips - a static label chip stays cursor-default:
[role="button"]/[tabindex]/:has(.cngx-chip__remove)- hover wash, cursor: pointer
:focus-visible- brand-primary outline ring[aria-selected="true"]/[aria-pressed="true"]- darker primary-tinted fill[aria-disabled="true"]/:disabled- opacity 0.38, no pointer events
Color variants
Selected via [data-color="..."] so consumers can add their own
keys on top of the four built-ins:
[data-color="info"]- blue-band tinted surface + text[data-color="success"]- success-coded[data-color="warning"]- warning-coded[data-color="danger"]- danger-coded
Slots
.cngx-chip__label- the text, ellipsis-truncates.cngx-chip__remove- inline button, fades in / out via--cngx-chip-remove-opacity+:focus-visiblering
Inheritance
--cngx-chip-inner-gap->--cngx-space-xs--cngx-chip-padding-inline->--cngx-space-sm--cngx-chip-radius->--cngx-radius-pill--cngx-chip-font-size->--cngx-font-size-sm--cngx-chip-focus-outlinecolor ->--cngx-color-primary--cngx-chip-remove-radius->--cngx-radius-sm--cngx-chip-remove-focus-color->--cngx-color-primary- Variant surfaces use alpha-tints that mix correctly on either light or dark backgrounds; only the text colors swap in dark
Dark mode
Three hooks flip only the four variant text colors from dark hues to light hues so they stay legible against the dark-mixed variant background - the alpha-tinted surfaces ride straight through unchanged:
prefers-color-scheme: dark[data-color-scheme="dark"]/.darkclass[data-color-scheme="light"]/.lightclass (explicit pin)
Index#
Typography
Motion
State / Hover
State / Disabled
State / Selected
Variant / Info
Variant / Success
Variant / Warning
Variant / Danger
Layout
<length>4pxGap between the chip's internal slots (prefix / label / remove).
Falls back to --cngx-space-xs.
<length>999pxCorner radius. Defaults to a full pill via --cngx-radius-pill.
Surface
<color>oklch(0.66 0.19 50 / 0.12)Background of the default (unkeyed) chip. Primary-tinted at low alpha so the chip reads as accented without competing with stronger surfaces.
See: [[--cngx-color-primary]]
*currentColorText color. Defaults to currentColor so the chip inherits the
container's text color.
*0 solid transparentBorder shorthand. Zero-width by default - pillows fill the box.
Typography
Motion
*background-color 150ms ease,
color 150ms ease,
border-color 150ms easeTransition shorthand for background / color / border-color changes on hover, selected, and disabled states.
State / Hover
<color>oklch(0.66 0.19 50 / 0.2)Background of the hover state for interactive chips
([role=button], [tabindex], or a chip with a remove button).
State / Focus
*2px solid oklch(0.66 0.19 50)Focus-ring shorthand applied via outline on :focus-visible.
Defaults to the brand primary so the ring contrasts with the chip's
own tinted fill (selected or unkeyed) instead of inheriting
currentColor, which would render the ring in the text color and
read as a generic dark border on top of the orange fill.
See: [[--cngx-color-primary]]
State / Disabled
<number>0.38Opacity multiplier applied by [aria-disabled=true] and :disabled.
State / Selected
<color>oklch(0.66 0.19 50 / 0.32)Background of the selected state ([aria-selected=true] /
[aria-pressed=true]).
Variant / Info
<color>oklch(0.65 0.12 240 / 0.16)Background of the [data-color=info] variant.
See: [[--cngx-color-info]]
<color>oklch(0.45 0.12 240)Text color of the [data-color=info] variant.
Variant / Success
<color>oklch(0.65 0.15 145 / 0.16)Background of the [data-color=success] variant.
See: [[--cngx-color-success]]
<color>oklch(0.45 0.15 145)Text color of the [data-color=success] variant.
Variant / Warning
<color>oklch(0.72 0.15 75 / 0.18)Background of the [data-color=warning] variant.
See: [[--cngx-color-warning]]
<color>oklch(0.5 0.15 75)Text color of the [data-color=warning] variant.
Variant / Danger
<color>oklch(0.65 0.22 25 / 0.18)Background of the [data-color=danger] variant.
See: [[--cngx-color-danger]]
<color>oklch(0.5 0.2 25)Text color of the [data-color=danger] variant.
State / Remove
<length>2pxFocus-ring width of the inline remove button.
<color>oklch(0.66 0.19 50)Focus-ring color of the inline remove button. Falls back to
--cngx-color-primary.
<length>1pxFocus-ring offset of the inline remove button.