metis-desk/packages/shadcn-ui/src/components/button-group.tsx
David 5adbe81364 feat: enhance access management with quick create functionality and improved forms
- Added QuickCreateDialog for creating systems and environments quickly.
- Implemented quickCreatePlan to handle creation logic based on context.
- Updated AccessForm to support quick creation and related modals.
- Enhanced i18n support for new quick add features in both English and Spanish.
- Refactored AssignmentForm to allow department creation directly from the form.
- Introduced SelectWithAction component for better user interaction with selections.
- Added tests for new components and functionalities to ensure reliability.
2026-10-04 15:46:39 +02:00

78 lines
2.5 KiB
TypeScript

import { mergeProps } from "@base-ui/react/merge-props";
import { useRender } from "@base-ui/react/use-render";
import { Separator } from "@repo/shadcn-ui/components/separator";
import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "cn";
import type { ComponentProps } from "react";
const buttonGroupVariants = cva(
"flex w-fit items-stretch *:focus-visible:relative *:focus-visible:z-10 has-[>[data-slot=button-group]]:gap-2 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
{
variants: {
orientation: {
horizontal:
"*:data-slot:rounded-r-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-md! [&>[data-slot]~[data-slot]]:rounded-l-none [&>[data-slot]~[data-slot]]:border-l-0",
vertical:
"flex-col *:data-slot:rounded-b-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-md! [&>[data-slot]~[data-slot]]:rounded-t-none [&>[data-slot]~[data-slot]]:border-t-0",
},
},
defaultVariants: {
orientation: "horizontal",
},
}
);
function ButtonGroup({
className,
orientation,
...props
}: ComponentProps<"fieldset"> & VariantProps<typeof buttonGroupVariants>) {
return (
<fieldset
className={cn(buttonGroupVariants({ orientation }), className)}
data-orientation={orientation}
data-slot="button-group"
{...props}
/>
);
}
function ButtonGroupText({ className, render, ...props }: useRender.ComponentProps<"div">) {
return useRender({
defaultTagName: "div",
props: mergeProps<"div">(
{
className: cn(
"flex items-center gap-2 rounded-md border bg-muted px-2.5 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
className
),
},
props
),
render,
state: {
slot: "button-group-text",
},
});
}
function ButtonGroupSeparator({
className,
orientation = "vertical",
...props
}: ComponentProps<typeof Separator>) {
return (
<Separator
className={cn(
"relative self-stretch bg-input data-horizontal:mx-px data-horizontal:w-auto data-vertical:my-px data-vertical:h-auto",
className
)}
data-slot="button-group-separator"
orientation={orientation}
{...props}
/>
);
}
export { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants };