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. 6 imports, 0 dependents.

File tsx DocumentationAtlas ContentSourcing 6 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27["toggle-group.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  3d9438e8_7604_787c_4898_907262aff28b["utils"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 3d9438e8_7604_787c_4898_907262aff28b
  72fb6f69_88f8_2278_f711_686056281cba["toggle"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 72fb6f69_88f8_2278_f711_686056281cba
  8014e1e4_19c1_40dc_68ec_b28df439b8ed["toggle"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 8014e1e4_19c1_40dc_68ec_b28df439b8ed
  29d61405_7856_0804_8e40_eb1b6fa3c8b5["toggle-group"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 29d61405_7856_0804_8e40_eb1b6fa3c8b5
  25383e8d_ca91_a50e_c3a8_5f228d02e1df["class-variance-authority"]
  7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 --> 25383e8d_ca91_a50e_c3a8_5f228d02e1df
  style 7084af5f_4f1d_1ba2_8ef4_6e9cfed46f27 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"use client"

import * as React from "react"
import { cn } from "@/examples/base/lib/utils"
import { toggleVariants } from "@/examples/base/ui-rtl/toggle"
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group"
import { type VariantProps } from "class-variance-authority"

const ToggleGroupContext = React.createContext<
  VariantProps<typeof toggleVariants> & {
    spacing?: number
    orientation?: "horizontal" | "vertical"
  }
>({
  size: "default",
  variant: "default",
  spacing: 0,
  orientation: "horizontal",
})

function ToggleGroup({
  className,
  variant,
  size,
  spacing = 0,
  orientation = "horizontal",
  children,
  ...props
}: ToggleGroupPrimitive.Props &
  VariantProps<typeof toggleVariants> & {
    spacing?: number
    orientation?: "horizontal" | "vertical"
  }) {
  return (
    <ToggleGroupPrimitive
      data-slot="toggle-group"
      data-variant={variant}
      data-size={size}
      data-spacing={spacing}
      data-orientation={orientation}
      style={{ "--gap": spacing } as React.CSSProperties}
      className={cn(
        "group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] rounded-lg data-vertical:flex-col data-vertical:items-stretch data-[size=sm]:rounded-[min(var(--radius-md),10px)]",
        className
      )}
      {...props}
    >
      <ToggleGroupContext.Provider
        value={{ variant, size, spacing, orientation }}
      >
        {children}
      </ToggleGroupContext.Provider>
    </ToggleGroupPrimitive>
  )
}

function ToggleGroupItem({
  className,
  children,
  variant = "default",
  size = "default",
  ...props
}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {
  const context = React.useContext(ToggleGroupContext)

  return (
    <TogglePrimitive
      data-slot="toggle-group-item"
      data-variant={context.variant || variant}
      data-size={context.size || size}
      data-spacing={context.spacing}
      className={cn(
        "shrink-0 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 focus:z-10 focus-visible:z-10 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-s-lg group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-lg group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-e-lg group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-lg group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:border-s-0 group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:border-t-0 group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-s group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-t",
        toggleVariants({
          variant: context.variant || variant,
          size: context.size || size,
        }),
        className
      )}
      {...props}
    >
      {children}
    </TogglePrimitive>
  )
}

export { ToggleGroup, ToggleGroupItem }

Subdomains

Dependencies

  • class-variance-authority
  • react
  • toggle
  • toggle
  • toggle-group
  • 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 DocumentationAtlas domain, ContentSourcing 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 6 module(s): class-variance-authority, react, toggle, toggle, toggle-group, utils.
Where is toggle-group.tsx in the architecture?
toggle-group.tsx is located at apps/v4/examples/base/ui-rtl/toggle-group.tsx (domain: DocumentationAtlas, subdomain: ContentSourcing, directory: apps/v4/examples/base/ui-rtl).

Analyze Your Own Codebase

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

Try Supermodel Free