| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 9 |
var MediaUploadCheck = wp.blockEditor.MediaUploadCheck; |
| 10 |
var PanelBody = wp.components.PanelBody; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var ToggleControl = wp.components.ToggleControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
var TextControl = wp.components.TextControl; |
| 15 |
var TextareaControl = wp.components.TextareaControl; |
| 16 |
var Button = wp.components.Button; |
| 17 |
|
| 18 |
var _TypographyControl, _typoCssVars; |
| 19 |
function getTypographyControl() { return _TypographyControl || (_TypographyControl = window.bkbgTypographyControl); } |
| 20 |
function getTypoCssVars() { return _typoCssVars || (_typoCssVars = window.bkbgTypoCssVars); } |
| 21 |
|
| 22 |
registerBlockType('blockenberg/interactive-image-sheen', { |
| 23 |
title: __('Interactive Image Sheen'), |
| 24 |
icon: 'visibility', |
| 25 |
category: 'bkbg-effects', |
| 26 |
|
| 27 |
edit: function (props) { |
| 28 |
var attr = props.attributes; |
| 29 |
var setAttr = props.setAttributes; |
| 30 |
var bp = useBlockProps((function () { |
| 31 |
var s = {}; |
| 32 |
var _tv = getTypoCssVars(); |
| 33 |
Object.assign(s, _tv(attr.captionTypo, '--bkbg-iis-cp-')); |
| 34 |
return { className: 'bkbg-iis-wrap', style: s }; |
| 35 |
})()); |
| 36 |
|
| 37 |
var inspector = el(InspectorControls, {}, |
| 38 |
/* Image */ |
| 39 |
el(PanelBody, { title: __('Image'), initialOpen: true }, |
| 40 |
el(MediaUploadCheck, {}, |
| 41 |
el(MediaUpload, { |
| 42 |
onSelect: function (m) { setAttr({ imageUrl: m.url, imageAlt: m.alt || '' }); }, |
| 43 |
allowedTypes: ['image'], value: attr.imageUrl, |
| 44 |
render: function (ref) { |
| 45 |
return el('div', {}, |
| 46 |
attr.imageUrl && el('img', { src: attr.imageUrl, style: { |
| 47 |
width: '100%', height: 80, objectFit: 'cover', |
| 48 |
borderRadius: 8, marginBottom: 8, display: 'block' |
| 49 |
}}), |
| 50 |
el(Button, { variant: attr.imageUrl ? 'secondary' : 'primary', onClick: ref.open }, |
| 51 |
attr.imageUrl ? __('Change Image') : __('Choose Image')) |
| 52 |
); |
| 53 |
} |
| 54 |
}) |
| 55 |
), |
| 56 |
attr.imageUrl && el(Button, { isDestructive: true, variant: 'secondary', |
| 57 |
onClick: function () { setAttr({ imageUrl: '', imageAlt: '' }); }, |
| 58 |
style: { marginTop: 8 } |
| 59 |
}, __('Remove Image')), |
| 60 |
el(TextControl, { label: __('Alt Text'), value: attr.imageAlt, |
| 61 |
onChange: function (v) { setAttr({ imageAlt: v }); }, |
| 62 |
__nextHasNoMarginBottom: true }) |
| 63 |
), |
| 64 |
|
| 65 |
/* Dimensions */ |
| 66 |
el(PanelBody, { title: __('Dimensions'), initialOpen: false }, |
| 67 |
el(SelectControl, { label: __('Alignment'), value: attr.align2, |
| 68 |
options: [ |
| 69 |
{ label: 'Left', value: 'left' }, |
| 70 |
{ label: 'Center', value: 'center' }, |
| 71 |
{ label: 'Right', value: 'right' } |
| 72 |
], |
| 73 |
onChange: function (v) { setAttr({ align2: v }); }, |
| 74 |
__nextHasNoMarginBottom: true }), |
| 75 |
el(RangeControl, { label: __('Max Width (px)'), value: attr.imageWidth, |
| 76 |
min: 160, max: 1200, |
| 77 |
onChange: function (v) { setAttr({ imageWidth: v }); }, |
| 78 |
__nextHasNoMarginBottom: true }), |
| 79 |
el(RangeControl, { label: __('Height (px)'), value: attr.imageHeight, |
| 80 |
min: 100, max: 800, |
| 81 |
onChange: function (v) { setAttr({ imageHeight: v }); }, |
| 82 |
__nextHasNoMarginBottom: true }), |
| 83 |
el(RangeControl, { label: __('Border Radius (px)'), value: attr.imageRadius, |
| 84 |
min: 0, max: 60, |
| 85 |
onChange: function (v) { setAttr({ imageRadius: v }); }, |
| 86 |
__nextHasNoMarginBottom: true }) |
| 87 |
), |
| 88 |
|
| 89 |
/* Sheen */ |
| 90 |
el(PanelBody, { title: __('Sheen Effect'), initialOpen: false }, |
| 91 |
el(RangeControl, { label: __('Sheen Size (% of card)'), value: attr.sheenSize, |
| 92 |
min: 20, max: 120, |
| 93 |
onChange: function (v) { setAttr({ sheenSize: v }); }, |
| 94 |
__nextHasNoMarginBottom: true }), |
| 95 |
el(RangeControl, { label: __('Sheen Blur (px)'), value: attr.sheenBlur, |
| 96 |
min: 0, max: 100, |
| 97 |
onChange: function (v) { setAttr({ sheenBlur: v }); }, |
| 98 |
__nextHasNoMarginBottom: true }), |
| 99 |
el(RangeControl, { label: __('Tilt Strength'), value: attr.tiltStrength, |
| 100 |
min: 0, max: 30, |
| 101 |
onChange: function (v) { setAttr({ tiltStrength: v }); }, |
| 102 |
__nextHasNoMarginBottom: true }), |
| 103 |
el(ToggleControl, { label: __('Dynamic Shadow'), checked: attr.tiltShadow, |
| 104 |
onChange: function (v) { setAttr({ tiltShadow: v }); }, |
| 105 |
__nextHasNoMarginBottom: true }) |
| 106 |
), |
| 107 |
|
| 108 |
/* Caption */ |
| 109 |
el(PanelBody, { title: __('Caption'), initialOpen: false }, |
| 110 |
el(ToggleControl, { label: __('Show Caption'), checked: attr.showCaption, |
| 111 |
onChange: function (v) { setAttr({ showCaption: v }); }, |
| 112 |
__nextHasNoMarginBottom: true }), |
| 113 |
el(TextareaControl, { label: __('Caption Text'), value: attr.caption, |
| 114 |
onChange: function (v) { setAttr({ caption: v }); }, |
| 115 |
__nextHasNoMarginBottom: true }), |
| 116 |
), |
| 117 |
|
| 118 |
|
| 119 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 120 |
getTypographyControl() && el(getTypographyControl(), { label: __('Caption'), value: attr.captionTypo, onChange: function (v) { setAttr({ captionTypo: v }); } }) |
| 121 |
), |
| 122 |
el(PanelColorSettings, { |
| 123 |
title: __('Colors'), initialOpen: false, |
| 124 |
colorSettings: [ |
| 125 |
{ label: __('Sheen'), value: attr.sheenColor, |
| 126 |
onChange: function (v) { setAttr({ sheenColor: v || 'rgba(255,255,255,0.35)' }); } }, |
| 127 |
{ label: __('Shadow'), value: attr.shadowColor, |
| 128 |
onChange: function (v) { setAttr({ shadowColor: v || 'rgba(99,102,241,0.4)' }); } }, |
| 129 |
{ label: __('Caption'), value: attr.captionColor, |
| 130 |
onChange: function (v) { setAttr({ captionColor: v || '#64748b' }); } }, |
| 131 |
{ label: __('Section BG'), value: attr.bgColor, |
| 132 |
onChange: function (v) { setAttr({ bgColor: v || '' }); } } |
| 133 |
] |
| 134 |
}) |
| 135 |
); |
| 136 |
|
| 137 |
var justifyMap = { left: 'flex-start', center: 'center', right: 'flex-end' }; |
| 138 |
|
| 139 |
return el(wp.element.Fragment, {}, inspector, |
| 140 |
el('div', bp, |
| 141 |
el('div', { style: { |
| 142 |
display: 'flex', |
| 143 |
justifyContent: justifyMap[attr.align2] || 'center', |
| 144 |
background: attr.bgColor || 'transparent', |
| 145 |
padding: attr.bgColor ? '32px' : '0' |
| 146 |
}}, |
| 147 |
el('div', { style: { maxWidth: attr.imageWidth + 'px', width: '100%' }}, |
| 148 |
attr.imageUrl |
| 149 |
? el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { |
| 150 |
width: '100%', height: attr.imageHeight + 'px', |
| 151 |
objectFit: 'cover', borderRadius: attr.imageRadius + 'px', |
| 152 |
display: 'block' |
| 153 |
}}) |
| 154 |
: el('div', { style: { |
| 155 |
width: '100%', height: attr.imageHeight + 'px', |
| 156 |
background: '#e2e8f0', borderRadius: attr.imageRadius + 'px', |
| 157 |
display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 158 |
color: '#94a3b8', fontSize: 14 |
| 159 |
}}, __('Choose an image →')), |
| 160 |
attr.showCaption && attr.caption && el('p', { className: 'bkbg-iis-caption', style: { |
| 161 |
color: attr.captionColor |
| 162 |
}}, attr.caption) |
| 163 |
) |
| 164 |
) |
| 165 |
) |
| 166 |
); |
| 167 |
}, |
| 168 |
|
| 169 |
save: function (props) { |
| 170 |
var attr = props.attributes; |
| 171 |
var bp = useBlockProps.save(); |
| 172 |
return el('div', bp, |
| 173 |
el('div', { className: 'bkbg-iis-app', 'data-opts': JSON.stringify(attr) }) |
| 174 |
); |
| 175 |
} |
| 176 |
}); |
| 177 |
}() ); |
| 178 |
|