FontSizeEditor.tsx 2.1 KB

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