{"version":3,"file":"FormText.CN4LPDBr.mjs","names":["useRef","useState","__esmMin","init_npm_react_18_3_1","_e","c","init_jsx_runtime","ce","de","addPropertyControls","init_framer_D1IzEvwH","RenderTarget","ControlType","TOKENS","init_OkoCore","useStore","makeStore","listenToTyping","listening","el","typed","FormText","props","isCanvas","ref","message","setMessage","values","mode","host","form","field","fieldName","onInvalid","wrong","invalidText","emptyText","f","onInput","text","colour","name","line","successText","successSize","shown","init_FormText","p"],"sources":["https:/framerusercontent.com/modules/UG6qNrrJGZdh2z4wOCjU/kPUghyPzsXJ2clYq7hKA/FormText.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useEffect,useRef,useState}from\"react\";import{makeStore,useStore,TOKENS}from\"https://framerusercontent.com/modules/8b2udaV7Tzk9eVgPM9JE/F2qudaOb7XGSan4e4jjx/OkoCore.js\";// the last name typed in any form on the page, for the thank-you line after the form is sent\nconst typed=makeStore({});let listening=false;function listenToTyping(){if(listening||typeof document===\"undefined\")return;listening=true;document.addEventListener(\"input\",e=>{const el=e.target;if(!el||!el.name)return;typed.set({...typed.get(),[el.name]:el.value});},true);}/**\n * Form text. Error mode: put it under a field of a Framer form; when the form is sent with that field empty\n * or wrong, it shows your text instead of the browser hint and focuses the first wrong field. Success mode:\n * shows the thank-you line with what the visitor typed in Field name, for example \"Got it, {name}.\".\n * Sending, the recipient and the form states stay with the Framer form.\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function FormText(props){const{mode,fieldName,emptyText,invalidText,successText,successSize,colour}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const ref=useRef(null);const[message,setMessage]=useState(\"\");const values=useStore(typed);useEffect(()=>{listenToTyping();},[]);useEffect(()=>{if(mode!==\"error\"||isCanvas)return;const host=ref.current;const form=host?host.closest(\"form\"):null;if(!form)return;const field=()=>form.querySelector('[name=\"'+String(fieldName).replace(/\"/g,\"\")+'\"]');const onInvalid=e=>{const el=field();if(!el||e.target!==el)return;e.preventDefault();const wrong=el.validity.typeMismatch||el.validity.patternMismatch;setMessage(wrong?invalidText:emptyText);el.setAttribute(\"aria-invalid\",\"true\");// the first wrong field in the form takes the focus (events arrive in field order)\nconst f=form;if(!f.__okoFocused){f.__okoFocused=true;el.focus();setTimeout(()=>f.__okoFocused=false,0);}};const onInput=e=>{const el=field();if(!el||e.target!==el)return;if(el.validity.valid){setMessage(\"\");el.removeAttribute(\"aria-invalid\");}};form.addEventListener(\"invalid\",onInvalid,true);form.addEventListener(\"input\",onInput,true);return()=>{form.removeEventListener(\"invalid\",onInvalid,true);form.removeEventListener(\"input\",onInput,true);};},[mode,fieldName,emptyText,invalidText,isCanvas]);const text={margin:0,color:colour,fontFamily:\"'Mona Sans', sans-serif\",WebkitFontSmoothing:\"antialiased\"};if(mode===\"success\"){const name=String(values[fieldName]||\"\").trim().split(/\\s+/)[0]||\"\";const line=name?successText.replace(\"{name}\",name):successText.replace(/,?\\s*\\{name\\}/,\"\");return /*#__PURE__*/_jsx(\"p\",{style:{...props.style,...text,fontWeight:500,fontSize:successSize||96,lineHeight:1.04,letterSpacing:\"-0.045em\"},className:\"okoFormSuccess\",children:isCanvas?successText.replace(\"{name}\",\"Elena\"):line});}// no message, no height: the field below does not move until an error appears\nconst shown=message;return /*#__PURE__*/_jsx(\"p\",{ref:ref,role:\"alert\",\"aria-live\":\"assertive\",style:{...props.style,...text,fontWeight:400,fontSize:16,lineHeight:\"22px\",minHeight:0,paddingTop:shown?8:0},children:shown});}addPropertyControls(FormText,{mode:{type:ControlType.Enum,title:\"Mode\",options:[\"error\",\"success\"],optionTitles:[\"Field error\",\"Thank you line\"],defaultValue:\"error\",displaySegmentedControl:true},fieldName:{type:ControlType.String,title:\"Field name\",defaultValue:\"Name\",description:\"Name of the form field, exactly as in the field's settings.\"},emptyText:{type:ControlType.String,title:\"Empty field\",defaultValue:\"Add your name.\",hidden:p=>p.mode!==\"error\"},invalidText:{type:ControlType.String,title:\"Wrong value\",defaultValue:\"That email looks unfinished.\",description:\"Shown when an email field is filled but not complete.\",hidden:p=>p.mode!==\"error\"},successText:{type:ControlType.String,title:\"Thank you\",defaultValue:\"Got it, {name}.\",description:\"{name} is the first word of what the visitor typed in Field name.\",hidden:p=>p.mode!==\"success\"},successSize:{type:ControlType.Number,title:\"Size\",defaultValue:96,min:32,max:160,unit:\"px\",description:\"Size of the thank-you line; the heading style of the page is 96 on desktop, 64 on tablet, 44 on phone.\",hidden:p=>p.mode!==\"success\"},colour:{type:ControlType.Color,title:\"Colour\",defaultValue:TOKENS.bone}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FormText\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FormText.map"],"mappings":"A,0QAC8C,SAASiB,GAAgB,CAAIC,GAAW,OAAO,SAAW,MAAmB,EAAU,GAAK,SAAS,iBAAiB,QAAQ,GAAG,CAAC,IAAMC,EAAG,EAAE,OAAWA,GAAKA,EAAG,MAAYC,EAAM,IAAI,CAAC,GAAGA,EAAM,IAAI,GAAGD,EAAG,MAAMA,EAAG,KAAK,CAAC,CAAE,EAAE,EAAI,EAAE,CAQ9Q,SAAwBE,EAAS,EAAM,CAAC,GAAK,CAAC,OAAK,YAAU,YAAU,cAAY,cAAY,cAAY,UAAQC,EAAYC,EAASZ,EAAa,QAAQ,IAAIA,EAAa,OAAaa,EAAIxB,EAAO,IAAI,EAAO,CAACyB,EAAQC,GAAYzB,EAAS,EAAE,EAAQ0B,EAAOZ,EAASK,CAAK,EAAEb,MAAc,CAACU,EAAe,CAAE,EAAE,CAAC,CAAC,EAAEV,MAAc,CAAC,GAAGqB,IAAO,SAASL,EAAS,OAAO,IAAMM,EAAKL,EAA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