| 12 | const modalSpecificProps = ['visible', 'onClose']; |
| 13 | |
| 14 | class DropDownMenu extends PureComponent { |
| 15 | constructor(props) { |
| 16 | super(props); |
| 17 | |
| 18 | autoBindReact(this); |
| 19 | |
| 20 | this.state = { |
| 21 | collapsed: false, |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | getSelectedOption() { |
| 26 | const { options, selectedOption } = this.props; |
| 27 | if (_.indexOf(options, selectedOption) === -1) { |
| 28 | // eslint-disable-next-line no-console |
| 29 | console.warn( |
| 30 | `Invalid \`selectedOption\` ${JSON.stringify(selectedOption)}, ` + |
| 31 | 'DropDownMenu `selectedOption` must be a member of `options`.' + |
| 32 | 'Check that you are using the same reference in both `options` and `selectedOption`.', |
| 33 | ); |
| 34 | |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | return selectedOption; |
| 39 | } |
| 40 | |
| 41 | collapse() { |
| 42 | this.setState({ collapsed: true }); |
| 43 | } |
| 44 | |
| 45 | close() { |
| 46 | this.setState({ collapsed: false }); |
| 47 | } |
| 48 | |
| 49 | renderSelectedOption() { |
| 50 | const { iconName, showSelectedOption, style, titleProperty } = this.props; |
| 51 | |
| 52 | const selectedOption = this.getSelectedOption(); |
| 53 | return selectedOption ? ( |
| 54 | <View style={style.horizontalContainer}> |
| 55 | <Button onPress={this.collapse} style={style.selectedOption}> |
| 56 | {showSelectedOption && <Text>{selectedOption[titleProperty]}</Text>} |
| 57 | <Icon name={iconName} style={style.icon} /> |
| 58 | </Button> |
| 59 | </View> |
| 60 | ) : null; |
| 61 | } |
| 62 | |
| 63 | render() { |
| 64 | const { collapsed } = this.state; |
| 65 | const { options } = this.props; |
| 66 | |
| 67 | const button = this.renderSelectedOption(); |
| 68 | if (_.size(options) === 0 || !button) { |
| 69 | return null; |
| 70 | } |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected