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 useMeasure from "react-use-measure";
|
||||||
import { clamp } from "lodash";
|
import { clamp } from "lodash";
|
||||||
|
|
||||||
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBarHandleContainer, ProgressSliderBody } from "./styles";
|
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBody } from "./styles";
|
||||||
|
|
||||||
const MARGIN_WIDTH = 15;
|
const MARGIN_WIDTH = 15;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export function ProgressSlider({
|
|||||||
const [bodyRef, {
|
const [bodyRef, {
|
||||||
width: bodyWidth,
|
width: bodyWidth,
|
||||||
}] = useMeasure();
|
}] = 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 bindBarPos = useDrag((params) => {
|
||||||
const newPos = clamp(
|
const newPos = clamp(
|
||||||
barPos.x.get() + params.delta[0],
|
barPos.x.get() + params.delta[0],
|
||||||
@@ -37,14 +37,16 @@ export function ProgressSlider({
|
|||||||
|
|
||||||
|
|
||||||
const AnimatedProgressSliderBar = animated(ProgressSliderBar);
|
const AnimatedProgressSliderBar = animated(ProgressSliderBar);
|
||||||
const AnimatedProgressSliderBarHandleContainer = animated(ProgressSliderBarHandleContainer);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProgressSliderBody ref={bodyRef}>
|
<ProgressSliderBody ref={bodyRef}>
|
||||||
<AnimatedProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
|
<AnimatedProgressSliderBar
|
||||||
<AnimatedProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
{...bindBarPos()}
|
||||||
|
style={{ x: barPos.x }}
|
||||||
|
bodyWidth={bodyWidth - MARGIN_WIDTH}
|
||||||
|
>
|
||||||
<ProgressSliderBarHandle />
|
<ProgressSliderBarHandle />
|
||||||
</AnimatedProgressSliderBarHandleContainer>
|
</AnimatedProgressSliderBar>
|
||||||
</ProgressSliderBody>
|
</ProgressSliderBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -28,31 +28,20 @@ export const ProgressSliderBar = styled.div<ProgressSliderBarProps>`
|
|||||||
`;
|
`;
|
||||||
ProgressSliderBar.displayName = "ProgressSliderBar";
|
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`
|
export const ProgressSliderBarHandle = styled.div`
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 1ch;
|
float: right;
|
||||||
height: 80%;
|
|
||||||
|
width: 0.8ch;
|
||||||
|
right: 0.5ch;
|
||||||
|
|
||||||
|
height: 70%;
|
||||||
|
top: 15%;
|
||||||
|
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ import {
|
|||||||
} from "../../../features/overlayTool/overlayToolSlice";
|
} from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
|
||||||
import { Toggle } from "../../Common/Inputs/Toggle";
|
import { Toggle } from "../../Common/Inputs/Toggle";
|
||||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
|
||||||
import { SlotSelector } from "../../Common/Inputs/SlotSelector";
|
import { SlotSelector } from "../../Common/Inputs/SlotSelector";
|
||||||
import { ProgressSlider } from "../../Common/Inputs/ProgressSlider";
|
import { ProgressSlider } from "../../Common/Inputs/ProgressSlider";
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
|
|
||||||
export function OverlayControl() {
|
export function OverlayControl() {
|
||||||
@@ -38,10 +36,6 @@ export function OverlayControl() {
|
|||||||
dispatch(setOpacity(value));
|
dispatch(setOpacity(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TEMP */
|
|
||||||
const [barValue, setBarValue] = useState(0.3);
|
|
||||||
/* TEMP */
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack as={PadBox} gutter="md" padding="sm">
|
<Stack as={PadBox} gutter="md" padding="sm">
|
||||||
<Inline gutter="md" stretch="end">
|
<Inline gutter="md" stretch="end">
|
||||||
|
|||||||
Reference in new issue
Block a user