Creating a sleek dark mode diary app with multimodal input (text, images, and audio) requires a combination of HTML, CSS, and JavaScript. Below is a simple implementation that allows users to input text, upload images, and record audio. This example uses the Web Audio API for audio recording and basic HTML5 features for file uploads.
Here's the complete code:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dark Mode Diary App</title>
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
.diary-entry {
background-color: #1e1e1e;
border-radius: 8px;
padding: 20px;
margin: 10px 0;
}
textarea {
width: 100%;
height: 100px;
border: none;
border-radius: 4px;
padding: 10px;
background-color: #2a2a2a;
color: #ffffff;
}
input[type="file"] {
margin: 10px 0;
}
button {
background-color: #6200ea;
color: #ffffff;
border: none;
border-radius: 4px;
padding: 10px 15px;
cursor: pointer;
}
button:hover {
background-color: #3700b3;
}
.audio-controls {
display: none;
margin-top: 10px;
}
.audio-controls button {
margin-right: 10px;
}
</style>
</head>
<body>
<h1>Diary App</h1>
<div class="diary-entry">
<textarea id="diaryText" placeholder="Write your diary entry..."></textarea>
<input type="file" id="imageInput" accept="image/*">
<div class="audio-controls">
<button id="startRecording">Start Recording</button>
<button id="stopRecording" disabled>Stop Recording</button>
<audio id="audioPlayback" controls></audio>
</div>
<button id="addEntry">Add Entry</button>
</div>
<div id="entries"></div>
<script>
let mediaRecorder;
let audioChunks = [];
document.getElementById('imageInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const img = document.createElement('img');
img.src = URL.createObjectURL(file);
img.style.width = '100%';
img.style.borderRadius = '4px';
document.getElementById('entries').appendChild(img);
}
});
document.getElementById('startRecording').addEventListener('click', async () => {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();
mediaRecorder.ondataavailable = event => {
audioChunks.push(event.data);
};
mediaRecorder.onstop = () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const audioUrl = URL.createObjectURL(audioBlob);
const audio = document.getElementById('audioPlayback');
audio.src = audioUrl;
audioChunks = [];
};
document.getElementById('startRecording').disabled = true;
document.getElementById('stopRecording').disabled = false;
});
document.getElementById('stopRecording').addEventListener('click', () => {
mediaRecorder.stop();
document.getElementById('startRecording').disabled = false;
document.getElementById('stopRecording').disabled = true;
});
document.getElementById('addEntry').addEventListener('click', () => {
const text = document.getElementById('diaryText').value;
const audio = document.getElementById('audioPlayback').src;
if (text || audio) {
const entryDiv = document.createElement('div');
entryDiv.className = 'diary-entry';
entryDiv.innerHTML = `<p>${text}</p>`;
if (audio) {
const audioElement = document.createElement('audio');
audioElement.src = audio;
audioElement.controls = true;
entryDiv.appendChild(audioElement);
}
document.getElementById('entries').appendChild(entryDiv);
document.getElementById('diaryText').value = '';
document.getElementById('audioPlayback').src = '';
}
});
</script>
</body>
</html>
Explanation:
HTML Structure : The app consists of a title, a text area for diary entries, an image upload input, and audio recording controls.
CSS Styles : The styles are designed for a dark mode theme, with a sleek and modern look.
JavaScript Functionality :
Image Upload : When an image is uploaded, it is displayed below the diary entry.
Audio Recording : Users can start and stop audio recording. The recorded audio can be played back and is attached to the diary entry.
Diary Entry Submission : When the "Add Entry" button is clicked, the text, image, and audio are compiled into a new diary entry displayed below.
Note:
This code is a basic implementation and can be expanded with features like saving entries to local storage, editing, deleting entries, and more.
Ensure that you test this code in a secure context (like localhost or HTTPS) as some features (like audio recording) require it.