Sure, let’s refine the application based on your additional requirements:
- Move Delete Button: Position the delete button as an "X" icon next to the date and time on each note.
- Button Sizing and Spacing: Adjust the size and spacing of control buttons on the left side to be more compact and as per your initial request.
- Resizable Notes: Add a feature allowing notes to be resized, resembling Microsoft Sticky Notes, ensuring note resizing does not affect other notes.
- Font Size Control: Add icons for increasing and decreasing font size placed on the left side of each note.
Here is the updated version:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Notes</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 0;
display: flex;
}
.sidebar {
width: 150px;
flex-shrink: 0;
padding: 20px;
background-color: #f0f0f0;
display: flex;
flex-direction: column;
align-items: center;
}
.notes-container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
padding: 20px;
gap: 10px;
flex-grow: 1;
overflow-y: auto;
}
.note {
margin: 10px;
padding: 60px 20px 20px 20px;
border-radius: 5px 5px 5px 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 200px;
height: 200px;
position: relative;
overflow: hidden;
background-color: #FFFFD1;
resize: both;
min-height: 150px;
min-width: 150px;
display: flex;
flex-direction: column;
}
.note textarea {
width: 100%;
flex-grow: 1;
resize: none;
border: none;
background: transparent;
font-family: inherit;
outline: none;
}
.toolbar {
position: absolute;
top: 10px;
left: 10px;
display: flex;
gap: 5px;
}
.toolbar button img {
width: 20px;
height: 20px;
cursor: pointer;
background: none;
border: none;
color: #555;
}
.add-note-btn, .export-import button, .font-size-control button {
margin: 5px 0;
padding: 5px 10px;
font-size: 14px;
border: none;
border-radius: 5px;
cursor: pointer;
background-color: #4CAF50;
color: white;
width: 100%;
}
.color-picker-container {
display: flex;
gap: 5px;
margin-top: 10px;
}
.color-choice {
width: 20px;
height: 20px;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.date-time {
position: absolute;
top: 10px;
right: 40px;
font-size: 0.8em;
color: #555;
display: flex;
align-items: center;
}
.delete-note {
position: absolute;
top: 10px;
right: 10px;
background: none;
border: none;
cursor: pointer;
width: 20px;
height: 20px;
}
.font-size-control {
display: flex;
flex-direction: column;
gap: 5px;
position: absolute;
left: 5px;
top: 60px;
z-index: 1;
}
.font-size-control button {
width: 20px;
height: 20px;
background: none;
border: none;
color: #555;
cursor: pointer;
}
</style>
</head>
<body>
<div class="sidebar">
<button class="add-note-btn" onclick="addNote()">Add Note</button>
<div class="color-picker-container" id="color-picker-container">
<div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div>
<div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div>
<div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div>
<div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div>
<div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div>
<div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div>
<div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div>
</div>
<div class="export-import">
<button onclick="exportNotes()">Export</button>
<input type="file" id="importFile" onchange="importNotes()" style="display: none;">
<button onclick="document.getElementById('importFile').click()">Import</button>
</div>
</div>
<div id="notes-container" class="notes-container"></div>
<script>
let selectedColor = '#FFFFD1'; // pastel yellow default color
function addNote() {
const noteContainer = document.getElementById('notes-container');
const note = document.createElement('div');
note.className = 'note';
note.style.backgroundColor = selectedColor;
const toolbar = document.createElement('div');
toolbar.className = 'toolbar';
toolbar.innerHTML = `
<button onclick="document.execCommand('bold', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold">
</button>
<button onclick="document.execCommand('italic', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic">
</button>
<button onclick="document.execCommand('underline', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline">
</button>
`;
note.appendChild(toolbar);
const fontSizeControl = document.createElement('div');
fontSizeControl.className = 'font-size-control';
fontSizeControl.innerHTML = `
<button onclick="changeFontSize(this, '+')">+</button>
<button onclick="changeFontSize(this, '-')">-</button>
`;
note.appendChild(fontSizeControl);
const textarea = document.createElement('textarea');
textarea.placeholder = 'Enter your note here...';
textarea.style.fontSize = '16px';
textarea.oninput = function () {
this.style.height = 'auto';
this.style.height = this.scrollHeight + 'px';
};
note.appendChild(textarea);
const dateTime = document.createElement('div');
dateTime.className = 'date-time';
const now = new Date();
const formattedDate = now.toLocaleDateString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
const formattedTime = now.toLocaleTimeString('en-GB', {
hour: '2-digit',
minute: '2-digit',
hour12: true
});
dateTime.textContent = `${formattedDate} ${formattedTime}`;
note.appendChild(dateTime);
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-note';
deleteBtn.onclick = () => note.remove();
deleteBtn.innerHTML = `<img src="https://img.icons8.com/ios-filled/50/000000/delete-sign.png" alt="Delete" title="Delete">`;
note.appendChild(deleteBtn);
noteContainer.appendChild(note);
}
function selectColor(color) {
selectedColor = color || '#FFFFD1'; // default to pastel yellow
}
function changeFontSize(button, action) {
const note = button.closest('.note');
const textarea = note.querySelector('textarea');
const currentSize = parseInt(window.getComputedStyle(textarea).fontSize);
if (action === '+') {
textarea.style.fontSize = `${currentSize + 1}px`;
} else if (action === '-') {
textarea.style.fontSize = `${currentSize - 1}px`;
}
}
function exportNotes() {
let notesData = '';
const notes = document.querySelectorAll('.note textarea');
notes.forEach(note => {
notesData += note.value + '\n\n---\n\n';
});
const blob = new Blob([notesData], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'notes.txt';
a.click();
}
function importNotes() {
const fileInput = document.getElementById('importFile');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
const content = e.target.result;
const notesData = content.split('\n\n---\n\n');
notesData.forEach(text => {
if (text.trim()) {
const noteContainer = document.getElementById('notes-container');
const note = document.createElement('div');
note.className = 'note';
note.style.backgroundColor = selectedColor;
const toolbar = document.createElement('div');
toolbar.className = 'toolbar';
toolbar.innerHTML = `
<button onclick="document.execCommand('bold', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold">
</button>
<button onclick="document.execCommand('italic', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic">
</button>
<button onclick="document.execCommand('underline', false, '')">
<img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline">
</button>
`;
note.appendChild(toolbar);
const fontSizeControl = document.createElement('div');
fontSizeControl.className = 'font-size-control';
fontSizeControl.innerHTML = `
<button onclick="changeFontSize(this, '+')">+</button>
<button onclick="changeFontSize(this, '-')">-</button>
`;
note.appendChild(fontSizeControl);
const textarea = document.createElement('textarea');
textarea.value = text.trim();
textarea.style.fontSize = '16px';
note.appendChild(textarea);
const dateTime = document.createElement('div');
dateTime.className = 'date-time';
const now = new Date();
const formattedDate = now.toLocaleDateString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
const formattedTime = now.toLocaleTimeString('en-GB', {
hour: '2-digit',
minute: '2-digit',
hour12: true
});
dateTime.textContent = `${formattedDate} ${formattedTime}`;
note.appendChild(dateTime);
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-note';
deleteBtn.onclick = () => note.remove();
deleteBtn.innerHTML = `<img src="https://img.icons8.com/ios-filled/50/000000/delete-sign.png" alt="Delete" title="Delete">`;
note.appendChild(deleteBtn);
noteContainer.appendChild(note);
}
});
};
reader.readAsText(file);
}
}
</script>
</body>
</html>
Key Adjustments Made:
- Delete Button Relocation: Positioned an "X" icon to the top-right corner of each note for easy deletion.
- Left Sidebar Adjustments: Organized the add note, color picker, export, and import buttons in a fixed left sidebar for a more streamlined layout.
- Note Resizing: Implemented resizable notes with both width and height adjustable like Microsoft Sticky Notes, ensuring individual notes can resize independently.
- Font Size Control: Added "+" and "-" buttons for individual font resizing on each note.
- Compact Button Size and Layout: Buttons and icons were resized and organized for better user engagement and consistency.
These updates should make the app more interactive and user-friendly, emulating real-world sticky note utilities more closely. Let me know how it works for your needs!