Button Group
pure-ui/button-groupFreeComponent
A customizable button group component
Install it
npx shadcn@latest add https://raw.githubusercontent.com/MusKRI/pure-ui/main/public/r/button-group.jsonSource
1import { mergeProps } from "@base-ui/react/merge-props";2import { useRender } from "@base-ui/react/use-render";3import { tv, VariantProps } from "tailwind-variants";45import { cn } from "@/lib/classes";6import { Separator } from "@/registry/pure-ui/ui/separator";78const buttonGroupVariants = tv({9 base: `flex w-fit items-stretch *:focus-visible:z-10 *:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md has-[>[data-slot=button-group]]:gap-2 [&_[data-slot=button]]:active:scale-100 [&_button]:active:scale-100`,10 variants: {11 orientation: {12 horizontal:13 "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 *:not-nth-last-[1_of_:not([aria-hidden],span[data-base-ui-inert],span[data-base-ui-focus-guard],span[aria-owns])]:rounded-r-none *:not-first:rounded-s-none",14 vertical:15 "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",16 },17 },18 defaultVariants: {19 orientation: "horizontal",20 },21});2223interface ButtonGroupProps24 extends React.ComponentProps<"div">,25 VariantProps<typeof buttonGroupVariants> {}2627function ButtonGroup({28 className,29 orientation = "horizontal",30 ...props31}: ButtonGroupProps) {32 return (33 <div34 role="group"35 data-slot="button-group"36 data-orientation={orientation}37 className={cn(buttonGroupVariants({ orientation }), className)}38 {...props}39 />40 );41}4243function ButtonGroupText({44 className,45 render,46 ...props47}: useRender.ComponentProps<"div">) {48 const defaultProps = {49 "data-slot": "button-group-text",50 className: cn(51 "bg-muted flex items-center gap-2 rounded-md border px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",52 className53 ),54 };5556 return useRender({57 defaultTagName: "div",58 props: mergeProps(defaultProps, props),59 render,60 });61}6263function ButtonGroupSeparator({64 className,65 orientation = "horizontal",66 ...props67}: React.ComponentProps<typeof Separator>) {68 return (69 <Separator70 data-slot="button-group-separator"71 orientation={orientation}72 className={cn(73// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Pure UI
All 291 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Pure UI | Components | Free | 4 deps | |
| Avataravatar | Pure UI | Components | Free | 3 deps | |
| Badgebadge | Pure UI | Components | Free | 4 deps | |
| Buttonbutton | Pure UI | Components | Free | 4 deps | |
| Calendarcalendar | Pure UI | Components | Free | 4 deps | |
| Cardcard | Pure UI | Components | Free | 2 deps | |
| Checkboxcheckbox | Pure UI | Components | Free | 4 deps | |
| Collapsiblecollapsible | Pure UI | Components | Free | 3 deps |
