Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import * as React from "react"; import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"; import { type VariantProps } from "class-variance-authority"; import { toggleVariants } from "@/components/ui/toggle"; import { ui } from "@/config/theme"; import { cn } from "@/lib/utils"; const ToggleGroupContext = React.createContext<VariantProps<typeof toggleVariants>>({ size: "default", variant: "default", }); const ToggleGroup = React.forwardRef< React.ElementRef<typeof ToggleGroupPrimitive.Root>, React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> & VariantProps<typeof toggleVariants> >(({ className, variant, size, children, ...props }, ref) => ( <ToggleGroupPrimitive.Root ref={ref} className={cn(ui("toggleGroupRoot"), className)} {...props}> <ToggleGroupContext.Provider value={{ variant, size }}>{children}</ToggleGroupContext.Provider> </ToggleGroupPrimitive.Root> )); ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName; const ToggleGroupItem = React.forwardRef< React.ElementRef<typeof ToggleGroupPrimitive.Item>, React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> & VariantProps<typeof toggleVariants> >(({ className, children, variant, size, ...props }, ref) => { const context = React.useContext(ToggleGroupContext); return ( <ToggleGroupPrimitive.Item ref={ref} className={cn( toggleVariants({ variant: context.variant || variant, size: context.size || size, }), className, )} {...props} > {children} </ToggleGroupPrimitive.Item> ); }); ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName; export { ToggleGroup, ToggleGroupItem }; |