Skip to content

Commit

Permalink
Add placeholder components when no links specified
Browse files Browse the repository at this point in the history
Improve the default experience for social links when no links are
specified. This uses the new placeholder prop in InnerBlocks and
BlockList.
  • Loading branch information
mkaz committed Oct 8, 2020
1 parent 2cd975b commit 74bac8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,18 @@ import { __ } from '@wordpress/i18n';

const ALLOWED_BLOCKS = [ 'core/social-link' ];

// Template contains the links that show when start.
const TEMPLATE = [
[
'core/social-link',
{ service: 'wordpress', url: 'https://wordpress.org' },
],
[ 'core/social-link', { service: 'facebook' } ],
[ 'core/social-link', { service: 'twitter' } ],
[ 'core/social-link', { service: 'instagram' } ],
[ 'core/social-link', { service: 'linkedin' } ],
[ 'core/social-link', { service: 'youtube' } ],
];

export function SocialLinksEdit( props ) {
const {
attributes: { openInNewTab },
setAttributes,
} = props;

const SocialPlaceholder = (
<div className="wp-block-social-links__social-placeholder">
Use [+] to add icons.
</div>
);

const blockProps = useBlockProps();
return (
<Fragment>
Expand All @@ -49,8 +43,8 @@ export function SocialLinksEdit( props ) {
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
templateLock={ false }
template={ TEMPLATE }
orientation="horizontal"
placeholder={ SocialPlaceholder }
__experimentalTagName="ul"
__experimentalPassedProps={ blockProps }
__experimentalAppenderTagName="li"
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/social-links/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
.editor-styles-wrapper .wp-block-social-links {
padding: 0;
}
.wp-block-social-links__social-placeholder {
background-color: #aaa;
border-radius: 8px;
margin: 8px;
padding: 4px;
font-size: 13px;
}

// Polish the Appender.
.wp-block-social-links .block-list-appender {
Expand Down

0 comments on commit 74bac8b

Please sign in to comment.