Skip to content

Commit

Permalink
docs(share-button): update readme with CDN and fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Dec 22, 2024
1 parent c4025d8 commit 118b131
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
32 changes: 28 additions & 4 deletions packages/share-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ npm install --save @parsonic/share-button
## Usage

The share button can be used with your favourite bundler or directly
from a CDN. Minified builds for the browser are supplied in the [`dist`
directory](`https://cdn.jsdelivr.net/npm/@parsonic/share-button@latest/dist/index.js`)
from a CDN. Minified builds for the browser are supplied in the
[`dist` directory][dist]

### Quick start

Add the script tag and use the button in your page.

```html
<script
defer
type="module"
src="https://cdn.jsdelivr.net/npm/@parsonic/share-button@latest/+esm"
src="https://cdn.jsdelivr.net/npm/@parsonic/share-button@latest/dist/index.js"
></script>
<share-button data-button-label="Share this page"></share-button>
```
Expand All @@ -31,7 +32,7 @@ Add the script tag and use the button in your page.
Import the component at the root of your application and register it.

```js
import ShareButton from '@parsonic/share-button'
import ShareButton from '@parsonic/share-button/ShareButton.js'

ShareButton.register()

Expand Down Expand Up @@ -140,5 +141,28 @@ document.addEventListener('share', (ev) => {
})
```

## Fallback content

Fallback content can be provided if for some reason the native share
function isn't available or the scripts aren't loaded. Please see this
[blog post][blog-post] for thorough explanation of using fallback content.

```html
<share-button>
<button popovertarget="fallback">Share</button>

<div popover id="fallback">
<h2>Share this post</h2>

<div>
<label>Page URL</label>
<input value="{{ post.url }}" readonly />
</div>
</div>
</share-button>
```

[share]: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
[open-graph]: https://ogp.me/
[dist]: https://cdn.jsdelivr.net/npm/@parsonic/[email protected]/dist/
[blog-post]: https://philparsons.co.uk/blog/dont-fouc-up-your-web-components/
3 changes: 2 additions & 1 deletion stories/ShareButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export const Custom = {
export const CDN = {
render: () => `
<script
defer
type="module"
src="https://cdn.jsdelivr.net/npm/@parsonic/share-button@latest/+esm"
src="https://cdn.jsdelivr.net/npm/@parsonic/share-button@latest/dist/index.js"
></script>
<share-button data-button-label="Share this page"></share-button>
`,
Expand Down

0 comments on commit 118b131

Please sign in to comment.