Fix Gas Price Selector Tooltips (#4865)

This commit is contained in:
Nicolas Gotchac 2017-03-11 15:25:27 +01:00 committed by Gav Wood
parent 5684906d3e
commit 96f4033a40
2 changed files with 33 additions and 3 deletions

View File

@ -19,12 +19,17 @@ import { FormattedMessage } from 'react-intl';
export default class CustomTooltip extends Component { export default class CustomTooltip extends Component {
static propTypes = { static propTypes = {
active: PropTypes.bool,
histogram: PropTypes.object.isRequired, histogram: PropTypes.object.isRequired,
intl: PropTypes.object.isRequired,
active: PropTypes.bool,
label: PropTypes.number, label: PropTypes.number,
payload: PropTypes.array, payload: PropTypes.array,
type: PropTypes.string type: PropTypes.string
} };
static childContextTypes = {
intl: PropTypes.object.isRequired
};
render () { render () {
const { active, label, histogram } = this.props; const { active, label, histogram } = this.props;
@ -55,4 +60,8 @@ export default class CustomTooltip extends Component {
</div> </div>
); );
} }
getChildContext () {
return { intl: this.props.intl };
}
} }

View File

@ -36,6 +36,10 @@ const TOOL_STYLE = {
}; };
export default class GasPriceSelector extends Component { export default class GasPriceSelector extends Component {
static contextTypes = {
intl: PropTypes.object.isRequired
};
static propTypes = { static propTypes = {
histogram: PropTypes.object.isRequired, histogram: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
@ -145,7 +149,7 @@ export default class GasPriceSelector extends Component {
shape={ <CustomBar selected={ selectedIndex } onClick={ this.onClickprice } /> }stroke={ COLORS.line } shape={ <CustomBar selected={ selectedIndex } onClick={ this.onClickprice } /> }stroke={ COLORS.line }
/> />
<Tooltip <Tooltip
content={ <CustomTooltip histogram={ histogram } /> } content={ this.tooltipContentRenderer }
cursor={ this.renderCustomCursor() } cursor={ this.renderCustomCursor() }
wrapperStyle={ TOOL_STYLE } wrapperStyle={ TOOL_STYLE }
/> />
@ -168,6 +172,23 @@ export default class GasPriceSelector extends Component {
); );
} }
/**
* Passing the `intl` object as a prop
* so the CustomTooltip can add for child
* context (used by FormattedMessages)
*/
tooltipContentRenderer = (props) => {
const { histogram } = this.props;
return (
<CustomTooltip
histogram={ histogram }
intl={ this.context.intl }
{ ...props }
/>
);
}
renderSlider () { renderSlider () {
const { sliderValue } = this.state; const { sliderValue } = this.state;