🎥 Make videos programmatically with React
better hover considerations. No volume bar on mobile
umungobungo4b3f7bb06f81
diff --git a/packages/docs/src/components/Demo/PlayerVolume.tsx b/packages/docs/src/components/Demo/PlayerVolume.tsxindex a481b86acb..e25cd16ff4 100644--- a/packages/docs/src/components/Demo/PlayerVolume.tsx+++ b/packages/docs/src/components/Demo/PlayerVolume.tsx@@ -13,6 +13,8 @@ export const PlayerVolume: React.FC<{};}> = ({playerRef, updateAudioMute, updateAudioVolume, audioState}) => {const containerRef = useRef<HTMLDivElement>(null);+ const [isHovered, setIsHovered] = useState(false);+useEffect(() => {const {current} = playerRef;@@ -31,6 +33,14 @@ export const PlayerVolume: React.FC<{};}, [playerRef, updateAudioMute]);+ useEffect(() => {+ if (isHovered) {+ document.body.style.userSelect = 'none';+ } else {+ document.body.style.userSelect = 'auto';+ }+ }, [isHovered]);+const onClick = useCallback(() => {if (audioState.isMuted) {playerRef.current.unmute();@@ -87,6 +97,9 @@ export const PlayerVolume: React.FC<{const handlePointerUp = useCallback(() => {setIsDragging(false);+ setTimeout(() => {+ setIsHovered(false);+ }, 1000);}, []);useEffect(() => {@@ -101,8 +114,18 @@ export const PlayerVolume: React.FC<{};}, [isDragging, handlePointerMove, handlePointerUp]);+ const handleMouseLeave = useCallback(() => {+ if (!isDragging) {+ setIsHovered(false);+ }+ }, [isDragging]);+return (- <div className={styles['volume-button']}>+ <div+ className={styles['volume-button']}+ onMouseEnter={() => setIsHovered(true)}+ onMouseLeave={handleMouseLeave}+ ><buttontype="button"onClick={onClick}@@ -123,6 +146,10 @@ export const PlayerVolume: React.FC<{ref={containerRef}onPointerDown={handlePointerDown}className={styles['volume-bar']}+ style={{+ height: isHovered ? '80px' : '0px',+ opacity: isHovered ? 1 : 0,+ }}><divstyle={{@@ -136,7 +163,7 @@ export const PlayerVolume: React.FC<{}}><div- className={styles['volume-active']}+ className={`${styles['volume-active']} ${isDragging ? undefined : styles['animate-height']}`}style={{height: `${audioState.isMuted ? 0 : audioState.volume * 100}%`,}}diff --git a/packages/docs/src/components/Demo/player.module.css b/packages/docs/src/components/Demo/player.module.cssindex d7d0ac5606..a110ba6bb7 100644--- a/packages/docs/src/components/Demo/player.module.css+++ b/packages/docs/src/components/Demo/player.module.css@@ -52,14 +52,14 @@.volume-bar {position: absolute;- display: flex;justify-content: center;height: 0px;+ bottom: 35px;width: 100%;- opacity: 0;transition:height 0.2s,opacity 0.3s;+ opacity: 0;.volume-active {position: absolute;@@ -67,7 +67,6 @@background: var(--ifm-color-primary);border-radius: 10px;width: 100%;- transition: height 0.1s;z-index: 1;}@@ -79,24 +78,21 @@width: 100%;z-index: 0;}++ .volume-active.animate-height {+ transition: height 0.1s;+ }}}@media screen and (max-width: 900px) {.volume-bar {- bottom: 25px;+ display: none;}}@media screen and (min-width: 901px) {.volume-bar {- bottom: 35px;- }-}--.volume-button:hover {- .volume-bar {- height: 80px;- opacity: 1;+ display: flex;}}