All Projects → philnash → web-share-wrapper

philnash / web-share-wrapper

Licence: MIT license
A web component that wraps other share elements to replace with a web share button where supported.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to web-share-wrapper

web-component
Lightweight library providing interface for building web components
Stars: ✭ 37 (+105.56%)
Mutual labels:  web-component, web-components
paper-countries
Select Dropdown with list of countries with flags and autocomplete
Stars: ✭ 16 (-11.11%)
Mutual labels:  web-component, web-components
share-menu
A complete and simple to use share menu.
Stars: ✭ 15 (-16.67%)
Mutual labels:  web-component, web-share
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (+22.22%)
Mutual labels:  web-component, web-components
Use Custom Element
Custom hook to bridge Custom Elements (Web Components) to React.
Stars: ✭ 77 (+327.78%)
Mutual labels:  web-component, web-components
Html Midi Player
🎹 Play and display MIDI files on the web
Stars: ✭ 158 (+777.78%)
Mutual labels:  web-component, web-components
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: ✭ 27 (+50%)
Mutual labels:  web-component, web-components
Paper Timezone
Polymer based timezone selection component
Stars: ✭ 19 (+5.56%)
Mutual labels:  web-component, web-components
Vaadin Charts
Vaadin Charts is a feature-rich interactive graph library that answers the data visualization needs of modern web applications
Stars: ✭ 47 (+161.11%)
Mutual labels:  web-component, web-components
Ion Phaser
A web component to use Phaser Framework with Angular, React, Vue, etc 🎮
Stars: ✭ 152 (+744.44%)
Mutual labels:  web-component, web-components
vaadin-board
Web Component for creating flexible responsive layouts and building nice looking dashboards.
Stars: ✭ 17 (-5.56%)
Mutual labels:  web-component, web-components
xlayers-lite
🦋 xLayers' viewer as a Web Component 🦋
Stars: ✭ 22 (+22.22%)
Mutual labels:  web-component
polymer-2-carousel
Codelab
Stars: ✭ 18 (+0%)
Mutual labels:  web-components
toggle-icon
toggle-icon is a custom element created with Polymer. It provides an extremely powerful and customizable switch that looks like a paper-icon-button.
Stars: ✭ 21 (+16.67%)
Mutual labels:  web-components
nuxeo-elements
Nuxeo web components
Stars: ✭ 23 (+27.78%)
Mutual labels:  web-components
drawer
A touch-enabled drawer component for the modern web.
Stars: ✭ 26 (+44.44%)
Mutual labels:  web-components
chat-window
A simple and flexible chat window for listing messages.
Stars: ✭ 27 (+50%)
Mutual labels:  web-components
inclusive-elements
Accessible, lightweight, unstyled implementations of common UI controls.
Stars: ✭ 17 (-5.56%)
Mutual labels:  web-components
nativeweb
🤳 Tiny library for simple web components. [1kB]
Stars: ✭ 93 (+416.67%)
Mutual labels:  web-components
g-emoji-element
Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.
Stars: ✭ 112 (+522.22%)
Mutual labels:  web-components

<web-share-wrapper>

Published on webcomponents.org

A custom element that can be used to wrap existing share buttons and replace them with a button that invokes the Web Share API.

For example, in supporting browsers the following HTML will show a plain <button> saying "Share". In browsers that don't support the Web Share API, the default link to share on Twitter will be displayed.

<web-share-wrapper>
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

How to use

The <web-share-wrapper> is a web component that you can use to enhance your website with the Web Share API. If the API is available, the component will replace its contents with a single share button or a template that you provide.

The component only activates if the Web Share API is available, otherwise it will just show it's contents.

Browser support

Currently the only browser that supports the Web Share API (Chrome on Android) also supports custom elements and templates. So this module works where it will work and will fallback to your original HTML where it doesn't.

Installation

Bower

You can install the component with bower.

bower install --save web-share-wrapper

npm

You can also install with npm.

npm install web-share-wrapper

Once installed, you can either use the minified version by referencing it from the dist directory.

<script src="./node_modules/web-share-wrapper/dist/web-share-wrapper.min.js"></script>

Or if you have a build step, you can require the module.

const WebShareWrapper = require('web-share-wrapper');

unpkg

If you want to use the component from the unpkg CDN then you can.

You can get the latest version using the bare URL. See more options on https://unpkg.com/.

<script src="https://unpkg.com/web-share-wrapper"></script>

Example

<web-share-wrapper>
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

If navigator.share is available, the contents of the <web-share-wrapper> will be replaced with a single <button> element, which when clicked will invoke the Web Share API.

Check out this page with more examples.

Attributes

You can set attributes to control the text on the share button and the text and URL that is shared. The available attributes are:

  • text: Sets the text on the share button.
  • template: An id for a <template> element. The component will find the template, hydrate it and add it as the child of the component. This overrides the text attribute.
  • sharetitle: Sets the title to be shared.
  • sharetext: Sets the text to be shared. Falls back to the text contents of the <title> element.
  • shareurl: Sets the URL to be shared. Fallsback to the href of the canonical link, failing that window.location.href.
<web-share-wrapper text="Share this" sharetitle="This amazing thing was shared" sharetext="You should really click on the link to learn more" shareurl="http://example.com/amazing">
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

Check out this page with more examples.

Events

The <web-share-wrapper> emits one of two events in response to the result of using navigator.share.

If the share is successful then a share-success event is fired. The share title, text and URL are emitted in the event's details (though the user may have edited them in the share target).

If the share is unsuccessful then a share-failure event is fired. The share title, text, URL and the error that was thrown are emitted in the event's details.

Tests

[TODO]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/philnash/web-share-wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The code is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the <web-share-wrapper> project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].