-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ActionInfo component #642
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||
import { useState } from 'react' | ||||||
import { useTheme } from '@mui/material/styles' | ||||||
import { Stack } from '@mui/material' | ||||||
import Snackbar from '@mui/material/Snackbar' | ||||||
import Alert from '@mui/material/Alert' | ||||||
import AlertTitle from '@mui/material/AlertTitle' | ||||||
import IconButton from '@mui/material/IconButton' | ||||||
import Icon from 'ui/src/Icon' | ||||||
import Typography from '@mui/material/Typography' | ||||||
import Link from '@mui/material/Link' | ||||||
import { Duration } from '../../themes/design/0_primitives' | ||||||
import { shortenTokenAddress } from 'ui/src/utils/' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh shit didn't know this existed, now we have a somewhat duplicate implementation with |
||||||
import { t } from 'i18next' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait what's this, aren't we using |
||||||
import { SizesAndSpaces } from '../../themes/design/1_sizes_spaces' | ||||||
|
||||||
const { Spacing } = SizesAndSpaces | ||||||
|
||||||
type ComponentSize = 'S' | 'M' | 'L' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
type ActionInfoProps = { | ||||||
label: string | ||||||
address: string | ||||||
linkAddress: string | ||||||
size?: ComponentSize | ||||||
} | ||||||
|
||||||
const labelSize: Record<ComponentSize, 'bodyXsRegular' | 'bodyMRegular'> = { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could just use |
||||||
S: 'bodyXsRegular', | ||||||
M: 'bodyMRegular', | ||||||
L: 'bodyMRegular', | ||||||
} | ||||||
|
||||||
const addressSize: Record<ComponentSize, 'bodyXsBold' | 'highlightM' | 'headingSBold'> = { | ||||||
S: 'bodyXsBold', | ||||||
M: 'highlightM', | ||||||
L: 'headingSBold', | ||||||
} | ||||||
|
||||||
const ActionInfo = ({ label, address, linkAddress, size = 'S' }: ActionInfoProps) => { | ||||||
const { | ||||||
design: { Button }, | ||||||
} = useTheme() | ||||||
const [openCopyAlert, setOpenCopyAlert] = useState(false) | ||||||
OnlyJousting marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
const copyValue = () => { | ||||||
navigator.clipboard.writeText(address) | ||||||
setOpenCopyAlert(true) | ||||||
} | ||||||
|
||||||
return ( | ||||||
<Stack direction="row" alignItems="center" justifyContent="space-between"> | ||||||
<Typography variant={labelSize[size]} color="textTertiary"> | ||||||
{label} | ||||||
</Typography> | ||||||
<Stack direction="row" alignItems="center"> | ||||||
<Typography variant={addressSize[size]} color="textPrimary" sx={{ marginRight: Spacing.sm }}> | ||||||
{shortenTokenAddress(address)} | ||||||
</Typography> | ||||||
<IconButton size="small" onClick={copyValue} sx={{ svg: { color: Button.Primary.Default.Fill } }}> | ||||||
OnlyJousting marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
<Icon name="Copy" size={24} /> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it returns values in 'rem' and the Icon component requires |
||||||
</IconButton> | ||||||
<IconButton | ||||||
component={Link} | ||||||
href={linkAddress} | ||||||
target="_blank" | ||||||
rel="noopener" | ||||||
size="small" | ||||||
sx={{ svg: { color: Button.Primary.Default.Fill } }} | ||||||
> | ||||||
<Icon name="ArrowUpRight" size={24} /> | ||||||
</IconButton> | ||||||
</Stack> | ||||||
|
||||||
<Snackbar open={openCopyAlert} onClose={() => setOpenCopyAlert(false)} autoHideDuration={Duration.Snackbar}> | ||||||
<Alert variant="filled" severity="success"> | ||||||
<AlertTitle>{t`Copied to clipboard!`}</AlertTitle> | ||||||
{address} | ||||||
</Alert> | ||||||
</Snackbar> | ||||||
</Stack> | ||||||
) | ||||||
} | ||||||
|
||||||
export default ActionInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use
@ui-kit
if you want to instead of relative files.