GithubHelp home page GithubHelp logo

dawidkostyszak / react-share Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nygardk/react-share

0.0 2.0 0.0 5.61 MB

Easy social media share buttons and share counts

License: MIT License

JavaScript 100.00%

react-share's Introduction

react-share

npm version Download Count

Easy social media share buttons and share counts.

Share buttons and counts example

Features

  • no external script loading, i.e. no dependencies on SDKs
  • opens a popup share-window
  • share buttons for:
    • Facebook
    • Twitter
    • Telegram
    • Google+
    • Whatsapp
    • LinkedIn
    • Pinterest
    • VK
    • Odnoklassniki
    • Reddit
  • share counts for
    • Facebook
    • Google+
    • Linkedin
    • Pinterest
    • VK
    • Odnoklassniki
    • Reddit
  • social media icons included in the library
  • supports also custom icons

Demo

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

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, 0.14.x and 15.x.x.

API

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

Share buttons

const {
  FacebookShareButton,
  GooglePlusShareButton,
  LinkedinShareButton,
  TwitterShareButton,
  TelegramShareButton,
  WhatsappShareButton,
  PinterestShareButton,
  VKShareButton,
  OKShareButton,
  RedditShareButton,
} = ShareButtons;
Share button props
Required props Optional props
All children: A React node (e.g. string or element)
url: URL of the shared page (string)
disabled: Disables click action and adds disabled class (bool)
disabledStyle: Style when button is disabled (object, default = { opacity: 0.6 })
windowWidth, windowHeight: opened window dimensions (int, different defaults for all share buttons)
beforeOnClick: Takes a function that returns a Promise to be fulfilled before calling onClick. If you do not return promise, onClick is called immediately.
FacebookShareButton - title: Title of the shared page (string)
description: Description of the shared page (string)
picture: An absolute link to the image that will be shared (string)
GooglePlusShareButton - -
LinkedinShareButton - title: Title of the shared page (string)
description: Description of the shared page (string)
TwitterShareButton - title: Title of the shared page (string)
via: (string)
hashtags: (array)
TelegramShareButton - title: Title of the shared page (string)
WhatsappShareButton - title: Title of the shared page (string)
separator: Separates title from the url, default: " " (string)
PinterestShareButton media: An absolute link to the image that will be pinned (string) description: Description for the shared media.
VKShareButton - title: Title of the shared page (string)
description: Description of the shared page (string)
image: An absolute link to the image that will be shared (string)
OKShareButton - title: Title of the shared page (string)
description: Description of the shared page (string)
image: An absolute link to the image that will be shared (string)
RedditShareButton - title: Title of the shared page (string)

Share counts

const {
  FacebookShareCount,
  GooglePlusShareCount,
  LinkedinShareCount,
  PinterestShareCount,
  VKShareCount,
  OKShareCount,
  RedditShareCount,
} = ShareCounts;

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

Example:

<FacebookShareCount 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:

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

Icons

const FacebookIcon = generateShareIcon('facebook');
const TwitterIcon = generateShareIcon('twitter');
const TelegramIcon = generateShareIcon('telegram');
const WhatsappIcon = generateShareIcon('whatsapp');
const GooglePlusIcon = generateShareIcon('google');
const LinkedinIcon = generateShareIcon('linkedin');
const PinterestIcon = generateShareIcon('pinterest');
const VKIcon = generateShareIcon('vk');
const OKIcon = generateShareIcon('ok');
const RedditIcon = generateShareIcon('reddit');

Props:

  • size: Icon size in pixels (number)

  • round: Whether to show round or rect icons (bool)

  • iconBgStyle: customize background style, e.g. fill (object)

  • logoFillColor: customize logo's fill color (string, default = 'white')

Example:

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

License

MIT

Icons

Icon paths provided by: react-social-icons.

react-share's People

Contributors

nygardk avatar r0nd avatar vorontsovmaxim avatar watbe avatar yinglinchen avatar efernandesng avatar larsfinleypar avatar geloescht avatar zallek avatar renchap avatar thg303 avatar dlwalsh avatar ex0ns avatar juhaelee avatar

Watchers

James Cloos avatar Dawid Kostyszak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.