Toggle Switch
Thales Design System global CSS styles library - Toggle Switch Notice
Size
You can change size
attribute between small
, medium
and large
. By default, the size is on medium
<QtmToggleSwitch size="small">Small</QtmToggleSwitch>
<QtmToggleSwitch size="medium">Mid</QtmToggleSwitch>
<QtmToggleSwitch size="large">Large</QtmToggleSwitch>
Colors
The toggle switch are available in two colors neutral
and primary
. The default color of a checked toggle switch is the primary color.
Primary color
Neutral color
<QtmToggleSwitch checked>Default color</QtmToggleSwitch>
<QtmToggleSwitch checked color="primary">Primary color</QtmToggleSwitch>
<QtmToggleSwitch checked color="neutral">Neutral color</QtmToggleSwitch>
Disabled switch
Add disabled
to the toggle switch to disable this element.
<QtmToggleSwitch disabled>Label</QtmToggleSwitch>
Label on the right
You may want to set the toggle switch on the right. For that, you have to set labelPosition
attribute to right
. By default, the toggle switch has labelPosition="left"
<QtmToggleSwitch>default</QtmToggleSwitch>
<QtmToggleSwitch labelPosition="left">left</QtmToggleSwitch>
<QtmToggleSwitch labelPosition="right">right</QtmToggleSwitch>
An icon in the switch
You have the possibility to display icon in the switch. For that, you have to add displayIcon
attribute to your toggle switch
Label
Label
<QtmToggleSwitch size="small" displayIcon>Label</QtmToggleSwitch>
<QtmToggleSwitch displayIcon>Label</QtmToggleSwitch>
<QtmToggleSwitch size="large" displayIcon>Label</QtmToggleSwitch>
By default, icons are a cross and a thickle. You can change that by adding properties below:
iconOn
with a name of the icon when the switch is toggle "on"iconOff
with a name of the icon when the switch is toggle "off"
We are using the icon of material design for now. To know the name of the icon, please go to the material icon website here
Label
Label
<QtmToggleSwitch color="primary" displayIcon iconOn="lock_open" iconOff="lock">Label<QtmToggleSwitch>
<QtmToggleSwitch color="neutral" displayIcon iconOn="face" iconOff="group">Label<QtmToggleSwitch>
Checked
You can control a toggle switch by using checked
attribute.
Primary
Neutral
<QtmToggleSwitch checked color="primary">Primary</QtmToggleSwitch>
<QtmToggleSwitch checked color="neutral">Neutral</QtmToggleSwitch>
API
QtmToggleSwitch
Property | Type | Default | Description |
---|---|---|---|
checked | boolean | false | If true, the toggle is checked. |
classes | string | '' | list of classes to override or extend the styles applied to the component. You can use available utility classes by importing |
color | "neutral" | "primary" | 'primary' | The color of the toggle switch |
defaultChecked | boolean | false | If true, the component is checked by default. |
disabled | boolean | false | If true, the component is disabled. |
displayIcon | boolean | false | If we want the icon displayed on the toggle |
iconOff | string | The icon on the left side when toggle is switched off. You can find the icon name on material icon. You have to set the icon displayed | |
iconOn | string | The icon on the right side when toggle is switched on. You can find the icon name on material icon. You have to set the icon displayed | |
inputId | string | input id of the toggle switch | |
labelPosition | "" | "left" | "right" | '' | The position of the label |
name | string | Name of the toggle switch | |
size | "large" | "medium" | "small" | 'medium' | The size of the toggle switch |
Event | Type | Description |
---|---|---|
onValueChanged | CustomEvent<ToggleSwitchDetail> | Callback fired when the value is changed through the user interface. You can pull out the new value by accessing event.detail |