FontSizeEditor.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Libraries
  2. import React, { PureComponent } from 'react';
  3. // Components
  4. import { FormLabel, Select, PanelOptionsGroup } from '@grafana/ui';
  5. // Types
  6. import { SingleStatOptions } from './types';
  7. import { SelectableValue } from '@grafana/data';
  8. const labelWidth = 6;
  9. export interface Props {
  10. options: SingleStatOptions;
  11. onChange: (options: SingleStatOptions) => void;
  12. }
  13. const percents = ['20%', '30%', '50%', '70%', '80%', '100%', '110%', '120%', '150%', '170%', '200%'];
  14. const fontSizeOptions = percents.map(v => {
  15. return { value: v, label: v };
  16. });
  17. export class FontSizeEditor extends PureComponent<Props> {
  18. setPrefixFontSize = (v: SelectableValue<string>) =>
  19. this.props.onChange({ ...this.props.options, prefixFontSize: v.value });
  20. setValueFontSize = (v: SelectableValue<string>) =>
  21. this.props.onChange({ ...this.props.options, valueFontSize: v.value });
  22. setPostfixFontSize = (v: SelectableValue<string>) =>
  23. this.props.onChange({ ...this.props.options, postfixFontSize: v.value });
  24. render() {
  25. const { prefixFontSize, valueFontSize, postfixFontSize } = this.props.options;
  26. return (
  27. <PanelOptionsGroup title="Font Size">
  28. <div className="gf-form">
  29. <FormLabel width={labelWidth}>Prefix</FormLabel>
  30. <Select
  31. width={12}
  32. options={fontSizeOptions}
  33. onChange={this.setPrefixFontSize}
  34. value={fontSizeOptions.find(option => option.value === prefixFontSize)}
  35. />
  36. </div>
  37. <div className="gf-form">
  38. <FormLabel width={labelWidth}>Value</FormLabel>
  39. <Select
  40. width={12}
  41. options={fontSizeOptions}
  42. onChange={this.setValueFontSize}
  43. value={fontSizeOptions.find(option => option.value === valueFontSize)}
  44. />
  45. </div>
  46. <div className="gf-form">
  47. <FormLabel width={labelWidth}>Postfix</FormLabel>
  48. <Select
  49. width={12}
  50. options={fontSizeOptions}
  51. onChange={this.setPostfixFontSize}
  52. value={fontSizeOptions.find(option => option.value === postfixFontSize)}
  53. />
  54. </div>
  55. </PanelOptionsGroup>
  56. );
  57. }
  58. }