zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
2 lines (1 loc) • 2.04 kB
JavaScript
import{_ as r,e as f,z as d,w as u,b as o,H as m,D as p,i as c,o as h,V as y}from"./index-DwzE-W2i.js";const g={props:{modelValue:{type:[Array,String]},keyProp:{type:String},rules:{type:[Array]},accept:{type:String,default:"*"},label:{type:String,default:"choose_file"},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},multiple:{type:Boolean,default:!1}},emits:["update:modelValue","onFileSelect","formData"],data(){return{filename:""}},watch:{modelValue(t){this.filename=t}},mounted(){this.filename=this.modelValue},methods:{getFormData(t){const e=[];for(const l of t){const a=new FormData;a.append("data",l,l.name),e.push(a)}return e},clearInput(){this.filename=null,this.$emit("update:modelValue",this.filename),this.$emit("onFileSelect",{files:[],key:this.keyProp}),this.$emit("formData",null)},onFocus(){this.disabled||this.$refs.fileInput.click()},onFileChange(t){const e=t.target.files||t.dataTransfer.files,l=this.getFormData(e);e?e.length>0?this.filename=[...e].map(a=>a.name).join(", "):this.filename=null:this.filename=t.target.value.split("\\").pop(),this.$emit("update:modelValue",this.filename),this.$emit("onFileSelect",{files:e,key:this.keyProp}),this.$emit("formData",l)}}},b=["accept","multiple","disabled"];function V(t,e,l,a,s,i){return d(),f(y,{"align-center":""},{default:u(()=>[o(p,{"prepend-icon":"attach_file","single-line":"",modelValue:s.filename,"onUpdate:modelValue":e[0]||(e[0]=n=>s.filename=n),label:l.label.toUpperCase(),required:l.required,onClick:i.onFocus,rules:l.rules,disabled:l.disabled,ref:"fileTextField"},null,8,["modelValue","label","required","onClick","rules","disabled"]),o(c,{style:{margin:"0"},icon:"clear","aria-label":"Clear file input",onClick:e[1]||(e[1]=h(n=>i.clearInput(),["stop"]))}),m("input",{style:{position:"absolute",left:"-99999px"},type:"file",accept:l.accept,multiple:l.multiple,disabled:l.disabled,ref:"fileInput",onChange:e[2]||(e[2]=(...n)=>i.onFileChange&&i.onFileChange(...n))},null,40,b)]),_:1})}const k=r(g,[["render",V]]);export{k as default};