mirror of
https://github.com/SomboChea/ui
synced 2026-01-17 08:35:47 +07:00
feat(style): added dark mode (#446)
This commit is contained in:
committed by
GitHub
parent
91434cc814
commit
cdad5cf70d
@@ -30,7 +30,6 @@ const Header: React.FC<Props> = ({ withoutSearch }) => {
|
||||
}
|
||||
|
||||
const { user, scope, setUser } = appContext;
|
||||
const logo = window.VERDACCIO_LOGO;
|
||||
|
||||
/**
|
||||
* Logouts user
|
||||
@@ -46,7 +45,7 @@ const Header: React.FC<Props> = ({ withoutSearch }) => {
|
||||
<>
|
||||
<NavBar data-testid="header" position="static">
|
||||
<InnerNavBar>
|
||||
<HeaderLeft logo={logo} />
|
||||
<HeaderLeft />
|
||||
<HeaderRight
|
||||
onLogout={handleLogout}
|
||||
onOpenRegistryInfoDialog={() => setOpenInfoDialog(true)}
|
||||
|
||||
@@ -3,23 +3,22 @@ import styled from '@emotion/styled';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import Search from '../Search/';
|
||||
import Logo from '../Logo';
|
||||
|
||||
import HeaderLogo from './HeaderLogo';
|
||||
import { LeftSide, SearchWrapper } from './styles';
|
||||
|
||||
interface Props {
|
||||
withoutSearch?: boolean;
|
||||
logo?: string;
|
||||
}
|
||||
|
||||
const StyledLink = styled(Link)({
|
||||
marginRight: '1em',
|
||||
});
|
||||
|
||||
const HeaderLeft: React.FC<Props> = ({ withoutSearch = false, logo }) => (
|
||||
const HeaderLeft: React.FC<Props> = ({ withoutSearch = false }) => (
|
||||
<LeftSide>
|
||||
<StyledLink to={'/'}>
|
||||
<HeaderLogo logo={logo} />
|
||||
<Logo />
|
||||
</StyledLink>
|
||||
{!withoutSearch && (
|
||||
<SearchWrapper>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import React from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
import Logo from '../Logo';
|
||||
|
||||
interface Props {
|
||||
logo?: string;
|
||||
}
|
||||
|
||||
const HeaderLogo: React.FC<Props> = ({ logo }) => {
|
||||
if (logo) {
|
||||
const Wrapper = styled('div')({
|
||||
fontSize: 0,
|
||||
});
|
||||
return (
|
||||
<Wrapper>
|
||||
<img alt="logo" height="40px" src={logo} />
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return <Logo />;
|
||||
};
|
||||
|
||||
export default HeaderLogo;
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { useState, useEffect, MouseEvent } from 'react';
|
||||
import React, { useState, useEffect, useContext, MouseEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Button from '../../muiComponents/Button';
|
||||
import ThemeContext from '../../design-tokens/ThemeContext';
|
||||
|
||||
import { RightSide } from './styles';
|
||||
import HeaderToolTip from './HeaderToolTip';
|
||||
@@ -24,10 +25,16 @@ const HeaderRight: React.FC<Props> = ({
|
||||
onToggleMobileNav,
|
||||
onOpenRegistryInfoDialog,
|
||||
}) => {
|
||||
const themeContext = useContext(ThemeContext);
|
||||
const [anchorEl, setAnchorEl] = useState();
|
||||
const [isMenuOpen, setIsMenuOpen] = useState();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (!themeContext) {
|
||||
throw Error(t('theme-context-not-correct-used'));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setIsMenuOpen(Boolean(anchorEl));
|
||||
}, [anchorEl]);
|
||||
@@ -54,6 +61,12 @@ const HeaderRight: React.FC<Props> = ({
|
||||
onToggleLogin();
|
||||
};
|
||||
|
||||
const handleToggleDarkLightMode = () => {
|
||||
setTimeout(() => {
|
||||
themeContext.setIsDarkMode(!themeContext.isDarkMode);
|
||||
}, 300);
|
||||
};
|
||||
|
||||
return (
|
||||
<RightSide data-testid="header-right">
|
||||
{!withoutSearch && (
|
||||
@@ -61,6 +74,12 @@ const HeaderRight: React.FC<Props> = ({
|
||||
)}
|
||||
<HeaderToolTip title={t('header.documentation')} tooltipIconType={'help'} />
|
||||
<HeaderToolTip onClick={onOpenRegistryInfoDialog} title={t('header.registry-info')} tooltipIconType={'info'} />
|
||||
<HeaderToolTip
|
||||
onClick={handleToggleDarkLightMode}
|
||||
title={t('header.documentation')}
|
||||
tooltipIconType={themeContext.isDarkMode ? 'dark-mode' : 'light-mode'}
|
||||
/>
|
||||
|
||||
{username ? (
|
||||
<HeaderMenu
|
||||
anchorEl={anchorEl}
|
||||
|
||||
@@ -2,12 +2,14 @@ import React, { forwardRef } from 'react';
|
||||
import Info from '@material-ui/icons/Info';
|
||||
import Help from '@material-ui/icons/Help';
|
||||
import Search from '@material-ui/icons/Search';
|
||||
import NightsStay from '@material-ui/icons/NightsStay';
|
||||
import WbSunny from '@material-ui/icons/WbSunny';
|
||||
|
||||
import IconButton from '../../muiComponents/IconButton';
|
||||
|
||||
import { IconSearchButton, StyledLink } from './styles';
|
||||
|
||||
export type TooltipIconType = 'search' | 'help' | 'info';
|
||||
export type TooltipIconType = 'search' | 'help' | 'info' | 'dark-mode' | 'light-mode';
|
||||
interface Props {
|
||||
tooltipIconType: TooltipIconType;
|
||||
onClick?: () => void;
|
||||
@@ -50,6 +52,21 @@ const HeaderToolTipIcon = forwardRef<HeaderToolTipIconRef, Props>(function Heade
|
||||
<Search />
|
||||
</IconSearchButton>
|
||||
);
|
||||
case 'dark-mode':
|
||||
// todo(Priscila): Add Zoom transition effect
|
||||
return (
|
||||
<IconButton color="inherit" onClick={onClick} ref={ref}>
|
||||
<NightsStay />
|
||||
</IconButton>
|
||||
);
|
||||
|
||||
case 'light-mode':
|
||||
// todo(Priscila): Add Zoom transition effect
|
||||
return (
|
||||
<IconButton color="inherit" onClick={onClick} ref={ref}>
|
||||
<WbSunny />
|
||||
</IconButton>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -302,6 +302,30 @@ exports[`<Header /> component with logged in state should load the component in
|
||||
class="MuiTouchRipple-root"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
<span
|
||||
class="MuiIconButton-label"
|
||||
>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root"
|
||||
focusable="false"
|
||||
role="presentation"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
<span
|
||||
class="MuiTouchRipple-root"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit"
|
||||
data-testid="header--menu-accountcircle"
|
||||
@@ -635,6 +659,30 @@ exports[`<Header /> component with logged in state should load the component in
|
||||
class="MuiTouchRipple-root"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
<span
|
||||
class="MuiIconButton-label"
|
||||
>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root"
|
||||
focusable="false"
|
||||
role="presentation"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
<span
|
||||
class="MuiTouchRipple-root"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit"
|
||||
data-testid="header--button-login"
|
||||
|
||||
Reference in New Issue
Block a user