Skip to content

Switch

A switch allow users to enter data by making a selection between two distinct and opposite states, such as “On” and “Off”.

UX/UI Guidelines

Check the design documentation of the component in ZeroHeight.

Implementations

The component Switch is available in the following technologies:

CSS Components
cssreactvue
Web Components
webreactvueangular

Parameters

Parameters

Parameters are the attributes that can be used to customize the component when using it in a project. They apply to the WebComponents implementation and wrappers and to the Vue and React CSS implementations. Some parameters names change between the implementations, in order to follow the conventions of each technology and framework.

For example, the param model is named ngModel in Angular, modelValue in Vue, but stays as model in React.

By default, all the parameters are optional or can be set in different, except for the ones marked as required

The parametrization of the component can be done with the following custom params or properties:

NameTypeSlottableDescription
labelstringLabel of the input
modelboolean

Value of the model

checkedbooleanOverrides the "value" parameter as in the standard
disabledboolean

Blocks the interaction with the input component by using the disabled attribute of the HTML input element.

requiredboolean

Marks the input component as required. If and interaction is made with the input and the value is nullable or empty, the input will be marked as invalid as using the invalid attribute.

namestring

Identification for the field inside the form.

help-textstring

The forced message to be shown under the input. It is used to give more information about the input, or a message to the user, specially when the input is invalid.

invalidboolean

The attribute that forces the state of the input as invalid.

customobject

A record of key-value pairs to set the CSS custom tokens. It's a complex attribute set as an JS object in stringified JSON format.

Example:

html
<z-switch custom='{"fill":"#06e7a3"}' />
custom-strstring

The stringified version of the custom property. It follows the pattern key:value;key:value;, with the possibility of setting multiple values and spaces between the punctuation characters.

Example:

html
<z-switch custom-str="fill:#06e7a3" />
z-themestring

Sets the theme of the component. The possible values are light and dark.

html
<z-switch z-theme="dark" />

From Figma to code

You can check the Figma implementation here. This are the available properties:

  • Type select
  • State select

Customization

INFO

Check everything about the customization mechanics in the "How it works" documentation.

CSS VariableTypeDescription
--z-switch--thumb--oncolorThe color of the thumb when the switch is on
--z-switch--thumb--offcolorThe color of the thumb when the switch is off

The thumb of the switch can be customized for both states, checked and unchecked, using the --z-switch--thumb--on & --z-switch--thumb--off CSS custom properties, respectively.

Accessibility

...