3059c6cc77
Co-authored-by: Copilot <copilot@github.com>
1.5 KiB
1.5 KiB
Component API Design Guidelines
Use this when creating or evolving components so the API remains predictable.
Goals
- Consistency across all components
- Safe defaults for user content
- Low ceremony for common use cases
- Explicit escape hatches for advanced scenarios
Baseline API Conventions
For every new component, prefer:
classNamefor caller-supplied Tailwind/CSS classesattributesfor arbitrary HTML attributes (aria-*,data-*, test IDs)- Strongly typed semantic options where practical (enums or constants)
- Named item records instead of tuples for complex lists
Safety Rules
- Plain text input should be encoded by default.
- Raw HTML should require an explicit trusted path.
- Never require callers to manually concatenate unsafe attribute strings for normal usage.
Documentation Rules
Every component doc should include:
- Quick example
- All options
- Security notes
- Accessibility notes
- JS dependency notes (if interactive)
- Extension points (
className,attributes)
Evolution Rules
- Prefer additive changes first.
- Mark old APIs as deprecated with migration examples.
- Remove deprecated paths only in major release.
Review Checklist
- Is the API consistent with sibling components?
- Can callers add classes without wrapper divs?
- Can callers pass
aria-*anddata-*safely? - Are semantic options type-safe?
- Are user-provided strings encoded by default?
- Are interactive JS requirements documented?