PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.3
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.3
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 / transforms.js

transforms.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.3, at gutenberg/blocks/tabs/transforms.js

54 lines 964 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createBlock } from '@wordpress/blocks';
2
3 import getUniqueSlug from '../../utils/get-unique-slug';
4
5 export default {
6 from: [
7 {
8 type: 'block',
9 blocks: ['ghostkit/accordion'],
10 transform(attrs, innerBlocks) {
11 const tabsData = [];
12 let tabActive = '';
13
14 innerBlocks.forEach((item) => {
15 const slug = getUniqueSlug(
16 `tab-${item.attributes.heading}`,
17 item.clientId
18 );
19
20 if (!tabActive && item.attributes.active) {
21 tabActive = slug;
22 }
23
24 tabsData.push({
25 slug,
26 title: item.attributes.heading,
27 });
28 });
29
30 if (!tabActive) {
31 tabActive = tabsData[0].slug;
32 }
33
34 return createBlock(
35 'ghostkit/tabs-v2',
36 {
37 tabsData,
38 tabActive,
39 },
40 tabsData.map((tab, i) =>
41 createBlock(
42 'ghostkit/tabs-tab-v2',
43 {
44 slug: tab.slug,
45 },
46 innerBlocks[i] ? innerBlocks[i].innerBlocks : ''
47 )
48 )
49 );
50 },
51 },
52 ],
53 };
54