Rokkit 1.0.0-next.134

Composability

Extend and customize any component via Svelte snippets without forking

Composability

Every Rokkit component exposes named snippet slots. Pass a snippet to replace any part of the component's rendering — item content, group headers, empty states — without forking the component or fighting with CSS overrides.

Overview

Svelte 5 snippets are the clean equivalent of render props or slot content. They keep your customization logic co-located with your usage, not inside the library.

Snippets & Customization

Svelte snippets give you full control over how each item renders — without wrapping components or forking source code. The component handles data logic, keyboard navigation, and ARIA; you control the pixels.

Item Snippets

Every collection component accepts an itemContent snippet that receives a ProxyItem. Use proxy.label, proxy.icon, and proxy.get('field') to access mapped values:

svelte
Highlighting code...

The ProxyItem API

Snippets receive a ProxyItem instance that provides a unified interface to the underlying data, regardless of whether it's an object or a primitive:

Property / MethodReturnsDescription
proxy.labelstringMapped display text
proxy.iconstringMapped icon class
proxy.hrefstringMapped href (renders as <a>)
proxy.valueanyThe original raw item
proxy.disabledbooleanWhether the item is disabled
proxy.expandedbooleanExpand state for groups
proxy.get('field')anyRead any field by name

Per-Item Snippets

Set item.snippet = 'name' to route specific items to named snippets. Items without a snippet field use the default itemContent snippet:

svelte
Highlighting code...

Group Snippets

For nested data, use groupContent to customize how group headers render:

svelte
Highlighting code...

Per-Item Components

Map a component field to render entirely different Svelte components for different items:

svelte
Highlighting code...

Interactive Snippets

Snippets support full Svelte reactivity. Embed checkboxes, toggles, or inputs inside list items. Use e.stopPropagation() on the control's click to prevent the List from also triggering item selection:

svelte
Highlighting code...