-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:janis-commerce/ui-native into APP…
…SRN-340-implementación-del-componente-typography
- Loading branch information
Showing
25 changed files
with
902 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,8 @@ dist/ | |
|
||
# Static storybook page | ||
.storybook_static | ||
.docs | ||
.docs | ||
|
||
# Environments handler | ||
/env.json | ||
.env |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
src/components/molecules/ItemSelectionButton/index.test.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import {create} from 'react-test-renderer'; | ||
import ItemSelectionButton from './index'; | ||
import CheckBox from 'atoms/CheckBox'; | ||
import RadioButton from 'atoms/RadioButton'; | ||
import {TouchableOpacity} from 'react-native'; | ||
|
||
describe('ItemSelectionButton component', () => { | ||
describe('does not render', () => { | ||
it('as name prop is not passed', () => { | ||
const {toJSON} = create(<ItemSelectionButton name="" />); | ||
|
||
expect(toJSON()).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should render with checkbox at the right', () => { | ||
const ItemSelectionButtonComp = create( | ||
<ItemSelectionButton name="Warehouse" rightSelection /> | ||
).root; | ||
const CheckboxComp = ItemSelectionButtonComp.findByType(CheckBox); | ||
|
||
expect(CheckboxComp).toBeTruthy(); | ||
}); | ||
|
||
it('should render with checkbox at the left and press it', () => { | ||
const ItemSelectionButtonComp = create( | ||
<ItemSelectionButton name="Warehouse" leftSelection /> | ||
).root; | ||
|
||
const Touchable = ItemSelectionButtonComp.findByType(TouchableOpacity); | ||
const {onPress: onSelection} = Touchable.props; | ||
|
||
onSelection(); | ||
|
||
const CheckboxComp = ItemSelectionButtonComp.findByType(CheckBox); | ||
|
||
expect(CheckboxComp).toBeTruthy(); | ||
}); | ||
|
||
it('should render with radioButton at the right', () => { | ||
const ItemSelectionButtonComp = create( | ||
<ItemSelectionButton name="Warehouse" radioButton rightSelection /> | ||
).root; | ||
const RadioButtonComp = ItemSelectionButtonComp.findByType(RadioButton); | ||
|
||
expect(RadioButtonComp).toBeTruthy(); | ||
}); | ||
|
||
it('should render with radioButton at the left', () => { | ||
const ItemSelectionButtonComp = create( | ||
<ItemSelectionButton name="Warehouse" radioButton leftSelection /> | ||
).root; | ||
const RadioButtonComp = ItemSelectionButtonComp.findByType(RadioButton); | ||
|
||
expect(RadioButtonComp).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React from 'react'; | ||
import RadioButton from 'atoms/RadioButton'; | ||
import CheckBox from 'atoms/CheckBox'; | ||
import {StyleSheet, TouchableOpacity, View} from 'react-native'; | ||
import Text from 'atoms/Text'; | ||
import {palette} from 'theme/palette'; | ||
import {horizontalScale, moderateScale, scaledForDevice, verticalScale} from 'scale'; | ||
|
||
export interface ItemSelectionButtonProps { | ||
name: string; | ||
selected?: boolean; | ||
radioButton?: boolean; | ||
leftSelection?: boolean; | ||
rightSelection?: boolean; | ||
onSelection?: () => {}; | ||
} | ||
|
||
const validPaddingHorizontal = scaledForDevice(16, horizontalScale); | ||
const validMarginVertical = scaledForDevice(13, moderateScale); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
justifyContent: 'center', | ||
}, | ||
radioButtonContainer: { | ||
display: 'flex', | ||
height: verticalScale(48), | ||
borderRadius: verticalScale(4), | ||
}, | ||
checkBoxContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
paddingHorizontal: validPaddingHorizontal, | ||
marginVertical: validMarginVertical, | ||
alignItems: 'center', | ||
height: 'auto', | ||
}, | ||
text: { | ||
fontSize: 16, | ||
fontWeight: '400', | ||
color: palette.black.main, | ||
textTransform: 'capitalize', | ||
}, | ||
separator: { | ||
alignSelf: 'center', | ||
borderBottomColor: palette.grey[200], | ||
borderBottomWidth: verticalScale(1), | ||
width: '90%', | ||
}, | ||
}); | ||
|
||
const ItemSelectionButton: React.FC<ItemSelectionButtonProps> = ({ | ||
name, | ||
selected = false, | ||
radioButton = false, | ||
leftSelection = false, | ||
rightSelection = false, | ||
onSelection = () => {}, | ||
}) => { | ||
if (!name) { | ||
return null; | ||
} | ||
|
||
const checkPosition = rightSelection || (!rightSelection && !leftSelection) ? 'right' : 'left'; | ||
|
||
const renderSelectionComponent = () => { | ||
if (!radioButton) { | ||
return <CheckBox onPress={onSelection as () => {}} checked={selected} customSize={24} />; | ||
} | ||
|
||
return ( | ||
<RadioButton | ||
onPress={onSelection as () => {}} | ||
selected={selected} | ||
checkPosition={checkPosition} | ||
checkSize="md"> | ||
<Text style={styles.text}>{name}</Text> | ||
</RadioButton> | ||
); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<TouchableOpacity | ||
style={[ | ||
radioButton && styles.radioButtonContainer, | ||
!radioButton && styles.checkBoxContainer, | ||
]} | ||
onPress={onSelection}> | ||
{leftSelection && !rightSelection && renderSelectionComponent()} | ||
{!radioButton && <Text style={styles.text}>{name}</Text>} | ||
{((rightSelection && !leftSelection) || (!rightSelection && !leftSelection)) && | ||
renderSelectionComponent()} | ||
</TouchableOpacity> | ||
<View style={styles.separator} /> | ||
</View> | ||
); | ||
}; | ||
|
||
export default ItemSelectionButton; |
Oops, something went wrong.