# CompositionBar

A single horizontal bar split into proportional, color-coded segments — each category's share of the total, the composition read for open-ended counts with no fixed maximum.

Version: 0.2.0-preview.1 (preview)
Content digest: 70ac710f4d22dce040e7ac593379ba8aca9dcb59a0b9c0f839819cae0e2bb721
Contract kind: source-derived
Source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.tsx

## Guidance

{
  "summary": "A single horizontal bar split into proportional, color-coded segments — each category's share of the total, the composition read for open-ended counts with no fixed maximum.",
  "guidance": [
    {
      "heading": "Overview",
      "body": "A single horizontal bar split into proportional, color-coded segments — each category's share of\nthe total."
    },
    {
      "heading": "When to use",
      "body": "Reach for it when the counts are **open-ended** — a running total with no fixed maximum or goal.\nA share of the whole reads honestly at any scale: a brand-new user and a power user both see a\nmeaningful mix. `CategoryBars` scales length to the largest value, which pegs the leader near full\nand implies a ceiling that does not exist, so prefer this when the question is \"what's the mix?\"\nrather than \"read the exact magnitudes.\"\n\nEach segment takes its `color`; omit `color` and segments cycle the default category palette. Pair\nit with a labeled legend when the reader also needs the exact counts."
    }
  ],
  "usage": [],
  "examples": [],
  "source": "packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.mdx",
  "status": "local-preview",
  "note": "Guidance is read from local documentation, originally imported from the frozen source. Platform assertions in guidance are not parity verification."
}

## Contract and public API

