<vega-item-toggle id="web-item-toggle"></vega-item-toggle>
document.getElementById('web-item-toggle').itemToggleStatusMap = {
unToggledIcon: 'plus-sign',
toggledIcon: 'delete-bin',
unToggledLabel: 'Add',
togglingLabel: 'Added',
toggledLabel: 'Remove',
unTogglingLabel: 'Removed',
};
Note: The above example uses Vanilla JS. If you would like to use React, Angular, or Vue, please consult Storybook.
The vega-item-toggle
is an element which allows adding or removing items from a list. It is generally used in place of a checkbox, when it’s clear that an item should or should not be part of a selection.
In many cases, toggle switches resemble physical switches, such as a light switch, which enables turning an item on and off. However, the vega-item-toggle
more explicitly shows text which identifies whether an item is to be added or removed, interspersed with an animation showing a checkmark identifying whether the action has been completed.
The item toggle has the following states:
Each is interspersed with an animation showing a check mark indicating the action has been completed.
Name | Description | Default |
---|---|---|
item-toggle-status-map | The labels and icons for displaying for toggle. {"unToggledIcon": IconsTokenType, "toggledIcon": IconsTokenType, "unToggledLabel": string, "togglingLabel": string, "toggledLabel": string, "unTogglingLabel": string} |
|
is-toggled | This indicates whether the toggle status is on or off as its default setting. boolean | false |
document.getElementById('web-item-toggle').itemToggleStatusMap = {
unToggledIcon: 'plus-sign',
toggledIcon: 'delete-bin',
unToggledLabel: 'Add',
togglingLabel: 'Added',
toggledLabel: 'Remove',
unTogglingLabel: 'Removed',
};
<vega-item-toggle
id="web-item-toggle"
is-toggled=true|false
>
</vega-item-toggle>
The vegaToggleStatus
event is created on vega-item-toggle
when it is either turned on or off.
Example:
<vega-item-toggle id="toggle"></vega-item-toggle>
<script>
const toggle = document.getElementById("toggle");
toggle.addEventListener("vegaToggleStatus", (e) => { ... })
</script>
For more details, view in Storybook.
Good places to use a Vega item toggle include the following:
It is not recommended to use toggles in places where checkboxes make more sense, such as: