Home / File/ toggle-group.tsx — ui Source File

toggle-group.tsx — ui Source File

Architecture documentation for toggle-group.tsx, a tsx file in the ui codebase. 5 imports, 0 dependents.

File tsx ComponentRegistry ChartRegistry 5 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  c5e624b5_7590_b74f_e8d0_05042ff9a715["toggle-group.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  c5e624b5_7590_b74f_e8d0_05042ff9a715 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  25383e8d_ca91_a50e_c3a8_5f228d02e1df["class-variance-authority"]
  c5e624b5_7590_b74f_e8d0_05042ff9a715 --> 25383e8d_ca91_a50e_c3a8_5f228d02e1df
  9c463da6_747b_38dc_586b_cbb4873070b1["radix-ui"]
  c5e624b5_7590_b74f_e8d0_05042ff9a715 --> 9c463da6_747b_38dc_586b_cbb4873070b1
  79081a1f_55a3_945a_fb8c_d53d6d3eab81["utils"]
  c5e624b5_7590_b74f_e8d0_05042ff9a715 --> 79081a1f_55a3_945a_fb8c_d53d6d3eab81
  9f31239d_4d4f_f1b1_7ff3_ec54f2392841["toggle"]
  c5e624b5_7590_b74f_e8d0_05042ff9a715 --> 9f31239d_4d4f_f1b1_7ff3_ec54f2392841
  style c5e624b5_7590_b74f_e8d0_05042ff9a715 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"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 }

Subdomains

Dependencies

  • class-variance-authority
  • radix-ui
  • react
  • toggle
  • utils

Frequently Asked Questions

What does toggle-group.tsx do?
toggle-group.tsx is a source file in the ui codebase, written in tsx. It belongs to the ComponentRegistry domain, ChartRegistry subdomain.
What functions are defined in toggle-group.tsx?
toggle-group.tsx defines 2 function(s): ToggleGroup, ToggleGroupItem.
What does toggle-group.tsx depend on?
toggle-group.tsx imports 5 module(s): class-variance-authority, radix-ui, react, toggle, utils.
Where is toggle-group.tsx in the architecture?
toggle-group.tsx is located at apps/v4/registry/new-york-v4/ui/toggle-group.tsx (domain: ComponentRegistry, subdomain: ChartRegistry, directory: apps/v4/registry/new-york-v4/ui).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free