Age View

AgeView is a headless read-only display of a person's age, in the consumer's words. It renders as a <span>. The TypeScript libraries export ageParts(), which gives the age in units suited to it (minutes for a newborn, weeks and days for an infant, years and months for a child, years for an adult), and toIsoDuration().

Status: experimental — new, implemented and unit-tested in every headless library; not yet exercised in a composed flow.

Example

Age 3 weeks 2 days
Show demo markup
<span class="age-view" data-duration="P23D"><span class="screen-reader-span">Age </span>3 weeks 2 days</span>
Usage example
<span class="age-view" data-duration="P23D"><span class="screen-reader-span">Age </span>3 weeks 2 days</span>
Show Svelte source
// In your Svelte component:
import AgeView from "lily-design-system-svelte-headless/components/AgeView/AgeView.svelte";

<AgeView>
  <!-- content -->
</AgeView>

Usage

<AgeView
  label="Age"
  value="3 weeks 2 days"
  duration="P23D"
/>

Props

  • value: string (required) — the age as the consumer writes it
  • duration: string (optional) — the same age as an ISO 8601 duration, rendered as data-duration
  • label: string (optional) — hidden text naming the value
  • ...restProps: any — additional HTML attributes spread onto the root

Keyboard Interactions

None. This is not an interactive component.

ARIA

  • No role and no aria-label; label renders as hidden text

When to Use

  • Use beside a date of birth in a patient banner.
  • Use where an infant's age in weeks or a child's in years and months matters clinically.

When Not to Use

  • Do not use for a date — use date-time-view.
  • Do not use for a duration that is not an age — use duration-view.

Headless

This headless component ships zero CSS and decides nothing visual. The consumer provides all styling targeting the .age-view class hook, and every word.

Styles

.age-view and [data-duration].

Testing

  • The words and data-duration render
  • ageParts() returns the right units at every band boundary (shared tests)

Advice

  • The unit bands follow the NHS Common User Interface; another convention can ignore ageParts() and pass its own words.
  • Show the age beside the date of birth, not instead of it.

Implementation Notes

  • Renders <span class="age-view"> with the consumer's words
  • duration is the same age as an ISO 8601 duration, rendered as data-duration
  • Writes no words for units: the consumer formats ageParts() with Intl.DurationFormat or its own labels

Related components

  • date-time-view — a read-only display of a date and time
  • medical-banner — a prominent message bar with medical information

References


Lily™ and Lily Design System™ are trademarks.

Canonical contract

Generated from this component's canonical metadata — the machine-checked source the implementations are held to.

Metadata

  • Component: age-view
  • PascalCase: AgeView
  • Description: a read-only display of a person's age, in the units suited to it
  • Status: experimental — new, implemented and unit-tested in every headless library; not yet exercised in a composed flow
  • HTML tag: <span>
  • CSS class: .age-view
  • Interactive: no

ARIA

  • No role and no aria-label; label renders as hidden text

Keyboard

  • Not interactive

Props

  • value: string (required) — the age as the consumer writes it
  • duration: string (optional) — the same age as an ISO 8601 duration, rendered as data-duration
  • label: string (optional) — hidden text naming the value
  • ...restProps: any — additional HTML attributes spread onto the root

Markdown

This page as Markdown, for people and AI tools: age-view.md