// // Playpass (c) Playco // https://github.com/playpassgames/playpass/blob/main/LICENSE.txt import { html, css, svg } from "lit"; import { customElement, property } from "lit/decorators.js"; import { map } from "lit/directives/map.js"; import type { SVGTemplateResult } from "lit"; import { popupCss, Popup } from "./popup"; import { ShareType } from "../share/share-type"; type ShareIcon = { type: ShareType; path: SVGTemplateResult; color: string; }; const icons: ShareIcon[] = [ { type: ShareType.Facebook, path: svg``, color: "#0076FB", }, { type: ShareType.Twitter, path: svg``, color: "#1DA1F2", }, { type: ShareType.WhatsApp, path: svg``, color: "#25D366", }, { type: ShareType.Telegram, path: svg``, color: "#0088CC", }, { type: ShareType.Clipboard, path: svg``, color: "#718096", }, ]; @customElement("playpass-share") export class SharePopup extends Popup { static override styles = [ popupCss, css` button { font-size: 0; width: 4rem; padding: 0.5rem; } .preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 24rem; font-style: italic; color: #666; } ` ]; @property() shareText = ""; onShare?: (type: ShareType | null) => void; override onClose (event: Event) { super.onClose(event); if (this.onShare) { this.onShare(null); } } protected onShareClick (event: Event) { if (this.onShare && event.currentTarget instanceof HTMLButtonElement) { const type = event.currentTarget.name as ShareType; this.onShare(type as ShareType); } this.remove(); } override renderPopup () { return html`

${map(this.shareText.split("\n"), shareLine => html` ${shareLine}
`)}

${map(icons, icon => html` `)} `; } } declare global { interface HTMLElementTagNameMap { "playpass-share": SharePopup; } }