UNPKG

@truconsent/consent-banner-react

Version:

React consent-banner components (in-page & modal)

3 lines (2 loc) 3.15 kB
import e,{useState as t,useEffect as n}from"react";function o({bannerId:o,apiUrl:r="https://your-api.com",userId:l="anonymous"}){const[a,i]=t(null);if(n(()=>{fetch(`${r}/banners/${o}`).then(e=>e.json()).then(i).catch(console.error)},[o,r]),!a)return null;const s=(e=null)=>{const t={};a.purposes.forEach(n=>{if(null!==e)t[n]=e;else{const e=document.querySelector(`[data-purpose="${n}"] input[type="checkbox"]`);t[n]=e.checked}}),fetch(`${r}/banners/${o}/consent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:l,consentData:t})}).then(()=>i(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 ",a.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."),a.purposes.map(t=>/*#__PURE__*/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"}},a.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:")," ",a.data_elements.map(t=>/*#__PURE__*/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:()=>s(!1),style:{padding:"8px 16px",border:"1px solid #ccc",background:"#fff",borderRadius:6,cursor:"pointer",marginRight:8}},"Reject All"),/*#__PURE__*/e.createElement("button",{onClick:()=>s(!0),style:{padding:"8px 16px",background:"#F15B5B",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"}},"I Consent")))}export{o as default}; //# sourceMappingURL=TruConsent.modern.mjs.map