Logo VitNode
Documentation

Switch

An on/off toggle for settings that take effect right away, in two sizes with disabled and invalid states, plus nested AutoForm fields.

Preview

Usage

import { AutoForm } from '@vitnode/core/components/form/auto-form'
import { AutoFormSwitch } from '@vitnode/core/components/form/fields/switch'
import { z } from 'zod'

const formSchema = z.object({
  maintenance: z.boolean().default(false),
})
<AutoForm
  formSchema={formSchema}
  fields={[
    {
      id: 'maintenance',
      component: (props) => (
        <AutoFormSwitch {...props} label="Maintenance mode" />
      ),
    },
  ]}
/>

States

  • size="sm" fits dense lists. The default is "default".
  • disabled dims it. Add data-disabled to the parent Field to dim the label too.
  • aria-invalid adds a red ring. Point aria-describedby at the error.
<Field orientation="horizontal">
  <FieldLabel htmlFor="compact">Compact thread list</FieldLabel>
  <Switch id="compact" size="sm" />
</Field>

Nested fields

AutoFormSwitch can reveal the settings it controls in the same card. See Auto Form - Nested fields.

Props

Prop

Type

Every Base UI Switch prop works too.

API Reference

Base UI - Switch