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

Fix theme toggle button bugs #3875

Merged
merged 8 commits into from
May 10, 2023
4 changes: 4 additions & 0 deletions app/components/Header/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
justify-content: space-between;
align-items: center;
cursor: pointer;
transition: background-color var(--linear-medium);

& button {
padding: 0;
}
&:hover {
background-color: var(--color-gray-1);
}
}

.buttonGroup {
Expand Down
7 changes: 6 additions & 1 deletion app/components/Header/ToggleTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cx from 'classnames';
import { debounce } from 'lodash';
import { useCallback, useState, useEffect } from 'react';
import { applySelectedTheme, getTheme } from 'app/utils/themeUtils';
import Icon from '../Icon';
Expand Down Expand Up @@ -32,6 +33,10 @@ const ToggleTheme = ({
setIcon(getIcon());
}, []);

window.addEventListener('themeChange', () => {
setIcon(getIcon());
});

Bestem0r marked this conversation as resolved.
Show resolved Hide resolved
const handleThemeChange = useCallback(
(e) => {
e.preventDefault();
Expand All @@ -50,7 +55,7 @@ const ToggleTheme = ({
const props = {
name: 'Endre tema',
className: classN,
onClick: handleThemeChange,
onClick: debounce(handleThemeChange, 200),
};
return isButton ? (
<button {...props}>
Expand Down