Code Monkey home page Code Monkey logo

react-web-share's Introduction

react-web-share

Tiny Web Share API wrapper with fallback for unsupported browsers

GitHub Actions Status NPM gzip

Edit react-web-share

๐Ÿ’ก most browsers restricts web share api only to https websites

โœจ Features

  • ๐Ÿƒ Only ~6kb gzipped and no external dependencies
  • ๐ŸŒ€ Uses React Portal
  • โœŒ Written w/ TypeScript

๐Ÿ”ง Installation

npm i react-web-share    # npm
yarn add react-web-share # yarn

Preview

Mobile

Mobile Preview

Desktop

Desktop Preview

๐Ÿ“ฆ Example

import React, { useState } from "react";
import { RWebShare } from "react-web-share";

const Example = () => {
  return (
    <div>
      <RWebShare
        data={{
          text: "Like humans, flamingos make friends for life",
          url: "https://on.natgeo.com/2zHaNup",
          title: "Flamingos",
        }}
        onClick={() => console.log("shared successfully!")}
      >
        <button>Share ๐Ÿ”—</button>
      </RWebShare>
    </div>
  );
};

export default Example;

๐Ÿ‘€ Props

Prop Description Type Default
data Share Object {text, url, title} {text: "", url: currentURL, title: "Share"}
sites sites string[] all platforms (see list below for key list)
closeText translate close string localise close text
onClick callback on sucessful share
disableNative disables native share boolean false

๐ŸŒŽ Sites

  • facebook
  • twitter
  • whatsapp
  • reddit
  • telegram
  • linkedin
  • mail
  • copy (Copy to Clipboard)
  • vk
  • okru

๐Ÿ“œ License

MIT ยฉ harshzalavadiya

react-web-share's People

Contributors

harshzalavadiya avatar sanjaiyan-dev avatar sudhanshug16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-web-share's Issues

onClick callback not firing on mobile chrome

I'm using RWebShare in my nextjs app, but having an issue with the onClick callback - it fires on desktop browsers (chrome and firefox). On mobile it fires on Firefox, but doesn't seem to work on mobile chrome. It's a bit of an issue for me as the onClick callback sends some information to my database. Has anyone else had similar issue?

Fallback LinkedIn Addition

Hi,

Is it possible to add LinkedIn to the icon/list.tsx?

linkedin: {
path: (
<path d="M6.5 21.5h-5v-13h5v13zM4 6.5C2.5 6.5 1.5 5.3 1.5 4s1-2.4 2.5-2.4c1.6 0 2.5 1 2.6 2.5 0 1.4-1 2.5-2.6 2.5zm11.5 6c-1 0-2 1-2 2v7h-5v-13h5V10s1.6-1.5 4-1.5c3 0 5 2.2 5 6.3v6.7h-5v-7c0-1-1-2-2-2z" />
),
color: "#0073b1",
e: (l, t) => window.open(`https://www.linkedin.com/shareArticle?mini=true&url=${l}&title=${t}&summary=${t}&source=${l}`)
}

Link copied feedback and some styling customisation would be sweet!

Hey this is really nice.

A few suggestions

  • When using the link copy button, it would be really nice to get a little bit of feedback rather than the dialog just disappearing suddenly
  • It would be nice to get a styling API, right now I've had to use !important to override the styling for the UI. Let me know if there's a better way
  • Just a nitpick with the component name - it's a bit odd to have the React in the name abbreviated to R, kind of non standard. I would simply change it to import { ReactWebShare } from 'react-web-share' or make it a default export.

No big deal either way, this is really helpful!

Not working on mobile share

It doesn't open share for mobile and even with desktop share, it keeps me an error (TypeError: cannot read property 'writetext' of undefined), all this in localhost...

Share screen on dialog box?

Customize the close button text

Hello ๐Ÿ‘‹ !

I wanted to know if there is any possibility to get a props (eg: closeTitle) attached to RWebShare component for customizing the close button text ?

