2022-12-01 16:46:06 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Box from '../../../ui/box';
|
|
|
|
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,
|
2023-02-04 00:47:45 +01:00
|
|
|
Color,
|
2022-12-01 16:46:06 +01:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
2023-04-19 23:16:49 +02:00
|
|
|
import { Icon, IconName, IconSize } from '../../../component-library';
|
2022-12-01 16:46:06 +01:00
|
|
|
|
|
|
|
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 ? (
|
2023-02-03 23:06:14 +01:00
|
|
|
<Icon
|
2023-04-19 23:16:49 +02:00
|
|
|
name={IconName.CopySuccess}
|
|
|
|
size={IconSize.Lg}
|
2023-02-04 00:47:45 +01:00
|
|
|
color={Color.iconAlternative}
|
2022-12-01 16:46:06 +01:00
|
|
|
/>
|
|
|
|
) : (
|
2023-02-03 23:06:14 +01:00
|
|
|
<Icon
|
2023-04-19 23:16:49 +02:00
|
|
|
name={IconName.Copy}
|
|
|
|
size={IconSize.Lg}
|
2023-02-04 00:47:45 +01:00
|
|
|
color={Color.iconAlternative}
|
2022-12-01 16:46:06 +01:00
|
|
|
onClick={() => handleCopy(text)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Copyable.propTypes = {
|
|
|
|
text: PropTypes.string,
|
|
|
|
};
|