import React from 'react' type ShareLinkButtonProps = { postId: string articleUrl: string } const ShareLinkButton: React.FC = ({ postId, articleUrl, }) => { const copyUrl = async (e: React.MouseEvent) => { const button = e.currentTarget const wrapper = e.currentTarget.closest('.x-live-blog-post__link-container') wrapper?.setAttribute('data-tooltip', 'show') if (typeof window !== 'undefined' && navigator.clipboard) { const postUrl = articleUrl ? new URL(articleUrl) : null if (postUrl) { postUrl.searchParams.append('feature', 'blog-post-sharing') postUrl.hash = `post-${postId}` } await navigator.clipboard.writeText(postUrl?.toString() ?? '') } setTimeout(() => { wrapper?.setAttribute('data-tooltip', 'hide') button.blur() }, 6000) } return (
Link copied
) } export default ShareLinkButton