Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance volume slider appearance #15105

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions react/features/video-menu/components/web/VolumeSlider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { makeStyles } from 'tss-react/mui';

Expand Down Expand Up @@ -56,7 +56,9 @@ const useStyles = makeStyles()(theme => {
position: 'absolute',
width: '100%',
top: '50%',
transform: 'translate(0, -50%)'
transform: 'translate(0, -50%)',
outline: 'none',
borderRadius: '8px'
}
};
});
Expand All @@ -65,22 +67,37 @@ const _onClick = (e: React.MouseEvent) => {
e.stopPropagation();
};

const VolumeSlider = ({
initialValue,
onChange
}: IProps) => {
const { classes, cx } = useStyles();
const VolumeSlider = ({ initialValue, onChange }: IProps) => {
const { classes, cx, theme } = useStyles();
const { t } = useTranslation();

const sliderRef = useRef< HTMLInputElement | null >(null);
const [ volumeLevel, setVolumeLevel ] = useState((initialValue || 0) * VOLUME_SLIDER_SCALE);

const updateSliderBackground = (value: number) => {
const percentage = (value / VOLUME_SLIDER_SCALE) * 100;
const gradient = `linear-gradient(
to right,
${theme.palette.primary.main} ${percentage}%,
${theme.palette.grey[300]} ${percentage}%
)`;

if (sliderRef.current) {
sliderRef.current.style.background = gradient;
}
};

const _onVolumeChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
const newVolumeLevel = Number(event.currentTarget.value);

onChange(newVolumeLevel / VOLUME_SLIDER_SCALE);
setVolumeLevel(newVolumeLevel);
updateSliderBackground(newVolumeLevel);
}, [ onChange ]);

useEffect(() => {
updateSliderBackground(volumeLevel);
}, [ volumeLevel ]);

return (
<div
aria-label = { t('volumeSlider') }
Expand All @@ -100,6 +117,7 @@ const VolumeSlider = ({
max = { VOLUME_SLIDER_SCALE }
min = { 0 }
onChange = { _onVolumeChange }
ref = { sliderRef }
tabIndex = { 0 }
type = 'range'
value = { volumeLevel } />
Expand Down