├── LICENSE
├── README.md
├── demo.html
├── package.json
└── webcare-webshare.js
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2024 Zach Leatherman
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `` Web Component
2 |
3 | A web component that uses the [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API) to share a web site, falling back (on Desktop usually) to Copy to Clipboard.
4 |
5 | * [Demo](https://zachleat.github.io/webcare-webshare/demo.html)
6 | * In use on the registration flow for [`conf.11ty.dev`](https://conf.11ty.dev/).
7 | * [Blog post](https://www.zachleat.com/web/webcare-webshare/)
8 | * Inspired by [_How to let the user share the website they are on_—Thomas Steiner (web.dev)](https://web.dev/patterns/web-apps/share/)
9 |
10 |
11 |
12 | ## Features
13 |
14 | * Defaults to copy URL when Web Share API is not available.
15 | * Optionally override with your own copy-able content.
16 | * Custom button text when Web Share API is not available.
17 |
18 | ## Installation
19 |
20 | You can install via `npm` ([`@zachleat/webcare-webshare`](https://www.npmjs.com/package/@zachleat/webcare-webshare)) or download the `webcare-webshare.js` JavaScript file manually.
21 |
22 | ```shell
23 | npm install @zachleat/webcare-webshare --save
24 | ```
25 |
26 | Add `webcare-webshare.js` to your site’s JavaScript assets.
27 |
28 | ## Usage
29 |
30 | Use `share-text` and `share-url` per the [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API). The button is un-disabled when initialized.
31 |
32 | ```html
33 |
34 |
35 |
36 | ```
37 |
38 | ### Custom button text when Web Share API not available.
39 |
40 | _Copy to clipboard_ workflow only. Use the `label-copy` (Before) and `label-after-copy` (After) attributes.
41 |
42 | ```html
43 |
44 |
45 |
46 | ```
47 |
48 | ### Set custom share content for copying.
49 |
50 | _Copy to clipboard_ workflow only. Use `copy-text` to override `share-url` as the default content that is copied when using Copy to Clipboard.
51 |
52 | ```html
53 |
54 |
55 |
56 | ```
57 |
58 |
--------------------------------------------------------------------------------
/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | <webcare-webshare> Web Component
8 |
21 |
22 |
23 |
24 |
25 |