Sheet
Extends the Dialog component to display content that complements the main content of the screen.
import { Button } from "~/components/ui/button"
import { Input } from "~/components/ui/input"
import { Label } from "~/components/ui/label"
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger
} from "~/components/ui/sheet"
export default function SheetDemo() {
return (
<Sheet>
<SheetTrigger
render={(partProps) => <Button {...partProps} variant="outline" />}
>
Open
</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Edit profile</SheetTitle>
<SheetDescription>
Make changes to your profile here. Click save when you're done.
</SheetDescription>
</SheetHeader>
<div class="grid flex-1 auto-rows-min gap-6 px-4">
<div class="grid gap-3">
<Label for="sheet-demo-name">Name</Label>
<Input id="sheet-demo-name" value="Pedro Duarte" />
</div>
<div class="grid gap-3">
<Label for="sheet-demo-username">Username</Label>
<Input id="sheet-demo-username" value="@peduarte" />
</div>
</div>
<SheetFooter>
<Button type="submit">Save changes</Button>
<SheetClose
render={(partProps) => <Button {...partProps} variant="outline" />}
>
Close
</SheetClose>
</SheetFooter>
</SheetContent>
</Sheet>
)
}Installation
Install the following dependencies:
Install the required Solid UI dependencies:
Copy and paste the following code into your project.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { type ComponentProps } from "@solidjs/web"
import {
Dialog as SdkDialog,
DialogTrigger as SdkDialogTrigger,
DialogClose as SdkDialogClose,
DialogBackdrop as SdkDialogBackdrop,
DialogContent as SdkDialogContent,
DialogTitle as SdkDialogTitle,
DialogDescription as SdkDialogDescription
} from "@ui-sdk/solid/dialog"
import { merge, omit, Show, type Component } from "solid-js"
import { cn } from "~/lib/utils"
import { Button } from "~/components/ui/button"
type SheetProps = ComponentProps<typeof SdkDialog>
const Sheet: Component<SheetProps> = (props) => <SdkDialog {...props} />
type SheetTriggerProps = Omit<
ComponentProps<typeof SdkDialogTrigger>,
"class"
> & {
class?: string
}
const SheetTrigger = (props: SheetTriggerProps) => (
<SdkDialogTrigger {...props} />
)
type SheetCloseProps = Omit<ComponentProps<typeof SdkDialogClose>, "class"> & {
class?: string
}
const SheetClose = (props: SheetCloseProps) => <SdkDialogClose {...props} />
type SheetOverlayProps = Omit<
ComponentProps<typeof SdkDialogBackdrop>,
"class"
> & {
class?: string
}
const SheetOverlay = (props: SheetOverlayProps) => (
<SdkDialogBackdrop
{...props}
class={cn("bg-black/10 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 isolate z-50", props.class)}
/>
)
type SheetContentProps = (Omit<
ComponentProps<typeof SdkDialogContent>,
"class"
> & {
class?: string
"data-slot"?: string
}) & {
side?: "top" | "right" | "bottom" | "left"
showCloseButton?: boolean
}
const SheetContent = (props: SheetContentProps) => {
const others = omit(
props,
"children",
"side",
"showCloseButton",
"render",
"data-slot"
)
const renderContent: SheetContentProps["render"] = (part, state) => {
const attributes = merge(part, () => ({
"data-slot": props["data-slot"] ?? "sheet-content"
}))
return props.render ? (
props.render(attributes, state)
) : (
<div {...attributes} />
)
}
return (
<>
<SheetOverlay />
<SdkDialogContent
data-side={props.side ?? "right"}
{...others}
class={cn("fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t 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=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=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm", props.class)}
render={renderContent}
>
{props.children}
<Show when={props.showCloseButton !== false}>
<SdkDialogClose
render={(partProps) => (
<Button {...partProps} variant="ghost" size="icon-sm" />
)}
class="absolute top-3 right-3"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
<span class="sr-only">Close</span>
</SdkDialogClose>
</Show>
</SdkDialogContent>
</>
)
}
type SheetHeaderProps = ComponentProps<"div">
const SheetHeader = (props: SheetHeaderProps) => (
<div
data-slot="sheet-header"
{...props}
class={cn("gap-0.5 p-4 flex flex-col", props.class)}
/>
)
type SheetFooterProps = ComponentProps<"div">
const SheetFooter = (props: SheetFooterProps) => (
<div
data-slot="sheet-footer"
{...props}
class={cn("gap-2 p-4 mt-auto flex flex-col", props.class)}
/>
)
type SheetTitleProps = Omit<ComponentProps<typeof SdkDialogTitle>, "class"> & {
class?: string
}
const SheetTitle = (props: SheetTitleProps) => (
<SdkDialogTitle {...props} class={cn("text-base font-medium text-foreground", props.class)} />
)
type SheetDescriptionProps = Omit<
ComponentProps<typeof SdkDialogDescription>,
"class"
> & {
class?: string
}
const SheetDescription = (props: SheetDescriptionProps) => (
<SdkDialogDescription
{...props}
class={cn("text-sm text-muted-foreground", props.class)}
/>
)
export {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger
}Update the import paths to match your project setup.
Usage
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger
} from "~/components/ui/sheet"<Sheet>
<SheetTrigger>Open</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Are you absolutely sure?</SheetTitle>
<SheetDescription>This action cannot be undone.</SheetDescription>
</SheetHeader>
</SheetContent>
</Sheet>Composition
Use the following composition to build a Sheet:
Sheet
├── SheetTrigger
└── SheetContent
├── SheetHeader
│ ├── SheetTitle
│ └── SheetDescription
└── SheetFooterSide
Use the side prop on SheetContent to set the edge of the screen where the sheet appears. Values are top, right, bottom, or left.
import { For, Repeat } from "solid-js"
import { Button } from "~/components/ui/button"
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger
} from "~/components/ui/sheet"
const SHEET_SIDES = ["top", "right", "bottom", "left"] as const
export default function SheetSide() {
return (
<div class="flex flex-wrap gap-2">
<For each={SHEET_SIDES}>
{(side) => (
<Sheet>
<SheetTrigger
render={(partProps) => (
<Button {...partProps} variant="outline" />
)}
class="capitalize"
>
{side}
</SheetTrigger>
<SheetContent
class="data-[side=bottom]:max-h-[50vh] data-[side=top]:max-h-[50vh]"
side={side}
>
<SheetHeader>
<SheetTitle>Edit profile</SheetTitle>
<SheetDescription>
Make changes to your profile here. Click save when you're
done.
</SheetDescription>
</SheetHeader>
<div class="no-scrollbar overflow-y-auto px-4">
<Repeat count={10}>
{() => (
<p class="mb-4 leading-normal style-lyra:mb-2 style-lyra:leading-relaxed">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
</p>
)}
</Repeat>
</div>
<SheetFooter>
<Button type="submit">Save changes</Button>
<SheetClose
render={(partProps) => (
<Button {...partProps} variant="outline" />
)}
>
Cancel
</SheetClose>
</SheetFooter>
</SheetContent>
</Sheet>
)}
</For>
</div>
)
}No Close Button
Use showCloseButton={false} on SheetContent to hide the close button.
import { Button } from "~/components/ui/button"
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger
} from "~/components/ui/sheet"
export default function SheetNoCloseButton() {
return (
<Sheet>
<SheetTrigger
render={(partProps) => <Button {...partProps} variant="outline" />}
>
Open Sheet
</SheetTrigger>
<SheetContent showCloseButton={false}>
<SheetHeader>
<SheetTitle>No Close Button</SheetTitle>
<SheetDescription>
This sheet doesn't have a close button in the top-right corner.
Click outside to close.
</SheetDescription>
</SheetHeader>
</SheetContent>
</Sheet>
)
}API Reference
See the UI SDK documentation for more information.