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 / cta-band / index.js

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

168 lines 7.5 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 RichText = wp.blockEditor.RichText;
7 var PanelBody = wp.components.PanelBody;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var SelectControl = wp.components.SelectControl;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var TextControl = wp.components.TextControl;
13
14 var _cbTC, _cbTV;
15 function _tc() { return _cbTC || (_cbTC = window.bkbgTypographyControl); }
16 function _tv(obj, prefix) { var fn = _cbTV || (_cbTV = window.bkbgTypoCssVars); return fn ? fn(obj, prefix) : {}; }
17
18 registerBlockType( 'blockenberg/cta-band', {
19 edit: function ( props ) {
20 var attrs = props.attributes;
21 var setAttr = props.setAttributes;
22
23 var bg = attrs.useGradient
24 ? 'linear-gradient(135deg, ' + attrs.bgColor + ', ' + attrs.bgColor2 + ')'
25 : attrs.bgColor;
26
27 var wrapStyle = Object.assign({
28 '--bkcb-bg': bg,
29 '--bkcb-text': attrs.textColor,
30 '--bkcb-pv': attrs.paddingV + 'px',
31 '--bkcb-ph': attrs.paddingH + 'px',
32 '--bkcb-hSz': attrs.headlineSz + 'px',
33 '--bkcb-sSz': attrs.subtextSz + 'px',
34 '--bkcb-btnBg': attrs.btnBg,
35 '--bkcb-btnText': attrs.btnText,
36 '--bkcb-btnR': attrs.btnRadius + 'px'
37 }, _tv(attrs.typoHeadline, '--bkcb-hdl-'), _tv(attrs.typoSubtext, '--bkcb-sub-'));
38
39 return el( 'div', null,
40 el( InspectorControls, null,
41 el( PanelBody, { title: __( 'Content', 'blockenberg' ), initialOpen: true },
42 el( TextControl, {
43 label: __( 'Button Label', 'blockenberg' ),
44 value: attrs.btnLabel,
45 onChange: function (v) { setAttr({ btnLabel: v }); }
46 } ),
47 el( TextControl, {
48 label: __( 'Button URL', 'blockenberg' ),
49 value: attrs.btnUrl,
50 onChange: function (v) { setAttr({ btnUrl: v }); }
51 } ),
52 el( ToggleControl, {
53 label: __( 'Open in New Tab', 'blockenberg' ),
54 checked: attrs.btnNewTab,
55 onChange: function (v) { setAttr({ btnNewTab: v }); },
56 __nextHasNoMarginBottom: true
57 } )
58 ),
59 el( PanelBody, { title: __( 'Layout', 'blockenberg' ), initialOpen: false },
60 el( SelectControl, {
61 label: __( 'Content Alignment', 'blockenberg' ),
62 value: attrs.layout,
63 options: [
64 { label: 'Center', value: 'center' },
65 { label: 'Text left, Btn right', value: 'side' }
66 ],
67 onChange: function (v) { setAttr({ layout: v }); }
68 } ),
69 el( ToggleControl, {
70 label: __( 'Gradient Background', 'blockenberg' ),
71 checked: attrs.useGradient,
72 onChange: function (v) { setAttr({ useGradient: v }); },
73 __nextHasNoMarginBottom: true
74 } )
75 ),
76 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
77 _tc() && el(_tc(), { label: __('Headline', 'blockenberg'), value: attrs.typoHeadline, onChange: function (v) { setAttr({ typoHeadline: v }); } }),
78 _tc() && el(_tc(), { label: __('Subtext', 'blockenberg'), value: attrs.typoSubtext, onChange: function (v) { setAttr({ typoSubtext: v }); } })
79 ),
80 el( PanelBody, { title: __( 'Appearance', 'blockenberg' ), initialOpen: false },
81 el( RangeControl, {
82 label: __( 'Vertical Padding (px)', 'blockenberg' ),
83 value: attrs.paddingV, min: 20, max: 120,
84 onChange: function (v) { setAttr({ paddingV: v }); }
85 } ),
86 el( RangeControl, {
87 label: __( 'Horizontal Padding (px)', 'blockenberg' ),
88 value: attrs.paddingH, min: 16, max: 100,
89 onChange: function (v) { setAttr({ paddingH: v }); }
90 } ),
91 el( RangeControl, {
92 label: __( 'Button Border Radius (px)', 'blockenberg' ),
93 value: attrs.btnRadius, min: 0, max: 40,
94 onChange: function (v) { setAttr({ btnRadius: v }); }
95 } )
96 ),
97 el( PanelBody, { title: __( 'Colors', 'blockenberg' ), initialOpen: false },
98 el( PanelColorSettings, {
99 title: __( 'Colors', 'blockenberg' ),
100 colorSettings: [
101 { value: attrs.bgColor, onChange: function(v){setAttr({bgColor:v||'#1a73e8'});}, label: __('Background / Gradient Start') },
102 { value: attrs.bgColor2, onChange: function(v){setAttr({bgColor2:v||'#0d47a1'});}, label: __('Gradient End') },
103 { value: attrs.textColor, onChange: function(v){setAttr({textColor:v||'#ffffff'});}, label: __('Text') },
104 { value: attrs.btnBg, onChange: function(v){setAttr({btnBg:v||'#ffffff'});}, label: __('Button Background') },
105 { value: attrs.btnText, onChange: function(v){setAttr({btnText:v||'#1a73e8'});}, label: __('Button Text') }
106 ]
107 } )
108 )
109 ),
110 el( 'div', { className: 'bkcb-wrap bkcb-layout-' + attrs.layout, style: wrapStyle },
111 el( 'div', { className: 'bkcb-text' },
112 el( RichText, {
113 tagName: 'h2',
114 className: 'bkcb-headline',
115 value: attrs.headline,
116 onChange: function (v) { setAttr({ headline: v }); },
117 placeholder: __( 'Your headline…', 'blockenberg' )
118 } ),
119 el( RichText, {
120 tagName: 'p',
121 className: 'bkcb-subtext',
122 value: attrs.subtext,
123 onChange: function (v) { setAttr({ subtext: v }); },
124 placeholder: __( 'Supporting text…', 'blockenberg' )
125 } )
126 ),
127 el( 'a', {
128 className: 'bkcb-btn',
129 href: attrs.btnUrl,
130 target: attrs.btnNewTab ? '_blank' : '_self'
131 }, attrs.btnLabel )
132 )
133 );
134 },
135 save: function ( props ) {
136 var attrs = props.attributes;
137 var bg = attrs.useGradient
138 ? 'linear-gradient(135deg, ' + attrs.bgColor + ', ' + attrs.bgColor2 + ')'
139 : attrs.bgColor;
140 return el( 'div', {
141 className: 'bkcb-wrap bkcb-layout-' + attrs.layout,
142 style: Object.assign({
143 '--bkcb-bg': bg,
144 '--bkcb-text': attrs.textColor,
145 '--bkcb-pv': attrs.paddingV + 'px',
146 '--bkcb-ph': attrs.paddingH + 'px',
147 '--bkcb-hSz': attrs.headlineSz + 'px',
148 '--bkcb-sSz': attrs.subtextSz + 'px',
149 '--bkcb-btnBg': attrs.btnBg,
150 '--bkcb-btnText': attrs.btnText,
151 '--bkcb-btnR': attrs.btnRadius + 'px'
152 }, _tv(attrs.typoHeadline, '--bkcb-hdl-'), _tv(attrs.typoSubtext, '--bkcb-sub-'))
153 },
154 el( 'div', { className: 'bkcb-text' },
155 el( RichText.Content, { tagName: 'h2', className: 'bkcb-headline', value: attrs.headline } ),
156 el( RichText.Content, { tagName: 'p', className: 'bkcb-subtext', value: attrs.subtext } )
157 ),
158 el( 'a', {
159 className: 'bkcb-btn',
160 href: attrs.btnUrl,
161 target: attrs.btnNewTab ? '_blank' : '_self',
162 rel: attrs.btnNewTab ? 'noopener noreferrer' : null
163 }, attrs.btnLabel )
164 );
165 }
166 } );
167 } )();
168