Button Group
basecn/button-groupFreeComponent
A container that groups related buttons together with consistent styling.
Live preview
live · rendered by the registry
Rendered by basecn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://basecn.dev/r/button-group.jsonSource
1import { mergeProps } from "@base-ui/react/merge-props";2import { useRender } from "@base-ui/react/use-render";3import { cva, type VariantProps } from "class-variance-authority";45import { cn } from "@/lib/utils";6import { Separator } from "@/registry/components/ui/separator";78const buttonGroupVariants = cva(9 "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",10 {11 variants: {12 orientation: {13 horizontal:14 "*:not-[&:nth-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:rounded-l-none *:not-[&:nth-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:border-l-0 *:not-[&:nth-last-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:rounded-r-none",15 vertical:16 "flex-col *:not-[&:nth-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:rounded-t-none *:not-[&:nth-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:border-t-0 *:not-[&:nth-last-child(1_of_:not([aria-hidden],span[data-base-ui-inert]))]:rounded-b-none",17 },18 },19 defaultVariants: {20 orientation: "horizontal",21 },22 }23);2425function ButtonGroup({26 className,27 orientation,28 ...props29}: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {30 return (31 <div32 role="group"33 data-slot="button-group"34 data-orientation={orientation}35 className={cn(buttonGroupVariants({ orientation }), className)}36 {...props}37 />38 );39}4041function ButtonGroupText({42 className,43 render,44 ...props45}: React.ComponentProps<"div"> & {46 render?: useRender.RenderProp;47}) {48 return useRender({49 defaultTagName: "div",50 render,51 props: mergeProps(52 {53 className: cn(54 "bg-muted flex items-center gap-2 rounded-md border px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",55 className56 ),57 },58 props59 ),60 });61}6263function ButtonGroupSeparator({64 className,65 orientation = "vertical",66 ...props67}: React.ComponentProps<typeof Separator>) {68 return (69 <Separator70 data-slot="button-group-separator"71 orientation={orientation}72 className={cn(73 "bg-input relative !m-0 self-stretch data-[orientation=vertical]:h-auto",74// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from basecn
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | basecn | Components | Free | 2 deps | |
| Alertalert | basecn | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | basecn | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | basecn | Components | Free | no deps | |
| Autocompleteautocomplete | basecn | Components | Free | 2 deps | |
| Avataravatar | basecn | Components | Free | 1 dep | |
| Badgebadge | basecn | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | basecn | Components | Free | 2 deps |
