FontSizeEditor.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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<string>) =>
  18. this.props.onChange({ ...this.props.options, prefixFontSize: v.value });
  19. setValueFontSize = (v: SelectOptionItem<string>) =>
  20. this.props.onChange({ ...this.props.options, valueFontSize: v.value });
  21. setPostfixFontSize = (v: SelectOptionItem<string>) =>
  22. this.props.onChange({ ...this.props.options, postfixFontSize: v.value });
  23. render() {
  24. const { prefixFontSize, valueFontSize, postfixFontSize } = this.props.options;
  25. return (
  26. <PanelOptionsGroup title="Font Size">
  27. <div className="gf-form">
  28. <FormLabel width={labelWidth}>Prefix</FormLabel>
  29. <Select
  30. width={12}
  31. options={fontSizeOptions}
  32. onChange={this.setPrefixFontSize}
  33. value={fontSizeOptions.find(option => option.value === prefixFontSize)}
  34. />
  35. </div>
  36. <div className="gf-form">
  37. <FormLabel width={labelWidth}>Value</FormLabel>
  38. <Select
  39. width={12}
  40. options={fontSizeOptions}
  41. onChange={this.setValueFontSize}
  42. value={fontSizeOptions.find(option => option.value === valueFontSize)}
  43. />
  44. </div>
  45. <div className="gf-form">
  46. <FormLabel width={labelWidth}>Postfix</FormLabel>
  47. <Select
  48. width={12}
  49. options={fontSizeOptions}
  50. onChange={this.setPostfixFontSize}
  51. value={fontSizeOptions.find(option => option.value === postfixFontSize)}
  52. />
  53. </div>
  54. </PanelOptionsGroup>
  55. );
  56. }
  57. }