Skip to content

Commit

Permalink
WIP: Social Link: group all variations under one block type
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Jan 24, 2020
1 parent d11009e commit 134c2be
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 259 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
[
__experimentalEnableLegacyWidgetBlock ? legacyWidget : null,
socialLinks,
...socialLink.sites,
socialLink,

// Register Full Site Editing Blocks.
...( __experimentalEnableFullSiteEditing ?
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const SocialLinkEdit = ( { attributes, setAttributes, isSelected } ) => {
);

// Import icon.
const IconComponent = getIconBySite( site );
const socialLinkName = getNameBySite( site );
const IconComponent = site ? getIconBySite( site ) : null;
const socialLinkName = site ? getNameBySite( site ) : '';

return (
<Fragment>
Expand All @@ -52,7 +52,7 @@ const SocialLinkEdit = ( { attributes, setAttributes, isSelected } ) => {
className={ classes }
onClick={ () => setPopover( true ) }
>
<IconComponent />
{ IconComponent && <IconComponent /> }
{ isSelected && showURLPopover && (
<URLPopover
onClose={ () => setPopover( false ) }
Expand Down
48 changes: 18 additions & 30 deletions packages/block-library/src/social-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,30 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import edit from './edit';
import socialList from './social-list';
import patterns from './patterns';

const commonAttributes = {
export const name = 'core/social-link';

export const settings = {
title: __( 'Social Icon' ),
category: 'widgets',
parent: [ 'core/social-links' ],
supports: {
reusable: false,
html: false,
},
edit,
description: __( 'Link to a social media profile' ),
attributes: {
url: {
type: 'string',
},
site: {
type: 'string',
},
label: {
type: 'string',
},
},
patterns,
};

// Create individual blocks out of each site in social-list.js
export const sites = Object.keys( socialList ).map(
( site ) => {
const siteParams = socialList[ site ];
return {
name: 'core/social-link-' + site,
settings: {
title: siteParams.name,
icon: siteParams.icon,
description: __( 'Link to ' + siteParams.name ),
...commonAttributes,
attributes: {
url: {
type: 'string',
},
site: {
type: 'string',
default: site,
},
label: {
type: 'string',
},
},
},
};
}
);
18 changes: 18 additions & 0 deletions packages/block-library/src/social-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ function register_block_core_social_link() {
)
);
}

register_block_type(
'core/social-link',
array(
'attributes' => array(
'url' => array(
'type' => 'string',
),
'site' => array(
'type' => 'string',
),
'label' => array(
'type' => 'string',
),
),
'render_callback' => 'render_core_social_link',
)
);
}
add_action( 'init', 'register_block_core_social_link' );

Expand Down
Loading

0 comments on commit 134c2be

Please sign in to comment.