-
Notifications
You must be signed in to change notification settings - Fork 753
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 to clipboard on the address (#162)
- Loading branch information
1 parent
e0dba76
commit 9906aad
Showing
10 changed files
with
130 additions
and
38 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
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,13 @@ | ||
import React from "react"; | ||
import Svg from "../Svg"; | ||
import { SvgProps } from "../types"; | ||
|
||
const Icon: React.FC<SvgProps> = (props) => { | ||
return ( | ||
<Svg viewBox="0 0 24 24" {...props}> | ||
<path d="M15 1H4C2.9 1 2 1.9 2 3V16C2 16.55 2.45 17 3 17C3.55 17 4 16.55 4 16V4C4 3.45 4.45 3 5 3H15C15.55 3 16 2.55 16 2C16 1.45 15.55 1 15 1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM18 21H9C8.45 21 8 20.55 8 20V8C8 7.45 8.45 7 9 7H18C18.55 7 19 7.45 19 8V20C19 20.55 18.55 21 18 21Z" /> | ||
</Svg> | ||
); | ||
}; | ||
|
||
export default Icon; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
import Text from "../../components/Text/Text"; | ||
import { CopyIcon } from "../../components/Svg"; | ||
|
||
interface Props { | ||
toCopy?: string | number; | ||
} | ||
|
||
const StyleButton = styled(Text).attrs({ role: "button" })` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
color: ${({ theme }) => theme.colors.primary}; | ||
`; | ||
|
||
const Tooltip = styled.div<{ isTooltipDisplayed: boolean }>` | ||
display: ${({ isTooltipDisplayed }) => (isTooltipDisplayed ? "block" : "none")}; | ||
position: absolute; | ||
bottom: -22px; | ||
right: 0; | ||
left: 0; | ||
text-align: center; | ||
background-color: ${({ theme }) => theme.colors.contrast}; | ||
color: ${({ theme }) => theme.colors.invertedContrast}; | ||
border-radius: 16px; | ||
opacity: 0.7; | ||
`; | ||
|
||
const CopyToClipboard: React.FC<Props> = ({ toCopy, children, ...props }) => { | ||
const [isTooltipDisplayed, setIsTooltipDisplayed] = useState(false); | ||
|
||
return ( | ||
<StyleButton | ||
small | ||
bold | ||
onClick={() => { | ||
navigator.clipboard.writeText(JSON.stringify(toCopy)); | ||
setIsTooltipDisplayed(true); | ||
setTimeout(() => { | ||
setIsTooltipDisplayed(false); | ||
}, 1000); | ||
}} | ||
{...props} | ||
> | ||
{children} | ||
<CopyIcon width="20px" color="primary" ml="4px" /> | ||
<Tooltip isTooltipDisplayed={isTooltipDisplayed}>Copied</Tooltip> | ||
</StyleButton> | ||
); | ||
}; | ||
|
||
export default CopyToClipboard; |
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