@alifd/meet-react
Version:
Fusion Mobile React UI System Component
46 lines • 1.97 kB
JavaScript
import { rpx2vw4style as __rpx2vw__ } from "@alifd/babel-runtime-jsx-style-transform";
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); }
import { __rest } from "tslib";
import React, { createElement } from "react";
import navigate from '@uni/navigate';
import { setClipboard } from '@uni/clipboard';
import Message from '../message';
import { isStrictByteDanceMicroApp, isStrictMiniApp, scrollToId, isFunction, isUndef } from '../utils';
var MINIAPP_PAGE_REG = /^\/[a-zA-z0-9]/;
var SIMPLE_URL_REG = /[a-zA-z]+:\/\/[^\s]*/;
var RichTextLink = function RichTextLink(props) {
var style = props.style,
href = props.href,
className = props.className,
children = props.children,
onLinkClick = props.onLinkClick,
otherProps = __rest(props, ["style", "href", "className", "children", "onLinkClick"]);
var handleClick = function handleClick() {
if (href[0] === '#') {
var id = href.substring(1);
scrollToId(id);
} else if (SIMPLE_URL_REG.test(href)) {
if (isFunction(onLinkClick) && onLinkClick(href) !== false || isUndef(onLinkClick)) {
setClipboard({
text: href
}).then(function () {
if (isStrictMiniApp || isStrictByteDanceMicroApp) {
Message.show({
content: '链接已复制到粘贴板'
});
}
});
}
} else if (MINIAPP_PAGE_REG.test(href)) {
navigate.push({
url: href
}).then(function (res) {});
}
};
return /*#__PURE__*/React.createElement("view", _extends({}, otherProps, {
className: className,
onClick: handleClick,
style: __rpx2vw__(style)
}), children);
};
export default RichTextLink;