npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-share-popup

v1.0.0

Published

Quickly create a social share popup with Vue.

Downloads

39

Readme

vue-share-popup

This is an useful tool about social network sharing based on Vue and popper.js, you can easily create a social share popup in your project.

This project is inspired by need-more-share2.

Screenshot

Screenshot

Usage

I've used vue-demi to support both Vue 2 and Vue 3, if you're using Vue 2, please make sure you're using Vue 2.7.

Then you need to install this package:

npm install vue-share-popup
# or
yarn add vue-share-popup
# or
pnpm install vue-share-popup

The project finally exported an API called useSharePopup, you can use it to create a popup in your project, see more details in the reference section.

If you want to join our developement and make this project further, note that we're using pnpm in this project, please be sure you've installed it globally.

Examples

In src/demo, we provide some examples which shows how to use this package.

For someone who want to use this package outside Vue, you should take a look at src/demo/demo.html (The bundle version build already packed a Vue 3 to run the popup).

Here's a basic example when you import this package by ESM:

import { useSharePopup } from 'vue-share-popup';
import { qzone, weibo } from 'vue-share-popup/platform';

const share = ref(null); // bind to an element in template

useSharePopup({
  key: 'share',
  platforms: [qzone, weibo],
  meta: {
    title: 'vue-share-button',
    url: 'https://pwp.app',
  },
  ref: share.value,
  trigger: 'hover',
  placement: 'bottom',
});

Reference

useSharePopup

useSharePopup (props: SharePopupProps) => void

Create a social share popup.

SharePopupProps

key

key: string (Optional)

If useSharePopup was called multiple times with a same key, method will check if there's an existed popup, if so, method will unmount it first to avoid redundant.

platforms

platforms: SocialPlatformComp[]

The platforms you want to display in the share popup, buttons will be displayed in the same order as your configured.

The SocialPlatformComp can be imported from vue-share-popup/platforms, supported names contains qzone, wechat, weibo, douban, twitter.

meta

meta: ShareProps

Metadata of the current page used for social sharing, see ShareProps part for more details.

ref

ref: HTMLElement

An HTML element used as a popup trigger and position reference.

trigger

trigger: 'hover' | 'click'

Determine how the popup will be triggered.

placement

placement: string

Available values:

'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end'

Determine where should the popup layer be placed to the reference.

IMPORTANT: This property is provided by @popperjs/core, we used preventOverflow and flip modifiers when creating the popper, so in some cases your placement may seems not work properly, it's normal.

zIndex

zIndex: number (Optional)

If set, it will be the z-index style for the popup.

ShareProps

Metainfo of the page that will be shared.

The metadata required varies for different social platforms, on some platforms, some metadata will not be used for sharing.

url

url: string

The URL of the page that will be shared.

title

title: string

The title of the page that will be shared.

desc

desc: string (Optional)

The description (or summary) of the page that will be shared.

image

image: string (Optional)

An image URL for sharing.

options

Options for share popup, see SharePopupOptions part for more details.

SharePopupOptions

Options for share popup.

wechatSharePage

If you want to add wechat to the platforms array in the SharePopupProps, you need set this property neccessarily.

The value should be a URL, it will determine the page which will guide user to share something in wechat.

Example: https://YOUR_SHARE_PAGE/index.html?url={url}&title={title}

If you don't want to develope a wechat share page, you can take a look at this project:

wechat-share-page

License

MIT