Created a new token component (#15617)
Co-authored-by: ryanml <ryanlanese@gmail.com>feature/default_network_editable
parent
21e3b4785d
commit
341f761dd7
@ -0,0 +1,83 @@ |
||||
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import IconCopy from '../icon/icon-copy'; |
||||
import IconBlockExplorer from '../icon/icon-block-explorer'; |
||||
import Box from '../box/box'; |
||||
import Tooltip from '../tooltip/tooltip'; |
||||
import { useI18nContext } from '../../../hooks/useI18nContext'; |
||||
import Identicon from '../identicon/identicon.component'; |
||||
import Typography from '../typography/typography'; |
||||
import { |
||||
FONT_WEIGHT, |
||||
TYPOGRAPHY, |
||||
DISPLAY, |
||||
COLORS, |
||||
ALIGN_ITEMS, |
||||
JUSTIFY_CONTENT, |
||||
} from '../../../helpers/constants/design-system'; |
||||
import Button from '../button'; |
||||
import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard'; |
||||
|
||||
export default function ContractTokenValues({ address, tokenName }) { |
||||
const t = useI18nContext(); |
||||
const [copied, handleCopy] = useCopyToClipboard(); |
||||
|
||||
return ( |
||||
<Box |
||||
display={DISPLAY.FLEX} |
||||
alignItems={ALIGN_ITEMS.CENTER} |
||||
justifyContent={JUSTIFY_CONTENT.CENTER} |
||||
className="contract-token-values" |
||||
> |
||||
<Box marginRight={2}> |
||||
<Identicon address={address} diameter={24} /> |
||||
</Box> |
||||
<Typography |
||||
variant={TYPOGRAPHY.H2} |
||||
fontWeight={FONT_WEIGHT.BOLD} |
||||
color={COLORS.TEXT_ALTERNATIVE} |
||||
marginTop={0} |
||||
marginBottom={0} |
||||
> |
||||
{tokenName} |
||||
</Typography> |
||||
<Box className="contract-token-values__copy-address"> |
||||
<Tooltip |
||||
position="top" |
||||
title={copied ? t('copiedExclamation') : t('copyToClipboard')} |
||||
> |
||||
<Button |
||||
type="link" |
||||
className="contract-token-values__copy-address__button" |
||||
onClick={() => { |
||||
handleCopy(address); |
||||
}} |
||||
> |
||||
<IconCopy size={24} color="var(--color-icon-muted)" /> |
||||
</Button> |
||||
</Tooltip> |
||||
</Box> |
||||
<Box className="contract-token-values__block-explorer"> |
||||
<Tooltip position="top" title={t('openInBlockExplorer')}> |
||||
<Button |
||||
type="link" |
||||
className="contract-token-values__block-explorer__button" |
||||
> |
||||
<IconBlockExplorer size={24} color="var(--color-icon-muted)" /> |
||||
</Button> |
||||
</Tooltip> |
||||
</Box> |
||||
</Box> |
||||
); |
||||
} |
||||
|
||||
ContractTokenValues.propTypes = { |
||||
/** |
||||
* Address used for generating token image |
||||
*/ |
||||
address: PropTypes.string, |
||||
/** |
||||
* Displayed the token name currently tracked in state |
||||
*/ |
||||
tokenName: PropTypes.string, |
||||
}; |
@ -0,0 +1,27 @@ |
||||
import React from 'react'; |
||||
import ContractTokenValues from './contract-token-values'; |
||||
|
||||
export default { |
||||
title: 'Components/UI/ContractTokenValues', |
||||
id: __filename, |
||||
argTypes: { |
||||
tokenName: { |
||||
control: { |
||||
type: 'text', |
||||
}, |
||||
}, |
||||
address: { |
||||
control: { |
||||
type: 'text', |
||||
}, |
||||
}, |
||||
}, |
||||
args: { |
||||
tokenName: 'DAI', |
||||
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F', |
||||
}, |
||||
}; |
||||
|
||||
export const DefaultStory = (args) => <ContractTokenValues {...args} />; |
||||
|
||||
DefaultStory.storyName = 'Default'; |
@ -0,0 +1,17 @@ |
||||
.contract-token-values { |
||||
&__copy-address { |
||||
margin-inline-start: 8px; |
||||
|
||||
&__button { |
||||
padding: 0; |
||||
} |
||||
} |
||||
|
||||
&__block-explorer { |
||||
margin-inline-start: 8px; |
||||
|
||||
&__button { |
||||
padding: 0; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue