|
| 1 | +import Field from './Field'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import RadioBlocks from '../widgets/RadioBlocks'; |
| 4 | +import React, {Component} from 'react'; |
| 5 | +import {connectToContainer} from '../../lib'; |
| 6 | + |
| 7 | +export default class AxesSelector extends Component { |
| 8 | + constructor(props, context) { |
| 9 | + super(props, context); |
| 10 | + |
| 11 | + if (!props.axesTargetHandler && !context.axesTargetHandler) { |
| 12 | + throw new Error( |
| 13 | + 'AxesSelector must be nested within a connectAxesToPlot component ' + |
| 14 | + 'or passed axesTargetHandler and axesOptions props' |
| 15 | + ); |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + render() { |
| 20 | + let axesTargetHandler, axesOptions, axesTarget; |
| 21 | + if (this.props.axesTargetHandler) { |
| 22 | + axesTargetHandler = this.props.axesTargetHandler; |
| 23 | + axesOptions = this.props.axesOptions; |
| 24 | + axesTarget = this.props.axesTarget; |
| 25 | + } else { |
| 26 | + axesTargetHandler = this.context.axesTargetHandler; |
| 27 | + axesOptions = this.context.axesOptions; |
| 28 | + axesTarget = this.context.axesTarget; |
| 29 | + } |
| 30 | + return ( |
| 31 | + <Field {...this.props}> |
| 32 | + <RadioBlocks |
| 33 | + options={axesOptions} |
| 34 | + activeOption={axesTarget} |
| 35 | + onOptionChange={axesTargetHandler} |
| 36 | + /> |
| 37 | + </Field> |
| 38 | + ); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +AxesSelector.propTypes = { |
| 43 | + axesTargetHandler: PropTypes.func, |
| 44 | + axesOptions: PropTypes.array, |
| 45 | + axesTarget: PropTypes.string, |
| 46 | +}; |
| 47 | + |
| 48 | +AxesSelector.contextTypes = { |
| 49 | + axesTargetHandler: PropTypes.func, |
| 50 | + axesOptions: PropTypes.array, |
| 51 | + axesTarget: PropTypes.string, |
| 52 | +}; |
0 commit comments