11import React , { Component } from 'react' ;
22import './Dropdown.css' ;
33
4+ import Button from '../Button/Button' ;
5+
46const classNames = require ( 'classnames' ) ;
57
68export class Dropdown extends Component {
9+ constructor ( props ) {
10+ super ( props ) ;
11+
12+ this . state = {
13+ show : false ,
14+ } ;
15+ }
16+
17+ onBlur ( e ) {
18+ if ( this . state . show === true )
19+ this . setState ( { show : false } ) ;
20+ }
21+
722 render ( ) {
8- if ( this . props . show === true )
923 return (
10- < div
11- style = { {
12- top : this . props . target . Y ,
13- left : this . props . target . X ,
14- } }
15- className = {
16- classNames (
17- 'rce-dropdown' ,
18- this . props . animationType ,
19- 'rce-dropdown-open__' + this . props . animationPosition ,
20- )
21- } >
22- < ul >
23- {
24- this . props . items . map ( ( x , i ) => (
25- < li key = { i } onClick = { ( ) => this . props . onSelect ( i ) } >
26- < a > { x } </ a >
27- </ li >
28- ) )
29- }
30- </ ul >
24+ < div className = 'rce-dropdown-container' onBlur = { this . onBlur . bind ( this ) } >
25+ {
26+ < Button
27+ { ...this . props . buttonProps }
28+ onClick = { ( ) => this . setState ( { show : ! this . state . show } ) } />
29+ }
30+ {
31+ this . state . show &&
32+ < div
33+ className = {
34+ classNames (
35+ 'rce-dropdown' ,
36+ this . props . animationType ,
37+ 'rce-dropdown-open__' + this . props . animationPosition ,
38+ )
39+ } >
40+ < ul >
41+ {
42+ this . props . items . map ( ( x , i ) => (
43+ < li key = { i } onMouseDown = { ( e ) => this . props . onSelect ( i ) } >
44+ < a > { x } </ a >
45+ </ li >
46+ ) )
47+ }
48+ </ ul >
49+ </ div >
50+ }
3151 </ div >
3252 ) ;
33- return null ;
3453 }
3554}
3655
3756Dropdown . defaultProps = {
38- show : false ,
3957 animationType : 'default' ,
4058 animationPosition : 'nortwest' ,
4159 items : [ ] ,
4260 onSelect : Function ,
43- target : { X : 0 , Y : 0 } ,
61+ buttonProps : null
4462} ;
4563
46- export default Dropdown ;
64+ export default Dropdown ;
0 commit comments