From e473b3031f2f8f9ee6e7b70389fef5fad566414d Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 14 Apr 2021 21:36:01 -0400 Subject: [PATCH] imageInput: adds clear button fixes urbit/landscape#785 --- .../src/views/components/ImageInput.tsx | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/pkg/interface/src/views/components/ImageInput.tsx b/pkg/interface/src/views/components/ImageInput.tsx index 447adf40c..58e361d3b 100644 --- a/pkg/interface/src/views/components/ImageInput.tsx +++ b/pkg/interface/src/views/components/ImageInput.tsx @@ -8,7 +8,8 @@ import { Button, Label, BaseInput, - Text + Text, + Icon } from '@tlon/indigo-react'; import useStorage from '~/logic/lib/useStorage'; @@ -84,6 +85,31 @@ const errorRetry = (meta, uploading, clickUploadButton) => { return null; }; +const clearButton = (field, uploading, clearEvt) => { + if (field.value && !uploading) { + return ( + + + + ); + } + return null; +}; + export function ImageInput(props: ImageInputProps): ReactElement { const { id, label, caption } = props; const { uploadDefault, canUpload, uploading } = useStorage(); @@ -107,6 +133,11 @@ export function ImageInput(props: ImageInputProps): ReactElement { const clickUploadButton = useCallback(() => { ref.current?.click(); }, [ref]); + + const clearEvt = useCallback(() => { + setValue(''); + }, []); + return ( @@ -117,6 +148,7 @@ export function ImageInput(props: ImageInputProps): ReactElement { ) : null} {prompt(field, uploading, meta, clickUploadButton)} + {clearButton(field, uploading, clearEvt)} {uploadingStatus(uploading, meta)} {errorRetry(meta, uploading, clickUploadButton)}