# Switch Toggle component allows users to switch between two states typically representing on/off, enabled/disabled, or active/inactive settings. Toggles provide a quick and intuitive way to modify system or feature preferences with a single action. **Category:** Components **Storybook:** https://doc.ux4g.gov.in/web/?path=/story/ux4g-components-switch--introduction ## Framework setup ### HTML / CDN ```html ``` ### React ```bash npm install ux4g-web-components ``` ```jsx import 'ux4g-web-components/styles.css'; import 'ux4g-web-components/design-system'; ``` ### Angular Update `angular.json`: ```json { "styles": [ "node_modules/ux4g-web-components/styles/ux4g.css", "src/styles.css" ], "scripts": [ "node_modules/ux4g-web-components/dist/runtime/design-system.js" ] } ``` ## Code examples The snippets below are extracted from the Storybook canvas for Switch. Each example shows the rendered HTML, the equivalent React JSX, and the Angular template markup. ### 1. Description Variants — Description Variants HTML: ```html ``` React: ```jsx import React from 'react'; const SwitchExample1Demo = () => ( <> {/* Description: Helper */} {/* Description: Error */} {/* Description: Warning */} {/* Description: Success */} > ); export default SwitchExample1Demo; ``` Angular: ```html ``` ### 2. Introduction — Introduction HTML: ```html
Toggle component allows users to switch between two states typically representing on/off, enabled/disabled, or active/inactive settings. Toggles provide a quick and intuitive way to modify system or feature preferences with a single action.
Live previews taken directly from the switch states matrix in src/index.html.
Large, medium, and small switch sizes from the source component section.
Full, required, label-only, and control-only variants from the switch showcase.
Helper, error, warning, and success descriptions using source-backed switch description classes.
Whole-row toggle and switch-only toggle patterns from the list-switch source block.
Quickly copy the classes used by the showcased Switch variants.
|
Switch wrapper
ux4g-switch
|
|
Native checkbox input
ux4g-switch-input
|
|
Control wrapper
ux4g-switch-control
|
|
Track element
ux4g-switch-track
|
|
Thumb element
ux4g-switch-thumb
|
|
Content wrapper
ux4g-switch-content
|
|
Header row
ux4g-switch-header
|
|
Label text
ux4g-switch-label
|
|
Description text row
ux4g-switch-description
|
|
Large size
ux4g-switch-lg
|
|
Medium size
ux4g-switch-md
|
|
Small size
ux4g-switch-sm
|
|
Required marker
ux4g-switch-required
|
|
Icon treatment
ux4g-switch-icon
|
|
Helper description
ux4g-switch-desc-helper
|
|
Error description
ux4g-switch-desc-error
|
|
Warning description
ux4g-switch-desc-warning
|
|
Success description
ux4g-switch-desc-success
|
|
List switch layout
ux4g-list-switch
|
|
Whole-row switch pattern
ux4g-list-switch-select
|
Toggle component allows users to switch between two states typically representing on/off, enabled/disabled, or active/inactive settings. Toggles provide a quick and intuitive way to modify system or feature preferences with a single action.
Live previews taken directly from the switch states matrix in
src/index.html
.
Large, medium, and small switch sizes from the source component section.
Full, required, label-only, and control-only variants from the switch showcase.
Helper, error, warning, and success descriptions using source-backed switch description classes.
Whole-row toggle and switch-only toggle patterns from the list-switch source block.
Quickly copy the classes used by the showcased Switch variants.
|
Switch wrapper
ux4g-switch
|
|
Native checkbox input
ux4g-switch-input
|
|
Control wrapper
ux4g-switch-control
|
|
Track element
ux4g-switch-track
|
|
Thumb element
ux4g-switch-thumb
|
|
Content wrapper
ux4g-switch-content
|
|
Header row
ux4g-switch-header
|
|
Label text
ux4g-switch-label
|
|
Description text row
ux4g-switch-description
|
|
Large size
ux4g-switch-lg
|
|
Medium size
ux4g-switch-md
|
|
Small size
ux4g-switch-sm
|
|
Required marker
ux4g-switch-required
|
|
Icon treatment
ux4g-switch-icon
|
|
Helper description
ux4g-switch-desc-helper
|
|
Error description
ux4g-switch-desc-error
|
|
Warning description
ux4g-switch-desc-warning
|
|
Success description
ux4g-switch-desc-success
|
|
List switch layout
ux4g-list-switch
|
|
Whole-row switch pattern
ux4g-list-switch-select
|
Toggle component allows users to switch between two states typically representing on/off, enabled/disabled, or active/inactive settings. Toggles provide a quick and intuitive way to modify system or feature preferences with a single action.
Live previews taken directly from the switch states matrix in src/index.html.
Large, medium, and small switch sizes from the source component section.
Full, required, label-only, and control-only variants from the switch showcase.
Helper, error, warning, and success descriptions using source-backed switch description classes.
Whole-row toggle and switch-only toggle patterns from the list-switch source block.
Quickly copy the classes used by the showcased Switch variants.
|
Switch wrapper
ux4g-switch
|
|
Native checkbox input
ux4g-switch-input
|
|
Control wrapper
ux4g-switch-control
|
|
Track element
ux4g-switch-track
|
|
Thumb element
ux4g-switch-thumb
|
|
Content wrapper
ux4g-switch-content
|
|
Header row
ux4g-switch-header
|
|
Label text
ux4g-switch-label
|
|
Description text row
ux4g-switch-description
|
|
Large size
ux4g-switch-lg
|
|
Medium size
ux4g-switch-md
|
|
Small size
ux4g-switch-sm
|
|
Required marker
ux4g-switch-required
|
|
Icon treatment
ux4g-switch-icon
|
|
Helper description
ux4g-switch-desc-helper
|
|
Error description
ux4g-switch-desc-error
|
|
Warning description
ux4g-switch-desc-warning
|
|
Success description
ux4g-switch-desc-success
|
|
List switch layout
ux4g-list-switch
|
|
Whole-row switch pattern
ux4g-list-switch-select
|