| 12 | } |
| 13 | |
| 14 | class Link { |
| 15 | |
| 16 | static propTypes = { |
| 17 | to: PropTypes.string.isRequired, |
| 18 | children: PropTypes.element.isRequired, |
| 19 | state: PropTypes.object, |
| 20 | onClick: PropTypes.func |
| 21 | }; |
| 22 | |
| 23 | static handleClick = event => { |
| 24 | var allowTransition = true; |
| 25 | var clickResult; |
| 26 | |
| 27 | if (this.props && this.props.onClick) { |
| 28 | clickResult = this.props.onClick(event); |
| 29 | } |
| 30 | |
| 31 | if (isModifiedEvent(event) || !isLeftClickEvent(event)) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (clickResult === false || event.defaultPrevented === true) { |
| 36 | allowTransition = false; |
| 37 | } |
| 38 | |
| 39 | event.preventDefault(); |
| 40 | |
| 41 | if (allowTransition) { |
| 42 | const link = event.currentTarget; |
| 43 | Location.pushState( |
| 44 | this.props && this.props.state || null, |
| 45 | this.props && this.props.to || (link.pathname + link.search)); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | render() { |
| 50 | const { to, children, ...props } = this.props; |
| 51 | return <a onClick={Link.handleClick.bind(this)} {...props}>{children}</a>; |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |
| 56 | export default Link; |
nothing calls this directly
no test coverage detected