Skip to content

Commit

Permalink
feat: implement click event for share dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
MH4GF committed Oct 11, 2024
1 parent 339d82b commit edbff43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
height: 10px;
color: var(--overlay-70);
}

.link {
width: 100%;
height: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ type Props = PropsWithChildren<{
lang: Lang
}>

const handleSelect = (url: string) => () => {
window.open(url, '_blank', 'noreferrer')
}

export const ShareDropdownMenu: FC<Props> = ({ children, lang }) => {
const [open, setOpen] = useState(false)
const { t } = getTranslation(lang)
const url = encodeURIComponent(window.location.href)
const title = document.title

return (
<DropdownMenuRoot open={open} onOpenChange={setOpen}>
Expand All @@ -30,19 +36,25 @@ export const ShareDropdownMenu: FC<Props> = ({ children, lang }) => {
<CopyLinkItem t={t} onOpenChange={setOpen} />
<DropdownMenuItem
leftIcon={<XIcon className={styles.icon} />}
onSelect={() => alert('Item 2 clicked')}
onSelect={handleSelect(
`http://twitter.com/share?url=${url}&text=${title}`,
)}
>
<span>{t('posts.share.x')}</span>
</DropdownMenuItem>
<DropdownMenuItem
leftIcon={<FacebookIcon className={styles.icon} />}
onSelect={() => alert('Item 3 clicked')}
onSelect={handleSelect(
`http://www.facebook.com/share.php?u=${url}`,
)}
>
<span>{t('posts.share.facebook')}</span>
</DropdownMenuItem>
<DropdownMenuItem
leftIcon={<LinkedInIcon className={styles.icon} />}
onSelect={() => alert('Item 3 clicked')}
onSelect={handleSelect(
`https://www.linkedin.com/sharing/share-offsite/?url=${url}`,
)}
>
<span>{t('posts.share.linkedin')}</span>
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const DropdownMenuItem = forwardRef<
{leftIcon && (
<span className={clsx(styles.icon, styles.leftIcon)}>{leftIcon}</span>
)}
<div>{children}</div>
{children}
</Item>
)
},
Expand Down

0 comments on commit edbff43

Please sign in to comment.