Skip to content

Commit

Permalink
Merge pull request #133 from alleyinteractive/feature/LEDE-2613/two-u…
Browse files Browse the repository at this point in the history
…p-block-style-refactor

LEDE-2613 Refactor Post Two Up Block & Refine Text Styles
  • Loading branch information
cahdeemer authored May 31, 2024
2 parents 8b1ddad + 9c3c7f7 commit 56f3a0a
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 68 deletions.
17 changes: 17 additions & 0 deletions blocks/post-item/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wp-newsletter-builder/post-item",
"version": "0.1.0",
"title": "Newsletter Post Item",
"category": "design",
"icon": "editor-table",
"description": "Displays a post block inside a table cell.",
"textdomain": "wp-newsletter-builder",
"editorScript": "file:index.ts",
"editorStyle": "file:index.css",
"style": [
"file:style-index.css"
],
"render": "file:render.php"
}
47 changes: 47 additions & 0 deletions blocks/post-item/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* 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 the following line if styles are added.
// 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.
*/
const MY_TEMPLATE = [
['wp-newsletter-builder/post', {
showContent: false,
showExcerpt: false,
showByline: false,
showCta: false,
order: ['image', 'title', 'excerpt', 'content', 'byline'],
}],
];

export default function Edit() {
return (
<td {...useBlockProps()}>
<InnerBlocks
orientation="horizontal"
// @ts-ignore
template={MY_TEMPLATE}
templateLock="all"
/>
</td>
);
}
21 changes: 21 additions & 0 deletions blocks/post-item/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Block Name: Post Item.
*
* @package wp-newsletter-builder
*/

/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_item_block_init(): void {
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
);
}
add_action( 'init', 'wp_newsletter_builder_post_item_block_init' );
46 changes: 46 additions & 0 deletions blocks/post-item/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
// Uncomment the following line if styles are added.
// import './style.scss';

/**
* Internal dependencies
*/
import edit from './edit';
import metadata from './block.json';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType(
/* @ts-expect-error Provided types are inaccurate to the actual plugin API. */
metadata,
{
apiVersion: 2,
edit,
save: () => {
const blockProps = useBlockProps.save();
return (
<td {...blockProps}>
{/* @ts-ignore */}
<InnerBlocks.Content />
</td>
);
},
},
);
14 changes: 14 additions & 0 deletions blocks/post-item/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* All of the parameters passed to the function where this file is being required are accessible in this scope:
*
* @param array $attributes The array of attributes for this block.
* @param string $content Rendered block output. ie. <InnerBlocks.Content />.
* @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered.
*
* @package wp-newsletter-builder
*/

?>
<?php
echo $content ?? ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2 changes: 1 addition & 1 deletion blocks/post-title/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ a.post__title-link {
text-align: center;

&.post__title--small {
font-size: 24px;
font-size: 18px;
}
}
}
22 changes: 16 additions & 6 deletions blocks/post/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,22 @@ export default function Edit({
</div>
) : null}
{ postId || editPostType === 'nb_template' ? (
<InnerBlocks
// @ts-ignore
template={MY_TEMPLATE}
allowedBlocks={ALLOWED_BLOCKS}
templateLock={false}
/>
// Role='presentation' tells AT table is for layout only so table semantics are ignored.
<table role="presentation">
<tbody>
<tr>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
<td>
<InnerBlocks
// @ts-ignore
template={MY_TEMPLATE}
allowedBlocks={ALLOWED_BLOCKS}
templateLock={false}
/>
</td>
</tr>
</tbody>
</table>
) : null}
<InspectorControls>
{/* @ts-ignore */}
Expand Down
12 changes: 8 additions & 4 deletions blocks/post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ registerBlockType(
save: () => {
const blockProps = useBlockProps.save();
return (
<div {...blockProps}>
{/* @ts-ignore */}
<InnerBlocks.Content />
</div>
<table {...blockProps} role="presentation">
<tbody>
<tr>
{/* @ts-ignore */}
<InnerBlocks.Content />
</tr>
</tbody>
</table>
);
},
},
Expand Down
4 changes: 0 additions & 4 deletions blocks/post/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
margin: 20px auto;
}

.post__dek p {
margin: 20px;
}

