first commit
This commit is contained in:
83
blocks/sidebar-heading/sidebar-heading.js
Normal file
83
blocks/sidebar-heading/sidebar-heading.js
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
( function ( blocks, element, blockEditor ) {
|
||||
const el = element.createElement,
|
||||
registerBlockType = blocks.registerBlockType,
|
||||
ServerSideRender = PgServerSideRender2,
|
||||
InspectorControls = blockEditor.InspectorControls,
|
||||
useBlockProps = blockEditor.useBlockProps;
|
||||
|
||||
const {__} = wp.i18n;
|
||||
const {ColorPicker, TextControl, ToggleControl, SelectControl, Panel, PanelBody, Disabled, TextareaControl, BaseControl} = wp.components;
|
||||
const {useSelect} = wp.data;
|
||||
const {RawHTML, Fragment} = element;
|
||||
|
||||
const {InnerBlocks, URLInputButton, RichText} = wp.blockEditor;
|
||||
const useInnerBlocksProps = blockEditor.useInnerBlocksProps || blockEditor.__experimentalUseInnerBlocksProps;
|
||||
|
||||
const propOrDefault = function(val, prop, field) {
|
||||
if(block.attributes[prop] && (val === null || val === '')) {
|
||||
return field ? block.attributes[prop].default[field] : block.attributes[prop].default;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
const block = registerBlockType( 'leonpharmacy/sidebar-heading', {
|
||||
apiVersion: 2,
|
||||
title: 'Sidebar Heading',
|
||||
description: '',
|
||||
icon: 'block-default',
|
||||
category: 'archive',
|
||||
keywords: [],
|
||||
supports: {color: {background: false,text: false,gradients: false,link: false,},typography: {fontSize: false,},anchor: false,align: false,},
|
||||
attributes: {
|
||||
heading: {
|
||||
type: 'string',
|
||||
default: `Heading`,
|
||||
}
|
||||
},
|
||||
example: { attributes: { heading: `Heading` } },
|
||||
edit: function ( props ) {
|
||||
const blockProps = useBlockProps({ className: 'mb-4' });
|
||||
const setAttributes = props.setAttributes;
|
||||
|
||||
|
||||
const innerBlocksProps = null;
|
||||
|
||||
|
||||
return el(Fragment, {}, [
|
||||
el('div', { ...blockProps }, [' ', el(RichText, { tagName: 'h2', className: 'font-bold mb-4 text-2xl', value: propOrDefault( props.attributes.heading, 'heading' ), onChange: function(val) { setAttributes( {heading: val }) }, withoutInteractiveFormatting: true, allowedFormats: [] }), ' ', el('hr', { className: 'mb-4' }), ' ']),
|
||||
|
||||
el( InspectorControls, {},
|
||||
[
|
||||
|
||||
el(Panel, {},
|
||||
el(PanelBody, {
|
||||
title: __('Block properties')
|
||||
}, [
|
||||
|
||||
el(TextControl, {
|
||||
value: props.attributes.heading,
|
||||
help: __( '' ),
|
||||
label: __( 'Heading' ),
|
||||
onChange: function(val) { setAttributes({heading: val}) },
|
||||
type: 'text'
|
||||
}),
|
||||
])
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
]);
|
||||
},
|
||||
|
||||
save: function(props) {
|
||||
const blockProps = useBlockProps.save({ className: 'mb-4' });
|
||||
return el('div', { ...blockProps }, [' ', el(RichText.Content, { tagName: 'h2', className: 'font-bold mb-4 text-2xl', value: propOrDefault( props.attributes.heading, 'heading' ) }), ' ', el('hr', { className: 'mb-4' }), ' ']);
|
||||
}
|
||||
|
||||
} );
|
||||
} )(
|
||||
window.wp.blocks,
|
||||
window.wp.element,
|
||||
window.wp.blockEditor
|
||||
);
|
22
blocks/sidebar-heading/sidebar-heading_register.php
Normal file
22
blocks/sidebar-heading/sidebar-heading_register.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
PG_Blocks_v2::register_block_type( array(
|
||||
'name' => 'leonpharmacy/sidebar-heading',
|
||||
'title' => __( 'Sidebar Heading', 'leonpharmacy' ),
|
||||
'category' => 'archive',
|
||||
'supports' => array('color' => array('background' => false,'text' => false,'gradients' => false,'link' => false,),'typography' => array('fontSize' => false,),'anchor' => false,'align' => false,),
|
||||
'base_url' => get_template_directory_uri(),
|
||||
'base_path' => get_template_directory(),
|
||||
'js_file' => 'blocks/sidebar-heading/sidebar-heading.js',
|
||||
'attributes' => array(
|
||||
'heading' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'Heading'
|
||||
)
|
||||
),
|
||||
'example' => array(
|
||||
'heading' => 'Heading'
|
||||
),
|
||||
'dynamic' => false,
|
||||
'version' => '1.5'
|
||||
) );
|
Reference in New Issue
Block a user