|
1 | 1 | import { createElement } from "../lib/skeleton/index.js"; |
| 2 | +import { qs } from "../lib/dom.js"; |
2 | 3 | import { gid } from "../lib/random.js"; |
3 | 4 | import { ApplicationError } from "../lib/error.js"; |
4 | 5 |
|
@@ -267,14 +268,35 @@ export function $renderInput(options = {}) { |
267 | 268 | $img.setAttribute("src", value); |
268 | 269 | return $img; |
269 | 270 | } |
270 | | - case "file": { // TODO |
271 | | - return createElement(` |
272 | | - <input |
273 | | - type="password" |
274 | | - class="component_input" |
275 | | - readonly |
276 | | - /> |
| 271 | + case "file": { |
| 272 | + const $file = createElement(` |
| 273 | + <div className="fileupload-image"> |
| 274 | + <input |
| 275 | + type="file" |
| 276 | + class="component_input" |
| 277 | + /> |
| 278 | + <div class="preview" style="margin-top:-15px;"></div> |
| 279 | + </div> |
277 | 280 | `); |
| 281 | + const $preview = qs($file, ".preview"); |
| 282 | + const draw = (val) => { |
| 283 | + $preview.innerHTML = ""; |
| 284 | + if ((val || "").substring(0, 10) === "data:image") $preview.appendChild(createElement(` |
| 285 | + <img class="full-width" src="${val}" /> |
| 286 | + `)); |
| 287 | + else if ((val || "").substring(0, 20) === "data:application/pdf") $preview.appendChild(createElement(` |
| 288 | + <object class="full-width" type="application/pdf" data="${val}" style="height:250px;" /> |
| 289 | + `)); |
| 290 | + console.log("DRAW", $preview, (val || "").substring(0, 10)) |
| 291 | + }; |
| 292 | + qs($file, "input").onchange = (e) => { |
| 293 | + if (e.target.files.length === 0) return; |
| 294 | + const reader = new window.FileReader(); |
| 295 | + reader.readAsDataURL(e.target.files[0]); |
| 296 | + reader.onload = () => draw(reader.result); |
| 297 | + }; |
| 298 | + draw(value); |
| 299 | + return $file; |
278 | 300 | } |
279 | 301 | default: { |
280 | 302 | const $input = createElement(` |
|
0 commit comments