PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
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 / image-overlap-text / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/image-overlap-text/index.js

185 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( 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 MediaUpload = wp.blockEditor.MediaUpload;
7 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var RichText = wp.blockEditor.RichText;
10 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
11 var PanelBody = wp.components.PanelBody;
12 var ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15 var TextControl = wp.components.TextControl;
16 var Button = wp.components.Button;
17
18 var _TypographyControl, _typoCssVars;
19 function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); }
20 function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); }
21
22 registerBlockType('blockenberg/image-overlap-text', {
23 edit: function (props) {
24 var attr = props.attributes;
25 var setAttr = props.setAttributes;
26 var blockProps = useBlockProps({ className: 'bkbg-iot-editor', style: (function() {
27 var s = {}; var _tv = getTypoCssVars();
28 Object.assign(s, _tv(attr.eyebrowTypo, '--bkbg-iot-ey-'));
29 Object.assign(s, _tv(attr.headingTypo, '--bkbg-iot-h-'));
30 Object.assign(s, _tv(attr.subtextTypo, '--bkbg-iot-st-'));
31 Object.assign(s, _tv(attr.bodyTypo, '--bkbg-iot-bd-'));
32 return s;
33 })() });
34
35 var isRight = attr.overlapSide === 'right';
36
37 /* decorative element */
38 function makeDecor() {
39 if (attr.decorative === 'none') return null;
40 if (attr.decorative === 'dots') {
41 return el('div', { className: 'bkbg-iot-decor bkbg-iot-decor--dots', style: { '--dot-color': attr.dotColor } });
42 }
43 if (attr.decorative === 'lines') {
44 return el('div', { className: 'bkbg-iot-decor bkbg-iot-decor--lines', style: { '--accent': attr.accentColor } });
45 }
46 return el('div', { className: 'bkbg-iot-decor bkbg-iot-decor--shape', style: { background: attr.accentColor } });
47 }
48
49 var imageCol = el('div', {
50 className: 'bkbg-iot-image-col',
51 style: { position: 'relative', flex: '0 0 55%', overflow: 'visible' }
52 },
53 makeDecor(),
54 attr.imageUrl
55 ? el('img', {
56 src: attr.imageUrl, alt: attr.imageAlt,
57 className: 'bkbg-iot-img',
58 style: { borderRadius: attr.imageRadius + 'px', width: '100%', display: 'block', objectFit: 'cover', minHeight: '360px' }
59 })
60 : el('div', {
61 style: { background: '#f3f4f6', borderRadius: attr.imageRadius + 'px', minHeight: '360px', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '48px', color: '#d1d5db' }
62 }, '🖼️')
63 );
64
65 var textCol = el('div', {
66 className: 'bkbg-iot-text-col',
67 style: { flex: '1', padding: isRight ? '40px 0 40px ' + attr.overlapAmount + 'px' : '40px ' + attr.overlapAmount + 'px 40px 0', background: attr.panelBg, position: 'relative', zIndex: 1 }
68 },
69 attr.showEyebrow && el(RichText, {
70 tagName: 'p', value: attr.eyebrow,
71 className: 'bkbg-iot-eyebrow',
72 style: { color: attr.eyebrowColor, margin: '0 0 12px' },
73 onChange: function (v) { setAttr({ eyebrow: v }); }
74 }),
75 el(RichText, {
76 tagName: 'h2', value: attr.heading,
77 className: 'bkbg-iot-heading',
78 style: { color: attr.headingColor, margin: '0 0 16px' },
79 onChange: function (v) { setAttr({ heading: v }); }
80 }),
81 el(RichText, {
82 tagName: 'p', value: attr.subtext,
83 className: 'bkbg-iot-subtext',
84 style: { color: attr.subtextColor, margin: '0 0 16px' },
85 onChange: function (v) { setAttr({ subtext: v }); }
86 }),
87 attr.bodyText && el(RichText, {
88 tagName: 'p', value: attr.bodyText,
89 className: 'bkbg-iot-body',
90 style: { color: attr.bodyColor, margin: '0 0 24px' },
91 onChange: function (v) { setAttr({ bodyText: v }); }
92 }),
93 attr.ctaEnabled && el('div', {},
94 el('a', {
95 href: '#editor',
96 style: { display: 'inline-block', background: attr.ctaBg, color: attr.ctaColor, padding: '12px 28px', borderRadius: '6px', fontWeight: '600', fontSize: '15px', textDecoration: 'none' }
97 }, attr.ctaLabel)
98 )
99 );
100
101 var controls = el(InspectorControls, {},
102 el(PanelBody, { title: __('Image', 'blockenberg'), initialOpen: true },
103 el(MediaUploadCheck, {},
104 el(MediaUpload, {
105 onSelect: function (m) { setAttr({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
106 allowedTypes: ['image'], value: attr.imageId,
107 render: function (ref) {
108 return el('div', {},
109 attr.imageUrl && el('div', { style: { marginBottom: '8px', display: 'flex', gap: '8px', alignItems: 'center' } },
110 el('img', { src: attr.imageUrl, style: { width: '64px', height: '48px', objectFit: 'cover', borderRadius: '4px' } }),
111 el(Button, { isSmall: true, isDestructive: true, onClick: function () { setAttr({ imageUrl: '', imageId: 0 }); } }, '')
112 ),
113 el(Button, { isSecondary: true, isSmall: true, onClick: ref.open }, attr.imageUrl ? __('Replace Image', 'blockenberg') : __('Choose Image', 'blockenberg'))
114 );
115 }
116 })
117 ),
118 el(RangeControl, { label: __('Image Border Radius (px)', 'blockenberg'), value: attr.imageRadius, min: 0, max: 32, onChange: function (v) { setAttr({ imageRadius: v }); }, __nextHasNoMarginBottom: true }),
119 el(SelectControl, {
120 label: __('Decorative Element', 'blockenberg'), value: attr.decorative,
121 options: [{ label: 'Dot grid', value: 'dots' }, { label: 'Diagonal lines', value: 'lines' }, { label: 'Solid shape', value: 'shape' }, { label: 'None', value: 'none' }],
122 onChange: function (v) { setAttr({ decorative: v }); }, __nextHasNoMarginBottom: true
123 })
124 ),
125 el(PanelBody, { title: __('Layout & Text', 'blockenberg'), initialOpen: false },
126 el(SelectControl, {
127 label: __('Image Side', 'blockenberg'), value: attr.overlapSide,
128 options: [{ label: 'Image left, text right', value: 'left' }, { label: 'Image right, text left', value: 'right' }],
129 onChange: function (v) { setAttr({ overlapSide: v }); }, __nextHasNoMarginBottom: true
130 }),
131 el(RangeControl, { label: __('Overlap into text (px)', 'blockenberg'), value: attr.overlapAmount, min: 0, max: 120, onChange: function (v) { setAttr({ overlapAmount: v }); }, __nextHasNoMarginBottom: true }),
132 el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: attr.showEyebrow, onChange: function (v) { setAttr({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }),
133 el(ToggleControl, { label: __('Show CTA Button', 'blockenberg'), checked: attr.ctaEnabled, onChange: function (v) { setAttr({ ctaEnabled: v }); }, __nextHasNoMarginBottom: true }),
134 attr.ctaEnabled && el(TextControl, { label: __('CTA Label', 'blockenberg'), value: attr.ctaLabel, onChange: function (v) { setAttr({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }),
135 attr.ctaEnabled && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: attr.ctaUrl, onChange: function (v) { setAttr({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
136 attr.ctaEnabled && el(ToggleControl, { label: __('Open in New Tab', 'blockenberg'), checked: attr.ctaIsExternal, onChange: function (v) { setAttr({ ctaIsExternal: v }); }, __nextHasNoMarginBottom: true }),
137 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: attr.maxWidth, min: 600, max: 1600, onChange: function (v) { setAttr({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
138 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 160, onChange: function (v) { setAttr({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
139 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 160, onChange: function (v) { setAttr({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
140 ),
141
142 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
143 getTypographyControl() && el(getTypographyControl(), { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowTypo, onChange: function (v) { setAttr({ eyebrowTypo: v }); } }),
144 getTypographyControl() && el(getTypographyControl(), { label: __('Heading', 'blockenberg'), value: attr.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }),
145 getTypographyControl() && el(getTypographyControl(), { label: __('Subtext', 'blockenberg'), value: attr.subtextTypo, onChange: function (v) { setAttr({ subtextTypo: v }); } }),
146 getTypographyControl() && el(getTypographyControl(), { label: __('Body', 'blockenberg'), value: attr.bodyTypo, onChange: function (v) { setAttr({ bodyTypo: v }); } })
147 ),
148 el(PanelColorSettings, {
149 title: __('Colors', 'blockenberg'), initialOpen: false,
150 colorSettings: [
151 { label: __('Page Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#ffffff' }); } },
152 { label: __('Text Panel BG', 'blockenberg'), value: attr.panelBg, onChange: function (v) { setAttr({ panelBg: v || '#f9fafb' }); } },
153 { label: __('Eyebrow', 'blockenberg'), value: attr.eyebrowColor, onChange: function (v) { setAttr({ eyebrowColor: v || '#7c3aed' }); } },
154 { label: __('Heading', 'blockenberg'), value: attr.headingColor, onChange: function (v) { setAttr({ headingColor: v || '#111827' }); } },
155 { label: __('Subtext', 'blockenberg'), value: attr.subtextColor, onChange: function (v) { setAttr({ subtextColor: v || '#6b7280' }); } },
156 { label: __('Body Text', 'blockenberg'), value: attr.bodyColor, onChange: function (v) { setAttr({ bodyColor: v || '#374151' }); } },
157 { label: __('CTA Background', 'blockenberg'), value: attr.ctaBg, onChange: function (v) { setAttr({ ctaBg: v || '#7c3aed' }); } },
158 { label: __('CTA Text', 'blockenberg'), value: attr.ctaColor, onChange: function (v) { setAttr({ ctaColor: v || '#ffffff' }); } },
159 { label: __('Accent / Shape', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); } },
160 { label: __('Dot Color', 'blockenberg'), value: attr.dotColor, onChange: function (v) { setAttr({ dotColor: v || '#e5e7eb' }); } }
161 ]
162 })
163 );
164
165 return el('div', blockProps, controls,
166 el('div', { style: { background: attr.bgColor, paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' } },
167 el('div', {
168 style: {
169 maxWidth: attr.maxWidth + 'px', margin: '0 auto',
170 display: 'flex', flexDirection: isRight ? 'row-reverse' : 'row',
171 alignItems: 'stretch', position: 'relative', overflow: 'visible'
172 }
173 }, imageCol, textCol)
174 )
175 );
176 },
177
178 save: function (props) {
179 return el('div', wp.blockEditor.useBlockProps.save(),
180 el('div', { className: 'bkbg-iot-app', 'data-opts': JSON.stringify(props.attributes) })
181 );
182 }
183 });
184 }() );
185