CngxCopyBlock
projects/common/interactive/copy/copy-block.ts
Import#
import { CngxCopyBlock } from '@cngx/common/interactive'
Description#
Molecule: code/text block with a built-in copy button.
Renders content in a container with a "Copy" button that uses CngxCopyText
internally. Shows "Copied!" feedback automatically. The copy button includes
an aria-live region for screen reader announcements.
Copy a code snippet
<cngx-copy-block [value]="'npm install @cngx/common'">
<code>npm install @cngx/common</code>
</cngx-copy-block>Copy an API key
<cngx-copy-block [value]="apiKey()" buttonLabel="Copy Key">
{{ apiKey() }}
</cngx-copy-block>Metadata#
Relationships
Depends on1
Default visuals for CngxCopyBlock. The host carries
.cngx-copy-block and lays the projected content into
.cngx-copy-block__content next to a .cngx-copy-block__button
that toggles to a success-tinted confirmation state on click. The
copied colors fall back to --cngx-color-success so a brand
override in @layer cngx.theme propagates without forking tokens.
State modifiers
__button--copied- swaps background / border / text to the success-tinted palette for the confirmation pulse
Slots
.cngx-copy-block__content- the projected payload (flex: 1,overflow: hidden,min-width: 0).cngx-copy-block__button- the copy trigger.cngx-sr-only- visually-hidden status copy for AT
Inheritance
Layout, typography, and surface tokens cascade through the foundation; the copied-state palette delegates to the semantic success token:
--cngx-copy-block-gap->--cngx-space-sm--cngx-copy-block-btn-radius->--cngx-radius-sm--cngx-copy-block-btn-font-size->--cngx-font-size-sm--cngx-copy-block-btn-copied-border->--cngx-color-success--cngx-copy-block-btn-copied-color->--cngx-color-success
Dark mode
Three hooks flip the copied-state surface from a light-green tint to a dark-green tint, and the matching text color from a mid-green hue to a light-green hue. The border stays at mid-green since it reads on either surface:
prefers-color-scheme: dark[data-color-scheme="dark"].darkclass
A matching [data-color-scheme="light"] / .light block pins the
light values so explicit-light overrides win over the media query.
Index#
Typography
Layout
<length>8pxGap between the content block and the copy button. Falls back
to --cngx-space-sm.
<length>4pxCorner radius of the copy button. Defaults to --cngx-radius-sm.
Surface
Typography
*0.75remFont-size of the copy-button label. Falls back to
--cngx-font-size-sm.
State / Copied
<color>oklch(0.96 0.025 145)Background of the copied-state button - soft success tint.
inherits: true so the :root dark-mode override reaches the
button inside the copy-block host.
See: [[--cngx-color-success]]
<color>oklch(0.5 0.12 145)Border color of the copied-state button. Falls back to
--cngx-color-success.
<color>oklch(0.5 0.12 145)Text color of the copied-state button. Falls back to
--cngx-color-success. inherits: true so the :root dark-mode
override reaches the button.