ISSUE-021 - Simplified the ProgressSlider, dropping the container component and instead letting the entire progress bar be dragged.
This commit is contained in:
1 parent
8170ba3f86
commit
daae51e06d
3 files changed
+16
-31
No files matched your search
@@ -3,7 +3,7 @@ import { useDrag } from "@use-gesture/react";
|
||||
import useMeasure from "react-use-measure";
|
||||
import { clamp } from "lodash";
|
||||
|
||||
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBarHandleContainer, ProgressSliderBody } from "./styles";
|
||||
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBody } from "./styles";
|
||||
|
||||
const MARGIN_WIDTH = 15;
|
||||
|
||||
@@ -20,7 +20,7 @@ export function ProgressSlider({
|
||||
const [bodyRef, {
|
||||
width: bodyWidth,
|
||||
}] = useMeasure();
|
||||
const barPos = useSpring({ x: (bodyWidth - MARGIN_WIDTH) * value });
|
||||
const barPos = useSpring({ x: ((bodyWidth - 2 * MARGIN_WIDTH) * value) + MARGIN_WIDTH });
|
||||
const bindBarPos = useDrag((params) => {
|
||||
const newPos = clamp(
|
||||
barPos.x.get() + params.delta[0],
|
||||
@@ -37,14 +37,16 @@ export function ProgressSlider({
|
||||
|
||||
|
||||
const AnimatedProgressSliderBar = animated(ProgressSliderBar);
|
||||
const AnimatedProgressSliderBarHandleContainer = animated(ProgressSliderBarHandleContainer);
|
||||
|
||||
return (
|
||||
<ProgressSliderBody ref={bodyRef}>
|
||||
<AnimatedProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
|
||||
<AnimatedProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
||||
<AnimatedProgressSliderBar
|
||||
{...bindBarPos()}
|
||||
style={{ x: barPos.x }}
|
||||
bodyWidth={bodyWidth - MARGIN_WIDTH}
|
||||
>
|
||||
<ProgressSliderBarHandle />
|
||||
</AnimatedProgressSliderBarHandleContainer>
|
||||
</AnimatedProgressSliderBar>
|
||||
</ProgressSliderBody>
|
||||
);
|
||||
}
|
||||
@@ -28,31 +28,20 @@ export const ProgressSliderBar = styled.div<ProgressSliderBarProps>`
|
||||
`;
|
||||
ProgressSliderBar.displayName = "ProgressSliderBar";
|
||||
|
||||
|
||||
export const ProgressSliderBarHandleContainer = styled.div`
|
||||
position: relative;
|
||||
left: -50%;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
|
||||
background-color: rgba(200, 200, 0, 0.3);
|
||||
`;
|
||||
ProgressSliderBarHandleContainer.displayName = "ProgressSliderBarHandleContainer";
|
||||
|
||||
export const ProgressSliderBarHandle = styled.div`
|
||||
position: relative;
|
||||
width: 1ch;
|
||||
height: 80%;
|
||||
float: right;
|
||||
|
||||
width: 0.8ch;
|
||||
right: 0.5ch;
|
||||
|
||||
height: 70%;
|
||||
top: 15%;
|
||||
|
||||
border-radius: 2px;
|
||||
|
||||
opacity: 0.5;
|
||||
background-color: white;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
|
||||
Reference in new issue
Block a user