thank-you-tweet-button-004
Version:
Easy-to-use tweet button for saying thank you to @oluwatobiss.
20 lines (19 loc) • 1.21 kB
JavaScript
import { generateStarIcons } from "./generateStarIcons.js";
import { showError } from "./showError.js";
export function tweetButton(rating, bestNPMPackage, quantity) {
const tweetButtonContainer = document.createElement("section");
const anchorElement = document.createElement("a");
const anchorElementContent = document.createTextNode("Post a thank you message");
const tweetUrl = `https://twitter.com/intent/tweet?text=Thank+you,+
%40oluwatobiss.+Your+book+helped+me+create,+test,+and+publish+${quantity && quantity > 1 ? quantity : "an"}+NPM+${quantity && quantity > 1 ? "packages" : "package"}.%0A%0AMy+Favorite:+${bestNPMPackage}%0A%0ABook's+Rating:+${rating}-
star+rating!+${generateStarIcons(rating)}%0A%0Ahttps%3A%2F%2Famzn.to/4lifL3n`;
tweetButtonContainer.setAttribute("id", "tweet-btn-container");
anchorElement.setAttribute("class", "tweet-button");
anchorElement.setAttribute("target", "_blank");
anchorElement.setAttribute("href", tweetUrl);
anchorElement.appendChild(anchorElementContent);
tweetButtonContainer.appendChild(anchorElement);
return typeof rating === "number" && bestNPMPackage
? tweetButtonContainer
: showError();
}