File size: 3,010 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
import clsx from 'clsx';
import photon from 'photon';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import SocialLogo from 'calypso/components/social-logo';
import { gaRecordEvent } from 'calypso/lib/analytics/ga';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import getCurrentRouteParameterized from 'calypso/state/selectors/get-current-route-parameterized';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
class SharingButtonsPreviewButton extends Component {
static propTypes = {
button: PropTypes.object.isRequired,
style: PropTypes.oneOf( [ 'icon-text', 'icon', 'text', 'official' ] ),
enabled: PropTypes.bool,
onMouseOver: PropTypes.func,
onClick: PropTypes.func,
path: PropTypes.string,
};
static defaultProps = {
style: 'icon',
enabled: true,
onClick: function () {},
};
/* eslint-disable wpcalypso/jsx-classname-namespace */
getIcon() {
const shortnameToSocialLogo = {
email: 'mail',
'google-plus-1': 'google-plus-alt',
pinterest: 'pinterest-alt',
tumblr: 'tumblr-alt',
'jetpack-whatsapp': 'whatsapp',
'press-this': 'wordpress',
twitter: 'x',
more: 'share',
};
if ( ! this.props.button.custom ) {
const icon = shortnameToSocialLogo[ this.props.button.ID ] || this.props.button.shortname;
return <SocialLogo icon={ icon } size={ 18 } />;
} else if ( 'string' === typeof this.props.button.icon ) {
return (
<span
className="sharing-buttons-preview-button__custom-icon"
style={ {
backgroundImage: 'url(' + photon( this.props.button.icon, { width: 16 } ) + ')',
} }
/>
);
}
}
/* eslint-enable wpcalypso/jsx-classname-namespace */
onClick = () => {
recordTracksEvent( 'calypso_sharing_buttons_share_button_click', {
service: this.props.button.ID,
enabled: ! this.props.enabled, // during onClick enabled is the old state, so negating gives the new state
path: this.props.path,
} );
gaRecordEvent( 'Sharing', 'Clicked Share Button', this.props.button.ID );
this.props.onClick();
};
/* eslint-disable wpcalypso/jsx-classname-namespace */
render() {
const classes = clsx(
'sharing-buttons-preview-button',
'style-' + this.props.style,
'share-' + this.props.button.ID,
{
'is-enabled': this.props.enabled,
'is-custom': this.props.button.custom,
}
);
return (
<div
className={ classes }
onClick={ this.onClick }
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
onMouseOver={ this.props.onMouseOver }
role="presentation"
>
{ this.getIcon() }
<span className="sharing-buttons-preview-button__service">{ this.props.button.name }</span>
</div>
);
}
/* eslint-enable wpcalypso/jsx-classname-namespace */
}
export default connect(
( state ) => ( {
path: getCurrentRouteParameterized( state, getSelectedSiteId( state ) ),
} ),
null,
null,
{ forwardRef: true }
)( SharingButtonsPreviewButton );
|