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

Switch Social Links to use LinkControl component #20740

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/block-library/src/social-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"service": {
"type": "string"
},
"opensInNewTab": {
"type": "boolean",
"default": false
},
"label": {
"type": "string"
}
Expand Down
26 changes: 18 additions & 8 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import classNames from 'classnames';
* WordPress dependencies
*/
import {
__experimentalLinkControl as LinkControl,
InspectorControls,
URLPopover,
URLInput,
} from '@wordpress/block-editor';
import { Fragment, useState } from '@wordpress/element';
import {
Expand All @@ -27,12 +27,17 @@ import { keyboardReturn } from '@wordpress/icons';
import { getIconBySite, getNameBySite } from './social-list';

const SocialLinkEdit = ( { attributes, setAttributes, isSelected } ) => {
const { url, service, label } = attributes;
const { url, label, opensInNewTab, service } = attributes;
const [ showURLPopover, setPopover ] = useState( false );
const classes = classNames( 'wp-social-link', 'wp-social-link-' + service, {
'wp-social-link__is-incomplete': ! url,
} );

const link = {
url,
opensInNewTab,
};

// Import icon.
const IconComponent = getIconBySite( service );
const socialLinkName = getNameBySite( service );
Expand Down Expand Up @@ -70,13 +75,18 @@ const SocialLinkEdit = ( { attributes, setAttributes, isSelected } ) => {
} }
>
<div className="block-editor-url-input">
<URLInput
value={ url }
onChange={ ( nextURL ) =>
setAttributes( { url: nextURL } )
<LinkControl
value={ link }
onChange={ ( {
url: newURL = '',
opensInNewTab: newOpensInNewTab,
} = {} ) =>
setAttributes( {
url: encodeURI( newURL ),
opensInNewTab: newOpensInNewTab,
} )
}
placeholder={ __( 'Enter address' ) }
disableSuggestions={ true }
showInitialSuggestions={ false }
/>
</div>
<Button
Expand Down
13 changes: 7 additions & 6 deletions packages/block-library/src/social-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
* @return string Rendered HTML of the referenced block.
*/
function render_block_core_social_link( $attributes ) {
$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
$url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
$label = ( isset( $attributes['label'] ) ) ?
$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
$url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
$opens_in_new_tab = ( isset( $attributes['opensInNewTab'] ) ) ? $attributes['opensInNewTab'] : false;
$label = ( isset( $attributes['label'] ) ) ?
$attributes['label'] :
/* translators: %s: Social Link service name */
sprintf( __( 'Link to %s' ), block_core_social_link_get_name( $service ) );
Expand All @@ -24,9 +25,9 @@ function render_block_core_social_link( $attributes ) {
if ( ! $url ) {
return '';
}

$icon = block_core_social_link_get_icon( $service );
return '<li class="wp-social-link wp-social-link-' . esc_attr( $service ) . '"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>';
$target = ( $opens_in_new_tab ) ? 'target="_new"' : '';
$icon = block_core_social_link_get_icon( $service );
return '<li class="wp-social-link wp-social-link-' . esc_attr( $service ) . '"><a href="' . esc_url( $url ) . '" ' . $target . ' aria-label="' . esc_attr( $label ) . '"> ' . $icon . '</a></li>';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "amazon"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "bandcamp"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "behance"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "chain"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "codepen"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "deviantart"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "dribbble"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "dropbox"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "etsy"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "facebook"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "feed"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "fivehundredpx"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "flickr"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "foursquare"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "github"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "goodreads"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "google"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "instagram"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "lastfm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "linkedin"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "mail"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "mastodon"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "medium"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "meetup"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "pinterest"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "pocket"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "reddit"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "skype"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "snapchat"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "soundcloud"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "spotify"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "tumblr"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "twitch"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "twitter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "vimeo"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "vk"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "wordpress"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/social-link",
"isValid": true,
"attributes": {
"opensInNewTab": false,
"url": "https://example.com/",
"service": "yelp"
},
Expand Down
Loading