-adisagar2003-react-share-on-social

中文文档
1.0.9发布于 2022/11/02MITTypeScriptESM + CJS

Native sharing using the Web Share API if supported, a beautiful fallback if not.

原始使用文档
文档目录10 节
  1. Demo
  2. Features
  3. Installation
  4. Usage
  5. Required props
  6. Optional props
  7. Supported socials
  8. What is the difference between react-share-on-social and re…
  9. Contribute
  10. License

react-share-on-social

:smiling_face_with_three_hearts::stuck_out_tongue_winking_eye::money_mouth_face::sunglasses::partying_face:

Native sharing if supported, beautiful fallback if not.

A ~8kb package for effortless social media sharing, originally forked from react-web-share.

npm bundle size Maintenance npm NPM
Enhanced with ❤︎ by Karl Sellergren, originally built by Harsh Zalavadiya.

react-share-on-social fallback preview

Features

Installation

npm install react-share-on-social

or, if you're using yarn:

yarn add react-share-on-social

Usage

Passing the linkFavicon prop drastically improves UX for devices that use the fallback. Without linkFavicon, the fallback renders a grey box instead.

Note: The Web Share API only works in secure contexts (HTTPS). Read more here.

import React from "react";
import ShareOnSocial from "react-share-on-social";
import favicon from "../assets/favicon.png";

const Example = () => {
  return (
    <ShareOnSocial
      textToShare="Check out this new wardrobe I just found from IKEA!"
      link="https://ikea.com/wardrobes/kalle"
      linkTitle="KALLE Wardorbe which chooses your clothes for you using AI - IKEA"
      linkMetaDesc="Stop going through the agony of choosing clothes that fit the weather and your mood."
      linkFavicon={favicon}
      noReferer
    >
      <button>Share this product</button>
    </ShareOnSocial>
  );
};

Required props

PropertyTypeDescription
textToSharestringThe text that appears in the post.
linkURLThe URL to share.
linkTitlestringThe link title which should correspond to the <title> tag.
linkMetaDescstringThe meta description of the link, should correspond to the <meta og:description> tag.
linkFaviconHTMLImageElementA small image which is shown in the header of th popup fallback.

Optional props

PropertyTypeDefaultDescription
shareToArray<string>["facebook", "twitter", ... , "email"]A list of all social media channels that should appear in the fallback.
noRefererbooleanfalseIf the social media buttons should have a noreferrer tag or not.
backdropColorstringrgba(0,0,0,0.4)The background color of the backdrop.
closeTextstringCloseThe label of the close button.
copyToClipboardTextstringCopy to clipboardThe label of the copy to clipboard button.
copySuccessTextstringCopiedThe label of the copy to clipboard button after a successful copy.
onSocialClick() => void() => nullA callback invoked when user clicks on any of the social media buttons in the fallback.

Supported socials

The supported props are passed in the sharing URL to each service, and will appear in the post draft. | Social media | Supported props |
| ----------- | ----------- | | Facebook | link | | Twitter | link, textToShare | | Whatsapp | link | | Reddit | link, textToShare | | LinkedIn | link, linkTitle, textToShare | | Pinterest | link | | Telegram | link, textToShare | | Email | link, textToShare |

What is the difference between react-share-on-social and react-web-share?

  • The fallback is more rich with a header and an improved copy-to-clipboard functionality

  • Props are restructured for better usability

  • Pinterest is supported

  • Social media services are opened in a minimal window instead of a new tab

Contribute

So you want to contribute? Good, the world needs more brave troopers like you. Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated by us and the community.

  • If you find a typo, bug or want to add a feature, create an issue or add a pull request with the code you want to add!

  • Regarding bugs, please make sure that your issue is:

    • Reproducible. Include steps to reproduce the problem.

    • Specific. Include as much detail as possible: which device you use, how you have interacted with the website, etc.

    • Scoped to a Single Bug. One bug per issue.

License

MIT

版本与发布记录

-adisagar2003-react-share-on-social 共发布 1 个版本,首次发布于 2022/11/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.9latest2022/11/024 年前

关于 -adisagar2003-react-share-on-social 的常见问题

-adisagar2003-react-share-on-social 是什么?

如果支持,使用Web共享API的本机共享,如果不支持,一个美丽的回退。

如何安装 -adisagar2003-react-share-on-social?

在项目目录运行 npm install -- -adisagar2003-react-share-on-social,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=17)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

-adisagar2003-react-share-on-social 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

-adisagar2003-react-share-on-social 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

-adisagar2003-react-share-on-social 可以商用吗?

-adisagar2003-react-share-on-social 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

-adisagar2003-react-share-on-social 还在维护吗?

最新版本 1.0.9 发布于 2022/11/02(4 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。