UnitPicker.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React, { PureComponent } from 'react';
  2. import Select from 'react-select';
  3. import UnitGroup from './UnitGroup';
  4. import UnitOption from './UnitOption';
  5. import ResetStyles from '../ResetStyles';
  6. import kbn from '../../../utils/kbn';
  7. interface Props {
  8. onSelected: (item: any) => {} | void;
  9. }
  10. export default class UnitPicker extends PureComponent<Props> {
  11. render() {
  12. const unitGroups = kbn.getUnitFormats();
  13. const options = unitGroups.map(group => {
  14. const options = group.submenu.map(unit => {
  15. return {
  16. label: unit.text,
  17. value: unit.value,
  18. };
  19. });
  20. return {
  21. label: group.text,
  22. options,
  23. };
  24. });
  25. const styles = {
  26. ...ResetStyles,
  27. menu: () => ({
  28. maxHeight: '500px',
  29. overflow: 'scroll',
  30. }),
  31. menuList: () =>
  32. ({
  33. WebkitOverflowScrolling: 'touch',
  34. overflowY: 'auto',
  35. position: 'relative',
  36. } as React.CSSProperties),
  37. };
  38. return (
  39. <Select
  40. classNamePrefix="gf-form-select-box"
  41. className="width-20 gf-form-input"
  42. isSearchable={true}
  43. options={options}
  44. placeholder="Choose"
  45. components={{
  46. Group: UnitGroup,
  47. Option: UnitOption,
  48. }}
  49. styles={styles}
  50. />
  51. );
  52. }
  53. }