Form

Switch

Toggle switch for boolean settings.

Available inreactangular

Preview

Live previewreal component

Install

TerminalBash
npx mcp-elements add switch

Usage

switch-example.tsxTSX
import { Switch } from '@mcp-elements/react'
import { useState } from 'react'

export function Example() {
  const [checked, setChecked] = useState(true)
  return (
    <label className="flex items-center gap-3">
      <Switch checked={checked} onCheckedChange={setChecked} />
      Auto-approve safe tool calls
    </label>
  )
}

Props

PropTypeDefaultDescription
checkedbooleanfalseWhether the switch is on
onCheckedChange(checked: boolean) => voidCalled when the checked state should change
disabledbooleanWhether the switch is disabled
idstringHTML id applied to the switch button
namestringName for a hidden input, useful inside forms