SidebarContent.js (4826B)
1 import {Tooltip, Panel, PanelBody, PanelRow} from '@wordpress/components'; 2 import {more} from '@wordpress/icons'; 3 4 5 const {useState, useEffect} = wp.element 6 const {__} = wp.i18n 7 8 import * as Icons from '~redux-templates/icons' 9 import copy from 'clipboard-copy'; 10 import SafeImageLoad from '~redux-templates/components/safe-image-load'; 11 import {requiresInstall, requiresPro} from '~redux-templates/stores/dependencyHelper' 12 import React from 'react'; 13 14 export default function SidebarContent(props) { 15 const {itemData, pro} = props; 16 const {hash, name, image, blocks, proDependencies, installDependencies, url, source} = itemData; 17 const [copied, setCopied] = useState(false); 18 19 const copyHash = () => { 20 copy(hash.substring(0, 7)); 21 setCopied(true); 22 setTimeout(function () { 23 setCopied(false); 24 }, 3500); 25 } 26 27 useEffect(() => { 28 setCopied(false); 29 }, [itemData]); 30 31 32 if ('redux' === source) { 33 const source_instance = redux_templates.supported_plugins['redux-framework']; 34 } else { 35 const source_instance = redux_templates.supported_plugins[source]; 36 } 37 38 return ( 39 <div className="wp-full-overlay-sidebar-content"> 40 <div className="install-theme-info"> 41 <h3 className="theme-name">{name} { url && <Tooltip position={'top right'} 42 text={__('Full Preview', redux_templates.i18n)}><a href={url} 43 target="_blank"><i 44 className="fas fa-external-link-alt"/></a></Tooltip> }</h3> 45 <div className="theme-screenshot-wrap"> 46 <SafeImageLoad url={image} className="theme-screenshot"/> 47 {pro ? 48 <span className="redux-templates-pro-badge">{__('Premium', redux_templates.i18n)}</span> : ''} 49 </div> 50 51 <h5 className="theme-hash"> 52 <Tooltip position={'top center'} text={__('Copy the template identifier', redux_templates.i18n)}> 53 <div className="button-container" onClick={copyHash}> 54 <span className="button button-secondary the-copy"> 55 <i className="fa fa-copy" aria-hidden="true"></i> 56 </span> 57 <span className="button button-secondary the-hash">{hash.substring(0, 7)}</span> 58 {copied && <span className="copied hideMe"><br/>{__('copied', redux_templates.i18n)}</span>} 59 </div> 60 </Tooltip> 61 </h5> 62 </div> 63 { 64 installDependencies && installDependencies.length > 0 && 65 <PanelBody title={__('Required Plugins', redux_templates.i18n)} icon={more} initialOpen={true}> 66 <PanelRow className="requirements-list-div"> 67 <div className="requirements-list"> 68 <ul> 69 { 70 installDependencies.map(pluginKey => { 71 const pluginInstance = redux_templates.supported_plugins[pluginKey]; 72 if (!pluginInstance) { 73 console.log('Missing plugin details for ' + pluginKey); 74 return null; 75 } 76 const plugin_name = pluginKey.replace('-pro', '').replace('-premium', '').replace(/\W/g, '').toLowerCase(); 77 if ('redux' === plugin_name) { 78 return; 79 } 80 const IconComponent = Icons[plugin_name]; 81 return ( 82 83 <li key={pluginKey}> 84 {IconComponent && <IconComponent/>} 85 <span 86 className="redux-templates-dependency-name">{pluginInstance.name}</span> 87 {requiresInstall(itemData) && 88 <Tooltip position={'bottom center'} 89 text={__('Not Installed', redux_templates.i18n)}> 90 <div className='redux-icon-wrapper'><i 91 className="fa fa-exclamation-triangle"/></div> 92 </Tooltip> 93 } 94 {pluginInstance.url ? 95 <Tooltip position={'top right'} 96 text={__('Visit Plugin Website', redux_templates.i18n)}> 97 <span className="pluginURL"><a href={pluginInstance.url} 98 target="_blank"><i 99 className="fas fa-external-link-alt"/></a></span> 100 </Tooltip> : null} 101 </li>); 102 }) 103 } 104 </ul> 105 </div> 106 </PanelRow> 107 </PanelBody> 108 } 109 { blocks && blocks.length > 0 && 110 <PanelBody title={__('Blocks Used', redux_templates.i18n)} icon={more} initialOpen={true}> 111 <PanelRow className="redux-block-pills"> 112 <ul> 113 { 114 blocks.map((block, i) => { 115 return ( 116 <li key={i}><span>{block}</span></li> 117 ) 118 } ) 119 } 120 </ul> 121 </PanelRow> 122 </PanelBody> 123 } 124 125 { 126 'redux' !== source && 127 <PanelBody title={__('Template Details', redux_templates.i18n)} icon={more} initialOpen={false}> 128 <PanelRow className="redux-block-pills"> 129 <ul> 130 {'redux' !== source && <li><strong>Author</strong>: {source.slice(0,1).toUpperCase() + source.slice(1, source.length)}</li>} 131 </ul> 132 </PanelRow> 133 </PanelBody> 134 } 135 </div> 136 ); 137 }