KKiotaPay UI
Browse documentation

Switch

A labelled boolean toggle. The caption beside it changes with the state, so the current setting is readable as words rather than inferred from a knob.

Installation

pnpm dlx shadcn@latest add https://kiotapay-ui-staging.staging.kiotapay.com/r/switch.json

Installs components/custom/switch.tsx, the shadcn switch primitive and form-field. The bare primitive stays at @/components/ui/switch.

Usage

'use client'

import { Switch } from '@/components/custom/switch'

export function CarryOverField({ value, onChange }) {
  return (
    <Switch
      label="Carry over unused leave"
      checked={value}
      onCheckedChange={onChange}
      trueLabel="Carries over"
      falseLabel="Expires at year end"
    />
  )
}

Props

PropTypeDefaultDescription
labelstring—Required. Rendered above the switch.
checkedbooleanfalseControlled state.
onCheckedChange(checked: boolean) => void—Fires on toggle.
descriptionstring—Fixed caption. Overrides both state labels.
trueLabelstring'Yes'Caption while on.
falseLabelstring'No'Caption while off.
disabledbooleanfalseBlocks toggling.
errorbooleanfalseTurns the label to the danger ramp.
errorMessageReactNode—Shown only while error is true.

Behaviour notes

Say what the state means, not just yes or no. trueLabel/falseLabel default to Yes and No, but a switch reads far better when the caption states the consequence — "Carries over" beats "Yes" for anyone arriving at the form cold.

The caption is a <label> for the switch, so clicking the words toggles it. That is a much larger target than the switch itself.