Skip to content

Commit

Permalink
feat: switcher dark mode to light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sahas-01 committed Oct 27, 2023
1 parent 6e0909f commit 6519bec
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
5 changes: 1 addition & 4 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ function App({ Component, pageProps }: AppProps) {

return (
<PersistGate persistor={store.__persistor}>
<ThemeProvider
attribute='class'
enableSystem
>
<ThemeProvider attribute='class'>
<ConfigProvider theme={antdTheme}>
<ModalProvider>
<ErrorBoundary>
Expand Down
3 changes: 3 additions & 0 deletions public/assets/icons/darkmodeswitcher.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/assets/icons/lightmodeswitcher.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/components/AppLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { useDispatch } from 'react-redux';
import { logout } from '~src/redux/userDetails';
import { useTheme } from 'next-themes';
import { Dropdown } from '~src/ui-components/Dropdown';
import ToggleButton from '~src/ui-components/ToggleButton';

const OnChainIdentity = dynamic(() => import('~src/components/OnchainIdentity'), {
ssr: false
Expand Down Expand Up @@ -695,7 +696,7 @@ const AppLayout = ({ className, Component, pageProps }: Props) => {
if (isMobile) {
sidebarItems = [getSiderMenuItem('', '', <div className='mt-[60px]' />), username && isMobile ? userDropdown : null, ...sidebarItems];
}

sidebarItems.push(getSiderMenuItem('', '', <ToggleButton />));
return (
<Layout className={className}>
<NavHeader
Expand Down
30 changes: 30 additions & 0 deletions src/ui-components/ToggleButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019-2025 @polkassembly/polkassembly authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import React from 'react';
import { useTheme } from 'next-themes';
import DarkModeSwitcher from '~assets/icons/darkmodeswitcher.svg';
import LightModeSwitcher from '~assets/icons/lightmodeswitcher.svg';

const ToggleButton = () => {
const { resolvedTheme: theme, setTheme } = useTheme();

return (
<button
onClick={(e) => {
e.preventDefault();
setTheme(theme === 'dark' ? 'light' : 'dark');
}}
className='m-0 flex min-w-[200px] cursor-pointer items-center justify-center rounded-full border border-solid border-[#D2D8E0] bg-white p-2 py-1 hover:bg-none dark:border-separatorDark dark:bg-section-dark-overlay'
>
{theme === 'dark' ? <LightModeSwitcher /> : <DarkModeSwitcher />}
<p className='m-0 font-poppins text-xs font-normal leading-[15px] text-bodyBlue dark:text-white'>Switch to</p>
<p className='m-0 ml-[6px] mr-[11px] font-poppins text-xs font-semibold font-semibold leading-[18px] tracking-[0.02em] text-bodyBlue dark:text-white'>
{theme === 'dark' ? 'Light Mode' : 'Dark Mode'}
</p>
</button>
);
};

export default ToggleButton;
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* eslint-disable sort-keys */
module.exports = {
important: true,
darkMode: 'class',
content: ['./pages/**/*.{js,ts,jsx,tsx}', './src/**/*.{jsx,tsx}'],
theme: {
extend: {
Expand Down

0 comments on commit 6519bec

Please sign in to comment.