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
- Host: GitHub
- URL: https://github.com/daviddarnes/share-button
- Owner: daviddarnes
- License: mit
- Created: 2023-12-11T14:38:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-18T17:12:49.000Z (almost 2 years ago)
- Last Synced: 2025-04-12T02:05:22.088Z (12 months ago)
- Topics: component, components, customelement, customelements, webcomponent, webcomponents
- Language: HTML
- Homepage: https://daviddarnes.github.io/share-button/demo.html
- Size: 21.5 KB
- Stars: 91
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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)