Switch
Introduction
The Switch component is a toggle switch that allows users to choose between two mutually exclusive states (on/off, true/false, enabled/disabled). It provides a visual alternative to checkboxes for binary choices, often used for settings, preferences, or feature toggles. The component features Mantine styling with smooth transitions.
The Switch component is based on Mantine Switch. It is included within the following NPM package: @react-form-builder/components-mantine.
The Switch component can be styled and configured to fit specific design and functionality requirements by using various properties that are presented and described below.
Main properties
The following general properties are available within the Main tab:
| Name | Type | Description |
|---|---|---|
| Label | string | Text displayed next to the switch |
| Checked | boolean | Sets the initial state (true = on, false = off) (uncontrolled value) |
| Label position | 'left' | 'right' | Position of the label relative to the switch |
| Description | string | Helper text below the switch |
| Size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | The size of the switch |
| Color | string | Mantine theme color when checked |
| Disabled | boolean | Disables the switch |
| With thumb indicator | boolean | If true, shows an indicator on the thumb |
| On label | string | Label text when switch is on |
| Off label | string | Label text when switch is off |
| On change | event | Fired when the checked state changes |
At the bottom of the Main properties menu, you can find additional options:
- Render When: Provides conditional rendering for your component as described in the corresponding chapter.
- HTML attributes: Allows you to provide custom HTML attributes for your form.
Style properties
These are properties that allow to customize the size, color and other style properties of your component:
- For Device: You can provide component's style customization for all devices or specific devices by using this dropdown list. Refer to Adaptive Layout for more details.
- Component > Class Name: Add a class name for your component for the subsequent styling if necessary.
-
Wrapper: The options below enable you to tailor the appearance of your component and customize it for a specific device type, as selected in the For Device property:
Name Type Description Width numberSpecifies the width for your component Height numberSpecifies the height for your component Margin top/right/bottom/left numberMargin values for you component Color stringAllows customizing the text color Background color stringEnables customizing the background color