PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.3
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.3
2.0.14 2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / section / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.3, at blocks/section/index.js

188 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 wp.domReady(function () {
2 var el = wp.element.createElement;
3 var __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var BlockControls = wp.blockEditor.BlockControls;
7 var useBlockProps = wp.blockEditor.useBlockProps;
8 var InnerBlocks = wp.blockEditor.InnerBlocks;
9 var PanelBody = wp.components.PanelBody;
10 var SelectControl = wp.components.SelectControl;
11 var ToolbarGroup = wp.components.ToolbarGroup;
12 var ToolbarButton = wp.components.ToolbarButton;
13 var ColorPalette = wp.components.ColorPalette;
14 var BaseControl = wp.components.BaseControl;
15
16 // Spacing token scale
17 var spacingOptions = [
18 { label: __('None', 'blockenberg'), value: 'none' },
19 { label: __('XS (8px)', 'blockenberg'), value: 'xs' },
20 { label: __('S (16px)', 'blockenberg'), value: 's' },
21 { label: __('M (32px)', 'blockenberg'), value: 'm' },
22 { label: __('L (48px)', 'blockenberg'), value: 'l' },
23 { label: __('XL (64px)', 'blockenberg'), value: 'xl' }
24 ];
25
26 // Background presets
27 var backgroundOptions = [
28 { label: __('None', 'blockenberg'), value: 'none' },
29 { label: __('Light', 'blockenberg'), value: 'light' },
30 { label: __('Dark', 'blockenberg'), value: 'dark' },
31 { label: __('Accent', 'blockenberg'), value: 'accent' },
32 { label: __('Custom', 'blockenberg'), value: 'custom' }
33 ];
34
35 // Max width options
36 var maxWidthOptions = [
37 { label: '1024px', value: '1024' },
38 { label: '1200px', value: '1200' },
39 { label: '1440px', value: '1440' }
40 ];
41
42 // Section icon
43 var sectionIcon = el('svg', {
44 width: 24,
45 height: 24,
46 viewBox: '0 0 24 24',
47 xmlns: 'http://www.w3.org/2000/svg'
48 },
49 el('path', {
50 d: 'M3 5h18v2H3V5zm0 12h18v2H3v-2zm0-6h18v2H3v-2z',
51 fill: 'currentColor'
52 })
53 );
54
55 registerBlockType('blockenberg/section', {
56 title: __('Section', 'blockenberg'),
57 icon: sectionIcon,
58 category: 'blockenberg',
59 description: __('A container section for organizing content with rows and columns.', 'blockenberg'),
60
61 edit: function (props) {
62 var attributes = props.attributes;
63 var setAttributes = props.setAttributes;
64 var a = attributes;
65
66 var blockProps = useBlockProps({
67 className: [
68 'bkbg-section',
69 'bkbg-section--width-' + a.contentWidth,
70 'bkbg-section--padding-' + a.paddingY,
71 'bkbg-section--bg-' + a.background
72 ].join(' '),
73 style: {
74 '--bkbg-section-max-width': a.boxedMaxWidth + 'px',
75 '--bkbg-section-custom-bg': a.backgroundColor || undefined
76 }
77 });
78
79 // Toolbar controls
80 var toolbar = el(BlockControls, {},
81 el(ToolbarGroup, {},
82 el(ToolbarButton, {
83 icon: 'align-full-width',
84 label: __('Full Width', 'blockenberg'),
85 isPressed: a.contentWidth === 'full',
86 onClick: function () { setAttributes({ contentWidth: 'full' }); }
87 }),
88 el(ToolbarButton, {
89 icon: 'align-center',
90 label: __('Boxed', 'blockenberg'),
91 isPressed: a.contentWidth === 'boxed',
92 onClick: function () { setAttributes({ contentWidth: 'boxed' }); }
93 })
94 )
95 );
96
97 // Inspector controls
98 var inspector = el(InspectorControls, {},
99 el(PanelBody, { title: __('Section Settings', 'blockenberg'), initialOpen: true },
100 el(SelectControl, {
101 label: __('Content Width', 'blockenberg'),
102 value: a.contentWidth,
103 options: [
104 { label: __('Full Width', 'blockenberg'), value: 'full' },
105 { label: __('Boxed', 'blockenberg'), value: 'boxed' }
106 ],
107 onChange: function (v) { setAttributes({ contentWidth: v }); }
108 }),
109 a.contentWidth === 'boxed' && el(SelectControl, {
110 label: __('Max Width', 'blockenberg'),
111 value: a.boxedMaxWidth,
112 options: maxWidthOptions,
113 onChange: function (v) { setAttributes({ boxedMaxWidth: v }); }
114 }),
115 el(SelectControl, {
116 label: __('Vertical Padding', 'blockenberg'),
117 value: a.paddingY,
118 options: spacingOptions,
119 onChange: function (v) { setAttributes({ paddingY: v }); }
120 })
121 ),
122 el(PanelBody, { title: __('Background', 'blockenberg'), initialOpen: false },
123 el(SelectControl, {
124 label: __('Background Preset', 'blockenberg'),
125 value: a.background,
126 options: backgroundOptions,
127 onChange: function (v) {
128 setAttributes({ background: v });
129 if (v !== 'custom') {
130 setAttributes({ backgroundColor: '' });
131 }
132 }
133 }),
134 a.background === 'custom' && el(BaseControl, {
135 label: __('Custom Color', 'blockenberg')
136 },
137 el(ColorPalette, {
138 value: a.backgroundColor,
139 onChange: function (color) { setAttributes({ backgroundColor: color }); }
140 })
141 )
142 )
143 );
144
145 // Inner blocks template - only allow Row blocks
146 var innerBlocksTemplate = [
147 ['blockenberg/row', { columnsCount: 1 }]
148 ];
149 var allowedBlocks = ['blockenberg/row'];
150
151 return el('div', blockProps,
152 toolbar,
153 inspector,
154 el('div', { className: 'bkbg-section__inner' },
155 el(InnerBlocks, {
156 template: innerBlocksTemplate,
157 allowedBlocks: allowedBlocks,
158 templateLock: false,
159 renderAppender: false
160 })
161 )
162 );
163 },
164
165 save: function (props) {
166 var a = props.attributes;
167 var blockProps = useBlockProps.save({
168 className: [
169 'bkbg-section',
170 'bkbg-section--width-' + a.contentWidth,
171 'bkbg-section--padding-' + a.paddingY,
172 'bkbg-section--bg-' + a.background
173 ].join(' '),
174 style: {
175 '--bkbg-section-max-width': a.boxedMaxWidth + 'px',
176 '--bkbg-section-custom-bg': a.backgroundColor || undefined
177 }
178 });
179
180 return el('div', blockProps,
181 el('div', { className: 'bkbg-section__inner' },
182 el(InnerBlocks.Content)
183 )
184 );
185 }
186 });
187 });
188