0.0.5 • Published 2 years ago

next-image-uploader v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Nextjs Image Uploader

Drag and drop image uploader for Nextjs.

Demo

Installation

pnpm add next-image-uploader

or

yarn add next-image-uploader

Usage

import React, { useState } from "react";
import ImageUploader from "react-image-uploader";

const App = () => {
	const [photo, setPhoto] = useState(null);

	return (
		<ImageUploader
			photo={photo}
			setPhoto={setPhoto}
			hoverIcon={hoverIcon}
			dropScope="window"
			onError={(error) => console.log(error)}
		/>
	);
};

export default App;

const hoverIcon = (
	<svg
		xmlns="http://www.w3.org/2000/svg"
		fill="none"
		viewBox="0 0 24 24"
		strokeWidth="1.5"
		stroke="currentColor"
		className="w-6 h-6"
	>
		<path
			strokeLinecap="round"
			strokeLinejoin="round"
			d="M6.827 6.175A2.31 2.31 0 015.186 7.23c-.38.054-.757.112-1.134.175C2.999 7.58 2.25 8.507 2.25 9.574V18a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9.574c0-1.067-.75-1.994-1.802-2.169a47.865 47.865 0 00-1.134-.175 2.31 2.31 0 01-1.64-1.055l-.822-1.316a2.192 2.192 0 00-1.736-1.039 48.774 48.774 0 00-5.232 0 2.192 2.192 0 00-1.736 1.039l-.821 1.316z"
		/>
		<path
			strokeLinecap="round"
			strokeLinejoin="round"
			d="M16.5 12.75a4.5 4.5 0 11-9 0 4.5 4.5 0 019 0zM18.75 10.5h.008v.008h-.008V10.5z"
		/>
	</svg>
);

Props

Main

NameTypeDefaultDescription
photostring''The preview image to be displayed.
setPhotofunctionnullThe callback function to receive the image.

Additional

NameTypeDefaultDescription
altstring'image'The alt text of the Image.
objectFitstring'cover'The object-fit property.
setFileNamefunctionnullThe callback func to get the file name.
setSizefunctionnullThe callback func to get the file size (width, height)
isFormikbooleanfalseIf true, the setPhoto will receive the file object instead of the base64 string.
getFileSizefunctionnullThe callback func to get the file size
disabledbooleanfalseIf true, the uploader will be disabled
inputRefReact.RefObjectnullThe ref of the input element, if you want to control the input element
classNamestring''The class name of the uploader's root
hoverIconReact.ReactNodenullThe icon to be displayed when hovering the uploader
dropScopestring'element'The drop area of the uploader. 'element' means the whole uploader, 'window' means the whole window.
onErrorfunctionnullThe callback func to handle the error.
onDraggingImagestringnullThe displayed image when dragging the image.
0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago