on df0c310 help sign in
bridge/src/components/copiable/CopiableWithTooltip.jsx
30 lines 744 B history raw
1import React from 'react';
3import useCopiable from 'lib/useCopiable';
4import WithTooltip, { TooltipPosition } from 'components/WithTooltip';
5import { Icon } from '@tlon/indigo-react';
7export default function CopiableWithTooltip({
8 as: As = 'span',
9 text,
10 children = null,
11 className,
12 position = TooltipPosition.Top,
13 ...rest
14}) {
15 const [doCopy, didCopy] = useCopiable(text || children);
17 return (
18 <As className={className} {...rest}>
19 {children}
20 <WithTooltip position={position} content={didCopy ? 'Copied!' : 'Copy'}>
21 <Icon
22 icon="Copy"
23 style={{ height: '1em', width: '1em' }}
24 className="ml1 pointer"
25 onClick={doCopy}
26 />
27 </WithTooltip>
28 </As>
29 );