Skip to main content
cngx-src documentation

CngxMetric

ComponentPrimaryOnPushNo encapsulationv0.1.0WCAG AA

projects/common/data/display/metric/metric.component.ts

Import#

import { CngxMetric } from '@cngx/common/data'

Description#

Displays a formatted numeric value with optional unit.

Uses Intl.NumberFormat with the injected LOCALE_ID for locale-aware formatting. Null values render as an em-dash.

Composable - works inside any card variant, header, body, or standalone.

Basic

<cngx-metric [value]="1234" unit="bpm" />

With format options

<cngx-metric [value]="99.6" unit="%" [format]="{ maximumFractionDigits: 1 }" />

Inside a card

<cngx-card>
  <header cngxCardHeader>Puls</header>
  <cngx-metric cngxCardBody [value]="75" unit="bpm" />
</cngx-card>

https://cngxjs.github.io/cngx/examples/#/common/data/metric/inside-a-card https://cngxjs.github.io/cngx/examples/#/common/data/metric/standalone-metrics

Metadata#

Host#

Index#

Inputs#

format#Intl.NumberFormatOptions | undefined
input()

Intl.NumberFormatOptions for the primary value.

unit#string | undefined
input()

Unit suffix (e.g. "bpm", "h", "%", "kg").

value#number | string | null
input()Required

Numeric or string value. null renders as a placeholder hyphen.

HostBindings#

BindingExpression
[attr.aria-label]accessibleValue()

Default visuals for CngxMetric. The host carries .cngx-metric - an inline-flex container that pairs a large bold figure with a small muted unit on a shared baseline.

Slots

  • .cngx-metric__value - the numeric figure (large, bold)
  • .cngx-metric__unit - the trailing unit or label (small, muted)

Inheritance

  • --cngx-metric-value-color -> --cngx-color-text
  • --cngx-metric-unit-color - leaf token, swaps in dark mode

Dark mode

Three hooks lift value and unit text to the foundation's dark-mode lightness; chroma and hue identity stay constant:

  • prefers-color-scheme: dark
  • [data-color-scheme="dark"] / .dark class
  • [data-color-scheme="light"] / .light class (explicit pin)

Index#

Layout

--cngx-metric-gap#<length>
Default value 2px

Gap between the value and the unit slot.

Typography

--cngx-metric-value-size#*
Default value 1.75rem

Font-size of the value slot.

--cngx-metric-value-weight#<number>
Default value 600

Font-weight of the value slot.

--cngx-metric-value-color#<color>
Default value oklch(0.2 0.01 290)

Text color of the value slot.

--cngx-metric-unit-size#*
Default value 0.875rem

Font-size of the unit slot.

--cngx-metric-unit-weight#<number>
Default value 400

Font-weight of the unit slot.

--cngx-metric-unit-color#<color>
Default value oklch(0.36 0.02 290)

Text color of the unit slot - muted by default.