ISSUE-021 - Another progress commit. Have issues with combining spring animated components and Styled-Components.
This commit is contained in:
1 parent
97c5752102
commit
9925eae4cc
2 files changed
+13
-14
No files matched your search
@@ -5,7 +5,7 @@ import { clamp } from "lodash";
|
|||||||
|
|
||||||
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBarHandleContainer, ProgressSliderBody } from "./styles";
|
import { ProgressSliderBar, ProgressSliderBarHandle, ProgressSliderBarHandleContainer, ProgressSliderBody } from "./styles";
|
||||||
|
|
||||||
const MARGIN_WIDTH = 30;
|
const MARGIN_WIDTH = 15;
|
||||||
|
|
||||||
type ProgressSliderProps = {
|
type ProgressSliderProps = {
|
||||||
value: number, // Fraction of 1 (0.0 to 1.0)
|
value: number, // Fraction of 1 (0.0 to 1.0)
|
||||||
@@ -20,7 +20,7 @@ export function ProgressSlider({
|
|||||||
const [bodyRef, {
|
const [bodyRef, {
|
||||||
width: bodyWidth,
|
width: bodyWidth,
|
||||||
}] = useMeasure();
|
}] = useMeasure();
|
||||||
const barPos = useSpring({ x: (bodyWidth - 2 * MARGIN_WIDTH) * value });
|
const barPos = useSpring({ x: (bodyWidth - MARGIN_WIDTH) * value });
|
||||||
const bindBarPos = useDrag((params) => {
|
const bindBarPos = useDrag((params) => {
|
||||||
const newPos = clamp(barPos.x.get() + params.delta[0], MARGIN_WIDTH, bodyWidth - MARGIN_WIDTH);
|
const newPos = clamp(barPos.x.get() + params.delta[0], MARGIN_WIDTH, bodyWidth - MARGIN_WIDTH);
|
||||||
const newValue = newPos / (bodyWidth - MARGIN_WIDTH);
|
const newValue = newPos / (bodyWidth - MARGIN_WIDTH);
|
||||||
@@ -33,20 +33,17 @@ export function ProgressSlider({
|
|||||||
|
|
||||||
// const
|
// const
|
||||||
// console.log("main", bodyWidth, barPos.x.get());
|
// console.log("main", bodyWidth, barPos.x.get());
|
||||||
console.log("main",barPos.x.get());
|
// console.log("main",barPos.x.get());
|
||||||
|
// console.log(bodyWidth);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProgressSliderBody ref={bodyRef}>
|
<ProgressSliderBody ref={bodyRef}>
|
||||||
{/* <animated.div style={{ x: barPos.x }}> */}
|
|
||||||
|
|
||||||
<ProgressSliderBar>
|
|
||||||
{/* <animated.div {...bindBarPos()} style={{ x: barPos.x }}> */}
|
<ProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
|
||||||
<ProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
<ProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
||||||
<ProgressSliderBarHandle />
|
<ProgressSliderBarHandle />
|
||||||
</ProgressSliderBarHandleContainer>
|
</ProgressSliderBarHandleContainer>
|
||||||
{/* </animated.div> */}
|
|
||||||
</ProgressSliderBar>
|
|
||||||
{/* </animated.div> */}
|
|
||||||
|
|
||||||
</ProgressSliderBody>
|
</ProgressSliderBody>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ export const ProgressSliderBody = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
type ProgressSliderBarProps = {
|
type ProgressSliderBarProps = {
|
||||||
|
bodyWidth: number,
|
||||||
color?: string,
|
color?: string,
|
||||||
};
|
};
|
||||||
export const ProgressSliderBar = styled.div<ProgressSliderBarProps>`
|
export const ProgressSliderBar = styled(animated.div)<ProgressSliderBarProps>`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
left: ${({ bodyWidth }) => `${-bodyWidth}px`};
|
||||||
|
/* left: -359px; */
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: ${({ color }) => (color ?? (p => p.theme.colors.activeGreen))};
|
background-color: ${({ color }) => (color ?? (p => p.theme.colors.activeGreen))};
|
||||||
@@ -29,9 +32,9 @@ ProgressSliderBar.displayName = "ProgressSliderBar";
|
|||||||
|
|
||||||
|
|
||||||
export const ProgressSliderBarHandleContainer = styled(animated.div)`
|
export const ProgressSliderBarHandleContainer = styled(animated.div)`
|
||||||
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: absolute;
|
|
||||||
`;
|
`;
|
||||||
ProgressSliderBarHandleContainer.displayName = "ProgressSliderBarHandleContainer";
|
ProgressSliderBarHandleContainer.displayName = "ProgressSliderBarHandleContainer";
|
||||||
|
|
||||||
@@ -39,15 +42,14 @@ export const ProgressSliderBarHandle = styled.div`
|
|||||||
position: relative;
|
position: relative;
|
||||||
width: 1ch;
|
width: 1ch;
|
||||||
height: 1.2em;
|
height: 1.2em;
|
||||||
background-color: white;
|
background-color: black;
|
||||||
/* margin: 2px; */
|
|
||||||
margin-top: 1px;
|
margin-top: 1px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 0.9;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
ProgressSliderBarHandle.displayName = "ProgressSliderBarHandle";
|
ProgressSliderBarHandle.displayName = "ProgressSliderBarHandle";
|
||||||
Reference in new issue
Block a user