Skip to content

Commit cc01a54

Browse files
Social: Replace ConnectionIcon component with the implementation of ConnectionImage component (#45972)
* Social: Replace ConnectionIcon component with the implementation of ConnectionImage component. * Fix story import
1 parent fb5707c commit cc01a54

File tree

8 files changed

+58
-167
lines changed

8 files changed

+58
-167
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Social: Replace ConnectionIcon component with the implementation of ConnectionImage component.

projects/js-packages/publicize-components/src/components/connection-icon/index.jsx

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { SocialServiceIcon } from '@automattic/jetpack-components';
2+
import { useCallback, useState } from '@wordpress/element';
3+
import clsx from 'clsx';
4+
import styles from './styles.module.scss';
5+
6+
export type ConnectionIconProps = {
7+
serviceName: string;
8+
label: string;
9+
profilePicture: string;
10+
disabled?: boolean;
11+
};
12+
13+
/**
14+
* The component to render a social media connection icon.
15+
* @param {ConnectionIconProps} props - Component props.
16+
* @return React element
17+
*/
18+
export function ConnectionIcon( {
19+
label,
20+
serviceName,
21+
profilePicture,
22+
disabled,
23+
}: ConnectionIconProps ) {
24+
const [ imageErrorFor, setImageErrorFor ] = useState( null );
25+
26+
const onError = useCallback( () => setImageErrorFor( profilePicture ), [ profilePicture ] );
27+
28+
const hasDisplayPicture = !! profilePicture && imageErrorFor !== profilePicture;
29+
30+
const service_name = (
31+
'instagram-business' === serviceName ? 'instagram' : serviceName
32+
) as React.ComponentProps< typeof SocialServiceIcon >[ 'serviceName' ];
33+
34+
return (
35+
<div
36+
className={ clsx( styles.wrapper, {
37+
[ styles[ 'has-picture' ] ]: hasDisplayPicture,
38+
[ styles.disabled ]: disabled,
39+
} ) }
40+
>
41+
{ hasDisplayPicture && <img src={ profilePicture } alt={ label } onError={ onError } /> }
42+
<SocialServiceIcon serviceName={ service_name } className={ styles[ 'social-icon' ] } />
43+
</div>
44+
);
45+
}
46+
47+
export default ConnectionIcon;

projects/js-packages/publicize-components/src/components/connection-icon/stories/index.stories.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ConnectionIcon from '../index.jsx';
1+
import ConnectionIcon from '../index.tsx';
22
import '../../../../../social-logos/src/social-logo-colors.css';
33

44
export default {
@@ -12,7 +12,7 @@ export default {
1212
options: [
1313
'facebook',
1414
'x',
15-
'instagram',
15+
'instagram-business',
1616
'linkedin',
1717
'nextdoor',
1818
'tumblr',
@@ -29,7 +29,6 @@ export const _default = Template.bind( {} );
2929
_default.args = {
3030
serviceName: 'tumblr',
3131
label: 'Jetpack Social',
32-
checked: true,
3332
profilePicture:
3433
'https://gravatar.com/avatar/5a5f21e099ba62ae525e62cd1ad859985c8170b8811431e7fa6ccbc9da22405b',
3534
};

projects/js-packages/publicize-components/src/components/connection-icon/style.scss

Lines changed: 0 additions & 47 deletions
This file was deleted.

projects/js-packages/publicize-components/src/components/connection-image/index.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

projects/js-packages/publicize-components/src/components/connections-toggle-list/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormToggle, MenuGroup, MenuItem } from '@wordpress/components';
33
import { useCallback } from 'react';
44
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
55
import { Connection } from '../../social-store/types';
6-
import { ConnectionImage } from '../connection-image';
6+
import { ConnectionIcon } from '../connection-icon';
77
import { useConnectionState } from '../form/use-connection-state';
88
import styles from './styles.module.scss';
99

@@ -55,10 +55,10 @@ export function ConnectionsToggleList() {
5555
className={ styles.item }
5656
>
5757
<div className={ styles[ 'item-content' ] }>
58-
<ConnectionImage
59-
service_name={ connection.service_name }
60-
display_name={ connection.display_name }
61-
profile_picture={ connection.profile_picture }
58+
<ConnectionIcon
59+
serviceName={ connection.service_name }
60+
label={ connection.display_name }
61+
profilePicture={ connection.profile_picture }
6262
disabled={ isDisabled }
6363
/>
6464
<div className={ styles[ 'display-name' ] } title={ connection.display_name }>

0 commit comments

Comments
 (0)