@@ -3,7 +3,7 @@ import { useTheme } from '@emotion/react';
33import styled from '@emotion/styled' ;
44
55import { Button } from '@/ui/button/components/Button' ;
6- import { IconFileUpload , IconTrash , IconUpload } from '@/ui/icon' ;
6+ import { IconFileUpload , IconTrash , IconUpload , IconX } from '@/ui/icon' ;
77
88const StyledContainer = styled . div `
99 display: flex;
@@ -67,6 +67,12 @@ const StyledText = styled.span`
6767 font-size: ${ ( { theme } ) => theme . font . size . xs } ;
6868` ;
6969
70+ const StyledErrorText = styled . span `
71+ color: ${ ( { theme } ) => theme . font . color . danger } ;
72+ font-size: ${ ( { theme } ) => theme . font . size . xs } ;
73+ margin-top: ${ ( { theme } ) => theme . spacing ( 1 ) } ;
74+ ` ;
75+
7076const StyledHiddenFileInput = styled . input `
7177 display: none;
7278` ;
@@ -76,7 +82,8 @@ type Props = Omit<React.ComponentProps<'div'>, 'children'> & {
7682 onUpload ?: ( file : File ) => void ;
7783 onRemove ?: ( ) => void ;
7884 onAbort ?: ( ) => void ;
79- error ?: Error | null ;
85+ isUploading ?: boolean ;
86+ errorMessage ?: string | null ;
8087 disabled ?: boolean ;
8188} ;
8289
@@ -85,7 +92,8 @@ export function ImageInput({
8592 onUpload,
8693 onRemove,
8794 onAbort,
88- error,
95+ isUploading = false ,
96+ errorMessage,
8997 disabled = false ,
9098 ...restProps
9199} : Props ) {
@@ -125,37 +133,38 @@ export function ImageInput({
125133 }
126134 } }
127135 />
128- < Button
129- icon = { < IconUpload size = { theme . icon . size . sm } /> }
130- onClick = { onUploadButtonClick }
131- variant = "secondary"
132- title = "Upload"
133- disabled = { disabled }
134- fullWidth
135- />
136- < Button
137- icon = { < IconTrash size = { theme . icon . size . sm } /> }
138- onClick = { onRemove }
139- variant = "secondary"
140- title = "Remove"
141- disabled = { ! picture || disabled }
142- fullWidth
143- />
144- { onAbort && (
136+ { isUploading && onAbort ? (
145137 < Button
146- icon = { < IconTrash size = { theme . icon . size . sm } /> }
138+ icon = { < IconX /> }
147139 onClick = { onAbort }
148140 variant = "secondary"
149141 title = "Abort"
150142 disabled = { ! picture || disabled }
151143 fullWidth
152144 />
145+ ) : (
146+ < Button
147+ icon = { < IconUpload /> }
148+ onClick = { onUploadButtonClick }
149+ variant = "secondary"
150+ title = "Upload"
151+ disabled = { disabled }
152+ fullWidth
153+ />
153154 ) }
155+ < Button
156+ icon = { < IconTrash /> }
157+ onClick = { onRemove }
158+ variant = "secondary"
159+ title = "Remove"
160+ disabled = { ! picture || disabled }
161+ fullWidth
162+ />
154163 </ StyledButtonContainer >
155164 < StyledText >
156165 We support your best PNGs, JPEGs and GIFs portraits under 10MB
157166 </ StyledText >
158- { error && < StyledText > { error . message } </ StyledText > }
167+ { errorMessage && < StyledErrorText > { errorMessage } </ StyledErrorText > }
159168 </ StyledContent >
160169 </ StyledContainer >
161170 ) ;
0 commit comments