-
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.
- Loading branch information
1 parent
c5a4d1e
commit 64677b3
Showing
8 changed files
with
1,756 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/pancake-uikit/src/__tests__/components/tokenimage.test.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,48 @@ | ||
import React from "react"; | ||
import { renderWithTheme, setupMockIntersectionObserver } from "../../testHelpers"; | ||
import TokenImage from "../../components/Image/TokenImage"; | ||
|
||
it("renders correctly", () => { | ||
setupMockIntersectionObserver(); | ||
const { asFragment } = renderWithTheme( | ||
<TokenImage tokenAddress="0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82" height={48} width={48} /> | ||
); | ||
expect(asFragment()).toMatchInlineSnapshot(` | ||
<DocumentFragment> | ||
.c0 { | ||
position: relative; | ||
background-position: center center; | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
height: 48px; | ||
max-width: 48px; | ||
max-height: 48px; | ||
width: 100%; | ||
padding-top: 0%; | ||
} | ||
.c1 { | ||
-webkit-align-items: center; | ||
-webkit-box-align: center; | ||
-ms-flex-align: center; | ||
align-items: center; | ||
background-origin: border-box; | ||
border: 2px solid rgba(0,0,0,0.25); | ||
border-radius: 50%; | ||
display: -webkit-inline-box; | ||
display: -webkit-inline-flex; | ||
display: -ms-inline-flexbox; | ||
display: inline-flex; | ||
height: 48px; | ||
width: 48px; | ||
z-index: 5; | ||
} | ||
<div | ||
class="c0 c1" | ||
height="48" | ||
width="48" | ||
/> | ||
</DocumentFragment> | ||
`); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/pancake-uikit/src/components/Image/TokenImage.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,26 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import BackgroundImage from "./BackgroundImage"; | ||
import { TokenImageProps } from "./types"; | ||
|
||
const StyledTokenImage = styled(BackgroundImage)` | ||
align-items: center; | ||
background-origin: border-box; | ||
border: 2px solid rgba(0, 0, 0, 0.25); | ||
border-radius: 50%; | ||
display: inline-flex; | ||
height: ${({ height }) => `${height}px`}; | ||
width: ${({ width }) => `${width}px`}; | ||
z-index: 5; | ||
`; | ||
|
||
const TokenImage: React.FC<TokenImageProps> = ({ | ||
tokenAddress, | ||
baseUrl = "https://pancakeswap.finance/images/tokens", | ||
imageFormat = "png", | ||
...props | ||
}) => { | ||
return <StyledTokenImage src={`${baseUrl}/${tokenAddress}.${imageFormat}`} {...props} />; | ||
}; | ||
|
||
export default TokenImage; |
35 changes: 35 additions & 0 deletions
35
packages/pancake-uikit/src/components/Image/TokenPairImage.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,35 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import Flex from "../Box/Flex"; | ||
import TokenImage from "./TokenImage"; | ||
import { TokenPairImageProps } from "./types"; | ||
|
||
const StyledSecondaryImage = styled(TokenImage)` | ||
bottom: -4px; | ||
position: absolute; | ||
right: -4px; | ||
z-index: 6; | ||
`; | ||
|
||
const TokenPairImage: React.FC<TokenPairImageProps> = ({ | ||
primaryTokenAddress, | ||
secondaryTokenAddress, | ||
width, | ||
height, | ||
...props | ||
}) => { | ||
const secondaryImageSize = Math.floor(width / 2); | ||
|
||
return ( | ||
<Flex alignItems="center" position="relative" display="inline-flex" width={width} height={height}> | ||
<TokenImage tokenAddress={primaryTokenAddress} width={width} height={height} {...props} /> | ||
<StyledSecondaryImage | ||
tokenAddress={secondaryTokenAddress} | ||
width={secondaryImageSize} | ||
height={secondaryImageSize} | ||
/> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default TokenPairImage; |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as BackgroundImage } from "./BackgroundImage"; | ||
export { default as Image } from "./Image"; | ||
export { default as TokenImage } from "./TokenImage"; | ||
export { default as TokenPairImage } from "./TokenPairImage"; |
Oops, something went wrong.