-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add color mode toggle * refactor: move header to separate component * chore: squash
- Loading branch information
1 parent
9a7e6b1
commit d9be770
Showing
7 changed files
with
131 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
ColorModeContextType, | ||
HStack, | ||
IconButton, | ||
Spacer, | ||
Tooltip, | ||
useColorMode, | ||
} from '@chakra-ui/react'; | ||
import React, { FC } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
IoArrowBackOutline, | ||
IoMoonOutline, | ||
IoSunnyOutline, | ||
} from 'react-icons/io5'; | ||
import { | ||
Location, | ||
NavigateFunction, | ||
useLocation, | ||
useNavigate, | ||
} from 'react-router-dom'; | ||
|
||
// constants | ||
import { DEFAULT_GAP, SEARCH_ROUTE } from '@app/constants'; | ||
|
||
// hooks | ||
import useButtonHoverBackgroundColor from '@app/hooks/useButtonHoverBackgroundColor'; | ||
import useDefaultTextColor from '@app/hooks/useDefaultTextColor'; | ||
|
||
const Header: FC = () => { | ||
const { t } = useTranslation(); | ||
const location: Location = useLocation(); | ||
const navigate: NavigateFunction = useNavigate(); | ||
// hooks | ||
const buttonHoverBackgroundColor: string = useButtonHoverBackgroundColor(); | ||
const defaultTextColor: string = useDefaultTextColor(); | ||
const { colorMode, toggleColorMode }: ColorModeContextType = useColorMode(); | ||
// handlers | ||
const handlerBackClick = () => | ||
navigate(SEARCH_ROUTE, { | ||
replace: true, | ||
}); | ||
const handlerColorChangeClick = () => toggleColorMode(); | ||
|
||
return ( | ||
<HStack | ||
alignItems="center" | ||
justifyContent="space-between" | ||
p={DEFAULT_GAP / 2} | ||
w="full" | ||
> | ||
{!location.pathname.includes(SEARCH_ROUTE) && ( | ||
<Tooltip label={t('captions.goBackToSearch')}> | ||
<IconButton | ||
_hover={{ bg: buttonHoverBackgroundColor }} | ||
aria-label="Go back" | ||
color={defaultTextColor} | ||
icon={<IoArrowBackOutline />} | ||
onClick={handlerBackClick} | ||
size="lg" | ||
variant="ghost" | ||
/> | ||
</Tooltip> | ||
)} | ||
|
||
<Spacer /> | ||
|
||
<Tooltip | ||
label={t('captions.switchColorMode', { | ||
colorMode: colorMode === 'dark' ? 'light' : 'dark', | ||
})} | ||
> | ||
<IconButton | ||
_hover={{ bg: buttonHoverBackgroundColor }} | ||
aria-label="Change color mode" | ||
color={defaultTextColor} | ||
icon={colorMode === 'dark' ? <IoSunnyOutline /> : <IoMoonOutline />} | ||
onClick={handlerColorChangeClick} | ||
size="lg" | ||
variant="ghost" | ||
/> | ||
</Tooltip> | ||
</HStack> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Header'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters