shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Collapsible

An interactive component which expands/collapses a panel.

Order #4189

Status Shipped
package examples import (

Installation

shadcn-templ add collapsible

Usage

import "github.com/axadrn/shadcn-templ/v2/components/collapsible"
@collapsible.Collapsible() {	@button.Button(button.Props{Attributes: collapsible.Trigger(ctx)}) {		Can I use this in my project?	}	@collapsible.Content() {		Yes. Free to use for personal and commercial projects. No attribution required.	}}

Composition

Use the following composition to build a Collapsible:

collapsible.Collapsible├── collapsible.Trigger└── collapsible.Content

Open State

Use the Open prop to render the collapsible expanded initially.

@collapsible.Collapsible(collapsible.Props{Open: true}) {	@button.Button(button.Props{Attributes: collapsible.Trigger(ctx)}) {		Toggle	}	@collapsible.Content() {		Content	}}

Basic

package examples import (

Settings Panel

Use a trigger button to reveal additional settings.

Radius
Set the corner radius of the element.
package examples import (

File Tree

Use nested collapsibles to build a file tree.

package examples import (

API Reference

Collapsible

The Collapsible component is the root that manages the open state and links trigger and content.

Prop Type Default
Open bool false
Class string -

Trigger

collapsible.Trigger(ctx) returns the attributes that turn any element into the trigger, usually spread onto a Button. The trigger carries data-panel-open while the panel is open.

Prop Type Default
ctx context.Context -

Content

The collapsible.Content component holds the content revealed by the trigger.

Prop Type Default
Class string -