@upendradevsingh/webcore
Version:
UI Core Components for web
45 lines (37 loc) • 1.3 kB
JavaScript
/**
* =======================================================
* WebCore: Smart Anchor Component 1.0.0
* https://webcore.jabong.com/components/smartanchor
* =======================================================
* * Copyright 2017 Jabong, Inc.
* Licensed under MIT (https://github.com/jabong/webcore/blob/master/LICENSE)
*/
import React, { Component } from 'react';
import * as utils from '../utils';
import Dialog from '../Modal';
class SmartAnchor extends Component {
onClick(event) {
// Navigate user to new page in mobile devices
if(utils.browser.isMobile()){
return true;
} else {
// Open a dialog for given url
event.preventDefault();
let url = utils.browser.isSecureProtocol() ? this.props.secureUrl : this.props.nonSecureUrl;
//@todo Add dialog support late
React.render(<Dialog dataUrl={url} />, document.body);
}
}
render(){
let attrs = {
href: `${this.props.baseUrl}${this.props.to}`
};
if(typeof this.props.gaq !== 'undefined') attrs['data-gaq-event'] = this.props.gaq;
return(
<a {...attrs}>
{this.props.children}
</a>
);
}
}
export default SmartAnchor;