# Component Variant API

## Objective

Give every component one consistent way to express size, tone, emphasis, and state.

A shared variant vocabulary applied across the component set, with stable defaults and impossible combinations refused.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Inventory how the existing components already express difference — a primary flag on one, a kind string on another, a boolean per style on a third — and collapse them onto one vocabulary of size, tone, emphasis, and state.
2. Name variants for their meaning rather than their appearance. A tone called danger survives a redesign; a tone called red does not, and it lies the moment the palette changes or the theme inverts.
3. Give every variant prop a default that produces the most common correct result, so a component rendered with no variant props at all is still valid and typical.
4. Refuse combinations that cannot be rendered coherently, at development time and with a message naming the conflict. A quiet emphasis with a destructive tone and a loading state may have no sensible appearance, and guessing one produces a control nobody designed.
5. Do not add a variant for every one-off design request. Each new value multiplies the combinations that must be checked; if a screen needs something the vocabulary cannot express, that is a design conversation, not a new enum member.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Conflicting variant combinations must be rejected rather than resolved by precedence. Silently letting one variant win produces a control that looks deliberate but was never designed, and the bug surfaces only when someone screenshots it.
- Defaults must be stable across releases. Changing what an unspecified variant means re-styles every call site that relied on the default, and those call sites are exactly the ones nobody reviews.
- Variant names must be semantic, not visual. Names describing colour, weight, or position break as soon as the theme changes, and they read as lies in a dark theme or a high-contrast mode.
- The variant vocabulary must not defeat static typing or dead-code elimination. Values assembled dynamically from strings cannot be checked at build time and force the whole style surface to ship even when a handful of variants are used.
- State variants such as loading, disabled, and invalid must not be settable in ways that contradict the component's actual behaviour — a control styled disabled while remaining clickable is a trap.
- Every tone must remain legible against every surface it can appear on, including inverted panels and the dark theme, otherwise a valid combination produces unreadable text.
- How a variant value varies across breakpoints belongs to Responsive Prop System; this brief owns the set of allowed values and their meaning, and the two must draw on one shared vocabulary.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every component in the set expresses difference through the same variant vocabulary, with no leftover per-component flags.
- [ ] Variant names describe meaning rather than appearance.
- [ ] A component rendered with no variant props produces a valid, typical result.
- [ ] Incoherent variant combinations raise a development-time error naming the conflict.
- [ ] Variant values are statically known, so unused styles are eliminated from the build.
- [ ] Every tone is legible on every surface it can appear on, in both light and dark themes.
- [ ] State variants match the component's real interactive behaviour.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
