diff --git a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/CopyLinkItem.tsx b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/CopyLinkItem.tsx new file mode 100644 index 000000000..1565b3fa3 --- /dev/null +++ b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/CopyLinkItem.tsx @@ -0,0 +1,56 @@ +import type { TranslationFn } from '@/features/i18n' +import { + DropdownMenuItem, + TooltipContent, + TooltipPortal, + TooltipProvider, + TooltipRoot, + TooltipTrigger, +} from '@packages/ui' +import { CopyIcon } from 'lucide-react' +import { type FC, useCallback, useEffect, useState } from 'react' +import styles from './ShareDropdownMenu.module.css' + +type Props = { + t: TranslationFn + onOpenChange: (open: boolean) => void +} + +export const CopyLinkItem: FC = ({ t, onOpenChange }) => { + const [show, setShow] = useState(false) + + useEffect(() => { + if (!show) return + + const timer = setTimeout(() => { + setShow(false) + onOpenChange(false) + }, 1000) + return () => clearTimeout(timer) + }, [show, onOpenChange]) + + const handleCopyLink = useCallback(async (event: Event) => { + event.preventDefault() + navigator.clipboard.writeText(window.location.href).then(() => { + setShow(true) + }) + }, []) + + return ( + + + + } + onSelect={handleCopyLink} + > + {t('posts.share.copyLink')} + + + + Link Copied + + + + ) +} diff --git a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.module.css b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.module.css index dc619d6dc..a7a2ffa41 100644 --- a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.module.css +++ b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.module.css @@ -3,3 +3,8 @@ height: 10px; color: var(--overlay-70); } + +.link { + width: 100%; + height: 100%; +} diff --git a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.stories.tsx b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.stories.tsx index f08608f96..5bcb38447 100644 --- a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.stories.tsx +++ b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.stories.tsx @@ -1,14 +1,11 @@ import type { Meta, StoryObj } from '@storybook/react' -import { getTranslation } from '@/features/i18n' import { ShareDropdownMenu } from '.' -const { t } = getTranslation('en') - const meta = { component: ShareDropdownMenu, args: { - t, + lang: 'en', children: , }, } satisfies Meta diff --git a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.tsx b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.tsx index 3ecf1899a..5c6983c55 100644 --- a/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.tsx +++ b/frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.tsx @@ -1,4 +1,4 @@ -import type { TranslationFn } from '@/features/i18n' +import { type Lang, getTranslation } from '@/features/i18n' import { DropdownMenuContent, DropdownMenuItem, @@ -9,42 +9,52 @@ import { LinkedInIcon, XIcon, } from '@packages/ui' -import { CopyIcon } from 'lucide-react' -import type { FC, PropsWithChildren } from 'react' +import { type FC, type PropsWithChildren, useState } from 'react' +import { CopyLinkItem } from './CopyLinkItem' import styles from './ShareDropdownMenu.module.css' type Props = PropsWithChildren<{ - t: TranslationFn + lang: Lang }> -export const ShareDropdownMenu: FC = ({ children, t }) => { +const handleSelect = (url: string) => () => { + window.open(url, '_blank', 'noreferrer') +} + +export const ShareDropdownMenu: FC = ({ children, lang }) => { + const [open, setOpen] = useState(false) + const { t } = getTranslation(lang) + const url = encodeURIComponent(window.location.href) + const title = encodeURIComponent(document.title) + return ( - + {children} - } - onSelect={() => alert('Item 1 clicked')} - > - {t('posts.share.copyLink')} - + } - onSelect={() => alert('Item 2 clicked')} + onSelect={handleSelect( + `http://twitter.com/share?url=${url}&text=${title}`, + )} > {t('posts.share.x')} } - onSelect={() => alert('Item 3 clicked')} + onSelect={handleSelect( + `http://www.facebook.com/share.php?u=${url}`, + )} > {t('posts.share.facebook')} } - onSelect={() => alert('Item 3 clicked')} + onSelect={handleSelect( + `https://www.linkedin.com/sharing/share-offsite/?url=${url}`, + )} > {t('posts.share.linkedin')} diff --git a/frontend/packages/ui/src/components/DropdownMenu/DropdownMenu.tsx b/frontend/packages/ui/src/components/DropdownMenu/DropdownMenu.tsx index c3d6a2356..37836d35b 100644 --- a/frontend/packages/ui/src/components/DropdownMenu/DropdownMenu.tsx +++ b/frontend/packages/ui/src/components/DropdownMenu/DropdownMenu.tsx @@ -76,7 +76,7 @@ export const DropdownMenuItem = forwardRef< {leftIcon && ( {leftIcon} )} -
{children}
+ {children} ) },