Closed
Description
In case someone need to add target value to anchor. here is a simple solution to do it.
export const BtnLink = createButton(
"Link",
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className={btnSize}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"
/>
</svg>,
({ $selection }) => {
if ($selection?.nodeName === "A") {
document.execCommand("unlink");
} else {
const Selection = document.getSelection()?.toString();
// eslint-disable-next-line no-alert -- ignore
const Uri = prompt("URL", "");
document.execCommand(
"insertHTML",
false,
Uri ? `<a href="${Uri}" target="_blank">${Selection ? Selection : Uri}</a>` : Selection,
);
}
},
);
Metadata
Metadata
Assignees
Labels
No labels