GaugeOptionsBox.tsx 1.7 KB

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