Zach’s ugly mug (his face) Zach Leat­herman

<webcare-webshare> Web Component

Two small hands play with colorful wooden blocks
463 00 February 20, 2024
🚾Web Component@zachleat/webcare-webshare

Web component to use the Web Share API, with a fallback to copy to the clipboard.

2.3%
Versions
4 versions in
1.0.3
Audit
0 reports
0 deps
Issues
1
PRs
0

<webcare-webshare> is a web component that uses the Web Share API to share a web site, falling back (on desktop usually) to a copy to clipboard workflow.

Used on the registration flow for conf.11ty.dev.

Features

  • Defaults to copy URL when Web Share API is not available.
  • Optionally override with your own copy-able content.
  • Custom button text when Web Share API is not available.

Installation

You can install via npm (@zachleat/webcare-webshare) or download the webcare-webshare.js JavaScript file manually.

npm install @zachleat/webcare-webshare --save

Add webcare-webshare.js to your site’s JavaScript assets.

Usage

Use share-text and share-url per the Web Share API. The button is un-disabled when initialized.

<webcare-webshare share-text="I am going to the 11ty Conference! #11ty #11tyConf" share-url="https://conf.11ty.dev/">
	<button disabled>Share your ticket!</button>
</webcare-webshare>

Custom button text

Copy to clipboard workflow only. Use the label-copy (Before) and label-after-copy (After) attributes.

<webcare-webshare share-text="I am going to the 11ty Conference! #11ty #11tyConf" share-url="https://conf.11ty.dev/" label-copy="📋 Copy your ticket URL" label-after-copy="✅ Copied to Clipboard">
	<button disabled>Share your ticket!</button>
</webcare-webshare>

Set custom share content

Copy to clipboard workflow only. Use copy-text to override share-url as the default content that is copied when using Copy to Clipboard.

<webcare-webshare share-text="I am going to the 11ty Conference! #11ty #11tyConf" share-url="https://conf.11ty.dev/" copy-text="Go to https://conf.11ty.dev/">
	<button disabled>Share your ticket!</button>
</webcare-webshare>

IndieWeb Avatar for https://unsplash.com/Poster image by Michał Bożek

< Older
throbber Web Component
Newer >
hypercard Web Component

Zach Leatherman IndieWeb Avatar for https://zachleat.com/is a builder for the web at Font Awesome and the creator of Build Awesome (née IndieWeb Avatar for https://www.11ty.devEleventy/11ty), an award-winning open source website generator. He measures website performance with speedlify and at one point became too fixated on web fonts. He has given 89 talks in nine different countries at events like Beyond Tellerrand, Smashing Conference, Jamstack Conf, CSSConf, and The White House. Formerly part of CloudCannon, Netlify, Filament Group, NEJS CONF, and NebraskaJS. Learn more about Zach »

Shamelessly plug your related post

These are webmentions via the IndieWeb and webmention.io.

Sharing on social media?

This is what will show up when you share this post on Social Media:

How did you do this? I automated my Open Graph images. (Peer behind the curtain at the test page)