Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add theme toggle and Monospace font #2

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
<h1>Igor Costa.io</h1>

<p>Senior Architect @ GitHub</p>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Igor Costa.io</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
.dark-theme {
background-color: #333;
color: white;
}
.light-theme {
background-color: #FFF;
color: black;
}
.toggle-theme-btn {
position: fixed;
top: 10px;
right: 10px;
}
</style>
<script src="theme-toggle.js" defer></script>
</head>
<body>
<h1>Igor Costa.io</h1>
<p>Senior Architect @ GitHub</p>
<button id="theme-toggle" class="toggle-theme-btn">Toggle Theme</button>
</body>
</html>
25 changes: 25 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Function to toggle between dark and light theme
function toggleTheme() {
const body = document.body;
const currentTheme = localStorage.getItem('theme');
if (currentTheme === 'dark') {
body.classList.replace('dark-theme', 'light-theme');
localStorage.setItem('theme', 'light');
} else {
body.classList.replace('light-theme', 'dark-theme');
localStorage.setItem('theme', 'dark');
}
}

// Event listener for the theme toggle button
document.getElementById('theme-toggle').addEventListener('click', toggleTheme);

// Check local storage for theme preference and apply it
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-theme');
} else {
document.body.classList.add('light-theme');
}
});
42 changes: 42 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');

:root {
--dark-bg: #2b2d42;
--dark-text: #edf2f4;
--light-bg: #edf2f4;
--light-text: #2b2d42;
}

body {
font-family: 'Source Code Pro', monospace;
background: var(--light-bg);
color: var(--light-text);
transition: all 0.5s ease;
}

.dark-theme {
background: var(--dark-bg);
color: var(--dark-text);
}

.light-theme {
background: var(--light-bg);
color: var(--light-text);
}

.toggle-theme-btn {
position: fixed;
top: 20px;
right: 20px;
padding: 10px 20px;
background-color: #8d99ae;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.toggle-theme-btn:hover {
background-color: #4c5c68;
}
25 changes: 25 additions & 0 deletions theme-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Function to toggle between dark and light theme
function toggleTheme() {
const body = document.body;
const currentTheme = localStorage.getItem('theme');
if (currentTheme === 'dark') {
body.classList.replace('dark-theme', 'light-theme');
localStorage.setItem('theme', 'light');
} else {
body.classList.replace('light-theme', 'dark-theme');
localStorage.setItem('theme', 'dark');
}
}

// Event listener for the theme toggle button
document.getElementById('theme-toggle').addEventListener('click', toggleTheme);

// Check local storage for theme preference and apply it
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-theme');
} else {
document.body.classList.add('light-theme');
}
});