import classNames from 'classnames'; import { action, makeObservable, observable } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { ButtonGroup } from 'react-bootstrap'; interface IAxisScaleSwitchProps { onChange: (selectedScale: AxisScale) => void; selectedScale: AxisScale; } export enum AxisScale { PERCENT = '%', COUNT = '#', } @observer export class AxisScaleSwitch extends React.Component< IAxisScaleSwitchProps, {} > { public static defaultProps: Partial = { selectedScale: AxisScale.COUNT, }; @observable private selectedScale: AxisScale; constructor(props: IAxisScaleSwitchProps) { super(props); this.selectedScale = props.selectedScale; makeObservable(this); } public toggleButton(scale: AxisScale, onClick: () => void) { return ( ); } public render() { return ( {this.toggleButton(AxisScale.PERCENT, this.handlePercentClick)} {this.toggleButton(AxisScale.COUNT, this.handleCountClick)} ); } @action.bound private handlePercentClick() { this.selectedScale = AxisScale.PERCENT; this.props.onChange(this.selectedScale); } @action.bound private handleCountClick() { this.selectedScale = AxisScale.COUNT; this.props.onChange(this.selectedScale); } }