# Slot-Based Composition

## Objective

Let components take content in named positions instead of accumulating a prop per element.

Named content positions on layout-shaped components, with defaults, validation, and an accessible source order.

## 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. Find the components that have grown a prop for every possible piece of content — icon, title, subtitle, badge, action, footer — and replace that accumulation with a small set of named positions.
2. Name each position for its role in the layout rather than for what is typically put in it, so a position remains truthful when a caller puts something unexpected there.
3. Give each position a sensible default or a defined empty behaviour, so an omitted position collapses cleanly instead of leaving a gap, a stray separator, or a border around nothing.
4. Keep the source order of the rendered output meaningful even where visual order differs, so keyboard and screen reader users encounter the content in a sequence that makes sense.
5. Do not implement positions by matching on child type, position in the child list, or a class name applied by the caller. Those break as soon as content is wrapped or conditionally rendered, and they give a caller no way to find out what went wrong.

## 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

- Required and mutually exclusive positions must be validated. A component with no content in its required position, or with two positions filled that were never meant to appear together, should say so at development time rather than rendering something misaligned.
- Visual order and source order can diverge once positions are laid out with a grid or reordered for a breakpoint, and when they do the keyboard tab sequence stops matching what is on screen. Keep the accessible order deliberate rather than letting the layout decide it.
- Every position needs a defined behaviour when it is empty. Reserving space for an absent icon, or drawing a separator above a footer nobody supplied, is the usual result of leaving it unspecified.
- Selecting content by child type or list position is brittle: wrapping one item in a conditional, a fragment, or a caller's own component silently drops it into the wrong place or out of the render entirely. Positions must be addressed by name.
- Content placed in a position must not be able to break the component's own layout — an over-long title, a tall image, a translated label at three times the English length — so each position needs its own constraints for wrapping, truncation, and maximum size.
- Nesting a component inside one of its own positions must resolve unambiguously, so an inner card's footer is not styled by the outer card's rules.
- The set of positions is part of the component's contract, so removing or renaming one is a breaking change and needs treating as such.

## 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

- [ ] Layout-shaped components accept content by named position rather than through a prop per element.
- [ ] Positions are addressed by name, with no matching on child type, index, or class name.
- [ ] Missing required positions and mutually exclusive combinations raise development-time errors.
- [ ] An omitted position collapses cleanly, with no reserved space, stray separator, or empty border.
- [ ] Source order remains meaningful for keyboard and screen reader users at every breakpoint.
- [ ] Over-long or over-tall content in a position is constrained rather than breaking the component's layout.
- [ ] The prop-per-element accumulation on the affected components has been removed.
- [ ] 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.
