@truconsent/consent-banner-react
Version:
React consent-banner components (in-page & modal)
3 lines (2 loc) • 3.31 kB
JavaScript
import e,{useState as t,useEffect as n}from"react";function o(o){var r=o.bannerId,l=o.apiUrl,i=void 0===l?"https://your-api.com":l,a=o.userId,d=void 0===a?"anonymous":a,s=t(null),c=s[0],u=s[1];if(n(function(){fetch(i+"/banners/"+r).then(function(e){return e.json()}).then(u).catch(console.error)},[r,i]),!c)return null;var p=function(e){void 0===e&&(e=null);var t={};c.purposes.forEach(function(n){if(null!==e)t[n]=e;else{var o=document.querySelector('[data-purpose="'+n+'"] input[type="checkbox"]');t[n]=o.checked}}),fetch(i+"/banners/"+r+"/consent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:d,consentData:t})}).then(function(){return u(null)})};/*#__PURE__*/return e.createElement("div",{style:{fontFamily:"'Segoe UI', sans-serif",maxWidth:500,margin:"20px auto",border:"1px solid #e0e0e0",borderRadius:8,boxShadow:"0 2px 8px rgba(0,0,0,0.1)",background:"#fff",overflow:"hidden"}},/*#__PURE__*/e.createElement("div",{style:{background:"#f7f7f7",padding:16,borderBottom:"1px solid #e0e0e0"}},/*#__PURE__*/e.createElement("h3",{style:{margin:0,fontSize:18,fontWeight:600}},"Consents by ",c.legal_entities.join(", "))),/*#__PURE__*/e.createElement("div",{style:{padding:16}},/*#__PURE__*/e.createElement("p",{style:{fontSize:13,color:"#555",marginBottom:16}},"You have all the rights to decline consents you feel are not required."),c.purposes.map(function(t){/*#__PURE__*/return e.createElement("div",{key:t,"data-purpose":t,style:{border:"1px solid #eee",borderRadius:6,padding:12,marginBottom:16}},/*#__PURE__*/e.createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8}},/*#__PURE__*/e.createElement("div",null,/*#__PURE__*/e.createElement("b",null,t),/*#__PURE__*/e.createElement("br",null),/*#__PURE__*/e.createElement("small",{style:{color:"#666"}},c.collection_point)),/*#__PURE__*/e.createElement("label",{style:{position:"relative",display:"inline-block",width:36,height:20}},/*#__PURE__*/e.createElement("input",{type:"checkbox",defaultChecked:!0,style:{display:"none"}}),/*#__PURE__*/e.createElement("span",{style:{position:"absolute",cursor:"pointer",top:0,left:0,right:0,bottom:0,backgroundColor:"#ccc",borderRadius:34,transition:"0.2s"}}),/*#__PURE__*/e.createElement("span",{style:{position:"absolute",height:14,width:14,left:3,bottom:3,backgroundColor:"#fff",borderRadius:"50%",transition:"0.2s"}}))),/*#__PURE__*/e.createElement("div",null,/*#__PURE__*/e.createElement("b",null,"Data Elements:")," ",c.data_elements.map(function(t){/*#__PURE__*/return e.createElement("span",{key:t,style:{display:"inline-block",padding:"4px 8px",fontSize:12,background:"#f0f0f0",borderRadius:12,margin:"4px 6px 0 0"}},t)})))})),/*#__PURE__*/e.createElement("div",{style:{textAlign:"right",padding:16,background:"#f7f7f7",borderTop:"1px solid #e0e0e0"}},/*#__PURE__*/e.createElement("button",{onClick:function(){return p(!1)},style:{padding:"8px 16px",border:"1px solid #ccc",background:"#fff",borderRadius:6,cursor:"pointer",marginRight:8}},"Reject All"),/*#__PURE__*/e.createElement("button",{onClick:function(){return p(!0)},style:{padding:"8px 16px",background:"#F15B5B",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"}},"I Consent")))}export{o as default};
//# sourceMappingURL=TruConsent.esm.js.map