-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
419 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Button } from '@/components/ui/Button' | ||
import { createElement } from '@/utils' | ||
import { ImageIcon } from 'lucide-react' | ||
|
||
export interface ImageButtonProps { | ||
onSelect?: (file: File) => void | ||
disabled?: boolean | ||
} | ||
|
||
const ImageButton = ({ onSelect, disabled }: ImageButtonProps) => { | ||
const handleClick = () => { | ||
const input = createElement<HTMLInputElement>(`<input type="file" accept="image/png,image/jpeg,image/webp" />`) | ||
|
||
input.addEventListener( | ||
'change', | ||
async (e: Event) => { | ||
onSelect?.((e.target as HTMLInputElement).files![0]) | ||
}, | ||
{ once: true } | ||
) | ||
|
||
input.click() | ||
} | ||
|
||
return ( | ||
<Button disabled={disabled} onClick={handleClick} variant="ghost" size="icon" className="dark:text-white"> | ||
<ImageIcon size={20} /> | ||
</Button> | ||
) | ||
} | ||
|
||
ImageButton.displayName = 'ImageButton' | ||
|
||
export default ImageButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const blobToBase64 = (blob: Blob) => { | ||
return new Promise<string>((resolve, reject) => { | ||
const reader = new FileReader() | ||
reader.onload = (e) => resolve(e.target?.result as string) | ||
reader.onerror = () => reject(new Error('Failed to read file.')) | ||
reader.readAsDataURL(blob) | ||
}) | ||
} | ||
|
||
export default blobToBase64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters