forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic toggle button option to
Navbar
- Loading branch information
Showing
8 changed files
with
251 additions
and
123 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
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,112 @@ | ||
import ReactTransitionEvents from './react-es6/lib/ReactTransitionEvents'; | ||
|
||
var CollapsableMixin = { | ||
|
||
getInitialState: function() { | ||
return { | ||
isOpen: this.props.defaultOpen != null ? this.props.defaultOpen : null, | ||
isCollapsing: false | ||
}; | ||
}, | ||
|
||
handleTransitionEnd: function () { | ||
this._collapseEnd = true; | ||
this.setState({ | ||
isCollapsing: false | ||
}); | ||
}, | ||
|
||
componentWillReceiveProps: function (newProps) { | ||
if (newProps.isOpen !== this.props.isOpen) { | ||
this._collapseEnd = false; | ||
this.setState({ | ||
isCollapsing: true | ||
}); | ||
} | ||
}, | ||
|
||
_addEndTransitionListener: function () { | ||
var node = this.getCollapsableDOMNode(); | ||
|
||
if (node) { | ||
ReactTransitionEvents.addEndEventListener( | ||
node, | ||
this.handleTransitionEnd | ||
); | ||
} | ||
}, | ||
|
||
_removeEndTransitionListener: function () { | ||
var node = this.getCollapsableDOMNode(); | ||
|
||
if (node) { | ||
ReactTransitionEvents.addEndEventListener( | ||
node, | ||
this.handleTransitionEnd | ||
); | ||
} | ||
}, | ||
|
||
componentDidMount: function () { | ||
this._afterRender(); | ||
}, | ||
|
||
componentWillUnmount: function () { | ||
this._removeEndTransitionListener(); | ||
}, | ||
|
||
componentWillUpdate: function (nextProps) { | ||
var dimension = (typeof this.getCollapsableDimension === 'function') ? | ||
this.getCollapsableDimension() : 'height'; | ||
var node = this.getCollapsableDOMNode(); | ||
|
||
this._removeEndTransitionListener(); | ||
if (node && nextProps.isOpen !== this.props.isOpen && this.props.isOpen) { | ||
node.style[dimension] = this.getCollapsableDimensionValue() + 'px'; | ||
} | ||
}, | ||
|
||
componentDidUpdate: function () { | ||
this._afterRender(); | ||
}, | ||
|
||
_afterRender: function () { | ||
this._addEndTransitionListener(); | ||
setTimeout(this._updateDimensionAfterRender, 0); | ||
}, | ||
|
||
_updateDimensionAfterRender: function () { | ||
var dimension = (typeof this.getCollapsableDimension === 'function') ? | ||
this.getCollapsableDimension() : 'height'; | ||
var node = this.getCollapsableDOMNode(); | ||
|
||
if (node) { | ||
node.style[dimension] = this.isOpen() ? | ||
this.getCollapsableDimensionValue() + 'px' : '0px'; | ||
} | ||
}, | ||
|
||
isOpen: function () { | ||
return (this.props.isOpen != null) ? this.props.isOpen : this.state.isOpen; | ||
}, | ||
|
||
getCollapsableClassSet: function (className) { | ||
var classes = {}; | ||
|
||
if (typeof className === 'string') { | ||
className.split(' ').forEach(function (className) { | ||
if (className) { | ||
classes[className] = true; | ||
} | ||
}); | ||
} | ||
|
||
classes.collapsing = this.state.isCollapsing; | ||
classes.collapse = !this.state.isCollapsing; | ||
classes['in'] = this.isOpen() && !this.state.isCollapsing; | ||
|
||
return classes; | ||
} | ||
}; | ||
|
||
export default = CollapsableMixin; |
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
Oops, something went wrong.