generated from zayne-labs/create-ts-library
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add handleImagePreview function
feat(core): add FileValidationOptions and related types feat(core): export handleFileValidation and handleImagePreview feat(toolkit): add tailwind config chore(deps): update dependencies
- Loading branch information
1 parent
c2cfa6e
commit 9f56ef9
Showing
11 changed files
with
652 additions
and
619 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@zayne-labs/toolkit": minor | ||
--- | ||
|
||
feat(core): add handleImagePreview function | ||
feat(core): add FileValidationOptions and related types | ||
feat(core): export handleFileValidation and handleImagePreview | ||
feat(toolkit): add tailwind config | ||
chore(deps): update dependencies |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { isFile } from "@/type-helpers"; | ||
|
||
export type ImagePreviewOptions = { | ||
file: File | undefined; | ||
onError?: (ctx: { error: DOMException | null }) => void; | ||
onSuccess?: (ctx: { result: string }) => void; | ||
resultType?: "base64" | "objectURL"; | ||
}; | ||
|
||
function handleImagePreview(options: { | ||
file: File | undefined; | ||
onError?: never; | ||
onSuccess?: (ctx: { result: string }) => void; | ||
resultType?: "objectURL"; | ||
}): string; | ||
|
||
function handleImagePreview(options: { | ||
file: File | undefined; | ||
onError?: (ctx: { error: DOMException | null }) => void; | ||
onSuccess: (ctx: { result: string }) => void; | ||
resultType: "base64"; | ||
}): void; | ||
|
||
function handleImagePreview(options: ImagePreviewOptions) { | ||
const { file, onError, onSuccess, resultType = "objectURL" } = options; | ||
|
||
if (!isFile(file)) return; | ||
|
||
if (resultType === "objectURL") { | ||
const result = URL.createObjectURL(file); | ||
|
||
onSuccess?.({ result }); | ||
|
||
return result; | ||
} | ||
|
||
const reader = new FileReader(); | ||
|
||
reader.addEventListener("load", () => { | ||
if (!reader.result) return; | ||
|
||
onSuccess?.({ result: reader.result as string }); | ||
}); | ||
|
||
reader.addEventListener("error", () => { | ||
onError?.({ error: reader.error }); | ||
}); | ||
|
||
reader.readAsDataURL(file); | ||
|
||
return reader.result as string; | ||
} | ||
|
||
export { handleImagePreview }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Config } from "tailwindcss"; | ||
|
||
const config = { | ||
content: ["./src/react/hooks/**/*.ts"], | ||
} satisfies Config; | ||
|
||
export default config; |
Oops, something went wrong.