View as Markdown

API reference: @salmonui/inputs/switch

Switchcomponent

import { Switch } from '@salmonui/inputs/switch';
function Switch(props: SwitchProps): ReactNode;

Switch: a native <input type="checkbox" role="switch"> drawn as a track and thumb, labelled by its children. Space toggles; the checked state is the native one. ref is the input; unknown props go to the input, className / style to the root.

Props: SwitchProps

Switch props (18)
NameSignatureDescription
thumbIconoptionalreadonly thumbIcon?: ReactNode;

Icon drawn inside the thumb; decorative.

descriptionoptionalinheriteddescription?: ReactNode;
errorMessageoptionalinheritederrorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) | ReactNode;

Error text (or a function of the errors) shown while the field is invalid.

invalidoptionalinheritedinvalid?: boolean;

Forces the error state.

validationoptionalinheritedvalidation?: FieldValidation;

Rules in the Data Grid vocabulary.

validateOnoptionalinheritedvalidateOn?: ValidateOn;

When errors appear; default the Form's, else 'blur'.

sizeoptionalinheritedsize?: FieldSize;

Metric set. Default 'md'.

checkedoptionalinheritedchecked?: boolean;
defaultCheckedoptionalinheriteddefaultChecked?: boolean;
onCheckedChangeoptionalinheritedonCheckedChange?: ((checked: boolean, details: CheckedChangeDetails) => void);
valueoptionalinheritedvalue?: string;

Submitted value when checked (native, default 'on').

childrenoptionalinheritedchildren?: ReactNode;

Label text (rendered in a real <label for>).

labelPlacementoptionalinheritedlabelPlacement?: LabelPlacement;

Label before ('start') or after ('end', default) the control.

localeTextoptionalinheritedlocaleText?: FieldValidationText;
classNameoptionalinheritedclassName?: string;
styleoptionalinheritedstyle?: CSSProperties;
classNamesoptionalinheritedclassNames?: { readonly input?: string; readonly label?: string; readonly description?: string; readonly error?: string; };

Part classes: root is className; input, label, description, error.

refoptionalinheritedref?: Ref<HTMLInputElement>;

The native <input type="checkbox">.