UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

130 lines (129 loc) 3.41 kB
/*! * NENT 2022 */ /* istanbul ignore file */ /** Untestable at the moment */ import { Component, Element, h, Host, Method, Prop, } from '@stencil/core'; /** * This element leverages the browser's web-share * API to give the application a native-app feel. * @system app */ export class ContentShare { componentWillLoad() { if (!this.url) { let url = document.location.href; const canonicalElement = document.querySelector('link[rel=canonical]'); if (canonicalElement) { url = canonicalElement.href; } this.url = url; } } /** * Manual share method for more complex scenarios * @param data */ async share(data) { if (navigator === null || navigator === void 0 ? void 0 : navigator.share) { await navigator.share({ title: (data === null || data === void 0 ? void 0 : data.title) || this.headline || document.title, text: (data === null || data === void 0 ? void 0 : data.text) || this.text, url: (data === null || data === void 0 ? void 0 : data.url) || this.url, }); } } render() { return (h(Host, { onClick: async () => await this.share() }, h("slot", null))); } static get is() { return "n-app-share"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["app-share.css"] }; } static get styleUrls() { return { "$": ["app-share.css"] }; } static get properties() { return { "headline": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Headline for the share" }, "attribute": "headline", "reflect": false }, "text": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The textual body of web share" }, "attribute": "text", "reflect": false }, "url": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The URL we are sharing" }, "attribute": "url", "reflect": false } }; } static get methods() { return { "share": { "complexType": { "signature": "(data?: { title?: string | undefined; text?: string | undefined; url?: string | undefined; } | null | undefined) => Promise<void>", "parameters": [{ "tags": [{ "name": "param", "text": "data" }], "text": "" }], "references": { "Promise": { "location": "global" } }, "return": "Promise<void>" }, "docs": { "text": "Manual share method for more complex scenarios", "tags": [{ "name": "param", "text": "data" }] } } }; } static get elementRef() { return "el"; } }