-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Fauntleroy/modernize
Thoroughly modernize Dropdown components fixes #4
- Loading branch information
Showing
12 changed files
with
301 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ browsers: | |
- name: chrome | ||
version: latest | ||
browserify: | ||
- transform: reactify | ||
- transform: babelify |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { cloneElement, createClass } from 'react'; | ||
import { findDOMNode } from 'react-dom'; | ||
import cx from 'classnames'; | ||
|
||
import DropdownTrigger from './DropdownTrigger.js'; | ||
import DropdownContent from './DropdownContent.js'; | ||
|
||
var Dropdown = createClass({ | ||
getInitialState: function(){ | ||
return { | ||
active: false | ||
}; | ||
}, | ||
getDefaultProps: function(){ | ||
return { | ||
className: '' | ||
} | ||
}, | ||
componentDidMount: function () { | ||
window.addEventListener( 'click', this._onWindowClick ); | ||
}, | ||
componentWillUnmount: function () { | ||
window.removeEventListener( 'click', this._onWindowClick ); | ||
}, | ||
render: function () { | ||
const { children, className } = this.props; | ||
// create component classes | ||
const active = this.isActive(); | ||
var dropdown_classes = cx({ | ||
dropdown: true, | ||
'dropdown--active': active | ||
}); | ||
dropdown_classes += ' ' + className; | ||
// stick callback on trigger element | ||
const bound_children = React.Children.map( children, child => { | ||
if( child.type === DropdownTrigger ){ | ||
child = cloneElement( child, { | ||
ref: 'trigger', | ||
onClick: this._onToggleClick | ||
}); | ||
} | ||
return child; | ||
}); | ||
return <div className={dropdown_classes}>{bound_children}</div>; | ||
}, | ||
isActive: function(){ | ||
return ( typeof this.props.active === 'boolean' ) ? | ||
this.props.active : | ||
this.state.active; | ||
}, | ||
hide: function(){ | ||
this.setState({ | ||
active: false | ||
}); | ||
if( this.props.onHide ){ | ||
this.props.onHide(); | ||
} | ||
}, | ||
show: function(){ | ||
this.setState({ | ||
active: true | ||
}); | ||
if( this.props.onShow ){ | ||
this.props.onShow(); | ||
} | ||
}, | ||
_onWindowClick: function( event ){ | ||
const dropdown_element = findDOMNode( this ); | ||
if( event.target !== dropdown_element && !dropdown_element.contains( event.target ) && this.isActive() ){ | ||
this.hide(); | ||
} | ||
}, | ||
_onToggleClick: function( event ){ | ||
event.preventDefault(); | ||
if( this.isActive() ){ | ||
this.hide(); | ||
} else { | ||
this.show(); | ||
} | ||
} | ||
}); | ||
|
||
export { DropdownTrigger, DropdownContent }; | ||
export default Dropdown; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { createClass, PropTypes } from 'react'; | ||
|
||
const DropdownContent = createClass({ | ||
propTypes: { | ||
children: PropTypes.any, | ||
className: PropTypes.string | ||
}, | ||
getDefaultProps: function(){ | ||
return { | ||
className: '' | ||
} | ||
}, | ||
render: function(){ | ||
const { children, className } = this.props; | ||
const classes = 'dropdown__content ' + className; | ||
return <div className={classes}>{children}</div>; | ||
} | ||
}); | ||
|
||
export default DropdownContent; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { createClass, PropTypes } from 'react'; | ||
|
||
const DropdownTrigger = createClass({ | ||
propTypes: { | ||
children: PropTypes.any, | ||
className: PropTypes.string, | ||
onClick: PropTypes.func | ||
}, | ||
getDefaultProps: function(){ | ||
return { | ||
className: '' | ||
}; | ||
}, | ||
render: function(){ | ||
const { children, className, onClick } = this.props; | ||
const classes = 'dropdown__trigger ' + className; | ||
return ( | ||
<a className={classes} href="#dropdown-trigger" onClick={onClick}> | ||
{children} | ||
</a> | ||
); | ||
} | ||
}); | ||
|
||
export default DropdownTrigger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.