| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var useState = wp.element.useState; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var registerBlockType = wp.blocks.registerBlockType; |
| 7 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var Button = wp.components.Button; |
| 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 TextareaControl = wp.components.TextareaControl; |
| 16 |
var ColorPicker = wp.components.ColorPicker; |
| 17 |
var Popover = wp.components.Popover; |
| 18 |
|
| 19 |
var NAV_STYLE_OPTIONS = [ |
| 20 |
{ label: __('Sidebar nav', 'blockenberg'), value: 'sidebar' }, |
| 21 |
{ label: __('Tabs', 'blockenberg'), value: 'tabs' }, |
| 22 |
]; |
| 23 |
var NAV_POS_OPTIONS = [ |
| 24 |
{ label: __('Left', 'blockenberg'), value: 'left' }, |
| 25 |
{ label: __('Right', 'blockenberg'), value: 'right' }, |
| 26 |
]; |
| 27 |
var ICON_TYPE_OPTIONS = [ |
| 28 |
{ label: __('Plus / Minus', 'blockenberg'), value: 'plus' }, |
| 29 |
{ label: __('Chevron', 'blockenberg'), value: 'chevron' }, |
| 30 |
{ label: __('Arrow', 'blockenberg'), value: 'arrow' }, |
| 31 |
]; |
| 32 |
|
| 33 |
function iconChar(type, open) { |
| 34 |
if (type === 'chevron') return open ? '▲' : '▼'; |
| 35 |
if (type === 'arrow') return open ? '↑' : '↓'; |
| 36 |
return open ? '−' : '+'; |
| 37 |
} |
| 38 |
|
| 39 |
function makeId() { return 'c' + Math.random().toString(36).substr(2, 6); } |
| 40 |
|
| 41 |
var _faqcTC, _faqcTV; |
| 42 |
function _tc() { return _faqcTC || (_faqcTC = window.bkbgTypographyControl); } |
| 43 |
function _tv(o, p) { if (!_faqcTV) _faqcTV = window.bkbgTypoCssVars; return _faqcTV ? _faqcTV(o, p) : {}; } |
| 44 |
var IP = function () { return window.bkbgIconPicker; }; |
| 45 |
|
| 46 |
function buildWrapStyle(a) { |
| 47 |
return Object.assign({ |
| 48 |
'--bkbg-faqc-accent': a.accentColor, |
| 49 |
'--bkbg-faqc-nav-bg': a.navBg, |
| 50 |
'--bkbg-faqc-nav-active-bg':a.navActiveBg, |
| 51 |
'--bkbg-faqc-nav-active': a.navActiveColor, |
| 52 |
'--bkbg-faqc-nav-inactive': a.navInactiveColor, |
| 53 |
'--bkbg-faqc-q-color': a.questionColor, |
| 54 |
'--bkbg-faqc-a-color': a.answerColor, |
| 55 |
'--bkbg-faqc-item-bg': a.itemBg, |
| 56 |
'--bkbg-faqc-item-border': a.itemBorderColor, |
| 57 |
'--bkbg-faqc-icon-color': a.iconColor, |
| 58 |
'--bkbg-faqc-nav-r': a.navRadius + 'px', |
| 59 |
'--bkbg-faqc-item-r': a.itemRadius + 'px', |
| 60 |
'--bkbg-faqc-item-gap': a.itemGap + 'px', |
| 61 |
'--bkbg-faqc-q-pad': a.questionPadding + 'px', |
| 62 |
'--bkbg-faqc-a-pad': a.answerPadding + 'px', |
| 63 |
'--bkbg-faqc-nav-w': a.navWidth + 'px', |
| 64 |
paddingTop: a.paddingTop + 'px', |
| 65 |
paddingBottom: a.paddingBottom + 'px', |
| 66 |
backgroundColor: a.bgColor || undefined, |
| 67 |
}, |
| 68 |
_tv(a.typoNavLabel, '--bkbg-faqc-nl-'), |
| 69 |
_tv(a.typoQuestion, '--bkbg-faqc-qt-'), |
| 70 |
_tv(a.typoAnswer, '--bkbg-faqc-an-')); |
| 71 |
} |
| 72 |
|
| 73 |
function renderColorControl(key, label, value, onChange, openKey, setOpenKey) { |
| 74 |
var isOpen = openKey === key; |
| 75 |
return el('div', { key: key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 0', gap: '8px' } }, |
| 76 |
el('span', { style: { fontSize: '12px', color: '#1e1e1e', flex: 1, lineHeight: 1.4 } }, label), |
| 77 |
el('div', { style: { position: 'relative', flexShrink: 0 } }, |
| 78 |
el('button', { type: 'button', title: value || 'default', onClick: function () { setOpenKey(isOpen ? null : key); }, |
| 79 |
style: { width: '28px', height: '28px', borderRadius: '4px', border: isOpen ? '2px solid #007cba' : '2px solid #ddd', cursor: 'pointer', padding: 0, background: value || '#cccccc' } |
| 80 |
}), |
| 81 |
isOpen && el(Popover, { position: 'bottom left', onClose: function () { setOpenKey(null); } }, |
| 82 |
el('div', { style: { padding: '8px' } }, |
| 83 |
el(ColorPicker, { color: value, enableAlpha: true, onChange: onChange }) |
| 84 |
) |
| 85 |
) |
| 86 |
) |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
/* ── FaqItem component ─────────────────────────────────────────────── */ |
| 91 |
function FaqItem(props) { |
| 92 |
var item = props.item; |
| 93 |
var a = props.a; |
| 94 |
var openState = useState(props.expandFirst && props.isFirst); |
| 95 |
var isOpen = openState[0]; |
| 96 |
var setOpen = openState[1]; |
| 97 |
return el('div', { className: 'bkbg-faqc-item', style: { background: a.itemBg, border: '1px solid ' + a.itemBorderColor, borderRadius: a.itemRadius + 'px', overflow: 'hidden', marginBottom: a.itemGap + 'px' } }, |
| 98 |
el('button', { type: 'button', className: 'bkbg-faqc-q' + (isOpen ? ' is-open' : ''), onClick: function () { setOpen(!isOpen); }, style: { width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: a.questionPadding + 'px', background: 'none', border: 'none', cursor: 'pointer', textAlign: 'left', gap: '12px', color: a.questionColor } }, |
| 99 |
el('span', null, item.question || __('Question goes here', 'blockenberg')), |
| 100 |
el('span', { style: { color: isOpen ? a.accentColor : a.iconColor, flexShrink: 0 } }, iconChar(a.iconType, isOpen)) |
| 101 |
), |
| 102 |
isOpen && el('div', { className: 'bkbg-faqc-a', style: { padding: '0 ' + a.answerPadding + 'px ' + a.answerPadding + 'px', color: a.answerColor } }, item.answer || __('Answer goes here.', 'blockenberg')) |
| 103 |
); |
| 104 |
} |
| 105 |
|
| 106 |
/* ── Nav item ──────────────────────────────────────────────────────── */ |
| 107 |
function NavItem(props) { |
| 108 |
var cat = props.cat; |
| 109 |
var a = props.a; |
| 110 |
var isActive = props.isActive; |
| 111 |
return el('button', { type: 'button', className: 'bkbg-faqc-nav-item' + (isActive ? ' is-active' : ''), onClick: props.onClick, style: { width: '100%', display: 'flex', alignItems: 'center', gap: '10px', padding: '12px 16px', background: isActive ? a.navActiveBg : 'transparent', color: isActive ? a.navActiveColor : a.navInactiveColor, border: 'none', cursor: 'pointer', borderRadius: a.navRadius + 'px', textAlign: 'left' } }, |
| 112 |
a.showCatIcon && el('span', null, (cat.iconPickerType || 'custom-char') !== 'custom-char' ? IP().buildEditorIcon(cat.iconPickerType, cat.icon, cat.iconDashicon, cat.iconImageUrl, cat.iconDashiconColor) : (cat.icon || '📂')), |
| 113 |
el('span', { style: { flex: 1 } }, cat.label), |
| 114 |
a.showCatCount && el('span', { style: { background: isActive ? a.accentColor : a.itemBorderColor, color: isActive ? '#fff' : a.navInactiveColor, borderRadius: '99px', padding: '2px 8px', fontSize: '12px', fontWeight: 700, flexShrink: 0 } }, cat.items ? cat.items.length : 0) |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
registerBlockType('blockenberg/faq-categories', { |
| 119 |
title: __('FAQ with Categories', 'blockenberg'), |
| 120 |
icon: 'editor-help', |
| 121 |
category: 'bkbg-business', |
| 122 |
|
| 123 |
edit: function (props) { |
| 124 |
var a = props.attributes; |
| 125 |
var setAttributes = props.setAttributes; |
| 126 |
|
| 127 |
var openColorKeyState = useState(null); |
| 128 |
var openColorKey = openColorKeyState[0]; |
| 129 |
var setOpenColorKey = openColorKeyState[1]; |
| 130 |
|
| 131 |
var activeCatState = useState(0); |
| 132 |
var activeCat = activeCatState[0]; |
| 133 |
var setActiveCat = activeCatState[1]; |
| 134 |
|
| 135 |
var blockProps = useBlockProps({ style: buildWrapStyle(a) }); |
| 136 |
|
| 137 |
function cc(key, label, attrKey) { |
| 138 |
return renderColorControl(key, label, a[attrKey], function (val) { |
| 139 |
var upd = {}; upd[attrKey] = val; setAttributes(upd); |
| 140 |
}, openColorKey, setOpenColorKey); |
| 141 |
} |
| 142 |
|
| 143 |
function updateCat(id, key, val) { |
| 144 |
setAttributes({ categories: a.categories.map(function (c) { if (c.id !== id) return c; var u = Object.assign({}, c); u[key] = val; return u; }) }); |
| 145 |
} |
| 146 |
function addItem(catId) { |
| 147 |
var cat = a.categories.find(function (c) { return c.id === catId; }); |
| 148 |
var items = (cat.items || []).concat([{ id: makeId(), question: __('New question?', 'blockenberg'), answer: __('Answer goes here.', 'blockenberg') }]); |
| 149 |
updateCat(catId, 'items', items); |
| 150 |
} |
| 151 |
function updateItem(catId, itemId, key, val) { |
| 152 |
var cat = a.categories.find(function (c) { return c.id === catId; }); |
| 153 |
updateCat(catId, 'items', (cat.items || []).map(function (item) { if (item.id !== itemId) return item; var u = Object.assign({}, item); u[key] = val; return u; })); |
| 154 |
} |
| 155 |
function removeItem(catId, itemId) { |
| 156 |
var cat = a.categories.find(function (c) { return c.id === catId; }); |
| 157 |
updateCat(catId, 'items', (cat.items || []).filter(function (item) { return item.id !== itemId; })); |
| 158 |
} |
| 159 |
|
| 160 |
var safeCat = Math.min(activeCat, Math.max(0, a.categories.length - 1)); |
| 161 |
var currentCat = a.categories[safeCat]; |
| 162 |
|
| 163 |
var isSidebar = a.navStyle === 'sidebar'; |
| 164 |
var navLeft = isSidebar && a.navPosition === 'left'; |
| 165 |
|
| 166 |
var navArea = el('div', { className: 'bkbg-faqc-nav', style: { flex: isSidebar ? '0 0 ' + a.navWidth + 'px' : '0 0 100%', background: a.navBg, borderRadius: a.navRadius + 'px', padding: '8px', display: 'flex', flexDirection: isSidebar ? 'column' : 'row', gap: '4px', overflowX: isSidebar ? 'hidden' : 'auto' } }, |
| 167 |
a.categories.map(function (cat, i) { |
| 168 |
return el(NavItem, { key: cat.id, cat: cat, a: a, isActive: i === safeCat, onClick: function () { setActiveCat(i); } }); |
| 169 |
}) |
| 170 |
); |
| 171 |
|
| 172 |
var questionsArea = el('div', { className: 'bkbg-faqc-questions', style: { flex: 1, minWidth: 0 } }, |
| 173 |
a.showSearch && el('input', { type: 'text', readOnly: true, placeholder: a.searchPlaceholder || __('Search questions…', 'blockenberg'), style: { width: '100%', padding: '10px 14px', border: '1px solid ' + a.itemBorderColor, borderRadius: a.itemRadius + 'px', marginBottom: '16px', boxSizing: 'border-box' } }), |
| 174 |
currentCat && currentCat.items && currentCat.items.map(function (item, i) { |
| 175 |
return el(FaqItem, { key: item.id, item: item, a: a, expandFirst: a.expandFirst, isFirst: i === 0 }); |
| 176 |
}) |
| 177 |
); |
| 178 |
|
| 179 |
var layoutStyle = { display: 'flex', flexDirection: isSidebar ? 'row' : 'column', gap: '24px', alignItems: isSidebar ? 'flex-start' : 'stretch' }; |
| 180 |
|
| 181 |
return el(Fragment, null, |
| 182 |
el(InspectorControls, null, |
| 183 |
el(PanelBody, { title: __('Settings', 'blockenberg'), initialOpen: true }, |
| 184 |
el(SelectControl, { label: __('Navigation style', 'blockenberg'), value: a.navStyle, options: NAV_STYLE_OPTIONS, onChange: function (v) { setAttributes({ navStyle: v }); } }), |
| 185 |
a.navStyle === 'sidebar' && el(SelectControl, { label: __('Sidebar position', 'blockenberg'), value: a.navPosition, options: NAV_POS_OPTIONS, onChange: function (v) { setAttributes({ navPosition: v }); } }), |
| 186 |
a.navStyle === 'sidebar' && el(RangeControl, { label: __('Sidebar width (px)', 'blockenberg'), value: a.navWidth, min: 160, max: 360, onChange: function (v) { setAttributes({ navWidth: v }); } }), |
| 187 |
el(SelectControl, { label: __('Accordion icon', 'blockenberg'), value: a.iconType, options: ICON_TYPE_OPTIONS, onChange: function (v) { setAttributes({ iconType: v }); } }), |
| 188 |
el(ToggleControl, { label: __('Show category icon', 'blockenberg'), checked: a.showCatIcon, onChange: function (v) { setAttributes({ showCatIcon: v }); }, __nextHasNoMarginBottom: true }), |
| 189 |
el(ToggleControl, { label: __('Show item count', 'blockenberg'), checked: a.showCatCount, onChange: function (v) { setAttributes({ showCatCount: v }); }, __nextHasNoMarginBottom: true }), |
| 190 |
el(ToggleControl, { label: __('Expand first item', 'blockenberg'), checked: a.expandFirst, onChange: function (v) { setAttributes({ expandFirst: v }); }, __nextHasNoMarginBottom: true }), |
| 191 |
el(ToggleControl, { label: __('Allow multiple open','blockenberg'), checked: a.allowMultiple, onChange: function (v) { setAttributes({ allowMultiple: v }); }, __nextHasNoMarginBottom: true }), |
| 192 |
el(ToggleControl, { label: __('Show search field', 'blockenberg'), checked: a.showSearch, onChange: function (v) { setAttributes({ showSearch: v }); }, __nextHasNoMarginBottom: true }), |
| 193 |
a.showSearch && el(TextControl, { label: __('Search placeholder', 'blockenberg'), value: a.searchPlaceholder, onChange: function (v) { setAttributes({ searchPlaceholder: v }); } }) |
| 194 |
), |
| 195 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 196 |
_tc() && _tc()({ label: __('Nav Label', 'blockenberg'), typo: a.typoNavLabel, onChange: function (v) { setAttributes({ typoNavLabel: v }); } }), |
| 197 |
_tc() && _tc()({ label: __('Question', 'blockenberg'), typo: a.typoQuestion, onChange: function (v) { setAttributes({ typoQuestion: v }); } }), |
| 198 |
_tc() && _tc()({ label: __('Answer', 'blockenberg'), typo: a.typoAnswer, onChange: function (v) { setAttributes({ typoAnswer: v }); } }) |
| 199 |
), |
| 200 |
el(PanelBody, { title: __('Sizing', 'blockenberg'), initialOpen: false }, |
| 201 |
el(RangeControl, { label: __('Question padding (px)', 'blockenberg'), value: a.questionPadding, min: 10, max: 36, onChange: function (v) { setAttributes({ questionPadding: v }); } }), |
| 202 |
el(RangeControl, { label: __('Answer padding (px)', 'blockenberg'), value: a.answerPadding, min: 10, max: 36, onChange: function (v) { setAttributes({ answerPadding: v }); } }), |
| 203 |
el(RangeControl, { label: __('Item radius (px)', 'blockenberg'), value: a.itemRadius, min: 0, max: 24, onChange: function (v) { setAttributes({ itemRadius: v }); } }), |
| 204 |
el(RangeControl, { label: __('Item gap (px)', 'blockenberg'), value: a.itemGap, min: 0, max: 24, onChange: function (v) { setAttributes({ itemGap: v }); } }), |
| 205 |
el(RangeControl, { label: __('Nav radius (px)', 'blockenberg'), value: a.navRadius, min: 0, max: 24, onChange: function (v) { setAttributes({ navRadius: v }); } }) |
| 206 |
), |
| 207 |
el(PanelBody, { title: __('Colors', 'blockenberg'), initialOpen: false }, |
| 208 |
cc('accentColor', __('Accent', 'blockenberg'), 'accentColor'), |
| 209 |
cc('navBg', __('Nav background', 'blockenberg'), 'navBg'), |
| 210 |
cc('navActiveBg', __('Nav active bg', 'blockenberg'), 'navActiveBg'), |
| 211 |
cc('navActiveColor', __('Nav active text', 'blockenberg'), 'navActiveColor'), |
| 212 |
cc('navInactiveColor',__('Nav inactive text', 'blockenberg'), 'navInactiveColor'), |
| 213 |
cc('itemBg', __('Item background', 'blockenberg'), 'itemBg'), |
| 214 |
cc('itemBorderColor',__('Item border', 'blockenberg'), 'itemBorderColor'), |
| 215 |
cc('questionColor', __('Question text', 'blockenberg'), 'questionColor'), |
| 216 |
cc('answerColor', __('Answer text', 'blockenberg'), 'answerColor'), |
| 217 |
cc('iconColor', __('Accordion icon', 'blockenberg'), 'iconColor'), |
| 218 |
cc('bgColor', __('Section background', 'blockenberg'), 'bgColor') |
| 219 |
), |
| 220 |
el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false }, |
| 221 |
el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }), |
| 222 |
el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } }) |
| 223 |
), |
| 224 |
el(PanelBody, { title: __('Categories', 'blockenberg'), initialOpen: false }, |
| 225 |
a.categories.map(function (cat, ci) { |
| 226 |
return el(PanelBody, { key: cat.id, title: (cat.icon || '') + ' ' + (cat.label || 'Category ' + (ci + 1)), initialOpen: ci === safeCat }, |
| 227 |
el(IP().IconPickerControl, { |
| 228 |
iconType: cat.iconPickerType, customChar: cat.icon, dashicon: cat.iconDashicon, imageUrl: cat.iconImageUrl, |
| 229 |
onChangeType: function (v) { updateCat(cat.id, 'iconPickerType', v); }, |
| 230 |
onChangeChar: function (v) { updateCat(cat.id, 'icon', v); }, |
| 231 |
onChangeDashicon: function (v) { updateCat(cat.id, 'iconDashicon', v); }, |
| 232 |
onChangeImageUrl: function (v) { updateCat(cat.id, 'iconImageUrl', v); } |
| 233 |
}), |
| 234 |
el(TextControl, { label: __('Label', 'blockenberg'), value: cat.label, onChange: function (v) { updateCat(cat.id, 'label', v); } }), |
| 235 |
el('strong', { style: { display: 'block', margin: '10px 0 6px', fontSize: '12px' } }, __('Questions', 'blockenberg')), |
| 236 |
(cat.items || []).map(function (item) { |
| 237 |
return el('div', { key: item.id, style: { background: '#f9f9f9', borderRadius: '6px', padding: '8px', marginBottom: '8px' } }, |
| 238 |
el(TextControl, { label: __('Question', 'blockenberg'), value: item.question, onChange: function (v) { updateItem(cat.id, item.id, 'question', v); } }), |
| 239 |
el(TextareaControl, { label: __('Answer', 'blockenberg'), value: item.answer, onChange: function (v) { updateItem(cat.id, item.id, 'answer', v); }, rows: 3 }), |
| 240 |
el(Button, { onClick: function () { removeItem(cat.id, item.id); }, isDestructive: true, variant: 'link', size: 'compact' }, __('Remove question', 'blockenberg')) |
| 241 |
); |
| 242 |
}), |
| 243 |
el(Button, { onClick: function () { addItem(cat.id); }, variant: 'secondary', size: 'compact', style: { marginBottom: '10px' } }, __('+ Add Question', 'blockenberg')), |
| 244 |
el(Button, { onClick: function () { setAttributes({ categories: a.categories.filter(function (c) { return c.id !== cat.id; }) }); }, isDestructive: true, variant: 'tertiary', size: 'compact' }, __('Remove category', 'blockenberg')) |
| 245 |
); |
| 246 |
}), |
| 247 |
el(Button, { onClick: function () { setAttributes({ categories: a.categories.concat([{ id: makeId(), icon: '📁', label: __('New Category', 'blockenberg'), items: [], iconPickerType: 'custom-char', iconDashicon: '', iconImageUrl: '' }]) }); }, variant: 'primary', style: { marginTop: '8px' } }, __('+ Add Category', 'blockenberg')) |
| 248 |
) |
| 249 |
), |
| 250 |
|
| 251 |
el('div', blockProps, |
| 252 |
a.showSearch && el('div', { style: { marginBottom: '20px' } }, |
| 253 |
el('input', { type: 'text', readOnly: true, placeholder: a.searchPlaceholder || __('Search questions…', 'blockenberg'), style: { width: '100%', padding: '10px 14px', border: '1px solid ' + a.itemBorderColor, borderRadius: a.itemRadius + 'px', boxSizing: 'border-box' } }) |
| 254 |
), |
| 255 |
el('div', { className: 'bkbg-faqc-layout bkbg-faqc--' + a.navStyle + (isSidebar ? ' bkbg-faqc--' + a.navPosition : ''), style: layoutStyle }, |
| 256 |
isSidebar && !navLeft ? questionsArea : null, |
| 257 |
navArea, |
| 258 |
isSidebar && navLeft ? questionsArea : !isSidebar ? questionsArea : null |
| 259 |
) |
| 260 |
) |
| 261 |
); |
| 262 |
}, |
| 263 |
|
| 264 |
save: function (props) { |
| 265 |
var a = props.attributes; |
| 266 |
var isSidebar = a.navStyle === 'sidebar'; |
| 267 |
var navLeft = isSidebar && a.navPosition === 'left'; |
| 268 |
var layoutStyle = { display: 'flex', flexDirection: isSidebar ? 'row' : 'column', gap: '24px', alignItems: isSidebar ? 'flex-start' : 'stretch' }; |
| 269 |
|
| 270 |
var navArea = el('nav', { className: 'bkbg-faqc-nav', role: 'tablist', style: { flex: isSidebar ? '0 0 ' + a.navWidth + 'px' : '0 0 100%' } }, |
| 271 |
a.categories.map(function (cat, i) { |
| 272 |
return el('button', { key: cat.id, type: 'button', role: 'tab', className: 'bkbg-faqc-nav-item' + (i === 0 ? ' is-active' : ''), 'data-cat': cat.id, 'aria-selected': i === 0 ? 'true' : 'false', style: { width: '100%', display: 'flex', alignItems: 'center', gap: '10px', padding: '12px 16px', border: 'none', cursor: 'pointer' } }, |
| 273 |
a.showCatIcon && el('span', { className: 'bkbg-faqc-cat-icon', 'aria-hidden': 'true' }, (cat.iconPickerType || 'custom-char') !== 'custom-char' ? IP().buildSaveIcon(cat.iconPickerType, cat.icon, cat.iconDashicon, cat.iconImageUrl, cat.iconDashiconColor) : cat.icon), |
| 274 |
el('span', null, cat.label), |
| 275 |
a.showCatCount && el('span', { className: 'bkbg-faqc-count' }, cat.items ? cat.items.length : 0) |
| 276 |
); |
| 277 |
}) |
| 278 |
); |
| 279 |
|
| 280 |
var questionsArea = el('div', { className: 'bkbg-faqc-panels' }, |
| 281 |
a.showSearch && el('input', { type: 'text', className: 'bkbg-faqc-search', placeholder: a.searchPlaceholder || __('Search questions…', 'blockenberg'), 'aria-label': __('Search FAQ', 'blockenberg') }), |
| 282 |
a.categories.map(function (cat, ci) { |
| 283 |
return el('div', { key: cat.id, className: 'bkbg-faqc-panel' + (ci === 0 ? ' is-active' : ''), role: 'tabpanel', 'data-cat': cat.id, 'aria-hidden': ci === 0 ? 'false' : 'true', style: { display: ci === 0 ? undefined : 'none' } }, |
| 284 |
(cat.items || []).map(function (item, ii) { |
| 285 |
return el('div', { key: item.id, className: 'bkbg-faqc-item', 'data-open': a.expandFirst && ii === 0 ? '1' : undefined }, |
| 286 |
el('button', { type: 'button', className: 'bkbg-faqc-q', 'aria-expanded': (a.expandFirst && ii === 0) ? 'true' : 'false' }, |
| 287 |
el('span', null, item.question), |
| 288 |
el('span', { className: 'bkbg-faqc-icon', 'aria-hidden': 'true' }, iconChar(a.iconType, a.expandFirst && ii === 0)) |
| 289 |
), |
| 290 |
el('div', { className: 'bkbg-faqc-a', 'aria-hidden': (a.expandFirst && ii === 0) ? 'false' : 'true', style: { display: (a.expandFirst && ii === 0) ? undefined : 'none' } }, |
| 291 |
el('p', null, item.answer) |
| 292 |
) |
| 293 |
); |
| 294 |
}) |
| 295 |
); |
| 296 |
}) |
| 297 |
); |
| 298 |
|
| 299 |
return el('div', wp.blockEditor.useBlockProps.save({ className: 'bkbg-faqc-wrapper', style: buildWrapStyle(a), 'data-allow-multiple': a.allowMultiple ? '1' : undefined, 'data-icon-type': a.iconType }), |
| 300 |
a.showSearch && el('input', { type: 'text', className: 'bkbg-faqc-search-global', placeholder: a.searchPlaceholder || __('Search questions…', 'blockenberg'), 'aria-label': __('Search FAQ', 'blockenberg') }), |
| 301 |
el('div', { className: 'bkbg-faqc-layout bkbg-faqc--' + a.navStyle + (isSidebar ? ' bkbg-faqc--' + a.navPosition : ''), style: layoutStyle }, |
| 302 |
isSidebar && !navLeft ? questionsArea : null, |
| 303 |
navArea, |
| 304 |
isSidebar && navLeft ? questionsArea : !isSidebar ? questionsArea : null |
| 305 |
) |
| 306 |
); |
| 307 |
} |
| 308 |
}); |
| 309 |
}() ); |
| 310 |
|