GaugeOptionsEditor.tsx 1.6 KB

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