2022-12-01 16:46:06 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Box from '../../../ui/box';
|
|
|
|
import IconCopied from '../../../ui/icon/icon-copied';
|
|
|
|
import IconCopy from '../../../ui/icon/icon-copy';
|
|
|
|
import Typography from '../../../ui/typography';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
|
|
|
BorderRadius,
|
|
|
|
JustifyContent,
|
2022-12-01 16:46:06 +01:00
|
|
|
OVERFLOW_WRAP,
|
|
|
|
FLEX_DIRECTION,
|
2023-02-02 21:15:26 +01:00
|
|
|
TypographyVariant,
|
|
|
|
BackgroundColor,
|
|
|
|
TextColor,
|
2022-12-01 16:46:06 +01:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
|
|
|
|
|
|
|
export const Copyable = ({ text }) => {
|
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className="copyable"
|
2023-02-02 21:15:26 +01:00
|
|
|
backgroundColor={BackgroundColor.backgroundAlternative}
|
|
|
|
alignItems={AlignItems.stretch}
|
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
|
|
|
borderRadius={BorderRadius.SM}
|
2022-12-01 16:46:06 +01:00
|
|
|
paddingLeft={4}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingTop={2}
|
|
|
|
paddingBottom={2}
|
|
|
|
>
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H6}
|
|
|
|
color={TextColor.textAlternative}
|
2022-12-01 16:46:06 +01:00
|
|
|
marginRight={2}
|
|
|
|
overflowWrap={OVERFLOW_WRAP.ANYWHERE}
|
|
|
|
>
|
|
|
|
{text}
|
|
|
|
</Typography>
|
|
|
|
<Box
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.flexStart}
|
2022-12-01 16:46:06 +01:00
|
|
|
marginTop={2}
|
|
|
|
marginBottom={1}
|
|
|
|
>
|
|
|
|
{copied ? (
|
|
|
|
<IconCopied
|
|
|
|
color="var(--color-icon-alternative)"
|
|
|
|
className="copyable__icon"
|
|
|
|
size={18}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<IconCopy
|
|
|
|
className="copyable__icon"
|
|
|
|
color="var(--color-icon-alternative)"
|
|
|
|
onClick={() => handleCopy(text)}
|
|
|
|
size={18}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Copyable.propTypes = {
|
|
|
|
text: PropTypes.string,
|
|
|
|
};
|