Skip to content
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

Full Site Editing: Add experimental SiteDescription block #18241

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create a SiteDescription block similar to SiteTitle
  • Loading branch information
Copons committed Nov 6, 2019
commit 18efe0b884c839f29ed77262ae5fd2ab39db6759
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $z-layers: (
".wp-block-cover.has-background-dim::before": 1, // Overlay area inside block cover need to be higher than the video background.
".wp-block-cover__video-background": 0, // Video background inside cover block.
".wp-block-site-title__save-button": 1,
".wp-block-site-description__save-button": 1,

// Active pill button
".components-button.is-button {:focus or .is-primary}": 1,
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@import "./verse/editor.scss";
@import "./video/editor.scss";
@import "./site-title/editor.scss";
@import "./site-description/editor.scss";

/**
* Import styles from internal editor components used by the blocks.
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import * as socialLink from './social-link';

// Full Site Editing Blocks
import * as siteTitle from './site-title';
import * as siteDescription from './site-description';

/**
* Function to register an individual block.
Expand Down Expand Up @@ -182,7 +183,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
...socialLink.sites,

// Register Full Site Editing Blocks.
...( __experimentalEnableFullSiteEditing ? [ siteTitle ] : [] ),
...( __experimentalEnableFullSiteEditing ? [ siteTitle, siteDescription ] : [] ),
].forEach( registerBlock );
} :
undefined;
39 changes: 39 additions & 0 deletions packages/block-library/src/site-description/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "core/site-description",
"category": "layout",
"supports": {
"align": [ "wide", "full" ],
"html": false,
"multiple": false,
"reusable": false
},
"attributes": {
"align": {
"type": "string",
"default": "wide"
},
"textAlign": {
"type": "string",
"default": "center"
},
"textColor": {
"type": "string"
},
"customTextColor": {
"type": "string"
},
"backgroundColor": {
"type": "string"
},
"customBackgroundColor": {
"type": "string"
},
"fontSize": {
"type": "string",
"default": "small"
},
"customFontSize": {
"type": "number"
}
}
}
65 changes: 65 additions & 0 deletions packages/block-library/src/site-description/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* WordPress dependencies
*/
import {
useEntityProp,
__experimentalUseEntitySaving,
} from '@wordpress/core-data';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { PlainText } from '@wordpress/block-editor';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { ENTER } from '@wordpress/keycodes';

function SiteDescriptionEdit( { insertDefaultBlock } ) {
const [ description, setDescription ] = useEntityProp( 'root', 'site', 'description' );
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
'root',
'site',
'description'
);

const preventNewlines = ( event ) => {
if ( event.keyCode === ENTER ) {
event.preventDefault();
insertDefaultBlock();
}
};

return (
<>
<Button
isPrimary
className="wp-block-site-description__save-button"
disabled={ ! isDirty || ! description }
isBusy={ isSaving }
onClick={ save }
>
{ __( 'Update' ) }
</Button>
<PlainText
placeholder={ __( 'Site Description' ) }
value={ description }
onChange={ setDescription }
isStylable
onKeyDown={ preventNewlines }
/>
</>
);
}

export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockIndex, getBlockRootClientId } = select( 'core/block-editor' );
const rootClientId = getBlockRootClientId( clientId );
return {
blockIndex: getBlockIndex( clientId, rootClientId ),
rootClientId,
};
} ),
withDispatch( ( dispatch, { blockIndex, rootClientId } ) => ( {
insertDefaultBlock: () =>
dispatch( 'core/block-editor' ).insertDefaultBlock( undefined, rootClientId, blockIndex + 1 ),
} ) ),
] )( SiteDescriptionEdit );
6 changes: 6 additions & 0 deletions packages/block-library/src/site-description/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.wp-block-site-description__save-button {
position: absolute;
right: 0;
top: 0;
z-index: z-index(".wp-block-site-description__save-button");
}
11 changes: 11 additions & 0 deletions packages/block-library/src/site-description/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* WordPress dependencies
*/
import { SVG, Path } from '@wordpress/components';

export default (
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<Path fill="none" d="M0 0h24v24H0z" />
<Path d="M4 9h16v2H4V9zm0 4h10v2H4v-2z" />
</SVG>
);
20 changes: 20 additions & 0 deletions packages/block-library/src/site-description/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

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

const { name } = metadata;
export { metadata, name };

export const settings = {
title: __( 'Site Description' ),
icon,
edit,
};