An open API service indexing awesome lists of open source software.

https://github.com/daviddarnes/share-button

A Web Component to share web pages using the native OS sharing options
https://github.com/daviddarnes/share-button

component components customelement customelements webcomponent webcomponents

Last synced: 12 months ago
JSON representation

A Web Component to share web pages using the native OS sharing options

Awesome Lists containing this project

README

          

# `share-button`

A Web Component to share web pages using the native OS sharing options.

**[Demo](https://daviddarnes.github.io/share-button/demo.html)** | **[Further reading](https://darn.es/share-button-web-component/)**

## Examples

General usage example:

```html

Share

```

Example using a fallback links:

```html

Share

Post to Twitter


Post to Facebook


Post to LinkedIn

share-button:not(:defined) button,
share-button:defined a {
display: none;
}
share-button:not(:defined) a + a {
margin-inline-start: 1ch;
}

```

Example using a fallback `readonly` input:

```html

Share

Share this page

share-button:not(:defined) button,
share-button:defined label {
display: none;
}

```

## Features

This Web Component allows you to:

- Use a standard `button` element to show the native OS sharing options to share the current web page

## Installation

You have a few options (choose one of these):

1. Install via [npm](https://www.npmjs.com/package/@daviddarnes/share-button): `npm install @daviddarnes/share-button`
1. [Download the source manually from GitHub](https://github.com/daviddarnes/share-button/releases) into your project.
1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)

### Usage

Make sure you include the `` in your project (choose one of these):

```html
<!-- Host yourself -->
<script type="module" src="share-button.js">
```

```html

```

```html

```

## Credit

With thanks to the following people:

- [Zach Leatherman](https://zachleat.com) for inspiring this [Web Component repo template](https://github.com/daviddarnes/component-template)