Giter Site home page Giter Site logo

peterpeterparker / web-social-share Goto Github PK

View Code? Open in Web Editor NEW
75.0 3.0 19.0 1.13 MB

A Web Component to share url and text on social networks

Home Page: http://websocialshare.com

License: MIT License

TypeScript 21.92% HTML 70.91% SCSS 7.03% JavaScript 0.14%
webcomponent stencil social social-network share social-share facebook twitter email linkedin

web-social-share's Introduction

Web Social Share

Web Social Share is a Web Component to share urls and text.

version npm

Table of contents

Goals

The idea behind this web component was to add a "social share" feature to Progressive Web Apps (pwa).

Nowadays, the Web Share API is supported by most recent mobile OS.

Even though, it may remain interesting to use such a component for the desktop version of web apps.

Features

The component present a dialog which contains the sharing options you selected.

Following providers or targets are currently supported:

Installation

$ npm install web-social-share

Integration

This Web Component is developed with Stencil.

The Stencil documentation provide examples of Javascript and framework integration for Angular, React, Vue and Ember.

NodeJS

You can either import the class directly or the defineCustomElement helper to register the web component to the CustomElementRegistry:

import { WebSocialShare, defineCustomElement } 'web-social-share';

With that you can extend the component, e.g.:

class WebSocialExtended extends WebSocialShare {
  render () {
    // custom render behavior
  }
}

or just register it to the CustomElementRegistry and use it in your application, e.g.:

defineCustomElement()

Getting Started

The Web Social Share Component can be use like following:

<web-social-share show={true} share={options}></web-social-share>

Both show and share are mandatory.

show

Trigger the display, or close, of the action sheet which contains the social-share options.

show is a boolean parameter

share

For details about them you could have a look to the interface WebSocialShareInput located under folder src/types/web-social-share/.

share is a property of type WebSocialShareInput.

Note: share is an object. Therefore, it has to be parsed with JavaScript if you use the component in a vanilla Javascript application.

Example

For example, if you would like to allow your users to share a website through Facebook and Twitter, you could define basic options like following:

const share = {
    config: [{
          facebook: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
        },{
          twitter: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
    }]
};

If you would like to display the action default name, you could extend your configuration using the attribute displayNames like the following:

const share = {
    displayNames: true,
    config: [{
          facebook: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
        },{
          twitter: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
    }]
};

Worth to notice, you could also provide your own custom brand name, for example in case you would translate the word Email, for example:

const share = {
    displayNames: true,
    config: [{
          email: {
            brandName: 'E-Mail-Adresse',
            socialShareTo: '[email protected]',
            socialShareBody: 'https://peterpeterparker.io'
          }
    }]
};

Slots

Slots have to be used to display the icon or text for your actions.

The available slots are: facebook, twitter, pinterest, linkedin, reddit, email, copy, hackernews, whatsapp and telegram.

These are sorted according the order of your configuration.

NOTE: Slot names MUST be lower case.

<web-social-share show="false">
    <i class="fab fa-reddit" slot="reddit" style="color: #cee3f8;"></ion-icon>
</web-social-share>

const share = [{
    reddit: {
      socialShareUrl: 'https://peterpeterparker.io'
    }
  }
}];

Note that you may have to add the style="display: block" on the slotted elements, notably if you would use <ion-icon/>, for them to be shown.

Styling your icons

The style of your icons is up to you and have to be applied on the icons provided as slots.

For example:

<web-social-share show="false">
    <i class="fab fa-twitter" slot="twitter" style="color: #00aced; width: 1.4rem;"></i>
</web-social-share>

Theming

Checkout the auto-generated readme.md for the list of customizable CSS variables.

Events

The component trigger an event closed when the modal is close. It is emitted regardless if the user shared or not aka "just" closed it.

@Event() closed<void>();

Typically, this use case can be used to post process the data you pass to the component. For example, I use a store to handle these and listen to the event to clean it afterwards.

Fallback and detection

This component is a dumb component. It does not proceed detection or fallback to anything in case one of the share options would not be supported by the device or browser where the component is used.

