react-utterances-github-comments
Version:
A lightweight React wrapper for Utterances GitHub comment system
1 lines • 1.18 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),GithubComments=({repo:e,issueTerm:t,theme:r="github-light",label:s,titleText:n="Comentarios",loadingText:i="Cargando comentarios...",className:o=""})=>{const[c,u]=(0,react_1.useState)(!0);return(0,react_1.useEffect)((()=>{if("undefined"==typeof window)return;const n=setTimeout((()=>{const n=document.getElementById("utterances-thread");if(!n)return;n.innerHTML="";const i=document.createElement("script");i.src="https://utteranc.es/client.js",i.setAttribute("repo",e),i.setAttribute("issue-term",t),i.setAttribute("theme",r),i.setAttribute("crossorigin","anonymous"),i.async=!0,s&&i.setAttribute("label",s),i.onload=()=>u(!1),i.onerror=()=>{u(!1),console.error("Error loading Utterances script")},n.appendChild(i)}),0);return()=>clearTimeout(n)}),[e,t,r,s]),(0,jsx_runtime_1.jsxs)("section",{className:o,children:[(0,jsx_runtime_1.jsx)("h3",{style:{textAlign:"center"},children:n}),c&&(0,jsx_runtime_1.jsx)("p",{style:{textAlign:"center"},children:i}),(0,jsx_runtime_1.jsx)("div",{id:"utterances-thread"})]})};exports.default=GithubComments;