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 / flip-countdown / index.js

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

203 lines 11.7 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 registerBlockType = wp.blocks.registerBlockType;
4 var useBlockProps = wp.blockEditor.useBlockProps;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
7 var RichText = wp.blockEditor.RichText;
8 var PanelBody = wp.components.PanelBody;
9 var RangeControl = wp.components.RangeControl;
10 var ToggleControl = wp.components.ToggleControl;
11 var SelectControl = wp.components.SelectControl;
12 var TextControl = wp.components.TextControl;
13
14 var _fcdTC, _fcdTV;
15 function _tc() { return _fcdTC || (_fcdTC = window.bkbgTypographyControl); }
16 function _tv() { return _fcdTV || (_fcdTV = window.bkbgTypoCssVars); }
17
18 var DEMO = { days: '05', hours: '14', minutes: '38', seconds: '27' };
19
20 function FlipCard(val, unit, a) {
21 var digits = String(val).padStart(2, '0').split('');
22 return el('div', { className: 'bkbg-fc-unit' },
23 el('div', { className: 'bkbg-fc-pair' },
24 digits.map(function (d, i) {
25 return el('div', { key: i, className: 'bkbg-fc-card',
26 style: {
27 background: a.flipBg || '#1e1b4b',
28 borderRadius: (a.cardRadius || 8) + 'px',
29 color: a.flipColor || '#ffffff'
30 }
31 },
32 el('div', { className: 'bkbg-fc-upper' }, d),
33 el('div', { className: 'bkbg-fc-hinge',
34 style: { background: a.flipHingeBg || '#0f0e17' } }),
35 el('div', { className: 'bkbg-fc-lower' }, d)
36 );
37 })
38 ),
39 a.showLabels !== false && el('div', { className: 'bkbg-fc-label',
40 style: { color: a.labelColor || '#64748b' }
41 }, unit)
42 );
43 }
44
45 function Separator(a) {
46 return el('div', { className: 'bkbg-fc-sep',
47 style: { color: a.separatorColor || '#6366f1' }
48 }, ':');
49 }
50
51 function EditorPreview(props) {
52 var a = props.attributes;
53 var units = [];
54 if (a.showDays !== false) { units.push({ val: DEMO.days, label: 'Days' }); }
55 if (a.showHours !== false) { units.push({ val: DEMO.hours, label: 'Hours' }); }
56 if (a.showMinutes !== false) { units.push({ val: DEMO.minutes, label: 'Minutes' }); }
57 if (a.showSeconds !== false) { units.push({ val: DEMO.seconds, label: 'Seconds' }); }
58
59 return el('div', { className: 'bkbg-fc-app', style: { background: a.sectionBg || '#f8fafc', padding: '40px 24px', borderRadius: 14,
60 textAlign: 'center', fontFamily: 'inherit' } },
61 el(RichText, {
62 tagName: 'h3', className: 'bkbg-fc-title', value: a.title, placeholder: 'Coming Soon',
63 style: { margin: '0 0 8px',
64 color: a.titleColor || '#1e1b4b' },
65 onChange: function (v) { props.setAttributes({ title: v }); }
66 }),
67 el(RichText, {
68 tagName: 'p', className: 'bkbg-fc-subtitle', value: a.subtitle, placeholder: 'Add a subtitle...',
69 style: { margin: '0 0 32px',
70 color: a.titleColor || '#1e1b4b', opacity: 0.65 },
71 onChange: function (v) { props.setAttributes({ subtitle: v }); }
72 }),
73 el('div', { className: 'bkbg-fc-row', style: { gap: (a.cardGap || 16) + 'px' } },
74 units.reduce(function (acc, u, i) {
75 if (i > 0 && a.showSeparators !== false) acc.push(Separator(a));
76 acc.push(FlipCard(u.val, u.label, a));
77 return acc;
78 }, [])
79 ),
80 a.targetDate && el('p', { style: { marginTop: 16, fontSize: 12, opacity: 0.45,
81 color: a.titleColor || '#1e1b4b' } }, '�
82 Target: ' + a.targetDate)
83 );
84 }
85
86 registerBlockType('blockenberg/flip-countdown', {
87 edit: function (props) {
88 var a = props.attributes;
89 var set = props.setAttributes;
90 var blockProps = useBlockProps({ className: 'bkbg-fc-editor-wrap', style: Object.assign({},
91 _tv()(a.typoTitle, '--bkbg-fcd-tt-'),
92 _tv()(a.typoSubtitle, '--bkbg-fcd-ts-'),
93 _tv()(a.typoDigit, '--bkbg-fcd-td-'),
94 _tv()(a.typoLabel, '--bkbg-fcd-tl-')
95 ) });
96
97 return el('div', blockProps,
98 el(InspectorControls, {},
99 el(PanelBody, { title: 'Content', initialOpen: true },
100 ),
101 el(PanelBody, { title: 'Countdown Settings', initialOpen: false },
102 el(TextControl, { label: 'Target date & time (ISO format)', value: a.targetDate || '',
103 help: 'e.g. 2026-12-31T23:59:59',
104 onChange: function (v) { set({ targetDate: v }); }, __nextHasNoMarginBottom: true }),
105 el(TextControl, { label: 'End message', value: a.endMessage || '',
106 onChange: function (v) { set({ endMessage: v }); }, __nextHasNoMarginBottom: true }),
107 el(SelectControl, { label: 'When countdown ends', value: a.endAction || 'message',
108 options: [
109 { label: 'Show end message', value: 'message' },
110 { label: 'Hide the block', value: 'hide' },
111 { label: 'Keep showing zeros', value: 'zero' }
112 ],
113 onChange: function (v) { set({ endAction: v }); }, __nextHasNoMarginBottom: true }),
114 el(ToggleControl, { label: 'Show Days', checked: a.showDays !== false,
115 onChange: function (v) { set({ showDays: v }); }, __nextHasNoMarginBottom: true }),
116 el(ToggleControl, { label: 'Show Hours', checked: a.showHours !== false,
117 onChange: function (v) { set({ showHours: v }); }, __nextHasNoMarginBottom: true }),
118 el(ToggleControl, { label: 'Show Minutes', checked: a.showMinutes !== false,
119 onChange: function (v) { set({ showMinutes: v }); }, __nextHasNoMarginBottom: true }),
120 el(ToggleControl, { label: 'Show Seconds', checked: a.showSeconds !== false,
121 onChange: function (v) { set({ showSeconds: v }); }, __nextHasNoMarginBottom: true }),
122 el(ToggleControl, { label: 'Show unit labels', checked: a.showLabels !== false,
123 onChange: function (v) { set({ showLabels: v }); }, __nextHasNoMarginBottom: true }),
124 el(ToggleControl, { label: 'Show separators', checked: a.showSeparators !== false,
125 onChange: function (v) { set({ showSeparators: v }); }, __nextHasNoMarginBottom: true })
126 ),
127 el(PanelBody, { title: 'Card Style', initialOpen: false },
128 el(RangeControl, { label: 'Card border radius', value: a.cardRadius || 8,
129 onChange: function (v) { set({ cardRadius: v }); }, min: 0, max: 30, __nextHasNoMarginBottom: true }),
130 el(RangeControl, { label: 'Gap between units', value: a.cardGap || 16,
131 onChange: function (v) { set({ cardGap: v }); }, min: 4, max: 60, __nextHasNoMarginBottom: true }),
132 ),
133
134 el( PanelBody, { title: 'Typography', initialOpen: false },
135 _tc()({ label: 'Title', value: a.typoTitle, onChange: function (v) { set({ typoTitle: v }); } }),
136 _tc()({ label: 'Subtitle', value: a.typoSubtitle, onChange: function (v) { set({ typoSubtitle: v }); } }),
137 _tc()({ label: 'Digit', value: a.typoDigit, onChange: function (v) { set({ typoDigit: v }); } }),
138 _tc()({ label: 'Label', value: a.typoLabel, onChange: function (v) { set({ typoLabel: v }); } })
139 ),
140 el(PanelColorSettings, {
141 title: 'Colors', initialOpen: false,
142 colorSettings: [
143 { label: 'Card background', value: a.flipBg, onChange: function (v) { set({ flipBg: v || '#1e1b4b' }); } },
144 { label: 'Digit color', value: a.flipColor, onChange: function (v) { set({ flipColor: v || '#ffffff' }); } },
145 { label: 'Hinge color', value: a.flipHingeBg, onChange: function (v) { set({ flipHingeBg: v || '#0f0e17' }); } },
146 { label: 'Label color', value: a.labelColor, onChange: function (v) { set({ labelColor: v || '#64748b' }); } },
147 { label: 'Separator color', value: a.separatorColor, onChange: function (v) { set({ separatorColor: v || '#6366f1' }); } },
148 { label: 'Section background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#f8fafc' }); } },
149 { label: 'Title color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#1e1b4b' }); } }
150 ],
151 disableCustomGradients: true
152 })
153 ),
154 el(EditorPreview, { attributes: a, setAttributes: props.setAttributes })
155 );
156 },
157
158 save: function (props) {
159 var a = props.attributes;
160 var blockProps = useBlockProps.save();
161 var opts = {
162 targetDate: a.targetDate || '',
163 showDays: a.showDays !== false,
164 showHours: a.showHours !== false,
165 showMinutes: a.showMinutes !== false,
166 showSeconds: a.showSeconds !== false,
167 showLabels: a.showLabels !== false,
168 showSeparators: a.showSeparators !== false,
169 endMessage: a.endMessage || '🎉 The wait is over!',
170 endAction: a.endAction || 'message',
171 cardRadius: a.cardRadius || 8,
172 cardGap: a.cardGap || 16,
173 digitSize: a.digitSize || 56,
174 labelFontSize: a.labelFontSize || 12,
175 labelFontWeight: a.labelFontWeight || '400',
176 titleFontSize: a.titleFontSize || 30,
177 titleFontWeight: a.titleFontWeight || '800',
178 titleLineHeight: a.titleLineHeight || 1.2,
179 subtitleSize: a.subtitleSize || 15,
180 subtitleFontWeight: a.subtitleFontWeight || '400',
181 subtitleLineHeight: a.subtitleLineHeight || 1.5,
182 flipBg: a.flipBg || '#1e1b4b',
183 flipColor: a.flipColor || '#ffffff',
184 flipHingeBg: a.flipHingeBg || '#0f0e17',
185 labelColor: a.labelColor || '#64748b',
186 separatorColor: a.separatorColor || '#6366f1',
187 sectionBg: a.sectionBg || '#f8fafc',
188 titleColor: a.titleColor || '#1e1b4b',
189 typoTitle: a.typoTitle || {},
190 typoSubtitle: a.typoSubtitle || {},
191 typoDigit: a.typoDigit || {},
192 typoLabel: a.typoLabel || {}
193 };
194 return el('div', blockProps,
195 el('div', { className: 'bkbg-fc-app', 'data-opts': JSON.stringify(opts) },
196 el(RichText.Content, { tagName: 'h3', className: 'bkbg-fc-title', value: a.title }),
197 el(RichText.Content, { tagName: 'p', className: 'bkbg-fc-subtitle', value: a.subtitle })
198 )
199 );
200 }
201 });
202 }() );
203