Skip to content
Page

Sidebar

Vertical navigation with groups. The docs shell is built on it.

import {
Sidebar,
SidebarHeader,
SidebarBrand,
SidebarContent,
SidebarNav,
SidebarGroup,
SidebarGroupLabel,
SidebarLink,
SidebarFooter,
} from "@pelagornis/page/components";

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

src/components/SidebarExample.tsx
import {
Box,
Sidebar,
SidebarBrand,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupLabel,
SidebarHeader,
SidebarLink,
SidebarNav,
Text,
} from "@pelagornis/page/components";
export default function SidebarDemo() {
return (
<Box border="strokeWidthThin" borderColor="borderDefault" radius="roundedLarge" className="h-80 w-64 overflow-hidden">
<Sidebar className="h-full">
<SidebarHeader>
<SidebarBrand>Docs</SidebarBrand>
</SidebarHeader>
<SidebarContent>
<SidebarNav>
<SidebarGroup>
<SidebarGroupLabel>Start</SidebarGroupLabel>
<SidebarLink href="#" active>
Getting started
</SidebarLink>
<SidebarLink href="#">Use in MDX</SidebarLink>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Components</SidebarGroupLabel>
<SidebarLink href="#">Button</SidebarLink>
<SidebarLink href="#">Tabs</SidebarLink>
</SidebarGroup>
</SidebarNav>
</SidebarContent>
<SidebarFooter>
<Text variant="captionMd">v2.0.0</Text>
</SidebarFooter>
</Sidebar>
</Box>
);
}

Sidebar 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 SidebarExample from "../../components/SidebarExample";
<SidebarExample 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/SidebarExample.astro
---
import SidebarExample from "../SidebarExample";
---
<SidebarExample 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: {
"sidebar-example": {
render: component("./src/components/markdoc/SidebarExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% sidebar-example /%}

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

PartRole
rootsidebar
brandsidebar-brand
contentsidebar-content
footersidebar-footer
groupsidebar-group
group_labelsidebar-group-label
headersidebar-header
linksidebar-link
navsidebar-nav
peeksidebar-peek
peek_edgesidebar-peek-edge
peek_insetsidebar-peek-inset
peek_panelsidebar-peek-panel
peek_pinsidebar-peek-pin
peek_surfacesidebar-peek-surface
providersidebar-provider
triggerbutton

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

KindStates
Pseudofocus-visible