Skip to main content

Switch

A custom switch with label, caption & error fields props.

Usage

Enable Awesome Feature
function SwitchUsage() {
return (
<View>
<Switch label="Enable Awesome Feature" />
</View>
)
}

Positions

Left Adjacent Position
Right Adjacent Position
Left Position
Right Position
function SwitchPositions() {
return (
<View>
<Switch
label="Left Adjacent Position"
containerStyle={styles.container}
/>
<Switch
label="Right Adjacent Position"
position="right"
containerStyle={styles.container}
/>
<Switch
label="Left Position"
adjacent={false}
containerStyle={styles.container}
/>
<Switch
label="Right Position"
position="right"
adjacent={false}
containerStyle={styles.container}
/>
</View>
)
}

Status

primary
accent
success
info
warning
error
function SwitchStatuses() {
return (
<View style={{justifyContent: 'space-evenly'}}>
<Switch
status="primary"
label="primary"
containerStyle={styles.container}
/>
<Switch
status="accent"
label="accent"
containerStyle={styles.container}
/>
<Switch
status="success"
label="success"
containerStyle={styles.container}
/>
<Switch status="info" label="info" containerStyle={styles.container} />
<Switch
status="warning"
label="warning"
containerStyle={styles.container}
/>
<Switch status="error" label="error" containerStyle={styles.container} />
</View>
)
}

Size

small
medium
large
function SwitchSizes() {
return (
<View row style={{justifyContent: 'space-evenly'}}>
<Switch label="small" size="small" />
<Switch label="medium" size="medium" />
<Switch label="large" size="large" />
</View>
)
}

Disabled

Disabled
Disabled
Disabled
function SwitchDisabled() {
return (
<View row style={{justifyContent: 'space-evenly'}}>
<Switch size="small" label="Disabled" disabled />
<Switch size="small" label="Disabled" value status="primary" disabled />
<Switch size="small" label="Disabled" disabled />
</View>
)
}

Custom

Agree to T&C
Click here to see Privacy Policy
Custom color switch
function SwitchCustom() {
const [isOn, setIsOn] = useState(true)

return (
<View style={{justifyContent: 'space-evenly'}}>
<Switch
label="Agree to T&C"
caption="Click here to see Privacy Policy"
status="info"
size="large"
adjacent={false}
value={isOn}
onValueChange={setIsOn}
error={isOn ? '' : 'Please Agree to T&C to continue'}
containerStyle={styles.container}
/>
<Switch
label="Custom color switch"
status="info"
color="green"
value={isOn}
size="medium"
onValueChange={setIsOn}
containerStyle={styles.container}
/>
</View>
)
}

const styles = StyleSheet.create({
container: {
marginVertical: 4,
},
label: {
marginEnd: 8,
},
})

Props

PropData TypeDefault ValueDescription
ExtendsSwitchProps$1--Inherits properties from SwitchProps$1
position"left" | "right"rightControl the position of the field
adjacentbooleantrueSet it to false to position them apart i.e. space-between
colorstring--Set custom color
labelstring--Label text above the input
captionstring--Caption text below the text input
errorstring--Error text in error `status` below caption text
containerStyleStyleProp<ViewStyle>--Container view style
labelStyleStyleProp<TextStyle>--Label text style
captionStyleStyleProp<TextStyle>--Caption text style
errorStyleStyleProp<TextStyle>--Error text style
statusBlossomStatusprimary--
sizeBlossomSizemedium--