| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var useState = wp.element.useState; |
| 4 |
var Fragment = wp.element.Fragment; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var PanelBody = wp.components.PanelBody; |
| 10 |
var RangeControl = wp.components.RangeControl; |
| 11 |
var TextControl = wp.components.TextControl; |
| 12 |
var ToggleControl = wp.components.ToggleControl; |
| 13 |
|
| 14 |
var _tc, _tv; |
| 15 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 16 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 17 |
|
| 18 |
registerBlockType('blockenberg/net-worth-calculator', { |
| 19 |
edit: function (props) { |
| 20 |
var attributes = props.attributes; |
| 21 |
var setAttributes = props.setAttributes; |
| 22 |
|
| 23 |
var blockProps = useBlockProps((function () { |
| 24 |
var _tvf = getTypoCssVars(); |
| 25 |
var s = { |
| 26 |
background: attributes.sectionBg, |
| 27 |
paddingTop: attributes.paddingTop + 'px', |
| 28 |
paddingBottom: attributes.paddingBottom + 'px' |
| 29 |
}; |
| 30 |
if (_tvf) { |
| 31 |
Object.assign(s, _tvf(attributes.titleTypo, '--bkbg-nwc-tt-')); |
| 32 |
Object.assign(s, _tvf(attributes.subtitleTypo, '--bkbg-nwc-st-')); |
| 33 |
} |
| 34 |
return { className: 'bkbg-nwc-wrap', style: s }; |
| 35 |
})()); |
| 36 |
|
| 37 |
function togCtrl(label, key) { |
| 38 |
return el(ToggleControl, { |
| 39 |
__nextHasNoMarginBottom: true, label: label, checked: attributes[key], |
| 40 |
onChange: function (v) { var o = {}; o[key] = v; setAttributes(o); } |
| 41 |
}); |
| 42 |
} |
| 43 |
function rng(label, key, min, max, step) { |
| 44 |
return el(RangeControl, { |
| 45 |
__nextHasNoMarginBottom: true, label: label, value: attributes[key], min: min, max: max, step: step || 1, |
| 46 |
onChange: function (v) { var o = {}; o[key] = v; setAttributes(o); } |
| 47 |
}); |
| 48 |
} |
| 49 |
|
| 50 |
var colors = [ |
| 51 |
{ label: 'Accent', value: attributes.accentColor, onChange: function (v) { setAttributes({ accentColor: v }); } }, |
| 52 |
{ label: 'Asset bar', value: attributes.assetColor, onChange: function (v) { setAttributes({ assetColor: v }); } }, |
| 53 |
{ label: 'Liability bar', value: attributes.liabilityColor, onChange: function (v) { setAttributes({ liabilityColor: v }); } }, |
| 54 |
{ label: 'Net positive', value: attributes.netPositiveColor, onChange: function (v) { setAttributes({ netPositiveColor: v }); } }, |
| 55 |
{ label: 'Net negative', value: attributes.netNegativeColor, onChange: function (v) { setAttributes({ netNegativeColor: v }); } }, |
| 56 |
{ label: 'Cash color', value: attributes.cashColor, onChange: function (v) { setAttributes({ cashColor: v }); } }, |
| 57 |
{ label: 'Investments', value: attributes.investColor, onChange: function (v) { setAttributes({ investColor: v }); } }, |
| 58 |
{ label: 'Real estate', value: attributes.realEstateColor, onChange: function (v) { setAttributes({ realEstateColor: v }); } }, |
| 59 |
{ label: 'Vehicles', value: attributes.vehicleColor, onChange: function (v) { setAttributes({ vehicleColor: v }); } }, |
| 60 |
{ label: 'Other assets', value: attributes.otherAssetColor, onChange: function (v) { setAttributes({ otherAssetColor: v }); } }, |
| 61 |
{ label: 'Section BG', value: attributes.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v }); } }, |
| 62 |
{ label: 'Card BG', value: attributes.cardBg, onChange: function (v) { setAttributes({ cardBg: v }); } }, |
| 63 |
{ label: 'Panel BG', value: attributes.panelBg, onChange: function (v) { setAttributes({ panelBg: v }); } }, |
| 64 |
{ label: 'Title', value: attributes.titleColor, onChange: function (v) { setAttributes({ titleColor: v }); } }, |
| 65 |
{ label: 'Subtitle', value: attributes.subtitleColor, onChange: function (v) { setAttributes({ subtitleColor: v }); } }, |
| 66 |
{ label: 'Label', value: attributes.labelColor, onChange: function (v) { setAttributes({ labelColor: v }); } }, |
| 67 |
{ label: 'Input BG', value: attributes.inputBg, onChange: function (v) { setAttributes({ inputBg: v }); } }, |
| 68 |
{ label: 'Input border', value: attributes.inputBorder, onChange: function (v) { setAttributes({ inputBorder: v }); } } |
| 69 |
]; |
| 70 |
|
| 71 |
var assetC = attributes.assetColor || '#10b981'; |
| 72 |
var liabC = attributes.liabilityColor || '#ef4444'; |
| 73 |
|
| 74 |
return el(Fragment, null, |
| 75 |
el(InspectorControls, null, |
| 76 |
el(PanelBody, { title: 'Content', initialOpen: true }, |
| 77 |
togCtrl('Show title', 'showTitle'), |
| 78 |
attributes.showTitle && el(TextControl, { |
| 79 |
__nextHasNoMarginBottom: true, label: 'Title', value: attributes.title, |
| 80 |
onChange: function (v) { setAttributes({ title: v }); } |
| 81 |
}), |
| 82 |
togCtrl('Show subtitle', 'showSubtitle'), |
| 83 |
attributes.showSubtitle && el(TextControl, { |
| 84 |
__nextHasNoMarginBottom: true, label: 'Subtitle', value: attributes.subtitle, |
| 85 |
onChange: function (v) { setAttributes({ subtitle: v }); } |
| 86 |
}), |
| 87 |
el(TextControl, { |
| 88 |
__nextHasNoMarginBottom: true, label: 'Currency symbol', value: attributes.currency, |
| 89 |
onChange: function (v) { setAttributes({ currency: v }); } |
| 90 |
}) |
| 91 |
), |
| 92 |
el(PanelBody, { title: 'Display', initialOpen: false }, |
| 93 |
togCtrl('Show bar chart', 'showChart'), |
| 94 |
togCtrl('Show breakdown', 'showBreakdown') |
| 95 |
), |
| 96 |
el(PanelColorSettings, { title: 'Colors', initialOpen: false, colorSettings: colors }), |
| 97 |
el(PanelBody, { title: 'Typography', initialOpen: false }, |
| 98 |
getTypoControl() && el(getTypoControl(), { label: 'Title Typography', value: attributes.titleTypo, onChange: function (v) { setAttributes({ titleTypo: v }); } }), |
| 99 |
getTypoControl() && el(getTypoControl(), { label: 'Subtitle Typography', value: attributes.subtitleTypo, onChange: function (v) { setAttributes({ subtitleTypo: v }); } }) |
| 100 |
), |
| 101 |
el(PanelBody, { title: 'Sizing', initialOpen: false }, |
| 102 |
rng('Max width (px)', 'maxWidth', 400, 1200, 10), |
| 103 |
rng('Card radius (px)', 'cardRadius', 0, 32), |
| 104 |
rng('Panel radius (px)', 'panelRadius', 0, 24), |
| 105 |
rng('Input radius (px)', 'inputRadius', 0, 24), |
| 106 |
rng('Padding top (px)', 'paddingTop', 0, 160, 4), |
| 107 |
rng('Padding bottom (px)', 'paddingBottom', 0, 160, 4) |
| 108 |
) |
| 109 |
), |
| 110 |
el('div', blockProps, |
| 111 |
el('div', { |
| 112 |
style: { |
| 113 |
background: attributes.cardBg, borderRadius: attributes.cardRadius + 'px', |
| 114 |
maxWidth: attributes.maxWidth + 'px', margin: '0 auto', padding: '40px 36px', |
| 115 |
boxShadow: '0 4px 32px rgba(0,0,0,0.08)' |
| 116 |
} |
| 117 |
}, |
| 118 |
attributes.showTitle && el('div', { className: 'bkbg-nwc-title', style: { color: attributes.titleColor, textAlign: 'center', marginBottom: '6px' } }, attributes.title), |
| 119 |
attributes.showSubtitle && el('div', { className: 'bkbg-nwc-subtitle', style: { color: attributes.subtitleColor, textAlign: 'center', marginBottom: '28px' } }, attributes.subtitle), |
| 120 |
el('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px', marginBottom: '24px' } }, |
| 121 |
el('div', { style: { background: attributes.panelBg, borderRadius: attributes.panelRadius + 'px', padding: '20px', borderTop: '3px solid ' + assetC } }, |
| 122 |
el('div', { style: { fontSize: '13px', fontWeight: '700', color: assetC, marginBottom: '12px' } }, '💰 Assets'), |
| 123 |
['Cash & Bank', 'Investments', 'Real Estate', 'Vehicles', 'Other'].map(function (label) { |
| 124 |
return el('div', { key: label, style: { marginBottom: '10px' } }, |
| 125 |
el('div', { style: { fontSize: '12px', fontWeight: '600', color: attributes.labelColor, marginBottom: '4px' } }, label), |
| 126 |
el('div', { style: { background: attributes.inputBg, border: '1.5px solid ' + attributes.inputBorder, borderRadius: attributes.inputRadius + 'px', padding: '8px 12px', fontSize: '14px', color: '#9ca3af' } }, attributes.currency + '0') |
| 127 |
); |
| 128 |
}) |
| 129 |
), |
| 130 |
el('div', { style: { background: attributes.panelBg, borderRadius: attributes.panelRadius + 'px', padding: '20px', borderTop: '3px solid ' + liabC } }, |
| 131 |
el('div', { style: { fontSize: '13px', fontWeight: '700', color: liabC, marginBottom: '12px' } }, '💳 Liabilities'), |
| 132 |
['Mortgage', 'Car Loans', 'Credit Cards', 'Student Loans', 'Other Debts'].map(function (label) { |
| 133 |
return el('div', { key: label, style: { marginBottom: '10px' } }, |
| 134 |
el('div', { style: { fontSize: '12px', fontWeight: '600', color: attributes.labelColor, marginBottom: '4px' } }, label), |
| 135 |
el('div', { style: { background: attributes.inputBg, border: '1.5px solid ' + attributes.inputBorder, borderRadius: attributes.inputRadius + 'px', padding: '8px 12px', fontSize: '14px', color: '#9ca3af' } }, attributes.currency + '0') |
| 136 |
); |
| 137 |
}) |
| 138 |
) |
| 139 |
), |
| 140 |
el('div', { style: { background: assetC + '15', border: '2px solid ' + assetC + '44', borderRadius: '12px', padding: '20px', textAlign: 'center' } }, |
| 141 |
el('div', { style: { fontSize: '12px', fontWeight: '700', color: assetC, textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '4px' } }, 'Net Worth'), |
| 142 |
el('div', { style: { fontSize: '40px', fontWeight: '900', color: assetC } }, attributes.currency + '0'), |
| 143 |
el('div', { style: { fontSize: '13px', color: '#6b7280', marginTop: '4px' } }, 'Total assets minus total liabilities') |
| 144 |
) |
| 145 |
) |
| 146 |
) |
| 147 |
); |
| 148 |
}, |
| 149 |
|
| 150 |
save: function (props) { |
| 151 |
var a = props.attributes; |
| 152 |
return el('div', wp.blockEditor.useBlockProps.save(), |
| 153 |
el('div', { className: 'bkbg-nwc-app', 'data-opts': JSON.stringify(a) }) |
| 154 |
); |
| 155 |
} |
| 156 |
}); |
| 157 |
}() ); |
| 158 |
|