DescriptionPicker.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { Component } from 'react';
  2. import Select from 'react-select';
  3. import DescriptionOption from './DescriptionOption';
  4. import IndicatorsContainer from './IndicatorsContainer';
  5. import ResetStyles from './ResetStyles';
  6. import NoOptionsMessage from './NoOptionsMessage';
  7. export interface OptionWithDescription {
  8. value: any;
  9. label: string;
  10. description: string;
  11. }
  12. export interface Props {
  13. optionsWithDesc: OptionWithDescription[];
  14. onSelected: (permission) => void;
  15. disabled: boolean;
  16. className?: string;
  17. value?: any;
  18. }
  19. const getSelectedOption = (optionsWithDesc, value) => optionsWithDesc.find(option => option.value === value);
  20. class DescriptionPicker extends Component<Props, any> {
  21. render() {
  22. const { optionsWithDesc, onSelected, disabled, className, value } = this.props;
  23. const selectedOption = getSelectedOption(optionsWithDesc, value);
  24. return (
  25. <div className="permissions-picker">
  26. <Select
  27. placeholder="Choose"
  28. classNamePrefix={`gf-form-select-box`}
  29. className={`width-7 gf-form-input gf-form-input--form-dropdown ${className || ''}`}
  30. options={optionsWithDesc}
  31. components={{
  32. Option: DescriptionOption,
  33. IndicatorsContainer,
  34. NoOptionsMessage,
  35. }}
  36. styles={ResetStyles}
  37. isDisabled={disabled}
  38. onChange={onSelected}
  39. getOptionValue={i => i.value}
  40. getOptionLabel={i => i.label}
  41. value={selectedOption}
  42. />
  43. </div>
  44. );
  45. }
  46. }
  47. export default DescriptionPicker;