{"version":3,"file":"FileUploadInput.C90awsf4.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/UXNWRabX0IeVTgbvsbAG/L8FV6c3bxSRcKG1QSrwj/FileUploadInput.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useEffect,useRef}from\"react\";import{motion}from\"framer\";import{createBackground,Border,borderProp,fillProp,createId,iconProp,Icon,HiddenInput}from\"https://framerusercontent.com/modules/DwWOdDzQZGCuvkNlbUjZ/RhTkfEJwV2NS1uN2FS3e/FramerFormsShared.js\";const presignedUrlApi=\"https://api.framerforms.com/s3/signed-url\";const MAX_SIZE_LIMIT_MB=25;const MAX_SIZE_LIMIT=MAX_SIZE_LIMIT_MB*1024*1024// 25MB in bytes\n;/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n * @framerIntrinsicWidth 400\n */export default function FileUploadInput(props){const{shadows,border,layout,icon}=props;const id=createId();const isVertical=props.layout.direction==\"vertical\";const[focused,setFocused]=useState(false);const[invalid,setInvalid]=useState(false);const[fileName,setFileName]=useState(\"\");const[fileUploadUrl,setFileUploadUrl]=useState(\"\");const inputRef=useRef(null);useEffect(()=>{if(invalid){var _props_invalidEvent;(_props_invalidEvent=props.invalidEvent)===null||_props_invalidEvent===void 0?void 0:_props_invalidEvent.call(props);}},[invalid]);function onFocus(){var _props_focusEvent;setFocused(true);(_props_focusEvent=props.focusEvent)===null||_props_focusEvent===void 0?void 0:_props_focusEvent.call(props);if(invalid){setInvalid(false);}}function onBlur(){var _props_blurEvent;setFocused(false);(_props_blurEvent=props.blurEvent)===null||_props_blurEvent===void 0?void 0:_props_blurEvent.call(props);}let fileTypes=\"\";switch(props.fileTypes){case\"audio\":fileTypes=\"audio/*\";break;case\"video\":fileTypes=\"video/*\";break;case\"image\":fileTypes=\"image/*\";break;case\"custom\":const fileTypeStrings=[];for(const fileType of props.fileTypesCustom){if(fileType.startsWith(\".\")||fileType==\"audio/*\"||fileType==\"video/*\"||fileType==\"image/*\"){fileTypeStrings.push(fileType);}else{fileTypeStrings.push(`.${fileType}`);}}fileTypes=fileTypeStrings.join(\",\");break;}async function onFileChange(event){const file=event.target.files[0];setFileName(file?file.name:\"\");const result=await uploadFile(file);setFileUploadUrl((result===null||result===void 0?void 0:result.fileLocation)||\"\");}function onKeyDown(event){if(event.key==\"Enter\"){var _inputRef_current;(_inputRef_current=inputRef.current)===null||_inputRef_current===void 0?void 0:_inputRef_current.click();}}return /*#__PURE__*/_jsxs(motion.div,{onFocus:onFocus,onBlur:onBlur,onKeyDown:onKeyDown,animate:{...createBackground(props.fill,null,focused,invalid),boxShadow:invalid&&(shadows===null||shadows===void 0?void 0:shadows.invalid)||focused&&(shadows===null||shadows===void 0?void 0:shadows.focus)||(shadows===null||shadows===void 0?void 0:shadows.default),borderColor:invalid&&(border===null||border===void 0?void 0:border.colorInvalid)||focused&&(border===null||border===void 0?void 0:border.colorFocus)||(border===null||border===void 0?void 0:border.color)},style:{borderRadius:props.radius,padding:props.padding,color:props.color,display:\"flex\",flexDirection:`${isVertical?\"column\":\"row\"}${(icon===null||icon===void 0?void 0:icon.location)==\"end\"?\"-reverse\":\"\"}`,alignItems:isVertical?layout.alignH:\"center\",justifyContent:isVertical?\"center\":layout.alignH,gap:layout.gap,textAlign:\"center\",...props.font,...props.style},initial:false,transition:props.transition,children:[/*#__PURE__*/_jsx(HiddenInput,{name:props.name,required:props.required,value:fileUploadUrl,setInvalid:setInvalid,noPrefill:true}),/*#__PURE__*/_jsx(\"input\",{ref:inputRef,type:\"file\",accept:fileTypes,autoFocus:props.autoFocus,onChange:onFileChange,style:{position:\"absolute\",inset:0,opacity:0,cursor:\"pointer\"},\"data-framerforms-no-prefill\":true}),icon&&/*#__PURE__*/_jsx(Icon,{...icon,defaultImage:`url('data:image/svg+xml,${encodeURIComponent(`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"28\" height=\"28\"><path d=\"M 9.366 18.419 C 8.284 18.422 7.242 18.009 6.456 17.266 C 5.69 16.541 5.254 15.535 5.25 14.481 C 5.25 13.437 5.684 12.436 6.456 11.697 C 7.242 10.953 8.284 10.54 9.366 10.544 C 9.624 9.395 10.378 8.385 11.463 7.738 C 12.009 7.413 12.61 7.191 13.235 7.082 C 13.869 6.971 14.518 6.973 15.152 7.088 C 15.783 7.202 16.383 7.429 16.919 7.753 C 17.445 8.068 17.903 8.483 18.269 8.975 C 18.626 9.458 18.873 10 18.997 10.57 C 19.121 11.139 19.12 11.725 18.992 12.294 L 19.867 12.294 C 21.558 12.294 22.929 13.665 22.929 15.356 C 22.929 17.048 21.558 18.419 19.867 18.419 L 18.992 18.419\" fill=\"transparent\" stroke-width=\"1.75\" stroke=\"white\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path><path d=\"M 11.117 15.794 L 13.742 13.169 L 16.367 15.794 M 13.742 13.169 L 13.742 21.044\" fill=\"transparent\" stroke-width=\"1.75\" stroke=\"white\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path><path d=\"M 0.6 5.85 C 0.6 2.951 2.951 0.6 5.85 0.6 L 22.15 0.6 C 25.049 0.6 27.4 2.951 27.4 5.85 L 27.4 22.15 C 27.4 25.049 25.049 27.4 22.15 27.4 L 5.85 27.4 C 2.951 27.4 0.6 25.049 0.6 22.15 Z\" fill=\"transparent\" stroke-width=\"1.2\" stroke=\"white\"></path></svg>`)}')`}),fileName.length?fileName:props.text.replace(\"##\",MAX_SIZE_LIMIT_MB.toString()),/*#__PURE__*/_jsx(Border,{...props.border}),/*#__PURE__*/_jsx(\"style\",{children:`\n            #${id} input:focus {\n                outline: none;\n            }`})]});}FileUploadInput.displayName=\"File Upload\";addPropertyControls(FileUploadInput,{userId:{type:ControlType.String,defaultValue:\"\",placeholder:\"FramerForms User ID\",title:\"User ID\",description:\"Get your user ID [here](https://app.framerforms.com/dashboard/account)\",hidden:props=>true},name:{type:ControlType.String,defaultValue:\"File\"},required:{type:ControlType.Boolean,defaultValue:false},autoFocus:{type:ControlType.Boolean,defaultValue:false,title:\"Auto-Focus\"},fileTypes:{type:ControlType.Enum,defaultValue:\"all\",options:[\"all\",\"audio\",\"video\",\"image\",\"custom\"],optionTitles:[\"Any File\",\"Any Audio File\",\"Any Video File\",\"Any Image File\",\"Custom\"]},fileTypesCustom:{type:ControlType.Array,defaultValue:[\".pdf\"],control:{type:ControlType.String,placeholder:\".pdf\"},title:\" \",hidden:props=>props.fileTypes!==\"custom\"},text:{type:ControlType.String,defaultValue:`Click to upload file or drag-and-drop. Max ##mb`,description:\"*##* → max size in MB\"},layout:{type:ControlType.Object,controls:{direction:{type:ControlType.Enum,defaultValue:\"vertical\",options:[\"horizontal\",\"vertical\"],optionTitles:[\"Horizontal\",\"Vertical\"],optionIcons:[\"direction-horizontal\",\"direction-vertical\"],displaySegmentedControl:true},alignH:{type:ControlType.Enum,defaultValue:\"center\",options:[\"start\",\"center\",\"end\"],optionTitles:[\"Left\",\"Center\",\"Right\"],displaySegmentedControl:true,title:\"Align\"},gap:{type:ControlType.Number,defaultValue:12,min:0,step:1}}},font:{type:\"font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:14,lineHeight:1.2}},color:{type:ControlType.Color,defaultValue:\"#999999\",title:\"Color\"},fill:fillProp({}),radius:{type:ControlType.BorderRadius,defaultValue:\"10px\"},padding:{type:ControlType.Padding,defaultValue:\"12px\"},icon:iconProp({size:28,controls:{location:{type:ControlType.Enum,options:[\"start\",\"end\"],optionTitles:[\"Start\",\"End\"],displaySegmentedControl:true}}}),border:borderProp({}),shadows:{type:ControlType.Object,buttonTitle:\"Shadows\",optional:true,controls:{default:{type:ControlType.BoxShadow},focus:{type:ControlType.BoxShadow}}},transition:{type:ControlType.Transition,defaultValue:{type:false}},focusEvent:{type:ControlType.EventHandler,title:\"Focus\"},blurEvent:{type:ControlType.EventHandler,title:\"Blur\"},invalidEvent:{type:ControlType.EventHandler,title:\"Invalid\"}});function uploadFile(file){return new Promise((resolve,reject)=>{fetchPresignedURL(file).then(({presignedUrl})=>postToPresignedURL(file,presignedUrl)).then(resolve).catch(reject);});}function fetchPresignedURL(file){var _file_name;return fetch(presignedUrlApi,{method:\"POST\",body:JSON.stringify({file_name:(_file_name=file.name)===null||_file_name===void 0?void 0:_file_name.replace(/\\s+/g,\"-\")}),headers:{\"Content-Type\":\"application/json\"}}).then(async response=>{const responseBody=await response.json();if(response.status>200){throw new Error(responseBody.errorMessage);}return responseBody;});}function postToPresignedURL(file,presignedUrl){return new Promise((resolve,reject)=>{fetch(presignedUrl,{method:\"PUT\",body:file}).then(()=>resolve({fileLocation:removeURLParameters(presignedUrl)})).catch(reject);});}function removeURLParameters(urlString){const url=new URL(urlString);url.search=\"\";return url.toString();}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FileUploadInput\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"400\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FileUploadInput.map"],"mappings":"8UAKG,SAAwB,EAAgB,EAAM,CAAC,GAAK,CAAC,UAAQ,SAAO,SAAO,QAAM,EAAY,EAAG,GAAU,CAAO,EAAW,EAAM,OAAO,WAAW,WAAgB,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAM,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAG,CAAM,CAAC,EAAc,GAAkBA,EAAS,GAAG,CAAO,EAASC,EAAO,KAAK,CAAC,MAAc,CAAC,GAAG,EAAQ,CAAC,IAAI,GAAqB,EAAoB,EAAM,eAAgB,MAA0C,EAAoB,KAAK,EAAM,GAAI,CAAC,EAAQ,CAAC,CAAC,SAAS,GAAS,CAAC,IAAI,EAAkB,EAAW,GAAK,EAAE,EAAkB,EAAM,a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