Skip to content

Commit

Permalink
feat: file upload accept camera
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed May 27, 2024
1 parent 54ac291 commit c07d2bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/app/src/components/profile/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export default function UpdateAvatar({
"image/png": [".png"],
"image/jpeg": [".jpg", ".jpeg"],
}}
acceptCamera
disabled={uploading}
/>
<Button color="primary" type="submit" isDisabled={uploading || !file} isLoading={uploading}>
Expand Down
10 changes: 9 additions & 1 deletion apps/app/src/components/ui/file-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type TFileUploadProps = Omit<
accept?: Accept //? See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
maxFiles?: number
dictionary: TDictionary<typeof FileUploadDr>
acceptCamera?: boolean
}

export default function FileUpload({
Expand All @@ -81,6 +82,7 @@ export default function FileUpload({
accept,
maxFiles,
dictionary,
acceptCamera,
...props
}: TFileUploadProps) {
const { acceptedFiles, getRootProps, getInputProps, isDragAccept, isDragReject } = useDropzone({
Expand Down Expand Up @@ -130,7 +132,13 @@ export default function FileUpload({
className
)}
>
<input type="file" {...getInputProps()} disabled={disabled} {...props} />
<input
type="file"
{...getInputProps()}
disabled={disabled}
accept={accept + (acceptCamera ? ";capture=camera" : "")}
{...props}
/>
<Upload className="size-12" />
<p className="text-center text-sm text-foreground/80">{dictionary.uploadDescription}</p>
</div>
Expand Down

0 comments on commit c07d2bc

Please sign in to comment.