DescriptionOption.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { Component } from 'react';
  2. export interface IProps {
  3. onSelect: any;
  4. onFocus: any;
  5. option: any;
  6. isFocused: any;
  7. className: any;
  8. }
  9. class DescriptionOption extends Component<IProps, any> {
  10. constructor(props) {
  11. super(props);
  12. this.handleMouseDown = this.handleMouseDown.bind(this);
  13. this.handleMouseEnter = this.handleMouseEnter.bind(this);
  14. this.handleMouseMove = this.handleMouseMove.bind(this);
  15. }
  16. handleMouseDown(event) {
  17. event.preventDefault();
  18. event.stopPropagation();
  19. this.props.onSelect(this.props.option, event);
  20. }
  21. handleMouseEnter(event) {
  22. this.props.onFocus(this.props.option, event);
  23. }
  24. handleMouseMove(event) {
  25. if (this.props.isFocused) {
  26. return;
  27. }
  28. this.props.onFocus(this.props.option, event);
  29. }
  30. render() {
  31. const { option, children, className } = this.props;
  32. return (
  33. <button
  34. onMouseDown={this.handleMouseDown}
  35. onMouseEnter={this.handleMouseEnter}
  36. onMouseMove={this.handleMouseMove}
  37. title={option.title}
  38. className={`user-picker-option__button btn btn-link ${className} width-19`}
  39. style={{
  40. whiteSpace: 'normal',
  41. // height: '55px',
  42. }}
  43. >
  44. <div className="gf-form">{children}</div>
  45. <div className="gf-form">
  46. <div className="muted width-17">{option.description}</div>
  47. {className.indexOf('is-selected') > -1 && (
  48. <i style={{ paddingLeft: '2px' }} className="fa fa-check" aria-hidden="true" />
  49. )}
  50. </div>
  51. </button>
  52. );
  53. }
  54. }
  55. export default DescriptionOption;