Button Group
Visually connected group of buttons that share borders. Install Button Group from the VLLNT UI registry with the shadcn CLI.
Visually connected group of buttons that share borders. Part of the form family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Button Group to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/button-group.jsonSource
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "../../lib/utils";
const buttonGroupVariants = cva(
"isolate inline-flex w-fit [&>*:focus-visible]:z-10 [&>*:focus-within]:z-10",
{
defaultVariants: {
orientation: "horizontal",
},
variants: {
orientation: {
horizontal:
"flex-row [&>*:not(:first-child)]:-ml-px [&>*:not(:first-child)]:rounded-l-none [&>*:not(:last-child)]:rounded-r-none",
vertical:
"flex-col [&>*:not(:first-child)]:-mt-px [&>*:not(:first-child)]:rounded-t-none [&>*:not(:last-child)]:rounded-b-none",
},
},
},
);
/**
* Visually connected group of buttons that share borders.
*
* @example
* <ButtonGroup>
* <Button variant="outline">Prev</Button>
* <Button variant="outline">Next</Button>
* </ButtonGroup>
*/
export type ButtonGroupProps = React.ComponentPropsWithoutRef<"div"> &
VariantProps<typeof buttonGroupVariants>;
const ButtonGroup = ({
className,
orientation,
ref,
...props
}: ButtonGroupProps & { ref?: React.Ref<HTMLDivElement> }) => (
<div
className={cn(buttonGroupVariants({ orientation }), className)}
data-slot="button-group"
ref={ref}
role="group"
{...props}
/>
);
ButtonGroup.displayName = "ButtonGroup";
export { ButtonGroup, buttonGroupVariants };
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.