mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-11-03 03:18:52 +00:00
Squash merge of shadcn-ui/ui main branch into hanzo/ui, bringing in: - [email protected] through [email protected] releases - New apps/v4 directory structure - Registry system improvements and MCP server - Framework support (Vue, Svelte, React Native) - New templates (vite-app, monorepo-next, laravel) - Zod 4 compatibility (scoped override for zod@>4) - Test fixture corrections for alias resolution All 867 merge conflicts resolved preserving Hanzo customizations. 1020/1020 shadcn tests pass.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { type VariantProps } from "class-variance-authority"
|
|
import { ToggleGroup as ToggleGroupPrimitive } from "radix-ui"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
import { toggleVariants } from "@/registry/new-york-v4/ui/toggle"
|
|
|
|
const ToggleGroupContext = React.createContext<
|
|
VariantProps<typeof toggleVariants> & {
|
|
spacing?: number
|
|
}
|
|
>({
|
|
size: "default",
|
|
variant: "default",
|
|
spacing: 0,
|
|
})
|
|
|
|
function ToggleGroup({
|
|
className,
|
|
variant,
|
|
size,
|
|
spacing = 0,
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
|
|
VariantProps<typeof toggleVariants> & {
|
|
spacing?: number
|
|
}) {
|
|
return (
|
|
<ToggleGroupPrimitive.Root
|
|
data-slot="toggle-group"
|
|
data-variant={variant}
|
|
data-size={size}
|
|
data-spacing={spacing}
|
|
style={{ "--gap": spacing } as React.CSSProperties}
|
|
className={cn(
|
|
"group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
<ToggleGroupContext.Provider value={{ variant, size, spacing }}>
|
|
{children}
|
|
</ToggleGroupContext.Provider>
|
|
</ToggleGroupPrimitive.Root>
|
|
)
|
|
}
|
|
|
|
function ToggleGroupItem({
|
|
className,
|
|
children,
|
|
variant,
|
|
size,
|
|
...props
|
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
|
|
VariantProps<typeof toggleVariants>) {
|
|
const context = React.useContext(ToggleGroupContext)
|
|
|
|
return (
|
|
<ToggleGroupPrimitive.Item
|
|
data-slot="toggle-group-item"
|
|
data-variant={context.variant || variant}
|
|
data-size={context.size || size}
|
|
data-spacing={context.spacing}
|
|
className={cn(
|
|
toggleVariants({
|
|
variant: context.variant || variant,
|
|
size: context.size || size,
|
|
}),
|
|
"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10",
|
|
"data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l",
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</ToggleGroupPrimitive.Item>
|
|
)
|
|
}
|
|
|
|
export { ToggleGroup, ToggleGroupItem }
|