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

dark mode toggle button #815

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"contributions": [
"code"
]
}
},
{
"login": "YashKandalkar",
"name": "yash",
Expand Down Expand Up @@ -77,7 +77,7 @@
"contributions": [
"code"
]
}
},
{
"login": "g-savitha",
"name": "Savitha Gollamudi",
Expand Down
85,515 changes: 25,737 additions & 59,778 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^6.1.0"
"react-helmet": "^6.1.0",
"styled-components": "^6.1.8"
},
"devDependencies": {
"babel-jest": "26.3.0",
Expand Down
37 changes: 37 additions & 0 deletions src/components/Mode.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useState } from 'react';
import { createGlobalStyle } from 'styled-components';
import '../styles/toggle.css';

const GlobalStyle = createGlobalStyle`
body {
background-color: ${props => props.isDarkMode ? '#1C3336' : '#fff'};
color: ${props => props.isDarkMode ? '#d0d0d5' : '#1C3336'};
transition: background-color 0.3s ease;
}
`;


const DarkMode = () => {
const [isDarkMode, setIsDarkMode] = useState(false);

const toggleMode = () => {
setIsDarkMode(prevMode => !prevMode);
};

return (
<>
<GlobalStyle isDarkMode={isDarkMode} />
<div class="toggle-container">
<span class="toggle-label">Light</span>
<div class="toggle">
<input type="checkbox" id="dark-mode-toggle" checked={isDarkMode} onChange={toggleMode} class="toggle-input" />
<label for="dark-mode-toggle" class="toggle-slider"></label>
<div class={`toggle-ball ${isDarkMode ? 'dark' : 'light'}`} />
</div>
<span class="toggle-label">Dark</span>
</div>
</>
);
};

export default DarkMode;
1 change: 1 addition & 0 deletions src/constants/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const categorizedSkills = {
'nginx',
'openresty',
'nestjs',
'strapi',
],
},

Expand Down
3 changes: 3 additions & 0 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Addons from '../components/addons';
import Skills from '../components/skills';
import Donate from '../components/donate';
import Support from '../components/support';
import Mode from '../components/Mode';
import { initialSkillState } from '../constants/skills';
import Loader from '../components/loader';
import SEO from '../components/seo';
Expand Down Expand Up @@ -394,7 +395,9 @@ const IndexPage = () => {

return (
<Layout>
<Mode />
<div className="m-4 sm:p-4">

<SEO title="GitHub Profile Readme Generator" />
<div id="form">
<Title
Expand Down
70 changes: 70 additions & 0 deletions src/styles/toggle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.toggle-container {
display: flex;
align-items: center;
}

.toggle-label {
margin-right: 0px;
}

.toggle {
position: relative;
width: 60px;
height: 34px;
}

.toggle-input {
display: none;
}

.toggle-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
border-radius: 34px;
transition: background-color 0.3s ease;
}

.toggle-slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
border-radius: 50%;
transition: transform 0.3s ease;
}

.toggle-input:checked + .toggle-slider {
background-color: #222;
}

.toggle-input:checked + .toggle-slider:before {
transform: translateX(26px);
}

.toggle-ball {
position: absolute;
top: 4px;
left: 4px;
width: 26px;
height: 26px;
background-color: white;
border-radius: 50%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
transition: left 0.3s ease;
}

.toggle-ball.light {
left: 4px;
}

.toggle-ball.dark {
left: 30px;
}