compose-slot-api-pattern

Designs reusable Jetpack Compose components using composable slot APIs instead of primitive content parameters.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill compose-slot-api-pattern-w0lzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-slot-api-pattern
Source: https://github.com/w0lzard/Wolzard-s-Marketplace/tree/main/plugins/personal-skills/skills/compose-slot-api-pattern
Command: npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill compose-slot-api-pattern-w0lzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Reusable Compose components accumulate primitive content parameters (title: String, leadingIcon: ImageVector?, showSwitch: Boolean) that enumerate call sites instead of describing layout, forcing a signature change every time a new call site needs a different visual shape. ## Core Features & Use Cases - Slot API Conversion: Replaces primitive content parameters and boolean shape flags with @Composable () -> Unit slots following Material 3 conventions like headlineContent and trailingContent. - Scope Receiver Guidance: Applies RowScope/ColumnScope/BoxScope receivers to slots so callers can use layout modifiers like Modifier.weight inside slot content. - Nullable Optional Slots and Defaults Objects: Uses nullable slots with null defaults for absent regions and co-locates common content in XxxDefaults objects. - Use Case: When reviewing a SettingsRow component with title, subtitle, leadingIcon, and showChevron parameters, refactor it into slot-based form so a caller can add a Badge next to the title without editing the component. ## Quick Start Ask the assistant to review this reusable Compose component's signature and refactor its primitive content parameters into slot APIs.

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 design a reusable Jetpack Compose component with flexible content?

Replace primitive content parameters like title: String and leadingIcon: ImageVector with @Composable () -> Unit slots such as headlineContent and leadingContent. The component then owns layout structure while callers supply whatever composables each region needs.

When should a Compose slot use RowScope or BoxScope receivers?

Use a scope receiver when the slot emits into a matching layout container and callers need its modifiers, such as Modifier.weight inside a Row. Declare actions: @Composable RowScope.() -> Unit so callers get the same capabilities as Material's TopAppBar actions slot.

Should optional Compose slots be nullable or default to empty lambdas?

Prefer (@Composable () -> Unit)? = null over an empty lambda default. A null slot lets the component skip the container, spacing, and padding entirely, while an empty lambda still allocates layout space for content that renders nothing.

When should I not use slot APIs in Compose components?

Skip slots for single-use components, design-system primitives that must look identical everywhere, and semantic parameters the component intentionally owns like Switch's checked state. Slot indirection adds reading cost without benefit when there is only one call site.

Is a sealed class better than slots for Compose component variants?

A sealed variant type is bounded and requires editing the component whenever an unanticipated variant appears. Slots are unbounded, so new visual shapes work without touching the component, which is why Material 3 uses slots for ListItem and TopAppBar.