You are currently viewing outdated (<=3.x) Chameleon documentation on our old website. For version >=4.x, check out our new website.

Current release: 3.5.0 | hub

components

Switch (code)

Switches toggle the state of a single setting on or off.

Game mode
Zelda
import { LinkText } from '@mediahuis/chameleon-react'

Props

NameTypeDefaultRequiredDescription
actionNode--Contents displayed within the ActionLabel.
checkedBoolean--Sets the native checkbox checked state.
classNameString--Extend classNames.
disabledBoolean--Sets the native checkbox disabled state.
errorBoolean--Visually displayed as error. Will add the necessary accessibility tags.
idString-trueNative HTML id attribute. Will also affect the label-id, and the message-id. For accessibility reasons.
labelNode-trueContents displayed within the PrimaryLabel.
labelHiddenBoolean--Visibly hide the label. (label is still required for a11y)
labelPlacement'left''right''left'-The placement of the label.
labelProps{ "color": "String" "decoration": "'inherit''none''underline''line-through'" "fontFamily": "'inherit''primary''secondary''system'" "fontWeight": "'inherit''regular''medium''bold'" "size": "'Heading1''Heading2''Heading3''Heading4''Heading5''Heading6''Caption1''Caption2'" "textTransform": "'inherit''none''capitalize''uppercase''lowercase'" }--Props passed to the label component, the API may change in the future.
messageString--Contents displayed beneath the label.
onChangeFunction--Native change event, validate on event.target.checked.
optionalLabelString--Contents displayed within the OptionalLabel.
requiredBoolean--Sets native input required attribute.
valueString--Native input value.

System Props

System Props

Next to the properties listed in the propstable, a collection of system props can be added to any component for further general styling and layouting purposes. These props vary per component.

To read more about the system, click here to check out its dedicated page.

Action

default: undefined

Adds an action or extra information to your item, mostly used for links.

Checked

default: undefined

Make a Switch selected by passing the checked prop.

Label

Disabled

default: undefined

Marking a Switch as disabled, will disable all interaction with the element.

Label

Error

default: undefined

To convey an error to the user, you can set the error prop to true.

Label

LabelHidden

default: undefined

To meet accessibility requirements, every Switch should have an associated label. We do support the ability to visually hide the label when the Switch's purpose is clear.

Label

LabelPlacement

default: undefined

The positioning of the label against the switch itself. The full label will move position (also action, message & optionalLabel).

Undefined
Left
Right

LabelProps

default: undefined

You can visually change the label of the Switch. For more info about the possibilities, check the Text component's documentation (Label inherits the Text).

Label

Message

default: undefined

Give additional information to the user.

Label
Message can be set to provide additional information.

OptionalLabel

default: undefined

Compared with TextField, the Switch is not required by default. The optionalLabel is additional feedback to the user, please provide it where needed.

Label(I'm optional)

Required

default: undefined

Make the field required if needed. If you already added optionalLabel, the field will stay optional to not confuse the user.

Label

Value

default: undefined

Use value for controlled Switches.

Label 1
Label 2

© Copyright 2020 Mediahuis NV. All rights Reserved