DescriptionPicker.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. constructor(props) {
  22. super(props);
  23. }
  24. render() {
  25. const { optionsWithDesc, onSelected, disabled, className, value } = this.props;
  26. const selectedOption = getSelectedOption(optionsWithDesc, value);
  27. return (
  28. <div className="permissions-picker">
  29. <Select
  30. placeholder="Choose"
  31. classNamePrefix={`gf-form-select-box`}
  32. className={`width-7 gf-form-input gf-form-input--form-dropdown ${className || ''}`}
  33. options={optionsWithDesc}
  34. components={{
  35. Option: DescriptionOption,
  36. IndicatorsContainer,
  37. NoOptionsMessage,
  38. }}
  39. styles={ResetStyles}
  40. isDisabled={disabled}
  41. onChange={onSelected}
  42. getOptionValue={i => i.value}
  43. getOptionLabel={i => i.label}
  44. value={selectedOption}
  45. />
  46. </div>
  47. );
  48. }
  49. }
  50. export default DescriptionPicker;