-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from route06inc/implement-share-dropdown-menu
feat: implement ShareDropdownMenu
- Loading branch information
Showing
5 changed files
with
88 additions
and
20 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
frontend/apps/service-site/src/features/posts/components/ShareDropdownMenu/CopyLinkItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Props> = ({ 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 ( | ||
<TooltipProvider> | ||
<TooltipRoot open={show}> | ||
<TooltipTrigger asChild> | ||
<DropdownMenuItem | ||
leftIcon={<CopyIcon className={styles.icon} />} | ||
onSelect={handleCopyLink} | ||
> | ||
<span>{t('posts.share.copyLink')}</span> | ||
</DropdownMenuItem> | ||
</TooltipTrigger> | ||
<TooltipPortal> | ||
<TooltipContent sideOffset={5}>Link Copied</TooltipContent> | ||
</TooltipPortal> | ||
</TooltipRoot> | ||
</TooltipProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
height: 10px; | ||
color: var(--overlay-70); | ||
} | ||
|
||
.link { | ||
width: 100%; | ||
height: 100%; | ||
} |
5 changes: 1 addition & 4 deletions
5
...ervice-site/src/features/posts/components/ShareDropdownMenu/ShareDropdownMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters