Skip to content
Page

Button Group

Bundles related buttons into one tube, with shared size and variant.

import { Button, ButtonGroup, WebIcon } from "@pelagornis/page/components";

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

src/components/ButtonGroupExample.tsx
import { Button, ButtonGroup, WebIcon } from "@pelagornis/page/components";
function Icon({ name }: { name: string }) {
return <WebIcon name={name} size={20} color="currentColor" aria-hidden />;
}
export default function ButtonGroupDemo() {
return (
<ButtonGroup aria-label="Canvas">
<Button layout="icon" aria-label="Back" title="Back">
<Icon name="chevron-left" />
</Button>
<Button layout="icon" aria-label="Zoom in" title="Zoom in">
<Icon name="zoom-in" />
</Button>
<Button layout="icon" aria-label="Zoom out" title="Zoom out">
<Icon name="zoom-out" />
</Button>
<Button layout="icon" aria-label="Copy" title="Copy">
<Icon name="copy" />
</Button>
<Button layout="icon" aria-label="Cut" title="Cut">
<Icon name="cut" />
</Button>
</ButtonGroup>
);
}

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

Values the component accepts for each variant prop.

PropValues
sizexs sm md lg xl
variantprimary secondary outline ghost
orientationhorizontal vertical

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

PartRole
rootbutton-group
buttonbutton

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

KindStates
Pseudohover active focus-visible

Keys the component handles when it has focus.

KeyAction
Enteractivate
Spaceactivate