UIPackage
Menu

Framework

Change language

Boilerplate repo

Toggle

toggleui

On/off button (different from Switch — this is shaped like a button and lives in toolbars). Three sizes, two variants. Use inside Toggle Group or standalone for "press to enable" buttons like bold / italic.

Also available for Vue ->

Installation

$npx shadcn@latest add https://uipkge.dev/r/react/toggle.json
Named registry:npx shadcn@latest add @uipkge-react/toggleInstalls to:components/ui/toggle/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
variant
'default''outline'
defaultoptional
size
'default''sm''lg'
defaultoptional
asChild

emitting a <button> — the React equivalent of reka-ui's as-child.

booleanoptional

Used by

Files installed (3)

  • components/ui/toggle/toggle.tsx0.9 kB
    'use client'
    
    import * as React from 'react'
    import * as TogglePrimitive from '@radix-ui/react-toggle'
    import { cn } from '@/lib/utils'
    import { toggleVariants, type ToggleVariants } from './toggle.variants'
    
    export interface ToggleProps
      extends Omit<React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root>, 'asChild'>, ToggleVariants {
      /** Render the child element as the toggle (merging props/styles) instead of
       *  emitting a <button> — the React equivalent of reka-ui's as-child. */
      asChild?: boolean
    }
    
    const Toggle = React.forwardRef<React.ElementRef<typeof TogglePrimitive.Root>, ToggleProps>(
      ({ className, variant, size, ...props }, ref) => (
        <TogglePrimitive.Root
          ref={ref}
          data-uipkge=""
          data-slot="toggle"
          className={cn(toggleVariants({ variant, size }), className)}
          {...props}
        />
      ),
    )
    Toggle.displayName = 'Toggle'
    
    export { Toggle }
    
  • components/ui/toggle/toggle.variants.ts1.6 kB
  • components/ui/toggle/index.ts0.1 kB

Raw manifest:https://uipkge.dev/r/react/toggle.json