11import React from 'react' ;
2- import createClass from 'create-react-class' ;
32import PropTypes from 'prop-types' ;
43import classNames from 'classnames' ;
54
6- const Option = createClass ( {
7- propTypes : {
8- children : PropTypes . node ,
9- className : PropTypes . string , // className (based on mouse position)
10- instancePrefix : PropTypes . string . isRequired , // unique prefix for the ids (used for aria)
11- isDisabled : PropTypes . bool , // the option is disabled
12- isFocused : PropTypes . bool , // the option is focused
13- isSelected : PropTypes . bool , // the option is selected
14- onFocus : PropTypes . func , // method to handle mouseEnter on option element
15- onSelect : PropTypes . func , // method to handle click on option element
16- onUnfocus : PropTypes . func , // method to handle mouseLeave on option element
17- option : PropTypes . object . isRequired , // object that is base for that option
18- optionIndex : PropTypes . number , // index of the option, used to generate unique ids for aria
19- } ,
5+ class Option extends React . Component {
6+
7+ constructor ( props ) {
8+ super ( props ) ;
9+
10+ this . handleMouseDown = this . handleMouseDown . bind ( this ) ;
11+ this . handleMouseEnter = this . handleMouseEnter . bind ( this ) ;
12+ this . handleMouseMove = this . handleMouseMove . bind ( this ) ;
13+ this . handleTouchStart = this . handleTouchStart . bind ( this ) ;
14+ this . onFocus = this . onFocus . bind ( this ) ;
15+ }
16+
17+
2018 blockEvent ( event ) {
2119 event . preventDefault ( ) ;
2220 event . stopPropagation ( ) ;
@@ -28,45 +26,46 @@ const Option = createClass({
2826 } else {
2927 window . location . href = event . target . href ;
3028 }
31- } ,
29+ }
3230
3331 handleMouseDown ( event ) {
3432 event . preventDefault ( ) ;
3533 event . stopPropagation ( ) ;
3634 this . props . onSelect ( this . props . option , event ) ;
37- } ,
35+ }
3836
3937 handleMouseEnter ( event ) {
4038 this . onFocus ( event ) ;
41- } ,
39+ }
4240
4341 handleMouseMove ( event ) {
4442 this . onFocus ( event ) ;
45- } ,
43+ }
4644
4745 handleTouchEnd ( event ) {
4846 // Check if the view is being dragged, In this case
4947 // we don't want to fire the click event (because the user only wants to scroll)
5048 if ( this . dragging ) return ;
5149
5250 this . handleMouseDown ( event ) ;
53- } ,
51+ }
5452
5553 handleTouchMove ( event ) {
5654 // Set a flag that the view is being dragged
5755 this . dragging = true ;
58- } ,
56+ }
5957
6058 handleTouchStart ( event ) {
6159 // Set a flag that the view is not being dragged
6260 this . dragging = false ;
63- } ,
61+ }
6462
6563 onFocus ( event ) {
6664 if ( ! this . props . isFocused ) {
6765 this . props . onFocus ( this . props . option , event ) ;
6866 }
69- } ,
67+ }
68+
7069 render ( ) {
7170 var { option, instancePrefix, optionIndex } = this . props ;
7271 var className = classNames ( this . props . className , option . className ) ;
@@ -93,6 +92,20 @@ const Option = createClass({
9392 </ div >
9493 ) ;
9594 }
96- } ) ;
95+ } ;
96+
97+ Option . propTypes = {
98+ children : PropTypes . node ,
99+ className : PropTypes . string , // className (based on mouse position)
100+ instancePrefix : PropTypes . string . isRequired , // unique prefix for the ids (used for aria)
101+ isDisabled : PropTypes . bool , // the option is disabled
102+ isFocused : PropTypes . bool , // the option is focused
103+ isSelected : PropTypes . bool , // the option is selected
104+ onFocus : PropTypes . func , // method to handle mouseEnter on option element
105+ onSelect : PropTypes . func , // method to handle click on option element
106+ onUnfocus : PropTypes . func , // method to handle mouseLeave on option element
107+ option : PropTypes . object . isRequired , // object that is base for that option
108+ optionIndex : PropTypes . number , // index of the option, used to generate unique ids for aria
109+ } ;
97110
98111module . exports = Option ;
0 commit comments