diff options
author | Sebastian <sebasjm@gmail.com> | 2022-10-26 14:50:50 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-10-26 14:52:52 -0300 |
commit | b4bad2deaf93eff5858d903cd68b8fdd5a5eecd3 (patch) | |
tree | e6ead0edbd2b56cf9bcd8bc312fb07ed9280c5cc /packages/demobank-ui/src/components/fields/FileInput.tsx | |
parent | c34e71cf3de3da90d0d1662141aa1754a42ea37a (diff) | |
download | wallet-core-b4bad2deaf93eff5858d903cd68b8fdd5a5eecd3.tar.gz wallet-core-b4bad2deaf93eff5858d903cd68b8fdd5a5eecd3.tar.bz2 wallet-core-b4bad2deaf93eff5858d903cd68b8fdd5a5eecd3.zip |
pretty
Diffstat (limited to 'packages/demobank-ui/src/components/fields/FileInput.tsx')
-rw-r--r-- | packages/demobank-ui/src/components/fields/FileInput.tsx | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/packages/demobank-ui/src/components/fields/FileInput.tsx b/packages/demobank-ui/src/components/fields/FileInput.tsx index 17413b907..79cd76f30 100644 --- a/packages/demobank-ui/src/components/fields/FileInput.tsx +++ b/packages/demobank-ui/src/components/fields/FileInput.tsx @@ -18,8 +18,8 @@ * * @author Sebastian Javier Marchano (sebasjm) */ -import { h, VNode } from 'preact'; -import { useLayoutEffect, useRef, useState } from 'preact/hooks'; +import { h, VNode } from "preact"; +import { useLayoutEffect, useRef, useState } from "preact/hooks"; const MAX_IMAGE_UPLOAD_SIZE = 1024 * 1024; @@ -42,9 +42,7 @@ export interface FileInputProps { export function FileInput(props: FileInputProps): VNode { const inputRef = useRef<HTMLInputElement>(null); useLayoutEffect(() => { - if (props.grabFocus) - inputRef.current?.focus(); - + if (props.grabFocus) inputRef.current?.focus(); }, [props.grabFocus]); const fileInputRef = useRef<HTMLInputElement>(null); @@ -56,9 +54,7 @@ export function FileInput(props: FileInputProps): VNode { <div class="icon is-small "> <i class="mdi mdi-folder" /> </div> - <span> - {props.label} - </span> + <span>{props.label}</span> </a> {props.tooltip && ( <span class="icon has-tooltip-right" data-tooltip={props.tooltip}> @@ -69,15 +65,14 @@ export function FileInput(props: FileInputProps): VNode { <div class="control"> <input ref={fileInputRef} - style={{ display: 'none' }} + style={{ display: "none" }} type="file" // name={String(name)} onChange={(e) => { const f: FileList | null = e.currentTarget.files; - if (!f || f.length != 1) - return props.onChange(undefined); - - console.log(f) + if (!f || f.length != 1) return props.onChange(undefined); + + console.log(f); if (f[0].size > MAX_IMAGE_UPLOAD_SIZE) { setSizeError(true); return props.onChange(undefined); @@ -87,10 +82,14 @@ export function FileInput(props: FileInputProps): VNode { const b64 = btoa( new Uint8Array(b).reduce( (data, byte) => data + String.fromCharCode(byte), - '', + "", ), ); - return props.onChange({content: `data:${f[0].type};base64,${b64}`, name: f[0].name, type: f[0].type}); + return props.onChange({ + content: `data:${f[0].type};base64,${b64}`, + name: f[0].name, + type: f[0].type, + }); }); }} /> |