GaugeOptionsEditor.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React, { PureComponent } from 'react';
  2. import { FormField, PanelOptionsProps, PanelOptionsGroup, Switch } from '@grafana/ui';
  3. import { GaugeOptions } from './types';
  4. export default class GaugeOptionsEditor extends PureComponent<PanelOptionsProps<GaugeOptions>> {
  5. onToggleThresholdLabels = () =>
  6. this.props.onChange({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels });
  7. onToggleThresholdMarkers = () =>
  8. this.props.onChange({ ...this.props.options, showThresholdMarkers: !this.props.options.showThresholdMarkers });
  9. onMinValueChange = ({ target }) => this.props.onChange({ ...this.props.options, minValue: target.value });
  10. onMaxValueChange = ({ target }) => this.props.onChange({ ...this.props.options, maxValue: target.value });
  11. render() {
  12. const { options } = this.props;
  13. const { maxValue, minValue, showThresholdLabels, showThresholdMarkers } = options;
  14. return (
  15. <PanelOptionsGroup title="Gauge">
  16. <FormField label="Min value" labelWidth={8} onChange={this.onMinValueChange} value={minValue} />
  17. <FormField label="Max value" labelWidth={8} onChange={this.onMaxValueChange} value={maxValue} />
  18. <Switch
  19. label="Show labels"
  20. labelClass="width-8"
  21. checked={showThresholdLabels}
  22. onChange={this.onToggleThresholdLabels}
  23. />
  24. <Switch
  25. label="Show markers"
  26. labelClass="width-8"
  27. checked={showThresholdMarkers}
  28. onChange={this.onToggleThresholdMarkers}
  29. />
  30. </PanelOptionsGroup>
  31. );
  32. }
  33. }