Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Data Color
  3. Usage

Data color

Usage

Overview
DataColor is the narrow exception to palette-only paint in @prepared911/ui. It carries a valid CSS color string from vendor or GIS data through toDataColor, then into fill or stroke on Shape or Swatch only. It is not a token, not ChartColor, and not a general escape hatch for product-owned UI.
When to use
  • Legend or map marks that must match third-party layer styles (for example ESRI symbology) where no Chroma token exists.
  • Chart-adjacent swatches that must show an exact vendor hex or named color returned by an API you do not control.
When not to use
  • Anything Axon 911 owns: status, emphasis, surfaces, borders, and typography use enum props and tokens.
  • Series colors you define in product code: use ChartColor on charts and Swatch.
  • Color-semantic props on layout and typography: Box background, Text foreground, Icon foreground, and similar token enums do not accept DataColor at the type level (packages/ui/src/components/data-color/scope.type-test.ts).
Decision table
SituationUse
Product status, alert, or emphasisForeground, Background, StatusDot, Badge, or other token props
Chart series you controlChartColor on Swatch or chart slices
Color string from GIS or vendor API you cannot remaptoDataColor, then fill or stroke on Shape or Swatch
One-off designer pick in app codeRequest a token or use an existing palette enum; not DataColor
toDataColor contract
  • Input: any string from data. Trimmed for validation only; on success the original string is returned, branded.
  • Valid: must parse as a CSS color after safety checks (hex, rgb/hsl/hwb/lab/lch/oklab/oklch/color(), named colors, transparent, and similar).
  • Invalid: returns undefined (does not throw). Call sites should omit paint or fall back to none.
  • Safety rejects: var(, url(, currentcolor, CSS-wide keywords, injection-like characters, and the full list in ADR 0034.
Where it is accepted
DataColor is a branded subtype of string, so any prop typed as plain string still accepts it at compile time. The real guarantee is narrower:
  • Color-semantic props (Box background, Text/Icon foreground, and other token paint enums) reject DataColor in type tests.
  • Only Shape and Swatch read DataColor on fill and stroke and paint it (mechanical scope: packages/ui/tests/data-color-scope.test.ts).
  • Vector fill/stroke still accept palette tokens and ChartColor for product-owned colors.
Do not pass DataColor through unrelated string props expecting components to paint it; only vector marks implement the runtime path.
Consumer lint
Calling toDataColor (from @prepared911/ui, @prepared911/ui/primitives or @prepared911/ui/data-color) or casting with as DataColor triggers design-system/to-data-color-call at warning severity in product trees. It shows in pnpm check output; pnpm lint:design-system covers the legacy trees. The rule is informational: explain in the pull request why the color is third-party data you cannot map.
Related
  • Shape for arbitrary SVG paths (documented separately).
  • Swatch for fixed 12×12 legend marks (documented separately).
Previous
Counter / Accessibility
Next
Data color / API and Development
On this page
Overview
When to use
When not to use
Decision table
toDataColor contract
Where it is accepted
Consumer lint
Related