From be72982e0e72f5413b4394885fd6451370bf8958 Mon Sep 17 00:00:00 2001 From: Bartosz Dryl Date: Thu, 22 Jul 2021 15:49:53 +0200 Subject: [PATCH] Add tooltips to player controls (#1015) * add VideoControlWithTooltip * refactor * use css for tooltips * lint fix * transition fix * lint --- .../VideoPlayer/VideoPlayer.style.tsx | 67 ++++++++++++++++++- .../components/VideoPlayer/VideoPlayer.tsx | 18 +++-- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/shared/components/VideoPlayer/VideoPlayer.style.tsx b/src/shared/components/VideoPlayer/VideoPlayer.style.tsx index 3720671850..665448c7c9 100644 --- a/src/shared/components/VideoPlayer/VideoPlayer.style.tsx +++ b/src/shared/components/VideoPlayer/VideoPlayer.style.tsx @@ -15,6 +15,12 @@ type CustomControlsProps = { isEnded?: boolean } +type ControlButtonProps = { + tooltipText?: string + tooltipPosition?: 'left' | 'right' + showTooltipOnlyOnFocus?: boolean +} + const focusStyles = css` :focus { /* Provide a fallback style for browsers @@ -58,7 +64,7 @@ export const CustomControls = styled.div` transition: transform 200ms ${transitions.easing}, opacity 200ms ${transitions.easing}; ` -export const ControlButton = styled.button` +export const ControlButton = styled.button` margin-right: 0.5em; display: flex !important; cursor: pointer; @@ -68,7 +74,8 @@ export const ControlButton = styled.button` align-items: center; justify-content: center; padding: 0.5em; - transition: background-color ${transitions.timings.player} ${transitions.easing} !important; + position: relative; + transition: background ${transitions.timings.player} ease-in !important; & > svg { filter: drop-shadow(0 1px 2px ${colors.transparentBlack[32]}); @@ -76,15 +83,67 @@ export const ControlButton = styled.button` height: 1.5em; } + ::before { + ${({ tooltipPosition }) => tooltipPosition === 'left' && 'left: 0'}; + ${({ tooltipPosition }) => tooltipPosition === 'right' && 'right: 0'}; + + opacity: 0; + pointer-events: none; + content: ${({ tooltipText }) => tooltipText && `'${tooltipText}'`}; + position: absolute; + font-size: 0.875em; + bottom: calc(3.5em - 1px); + background: ${colors.transparentBlack[54]}; + backdrop-filter: blur(${sizes(8)}); + display: flex; + align-items: center; + padding: 0.5em; + white-space: nowrap; + transition: opacity ${transitions.timings.player} ease-in !important; + } + :hover { background-color: ${colors.transparentPrimary[18]}; backdrop-filter: blur(${sizes(8)}); + transition: none !important; + + ::before { + transition: none !important; + opacity: ${({ showTooltipOnlyOnFocus }) => (showTooltipOnlyOnFocus ? 0 : 1)}; + } } :active { background-color: ${colors.transparentPrimary[10]}; } + :focus { + ::before { + /* turn off transition on mouse enter, but turn on on mouse leave */ + transition: none !important; + opacity: 1; + } + } + + :focus-visible { + ::before { + opacity: 1; + } + } + + :focus:not(:focus-visible):hover { + ::before { + transition: none !important; + opacity: ${({ showTooltipOnlyOnFocus }) => (showTooltipOnlyOnFocus ? 0 : 1)}; + } + } + + :focus:not(:focus-visible):not(:hover) { + ::before { + opacity: 0; + } + } + ${focusStyles} ` @@ -183,8 +242,10 @@ export const CurrentTime = styled(Text)` ` export const ScreenControls = styled.div` + display: grid; + grid-template-columns: auto auto; + gap: 0.5em; margin-left: auto; - display: flex; ${ControlButton}:last-of-type { margin-right: 0; diff --git a/src/shared/components/VideoPlayer/VideoPlayer.tsx b/src/shared/components/VideoPlayer/VideoPlayer.tsx index 22fef444e4..1c891b3673 100644 --- a/src/shared/components/VideoPlayer/VideoPlayer.tsx +++ b/src/shared/components/VideoPlayer/VideoPlayer.tsx @@ -427,11 +427,17 @@ const VideoPlayerComponent: React.ForwardRefRenderFunction - + {playerState === 'ended' ? : isPlaying ? : } - {renderVolumeButton()} + + {renderVolumeButton()} + {isPiPSupported && ( - + {isPiPEnabled ? : } )} - + {isFullScreen ? : }