feat/117: add toggle fullscreen button (#138)

This commit is contained in:
Carlos Valente
2022-05-28 15:57:59 +02:00
committed by GitHub
parent ca33624ffc
commit 8c2d6595b0
3 changed files with 75 additions and 28 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ontime-ui", "name": "ontime-ui",
"version": "1.0.1", "version": "1.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@chakra-ui/react": "^2.0.0-next.3", "@chakra-ui/react": "^2.0.0-next.3",
+39 -1
View File
@@ -5,6 +5,16 @@ import { Image } from '@chakra-ui/react';
import { AnimatePresence, motion } from 'framer-motion'; import { AnimatePresence, motion } from 'framer-motion';
import navlogo from 'assets/images/logos/LOGO-72.png'; import navlogo from 'assets/images/logos/LOGO-72.png';
import style from './NavLogo.module.scss'; import style from './NavLogo.module.scss';
import { IconButton } from '@chakra-ui/button';
import { IoExpand } from '@react-icons/all-files/io5/IoExpand';
/* Styling for action buttons */
const navButtonStyle = {
size: 'md',
variant: 'outline',
colorScheme: 'whiteAlpha',
_hover: { bg: '#ebedf0', color: '#333' },
};
export default function NavLogo(props) { export default function NavLogo(props) {
const { isHidden } = props; const { isHidden } = props;
@@ -24,6 +34,16 @@ export default function NavLogo(props) {
} }
}, []); }, []);
const toggleFullscreen = useCallback(() => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}, []);
useEffect(() => { useEffect(() => {
// attach the event listener // attach the event listener
document.addEventListener('keydown', handleKeyPress); document.addEventListener('keydown', handleKeyPress);
@@ -49,6 +69,21 @@ export default function NavLogo(props) {
<Image alt='' src={navlogo} className={style.logo} onClick={handleClick} /> <Image alt='' src={navlogo} className={style.logo} onClick={handleClick} />
<AnimatePresence> <AnimatePresence>
{showNav && ( {showNav && (
<>
<motion.div
initial={{ opacity: 0, scaleX: 0 }}
animate={{ opacity: 1, scaleX: 1 }}
whileInView={{ opacity: 1 }}
exit={{ opacity: 0, scaleX: 0 }}
className={style.actions}
>
<IconButton
aria-label='Toggle Fullscreen'
icon={<IoExpand />}
onClick={toggleFullscreen}
{...navButtonStyle}
/>
</motion.div>
<motion.div <motion.div
initial={{ opacity: 0, scale: 0, y: -50 }} initial={{ opacity: 0, scale: 0, y: -50 }}
animate={{ opacity: 1, scale: 1, y: 0 }} animate={{ opacity: 1, scale: 1, y: 0 }}
@@ -56,7 +91,9 @@ export default function NavLogo(props) {
exit={{ opacity: 0, scaleY: 0, y: -50 }} exit={{ opacity: 0, scaleY: 0, y: -50 }}
className={style.nav} className={style.nav}
> >
<Link to='/timer' {...tabProps}>Timer</Link> <Link to='/timer' {...tabProps}>
Timer
</Link>
<Link to='/minimal' {...tabProps}> <Link to='/minimal' {...tabProps}>
Minimal Timer Minimal Timer
</Link> </Link>
@@ -76,6 +113,7 @@ export default function NavLogo(props) {
Studio Clock Studio Clock
</Link> </Link>
</motion.div> </motion.div>
</>
)} )}
</AnimatePresence> </AnimatePresence>
</motion.div> </motion.div>
@@ -18,6 +18,7 @@
.nav, .nav,
.showNav { .showNav {
margin-top: 2vh;
gap: 2vh; gap: 2vh;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -29,4 +30,12 @@
color: $text-white; color: $text-white;
} }
} }
.actions {
display: flex;
gap: 8px;
position: absolute;
top: 0.5vw;
right: 75px;
}
} }