Design Systems and Component APIs
A design system is not just a folder of styled components. It is a set of stable product-independent contracts for semantics, interaction, accessibility, visual language, and composition.
Start with semantics
function Button(props) {
return <button {...props} />;
}
A role can change semantics; it does not recreate all native behavior for you.
Keep variant contracts intentional
type ButtonProps = {
variant?: 'primary' | 'secondary' | 'danger';
size?: 'sm' | 'md' | 'lg';
};
Avoid boolean matrices such as primary, danger, outlined, blue, and large when those combinations do not form a coherent public contract.
Reuse native DOM contracts
type ButtonProps = React.ComponentPropsWithoutRef<'button'> & {
variant?: 'primary' | 'secondary';
};
This preserves native disabled, type, aria-*, event, form, and data-attribute behavior.
React 19 also supports receiving ref as a normal prop in function components:
type InputProps = React.ComponentPropsWithoutRef<'input'> & {
ref?: React.Ref<HTMLInputElement>;
};
function Input({ ref, ...props }: InputProps) {
return <input ref={ref} {...props} />;
}
Composition beats configuration when structure varies
<Card>
<Card.Header>
<Card.Title>Revenue</Card.Title>
<Card.Description>Last 30 days</Card.Description>
</Card.Header>
<Card.Content><RevenueChart /></Card.Content>
<Card.Footer>Updated now</Card.Footer>
</Card>
Use configuration for genuinely fixed structure. Use composition when callers need meaningful structural freedom.
Compound components coordinate one interaction model
The design system owns keyboard behavior, focus management, selected state, and ARIA relationships. Product code owns the content.
Keep internal provider values private when possible; consumers should depend on the documented component API.
Controlled and uncontrolled ownership
<Dialog open={open} onOpenChange={setOpen} />
<Dialog defaultOpen />
Do not switch ownership modes accidentally during the same component lifetime.
Events should match the abstraction level
A Select consumer often cares that the selected value changed, not which DOM event produced it.
Prop merging is part of correctness
Do not swallow consumer handlers:
function Button({ onClick, ...props }) {
function handleClick(event) {
trackClick();
onClick?.(event);
}
return <button {...props} onClick={handleClick} />;
}
Also decide deliberately how className, style, IDs, ARIA props, and event cancellation are merged. The order of prop spreading can change the public contract.
Accessibility belongs in the primitive contract
Types can enforce props; they cannot by themselves guarantee keyboard semantics or focus behavior.
Keep product state out of the design system
A generic Dialog is infrastructure. EnterpriseBillingCancellationDialog is usually product behavior and should remain in the feature layer.
Headless vs styled APIs
Headless primitives can expose robust behavior while leaving visual composition to a product or design layer. Styled primitives can encode visual policy directly.
Design-system change lifecycle
A good design-system API is hard to misuse, easy to compose, accessible by default, and stable enough that many teams can depend on it without freezing its internals forever.