import React from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import config from '../../../config'; import { getTextualContent, getCodeBlocks, optimizeAllNodes } from '../util'; import ClipboardIcon from './SVGs/ClipboardIcon'; // import ShareIcon from './SVGs/ShareIcon'; import AniLink from 'gatsby-plugin-transition-link/AniLink'; import CollapseOpenIcon from './SVGs/CollapseOpenIcon'; import CollapseClosedIcon from './SVGs/CollapseClosedIcon'; import ReactCSSTransitionReplace from 'react-css-transition-replace'; // =================================================== // Snippet Card HOC - check components below for more // =================================================== const SnippetCard = ({ short, snippetData, ...rest }) => { let difficulty = snippetData.tags.includes('advanced') ? 'advanced' : snippetData.tags.includes('beginner') ? 'beginner' : 'intermediate'; return short ? ( ) : ( ); }; // =================================================== // Simple card corner for difficulty display // =================================================== const CardCorner = ({ difficulty = 'intermediate' }) => (
); // =================================================== // Full snippet view (tags, code, title, description) // =================================================== const FullCard = ({ snippetData, difficulty, isDarkMode }) => { const [examplesOpen, setExamplesOpen] = React.useState(false); const tags = snippetData.tags; let cardCodeHtml = `${optimizeAllNodes( getCodeBlocks(snippetData.html).code, )}`; let cardExamplesHtml = `${optimizeAllNodes( getCodeBlocks(snippetData.html).example, )}`; return (

{snippetData.title}

{tags.map(tag => ( {tag} ))}
{ let tst = document.createElement('div'); tst.classList = 'toast'; tst.innerHTML = 'Snippet copied to clipboard!'; document.body.appendChild(tst); setTimeout(function() { tst.style.opacity = 0; setTimeout(function() { document.body.removeChild(tst); }, 300); }, 1700); }} > {/* */}
        
        
          {examplesOpen && (
            
          )}
        
      
); }; // =================================================== // Short snippet view (title, description, code*) // =================================================== const ShortCard = ({ snippetData, difficulty, isDarkMode }) => { let cardCodeHtml = `${optimizeAllNodes( getCodeBlocks(snippetData.html).code, )}`; return (

{snippetData.title}

{ let tst = document.createElement('div'); tst.classList = 'toast'; tst.innerHTML = 'Snippet copied to clipboard!'; document.body.appendChild(tst); setTimeout(function() { tst.style.opacity = 0; setTimeout(function() { document.body.removeChild(tst); }, 300); }, 1700); }} >
      
); }; export default SnippetCard;