For example, the share options "Copy (to clipboard)" use the Web Api Clipboard.writeText() which might not be supported. Anyway the action will be displayed and if used by the user, nothing will happen.

Web Share API

When I develop web apps I generally develop a mixed solution between Web Share API and this component. If the Web Share API is supported, and maybe sometimes in combination to detecting desktop or mobile, I use the browser API. If not supported, I fallback on this component.

If interested to implement such a solution, check out the blog post I published about it

Showcase

A showcase is available at https://websocialshare.com

The above showcase is the www folder of this project deployed in Firebase. If you clone the repository you could run it locally using npm run start.

Credits

I didn't want to reinvent the wheel when it comes to the sharing actions themselves. Therefore, I forked the features of angular-socialshare. Kudos to 45kb ๐Ÿ‘

License

MIT ยฉ David Dal Busco

web-social-share's People

Contributors

adamdbradley avatar christian-bromann avatar dellos7 avatar elebetsamer avatar fmendoza avatar genebustam avatar harshabonthu avatar jgw96 avatar kensodemann avatar mlynch avatar nxtexe avatar peterennis avatar peterpeterparker avatar siemato avatar thescientist13 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

web-social-share's Issues

Problem using slotted icons using ionic 4

Hi there,

I followed the instructions for Ionic 4 but still I can't get the ionicons show correctly. Any advice?

Code:

public webSocialShare: { show: boolean, config: any, onClosed: any } = {
    show: false,
    config: [{
      facebook: {
        socialShareUrl: 'https://fluster.io',
        socialSharePopupWidth: 300,
        socialSharePopupHeight: 500
      }
    },{
      twitter: {
        socialShareUrl: 'https://fluster.io',
        socialSharePopupWidth: 300,
        socialSharePopupHeight: 500
      }
    }],
    onClosed: () => {
      this.webSocialShare.show = false;
    }
};

Template:

<web-social-share
    (closed)="webSocialShare.onClosed()"
    [show]="webSocialShare.show"
    [share]="webSocialShare.config">
    <ion-icon name="logo-facebook" slot="facebook"></ion-icon>
    <ion-icon name="logo-twitter" slot="twitter"></ion-icon>
</web-social-share>

Failed to load web-social-share.js after update package.json

I think there's an issue with the way of importing this package in Ionic 4.

I can replicate this problem following these steps:

  1. Update web-social-share version on package.json
  2. Push changes to Netlify
  3. App breaks with white screen and an error is logged in console.

Thoughts?

captura de pantalla 2019-02-05 a la s 11 57 43

Integrate from stenciljs app doesn't work like a normal stenciljs component

Hi there, thanks for this cool component,

Unfortunately it doesn't work if integrated from within a pure stenciljs app.

It gives:

TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 1
Declaration or statement expected.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 13
';' expected.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 8
Cannot find name 'type'.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 14
Cannot find name 'Components'.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 14
Left side of comma operator is unused and has no side effects.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 26
Cannot find name 'JSX'.
~dev-server:7 TypeScript ./node_modules\web-social-share\dist\types\interface.d.ts, line 1, column 31
Cannot find name 'from'.

I simply import the component with :

import 'web-social-share'

Move slots not compatible with Font Awesome CSS

The fact that slots are move by the component from parent (web-social-share) to children (web-social-share-target) is not compatible with Font Awesome CSS

Doing so, CSS style from Font Awesome won't be applied and therefore no icons are going to be displayed

Possible solution:

  • Refactor: get rid of web-social-share-target and don't move slots
  • Breaking change: ask users to use web-social-share-target to include slots

=> Refactor

Was "Instagram" explored as option?

I'm submitting a ... (check one with "x")
[ ] bug report
[X] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior:
There is no Instagram as option to share to

Expected behavior:
There is Instagram as option?

The plugin is real awesome UX, I was wondering if you explored adding Instagram to it?
I suspect I know the answer - Instagram 3rd party dev APIs do not support user friendly sharing path potentially, but still curious if you had explores this?

Use full height of the page

If the page has a scroll height, the web-social-share should use the all space, not just the top visible part

Icons not being shown

Hello @peterpeterparker,

I just can't get to show the icons. I'm trying to use the webcomponent in an Ionic/Angular app.

