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

Update theme component #239

Merged
merged 1 commit into from
Jun 16, 2023
Merged
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
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