Skip to content

Commit

Permalink
Separate checkbox single and checkbox with text styling (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
iRoachie committed Jan 26, 2018
1 parent 2593e33 commit 7f86fbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 71 deletions.
44 changes: 27 additions & 17 deletions src/checkbox/CheckBox.js
Expand Up @@ -53,7 +53,11 @@ const CheckBox = props => {
{...attributes}
onLongPress={onLongPress}
onPress={onPress}
style={[styles.container, containerStyle && containerStyle]}
style={[
styles.container,
title && styles.containerHasTitle,
containerStyle && containerStyle,
]}
>
<View
style={[
Expand All @@ -62,35 +66,39 @@ const CheckBox = props => {
center && { justifyContent: 'center' },
]}
>
{!iconRight &&
{!iconRight && (
<Icon
color={checked ? checkedColor : uncheckedColor}
name={iconName}
size={size || 24}
onLongPress={onLongIconPress}
onPress={onIconPress}
/>}
/>
)}

{React.isValidElement(title)
? title
: <TextElement
style={[
styles.text,
textStyle && textStyle,
fontFamily && { fontFamily },
]}
>
{checked ? checkedTitle || title : title}
</TextElement>}
: title && (
<TextElement
style={[
styles.text,
textStyle && textStyle,
fontFamily && { fontFamily },
]}
>
{checked ? checkedTitle || title : title}
</TextElement>
)}

{iconRight &&
{iconRight && (
<Icon
color={checked ? checkedColor : uncheckedColor}
name={iconName}
size={size || 24}
onLongPress={onLongIconPress}
onPress={onIconPress}
/>}
/>
)}
</View>
</Component>
);
Expand Down Expand Up @@ -140,11 +148,13 @@ const styles = StyleSheet.create({
margin: 5,
marginLeft: 10,
marginRight: 10,
backgroundColor: '#fafafa',
borderColor: '#ededed',
borderWidth: 1,
padding: 10,
},
containerHasTitle: {
borderWidth: 1,
borderRadius: 3,
backgroundColor: '#fafafa',
borderColor: '#ededed',
},
text: {
marginLeft: 10,
Expand Down
57 changes: 3 additions & 54 deletions src/checkbox/__tests__/__snapshots__/CheckBox.js.snap
Expand Up @@ -7,15 +7,12 @@ exports[`CheckBox Component should render with icon and checked 1`] = `
style={
Array [
Object {
"backgroundColor": "#fafafa",
"borderColor": "#ededed",
"borderRadius": 3,
"borderWidth": 1,
"margin": 5,
"marginLeft": 10,
"marginRight": 10,
"padding": 10,
},
undefined,
Object {
"backgroundColor": "red",
},
Expand All @@ -40,20 +37,6 @@ exports[`CheckBox Component should render with icon and checked 1`] = `
name="square-o"
size={24}
/>
<TextElement
style={
Array [
Object {
"color": "#43484d",
"fontWeight": "bold",
"marginLeft": 10,
"marginRight": 10,
},
undefined,
undefined,
]
}
/>
</View>
</TouchableOpacity>
`;
Expand All @@ -66,16 +49,13 @@ exports[`CheckBox Component should render with icon and iconRight 1`] = `
style={
Array [
Object {
"backgroundColor": "#fafafa",
"borderColor": "#ededed",
"borderRadius": 3,
"borderWidth": 1,
"margin": 5,
"marginLeft": 10,
"marginRight": 10,
"padding": 10,
},
undefined,
undefined,
]
}
>
Expand All @@ -93,20 +73,6 @@ exports[`CheckBox Component should render with icon and iconRight 1`] = `
]
}
>
<TextElement
style={
Array [
Object {
"color": "#43484d",
"fontWeight": "bold",
"marginLeft": 10,
"marginRight": 10,
},
undefined,
undefined,
]
}
/>
<Icon
allowFontScaling={false}
color="blue"
Expand All @@ -124,16 +90,13 @@ exports[`CheckBox Component should render without issues 1`] = `
style={
Array [
Object {
"backgroundColor": "#fafafa",
"borderColor": "#ededed",
"borderRadius": 3,
"borderWidth": 1,
"margin": 5,
"marginLeft": 10,
"marginRight": 10,
"padding": 10,
},
undefined,
undefined,
]
}
>
Expand All @@ -155,20 +118,6 @@ exports[`CheckBox Component should render without issues 1`] = `
name="square-o"
size={24}
/>
<TextElement
style={
Array [
Object {
"color": "#43484d",
"fontWeight": "bold",
"marginLeft": 10,
"marginRight": 10,
},
undefined,
undefined,
]
}
/>
</View>
</TouchableOpacity>
`;

0 comments on commit 7f86fbe

Please sign in to comment.