Get Started
Input
Feedback
Display
Installation
i18n
import { BookmarkIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"Installation#
pnpm dlx shadcn@latest add https://ui.tyap.me/r/styles/base/toggle.jsonnpx shadcn@latest add https://ui.tyap.me/r/styles/base/toggle.jsonyarn dlx shadcn@latest add https://ui.tyap.me/r/styles/base/toggle.jsonbunx --bun shadcn@latest add https://ui.tyap.me/r/styles/base/toggle.json
Install the following dependencies:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
Copy and paste the following code into your project.
"use client"
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const toggleVariants = cva(
"group/toggle inline-flex items-center justify-center whitespace-nowrap outline-none hover:bg-muted focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
{
variants: {
variant: {
default: "",
outline: "",
},
size: {
default: "",
sm: "",
lg: "",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Toggle({
className,
variant = "default",
size = "default",
...props
}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {
return (
<TogglePrimitive
data-slot="toggle"
className={cn(toggleVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Toggle, toggleVariants }
Update the import paths to match your project setup.
Usage#
import { Toggle } from "@/components/ui/toggle"<Toggle>Toggle</Toggle>Examples#
Outline#
Use variant="outline" for an outline style.
import { BoldIcon, ItalicIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"With Text#
import { ItalicIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"Size#
Use the size prop to change the size of the toggle.
import { Toggle } from "@/components/ui/toggle"
export function ToggleSizes() {Disabled#
import { Toggle } from "@/components/ui/toggle"
export function ToggleDisabled() {RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"API Reference#
See the Base UI Toggle documentation.