compose-slot-api-pattern
Installation
SKILL.md
Compose: slot API pattern
Core principle
A reusable Compose component describes layout structure. Callers provide variable visual content through slots.
API review procedure
- Confirm the component is reusable. For a true single-use composable, do not add slot ceremony.
- Mark which regions vary by caller: headline, supporting text, leading visual, trailing visual, actions, body.
- Replace caller-controlled primitive content and shape flags with slots.
- Add receiver scopes only when the slot is emitted inside a layout whose scope APIs callers should use.
- Make absent optional regions nullable (
null), so the component can omit their containers and spacing. - Put repeated default content or tokens in
XxxDefaults. - Pair this with the
modifierrules incompose-modifier-and-layout-style.
1. Replace primitive content with @Composable slots
Where the component asks for caller-controlled content, prefer a @Composable () -> Unit slot. Where the slot is structurally required, leave it non-nullable with no default. Where it's optional, make it nullable with a null default.