diff --git a/components/cycle-day/select-box-group.js b/components/cycle-day/select-box-group.js new file mode 100644 index 0000000..bde9177 --- /dev/null +++ b/components/cycle-day/select-box-group.js @@ -0,0 +1,34 @@ +import React, { Component } from 'react' +import { + View, + TouchableOpacity, +} from 'react-native' +import styles from '../../styles' +import { AppText } from '../app-text' + +export default class SelectBoxGroup extends Component { + render() { + return ( + + {this.props.data.map(({ label, stateKey }) => { + const style = [styles.selectBox] + const textStyle = [] + if (this.props.optionsState[stateKey]) { + style.push(styles.selectBoxActive) + textStyle.push(styles.selectBoxTextActive) + } + return ( + this.props.onSelect(stateKey)} + key={stateKey} + > + + {label} + + + ) + })} + + ) + } +} \ No newline at end of file diff --git a/components/cycle-day/select-box.js b/components/cycle-day/select-box.js deleted file mode 100644 index 62daece..0000000 --- a/components/cycle-day/select-box.js +++ /dev/null @@ -1,25 +0,0 @@ -import React, { Component } from 'react' -import { - View, - TouchableOpacity, -} from 'react-native' -import styles from '../../styles' -import { AppText } from '../app-text' - -export default class SelectBox extends Component { - render () { - const style = [styles.selectBox] - const textStyle = [] - if (this.props.value) { - style.push(styles.selectBoxActive) - textStyle.push(styles.selectBoxTextActive) - } - return ( - - - {this.props.children} - - - ) - } -} \ No newline at end of file diff --git a/components/cycle-day/symptoms/sex.js b/components/cycle-day/symptoms/sex.js index 248ef40..0019eb4 100644 --- a/components/cycle-day/symptoms/sex.js +++ b/components/cycle-day/symptoms/sex.js @@ -11,7 +11,7 @@ import { contraceptives as contraceptiveLabels } from '../labels/labels' import ActionButtonFooter from './action-button-footer' -import SelectBox from '../select-box' +import SelectBoxGroup from '../select-box-group' import { SymptomSectionHeader } from '../../app-text' const sexBoxes = [{ @@ -40,6 +40,9 @@ const contraceptiveBoxes = [{ }, { label: contraceptiveLabels.implant, stateKey: 'implant' +}, { + label: contraceptiveLabels.other, + stateKey: 'other' }] export default class Sex extends Component { @@ -57,23 +60,12 @@ export default class Sex extends Component { } } - makeSelectBoxes(boxes) { - return boxes.map(({ label, stateKey }) => { - return ( - this.toggleState(stateKey)} - key={stateKey} - > - {label} - - ) - }) - } - - toggleState(key) { + toggleState = (key) => { const curr = this.state[key] this.setState({[key]: !curr}) + if (key === 'other' && !curr) { + this.setState({focusTextArea: true}) + } } render() { @@ -81,18 +73,17 @@ export default class Sex extends Component { Activity - {this.makeSelectBoxes(sexBoxes)} + Contraceptives - {this.makeSelectBoxes(contraceptiveBoxes)} - { - this.toggleState('other') - this.setState({ focusTextArea: true }) - }} - > - {contraceptiveLabels.other} - + {this.state.other &&