Skip to content
Page

Drawer

Panel that slides in from the edge of the screen.

import {
Drawer,
DrawerTrigger,
DrawerContent,
DrawerHeader,
DrawerTitle,
DrawerDescription,
DrawerBody,
DrawerFooter,
} from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/DrawerExample.tsx
import { useState } from "react";
import {
Button,
Drawer,
DrawerBody,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
Switch,
Stack,
Text,
} from "@pelagornis/page/components";
export default function DrawerDemo() {
const [open, setOpen] = useState(false);
return (
<Drawer open={open} onOpenChange={setOpen} placement="right">
<DrawerTrigger variant="outline">Open settings</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Settings</DrawerTitle>
<DrawerDescription>Preferences for this workspace.</DrawerDescription>
</DrawerHeader>
<DrawerBody>
<Stack direction="row" gap="sizeSmall" align="center">
<Switch aria-label="Compact sidebar" />
<Text variant="bodyMd">Compact sidebar</Text>
</Stack>
</DrawerBody>
<DrawerFooter>
<Button variant="outline" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button variant="primary" onClick={() => setOpen(false)}>
Save
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
);
}

Drawer is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import DrawerExample from "../../components/DrawerExample";
<DrawerExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/DrawerExample.astro
---
import DrawerExample from "../DrawerExample";
---
<DrawerExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"drawer-example": {
render: component("./src/components/markdoc/DrawerExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% drawer-example /%}

Values the component accepts for each variant prop.

PropValues
typeoverlay inline
sizesm md lg

Parts of the component and the data-refineui role each one renders.

PartRole
rootdrawer

States the component styles. Component states are exposed as data attributes.

KindStates
data-stateopen closed

Keys the component handles when it has focus.

KeyAction
Escapeclose