Skip to content
Page

Toolbar

Grouped editing controls with toggle buttons and dividers.

import {
Toolbar,
ToolbarButton,
ToolbarDivider,
ToolbarGroup,
ToolbarToggleButton,
} from "@pelagornis/page/components";

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

src/components/ToolbarExample.tsx
import { useState } from "react";
import {
Toolbar,
ToolbarButton,
ToolbarDivider,
ToolbarGroup,
ToolbarToggleButton,
WebIcon,
} from "@pelagornis/page/components";
function Icon({ name }: { name: string }) {
return <WebIcon name={name} size={20} color="currentColor" aria-hidden />;
}
export default function ToolbarDemo() {
const [align, setAlign] = useState("left");
return (
<Toolbar label="Text formatting" attached>
<ToolbarGroup aria-label="Text style">
<ToolbarToggleButton aria-label="Highlight" title="Highlight" defaultPressed>
<Icon name="highlight" />
</ToolbarToggleButton>
<ToolbarToggleButton aria-label="Link" title="Link">
<Icon name="link" />
</ToolbarToggleButton>
<ToolbarToggleButton aria-label="Code" title="Code">
<Icon name="code" />
</ToolbarToggleButton>
</ToolbarGroup>
<ToolbarDivider />
<ToolbarGroup aria-label="Alignment">
{(["left", "center", "right"] as const).map((value) => (
<ToolbarToggleButton
key={value}
aria-label={`Align ${value}`}
title={`Align ${value}`}
pressed={align === value}
onPressedChange={() => setAlign(value)}
>
<Icon name={`text-align-${value}`} />
</ToolbarToggleButton>
))}
</ToolbarGroup>
<ToolbarDivider />
<ToolbarGroup aria-label="Clipboard">
<ToolbarButton aria-label="Copy" title="Copy">
<Icon name="copy" />
</ToolbarButton>
<ToolbarButton aria-label="Cut" title="Cut">
<Icon name="cut" />
</ToolbarButton>
</ToolbarGroup>
</Toolbar>
);
}

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

Values the component accepts for each variant prop.

PropValues
sizesm md lg
orientationhorizontal vertical

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

PartRole
roottoolbar
grouptoolbar-group
buttontoolbar-button
toggletoolbar-toggle-button
dividertoolbar-divider

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

KindStates
Pseudofocus-visible

Keys the component handles when it has focus.

KeyAction
ArrowRightnext-trigger
ArrowLeftprevious-trigger
ArrowDownnext-trigger
ArrowUpprevious-trigger
Homefirst-trigger
Endlast-trigger
Enteractivate
Spaceactivate