Skip to content

Commit

Permalink
feat(file): add file input
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadreza1388 committed Jan 6, 2025
1 parent f37e371 commit 984f954
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/components/header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
import Dropdown from "../shared/dropdown/Dropdown.jsx";
import DropdownItem from "../shared/dropdown/DropdownItem.jsx";
import {useState} from "react";

const Header = () => {
const [fileContent, setFileContent] = useState("");

const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
if (file.type === "text/plain") {
const reader = new FileReader();
reader.onload = (e) => {
console.log("File content:", e.target.result);
setFileContent(e.target.result);
};
reader.readAsText(file);
} else {

}
}
};

const openFilePicker = () => {
document.getElementById("fileInput").click();
};


return (<>
<header className={"header bg-[#ffdecc] h-[35px] w-[100vw] flex justify-start items-center pr-[75px] gap-[20px]"}>
<header
className={"header bg-[#ffdecc] h-[35px] w-[100vw] flex justify-start items-center pr-[75px] gap-[20px]"}>
<Dropdown title={"اسناد"}>
<DropdownItem title={"باز کردن فایل"} />
<DropdownItem title={"باز کردن فایل"} />
<DropdownItem title={"باز کردن فایل"} callback={() => {
openFilePicker()
}}/>
</Dropdown>
</header>
<input
type="file"
id="fileInput"
style={{display: "none"}}
className={"hidden"}
onChange={handleFileChange}
/>
</>)
}

Expand Down

0 comments on commit 984f954

Please sign in to comment.