File size: 1,816 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import { FormToggle, BaseControl } from '@wordpress/components';
import clsx from 'clsx';
import SocialLogo from 'calypso/components/social-logo';
import cssSafeUrl from 'calypso/lib/css-safe-url';
function serviceToIconName( service ) {
switch ( service ) {
case 'google_plus':
return 'google-plus';
case 'instagram-business':
return 'instagram';
default:
return service;
}
}
function hasRoundIcon( service ) {
return [ 'facebook', 'nextdoor' ].includes( service );
}
const PostShareConnection = ( { connection, isActive, onToggle } ) => {
const { external_display, external_profile_picture, ID, service, status } = connection;
const toggle = () => onToggle( ID );
const classes = clsx( {
'post-share__service': true,
[ service ]: true,
'is-active': isActive,
'is-broken': status === 'broken',
} );
const id = `post-share__label-${ ID }`;
const accountImageStyle = {};
if ( external_profile_picture ) {
accountImageStyle.backgroundImage = 'url( ' + cssSafeUrl( external_profile_picture ) + ' )';
} else {
accountImageStyle.backgroundColor = 'rgb( 168, 190, 206 )';
}
return (
<div onClick={ toggle } className={ classes } role="presentation">
<div className="post-share__service-account-image" style={ accountImageStyle }>
</div>
<div
className={ clsx( 'post-share__service-account-social-logo', {
'is-round': hasRoundIcon( service ),
} ) }
>
<SocialLogo icon={ serviceToIconName( service ) } />
</div>
<div className="post-share__service-account-name">
<label id={ id }>{ external_display }</label>
</div>
<BaseControl className={ clsx( 'components-toggle-control' ) }>
<FormToggle checked={ isActive } aria-describedby={ id } />
</BaseControl>
</div>
);
};
export default PostShareConnection;
|