-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ShareIcon 구현 * feat: ShareIcon 적용
- Loading branch information
Showing
9 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import styled from '@emotion/styled'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import ShareIcon from '.'; | ||
|
||
export default { | ||
title: 'common/ShareIcon', | ||
component: ShareIcon, | ||
argTypes: {}, | ||
} as ComponentMeta<typeof ShareIcon>; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
justify-content: end; | ||
`; | ||
|
||
const Template: ComponentStory<typeof ShareIcon> = (args) => ( | ||
<Container> | ||
<ShareIcon {...args} /> | ||
</Container> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
url: 'http://localhost:3000/topics/1', | ||
}; |
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,35 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import Icon from '@src/components/common/Icon'; | ||
import theme from '@src/styles/theme'; | ||
|
||
export const Container = styled.div` | ||
width: 24px; | ||
height: 24px; | ||
position: relative; | ||
`; | ||
|
||
export const Share = styled(Icon)` | ||
cursor: pointer; | ||
`; | ||
|
||
export const Toast = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 2px; | ||
position: absolute; | ||
width: 200px; | ||
height: 48px; | ||
top: calc(100% + 8px); | ||
right: 0; | ||
background-color: ${theme.color.G6}; | ||
border-radius: 8px; | ||
font-weight: ${theme.fontWeight.bold}; | ||
font-size: ${theme.textSize.T3}; | ||
line-height: ${theme.lineHeight.B}; | ||
`; |
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,42 @@ | ||
import React, { MouseEvent, useState } from 'react'; | ||
|
||
import Icon from '@src/components/common/Icon'; | ||
|
||
import * as S from './ShareIcon.styles'; | ||
|
||
interface ShareIconProps { | ||
url: string; | ||
} | ||
|
||
const ShareIcon: React.FC<ShareIconProps> = (props) => { | ||
const { url } = props; | ||
const [isCopied, setIsCopied] = useState<boolean>(false); | ||
|
||
const handleShare = async (e: MouseEvent<SVGSVGElement>) => { | ||
e.stopPropagation(); | ||
e.nativeEvent.preventDefault(); | ||
|
||
if (isCopied) return; | ||
if (!navigator.clipboard) return; | ||
|
||
await navigator.clipboard.writeText(url); | ||
setIsCopied(true); | ||
setTimeout(() => { | ||
setIsCopied(false); | ||
}, 1000); | ||
}; | ||
|
||
return ( | ||
<S.Container> | ||
<S.Share name="Share" onClick={handleShare} /> | ||
{isCopied && ( | ||
<S.Toast> | ||
<Icon name="Smile" /> | ||
링크가 복사되었습니다! | ||
</S.Toast> | ||
)} | ||
</S.Container> | ||
); | ||
}; | ||
|
||
export default ShareIcon; |
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 @@ | ||
export { default } from './ShareIcon'; |
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