UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

116 lines (89 loc) 4.84 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = Link; var _react = _interopRequireWildcard(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _Common = require("@zohodesk/components/es/utils/Common"); var _LinkContext = _interopRequireDefault(require("../../Link/LinkContext")); var _LinkModule = _interopRequireDefault(require("../../Link/Link.module.css")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function Link(props) { var children = props.children, href = props.href, target = props.target, urlData = props.urlData, urlName = props.urlName, className = props.className, title = props.title, download = props.download, rel = props.rel, dataId = props.dataId, customProps = props.customProps, ariaLabel = props.ariaLabel, hasReload = props.hasReload, onClick = props.onClick; var _useContext = (0, _react.useContext)(_LinkContext["default"]), options = _useContext.options; var isLink = options.isLink, constructURL = options.constructURL, onCallBack = options.onCallBack; var urlOutput = href ? href : constructURL(urlName, urlData); var option = (0, _react.useRef)({}); if (download) { option.current.download = true; } var ignoreKeys = ['children', 'href', 'target', 'urlData', 'urlName', 'className', 'title', 'download', 'rel', 'dataId', 'hasReload', 'customProps', 'option', 'ariaLabel']; var others = Object.keys(props).filter(function (key) { return ignoreKeys.indexOf(key) == -1; }).reduce(function (res, key) { res[key] = props[key]; return res; }, {}); function callBack(e) { if (e && (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)) { (0, _Common.cancelBubblingEffect)(e); return; } onClick && onClick(e); if (!hasReload && target != '_blank') { e && e.preventDefault(); } (0, _Common.cancelBubblingEffect)(e); !onClick && onCallBack && onCallBack(e); } function addHttp(url) { /* eslint-disable */ if (!/^(f|ht)tps?:\/\//i.test(url)) { url = 'http://' + url; } /* eslint-enable */ return url; } //urlOutput = addHttp(urlOutput); return /*#__PURE__*/_react["default"].createElement("a", _extends({ href: isLink && urlOutput ? urlOutput : 'javascript:void(0);', target: target, "data-title": title, className: "".concat(_LinkModule["default"].container, " ").concat(className ? className : '') }, option.current, { rel: rel, "data-id": dataId, "data-test-id": dataId }, others, { onClick: callBack }, customProps, { "aria-label": ariaLabel }), children); } Link.defaultProps = _defaultProps.defaultProps; Link.propTypes = _propTypes.propTypes; // if (__DOCS__) { // Link.docs = { // componentGroup: 'Atom' // }; // }