Skip to content

Commit

Permalink
update theme component
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-carabina committed Jun 16, 2023
1 parent 145d124 commit 4ed7923
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/components/Icons/Svg/Massa/StationLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import { ComponentPropsWithoutRef } from 'react';

interface SVGProps extends ComponentPropsWithoutRef<'div'> {
theme?: 'light' | 'dark' | undefined;
theme?: 'theme-light' | 'theme-dark' | undefined;
}

/* eslint-disable max-len */
Expand Down Expand Up @@ -73,9 +73,9 @@ function DarkLogo() {
/* eslint-enable max-len */

export function StationLogo(props: SVGProps) {
let { theme = 'dark', ...rest } = props;
let { theme = 'theme-dark', ...rest } = props;

const isDark = theme === 'dark';
const isDark = theme === 'theme-dark';

return (
<div
Expand Down
4 changes: 2 additions & 2 deletions src/components/Icons/Svg/SvgIcon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const _MassaWallet = {
export const _StationLogo = {
render: () => (
<>
<StationLogo theme="dark" />
<StationLogo theme="theme-dark" />
<br />
<StationLogo theme="light" />
<StationLogo theme="theme-light" />
</>
),
};
7 changes: 5 additions & 2 deletions src/components/LayoutStation/LayoutStation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export function LayoutStation({ ...props }) {
const { children, navigator, overwrittenTheme, onSetTheme, customClass } =
props;

const [storedTheme] = useLocalStorage<string>('massa-station-theme', 'light');
const [storedTheme] = useLocalStorage<string>(
'massa-station-theme',
'theme-dark',
);
const [selectedTheme, setSelectedTheme] = useState(
overwrittenTheme || storedTheme || 'light',
overwrittenTheme || storedTheme || 'theme-dark',
);

function handleSetTheme(theme: string) {
Expand Down
18 changes: 11 additions & 7 deletions src/components/ThemeMode/ThemeMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
// @ts-ignore
import React from 'react';

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

interface ThemeProps extends ComponentPropsWithoutRef<'div'> {
interface ThemeProps {
onSetTheme?: (theme: string) => void;
}

export function ThemeMode(props: ThemeProps) {
let { onSetTheme } = props;

const [theme, setTheme] = useLocalStorage<string>(
const [storedTheme, setStoredTheme] = useLocalStorage<string>(
'massa-station-theme',
'theme-dark',
);
const [theme, setTheme] = useState(storedTheme || 'theme-dark');

function handleClick() {
setTheme(theme === 'theme-dark' ? 'theme-light' : 'theme-dark');
const newTheme = theme === 'theme-light' ? 'theme-dark' : 'theme-light';

onSetTheme?.(theme);
setTheme(newTheme);
setStoredTheme(newTheme);

onSetTheme?.(newTheme);
}

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

return (
Expand Down

0 comments on commit 4ed7923

Please sign in to comment.