Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into restore-wallet
- Loading branch information
Showing
4 changed files
with
85 additions
and
79 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,27 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import {withHandlers} from 'recompose' | ||
import {TouchableOpacity, Image} from 'react-native' | ||
|
||
import styles from './styles/Checkbox.style' | ||
import Text from './Text' | ||
import checkIcon from '../../assets/img/check.png' | ||
import checkEmptyIcon from '../../assets/img/check-empty.png' | ||
|
||
import type {ComponentType} from 'react' | ||
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet' | ||
|
||
type Props = { | ||
checked: boolean, | ||
text: string, | ||
handleChange: () => void, | ||
onChange: (checked: boolean) => void, | ||
style?: ViewStyleProp, | ||
testID?: string, | ||
} | ||
const Checkbox = ({checked, text, handleChange, style, testID}: Props) => ( | ||
<TouchableOpacity style={[styles.container, style]} onPress={handleChange} testID={testID}> | ||
const Checkbox = ({checked, text, onChange, style, testID}: Props) => ( | ||
<TouchableOpacity style={[styles.container, style]} onPress={() => onChange(!checked)} testID={testID}> | ||
<Image source={checked ? checkIcon : checkEmptyIcon} /> | ||
<Text style={styles.text}>{text}</Text> | ||
</TouchableOpacity> | ||
) | ||
|
||
type ExternalProps = { | ||
checked: boolean, | ||
text: string, | ||
onChange: (checked: boolean) => void, | ||
style?: Object, | ||
testID?: string, | ||
} | ||
|
||
export default (withHandlers({ | ||
handleChange: | ||
({onChange, checked}) => | ||
() => | ||
onChange(!checked), | ||
})(Checkbox): ComponentType<ExternalProps>) | ||
export default Checkbox |
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,36 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import {StyleSheet, View} from 'react-native' | ||
|
||
import {storiesOf} from '@storybook/react-native' | ||
import {action} from '@storybook/addon-actions' | ||
|
||
import Checkbox from './Checkbox' | ||
|
||
const styles = StyleSheet.create({ | ||
checkbox: { | ||
padding: 16, | ||
justifyContent: 'center', | ||
flex: 1, | ||
}, | ||
}) | ||
|
||
const CheckboxWrapper = () => { | ||
const [checked, setChecked] = React.useState(false) | ||
|
||
return ( | ||
<Checkbox | ||
text={checked ? 'this is the checked text' : 'this is the unchecked text'} | ||
checked={checked} | ||
onChange={(value) => { | ||
action('checked')(value) | ||
setChecked(value) | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
storiesOf('Checkbox', module) | ||
.addDecorator((getStory) => <View style={styles.checkbox}>{getStory()}</View>) | ||
.add('default', () => <CheckboxWrapper />) |