Skip to content

Commit

Permalink
Merge pull request #756 from Mat-icon/feat/HNG-ImageBody-team-bulldozer
Browse files Browse the repository at this point in the history
Feat/hng image body team bulldozer
  • Loading branch information
kleenpulse authored Jul 30, 2024
2 parents 74c10d5 + e424af3 commit 8a28599
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use client";

import Image from "next/image";
import React, { useState } from "react";

const ImageBody: React.FC = () => {
const [selectedImage, setSelectedImage] = useState<
string | ArrayBuffer | undefined
>();

const handleImageChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onloadend = () => {
setSelectedImage(reader.result ?? undefined);
};
reader.readAsDataURL(file);
}
};

return (
<div className="h-96 w-3/5 rounded-sm border bg-white shadow-md hover:border-orange-500">
<label className="flex flex-col items-center">
<div className="flex h-48 w-full cursor-pointer items-center justify-center bg-gray-50">
{selectedImage ? (
<Image
src={selectedImage as string}
alt="Selected"
className="h-full w-full object-contain"
width={192}
height={192}
/>
) : (
<div className="h-24 w-24">
<Image
src="/images/icon.png"
alt="Selected"
width={192}
height={192}
/>
</div>
)}
</div>
<input
type="file"
accept="image/*"
onChange={handleImageChange}
className="hidden"
/>
</label>
<div className="w-full p-5">
<h1 className="mt-6 text-center text-2xl font-semibold">
Welcome to Boilerplate!
</h1>
<p className="text-center text-gray-600">Thanks for signing up</p>
</div>
</div>
);
};

export default ImageBody;

0 comments on commit 8a28599

Please sign in to comment.