Commit 83b6eec2 authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

fix(copy-icon): makes copy icon configurable for different uses (#3853)

parent cd76fffb
...@@ -10,7 +10,6 @@ const CopyIcon = styled(LinkStyledButton)` ...@@ -10,7 +10,6 @@ const CopyIcon = styled(LinkStyledButton)`
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;
text-decoration: none; text-decoration: none;
font-size: 12px;
:hover, :hover,
:active, :active,
:focus { :focus {
...@@ -18,20 +17,36 @@ const CopyIcon = styled(LinkStyledButton)` ...@@ -18,20 +17,36 @@ const CopyIcon = styled(LinkStyledButton)`
color: ${({ color, theme }) => color || theme.text2}; color: ${({ color, theme }) => color || theme.text2};
} }
` `
const TransactionStatusText = styled.span` const StyledText = styled.span`
margin-left: 0.25rem; margin-left: 0.25rem;
font-size: 12px;
${({ theme }) => theme.flexRowNoWrap}; ${({ theme }) => theme.flexRowNoWrap};
align-items: center; align-items: center;
` `
const Copied = ({ iconSize }: { iconSize?: number }) => (
<StyledText>
<CheckCircle size={iconSize ?? '16'} />
<StyledText>
<Trans>Copied</Trans>
</StyledText>
</StyledText>
)
const Icon = ({ iconSize }: { iconSize?: number }) => (
<StyledText>
<Copy size={iconSize ?? '16'} />
</StyledText>
)
interface BaseProps { interface BaseProps {
toCopy: string toCopy: string
color?: string color?: string
iconSize?: number
iconPosition?: 'left' | 'right'
} }
export type CopyHelperProps = BaseProps & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof BaseProps> export type CopyHelperProps = BaseProps & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof BaseProps>
export default function CopyHelper({ color, toCopy, children }: CopyHelperProps) { export default function CopyHelper({ color, toCopy, children, iconSize, iconPosition }: CopyHelperProps) {
const [isCopied, setCopied] = useCopyClipboard() const [isCopied, setCopied] = useCopyClipboard()
const copy = useCallback(() => { const copy = useCallback(() => {
setCopied(toCopy) setCopied(toCopy)
...@@ -39,20 +54,11 @@ export default function CopyHelper({ color, toCopy, children }: CopyHelperProps) ...@@ -39,20 +54,11 @@ export default function CopyHelper({ color, toCopy, children }: CopyHelperProps)
return ( return (
<CopyIcon onClick={copy} color={color}> <CopyIcon onClick={copy} color={color}>
{iconPosition === 'left' ? isCopied ? <Copied iconSize={iconSize} /> : <Icon iconSize={iconSize} /> : null}
{iconPosition === 'left' && <>&nbsp;</>}
{isCopied ? '' : children} {isCopied ? '' : children}
&nbsp; {iconPosition === 'right' && <>&nbsp;</>}
{isCopied ? ( {iconPosition === 'right' ? isCopied ? <Copied iconSize={iconSize} /> : <Icon iconSize={iconSize} /> : null}
<TransactionStatusText>
<CheckCircle size={'12'} />
<TransactionStatusText>
<Trans>Copied</Trans>
</TransactionStatusText>
</TransactionStatusText>
) : (
<TransactionStatusText>
<Copy size={'12'} />
</TransactionStatusText>
)}
</CopyIcon> </CopyIcon>
) )
} }
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Connector } from '@web3-react/types' import { Connector } from '@web3-react/types'
import CopyHelper from 'components/AccountDetails/Copy'
import useActiveWeb3React from 'hooks/useActiveWeb3React' import useActiveWeb3React from 'hooks/useActiveWeb3React'
import { useCallback, useContext } from 'react' import { useCallback, useContext } from 'react'
import { ExternalLink as LinkIcon } from 'react-feather' import { ExternalLink as LinkIcon } from 'react-feather'
...@@ -17,7 +18,6 @@ import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink' ...@@ -17,7 +18,6 @@ import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink'
import { ButtonSecondary } from '../Button' import { ButtonSecondary } from '../Button'
import StatusIcon from '../Identicon/StatusIcon' import StatusIcon from '../Identicon/StatusIcon'
import { AutoRow } from '../Row' import { AutoRow } from '../Row'
import Copy from './Copy'
import Transaction from './Transaction' import Transaction from './Transaction'
const HeaderRow = styled.div` const HeaderRow = styled.div`
...@@ -310,11 +310,11 @@ export default function AccountDetails({ ...@@ -310,11 +310,11 @@ export default function AccountDetails({
<AccountControl> <AccountControl>
<div> <div>
{account && ( {account && (
<Copy toCopy={account}> <CopyHelper toCopy={account} iconPosition="left">
<span style={{ marginLeft: '4px' }}> <span style={{ marginLeft: '4px' }}>
<Trans>Copy Address</Trans> <Trans>Copy Address</Trans>
</span> </span>
</Copy> </CopyHelper>
)} )}
{chainId && account && ( {chainId && account && (
<AddressLink <AddressLink
...@@ -336,11 +336,11 @@ export default function AccountDetails({ ...@@ -336,11 +336,11 @@ export default function AccountDetails({
<AccountControl> <AccountControl>
<div> <div>
{account && ( {account && (
<Copy toCopy={account}> <CopyHelper toCopy={account} iconPosition="left">
<span style={{ marginLeft: '4px' }}> <span style={{ marginLeft: '4px' }}>
<Trans>Copy Address</Trans> <Trans>Copy Address</Trans>
</span> </span>
</Copy> </CopyHelper>
)} )}
{chainId && account && ( {chainId && account && (
<AddressLink <AddressLink
......
...@@ -18,6 +18,9 @@ const WarningIcon = styled(AlertOctagon)` ...@@ -18,6 +18,9 @@ const WarningIcon = styled(AlertOctagon)`
min-width: 22px; min-width: 22px;
color: ${({ theme }) => theme.warning}; color: ${({ theme }) => theme.warning};
` `
const Copy = styled(CopyHelper)`
font-size: 12px;
`
interface ConnectedAccountBlockedProps { interface ConnectedAccountBlockedProps {
account: string | null | undefined account: string | null | undefined
...@@ -46,9 +49,9 @@ export default function ConnectedAccountBlocked(props: ConnectedAccountBlockedPr ...@@ -46,9 +49,9 @@ export default function ConnectedAccountBlocked(props: ConnectedAccountBlockedPr
<ThemedText.Main fontSize={12}> <ThemedText.Main fontSize={12}>
<Trans>If you believe this is an error, please send an email including your address to </Trans>{' '} <Trans>If you believe this is an error, please send an email including your address to </Trans>{' '}
</ThemedText.Main> </ThemedText.Main>
<CopyHelper toCopy="compliance@uniswap.org" color={theme.primary1}> <Copy iconSize={12} toCopy="compliance@uniswap.org" color={theme.primary1} iconPosition="right">
compliance@uniswap.org. compliance@uniswap.org
</CopyHelper> </Copy>
</ContentWrapper> </ContentWrapper>
</Modal> </Modal>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment