@truconsent/consent-banner-react
Version:
React consent-banner components (in-page & modal)
3 lines (2 loc) • 3.99 kB
JavaScript
import e,{useState as a,useEffect as t}from"react";import n from"react-dom";function c({bannerId:c,apiBaseUrl:m="https://7nd6pu6evh.execute-api.ap-south-1.amazonaws.com/dev/banners",logoUrl:s='data:image/svg+xml;utf8,\n<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 100 100">\n <rect width="100" height="100" fill="#8e44ad"/>\n <text x="50" y="55" font-size="50" text-anchor="middle" fill="#fff" font-family="Arial">M</text>\n</svg>',companyName:r="Mars Financial Technologies Private Limited"}){const[o,i]=a(null);return t(()=>{c&&fetch(`${m}/${c}`).then(e=>e.json()).then(e=>i(e)).catch(console.error)},[c,m]),o?n.createPortal(/*#__PURE__*/e.createElement("div",{className:"mcm-overlay"},/*#__PURE__*/e.createElement("div",{className:"mcm-container"},/*#__PURE__*/e.createElement("header",{className:"mcm-header"},/*#__PURE__*/e.createElement("img",{src:s,alt:"Logo",className:"mcm-logo"}),/*#__PURE__*/e.createElement("div",{className:"mcm-header-text"},/*#__PURE__*/e.createElement("h1",null,"Consents by ",r),/*#__PURE__*/e.createElement("p",null,"You have all the rights to decline consents which you feel are not required by ",r,"."))),/*#__PURE__*/e.createElement("div",{className:"mcm-separator"}),/*#__PURE__*/e.createElement("div",{className:"mcm-body"},o.purposes.map(a=>/*#__PURE__*/e.createElement(l,{key:a.id,banner:o,purpose:a}))),/*#__PURE__*/e.createElement("div",{className:"mcm-separator"}),/*#__PURE__*/e.createElement("footer",{className:"mcm-footer"},/*#__PURE__*/e.createElement("button",{className:"mcm-btn reject"},"Reject All"),/*#__PURE__*/e.createElement("button",{className:"mcm-btn consent"},"I Consent")))),document.body):null}function l({banner:t,purpose:n}){var c;const[l,s]=a(!1),[r,o]=a(!1),[i,d]=a(!1);/*#__PURE__*/return e.createElement("div",{className:"mcm-card"},/*#__PURE__*/e.createElement("div",{className:"mcm-card-header"},/*#__PURE__*/e.createElement("div",null,/*#__PURE__*/e.createElement("h2",null,n.name),/*#__PURE__*/e.createElement("p",{className:"mcm-purpose-desc"},n.description)),/*#__PURE__*/e.createElement("div",{className:"mcm-card-actions"},n.is_mandatory&&/*#__PURE__*/e.createElement("span",{className:"badge mandatory"},"Mandatory"),/*#__PURE__*/e.createElement("span",{className:"badge expiry"},"Expiry Type: ",{"7a203e84-016b-4f61-b776-2375dd1755e4":"One Year"}[p=n.expiry_period]||p),/*#__PURE__*/e.createElement("label",{className:"switch"},/*#__PURE__*/e.createElement("input",{type:"checkbox",defaultChecked:!0}),/*#__PURE__*/e.createElement("span",{className:"track"}),/*#__PURE__*/e.createElement("span",{className:"thumb"})),/*#__PURE__*/e.createElement("span",{className:"toggle-label"},"Accept"))),/*#__PURE__*/e.createElement("div",{className:"accordion"},/*#__PURE__*/e.createElement("button",{className:"accordion-btn",onClick:()=>s(!l)},"Data Elements",/*#__PURE__*/e.createElement(m,{open:l})),l&&/*#__PURE__*/e.createElement("div",{className:"panel"},t.data_elements.map(a=>/*#__PURE__*/e.createElement("span",{key:a.id,className:"pill"},a.name))),/*#__PURE__*/e.createElement("button",{className:"accordion-btn",onClick:()=>o(!r)},"Legal Entities",/*#__PURE__*/e.createElement(m,{open:r})),r&&/*#__PURE__*/e.createElement("div",{className:"panel"},t.legal_entities.map(a=>/*#__PURE__*/e.createElement("span",{key:a.id,className:"pill"},a.name))),/*#__PURE__*/e.createElement("button",{className:"accordion-btn",onClick:()=>d(!i)},"Tools",/*#__PURE__*/e.createElement(m,{open:i})),i&&/*#__PURE__*/e.createElement("div",{className:"panel"},null==(c=t.tools)?void 0:c.map((a,t)=>/*#__PURE__*/e.createElement("span",{key:t,className:"pill"},a)))));var p}function m({open:a}){/*#__PURE__*/return e.createElement("svg",{className:"chevron "+(a?"open":""),width:"16",height:"16",viewBox:"0 0 24 24"},/*#__PURE__*/e.createElement("path",{d:"M6 9l6 6 6-6",fill:"none",stroke:"#333",strokeWidth:"2"}))}export{c as TruConsentModal};
//# sourceMappingURL=TruConsentModal.modern.mjs.map