That's how I see the popup:

image

Code:

  <web-social-share style="--web-social-share-height: 140px;" [show]="false" [share]="webSocialShareOptions" (closed)="close()" id="wss-{{ index + 1 }}">
      <ion-icon name="logo-facebook" style="font-size:48px" slot="facebook"></ion-icon>
    <ion-icon name="logo-twitter" style="font-size:48px" slot="twitter"></ion-icon>
  </web-social-share>
this.webSocialShareOptions = {
  displayNames: true,
  config: [{
    facebook: {
      socialShareUrl: 'https://fluster.io'
    }
  },{
    twitter: {
      socialShareUrl: 'https://fluster.io'
    }
  }]
};

Was trying the solutions at #10 but I just can't get it working.

Thank you.

David.

Sending text message along with socialShareUrl.

How to send text message which had been already handled by web share API.
navigator.share({ text: 'How to implement the Web Share API and a fallback', url: shareUrl, });

And It's very helpful if you provide the list of attributes for services in config.
for example: brandName, socialShareUrl, socialShareBody, socialSharePopupWidth, ..etc

๐Ÿค”

FontAwesome Icons not appearing

I used the example:

<i class="fab fa-twitter" slot="twitter" style="color: #00aced; width: 1.4rem;"></i>

To show a twitter icon but I wasn't getting anything to display. So I installed the Angular FontAwesome package (https://www.npmjs.com/package/@fortawesome/angular-fontawesome) and attempted this:

<web-social-share [show]="show" [share]="options">
  <fa-icon [icon]="faTwitter" slot="twitter"></fa-icon>
</web-social-share>
...
import { faTwitter } from '@fortawesome/free-brands-svg-icons';
...
  options = {
    config: [{
          facebook: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
        },{
          twitter: {
            socialShareUrl: 'https://peterpeterparker.io'
          }
    }]
  };
  show = true;

  faTwitter = faTwitter;

Nothing is displaying. I think I'm missing a step.

ESM entry points in package.json resolve to an empty file

Was just testing this out and was debugging why nothing was showing up on the screen, but without any errors and it looks like the ESM / module entry point in package.json ultimately leads to an empty file?

  1. package.json defines a module field (and other fields) that point to a dist/index.js
  2. dist/index.js references file /dist/esm/index.js
  3. /dist/esm/index.js is an empty file ๐Ÿ˜ข

Screen Shot 2021-12-03 at 8 26 10 PM

Screen Shot 2021-12-03 at 8 47 51 PM

Looking forward to giving this a try! โœŒ๏ธ


Somewhat related, but the formal standard to wrangling all these fields is the new export map spec. Might be a nice way to clean all those up, since only main is a standard as far as NodeJS is concerned.

Material-UI React Icons not appearing

I am using Material-UI library in react to supply icons to slots for web-social-share. The share component shows up when I set show={true} prop. But my icons don't appear. Also I'm not able to override any of the styling. The buttons seem to have an outline to them. Help. ๐Ÿฅบ
Screenshot_745

Dynamic socialShareUrl

Is it possible to set a different URL? I have a list of products and I want to be able to share them individually.

Add pseudo slots to the social share actions

Adding <slot/> to each social share actions would let developers pass more complex styling or elements to the share actions than just styling with css, like for example passing an Ionic icon

As the component isn't shadowed, the slots are mostly use as selector

Shadow dom

Currently this Web Component isn't shadowed. As I spend several times developing such components recently I'm thinking about migrating this Web Component to a shadowed one.

Reason is also that I noticed yesterday some problems when a none shadowed components would be use in other shadowed components.

Finally, as recently <slot/> have been added, these could become the main way to inject actions icon.

Probably something I could develop when I'll implement it DeckDeckGo deckgo/starter-kit#30

Queryselector error on some old browser versions

Hello team,
Getting below js error on old chrome version browser, while clicking on any social share buttons and while clicking outside to hide the popup.

Uncaught TypeError: Cannot read property 'querySelector' of null e.hide @p-luoh4y63.system.entry.js:1

It seems those older version browser doesnt contain shadowRoot element which cause this issue.
Please check.

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.