Skip to content

Full Site Editing: Update the Content Slot block #32529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 29, 2019
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable wpcalypso/jsx-classname-namespace */
/**
* External dependencies
*/
import classNames from 'classnames';
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { IconButton, Placeholder, Toolbar } from '@wordpress/components';
import { withState } from '@wordpress/compose';
import { BlockControls } from '@wordpress/editor';
import { Fragment, RawHTML } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import PostAutocomplete from '../../components/post-autocomplete';

const ContentSlotEdit = withState( {
isEditing: false,
selectedPost: null,
} )( ( { attributes, isEditing, selectedPost, setState } ) => {
const { align } = attributes;

const toggleEditing = () => setState( { isEditing: ! isEditing } );

const onSelectPost = post => {
setState( { isEditing: false, selectedPost: post } );
};

const showToggleButton = ! isEditing || !! selectedPost;
const showPlaceholder = isEditing || ! selectedPost;
const showPreview = ! isEditing && !! selectedPost;

return (
<Fragment>
{ showToggleButton && (
<BlockControls>
<Toolbar>
<IconButton
className={ classNames( 'components-icon-button components-toolbar__control', {
'is-active': isEditing,
} ) }
label={ __( 'Change Preview' ) }
onClick={ toggleEditing }
icon="edit"
/>
</Toolbar>
</BlockControls>
) }
<div
className={ classNames( 'a8c-content-slot-block', {
[ `align${ align }` ]: align,
} ) }
>
{ showPlaceholder && (
<Placeholder
icon="layout"
label={ __( 'Content Slot' ) }
instructions={ __( 'Placeholder for a post or a page.' ) }
>
<div className="a8c-content-slot-block__selector">
<div>{ __( 'Select something to preview:' ) }</div>
<PostAutocomplete
selectedPostTitle={ get( selectedPost, 'title.rendered' ) }
onSelectPost={ onSelectPost }
/>
{ !! selectedPost && (
<a href={ `?post=${ selectedPost.id }&action=edit` }>{ __( 'Edit' ) }</a>
) }
</div>
</Placeholder>
) }
{ showPreview && (
<RawHTML className="a8c-content-slot-block__preview">
{ get( selectedPost, 'content.rendered' ) }
</RawHTML>
) }
</div>
</Fragment>
);
} );

export default ContentSlotEdit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import edit from './edit';
import './style.scss';

registerBlockType( 'a8c/content-slot', {
title: __( 'Content Slot' ),
description: __( 'Placeholder for a post or a page.' ),
icon: 'layout',
category: 'layout',
supports: {
align: [ 'wide', 'full' ],
anchor: true,
html: false,
multiple: false,
reusable: false,
},
edit,
save: () => null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at a later point in time or even now I think it's worth spitting some output here.
this is somewhat high-level and not a priority at this point, but one of our guiding principles is being part of the open web. I would love to see some fallback message here for the case where a post is viewed purely as HTML without WordPress the PHP engine rendering it.

could we think of a simple message to report that would convey "this is the spot where a post would normally show, but this page is being viewed without the necessary software so you get this instead 😄 "

} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

function render_content_slot_block( $attributes, $content ) {
$align = isset( $attributes['align'] ) ? ' align' . $attributes['align'] : '';

$content = '<div class="a8c-content'. $align . '">'
. __( '[Renders some content]' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. ha. see my above comment in the static render fallback. note that while we are free to render this here, we can also send that into the editor, and even have both. but if we have the static fallback render this isn't entirely necessary.

. '</div>';

return $content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.a8c-content-slot-block.alignfull {
padding: 0 12px;
}

.a8c-content-slot-block__selector {
width: 300px;
a {
font-family: sans-serif;
font-size: 13px;
padding-left: 8px;
}
}

.a8c-content-slot-block__preview {
pointer-events: none;
&::after {
content: '';
clear: both;
display: table;
}
}

This file was deleted.

This file was deleted.

Loading