PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.4.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.4.1
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / tabs-tab / edit.js

edit.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.4.1, at gutenberg/blocks/tabs-tab/edit.js

76 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import {
4 InnerBlocks,
5 useBlockProps,
6 useInnerBlocksProps,
7 } from '@wordpress/block-editor';
8 import { useSelect } from '@wordpress/data';
9 import { useEffect } from '@wordpress/element';
10 import { applyFilters } from '@wordpress/hooks';
11
12 /**
13 * Block Edit Class.
14 *
15 * @param props
16 */
17 export default function BlockEdit(props) {
18 const { clientId, attributes, setAttributes, context } = props;
19 const { slug, active, anchor } = attributes;
20 const { 'ghostkit/tabActive': tabActive } = context;
21
22 let { className = '' } = props;
23
24 // Update active state.
25 useEffect(() => {
26 if (tabActive === slug && !active) {
27 setAttributes({ active: true });
28 } else if (tabActive !== slug && active) {
29 setAttributes({ active: false });
30 }
31 }, [active, setAttributes, slug, tabActive]);
32
33 // Update anchor.
34 useEffect(() => {
35 if (anchor !== `${slug}-content`) {
36 setAttributes({ anchor: `${slug}-content` });
37 }
38 }, [slug, anchor, setAttributes]);
39
40 const hasChildBlocks = useSelect(
41 (select) => {
42 const blockEditor = select('core/block-editor');
43
44 return blockEditor
45 ? blockEditor.getBlockOrder(clientId).length > 0
46 : false;
47 },
48 [clientId]
49 );
50
51 className = classnames(
52 className,
53 'ghostkit-tab',
54 tabActive === slug && 'ghostkit-tab-active'
55 );
56
57 className = applyFilters('ghostkit.editor.className', className, props);
58
59 const blockProps = useBlockProps({
60 className,
61 tabIndex: 0,
62 role: 'tabpanel',
63 'aria-labelledby': slug,
64 'data-tab': slug,
65 });
66
67 const innerBlockProps = useInnerBlocksProps(blockProps, {
68 renderAppender: hasChildBlocks
69 ? undefined
70 : InnerBlocks.ButtonBlockAppender,
71 templateLock: false,
72 });
73
74 return <div {...innerBlockProps} />;
75 }
76