Default Image

Switch

Switching Selector.

import { Switch } from '@redshank/native';

When To Use

  • If you need to represent the switching between two states or on-off state.
  • The difference between Switch and Checkbox is that Switch will trigger a state change directly when you toggle it, while Checkbox is generally used for state marking, which should work in conjunction with submit operation.

Examples

Default

Default switch element.

Sizes

Sizes switch element.

Bordered

Bordered switch element.

With Icon

With icon switch element.

Variants

With variant switch element.

Error Variant

With error switch element.

APIs

Switch Props

Api props extends from TouchableOpacity

AttributeTypeAccepted valuesDescriptionDefault
activeColorThemeColorThemeColorActive color of the elementinputColor
borderColorThemeColorThemeColorBorder color of the elementprimary
borderedbooleantrue falseShow or not borderColor componentfalse
deactiveColorThemeColorThemeColorColor when switch is falseinputColor
defaultValuebooleantrue falseDefault value of the switch input-
errorbooleantrue falseShow error variant-
iconobjectIconObjectPass icon for deactive and active switch-
onChangefunction(value) => voidOn change function trigger received true or false-
sizeSizeTypesmall middle largeSize of the switch selectormiddle
styleobjectStyleProp<StyleView>Style for the point-
textErrorstringTextMessage of the error, set with error prop in true-
thumbActiveColorThemeColorThemeColorBackground color of the element when is switchableprimary
thumbDisabledColorThemeColorThemeColorBackground color of the element when is not selectedborder
thumbStyleobjectStyleProp<StyleView>Style for the wrapper-
typeSwitchTyperounded squareVariant type for the switchrounded
valuebooleantrue falseValue of the switch input-

IconObject

type IconObject = {
  false: ReactNode,
  true: ReactNode,
}

Community:

We're excited to see the community adopt @redshank/native, raise issues, and provide feedback. Whether it's a feature request, bug report, or a project to showcase, please get involved!

DiscordGithub

Contributing:

PR's on @redshank/native are always welcome, please see our contribution guidelines to learn how you can contribute to this project.

Copyright © 2023 @redshank.