Thx in advance for your answer ! ๐Ÿ˜‰

Copy functionality not working as expected

Describe the bug
Copy functionality shows different behavior in desktop/mobile
On desktop it copies only the link.
On mobile app it copies data+link

Expected behavior
The copy functionality should copy data+link in desktop too

instagram

You can add Instagram or I can help you. Thank you

Issue in sharing the link on facebook

I basically created the dynamically generated page which opens through url in next-app
And the problem is that when I sharing the url on FaceBook through react-web-share it is not work properly, but when with same url is share on WhatsApp and Twitter then it works properly.
I am not getting the solution regarding issue, so please help me for this issue.

Encoded URI while using `navigator.share`

Hey, firstly thanks for the amazing package.

I noticed that the url that I pass to the component via data prop is actually URL encoded.
https://github.com/harshzalavadiya/react-web-share/blob/0b3d5ef70c6719e1f7982f88435a14143a6af8af/src/index.tsx#L18 this is the code responsible for the same.

Correct me if I am wrong, there shouldn't be a need to encode the url here. And in fact the package should assume that the URL provided by the user is correct. If not, then it is user's fault.

For example:

I passed this

url: `${window.location.origin}/view`

and the URI for the navigator.share came out in this format

<current_pathname>/encoded(<origin>/view)

Missing URL encoding for Links with parameters by sharing on Facebook and Whatsapp

For instance I would like to share this url https://canitravel.net/countries/?from=176&passport=176
as you can see there are from and passport as parameters in the above link

on whatsapp the request made would be

https://api.whatsapp.com/send?text=https://canitravel.net/countries/?from=176&passport=176

which results in https://canitravel.net/countries/?from=176, missing the passport parameter

I think it would be only a matter of encoding the url in the text parameter of the request to whatsapp.

What do you think, would it be possible?

Thanks,

Super nice component by the way!

Add instagram

Hey, great package thank you for making this available!

I see instagram isn't one of the available sharing options though, do you think it's simple to add it? I need ig sharing in my platform, let me know if you plan on doing that soon or if I need to switch to another sharing tool.

Best regards

Issues in production on mobile browsers

Describe the bug
After building for production, the RWebshare component doesn't work on mobile browsers (it works on mobile browsers using development server). Only the original web share API works, and the RWebshare UI doesn't render, or the onClick callback does not fire.

I am using Nextjs, so perhaps its an issue with the build.

I really need to onClick callback in my app, so this is causing me quite a headache.

Sandbox / Git Repo
Here is a repo that works fine in local development, but not on mobile browsers in production:
https://github.com/strangecarr/ts-nextjs-tailwind-starter.git
https://web-share-de

Also, see web browser screencast of the webshare component in local dev vs production:

Development server (working - the onClick callback fires an alert popup)
https://user-images.githubusercontent.com/52605713/213854889-93ace864-bbb3-4185-9bfb-6eebd19cf96a.mp4

Production (not working):
https://user-images.githubusercontent.com/52605713/213854813-e427d3b6-689e-42c9-a5f3-b46e8e837275.mp4

use site in onclick callback function

Is it possible to feed in the site that the url has been shared to into the onclick callback function? e.g. so its possible to record which sites (facebook, whatsapp, email etc) are being used?

"option" property is actually "sites"

Hey @harshzalavadiya, Thank you for this amazing package. I'm very happy to be able to use it.
I just wanted to flag that the "option" prop described in the readme is actually "sites".

For example

<div className="share-button-container">
  <RWebShare
    data={{
      text: "texte",
      url: window.location.href,
      title: "title",
    }}
    sites={["facebook", "whatsapp", "mail", "copy"]}
  >
    <button className="share-button">Share the message</button>
  </RWebShare>
</div>

Also, I was wondering if there was a way to custom the style of the fallback? I'd like to change the colors and the icons but I'm not sure what's the best way to proceed...

Again, thank you very much for your work.

Have a nice one!

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.