-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add copy token address button to currency input panel (#3334)
To review 1. Go to swap 2. Select token from list 3. See copy address button
- Loading branch information
Showing
3 changed files
with
139 additions
and
83 deletions.
There are no files selected for viewing
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,72 @@ | ||
import { useState } from 'react' | ||
import { CopyIcon, SvgProps } from '@pancakeswap/uikit' | ||
import { copyText } from 'utils/copyText' | ||
import styled from 'styled-components' | ||
|
||
const Tooltip = styled.div<{ | ||
isTooltipDisplayed: boolean | ||
tooltipTop: number | ||
tooltipRight: number | ||
tooltipFontSize?: number | ||
}>` | ||
display: ${({ isTooltipDisplayed }) => (isTooltipDisplayed ? 'inline' : 'none')}; | ||
position: absolute; | ||
padding: 8px; | ||
top: ${({ tooltipTop }) => `${tooltipTop}px`}; | ||
right: ${({ tooltipRight }) => (tooltipRight ? `${tooltipRight}px` : 0)}; | ||
text-align: center; | ||
font-size: ${({ tooltipFontSize }) => `${tooltipFontSize}px` ?? '100%'}; | ||
background-color: ${({ theme }) => theme.colors.contrast}; | ||
color: ${({ theme }) => theme.colors.invertedContrast}; | ||
border-radius: 16px; | ||
opacity: 0.7; | ||
width: max-content; | ||
` | ||
|
||
interface CopyButtonProps extends SvgProps { | ||
text: string | ||
tooltipMessage: string | ||
tooltipTop: number | ||
tooltipRight?: number | ||
tooltipFontSize?: number | ||
buttonColor?: string | ||
} | ||
|
||
export const CopyButton: React.FC<CopyButtonProps> = ({ | ||
text, | ||
tooltipMessage, | ||
width, | ||
tooltipTop, | ||
tooltipRight, | ||
tooltipFontSize, | ||
buttonColor = 'primary', | ||
...props | ||
}) => { | ||
const [isTooltipDisplayed, setIsTooltipDisplayed] = useState(false) | ||
|
||
const displayTooltip = () => { | ||
setIsTooltipDisplayed(true) | ||
setTimeout(() => { | ||
setIsTooltipDisplayed(false) | ||
}, 1000) | ||
} | ||
return ( | ||
<> | ||
<CopyIcon | ||
style={{ cursor: 'pointer' }} | ||
color={buttonColor} | ||
width={width} | ||
onClick={() => copyText(text, displayTooltip)} | ||
{...props} | ||
/> | ||
<Tooltip | ||
isTooltipDisplayed={isTooltipDisplayed} | ||
tooltipTop={tooltipTop} | ||
tooltipRight={tooltipRight} | ||
tooltipFontSize={tooltipFontSize} | ||
> | ||
{tooltipMessage} | ||
</Tooltip> | ||
</> | ||
) | ||
} |
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