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 / click-to-tweet / index.js

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

205 lines 10.4 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 useBlockProps = wp.blockEditor.useBlockProps;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14
15 function getTypographyControl() { return (window.bkbgTypographyControl || function () { return null; }); }
16 function getTypoCssVars() { return (window.bkbgTypoCssVars || function () { return {}; }); }
17 function _tv(typo, prefix) { var fn = getTypoCssVars(); return fn(typo || {}, prefix); }
18
19 function xIcon() {
20 return el('svg', {
21 viewBox: '0 0 24 24',
22 width: 16,
23 height: 16,
24 fill: 'currentColor',
25 style: { display: 'inline-block', verticalAlign: 'middle', marginRight: '6px' }
26 },
27 el('path', { d: 'M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.744l7.73-8.835L1.254 2.25H8.08l4.258 5.63L18.244 2.25Zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77Z' })
28 );
29 }
30
31 registerBlockType('blockenberg/click-to-tweet', {
32 edit: function (props) {
33 var attr = props.attributes;
34 var setAttr = props.setAttributes;
35
36 var blockProps = useBlockProps({ className: 'bkbg-ctt-editor', style: Object.assign({}, _tv(attr.typoQuote, '--bkbg-ctt-q-')) });
37
38 function cardStyle() {
39 var base = {
40 background: attr.bgColor,
41 borderRadius: attr.borderRadius + 'px',
42 padding: '28px 32px',
43 maxWidth: attr.maxWidth + 'px',
44 margin: '0 auto'
45 };
46 if (attr.cardStyle === 'bordered') {
47 base.border = '2px solid ' + attr.borderColor;
48 base.background = '#fff';
49 }
50 if (attr.cardStyle === 'minimal') {
51 base.background = 'transparent';
52 base.borderLeft = '4px solid ' + attr.accentColor;
53 base.borderRadius = '0';
54 base.paddingLeft = '24px';
55 }
56 return base;
57 }
58
59 var controls = el(InspectorControls, {},
60 el(PanelBody, { title: __('Quote Settings', 'blockenberg'), initialOpen: true },
61 el(TextControl, {
62 label: __('Attribution', 'blockenberg'),
63 value: attr.attribution,
64 onChange: function (v) { setAttr({ attribution: v }); },
65 __nextHasNoMarginBottom: true
66 }),
67 el(ToggleControl, {
68 label: __('Show Attribution', 'blockenberg'),
69 checked: attr.showAttribution,
70 onChange: function (v) { setAttr({ showAttribution: v }); },
71 __nextHasNoMarginBottom: true
72 }),
73 el(ToggleControl, {
74 label: __('Show Quote Icon (")', 'blockenberg'),
75 checked: attr.showQuoteIcon,
76 onChange: function (v) { setAttr({ showQuoteIcon: v }); },
77 __nextHasNoMarginBottom: true
78 }),
79 el(SelectControl, {
80 label: __('Card Style', 'blockenberg'),
81 value: attr.cardStyle,
82 options: [
83 { label: 'Card (with background)', value: 'card' },
84 { label: 'Bordered', value: 'bordered' },
85 { label: 'Minimal (left accent bar)', value: 'minimal' }
86 ],
87 onChange: function (v) { setAttr({ cardStyle: v }); },
88 __nextHasNoMarginBottom: true
89 }),
90 el(RangeControl, {
91 label: __('Border Radius (px)', 'blockenberg'),
92 value: attr.borderRadius,
93 min: 0, max: 40,
94 onChange: function (v) { setAttr({ borderRadius: v }); },
95 __nextHasNoMarginBottom: true
96 })
97 ),
98 el(PanelBody, { title: __('Share Button', 'blockenberg'), initialOpen: false },
99 el(TextControl, {
100 label: __('Button Label', 'blockenberg'),
101 value: attr.buttonLabel,
102 onChange: function (v) { setAttr({ buttonLabel: v }); },
103 __nextHasNoMarginBottom: true
104 }),
105 el(ToggleControl, {
106 label: __('Include Page URL in tweet', 'blockenberg'),
107 checked: attr.includeUrl,
108 onChange: function (v) { setAttr({ includeUrl: v }); },
109 __nextHasNoMarginBottom: true
110 })
111 ),
112
113 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
114 el(getTypographyControl(), { label: __('Quote', 'blockenberg'), value: attr.typoQuote, onChange: function (v) { setAttr({ typoQuote: v }); } })
115 ),
116 el(PanelColorSettings, {
117 title: __('Colors', 'blockenberg'),
118 initialOpen: false,
119 colorSettings: [
120 { label: __('Quote Text', 'blockenberg'), value: attr.quoteColor, onChange: function (v) { setAttr({ quoteColor: v || '#111827' }); } },
121 { label: __('Attribution', 'blockenberg'), value: attr.attributionColor, onChange: function (v) { setAttr({ attributionColor: v || '#6b7280' }); } },
122 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#f9fafb' }); } },
123 { label: __('Border / Accent', 'blockenberg'), value: attr.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#e5e7eb' }); } },
124 { label: __('Accent Color', 'blockenberg'), value: attr.accentColor, onChange: function (v) { setAttr({ accentColor: v || '#7c3aed' }); } },
125 { label: __('Button Background', 'blockenberg'), value: attr.buttonBg, onChange: function (v) { setAttr({ buttonBg: v || '#000' }); } },
126 { label: __('Button Text', 'blockenberg'), value: attr.buttonColor, onChange: function (v) { setAttr({ buttonColor: v || '#fff' }); } }
127 ]
128 }),
129 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
130 el(RangeControl, {
131 label: __('Max Width (px)', 'blockenberg'),
132 value: attr.maxWidth,
133 min: 300, max: 1200,
134 onChange: function (v) { setAttr({ maxWidth: v }); },
135 __nextHasNoMarginBottom: true
136 }),
137 el(RangeControl, {
138 label: __('Padding Top (px)', 'blockenberg'),
139 value: attr.paddingTop,
140 min: 0, max: 120,
141 onChange: function (v) { setAttr({ paddingTop: v }); },
142 __nextHasNoMarginBottom: true
143 }),
144 el(RangeControl, {
145 label: __('Padding Bottom (px)', 'blockenberg'),
146 value: attr.paddingBottom,
147 min: 0, max: 120,
148 onChange: function (v) { setAttr({ paddingBottom: v }); },
149 __nextHasNoMarginBottom: true
150 })
151 )
152 );
153
154 var preview = el('div', { style: { paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' } },
155 el('div', { style: cardStyle() },
156 attr.showQuoteIcon && el('div', { className: 'bkbg-ctt-quote-icon', style: { color: attr.accentColor, fontSize: '48px', lineHeight: 1, marginBottom: '8px', opacity: 0.4 } }, '"'),
157 el(RichText, {
158 tagName: 'p',
159 className: 'bkbg-ctt-quote',
160 style: {
161 color: attr.quoteColor,
162 margin: '0 0 16px'
163 },
164 value: attr.quote,
165 onChange: function (v) { setAttr({ quote: v }); },
166 placeholder: __('Enter a quote to share…', 'blockenberg')
167 }),
168 attr.showAttribution && attr.attribution && el('p', {
169 style: { fontSize: '14px', color: attr.attributionColor, margin: '0 0 20px', fontWeight: 500 }
170 }, '' + attr.attribution),
171 el('div', { className: 'bkbg-ctt-footer' },
172 el('span', {
173 style: {
174 display: 'inline-flex',
175 alignItems: 'center',
176 background: attr.buttonBg,
177 color: attr.buttonColor,
178 padding: '8px 16px',
179 borderRadius: '999px',
180 fontSize: '14px',
181 fontWeight: '600',
182 gap: '6px',
183 cursor: 'default'
184 }
185 }, xIcon(), attr.buttonLabel)
186 )
187 )
188 );
189
190 return el('div', blockProps, controls, preview);
191 },
192
193 save: function (props) {
194 var attr = props.attributes;
195 var blockProps = wp.blockEditor.useBlockProps.save();
196 return el('div', blockProps,
197 el('div', {
198 className: 'bkbg-ctt-app',
199 'data-opts': JSON.stringify(attr)
200 })
201 );
202 }
203 });
204 }() );
205