{"version":3,"file":"NewsletterSubscribeForm.CBlnKfLG.mjs","names":["useId","useMemo","useState","__esmMin","pe","init_npm_react_18_3_1","ie","_e","p","addPropertyControls","init_framer_DKWANagr","ControlType","NewsletterSignup","props","rawId","scope","email","setEmail","status","setStatus","detail","setDetail","onSubmit","event","body","tag","response","EMBED_URL","username","html","parsed","errorMessage","text","font","textColor","style","successMessage","busy","placeholder","borderColor","buttonBackground","buttonText","submittingLabel","buttonLabel","errorColor","init_NewsletterSubscribeForm","init_jsx_runtime"],"sources":["https:/framerusercontent.com/modules/ESrGFP1jvjDqUQLEBpXk/VOhouXhEWX0IeS1I3Pgq/NewsletterSubscribeForm.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useId,useMemo,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * Framer code component: newsletter signup form that subscribes through\n * Buttondown's public embed endpoint.\n *\n * Why the embed endpoint and not the REST API: it needs no API key (nothing\n * secret ships to the browser) and it honours the newsletter's double opt-in,\n * so Buttondown sends the confirmation email. Creating subscribers through the\n * API would bypass that and is not something a public form should do.\n *\n * The endpoint sends `access-control-allow-origin: *` and answers a malformed\n * address with a 400, so a plain fetch can report real errors. A successful\n * subscribe answers with a 302 to Buttondown's confirmation page, which we\n * must not follow (that page has no CORS headers and would reject the fetch\n * even though the subscribe worked) — hence `redirect: \"manual\"`, which yields\n * an opaque redirect that we treat as success.\n *\n * Styling mirrors the boitano.no/kontakt form, measured from the live page:\n * transparent fields with only a 1px bottom border, no padding, 40px tall,\n * placeholder in the same colour as the text, and a 4px-radius button. The\n * contact button has a leading arrow and uneven padding to match; this one\n * has no arrow, so its padding is even (the site's own arrowless variant uses\n * 10px 16px). Defaults are those values; everything that is a brand colour or\n * the font is exposed as a property control.\n */const EMBED_URL=\"https://buttondown.com/api/emails/embed-subscribe/\";export default function NewsletterSignup(props){const{username,tag,placeholder,buttonLabel,submittingLabel,successMessage,errorMessage,textColor,borderColor,buttonBackground,buttonText,errorColor,font,style}=props;const rawId=useId();const scope=useMemo(()=>`newsletter-signup-${rawId.replace(/[:]/g,\"\")}`,[rawId]);const[email,setEmail]=useState(\"\");const[status,setStatus]=useState(\"idle\");const[detail,setDetail]=useState(\"\");async function onSubmit(event){event.preventDefault();if(status===\"submitting\")return;// Honeypot: a real visitor never fills this in.\nconst form=new FormData(event.currentTarget);if(form.get(\"website\"))return;setStatus(\"submitting\");setDetail(\"\");const body=new URLSearchParams({email:email.trim(),embed:\"1\"});if(tag)body.set(\"tag\",tag);try{const response=await fetch(EMBED_URL+encodeURIComponent(username),{method:\"POST\",body,redirect:\"manual\"});if(response.type===\"opaqueredirect\"||response.ok){setStatus(\"success\");return;}// Buttondown renders its error as an HTML page; the message sits in\n// a .message-box element. Fall back to our own copy if it is not\n// there (or the markup changes).\nconst html=await response.text();const parsed=new DOMParser().parseFromString(html,\"text/html\").querySelector(\".message-box\")?.textContent?.trim();setDetail(parsed||errorMessage);setStatus(\"error\");}catch{setDetail(errorMessage);setStatus(\"error\");}}const text={fontSize:16,lineHeight:\"20px\",...font,color:textColor};if(status===\"success\"){return /*#__PURE__*/_jsx(\"div\",{role:\"status\",style:{...text,...style},children:successMessage});}const busy=status===\"submitting\";return /*#__PURE__*/_jsxs(\"form\",{onSubmit:onSubmit,className:scope,style:{display:\"flex\",flexDirection:\"column\",alignItems:\"flex-start\",gap:20,width:\"100%\",...style},children:[/*#__PURE__*/_jsx(\"style\",{children:`\n.${scope} input[type=email]::placeholder { color: ${textColor}; opacity: 1; }\n.${scope} input[type=email]:-webkit-autofill {\n    -webkit-text-fill-color: ${textColor};\n    transition: background-color 9999s ease-out;\n}\n                `}),/*#__PURE__*/_jsx(\"input\",{type:\"email\",name:\"email\",required:true,autoComplete:\"email\",inputMode:\"email\",\"aria-label\":placeholder,placeholder:placeholder,value:email,onChange:e=>setEmail(e.target.value),disabled:busy,style:{...text,lineHeight:1.2,boxSizing:\"border-box\",width:\"100%\",height:40,padding:0,background:\"transparent\",border:\"none\",borderBottom:`1px solid ${borderColor}`,borderRadius:0,outline:\"none\"}}),/*#__PURE__*/_jsx(\"input\",{type:\"text\",name:\"website\",tabIndex:-1,autoComplete:\"one-time-code\",\"aria-hidden\":\"true\",style:{position:\"absolute\",transform:\"scale(0)\"}}),/*#__PURE__*/_jsx(\"button\",{type:\"submit\",disabled:busy,style:{display:\"flex\",alignItems:\"center\",justifyContent:\"center\",height:40,padding:\"10px 16px\",border:\"none\",borderRadius:4,background:buttonBackground,color:buttonText,cursor:busy?\"progress\":\"pointer\",opacity:busy?.7:1,...font},children:/*#__PURE__*/_jsx(\"span\",{style:{fontSize:16,lineHeight:\"20px\"},children:busy?submittingLabel:buttonLabel})}),status===\"error\"&&/*#__PURE__*/_jsx(\"div\",{role:\"alert\",style:{...text,color:errorColor},children:detail})]});}NewsletterSignup.defaultProps={username:\"boitano.no\",tag:\"\",placeholder:\"Din e-postadresse\",buttonLabel:\"Abonner\",submittingLabel:\"Sender…\",successMessage:\"Takk! Sjekk innboksen din for \\xe5 bekrefte abonnementet.\",errorMessage:\"Noe gikk galt. Pr\\xf8v igjen om litt.\",textColor:\"#FFDFF3\",borderColor:\"#FFDFF3\",buttonBackground:\"#FFDFF3\",buttonText:\"#161515\",errorColor:\"#FFDFF3\",font:{fontFamily:'\"Boitano Sans Regular\", sans-serif',fontWeight:400}};addPropertyControls(NewsletterSignup,{username:{type:ControlType.String,title:\"Buttondown\",description:\"Newsletter username (the part after buttondown.com/).\"},tag:{type:ControlType.String,title:\"Tag\",description:\"Optional tag to add to new subscribers, e.g. “website”.\"},placeholder:{type:ControlType.String,title:\"Placeholder\"},buttonLabel:{type:ControlType.String,title:\"Button\"},submittingLabel:{type:ControlType.String,title:\"Sending\"},successMessage:{type:ControlType.String,title:\"Success\",displayTextArea:true},errorMessage:{type:ControlType.String,title:\"Error\",displayTextArea:true},font:{// @ts-ignore - Framer's font control is not in every type version.\ntype:ControlType.Font,title:\"Font\",controls:\"basic\"},textColor:{type:ControlType.Color,title:\"Text\"},borderColor:{type:ControlType.Color,title:\"Underline\"},buttonBackground:{type:ControlType.Color,title:\"Button bg\"},buttonText:{type:ControlType.Color,title:\"Button text\"},errorColor:{type:ControlType.Color,title:\"Error\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NewsletterSignup\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NewsletterSubscribeForm.map"],"mappings":"A,qLAuBwE,SAAwBY,EAAiB,EAAM,CAAC,GAAK,CAAC,WAAS,MAAI,cAAY,cAAY,kBAAgB,iBAAe,eAAa,YAAU,cAAY,mBAAiB,aAAW,aAAW,OAAK,SAAOC,EAAYC,EAAMd,EAAM,EAAQe,EAAMd,MAAY,qBAAqBa,EAAM,QAAQ,OAAO,EAAE,IAAI,CAACA,CAAK,CAAC,EAAO,CAACE,EAAMC,GAAUf,EAAS,EAAE,EAAO,CAACgB,EAAOC,GAAWjB,EAAS,MAAM,EAAO,CAACkB,EAAOC,GAAWnB,EAAS,EAAE,EAAE,eAAeoB,EAAS,EAAM,CACre,GADseC,EAAM,eAAe,EAAKL,IAAS,cACtgB,IAAjC,SAASK,EAAM,aAAqB,CAAC,CAAC,IAAI,SAAS,EAAE,OAAOJ,EAAU,YAAY,EAAEE,EAAU,EAAE,EAAE,IAAMG,EAAK,IAAI,gBAAgB,CAAC,MAAMR,EAAM,KAAK,EAAE,MAAM,GAAG,CAAC,EAAKS,GAAID,EAAK,IAAI,MAAMC,CAAG,EAAE,GAAG,CAAC,IAAMC,EAAS,MAAM,MAAMC,EAAU,mBAAmBC,CAAQ,EAAE,CAAC,OAAO,OAAO,OAAK,SAAS,QAAQ,CAAC,EAAE,GAAGF,EAAS,OAAO,kBAAkBA,EAAS,GAAG,CAACP,EAAU,SAAS,EAAE,MAAO,CAGvY,IAAMU,EAAK,MAAMH,EAAS,KAAK,EAAQI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