Created
May 14, 2021 00:26
-
-
Save iaurg/6278a9629e2f9bbd74aca9e14513a718 to your computer and use it in GitHub Desktop.
CheckBox component React Native pure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Feather } from '@expo/vector-icons'; | |
import { View, TouchableOpacity, Text, StyleSheet } from 'react-native'; | |
type CheckboxProps = { | |
label: string, | |
labelStyle: object, | |
iconColor: string, | |
onChange: () => void, | |
value: boolean, | |
checkColor: string | |
} | |
export default function CheckBox({ label, onChange, checkColor, iconColor, value, labelStyle }: CheckboxProps) { | |
return ( | |
<View style={styles.wrapperCheckBox}> | |
<TouchableOpacity onPress={onChange} style={[ | |
styles.checkBox, | |
{ borderColor: checkColor ? checkColor : '#fff' } | |
]}> | |
{ | |
value ? <Feather name="check" | |
style={{ | |
fontSize: 16, | |
color: iconColor ? iconColor : '#fff' | |
}} | |
/> : null | |
} | |
</TouchableOpacity> | |
<Text style={[styles.labelCheck, labelStyle]}> | |
{label} | |
</Text> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
checkBox: { | |
width: 25, | |
height: 25, | |
borderWidth: 1, | |
borderColor: '#000', | |
justifyContent: "center", | |
alignItems: "center" | |
}, | |
wrapperCheckBox: { | |
flexDirection: "row", | |
alignItems: "center" | |
}, | |
labelCheck: { | |
color: '#fff', | |
marginLeft: 6 | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment