Skip to content

🎥 Make videos programmatically with React

feat(player): change styles of volume slider

Arthur Denner6c6b1fdeded5
diff --git a/packages/player/src/MediaVolumeSlider.tsx b/packages/player/src/MediaVolumeSlider.tsx
index acc41041e9..a738fe44bf 100644
--- a/packages/player/src/MediaVolumeSlider.tsx
+++ b/packages/player/src/MediaVolumeSlider.tsx
@@ -1,12 +1,46 @@
import React, {useCallback, useRef, useState} from 'react';
import {Internals} from 'remotion';
import {ICON_SIZE, VolumeOffIcon, VolumeOnIcon} from './icons';
+import {VOLUME_SLIDER_INPUT_CSS_CLASSNAME} from './player-css-classname';
import {useHoverState} from './use-hover-state';
const BAR_HEIGHT = 5;
-// const KNOB_SIZE = 12;
+const KNOB_SIZE = 12;
const VOLUME_SLIDER_WIDTH = 100;
+const scope = `.${VOLUME_SLIDER_INPUT_CSS_CLASSNAME}`;
+const sliderStyle = `
+ ${scope} {
+ -webkit-appearance: none;
+ background-color: rgba(255, 255, 255, 0.5);
+ border-radius: ${BAR_HEIGHT / 2}px;
+ cursor: pointer;
+ height: ${BAR_HEIGHT}px;
+ margin-left: 5px;
+ width: ${VOLUME_SLIDER_WIDTH}px;
+ }
+
+ ${scope}::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ background-color: white;
+ border-radius: ${KNOB_SIZE / 2}px;
+ box-shadow: 0 0 2px black;
+ height: ${KNOB_SIZE}px;
+ width: ${KNOB_SIZE}px;
+ }
+
+ ${scope}::-moz-range-thumb {
+ -webkit-appearance: none;
+ background-color: white;
+ border-radius: ${KNOB_SIZE / 2}px;
+ box-shadow: 0 0 2px black;
+ height: ${KNOB_SIZE}px;
+ width: ${KNOB_SIZE}px;
+ }
+`;
+
+Internals.CSSUtils.injectCSS(sliderStyle);
+
const parentDivStyle: React.CSSProperties = {
display: 'inline-flex',
background: 'none',
@@ -17,14 +51,6 @@ const parentDivStyle: React.CSSProperties = {
touchAction: 'none',
};
-const barBackground: React.CSSProperties = {
- height: BAR_HEIGHT,
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
- width: VOLUME_SLIDER_WIDTH,
- borderRadius: BAR_HEIGHT / 2,
- marginLeft: 5,
-};
-
const volumeContainer: React.CSSProperties = {
display: 'inline',
width: ICON_SIZE,
@@ -87,12 +113,12 @@ export const MediaVolumeSlider: React.FC = () => {
<input
ref={inputRef}
aria-label="Change volume"
+ className={VOLUME_SLIDER_INPUT_CSS_CLASSNAME}
max={1}
min={0}
onBlur={() => setFocused(false)}
onChange={onVolumeChange}
step={0.01}
- style={barBackground}
type="range"
value={mediaVolume}
/>
diff --git a/packages/player/src/player-css-classname.ts b/packages/player/src/player-css-classname.ts
index 7fdd3e250b..a7ab926ab8 100644
--- a/packages/player/src/player-css-classname.ts
+++ b/packages/player/src/player-css-classname.ts
@@ -1 +1,4 @@
export const PLAYER_CSS_CLASSNAME = '__remotion-player';
+export const VOLUME_SLIDER_INPUT_CSS_CLASSNAME = PLAYER_CSS_CLASSNAME.concat(
+ '_volume-slider-input'
+);