PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 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 All 162 releases
cartflows / modules / gutenberg / src / components / tabs / index.js

index.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/gutenberg/src/components/tabs/index.js

81 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { TabPanel } from '@wordpress/components';
2 import styles from './editor.lazy.scss';
3 import React, { useLayoutEffect } from 'react';
4 import Separator from '@Components/separator';
5 import { useRef } from '@wordpress/element';
6 import { select } from '@wordpress/data'
7 import getUAGEditorStateLocalStorage from '@Controls/getUAGEditorStateLocalStorage';
8
9 const UAGTabsControl = ( props ) => {
10 // Add and remove the CSS on the drop and remove of the component.
11 useLayoutEffect( () => {
12 styles.use();
13 return () => {
14 styles.unuse();
15 };
16 }, [] );
17
18
19 const tabRef = useRef( null );
20
21 const tabsCountClass =
22 3 === props.tabs.length ? 'uag-control-tabs-three-tabs ' : '';
23
24 const tabs = props.tabs.map( ( tab, index )=>{
25 return {
26 ...tab,
27 className: `uagb-tab-${index + 1} ${tab?.name}`
28 }
29 } );
30
31 return (
32 <>
33 <TabPanel
34 className={ `uag-control-tabs ${ tabsCountClass }` }
35 activeClass="active-tab"
36 tabs={ tabs }
37 ref={ tabRef }
38 onSelect= {
39 ( tabName ) => {
40 const selectedTab = document.getElementsByClassName( 'uag-control-tabs' )[0]?.querySelector( `.${ tabName }` );
41 let selectedTabClass = false;
42 if ( selectedTab && selectedTab?.classList ) {
43 selectedTab?.classList.forEach( ( className ) => {
44 if ( className.includes( 'uagb-tab' ) ) {
45 selectedTabClass = `.${ className }`;
46 }
47 } );
48 }
49
50 const { getSelectedBlock } = select( 'core/block-editor' );
51 const blockName = getSelectedBlock()?.name;
52 const uagSettingState = getUAGEditorStateLocalStorage( 'uagSettingState' );
53 const data = {
54 ...uagSettingState,
55 [blockName] : {
56 ...uagSettingState?.[blockName],
57 selectedInnerTab : selectedTabClass
58 }
59 }
60
61 const uagLocalStorage = getUAGEditorStateLocalStorage();
62 if ( uagLocalStorage ) {
63 uagLocalStorage.setItem( 'uagSettingState', JSON.stringify( data ) );
64 }
65 }
66 }
67 >
68 { ( tabName ) => {
69 return (
70 <div className="uag-control-tabs-output">
71 { props[ tabName.name ] }
72 </div>
73 );
74 } }
75 </TabPanel>
76 { ! props?.disableBottomSeparator && <Separator/> }
77 </>
78 );
79 };
80 export default UAGTabsControl;
81