-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(videoPlayer): simplify video player visiblity
- Loading branch information
Stéphane
committed
Oct 24, 2023
1 parent
a55ddae
commit aee836d
Showing
5 changed files
with
54 additions
and
112 deletions.
There are no files selected for viewing
25 changes: 7 additions & 18 deletions
25
src/components/ButtonToggleVideoIframeVisibility.module.css
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 |
---|---|---|
@@ -1,20 +1,9 @@ | ||
.button { | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
border-top-right-radius: 0; | ||
border-bottom-right-radius: 0; | ||
z-index: 5; | ||
transition: 0.2s; | ||
} | ||
|
||
@media (min-width: em(2140px)) { | ||
.button { | ||
top: auto; | ||
right: calc(50% - rem(20px)); | ||
bottom: 0; | ||
border-top-right-radius: var(--mantine-radius-md); | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
} | ||
position: absolute; | ||
left: rem(-44px); | ||
top: 0; | ||
border-top-right-radius: 0; | ||
border-bottom-right-radius: 0; | ||
z-index: 5; | ||
transition: 0.2s; | ||
} |
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 |
---|---|---|
|
@@ -34,10 +34,6 @@ | |
left: rem(44px); | ||
} | ||
|
||
.buttonMove { | ||
right: rem(8px); | ||
} | ||
|
||
.buttonInfo { | ||
right: rem(44px); | ||
right: rem(8px); | ||
} |
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,37 @@ | ||
.container { | ||
position: absolute; | ||
bottom: rem(160px); | ||
right: rem(20px); | ||
width: rem(300px); | ||
height: rem(150px); | ||
z-index: 4; | ||
pointer-events: all; | ||
transition: .2s; | ||
|
||
&[data-visible="false"] { | ||
transform: translate3d(320px, 0, 0); | ||
} | ||
|
||
@media (min-width: $mantine-breakpoint-md) { | ||
bottom: rem(130px); | ||
right: rem(40px); | ||
width: rem(400px); | ||
height: rem(200px); | ||
|
||
&[data-visible="false"] { | ||
transform: translate3d(440px, 0, 0); | ||
} | ||
} | ||
|
||
@media (min-width: $mantine-breakpoint-lg) { | ||
bottom: rem(180px); | ||
} | ||
|
||
@media (min-width: em(2140)) { | ||
bottom: rem(70px); | ||
right: rem(550px); | ||
} | ||
|
||
/* &[data-visible="true"] { | ||
} */ | ||
} |
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 |
---|---|---|
@@ -1,79 +1,17 @@ | ||
import { useMantineTheme } from "@mantine/core"; | ||
import { useMediaQuery } from "@mantine/hooks"; | ||
import { type MotionStyle, motion } from "framer-motion"; | ||
import { memo, useMemo, useRef } from "react"; | ||
import { memo } from "react"; | ||
import classes from './VideoPlayer.module.css'; | ||
|
||
import { useVideoIframeVisibility } from "../providers/VideoIframeVisibility"; | ||
import { ButtonToggleVideoIframeVisibility } from "./ButtonToggleVideoIframeVisibility"; | ||
import { VideoIframe } from "./VideoIframe"; | ||
|
||
export const VideoPlayer = memo(() => { | ||
const theme = useMantineTheme(); | ||
const constraintsRef = useRef(null); | ||
const isMobile = useMediaQuery(`(max-width: ${theme.breakpoints.sm})`); | ||
const visible = useVideoIframeVisibility(); | ||
|
||
const iframeSize = useMemo( | ||
() => ({ | ||
width: isMobile ? 300 : 400, | ||
height: isMobile ? 150 : 200, | ||
}), | ||
[isMobile], | ||
); | ||
|
||
const containerStyles: MotionStyle = useMemo( | ||
() => ({ | ||
position: "absolute", | ||
bottom: 0, | ||
right: 0, | ||
transition: "0.2s", | ||
maxWidth: "100vw", | ||
pointerEvents: "none", | ||
overflow: "hidden", | ||
top: isMobile ? "20vh" : "60vh", | ||
left: 0, | ||
}), | ||
[isMobile], | ||
); | ||
|
||
const commonStyles: MotionStyle = useMemo( | ||
() => ({ | ||
zIndex: 4, | ||
pointerEvents: "all", | ||
position: "absolute", | ||
backgroundColor: theme.colors.blue[7], | ||
borderRadius: theme.radius.md, | ||
transition: "0.2s", | ||
opacity: 1, | ||
visibility: "visible", | ||
...iframeSize, | ||
}), | ||
[theme, iframeSize], | ||
); | ||
|
||
const visibleStyles: MotionStyle = { | ||
...commonStyles, | ||
}; | ||
|
||
const hiddenStyles: MotionStyle = { | ||
...commonStyles, | ||
opacity: 0, | ||
visibility: "hidden", | ||
}; | ||
|
||
const iframeContainerStyles = visible ? visibleStyles : hiddenStyles; | ||
const videoIframeVisibility = useVideoIframeVisibility(); | ||
|
||
return ( | ||
<motion.div ref={constraintsRef} style={containerStyles}> | ||
<div className={classes.container} data-visible={videoIframeVisibility}> | ||
<ButtonToggleVideoIframeVisibility /> | ||
<motion.div | ||
drag | ||
dragConstraints={constraintsRef} | ||
dragMomentum={false} | ||
style={iframeContainerStyles} | ||
> | ||
<VideoIframe {...iframeSize} /> | ||
</motion.div> | ||
</motion.div> | ||
<VideoIframe /> | ||
</div> | ||
); | ||
}); |