Skip to content
Snippets Groups Projects
Commit 2ec6626b authored by Julia Friesel's avatar Julia Friesel
Browse files

Use select box group instead of single select boxes

parent 71af282d
No related branches found
No related tags found
No related merge requests found
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 (
<View flexDirection='row' flexWrap='wrap'>
{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 (
<TouchableOpacity
onPress={() => this.props.onSelect(stateKey)}
key={stateKey}
>
<View style={style}>
<AppText style={textStyle}>{label}</AppText>
</View>
</TouchableOpacity>
)
})}
</View>
)
}
}
\ No newline at end of file
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 (
<TouchableOpacity onPress={this.props.onPress}>
<View style={style}>
<AppText style={textStyle}>{this.props.children}</AppText>
</View>
</TouchableOpacity>
)
}
}
\ No newline at end of file
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
contraceptives as contraceptiveLabels contraceptives as contraceptiveLabels
} from '../labels/labels' } from '../labels/labels'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
import SelectBox from '../select-box' import SelectBoxGroup from '../select-box-group'
import { SymptomSectionHeader } from '../../app-text' import { SymptomSectionHeader } from '../../app-text'
const sexBoxes = [{ const sexBoxes = [{
...@@ -40,6 +40,9 @@ const contraceptiveBoxes = [{ ...@@ -40,6 +40,9 @@ const contraceptiveBoxes = [{
}, { }, {
label: contraceptiveLabels.implant, label: contraceptiveLabels.implant,
stateKey: 'implant' stateKey: 'implant'
}, {
label: contraceptiveLabels.other,
stateKey: 'other'
}] }]
export default class Sex extends Component { export default class Sex extends Component {
...@@ -57,23 +60,12 @@ export default class Sex extends Component { ...@@ -57,23 +60,12 @@ export default class Sex extends Component {
} }
} }
makeSelectBoxes(boxes) { toggleState = (key) => {
return boxes.map(({ label, stateKey }) => {
return (
<SelectBox
value={this.state[stateKey]}
onPress={() => this.toggleState(stateKey)}
key={stateKey}
>
{label}
</SelectBox>
)
})
}
toggleState(key) {
const curr = this.state[key] const curr = this.state[key]
this.setState({[key]: !curr}) this.setState({[key]: !curr})
if (key === 'other' && !curr) {
this.setState({focusTextArea: true})
}
} }
render() { render() {
...@@ -81,18 +73,17 @@ export default class Sex extends Component { ...@@ -81,18 +73,17 @@ export default class Sex extends Component {
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<ScrollView style={styles.page}> <ScrollView style={styles.page}>
<SymptomSectionHeader>Activity</SymptomSectionHeader> <SymptomSectionHeader>Activity</SymptomSectionHeader>
{this.makeSelectBoxes(sexBoxes)} <SelectBoxGroup
data={sexBoxes}
onSelect={this.toggleState}
optionsState={this.state}
/>
<SymptomSectionHeader>Contraceptives</SymptomSectionHeader> <SymptomSectionHeader>Contraceptives</SymptomSectionHeader>
{this.makeSelectBoxes(contraceptiveBoxes)} <SelectBoxGroup
<SelectBox data={contraceptiveBoxes}
value={this.state.other} onSelect={this.toggleState}
onPress={() => { optionsState={this.state}
this.toggleState('other') />
this.setState({ focusTextArea: true })
}}
>
{contraceptiveLabels.other}
</SelectBox>
{this.state.other && {this.state.other &&
<TextInput <TextInput
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment