react-icons/md#MdContentCopy TypeScript Examples

The following examples show how to use react-icons/md#MdContentCopy. 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: CodeCopy.tsx    From frontend with Apache License 2.0 6 votes vote down vote up
CodeCopy: FunctionComponent<Props> = ({ text, onCopy, className, nested }) => {
  const { t } = useTranslation()
  const [copied, setCopied] = useState(false)

  useEffect(() => {
    const timeout = setTimeout(() => {
      if (copied) setCopied(false);
    }, 1200);

    return () => clearTimeout(timeout);
  }, [copied]);


  return (< div className={`${styles.pre} ${className} ${nested ? styles.nested : ''}`}>
    {text}
    <CopyToClipboard text={text} onCopy={() => {
      setCopied(true)
      onCopy()
    }}>
      <button className={styles.copy} title={t('copy-text')}>
        {!copied && <MdContentCopy></MdContentCopy>}
        {copied && <MdCheck style={{ 'color': "green" }}></MdCheck>}
      </button>
    </CopyToClipboard >
  </div >
  )
}
Example #2
Source File: CodeBlockWithCopy.tsx    From slice-machine with Apache License 2.0 5 votes vote down vote up
CodeBlockWithCopy: React.FC<{ children: string }> = ({ children }) => {
  const { theme } = useThemeUI();
  const [isCopied, setIsCopied] = useState(false);

  const copy = (): void => {
    children &&
      navigator.clipboard.writeText(children).then(() => {
        setIsCopied(true);
        setTimeout(() => {
          setIsCopied(false);
        }, 1200);
      });
  };

  return (
    <Box sx={{ position: "relative" }}>
      <CodeBlock codeStyle={{ padding: "16px", width: "100%" }}>
        {children}
      </CodeBlock>
      <Button
        onClick={copy}
        sx={{
          position: "absolute",
          top: "4px",
          right: "4px",
          width: 24,
          height: 24,
          display: "flex",
          justifyContent: "center",
          alignItems: "center",
          p: 0,
        }}
      >
        {isCopied ? (
          <MdCheck
            size={16}
            color={theme?.colors?.success as string | undefined}
          />
        ) : (
          <MdContentCopy size={14} />
        )}
      </Button>
    </Box>
  );
}