Share Sheet
Share a link anywhere: copy it, send it to email or a network, scan it as a QR code, or hand it to the device’s own share sheet.
c2-share-sheet is the share dialog of Notion, Figma and YouTube. It shows the link with a copy button, a row of targets (email, X, LinkedIn, Facebook, WhatsApp, …) and an optional QR code. Where the device has its own share sheet, a “More” target hands the link to it. It opens as a c2-sheet, from the bottom by default.
Import
import '@c2n/components/share-sheet'Usage
What is shared
url is what is shared, heading names it in the heading (“Share “Trip to Lisbon””) and as the subject or title where a target takes one, and text goes with the link where a target takes text. Only an http(s) link is offered: for anything else the sheet stays empty, with no target and nothing to copy.
Targets
targets picks them, ;-separated, in order: email, sms, x, linkedin, facebook, whatsapp, telegram and reddit (default email;x;linkedin;facebook;whatsapp). Copying the link is always there. Each target is a link to that service’s share page, with every part encoded, opened in a new tab without a referrer (mail and text messages hand over to the device’s app). qr adds a QR code of the link.
The targets show the network’s initial on a neutral tile: no trademarked logo is drawn. An app with licensed artwork puts it in the target’s slot (<img slot="icon-linkedin" …>).
Opening it
share() is what a Share button calls: it opens the device’s own share sheet (navigator.share) where there is one, and this sheet otherwise. show() always opens this sheet, close() closes it, and open reflects its state; open and close events follow.
Events
Every target fires a cancelable share event with { target, url } before it opens, and copying fires one with target copy. Cancel the event to handle a target yourself, or just listen to count shares:
sheet.addEventListener('share', (event) => analytics.track('share', { target: event.detail.target }))