UNPKG

kedao

Version:

Rich Text Editor Based On Draft.js

20 lines (19 loc) 916 B
import { classNameParser } from '../../utils/style'; import React from 'react'; import styles from "./style.module.css"; const cls = classNameParser(styles); const viewLink = (event, link) => { // When pressing the Ctrl / command key, click to open the url in the link text if (event.getModifierState('Control') || event.getModifierState('Meta')) { const tempLink = document.createElement('a'); tempLink.href = link; tempLink.target = event.currentTarget.target; tempLink.click(); } }; const Link = ({ children, entityKey, contentState }) => { const { href, target } = contentState.getEntity(entityKey).getData(); return (React.createElement("span", { className: cls('kedao-link-wrap') }, React.createElement("a", { onClick: (event) => viewLink(event, href), className: cls('kedao-link'), href: href, target: target }, children))); }; export default Link;