DescriptionOption.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { Component } from 'react';
  2. export interface Props {
  3. onSelect: any;
  4. onFocus: any;
  5. option: any;
  6. isFocused: any;
  7. className: any;
  8. }
  9. class DescriptionOption extends Component<Props, 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={`description-picker-option__button btn btn-link ${className} width-19`}
  39. >
  40. <div className="gf-form">{children}</div>
  41. <div className="gf-form">
  42. <div className="muted width-17">{option.description}</div>
  43. {className.indexOf('is-selected') > -1 && <i className="fa fa-check" aria-hidden="true" />}
  44. </div>
  45. </button>
  46. );
  47. }
  48. }
  49. export default DescriptionOption;