sutty-base-jekyll-theme/_packs/controllers/share_controller.js
2021-11-22 14:51:50 -03:00

27 lines
586 B
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
static values = {
title: String,
text: String,
url: String,
};
async share(event = undefined) {
event?.preventDefault();
event?.stopPropagation();
const title = this.titleValue;
const text = this.textValue;
const url = this.urlValue;
const data = { title, text, url };
if ("share" in navigator) {
if (navigator.canShare(data)) {
navigator.share(data);
} else {
console.error("No se puede compartir", data);
}
}
}
}