Sheet
Extends the Dialog component to display content that complements the main content of the screen.
package showcase
import (
"github.com/templui/templui/components/button"
"github.com/templui/templui/components/input"
"github.com/templui/templui/components/label"
"github.com/templui/templui/components/sheet"
)
templ SheetDefault() {
@sheet.Sheet(sheet.Props{
Side: sheet.SideRight,
}) {
@sheet.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
}) {
Open
}
}
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
Edit profile
}
@sheet.Description() {
Make changes to your profile here. Click save when you're done.
}
}
<div class="grid flex-1 auto-rows-min gap-6 px-4">
<div class="grid gap-3">
@label.Label(label.Props{
For: "sheet-demo-name",
}) {
Name
}
@input.Input(input.Props{
ID: "sheet-demo-name",
Type: input.TypeText,
Value: "Pedro Duarte",
})
</div>
<div class="grid gap-3">
@label.Label(label.Props{
For: "sheet-demo-username",
}) {
Username
}
@input.Input(input.Props{
ID: "sheet-demo-username",
Type: input.TypeText,
Value: "@peduarte",
})
</div>
</div>
@sheet.Footer() {
@button.Button(button.Props{
Type: "submit",
}) {
Save changes
}
@sheet.Close() {
@button.Button(button.Props{
Variant: button.VariantOutline,
}) {
Close
}
}
}
}
}
}
Examples
Sheet Sides
package showcase
import (
"github.com/templui/templui/components/button"
"github.com/templui/templui/components/sheet"
)
templ SheetSides() {
<div class="grid grid-cols-2 gap-4">
// Top Sheet
@sheet.Sheet(sheet.Props{
Side: sheet.SideTop,
}) {
@sheet.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
Class: "w-full",
}) {
Open from Top
}
}
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
Top Sheet
}
@sheet.Description() {
This slides in from the top.
}
}
<div class="px-4 py-6">
<p class="text-sm">Content for the top sheet.</p>
</div>
@sheet.Footer() {
@sheet.Close() {
@button.Button() {
Close
}
}
}
}
}
// Right Sheet
@sheet.Sheet(sheet.Props{
Side: sheet.SideRight,
}) {
@sheet.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
Class: "w-full",
}) {
Open from Right
}
}
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
Right Sheet
}
@sheet.Description() {
This slides in from the right.
}
}
<div class="px-4 py-6">
<p class="text-sm">Content for the right sheet.</p>
</div>
@sheet.Footer() {
@sheet.Close() {
@button.Button() {
Close
}
}
}
}
}
// Bottom Sheet
@sheet.Sheet(sheet.Props{
Side: sheet.SideBottom,
}) {
@sheet.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
Class: "w-full",
}) {
Open from Bottom
}
}
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
Bottom Sheet
}
@sheet.Description() {
This slides in from the bottom.
}
}
<div class="px-4 py-6">
<p class="text-sm">Content for the bottom sheet.</p>
</div>
@sheet.Footer() {
@sheet.Close() {
@button.Button() {
Close
}
}
}
}
}
// Left Sheet
@sheet.Sheet(sheet.Props{
Side: sheet.SideLeft,
}) {
@sheet.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
Class: "w-full",
}) {
Open from Left
}
}
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
Left Sheet
}
@sheet.Description() {
This slides in from the left.
}
}
<div class="px-4 py-6">
<p class="text-sm">Content for the left sheet.</p>
</div>
@sheet.Footer() {
@sheet.Close() {
@button.Button() {
Close
}
}
}
}
}
</div>
}
External Trigger
package showcase
import (
"github.com/templui/templui/components/button"
"github.com/templui/templui/components/sheet"
)
templ SheetExternalTrigger() {
// Sheet with content but no internal trigger
@sheet.Sheet(sheet.Props{
ID: "external-trigger-demo",
Side: sheet.SideRight,
}) {
// No trigger inside - will be triggered externally
@sheet.Content() {
@sheet.Header() {
@sheet.Title() {
External Trigger
}
@sheet.Description() {
This sheet has no internal trigger
}
}
<div class="flex-1 p-4">
<p class="text-sm text-muted-foreground">
The trigger button exists outside the Sheet component.
</p>
</div>
@sheet.Footer() {
@sheet.Close() {
@button.Button(button.Props{
Variant: button.VariantOutline,
}) {
Close
}
}
}
}
}
// External trigger outside of Sheet component
@sheet.Trigger(sheet.TriggerProps{
For: "external-trigger-demo",
}) {
@button.Button(button.Props{
Variant: button.VariantOutline,
}) {
Open Sheet
}
}
}
Installation
templui add sheetLoad the script once in your layout:
<head>
@sheet.Script()
</head>import "github.com/templui/templui/components/sheet"Load the script once in your layout:
<head>
@sheet.Script()
</head>API Reference
Sheet
| Name | Type | Default |
|---|---|---|
Optional HTML id for the sheet root. Useful for external targeting. | | |
Additional CSS classes to apply to the sheet wrapper | | |
Additional HTML attributes to apply to the sheet wrapper | | |
Side from which the sheet slides in (top, right, bottom, left) | | |
Whether the sheet should be open initially | | |
Disable closing the sheet when clicking the backdrop | | |
Disable closing the sheet with the ESC key | | |
Trigger
| Name | Type | Default |
|---|---|---|
Unique identifier for the trigger element | | |
Additional CSS classes to apply to the trigger | | |
Additional HTML attributes to apply to the trigger | | |
Optional sheet root id for external triggers outside Sheet wrapper | | |
Content
| Name | Type | Default |
|---|---|---|
Additional CSS classes to apply to the content container | | |
Additional HTML attributes to apply to the content container | | |
Hide the close X button in the top right corner | | |
Side from which the sheet slides in. Usually inherited from Sheet. | | |
Header
| Name | Type | Default |
|---|---|---|
Unique identifier for the header element | | |
Additional CSS classes to apply to the header | | |
Additional HTML attributes to apply to the header | | |
Title
| Name | Type | Default |
|---|---|---|
Unique identifier for the title element | | |
Additional CSS classes to apply to the title | | |
Additional HTML attributes to apply to the title | | |
Description
| Name | Type | Default |
|---|---|---|
Unique identifier for the description element | | |
Additional CSS classes to apply to the description | | |
Additional HTML attributes to apply to the description | | |
Close
| Name | Type | Default |
|---|---|---|
Unique identifier for the close button | | |
Additional CSS classes to apply to the close button | | |
Additional HTML attributes to apply to the close button | | |