```json
{
  "props": [
    {
      "name": "items",
      "type": "readonly CategoryDatum[]",
      "declared_type": "readonly CategoryDatum[]",
      "required": true,
      "description": "Category segments rendered left to right in the given order.",
      "source": {
        "path": "packages/design-system/src/components/visualizations/types.ts",
        "line": 73
      }
    },
    {
      "name": "ariaLabel",
      "type": "string | undefined",
      "declared_type": "string",
      "required": false,
      "description": "Accessible label for meaningful chart content.",
      "source": {
        "path": "packages/design-system/src/components/visualizations/types.ts",
        "line": 75
      }
    },
    {
      "name": "testId",
      "type": "string | undefined",
      "declared_type": "string",
      "required": false,
      "description": "Optional test selector.",
      "source": {
        "path": "packages/design-system/src/components/visualizations/types.ts",
        "line": 77
      }
    }
  ],
  "prop_shapes": {},
  "api": {
    "method": "typescript-type-checker",
    "typescript_version": "5.9.3",
    "public_export": "CompositionBar",
    "public_path": "CompositionBar",
    "import_path": "@cloakedinc/design-system",
    "root_kind": "component",
    "entrypoints": [
      {
        "name": "CompositionBar",
        "signature": 1,
        "visibility": "public",
        "source": {
          "path": "packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.tsx",
          "line": 12
        },
        "props_type": "CompositionBarProps",
        "props": [
          {
            "name": "items",
            "type": "readonly CategoryDatum[]",
            "declared_type": "readonly CategoryDatum[]",
            "required": true,
            "description": "Category segments rendered left to right in the given order.",
            "source": {
              "path": "packages/design-system/src/components/visualizations/types.ts",
              "line": 73
            }
          },
          {
            "name": "ariaLabel",
            "type": "string | undefined",
            "declared_type": "string",
            "required": false,
            "description": "Accessible label for meaningful chart content.",
            "source": {
              "path": "packages/design-system/src/components/visualizations/types.ts",
              "line": 75
            }
          },
          {
            "name": "testId",
            "type": "string | undefined",
            "declared_type": "string",
            "required": false,
            "description": "Optional test selector.",
            "source": {
              "path": "packages/design-system/src/components/visualizations/types.ts",
              "line": 77
            }
          }
        ],
        "branches": [],
        "constraints": [],
        "extraction_status": "extracted"
      }
    ],
    "type_sources": [
      {
        "path": "packages/design-system/src/components/visualizations/types.ts",
        "line": 46,
        "name": "CategoryDatum",
        "code": "export interface CategoryDatum {\n    /** Stable category identifier. */\n    id: string;\n    label: React.ReactNode;\n    /** Non-negative category count or magnitude. */\n    value: number;\n    color?: string;\n}"
      },
      {
        "path": "packages/design-system/src/components/visualizations/types.ts",
        "line": 71,
        "name": "CompositionBarProps",
        "code": "export interface CompositionBarProps {\n    /** Category segments rendered left to right in the given order. */\n    items: readonly CategoryDatum[];\n    /** Accessible label for meaningful chart content. */\n    ariaLabel?: string;\n    /** Optional test selector. */\n    testId?: string;\n}"
      }
    ],
    "defaults_policy": "Only explicit destructured parameter initializers are extracted. Other runtime defaults remain in implementation source."
  },
  "spec": {
    "$schema": "../../../specs/component-spec.schema.json",
    "identity": {
      "name": "CompositionBar",
      "status": "preview",
      "version": "1.0.0",
      "summary": "A single horizontal bar split into proportional, color-coded segments — each category's share of the total, the composition read for open-ended counts with no fixed maximum."
    },
    "parts": [
      {
        "id": "bar",
        "label": "Bar",
        "description": "The full-width pill track that holds the segments.",
        "required": true
      },
      {
        "id": "segment",
        "label": "Segment",
        "description": "A colored slice whose width is one category's share of the total."
      }
    ],
    "allowedDesignChoices": {
      "variants": {
        "base": {
          "label": "Base",
          "description": "Category data changes the segment widths and colors without changing the bar treatment."
        }
      },
      "sizes": {}
    },
    "variants": [
      {
        "id": "base",
        "label": "Base",
        "description": "One pill bar of proportional category segments.",
        "platforms": [
          "ios",
          "android",
          "web"
        ]
      }
    ],
    "sizes": [],
    "measurements": [
      {
        "id": "bar-height",
        "label": "Bar height",
        "kind": "exact",
        "token": "--cds-size-16",
        "value": 16,
        "unit": "px",
        "appliesTo": [
          "bar"
        ]
      }
    ],
    "layout": {
      "alignment": "Segments sit flush in a single row, each sized to its share of the total.",
      "flow": "Segments render left to right in the order given.",
      "notes": [
        "The bar is a full-width pill (`--cds-radius-full`) that clips its segments to rounded ends.",
        "Segment widths are shares of the summed whole, not of the largest value.",
        "Zero-value categories are dropped so no invisible slivers accumulate."
      ]
    },
    "typographyAndColor": {
      "typography": [],
      "colors": [
        {
          "label": "Segment",
          "description": "Each segment uses its own `item.color` — canonically one of the PII category tokens (`PII_CATEGORY_COLOR_VARS`), one per category — or cycles the default category palette when none is given.",
          "token": "--cds-pii-category-name"
        }
      ]
    },
    "states": [
      {
        "id": "composition",
        "label": "Composition",
        "description": "Segments render in order, each sized to its share of the total."
      },
      {
        "id": "default-palette",
        "label": "Default palette",
        "description": "Segments without a color cycle the built-in category palette."
      },
      {
        "id": "empty",
        "label": "Empty",
        "description": "A zero total renders nothing, so pair with an upstream empty state."
      }
    ],
    "behavior": [
      {
        "label": "Share of the whole",
        "description": "Segment width is each value divided by the sum, so the bar always fills and never implies a fixed maximum."
      },
      {
        "label": "Palette fallback",
        "description": "Segments take their own color, or cycle the default category palette when none is given."
      },
      {
        "label": "Drops empty slices",
        "description": "Categories at or below zero are omitted rather than rendered as invisible segments."
      }
    ],
    "accessibility": [
      {
        "label": "Meaningful chart",
        "description": "Pass an accessible label so the bar is announced as a meaningful image."
      },
      {
        "label": "Pair with a legend",
        "description": "The bar shows proportion only; surface category labels and exact counts in an adjacent legend."
      }
    ],
    "contentAdaptation": [
      {
        "label": "Open-ended counts",
        "description": "Use CompositionBar when a running total has no goal or maximum and the reader needs the mix, not exact magnitudes."
      },
      {
        "label": "Read the numbers",
        "description": "Use CategoryBars instead when the reader must compare exact category magnitudes side by side."
      }
    ],
    "motionHaptics": {
      "motion": [
        {
          "label": "No intrinsic motion",
          "description": "Segments do not animate on mount; a parent may transition the whole bar."
        }
      ],
      "haptics": [
        {
          "label": "No feedback",
          "description": "The chart is a display and requests no haptic feedback."
        }
      ]
    },
    "platformDifferences": []
  },
  "platforms": {
    "implemented": [
      "web"
    ],
    "native": "Imported design guidance only; no native implementation or parity verification in this preview.",
    "react": {
      "implementation": "local",
      "status": "preview",
      "parity": "web-reference"
    },
    "vue": {
      "implementation": "absent",
      "parity": "not-verified",
      "status": "reference-only"
    },
    "swift": {
      "implementation": "absent",
      "parity": "not-verified",
      "status": "reference-only"
    },
    "kotlin": {
      "implementation": "absent",
      "parity": "not-verified",
      "status": "reference-only"
    }
  },
  "tokens": [
    {
      "name": "--cds-size-16",
      "light": "16px",
      "dark": "16px"
    },
    {
      "name": "--cds-radius-full",
      "light": "9999px",
      "dark": "9999px"
    },
    {
      "name": "--cds-pii-category-name",
      "light": "#00c876",
      "dark": "#00c876"
    }
  ],
  "review": {
    "local_status": "not-reviewed",
    "source_approval": null,
    "imported_spec_status": "approved",
    "spec_origin": "imported-adapted",
    "local_spec_source_status": "approved",
    "imported_source_revision": "f96f416e1c3bfbfaffcd155a88b87b18b8bb25f1",
    "note": "Inherited specification status is provenance, not approval of the current local implementation or extracted contract."
  },
  "missing_facts": [
    {
      "code": "human-review-pending",
      "detail": "This local preview has no recorded human design or engineering sign-off."
    },
    {
      "code": "platform-parity-unverified",
      "detail": "Vue, Swift and Kotlin implementations are absent from this package; platform parity has not been verified."
    },
    {
      "code": "figma-mapping-unverified",
      "detail": "No current component-level Figma node and immutable revision have been verified for this contract."
    }
  ]
}
```

## Visual states

- [Default](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--default&viewMode=story) | export: Default | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

- [Clustered](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--clustered&viewMode=story) | export: Clustered | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

- [One Dominant](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--one-dominant&viewMode=story) | export: OneDominant | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

- [Default Palette](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--default-palette&viewMode=story) | export: DefaultPalette | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

- [Empty](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--empty&viewMode=story) | export: Empty | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

- [Dark Theme](/storybook/iframe.html?id=cloaked-design-system-visualizations-compositionbar--dark-theme&viewMode=story) | export: DarkTheme | source: packages/design-system/src/components/visualizations/CompositionBar/CompositionBar.stories.tsx

Preview pending human sign-off. Source-derived APIs and successful checks do not certify accessibility, native parity or approval.
