返回 presentation-ai
toggle.tsx
根目录 / src / components / ui / toggle.tsx
1 "use client";
2
3 import * as TogglePrimitive from "@radix-ui/react-toggle";
4 import { cva, type VariantProps } from "class-variance-authority";
5 import * as React from "react";
6
7 import { cn } from "@/lib/utils";
8
9 const toggleVariants = cva(
10 "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
11 {
12 variants: {
13 variant: {
14 default: "bg-transparent",
15 outline:
16 "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
17 },
18 size: {
19 default: "h-10 min-w-10 px-3",
20 sm: "h-9 min-w-9 px-2.5",
21 lg: "h-11 min-w-11 px-5",
22 },
23 },
24 defaultVariants: {
25 variant: "default",
26 size: "default",
27 },
28 },
29 );
30
31 const Toggle = React.forwardRef<
32 React.ElementRef<typeof TogglePrimitive.Root>,
33 React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
34 VariantProps<typeof toggleVariants>
35 >(({ className, variant, size, ...props }, ref) => (
36 <TogglePrimitive.Root
37 ref={ref}
38 className={cn(toggleVariants({ variant, size, className }))}
39 {...props}
40 />
41 ));
42
43 Toggle.displayName = TogglePrimitive.Root.displayName;
44
45 export { Toggle, toggleVariants };
46
46 lines Plain Text