webapp/src/components/Article/SharePopup.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-11-14 17:41:05 +00:00
import { Icon } from '../_shared/Icon'
2022-10-25 15:36:32 +00:00
import { t } from '../../utils/intl'
import { createSocialShare, TWITTER, VK, FACEBOOK, TELEGRAM } from '@solid-primitives/share'
2022-11-14 10:02:08 +00:00
2022-11-20 21:25:59 +00:00
import styles from '../_shared/Popup/Popup.module.scss'
2022-11-14 10:02:08 +00:00
import type { PopupProps } from '../_shared/Popup'
import { Popup } from '../_shared/Popup'
2022-10-25 15:36:32 +00:00
type SharePopupProps = {
title: string
shareUrl?: string
imageUrl: string
description: string
} & Omit<PopupProps, 'children'>
2022-10-25 15:36:32 +00:00
export const SharePopup = (props: SharePopupProps) => {
const [share] = createSocialShare(() => ({
title: props.title,
url: props.shareUrl,
description: props.description
}))
const copyLink = async () => {
await navigator.clipboard.writeText(window.location.href)
}
2022-10-25 15:36:32 +00:00
return (
2022-12-17 03:27:00 +00:00
<Popup {...props} variant="bordered">
2022-10-25 15:36:32 +00:00
<ul class="nodash">
<li>
<button role="button" onClick={() => share(VK)}>
2022-10-25 15:36:32 +00:00
<Icon name="vk-white" class={styles.icon} />
VK
</button>
2022-10-25 15:36:32 +00:00
</li>
<li>
<button role="button" onClick={() => share(FACEBOOK)}>
2022-10-25 15:36:32 +00:00
<Icon name="facebook-white" class={styles.icon} />
Facebook
</button>
2022-10-25 15:36:32 +00:00
</li>
<li>
<button role="button" onClick={() => share(TWITTER)}>
2022-10-25 15:36:32 +00:00
<Icon name="twitter-white" class={styles.icon} />
Twitter
</button>
2022-10-25 15:36:32 +00:00
</li>
<li>
<button role="button" onClick={() => share(TELEGRAM)}>
2022-10-25 15:36:32 +00:00
<Icon name="telegram-white" class={styles.icon} />
Telegram
</button>
2022-10-25 15:36:32 +00:00
</li>
<li>
<button role="button" onClick={copyLink}>
2022-10-25 15:36:32 +00:00
<Icon name="link-white" class={styles.icon} />
{t('Copy link')}
</button>
2022-10-25 15:36:32 +00:00
</li>
</ul>
</Popup>
)
}