PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / trunk
Starter Sites & Templates by Neve vtrunk
1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / onboarding / src / Components / EditorSelector.js
templates-patterns-collection / onboarding / src / Components Last commit date
CustomizeControls 2 months ago Steps 2 weeks ago App.js 2 years ago CategoryButtons.js 2 weeks ago CustomTooltip.js 2 years ago EditorSelector.js 2 years ago FeaturesList.js 1 year ago Filters.js 2 weeks ago Header.js 2 weeks ago ImportError.js 2 years ago ImportForm.js 1 year ago ImportMock.js 2 years ago ImportProgress.js 1 year ago Onboarding.js 2 weeks ago ProgressBar.js 2 years ago Search.js 2 weeks ago SitePreview.js 2 years ago SiteSettings.js 2 months ago Sites.js 2 weeks ago StarterSiteCard.js 2 weeks ago Toast.js 2 weeks ago WelcomeMock.js 2 years ago
EditorSelector.js
119 lines
1 /* global tiobDash */
2 import { __ } from '@wordpress/i18n';
3 import { useState, useEffect, useRef } from '@wordpress/element';
4 import { Button, Dashicon } from '@wordpress/components';
5 import { withDispatch, withSelect } from '@wordpress/data';
6 import { compose } from '@wordpress/compose';
7 import classnames from 'classnames';
8 import { EDITOR_MAP } from '../utils/common';
9
10 const EditorSelector = ( { editor, setCurrentEditor, sites } ) => {
11 const [ open, setOpen ] = useState( false );
12 const editorsOrderedFromAPI = Object.keys( sites );
13 const dropdownRef = useRef();
14
15 const toggleDropdown = () => setOpen( ! open );
16
17 const handleOutsideClick = ( e ) => {
18 if (
19 dropdownRef.current &&
20 ! dropdownRef.current.contains( e.target )
21 ) {
22 setOpen( false );
23 }
24 };
25
26 useEffect( () => {
27 const win = document.defaultView;
28 win.addEventListener( 'click', handleOutsideClick );
29
30 return () => {
31 win.removeEventListener( 'click', handleOutsideClick );
32 };
33 }, [] );
34
35 const toggleButtonClasses = classnames(
36 'select',
37 'ob-dropdown',
38 open ? 'active' : ''
39 );
40
41 return (
42 <div className="ob-editor-selector" ref={ dropdownRef }>
43 <Button
44 onClick={ toggleDropdown }
45 className={ toggleButtonClasses }
46 >
47 <span className="ob-current-editor">
48 <img
49 className="editor-icon"
50 src={
51 tiobDash.assets + 'img/' + EDITOR_MAP[ editor ].icon
52 }
53 alt={ __(
54 'Builder Logo',
55 'templates-patterns-collection'
56 ) }
57 />
58 <Dashicon
59 size={ 14 }
60 icon={ open ? 'arrow-up-alt2' : 'arrow-down-alt2' }
61 />
62 </span>
63 { open && (
64 <span className="ob-editor-options">
65 <ul className="options">
66 { editorsOrderedFromAPI.map( ( key, index ) => {
67 if ( key === editor ) {
68 return null;
69 }
70 return (
71 <li key={ index }>
72 <button
73 className="ob-editor-option"
74 onClick={ ( e ) => {
75 e.preventDefault();
76 setCurrentEditor( key );
77 setOpen( false );
78 } }
79 >
80 <img
81 className="editor-icon"
82 src={
83 tiobDash.assets +
84 'img/' +
85 EDITOR_MAP[ key ].icon
86 }
87 alt={ __(
88 'Builder Logo',
89 'templates-patterns-collection'
90 ) }
91 />
92 </button>
93 </li>
94 );
95 } ) }
96 </ul>
97 </span>
98 ) }
99 </Button>
100 </div>
101 );
102 };
103
104 export default compose(
105 withSelect( ( select ) => {
106 const { getCurrentEditor, getSites } = select( 'ti-onboarding' );
107 return {
108 editor: getCurrentEditor(),
109 sites: getSites().sites,
110 };
111 } ),
112 withDispatch( ( dispatch ) => {
113 const { setCurrentEditor } = dispatch( 'ti-onboarding' );
114 return {
115 setCurrentEditor: ( editor ) => setCurrentEditor( editor ),
116 };
117 } )
118 )( EditorSelector );
119