.wp-block-button {
margin: 20px auto;
}
Expand Down
36 changes: 14 additions & 22 deletions blocks/two-up-post/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,23 @@ import './index.scss';
* @return {WPElement} Element to render.
*/
const MY_TEMPLATE = [
['wp-newsletter-builder/post', {
showContent: false,
showExcerpt: false,
showByline: false,
showCta: false,
order: ['image', 'title', 'excerpt', 'content', 'byline'],
}],
['wp-newsletter-builder/post', {
showContent: false,
showExcerpt: false,
showByline: false,
showCta: false,
order: ['image', 'title', 'excerpt', 'content', 'byline'],
}],
['wp-newsletter-builder/post-item', {}],
['wp-newsletter-builder/post-item', {}],
];

export default function Edit() {
return (
<div {...useBlockProps()}>
<InnerBlocks
orientation="horizontal"
// @ts-ignore
template={MY_TEMPLATE}
templateLock="all"
/>
</div>
<table {...useBlockProps()} role="presentation">
<tbody>
<tr>
<InnerBlocks
orientation="horizontal"
// @ts-ignore
template={MY_TEMPLATE}
templateLock="all"
/>
</tr>
</tbody>
</table>
);
}
18 changes: 0 additions & 18 deletions blocks/two-up-post/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,5 @@
> .block-editor-inner-blocks {
max-width: initial;
width: 100%;

.block-editor-block-list__layout {
display: flex;
}
}

div[data-title="Newsletter Single Post"] {
flex: 1 0 50%;

.block-editor-inner-blocks{
display: flex;

// stylelint-disable selector-max-compound-selectors
.block-editor-block-list__layout {
display: flex;
flex-direction: column;
}
}
}
}
12 changes: 8 additions & 4 deletions blocks/two-up-post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ registerBlockType(
save: () => {
const blockProps = useBlockProps.save();
return (
<div {...blockProps}>
{/* @ts-ignore */}
<InnerBlocks.Content />
</div>
<table {...blockProps} role="presentation">
<tbody>
<tr>
{/* @ts-ignore */}
<InnerBlocks.Content />
</tr>
</tbody>
</table>
);
},
},
Expand Down
15 changes: 9 additions & 6 deletions blocks/two-up-post/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@
*/

.wp-block-wp-newsletter-builder-two-up-post {
display: flex;
flex-direction: row;
max-width: 600px;
width: 100%;
margin: 20px 0;

td {
vertical-align: top;
}

div.wp-block-wp-newsletter-builder-post {
max-width: 300px;
padding: 0 10px;
width: 50%;

img {
height: auto;
max-width: 300px;
width: 100%;
}
}

h3 {
margin-top: 20px;
@media screen and (max-width: 480px) {
td {
display: block;
width: 100%;
}
}
}
2 changes: 2 additions & 0 deletions entries/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ import '@/scss/core-blocks/image.scss';
import '@/scss/core-blocks/paragraph.scss';
import '@/scss/core-blocks/button.scss';
import '@/scss/core-blocks/separator.scss';
import '@/scss/core-blocks/list.scss';
import '@/scss/core-blocks/typography.scss';
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Newsletter Builder
* Plugin URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Description: Interface to manage email newsletters
* Version: 0.3.14
* Version: 0.3.15
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Requires at least: 6.2
Expand Down
6 changes: 5 additions & 1 deletion scss/core-blocks/heading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ h6 {
font-family: Georgia, serif;
font-weight: bold;
line-height: 1.3;

span {
font-family: Georgia, serif;
}
}

h2 {
font-size: 26px;
font-size: 22px;
}

h3 {
Expand Down
7 changes: 6 additions & 1 deletion scss/core-blocks/list.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
li {
ul, ol {
font-family: Georgia, serif;
font-size: 16px;
line-height: 1.3;

span {
font-family: Georgia, serif;
}
}
4 changes: 4 additions & 0 deletions scss/core-blocks/paragraph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ p {
font-family: Georgia, serif;
font-size: 16px;
line-height: 1.33;

span {
font-family: Georgia, serif;
}
}
3 changes: 3 additions & 0 deletions scss/core-blocks/typography.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a, em, s, strong, sup, sub {
font-family: Georgia, serif;
}
Loading

0 comments on commit 56f3a0a

Please sign in to comment.