JSPM

  • Created
  • Published
  • Downloads 359954
  • Score
    100M100P100Q163804F
  • License MIT

Easy social media share buttons and share counts.

Package Exports

  • react-share

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-share) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-share

Easy social media share buttons and share counts.

Share buttons and counts example

New! Pinterest support added in 1.2.0.

Pinterest share buttons and count example

Features:

  • no external script loading, i.e. no dependencies on SDKs
  • opens a popup share-window
  • supported services: Facebook, Twitter, Google+, LinkedIn, Pinterest
  • share buttons with generated icons or custom icons of your choice
  • share counts

Demos:

To run demos: clone repo and run npm install && npm run run-demos and open http://localhost:8080.

Install

npm install react-share --save

Browser

ShareButtons work on all browsers.

ShareCounts works on all browsers, with the exception of Goolge Plus share count working only on IE11 and newer (XHR CORS problem).

Compatibility

Compatible with React versions 0.13.x and 0.14.x.

API

import {
  ShareButtons,
  ShareCounts,
  generateShareIcon
} from 'react-share';

Share buttons

const {
  FacebookShareButton,
  GooglePlusShareButton,
  LinkedinShareButton,
  TwitterShareButton,
  PinterestShareButton
} = ShareButtons;

Required props for all:

  • children: A React node (e.g. string or element)
  • url: URL of the shared page (string)

Required props for LinkedinShareButton, TwitterShareButton and FacebookShareButton:

  • title: Title of the shared page (string)

Required prop for PinterestShareButton:

  • media: An absolute link to the image that will be pinned (string)

Share counts

const {
  FacebookShareCount,
  GooglePlusShareCount,
  LinkedinShareCount,
  TwitterShareCount,
  PinterestShareCount
} = ShareCounts;

All share count components take in only one mandatory prop: url, which is the URL you are sharing. className prop is optional.

Example:

<TwitterShareCount url={shareUrl} />

If you want to render anything else but the count, you can provide a function as a child element that takes in shareCount as an argument and returns an element:

<TwitterShareCount url={shareUrl}>
  {shareCount => (
    <span className="myShareCountWrapper">{shareCount}</span>
  )}
</TwitterShareCount>

Icons

const FacebookIcon = generateShareIcon('facebook');
const TwitterIcon = generateShareIcon('twitter');
const GooglePlusIcon = generateShareIcon('google');
const LinkedinIcon = generateShareIcon('linkedin');
const PinterestIcon = generateShareIcon('pinterest');

Props:

  • size: Icon size in pixels (number)
  • round: Whether to show round or rect icons (bool)

Example:

<TwitterIcon size={32} round={true} />

License

MIT

Icons

Icon paths provided by: react-social-icons.