Skip to content

Commit

Permalink
add dark mode in contributors page
Browse files Browse the repository at this point in the history
  • Loading branch information
ANKeshri committed Jul 24, 2024
1 parent 53f45aa commit 6aa13b7
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
122 changes: 121 additions & 1 deletion contributors.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,124 @@ body {
.contributor-card p {
color: #666;
}

/* Toggle button styles */
.toggle-container {
position: fixed; /* Change this as needed for positioning */
top: 25px;
right: 40px;
}

.toggle {
width: 50px; /* Adjust size as needed */
height: 25px; /* Adjust size as needed */
appearance: none;
background-color: #ccc;
cursor: pointer;
border-radius: 25px;
position: relative;
outline: none;
}

.toggle:checked {
background-color: #333;
}
.toggle:checked:before {
transform: translateX(25px);
}


body {
background-color: #f8f9fa;
color: #212529;
}

.nav-container {
background-color: #ffffff;
}

.footer {
background-color: #ffffff;
color: #212529;
}

/* Dark mode styles */
body.dark-mode {
background-color: #333;
color: #ffffff;
}

body.dark-mode .nav-container {
background-color: #343a40;
}

body.dark-mode .footer {
background-color: #343a40;
color: #ffffff;
}
#toggle {
display: inline-block;
border-radius: 50px;
transition: all 0.4s ease-in-out;
padding: 10px 10px;
background-color: transparent;
border: 2px solid #c6c9d8bf;
color: #c6c9d8bf;
font-weight: 600;
font-size: 14px;
letter-spacing: 2px;
text-decoration: none;
}
.toggle-container {
--size: 2rem;
width: var(--size);
height: var(--size);
}

.toggle {
appearance: none;
outline: none;
cursor: pointer;
width: 100%;
height: 100%;
box-shadow: inset calc(var(--size) * 0.33) calc(var(--size) * -0.25) 0;
border-radius: 999px;
color: hsl(240, 100%, 95%);
transition: all 500ms;
position: absolute;
top: 0;
right: 0;

&:checked {
--ray-size: calc(var(--size) * -0.4);
--offset-orthogonal: calc(var(--size) * 0.65);
--offset-diagonal: calc(var(--size) * 0.45);
transform: scale(0.75);
color: hsl(40, 100%, 50%);
box-shadow: inset 0 0 0 var(--size),
calc(var(--offset-orthogonal) * -1) 0 0 var(--ray-size),
var(--offset-orthogonal) 0 0 var(--ray-size),
0 calc(var(--offset-orthogonal) * -1) 0 var(--ray-size),
0 var(--offset-orthogonal) 0 var(--ray-size),
calc(var(--offset-diagonal) * -1) calc(var(--offset-diagonal) * -1) 0
var(--ray-size),
var(--offset-diagonal) var(--offset-diagonal) 0 var(--ray-size),
calc(var(--offset-diagonal) * -1) var(--offset-diagonal) 0 var(--ray-size),
var(--offset-diagonal) calc(var(--offset-diagonal) * -1) 0 var(--ray-size);
}
}

/* Apply fade-down animation to the toggle container */
.toggle-container[data-aos="fade-down"] {
transition: opacity 500ms ease-in-out;
opacity: 0;
}

.toggle-container[data-aos="fade-down"].aos-animate {
opacity: 1;
}
body.dark-mode .contributor-card{
background: #212529;
}
body.dark-mode .contributor-card p{
color: white;
}
3 changes: 3 additions & 0 deletions contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</head>
<body>
<div class="container">
<div class="toggle-container aos-init aos-animate" data-aos="fade-down">
<input id="themeToggle" class="toggle" type="checkbox">
</div>
<h1 class="title">Contributors</h1>
<div id="contributors" class="contributors-grid"></div>
</div>
Expand Down
23 changes: 22 additions & 1 deletion contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,25 @@ document.addEventListener('DOMContentLoaded', () => {

fetchContributors();
});

document.addEventListener('DOMContentLoaded', () => {
const toggleCheckbox = document.getElementById('themeToggle');
const body = document.body;

// Load saved dark mode preference from localStorage
if (localStorage.getItem('dark-mode') === 'enabled') {
body.classList.add('dark-mode');
toggleCheckbox.checked = true;
} else {
toggleCheckbox.checked = false;
}

toggleCheckbox.addEventListener('change', () => {
if (toggleCheckbox.checked) {
body.classList.add('dark-mode');
localStorage.setItem('dark-mode', 'enabled');
} else {
body.classList.remove('dark-mode');
localStorage.setItem('dark-mode', 'disabled');
}
});
});

0 comments on commit 6aa13b7

Please sign in to comment.