Sheet for Astro
Astro side panels for secondary tasks and compact navigation.
Installation
bunx --bun shadcn@latest add @gnostic/sheetnpx shadcn@latest add @gnostic/sheetpnpm dlx shadcn@latest add @gnostic/sheetComponent classes: Default Gnostic.
Complete the Installation guide first. Then copy the component files below.
Install component packages
bun add @data-slot/dialogCopy the files
src/components/ui/sheet/index.ts
export { default as Sheet } from './sheet.astro'
export { default as SheetContent } from './sheet-content.astro'
export { default as SheetTrigger } from './sheet-trigger.astro'
export { default as SheetHeader } from './sheet-header.astro'
export { default as SheetTitle } from './sheet-title.astro'
export { default as SheetDescription } from './sheet-description.astro'
export { default as SheetFooter } from './sheet-footer.astro'
export { default as SheetClose } from './sheet-close.astro'
export type { SheetProps, SheetContentProps } from './types.ts'
src/components/ui/sheet/sheet-close.astro
---
import type { HTMLTag, Polymorphic } from "astro/types"
import { Button } from "../button/index.ts"
import type { ButtonVariantProps } from "../button/button-variants.ts"
type Props<Tag extends HTMLTag = "button"> = Polymorphic<{ as: Tag }> & ButtonVariantProps
const { ...props } = Astro.props
---
<Button data-slot="dialog-close" {...props}>
<slot />
</Button>
src/components/ui/sheet/sheet-content.astro
---
import type { HTMLAttributes } from "astro/types"
import XIcon from "@lucide/astro/icons/x"
import { cn } from "cn"
import { Button } from "../button/index.ts"
import DialogPortal from "../dialog/dialog-portal.astro"
import type { SheetContentProps } from "./types.ts"
type Props = HTMLAttributes<"div"> & SheetContentProps
const {
class: className,
side = "right",
showCloseButton = true,
style,
...props
} = Astro.props
---
<DialogPortal>
<div
data-slot="dialog-overlay"
data-sheet
hidden
class="fixed inset-0 z-50 bg-black/32 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 backdrop-blur-sm"
style="z-index: calc(var(--dialog-overlay-stack-index, 0) * 2 + 100);"
></div>
<div
data-slot="dialog-content"
data-sheet
data-side={side}
hidden
class={cn("bg-popover text-popover-foreground fixed z-50 flex flex-col gap-4 not-dark:bg-clip-padding text-sm shadow-lg/5 before:pointer-events-none before:absolute before:inset-0 before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] transition duration-200 ease-in-out outline-none data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-10 data-[side=bottom]:data-starting-style:translate-y-10 data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:-translate-x-10 data-[side=left]:data-starting-style:-translate-x-10 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-10 data-[side=right]:data-starting-style:translate-x-10 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:-translate-y-10 data-[side=top]:data-starting-style:-translate-y-10 data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm", className)}
style={`z-index: calc(var(--dialog-content-stack-index, 0) * 2 + 101);${style ? ` ${style}` : ""}`}
{...props}
>
<slot />
{showCloseButton && (
<Button
type="button"
data-slot="dialog-close"
data-sheet
variant="ghost"
size="icon-sm"
class="absolute top-4 right-4"
>
<XIcon />
<span class="sr-only">Close</span>
</Button>
)}
</div>
</DialogPortal>
src/components/ui/sheet/sheet-description.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"p">
const { class: className, ...props } = Astro.props
---
<p
data-slot="dialog-description"
data-sheet
class={cn("text-muted-foreground text-sm", className)}
{...props}
>
<slot />
</p>
src/components/ui/sheet/sheet-footer.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div
data-slot="sheet-footer"
class={cn("mt-auto flex flex-col gap-2 p-4", className)}
{...props}
>
<slot />
</div>
src/components/ui/sheet/sheet-header.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div">
const { class: className, ...props } = Astro.props
---
<div
data-slot="sheet-header"
class={cn("flex flex-col gap-1.5 p-4", className)}
{...props}
>
<slot />
</div>
src/components/ui/sheet/sheet-title.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"h2">
const { class: className, ...props } = Astro.props
---
<h2
data-slot="dialog-title"
data-sheet
class={cn("font-heading font-semibold text-xl leading-none", className)}
{...props}
>
<slot />
</h2>
src/components/ui/sheet/sheet-trigger.astro
---
import type { ComponentProps } from "astro/types"
import { Button } from "../button/index.ts"
type Props = ComponentProps<typeof Button>
const { ...props } = Astro.props
---
<Button data-slot="dialog-trigger" {...props}>
<slot />
</Button>
src/components/ui/sheet/sheet.astro
---
import type { HTMLAttributes } from "astro/types"
import type { SheetProps } from "./types.ts"
type Props = HTMLAttributes<"div"> & SheetProps
const {
class: className,
defaultOpen,
closeOnClickOutside,
closeOnEscape,
lockScroll,
...props
} = Astro.props
---
<div
data-slot="dialog"
class={className}
data-default-open={defaultOpen}
data-close-on-click-outside={closeOnClickOutside}
data-close-on-escape={closeOnEscape}
data-lock-scroll={lockScroll}
{...props}
>
<slot />
</div>
<script>
import { create } from "@data-slot/dialog"
import type { DialogController as SheetController } from "@data-slot/dialog"
// Destroy bindings before a view transition so the next page-load binds once.
const controllers: SheetController[] = []
const initialize = () => controllers.push(...create())
initialize()
document.addEventListener("astro:page-load", initialize)
document.addEventListener("astro:before-swap", () => {
for (const controller of controllers) controller.destroy()
controllers.length = 0
})
</script>
src/components/ui/sheet/types.ts
import type { DialogOptions } from '@data-slot/dialog'
/**
* Sheet configuration rendered as data attributes.
* A sheet uses the dialog controller. `alertDialog` stays on Alert Dialog.
*/
export type SheetProps = Pick<
DialogOptions,
'defaultOpen' | 'closeOnClickOutside' | 'closeOnEscape' | 'lockScroll'
>
/** Edge and close control for the sheet panel. */
export type SheetContentProps = {
/**
* Screen edge the sheet slides in from.
*
* @default "right"
*/
side?: 'top' | 'right' | 'bottom' | 'left'
/**
* Show the close button.
*
* @default true
*/
showCloseButton?: boolean
}
Usage
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet"
<Sheet>
<SheetTrigger>Open</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Sheet Title</SheetTitle>
<SheetDescription>Sheet Description</SheetDescription>
</SheetHeader>
<SheetFooter>
<SheetClose variant="outline">Close</SheetClose>
<Button>Save</Button>
</SheetFooter>
</SheetContent>
</Sheet>
Composition
Arrange the parts as shown for a Sheet:
Sheet
├── SheetTrigger
└── SheetContent
├── SheetHeader
│ ├── SheetTitle
│ └── SheetDescription
└── SheetFooter
Examples
Sides
API Reference
SheetProps
defaultOpen?boolean
Initial open state
booleancloseOnClickOutside?boolean
Close when clicking overlay
booleancloseOnEscape?boolean
Close when pressing Escape
booleanlockScroll?boolean
Lock body scroll when open
booleanSheetContentProps
side?'top' | 'right' | 'bottom' | 'left'
Screen edge the sheet slides in from.
'top' | 'right' | 'bottom' | 'left'"right"showCloseButton?boolean
Show the close button.
booleantrueSee the data-slot docs for more information on interactivity.
Read the installed source for the complete prop types.
When to use Sheet
Choose a side for SheetContent and compose its title, body, and controls. Use a sheet when the task benefits from an edge panel, such as a filter form or mobile navigation.
Keyboard and behavior
Sheet uses the existing dialog controller for modal behavior. Keep a named close control and test focus return to the trigger. Navigation links inside it still need normal href values.
Theme and layout
The panel shares dialog colors and borders. Check wide content on a narrow screen and give a long body a deliberate scroll region. Side changes affect animation and layout, not application state.