Created
March 22, 2015 23:45
-
-
Save KeKs0r/74f7f2fcc53061a33d38 to your computer and use it in GitHub Desktop.
Cancable Touchstone Link
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
/** @jsx React.DOM */ | |
var React = require('react'); | |
var Tappable = require('react-tappable'); | |
var Navigation = require('touchstonejs').Navigation; | |
module.exports = React.createClass({ | |
displayName: 'Cancable_Link', | |
mixins: [Navigation], | |
contextTypes: { | |
isSwiping: React.PropTypes.func | |
}, | |
propTypes: { | |
to: React.PropTypes.string.isRequired, | |
params: React.PropTypes.object, | |
viewTransition: React.PropTypes.string, | |
component: React.PropTypes.any, | |
className: React.PropTypes.string, | |
check: React.PropTypes.func | |
}, | |
getDefaultProps: function () { | |
return { | |
viewTransition: 'none', | |
component: 'span' | |
}; | |
}, | |
action: function () { | |
var checkFunc = (this.props.check) ? this.props.check : this.context.isSwiping; | |
if (checkFunc && checkFunc()) { | |
return; | |
} | |
var params = this.props.params; | |
if ('function' === typeof params) { | |
params = params.call(this); | |
} | |
this.showView(this.props.to, this.props.viewTransition, params); | |
}, | |
render: function () { | |
return ( | |
<Tappable onTap={this.action} className={this.props.className} component={this.props.component}> | |
{this.props.children} | |
</Tappable> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment