compose-slot-api-pattern

Refactors Jetpack Compose components to replace primitive parameters with slot-based @Composable () -> Unit content delegates.

1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/leogallego/ansible-jane --skill compose-slot-api-pattern-leogallego
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-slot-api-pattern
Source: https://github.com/leogallego/ansible-jane/tree/main/skills/compose-slot-api-pattern
Command: npx skills add https://github.com/leogallego/ansible-jane --skill compose-slot-api-pattern-leogallego

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Replacing fixed, primitive parameters with flexible content slots lets a UI component describe structure and delegate content to callers, enabling reuse across different layouts and visual shapes.

Core Features & Use Cases

  • Convert hard-coded content props into @Composable () -> Unit slots (headlineContent, supportingContent, leadingContent, trailingContent) to ensure components remain layout-focused.
  • Support nullable optional slots to omit space and padding when content is absent.
  • Provide scope receivers when slots render inside a specific layout (e.g., @Composable RowScope.() -> Unit) to unlock layout helpers like weight.
  • Use a shared XxxDefaults object to centralize common defaults for consistent theming.
  • Use cases include building list items, top bars, or any reusable composite that must adapt its internal content without changing API.

Quick Start

Refactor a reusable Compose component to expose slot-based content through @Composable () -> Unit parameters and update call sites to provide content blocks.

Frequently Asked Questions about compose-slot-api-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a Jetpack Compose component reusable with flexible content?

To make a Jetpack Compose component reusable, replace primitive content parameters with flexible slot-based content using @Composable () -> Unit parameters like headlineContent or leadingContent to delegate visuals to callers.

What are slot APIs in Jetpack Compose and when should I use them?

Slot APIs in Jetpack Compose are parameters defined as @Composable () -> Unit that let a component describe structure while delegating content to callers, used when a UI composite must adapt across multiple layouts without changing its API.

How do I omit optional content in a Compose slot API without breaking the layout?

To omit optional content in a Compose slot API without breaking layout, define slots as nullable parameters like @Composable (() -> Unit)? so callers can pass null, allowing the component to skip space and padding when content is absent.

Can I use RowScope in Compose slot APIs to apply layout modifiers like weight?

Yes, you can provide scope receivers in Compose slot APIs by defining slots as @Composable RowScope.() -> Unit, unlocking layout helpers like weight to let callers control how their supplied content blocks render inside the specific layout.

What is the best way to centralize defaults for a Material3 Compose component?

The best way to centralize defaults for a Material3 Compose component is using a shared XxxDefaults object, ensuring consistent theming and spacing across all call sites when applying slot-based content parameters.

Why should I refactor a Compose component to replace primitive parameters with slots?

Refactoring a Compose component to replace primitive parameters with slots ensures the component remains layout-focused, enabling flexible reuse across different visual shapes and layouts without requiring API changes at the call sites.