Component API Design
The props a component exposes determine whether it gets used correctly or forked, which is the main failure mode of design systems.
Definition
A component's API is the set of properties, slots and events it exposes. It encodes which variations are supported and, by omission, which are not. Getting it wrong produces either rigidity that causes forking or flexibility that dissolves consistency.
Craft convention. True because the industry converged on it. Breaking it costs familiarity, not correctness.
On this plate
Reach for this when
- Designing a shared component.
- Reviewing why teams are not adopting the system.
- Deciding whether to add a variant.
Common mistakes
- Prop explosion from accumulated edge cases.
- Style escape hatches that undermine consistency.
- APIs that allow inaccessible configurations.
- Variants named after their appearance.
Principles
- Prefer composition to configuration. A card with slots beats a card with twenty props.
- Constrain variants to a defined set rather than accepting arbitrary values. variant="primary" not colour="#0055ff".
- Do not expose a style escape hatch by default. Once one exists, it becomes the path of least resistance.
- Make the accessible path the default. If a prop can produce an inaccessible result, reconsider the prop.
- Name props for meaning, not implementation: tone, emphasis, size, rather than colour codes.
- Provide sensible defaults so the common case needs no configuration at all.
Answering a request for flexibility
Most API damage is done one reasonable request at a time. The first answer matters more than the eventual one.
| Request | First answer | Why |
|---|---|---|
| We need this button in purple | Name the meaning instead | Purple is a brand decision, not a property of this button. If the meaning is genuinely new, the variant set is what needs changing. |
| We need one more element inside the card | A slot | Composition absorbs content you did not predict. A prop only absorbs the case in front of you. |
| Ours behaves differently on submit | A callback, not a boolean | Events let the consumer own their workflow without the component learning it. |
| We need to override the padding | Not through a style prop | Density is a system decision. If two densities are legitimate, ship a size. |
| It has to look completely different here | A different component | Two designs sharing only a name are two components. Forcing them together is how prop explosion starts. |
Designing the surface
Do
- Write the call sites for three real usages before writing the component.
- Make invalid combinations impossible to express, so a variant that requires an icon takes that icon as a required prop.
- Keep boolean props independent. Two booleans that can never both be true were always one enum.
- Forward the underlying element's props for cases you did not predict, rather than inventing a pass-through for each one.
Do not
- Do not name a prop after a team, a screen or a release.
- Do not treat an arbitrary class name as the general answer to customisation.
- Do not change behaviour implicitly based on the type of children. Rules that cannot be stated cannot be documented.
- Do not ship a variant whose name does not survive being said out loud to someone outside the team.
Commonly confused with
Close neighbours that get substituted for each other. The difference is stated first, then the condition that picks one over the other.
Component Anatomy, States and Variants
Design systemThe named parts of a component, its states, and why each variant exists.
Key difference
Anatomy and variants describe what a component is and which alternatives exist. The API is how anyone gets at them in code. One is the decision, the other is the surface that exposes it, and a good decision with a bad API still gets forked.
Use Component API Design when
- People are overriding styles or forking to get what they need.
- The question is which variations to support and which to refuse.
- The work touches naming, defaults and breaking changes.
Use Component Anatomy, States and Variants when
- Two teams have built near-duplicates because nothing was written down.
- The question is which states and variants are legitimate.
- The work is documentation and design, before any props are named.
Local chart
SYS·002 · Region VI · Grid C4
This entry and the entries it is stated to connect with. Each line is labelled with what the connection means.
Continue from here
Each link says what the connection is, so you can tell a principle from an alternative from a thing people mix this up with.
Principles behind this
The reasoning this solution is an application of.
- Consistency and StandardsHEUR·004 · Heuristic
Often used with
These usually appear in the same screen or the same decision.
Practical example
A worked decision where this was the deciding factor.
- Migrating Product Teams onto a Design SystemCASE·003 · Case study
Short definition
The one-paragraph version, for when that is all you need.
- Atomic DesignTERM·086 · Term
- ComponentTERM·037 · Term
- Component LibraryTERM·085 · Term
- Container QueryTERM·070 · Term
- Semantic VersioningTERM·090 · Term
Related concept
Connected closely enough to change how you apply this.
- Design System to DocumentationAI·007 · AI workflow
- Contribution ModelsSYS·007 · Design system
- Design System AdoptionSYS·005 · Design system
- Design System DocumentationSYS·003 · Design system
- Design System GovernanceSYS·004 · Design system
- Design TokensSYS·001 · Design system
- ThemingSYS·008 · Design system
- Versioning and DeprecationSYS·006 · Design system
- ContainersFND·041 · UI foundation
- RepetitionFND·010 · UI foundation
- SimilarityFND·005 · UI foundation
- Visual StatesFND·053 · UI foundation