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 / faq-section / index.js

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

167 lines 13.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 useState = wp.element.useState;
4 var __ = wp.i18n.__;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var useBlockProps = wp.blockEditor.useBlockProps;
8 var RichText = wp.blockEditor.RichText;
9 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
10 var PanelBody = wp.components.PanelBody;
11 var ToggleControl = wp.components.ToggleControl;
12 var RangeControl = wp.components.RangeControl;
13 var SelectControl = wp.components.SelectControl;
14 var TextControl = wp.components.TextControl;
15 var Button = wp.components.Button;
16
17 var _fsecTC, _fsecTV;
18 function _tc() { return _fsecTC || (_fsecTC = window.bkbgTypographyControl); }
19 function _tv() { return _fsecTV || (_fsecTV = window.bkbgTypoCssVars); }
20
21 registerBlockType('blockenberg/faq-section', {
22 edit: function (props) {
23 var a = props.attributes;
24 var set = props.setAttributes;
25 var blockProps = useBlockProps({ style: Object.assign({}, _tv()(a.typoEyebrow, '--bkbg-fsec-eb-'), _tv()(a.typoHeading, '--bkbg-fsec-hd-'), _tv()(a.typoSubtext, '--bkbg-fsec-st-'), _tv()(a.typoQuestion, '--bkbg-fsec-qt-'), _tv()(a.typoAnswer, '--bkbg-fsec-an-')) });
26
27 var openState = useState(a.expandFirst ? 0 : null);
28 var openIdx = openState[0];
29 var setOpenIdx = openState[1];
30
31 function updateItem(idx, key, val) {
32 var next = a.items.map(function (it, i) {
33 return i === idx ? Object.assign({}, it, { [key]: val }) : it;
34 });
35 set({ items: next });
36 }
37
38 function removeItem(idx) {
39 set({ items: a.items.filter(function (_, i) { return i !== idx; }) });
40 }
41
42 /* --- Icon helpers --- */
43 function iconEl(open) {
44 if (a.iconType === 'plus') return el('span', { style: { fontSize: '20px', lineHeight: 1, color: a.iconColor, transition: 'transform .2s' } }, open ? '' : '+');
45 if (a.iconType === 'arrow') return el('span', { style: { fontSize: '14px', color: a.iconColor, display: 'inline-block', transform: open ? 'rotate(90deg)' : 'none', transition: 'transform .2s' } }, '');
46 return el('span', { style: { fontSize: '14px', color: a.iconColor, display: 'inline-block', transform: open ? 'rotate(180deg)' : 'none', transition: 'transform .2s' } }, '');
47 }
48
49 var isSplit = a.layout === 'split';
50 var isTwoCol = a.layout === 'two-column';
51
52 /* --- Accordion items --- */
53 var accordionItems = el('div', { className: 'bkbg-faqs-accordion' },
54 a.items.map(function (item, idx) {
55 var isOpen = openIdx === idx;
56 return el('div', {
57 key: idx,
58 className: 'bkbg-faqs-item' + (isOpen ? ' bkbg-faqs-item--open' : ''),
59 style: {
60 borderBottom: a.showDividers ? '1px solid ' + a.dividerColor : 'none',
61 borderRadius: a.itemRadius + 'px'
62 }
63 },
64 el('div', {
65 className: 'bkbg-faqs-question-row',
66 style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px', cursor: 'pointer', padding: '16px 0' },
67 onClick: function () { setOpenIdx(isOpen ? null : idx); }
68 },
69 el(RichText, {
70 tagName: 'span',
71 value: item.question,
72 className: 'bkbg-faqs-question',
73 style: { color: isOpen ? a.activeAccent : a.questionColor, flex: 1, display: 'block' },
74 onChange: function (v) { updateItem(idx, 'question', v); }
75 }),
76 iconEl(isOpen)
77 ),
78 isOpen && el('div', { className: 'bkbg-faqs-answer', style: { paddingBottom: '16px' } },
79 el(RichText, {
80 tagName: 'p',
81 value: item.answer,
82 className: 'bkbg-faqs-answer-p',
83 style: { color: a.answerColor, margin: 0 },
84 onChange: function (v) { updateItem(idx, 'answer', v); }
85 }),
86 el(Button, { isDestructive: true, isSmall: true, style: { marginTop: '8px', opacity: 0.6 }, onClick: function (e) { e.stopPropagation(); removeItem(idx); } }, '✕ Remove')
87 )
88 );
89 }),
90 el(Button, { isSecondary: true, isSmall: true, style: { marginTop: '12px' }, onClick: function () { set({ items: a.items.concat([{ question: 'New question', answer: 'Your answer here.' }]) }); } }, '+ Add Question')
91 );
92
93 /* --- Section header --- */
94 var header = el('div', { className: 'bkbg-faqs-header', style: { textAlign: isSplit ? 'left' : 'center', marginBottom: isSplit ? '0' : '48px' } },
95 a.showEyebrow && el('span', { className: 'bkbg-faqs-eyebrow', style: { background: a.eyebrowBg, color: a.eyebrowColor, padding: '4px 14px', borderRadius: '999px', display: 'inline-block', marginBottom: '16px' } },
96 el(RichText, { tagName: 'span', value: a.eyebrow, onChange: function (v) { set({ eyebrow: v }); } })
97 ),
98 el(RichText, { tagName: 'h2', className: 'bkbg-faqs-heading', value: a.heading, style: { color: a.headingColor, margin: '0 0 16px' }, onChange: function (v) { set({ heading: v }); } }),
99 a.showSubtext && el(RichText, { tagName: 'p', className: 'bkbg-faqs-subtext', value: a.subtext, style: { color: a.subtextColor, maxWidth: '560px', margin: isSplit ? '0' : '0 auto' }, onChange: function (v) { set({ subtext: v }); } })
100 );
101
102 /* --- CTA row --- */
103 var ctaRowEl = a.showCta && el('div', { style: { textAlign: 'center', marginTop: '40px', borderTop: '1px solid ' + a.dividerColor, paddingTop: '24px' } },
104 el('span', { className: 'bkbg-faqs-cta-text', style: { color: a.subtextColor, marginRight: '8px' } }, el(RichText, { tagName: 'span', value: a.ctaText, onChange: function (v) { set({ ctaText: v }); } })),
105 el('a', { href: '#editor', className: 'bkbg-faqs-cta-link', style: { color: a.ctaLinkColor, textDecoration: 'underline' } }, el(RichText, { tagName: 'span', value: a.ctaLabel, onChange: function (v) { set({ ctaLabel: v }); } }))
106 );
107
108 var inner = isSplit
109 ? el('div', { style: { display: 'flex', gap: '64px', alignItems: 'flex-start' } }, el('div', { style: { flex: '0 0 320px' } }, header), el('div', { style: { flex: 1 } }, accordionItems, ctaRowEl))
110 : el('div', { style: { maxWidth: a.maxWidth + 'px', margin: '0 auto' } }, header, isTwoCol ? el('div', { style: { columns: 2, gap: '24px' } }, accordionItems) : accordionItems, ctaRowEl);
111
112 var controls = el(InspectorControls, {},
113 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: true },
114 el(SelectControl, { label: __('Layout', 'blockenberg'), value: a.layout, options: [{ label: 'Centered', value: 'centered' }, { label: 'Split (header left)', value: 'split' }, { label: 'Two columns', value: 'two-column' }], onChange: function (v) { set({ layout: v }); }, __nextHasNoMarginBottom: true }),
115 el(SelectControl, { label: __('Icon Style', 'blockenberg'), value: a.iconType, options: [{ label: 'Chevron ▾', value: 'chevron' }, { label: 'Plus +/−', value: 'plus' }, { label: 'Arrow →', value: 'arrow' }], onChange: function (v) { set({ iconType: v }); }, __nextHasNoMarginBottom: true }),
116 el(ToggleControl, { label: __('Show Eyebrow', 'blockenberg'), checked: a.showEyebrow, onChange: function (v) { set({ showEyebrow: v }); }, __nextHasNoMarginBottom: true }),
117 el(ToggleControl, { label: __('Show Subtext', 'blockenberg'), checked: a.showSubtext, onChange: function (v) { set({ showSubtext: v }); }, __nextHasNoMarginBottom: true }),
118 el(ToggleControl, { label: __('Show Dividers', 'blockenberg'), checked: a.showDividers, onChange: function (v) { set({ showDividers: v }); }, __nextHasNoMarginBottom: true }),
119 el(ToggleControl, { label: __('Expand First Item', 'blockenberg'), checked: a.expandFirst, onChange: function (v) { set({ expandFirst: v }); }, __nextHasNoMarginBottom: true }),
120 el(ToggleControl, { label: __('Allow Multiple Open', 'blockenberg'), checked: a.allowMultiple, onChange: function (v) { set({ allowMultiple: v }); }, __nextHasNoMarginBottom: true }),
121 el(ToggleControl, { label: __('Show CTA', 'blockenberg'), checked: a.showCta, onChange: function (v) { set({ showCta: v }); }, __nextHasNoMarginBottom: true }),
122 a.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: a.ctaUrl, onChange: function (v) { set({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
123 el(RangeControl, { label: __('Item Border Radius', 'blockenberg'), value: a.itemRadius, min: 0, max: 20, onChange: function (v) { set({ itemRadius: v }); }, __nextHasNoMarginBottom: true }),
124 el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, min: 500, max: 1400, onChange: function (v) { set({ maxWidth: v }); }, __nextHasNoMarginBottom: true }),
125 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: a.paddingTop, min: 0, max: 160, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
126 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: a.paddingBottom, min: 0, max: 160, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
127 ),
128
129 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
130 _tc() && el(_tc(), { label: __('Eyebrow', 'blockenberg'), value: a.typoEyebrow, onChange: function (v) { set({ typoEyebrow: v }); } }),
131 _tc() && el(_tc(), { label: __('Heading', 'blockenberg'), value: a.typoHeading, onChange: function (v) { set({ typoHeading: v }); } }),
132 _tc() && el(_tc(), { label: __('Subtext', 'blockenberg'), value: a.typoSubtext, onChange: function (v) { set({ typoSubtext: v }); } }),
133 _tc() && el(_tc(), { label: __('Question', 'blockenberg'), value: a.typoQuestion, onChange: function (v) { set({ typoQuestion: v }); } }),
134 _tc() && el(_tc(), { label: __('Answer', 'blockenberg'), value: a.typoAnswer, onChange: function (v) { set({ typoAnswer: v }); } })
135 ),
136 el(PanelColorSettings, {
137 title: __('Colors', 'blockenberg'), initialOpen: false,
138 colorSettings: [
139 { label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } },
140 { label: __('Heading', 'blockenberg'), value: a.headingColor, onChange: function (v) { set({ headingColor: v || '#111827' }); } },
141 { label: __('Eyebrow Text', 'blockenberg'), value: a.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#7c3aed' }); } },
142 { label: __('Eyebrow BG', 'blockenberg'), value: a.eyebrowBg, onChange: function (v) { set({ eyebrowBg: v || '#f3f0ff' }); } },
143 { label: __('Subtext', 'blockenberg'), value: a.subtextColor, onChange: function (v) { set({ subtextColor: v || '#6b7280' }); } },
144 { label: __('Question', 'blockenberg'), value: a.questionColor, onChange: function (v) { set({ questionColor: v || '#111827' }); } },
145 { label: __('Answer', 'blockenberg'), value: a.answerColor, onChange: function (v) { set({ answerColor: v || '#4b5563' }); } },
146 { label: __('Icon', 'blockenberg'), value: a.iconColor, onChange: function (v) { set({ iconColor: v || '#7c3aed' }); } },
147 { label: __('Divider', 'blockenberg'), value: a.dividerColor, onChange: function (v) { set({ dividerColor: v || '#e5e7eb' }); } },
148 { label: __('Active Accent', 'blockenberg'), value: a.activeAccent, onChange: function (v) { set({ activeAccent: v || '#7c3aed' }); } },
149 { label: __('CTA Link', 'blockenberg'), value: a.ctaLinkColor, onChange: function (v) { set({ ctaLinkColor: v || '#7c3aed' }); } }
150 ]
151 })
152 );
153
154 return el('div', blockProps,
155 controls,
156 el('div', { style: { background: a.bgColor, paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px' } }, inner)
157 );
158 },
159
160 save: function (props) {
161 return el('div', wp.blockEditor.useBlockProps.save(),
162 el('div', { className: 'bkbg-faqs-app', 'data-opts': JSON.stringify(props.attributes) })
163 );
164 }
165 });
166 }() );
167