Socket
Socket
Sign inDemoInstall

web-social-share

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    web-social-share

A Web Component for your PWA to share urls and content on social networks


Version published
Weekly downloads
1.7K
increased by7.14%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

5.0.0 (2019-02-17)

Breaking changes

  • transform component to a shadowed Web Component (#14)

Notes:

As of version v5.0.0 this Web Component will be shadowed. Therefore, you will have to use slots to inject the icons for the sharing actions and will have to style these in order to apply for example the proper colors. The README of the component has been updated to reflect these changes.

If you would miss variables to style the component, ping me, I would be happy to add more options.

<a name="4.0.2"></a>

Readme

Source

Web Social Share

Web Social Share is a Web Component for your PWA to share urls and content on social networks.

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

GitHub npm

Table of contents

Goals

The idea behind this web component was to add a "social share" feature to the progressive web app (pwa) version of my project Fluster.

Furthermore, I thought that using and building an action sheet to do so would be user friendly.

This Web Component is developed with Stencil.

Installation

$ npm install web-social-share

Integration in a Ionic v4 project

Once the library installed, proceed then with following steps to integrate the component:

  1. In the module where you would like to use the component, import and add CUSTOM_ELEMENTS_SCHEMA to your list of schemas

     @NgModule({
         declarations: [
             MyPage
         ],
         imports: [
             CommonModule,
             FormsModule,
             IonicModule,
             RouterModule.forChild(routes)
         ],
         schemas: [CUSTOM_ELEMENTS_SCHEMA]
     })
     export class MyPageModule {
     }
     
    
  2. In index.html import the component. As far as I understood, web component built with Stencil inherit Lazy Loading, therefore, no worries about effect on your boot time

      <script async src="websocialshare.js"></script>
      
    
  3. Finally add the following to your assets configuration in your angular.json files in oder to include the component in your bundle

    "assets": [
        {
          "glob": "websocialshare.js",
          "input": "node_modules/web-social-share/dist",
          "output": "./"
        },
        {
          "glob": "websocialshare/*",
          "input": "node_modules/web-social-share/dist",
          "output": "./"
        }
    ]
    

Other frameworks integration

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

Getting Started

The Web Social Share Component could be use like following:

<web-social-share [show]="true" [share]="options" (closed)="close()"></web-social-share>

Both show and share are mandatory.

show

Trigger the display or closing of the action sheet presenting the social-share options you have selected.

show is a boolean parameter

share

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

share is a parameter of type WebSocialShareInput

Example

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

const share = {
    config: [{
          facebook: {
            socialShareUrl: 'https://fluster.io'
          }
        },{
          twitter: {
            socialShareUrl: 'https://fluster.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://fluster.io'
          }
        },{
          twitter: {
            socialShareUrl: 'https://fluster.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: 'me@outlook.com',
            socialShareBody: 'https://fluster.io'
          }
    }]
};
Vanilla JS

For an example of Vanilla JS use, you could have a look to the index.html demo located in this repo under folder src.

Slots

Slots has to be used to inject the icons for your actions in the component.

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

<web-social-share show="false">
    <ion-icon name="logo-reddit" slot="reddit"></ion-icon>
</web-social-share>

const share = [{
    reddit: {
      socialShareUrl: 'https://fluster.io',
      socialSharePopupWidth: 300,
      socialSharePopupHeight: 500
    }
  }
}];
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

The following CSS variables are exposed by the component:

CSS4 variableDefaultNote
--web-social-share-backdrop-opacity0.25Backdrop opacity
--web-social-share-backdrop-backgroundblackBackdrop background
--web-social-share-height80pxAction sheet height
--web-social-share-height-small-device140pxAction sheet height on device smaller than 540px
--web-social-share-target-width4remAn action container width
--web-social-share-target-height3remAn action container height
--web-social-share-button-width100%An action inner button width
--web-social-share-button-height100%An action inner button height
--web-social-share-target-icon-container-height2remAn action icon container height
--web-social-share-button-font-sizeThe font-size of an action button
--web-social-share-brand-font-size0.6remThe font-size of an action brand name
--web-social-share-brand-colorinheritThe color of an action brand name

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 wanted to reinvent the wheel when it comes to the sharing actions themselves. Therefore I forked the features of angular-socialshare. Kudos to 45kb :+1:

License

MIT © David Dal Busco

Keywords

FAQs

Last updated on 17 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc