Skip to content

Commit

Permalink
add nightMode (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyanB authored May 31, 2023
1 parent 5c42171 commit f21095d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/ThemeMode/ThemeMode.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ThemeMode } from './ThemeMode';

export default {
title: 'Components/Theme Mode',
component: ThemeMode,
};

export const _ThemeMode = {
render: () => <ThemeMode />,
};
13 changes: 13 additions & 0 deletions src/components/ThemeMode/ThemeMode.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { ThemeMode } from './ThemeMode';

describe('Components | Button | ThemeMode', () => {
test('it should render', () => {
render(<ThemeMode />);

let button = screen.getByTestId('theme-mode');

expect(button).toBeInTheDocument();
});
});
38 changes: 38 additions & 0 deletions src/components/ThemeMode/ThemeMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import React from 'react';

import { FiMoon, FiSun } from 'react-icons/fi';
import { useLocalStorage } from '../../util/useLocalStorage';

export function ThemeMode() {
const [theme, setTheme] = useLocalStorage<string>(
'massa-station-theme',
'dark',
);

function handleClick() {
setTheme(theme === 'dark' ? 'light' : 'dark');
}

const themeIcons = {
dark: <FiSun className="h-8 w-8" />,
light: <FiMoon className="h-8 w-8" />,
};

return (
<button
data-testid="theme-mode"
className={`bg-primary text-f-primary p-3 rounded-lg cursor-pointer
flex flex-row items-center justify-center
hover:bg-tertiary
active:bg-secondary
h-12 w-12`}
onClick={handleClick}
>
<div className="flex justify-center items-center">
{themeIcons[theme as keyof typeof themeIcons]}
</div>
</button>
);
}
1 change: 1 addition & 0 deletions src/components/ThemeMode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ThemeMode';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './SideMenu';
export * from './Icons';
export * from './Toggle';
export * from './Balance';
export * from './ThemeMode';

0 comments on commit f21095d

Please sign in to comment.