Latest Commit
This commit is contained in:
parent
9d46932584
commit
517d4a94ec
|
@ -9,7 +9,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Sticky Note App</title>
|
||||
</head>
|
||||
<body>
|
||||
<body class="bg-gradient-to-r from-yellow-200 to-amber-400 h-full">
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
|
|
868
package-lock.json
generated
868
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,7 @@ function App() {
|
|||
<div className="font-poppins">
|
||||
<StickyNote />
|
||||
</div>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
192
src/assets/SvgIcons/SvgIcons.jsx
Normal file
192
src/assets/SvgIcons/SvgIcons.jsx
Normal file
|
@ -0,0 +1,192 @@
|
|||
/* eslint-disable react/no-unknown-property */
|
||||
const addNote = (
|
||||
<svg
|
||||
width="20px"
|
||||
height="20px"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22ZM12 8.25C12.4142 8.25 12.75 8.58579 12.75 9V11.25H15C15.4142 11.25 15.75 11.5858 15.75 12C15.75 12.4142 15.4142 12.75 15 12.75H12.75L12.75 15C12.75 15.4142 12.4142 15.75 12 15.75C11.5858 15.75 11.25 15.4142 11.25 15V12.75H9C8.58579 12.75 8.25 12.4142 8.25 12C8.25 11.5858 8.58579 11.25 9 11.25H11.25L11.25 9C11.25 8.58579 11.5858 8.25 12 8.25Z"
|
||||
fill="#1C274C"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const showNotes = (
|
||||
<svg
|
||||
fill="#000000"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
xmlns:x="&ns_extend;"
|
||||
xmlns:i="&ns_ai;"
|
||||
xmlns:graph="&ns_graphs;"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="20px"
|
||||
height="20px"
|
||||
viewBox="0 0 24 24"
|
||||
enableBackground="new 0 0 24 24"
|
||||
xml:space="preserve"
|
||||
>
|
||||
<metadata>
|
||||
<sfw xmlns="&ns_sfw;">
|
||||
<slices></slices>
|
||||
<sliceSourceBounds
|
||||
width="505"
|
||||
height="984"
|
||||
bottomLeftOrigin="true"
|
||||
x="0"
|
||||
y="-120"
|
||||
></sliceSourceBounds>
|
||||
</sfw>
|
||||
</metadata>
|
||||
<g>
|
||||
<g>
|
||||
<g>
|
||||
<path
|
||||
d="M20,24H4c-2.2,0-4-1.8-4-4V4c0-2.2,1.8-4,4-4h16c2.2,0,4,1.8,4,4v16C24,22.2,22.2,24,20,24z M4,2C2.9,2,2,2.9,2,4v16
|
||||
c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V4c0-1.1-0.9-2-2-2H4z"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path d="M23,9H1C0.4,9,0,8.6,0,8s0.4-1,1-1h22c0.6,0,1,0.4,1,1S23.6,9,23,9z" />
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<g>
|
||||
<path
|
||||
d="M12,18c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l3-3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-3,3C12.5,17.9,12.3,18,12,18
|
||||
z"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path
|
||||
d="M12,18c-0.3,0-0.5-0.1-0.7-0.3l-3-3c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l3,3c0.4,0.4,0.4,1,0,1.4C12.5,17.9,12.3,18,12,18
|
||||
z"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const hideNotes = (
|
||||
<svg
|
||||
fill="#000000"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
xmlns:x="&ns_extend;"
|
||||
xmlns:i="&ns_ai;"
|
||||
xmlns:graph="&ns_graphs;"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="20px"
|
||||
height="20px"
|
||||
viewBox="0 0 24 24"
|
||||
enable-background="new 0 0 24 24"
|
||||
xml:space="preserve"
|
||||
>
|
||||
<metadata>
|
||||
<sfw xmlns="&ns_sfw;">
|
||||
<slices></slices>
|
||||
<sliceSourceBounds
|
||||
width="505"
|
||||
height="984"
|
||||
bottomLeftOrigin="true"
|
||||
x="0"
|
||||
y="-120"
|
||||
></sliceSourceBounds>
|
||||
</sfw>
|
||||
</metadata>
|
||||
<g>
|
||||
<g>
|
||||
<g>
|
||||
<path
|
||||
d="M20,24H4c-2.2,0-4-1.8-4-4V4c0-2.2,1.8-4,4-4h16c2.2,0,4,1.8,4,4v16C24,22.2,22.2,24,20,24z M4,2C2.9,2,2,2.9,2,4v16
|
||||
c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V4c0-1.1-0.9-2-2-2H4z"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path d="M23,9H1C0.4,9,0,8.6,0,8s0.4-1,1-1h22c0.6,0,1,0.4,1,1S23.6,9,23,9z" />
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path
|
||||
d="M15,18c-0.3,0-0.5-0.1-0.7-0.3l-3-3c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l3,3c0.4,0.4,0.4,1,0,1.4C15.5,17.9,15.3,18,15,18z
|
||||
"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path d="M9,18c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l3-3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-3,3C9.5,17.9,9.3,18,9,18z" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const saveNote = (
|
||||
<svg
|
||||
fill="#000000"
|
||||
width="30px"
|
||||
height="30px"
|
||||
viewBox="0 0 30 30"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M6.494 13.994c-.45 0-.67.547-.348.86l8 8c.188.186.488.195.686.02l9-8c.547-.44-.164-1.24-.664-.747l-8.648 7.685-7.666-7.666c-.095-.097-.224-.152-.36-.152zM14.5 2c.277 0 .5.223.5.5v18c0 .277-.223.5-.5.5s-.5-.223-.5-.5v-18c0-.277.223-.5.5-.5zM.5 22c-.276.004-.504.224-.5.5v4c0 .822.678 1.5 1.5 1.5h27c.822 0 1.5-.678 1.5-1.5v-4c.01-.66-1-.657-1 0v4c0 .286-.214.5-.5.5h-27c-.286 0-.5-.214-.5-.5v-4c.004-.282-.218-.504-.5-.5z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
const deleteNote = (
|
||||
<svg
|
||||
width="30px"
|
||||
height="30px"
|
||||
viewBox="0 0 1024 1024"
|
||||
fill="#000000"
|
||||
class="icon"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M32 241.6c-11.2 0-20-8.8-20-20s8.8-20 20-20l940 1.6c11.2 0 20 8.8 20 20s-8.8 20-20 20L32 241.6zM186.4 282.4c0-11.2 8.8-20 20-20s20 8.8 20 20v688.8l585.6-6.4V289.6c0-11.2 8.8-20 20-20s20 8.8 20 20v716.8l-666.4 7.2V282.4z"
|
||||
fill=""
|
||||
/>
|
||||
<path
|
||||
d="M682.4 867.2c-11.2 0-20-8.8-20-20V372c0-11.2 8.8-20 20-20s20 8.8 20 20v475.2c0.8 11.2-8.8 20-20 20zM367.2 867.2c-11.2 0-20-8.8-20-20V372c0-11.2 8.8-20 20-20s20 8.8 20 20v475.2c0.8 11.2-8.8 20-20 20zM524.8 867.2c-11.2 0-20-8.8-20-20V372c0-11.2 8.8-20 20-20s20 8.8 20 20v475.2c0.8 11.2-8.8 20-20 20zM655.2 213.6v-48.8c0-17.6-14.4-32-32-32H418.4c-18.4 0-32 14.4-32 32.8V208h-40v-42.4c0-40 32.8-72.8 72.8-72.8H624c40 0 72.8 32.8 72.8 72.8v48.8h-41.6z"
|
||||
fill=""
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const editNote = (
|
||||
<svg
|
||||
width="25px"
|
||||
height="25px"
|
||||
viewBox="0 0 1024 1024"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M832 512a32 32 0 1 1 64 0v352a32 32 0 0 1-32 32H160a32 32 0 0 1-32-32V160a32 32 0 0 1 32-32h352a32 32 0 0 1 0 64H192v640h640V512z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="m469.952 554.24 52.8-7.552L847.104 222.4a32 32 0 1 0-45.248-45.248L477.44 501.44l-7.552 52.8zm422.4-422.4a96 96 0 0 1 0 135.808l-331.84 331.84a32 32 0 0 1-18.112 9.088L436.8 623.68a32 32 0 0 1-36.224-36.224l15.104-105.6a32 32 0 0 1 9.024-18.112l331.904-331.84a96 96 0 0 1 135.744 0z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
export { addNote, showNotes, saveNote, deleteNote, editNote, hideNotes };
|
|
@ -1,11 +1,21 @@
|
|||
/* eslint-disable react/prop-types */
|
||||
import { useState } from "react";
|
||||
import { saveNote, deleteNote, editNote } from "../../assets/SvgIcons/SvgIcons";
|
||||
|
||||
const Card = ({ onDelete, onSave, id }) => {
|
||||
const [content, setContent] = useState("");
|
||||
const Card = ({ onDelete, onSave, id, content: initialContent }) => {
|
||||
const [content, setContent] = useState(initialContent || "");
|
||||
const [isEditing, setIsEditing] = useState(true);
|
||||
const [saved, setSaved] = useState(false);
|
||||
|
||||
const handleSave = () => {
|
||||
onSave(id, content);
|
||||
setIsEditing(false);
|
||||
setSaved(true);
|
||||
setTimeout(() => setSaved(false), 3000);
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
setIsEditing(true);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -13,25 +23,45 @@ const Card = ({ onDelete, onSave, id }) => {
|
|||
<div>
|
||||
<textarea
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
onChange={(e) => setContent(e?.target?.value)}
|
||||
placeholder="Write your note here..."
|
||||
className="flex items-center bg-yellow-200 rounded focus:outline-0 w-full p-2 placeholder-black"
|
||||
readOnly={!isEditing}
|
||||
className={`flex items-center justify-normal bg-yellow-200 rounded focus:outline-0 w-full p-2 placeholder-black ${
|
||||
isEditing
|
||||
? "border-none "
|
||||
: "bg-yellow-200 cursor-not-allowed border border-gray-400"
|
||||
}`}
|
||||
//Reference
|
||||
></textarea>
|
||||
{saved && <p className="text-green-600 text-sm mt-2">Note Saved</p>}
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<div className="flex justify-between gap-4">
|
||||
{isEditing ? (
|
||||
<>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
className="flex px-4 py-2 items-center bg-blue-600 text-white text-xs font-bold uppercase rounded hover:bg-blue-500 focus:outline-none mt-4"
|
||||
onClick={() => {
|
||||
handleSave();
|
||||
}}
|
||||
className="flex px-4 py-2 items-center bg-blue-600 text-white text-xs font-bold uppercase rounded hover:bg-blue-500 focus:outline-none mt-4 gap-3"
|
||||
>
|
||||
Save Note
|
||||
Save Note {saveNote}
|
||||
</button>
|
||||
<button
|
||||
onClick={onDelete}
|
||||
className="flex px-4 py-2 items-center bg-red-500 text-white text-xs font-bold uppercase rounded hover:bg-red-400 focus:outline-none mt-4"
|
||||
className="flex px-4 py-2 items-center bg-red-500 text-white text-xs font-bold uppercase rounded hover:bg-red-400 focus:outline-none mt-4 gap-3"
|
||||
>
|
||||
Delete Note
|
||||
Delete Note {deleteNote}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleEdit}
|
||||
className="flex px-4 py-2 items-center bg-gray-600 text-white text-xs font-bold uppercase rounded hover:bg-gray-500 focus:outline-none mt-4 gap-3"
|
||||
>
|
||||
Edit Note {editNote}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,71 +1,102 @@
|
|||
import { useState } from "react";
|
||||
import ReusableCard from "../reusableCard/index";
|
||||
import { useState, useEffect } from "react";
|
||||
import Card from "../reusableCard/index";
|
||||
import { addNote, showNotes, hideNotes } from "../../assets/SvgIcons/SvgIcons";
|
||||
|
||||
// const StickyNote = () => {
|
||||
// const [notes, setNotes] = useState([]);
|
||||
// const [showNote, setShowNote] = useState(false);
|
||||
|
||||
|
||||
|
||||
const StickyNote = () => {
|
||||
const StickyNote = () => {
|
||||
const [notes, setNotes] = useState([]);
|
||||
const [showNote, setShowNote] = useState(false);
|
||||
const [showNote, setShowNote] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const savedNotes = JSON?.parse(localStorage?.getItem("stickyNotes")) || [];
|
||||
setNotes(savedNotes);
|
||||
}, []);
|
||||
|
||||
const handleShowNote = () => {
|
||||
setShowNote(!showNote);
|
||||
};
|
||||
|
||||
const handleAddNote = () => {
|
||||
setNotes([...notes, {id: Date.now(), content: ""}]);
|
||||
setNotes([...notes, { id: Date.now(), content: "" }]); //Reference
|
||||
};
|
||||
|
||||
const handleDeleteNote = (id) => {
|
||||
setNotes(notes.filter((note) => note.id !== id));
|
||||
setNotes(notes?.filter((note) => note?.id !== id));
|
||||
};
|
||||
|
||||
const handleSaveNote = (id, content) => {
|
||||
setNotes(
|
||||
notes.map((note) =>
|
||||
note.id === id ? {...note, content} : note
|
||||
)
|
||||
let notesData = notes?.map((note) =>
|
||||
note?.id === id ? { ...note, content } : note
|
||||
);
|
||||
setNotes(notesData);
|
||||
localStorage?.setItem("stickyNotes", JSON.stringify(notes));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="bg-yellow-300 h-30 sm:h-20 w-full text-center text-4xl">
|
||||
<p className="uppercase py-4 font-bold">Sticky Notes Application</p>
|
||||
<div className=" h-30 sm:h-20 w-full text-center text-4xl transition scale-110">
|
||||
<p className="uppercase py-8 font-bold scale-110 cursor-pointer">Sticky Notes Application</p>
|
||||
</div>
|
||||
<hr className="h-0.5 mx-auto my-4 bg-gray-100 border-0 rounded md:my-5 dark:bg-gray-700" />
|
||||
<div className="p-6 gap-10 flex justify-center">
|
||||
<button
|
||||
onClick={handleAddNote}
|
||||
className="border border-gray-600 bg-gray-200 rounded p-2 hover:bg-gray-500 hover:text-white transition delay-0 flex items-center justify-center"
|
||||
>
|
||||
Add Note
|
||||
<button onClick={handleAddNote} className="">
|
||||
<div className="relative inline-flex items-center justify-center p-4 px-6 py-3 overflow-hidden font-medium text-white transition duration-300 ease-out border-2 border-black rounded-full shadow-md group">
|
||||
<span className="absolute inset-0 flex items-center justify-center w-full h-full text-white duration-300 -translate-x-full bg-green-600 group-hover:translate-x-0 ease">
|
||||
{addNote}
|
||||
</span>
|
||||
<span className="absolute flex items-center justify-center w-full h-full text-black bg-gradient-to-r from-green-600 to-amber-300 transition-all duration-300 transform group-hover:translate-x-full ease">
|
||||
Add note
|
||||
</span>
|
||||
<span className="relative invisible">Add Note</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={handleShowNote}
|
||||
className="border border-gray-600 bg-gray-200 rounded p-2 hover:bg-gray-500 hover:text-white transition delay-0 flex items-center justify-center"
|
||||
onClick={() => {
|
||||
handleShowNote();
|
||||
}}
|
||||
className=""
|
||||
>
|
||||
Show Notes
|
||||
<div className="relative inline-flex items-center justify-center p-4 px-5 py-3 overflow-hidden border-2 border-black font-medium text-green-400 transition duration-300 ease-out rounded-full shadow-xl group hover:ring-green-950">
|
||||
<span className="absolute inset-0 w-full h-full bg-gradient-to-br from-green-100- via-green-600 to-green-100"></span>
|
||||
<span className="absolute bottom-0 right-0 block w-64 h-64 mb-32 mr-4 transition duration-500 origin-bottom-left transform rotate-45 translate-x-24 bg-green-600 rounded-full opacity-30 group-hover:rotate-90 ease"></span>
|
||||
<span className="relative text-black">
|
||||
{showNote ? (
|
||||
<>
|
||||
<span className="flex justify-between gap-3">
|
||||
Hide Notes {hideNotes}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="flex justify-between gap-3">
|
||||
Show Notes {showNotes}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
{showNote && (
|
||||
<div className="p-10 flex flex-wrap gap-10">
|
||||
|
||||
{notes.map((note) => (
|
||||
<ReusableCard
|
||||
key={note.id}
|
||||
id={note.id}
|
||||
onDelete={() => handleDeleteNote(note.id)}
|
||||
{notes?.length > 0 ? (
|
||||
notes
|
||||
?.filter((note) => note?.content || showNote)
|
||||
?.map((note) => (
|
||||
<Card
|
||||
key={note?.id}
|
||||
id={note?.id}
|
||||
content={note?.content}
|
||||
onDelete={() => handleDeleteNote(note?.id)}
|
||||
onSave={handleSaveNote}
|
||||
/>
|
||||
|
||||
))}
|
||||
|
||||
))
|
||||
) : (
|
||||
<div className="w-full text-center justify-center text-xl text-gray-600">
|
||||
No Notes are available. Click on <b>"Add Note button"</b>{" "}
|
||||
above to add
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue