ISSUE-021 - Another progress commit. Have issues with combining spring animated components and Styled-Components.

This commit is contained in:
Kyle Geib committed 2022-01-18 15:18:39 -05:00
1 parent 97c5752102
commit 9925eae4cc
2 files changed
+16 -17

No files matched your search

@@ -5,7 +5,7 @@ import { clamp } from "lodash";
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBarHandleContainer, ProgressSliderBody } from "./styles";
const MARGIN_WIDTH = 30;
const MARGIN_WIDTH = 15;
type ProgressSliderProps = {
value: number, // Fraction of 1 (0.0 to 1.0)
@@ -20,7 +20,7 @@ export function ProgressSlider({
const [bodyRef, {
width: bodyWidth,
}] = useMeasure();
const barPos = useSpring({ x: (bodyWidth - 2 * MARGIN_WIDTH) * value });
const barPos = useSpring({ x: (bodyWidth - MARGIN_WIDTH) * value });
const bindBarPos = useDrag((params) => {
const newPos = clamp(barPos.x.get() + params.delta[0], MARGIN_WIDTH, bodyWidth - MARGIN_WIDTH);
const newValue = newPos / (bodyWidth - MARGIN_WIDTH);
@@ -33,20 +33,17 @@ export function ProgressSlider({
// const
// console.log("main", bodyWidth, barPos.x.get());
console.log("main",barPos.x.get());
// console.log("main",barPos.x.get());
// console.log(bodyWidth);
return (
<ProgressSliderBody ref={bodyRef}>
{/* <animated.div style={{ x: barPos.x }}> */}
<ProgressSliderBar>
{/* <animated.div {...bindBarPos()} style={{ x: barPos.x }}> */}
<ProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
<ProgressSliderBarHandle />
</ProgressSliderBarHandleContainer>
{/* </animated.div> */}
</ProgressSliderBar>
{/* </animated.div> */}
<ProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
<ProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
<ProgressSliderBarHandle />
</ProgressSliderBarHandleContainer>
</ProgressSliderBody>
);
@@ -17,10 +17,13 @@ export const ProgressSliderBody = styled.div`
`;
type ProgressSliderBarProps = {
bodyWidth: number,
color?: string,
};
export const ProgressSliderBar = styled.div<ProgressSliderBarProps>`
export const ProgressSliderBar = styled(animated.div)<ProgressSliderBarProps>`
position: absolute;
left: ${({ bodyWidth }) => `${-bodyWidth}px`};
/* left: -359px; */
height: 100%;
width: 100%;
background-color: ${({ color }) => (color ?? (p => p.theme.colors.activeGreen))};
@@ -29,9 +32,9 @@ ProgressSliderBar.displayName = "ProgressSliderBar";
export const ProgressSliderBarHandleContainer = styled(animated.div)`
position: absolute;
width: 100%;
height: 100%;
position: absolute;
`;
ProgressSliderBarHandleContainer.displayName = "ProgressSliderBarHandleContainer";
@@ -39,15 +42,14 @@ export const ProgressSliderBarHandle = styled.div`
position: relative;
width: 1ch;
height: 1.2em;
background-color: white;
/* margin: 2px; */
background-color: black;
margin-top: 1px;
border-radius: 3px;
opacity: 0.5;
cursor: pointer;
&:hover {
opacity: 0.9;
opacity: 0.8;
}
`;
ProgressSliderBarHandle.displayName = "ProgressSliderBarHandle";