react-icons/hi#HiClipboardCopy TypeScript Examples

The following examples show how to use react-icons/hi#HiClipboardCopy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Clippy.tsx    From camunda-cockpit-plugins with Apache License 2.0 6 votes vote down vote up
Clippy: React.FC<Props> = ({ value, children }) => {
  const [mouseOver, setMouseOver] = useState(false);
  const [copied, setCopied] = useState(false);
  return (
    <span
      onMouseOver={() => {
        if (!mouseOver) {
          setMouseOver(true);
        }
      }}
      onMouseLeave={() => {
        setMouseOver(false);
        setCopied(false);
      }}
      style={{ display: 'flex', alignItems: 'center' }}
    >
      {children}
      {mouseOver ? (
        <CopyToClipboard text={value} onCopy={() => setCopied(true)}>
          <a
            href="#"
            onClick={e => {
              e.preventDefault();
            }}
            style={{ fontSize: '120%', paddingLeft: '0.2em' }}
          >
            {copied ? (
              <HiCheck style={{ color: 'green', display: 'flex' }} />
            ) : (
              <HiClipboardCopy style={{ display: 'flex' }} />
            )}
          </a>
        </CopyToClipboard>
      ) : (
        <span style={{ fontSize: '120%', width: '1.2em' }} />
      )}
    </span>
  );
}