diff --git a/block-filters/button/index.php b/block-filters/button/index.php new file mode 100644 index 00000000..66869cda --- /dev/null +++ b/block-filters/button/index.php @@ -0,0 +1,36 @@ + { unregisterBlockStyle('core/button', ['fill', 'outline']); }); diff --git a/blocks/button/block.json b/blocks/button/block.json new file mode 100644 index 00000000..35134481 --- /dev/null +++ b/blocks/button/block.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "wp-newsletter-builder/button", + "version": "0.1.0", + "title": "Newsletter Button", + "allowedBlocks": ["core/button"], + "category": "design", + "icon": "button", + "description": "Button wrapper that provides email-friendly enhancements", + "textdomain": "button", + "editorScript": "file:index.ts", + "editorStyle": "file:index.css", + "style": [ + "file:style-index.css" + ], + "render": "file:render.php", + "attributes": { + "textColor": { + "type": "string", + "default": "#fff" + }, + "bgColor": { + "type": "string", + "default": "#0279af" + }, + "radius": { + "type": "string", + "default": "0" + }, + "btnWidth": { + "type": "string", + "default": "max-content" + } + } +} diff --git a/blocks/button/edit.tsx b/blocks/button/edit.tsx new file mode 100644 index 00000000..e642884a --- /dev/null +++ b/blocks/button/edit.tsx @@ -0,0 +1,91 @@ +import { useEffect } from 'react'; +import { __ } from '@wordpress/i18n'; +import { useBlockProps, InspectorControls, InnerBlocks } from '@wordpress/block-editor'; +import { ColorPicker, PanelBody } from '@wordpress/components'; +import useInnerBlockAttributes from '@/hooks/useInnerBlocksAttributes'; + +/** + * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. + * Those files can contain any CSS code that gets applied to the editor. + * + * @see https://www.npmjs.com/package/@wordpress/scripts#using-css + */ +// Uncomment this line if you want to import a CSS file for this block. +// import './index.scss'; + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +interface EditProps { + attributes: { + bgColor?: string; + btnWidth?: string, + radius?: string, + textColor?: string, + }; + setAttributes: (attributes: {}) => void; + clientId: string, +} + +export default function Edit({ + attributes: { + bgColor = '#0279af', + btnWidth = 'max-content', + radius = '0', + textColor = '#fff', + }, + setAttributes, + clientId, +}: EditProps) { + const TEMPLATE = [['core/button']]; + const innerBlockAttributes = useInnerBlockAttributes(clientId); + const innerBorderRadius = innerBlockAttributes[0]?.style?.border?.radius || '0'; + const innerWidth = innerBlockAttributes[0]?.width; + const buttonStyles = { + backgroundColor: bgColor, + borderRadius: radius, + color: textColor, + margin: '0 auto', + width: btnWidth, + }; + + useEffect(() => { + setAttributes({ + radius: innerBorderRadius, + btnWidth: innerWidth !== undefined ? `${innerWidth}%` : 'max-content', + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [innerBorderRadius, innerWidth]); + + return ( + <> + + +

{__('Background color', 'wp-newsletter-builder')}

+ {/* Using ColorPicker instead of ColorPalette to ensure email-friendly values. */} + setAttributes({ bgColor: color })} + /> +

{__('Text color', 'wp-newsletter-builder')}

+ setAttributes({ textColor: color })} + /> +
+
+
+ +
+ + ); +} diff --git a/blocks/button/index.php b/blocks/button/index.php new file mode 100644 index 00000000..78ee2fc9 --- /dev/null +++ b/blocks/button/index.php @@ -0,0 +1,21 @@ + { + const blockProps = useBlockProps.save(); + return ( +
+ {/* @ts-ignore */} + +
+ ); + }, + title: metadata.title, + }, +); diff --git a/blocks/button/render.php b/blocks/button/render.php new file mode 100644 index 00000000..245dfebf --- /dev/null +++ b/blocks/button/render.php @@ -0,0 +1,20 @@ +. + * @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. + * + * @package wp-newsletter-builder + */ + +$wp_newsletter_builder_button_color = $attributes['textColor'] ?? ''; +$wp_newsletter_builder_button_bg_color = $attributes['bgColor'] ?? ''; +$wp_newsletter_builder_button_radius = $attributes['radius'] ?? ''; +$wp_newsletter_builder_button_width = $attributes['btnWidth'] ?? ''; +?> + +
+ +
diff --git a/blocks/post-read-more/edit.tsx b/blocks/post-read-more/edit.tsx index 2998127b..1398d993 100644 --- a/blocks/post-read-more/edit.tsx +++ b/blocks/post-read-more/edit.tsx @@ -32,7 +32,7 @@ export default function Edit({
setAttributes({ readMoreText: value })} /> diff --git a/blocks/post-read-more/render.php b/blocks/post-read-more/render.php index 34ff2a23..8b02396a 100644 --- a/blocks/post-read-more/render.php +++ b/blocks/post-read-more/render.php @@ -27,7 +27,7 @@
- +