ISSUE-021 - Discovered the animated() wrapper solution to using Styled-Components that solves some problems.
Currently working on making the draggable activation area larger.
This commit is contained in:
1 parent
9925eae4cc
commit
8170ba3f86
2 files changed
+28
-21
No files matched your search
@@ -22,8 +22,12 @@ export function ProgressSlider({
|
||||
}] = useMeasure();
|
||||
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);
|
||||
const newPos = clamp(
|
||||
barPos.x.get() + params.delta[0],
|
||||
MARGIN_WIDTH,
|
||||
bodyWidth - MARGIN_WIDTH,
|
||||
);
|
||||
const newValue = (newPos - MARGIN_WIDTH) / (bodyWidth - 2 * MARGIN_WIDTH);
|
||||
|
||||
barPos.x.set(newPos);
|
||||
onChange(newValue);
|
||||
@@ -31,20 +35,16 @@ export function ProgressSlider({
|
||||
console.log("drag", newPos, newValue);
|
||||
});
|
||||
|
||||
// const
|
||||
// console.log("main", bodyWidth, barPos.x.get());
|
||||
// console.log("main",barPos.x.get());
|
||||
// console.log(bodyWidth);
|
||||
|
||||
const AnimatedProgressSliderBar = animated(ProgressSliderBar);
|
||||
const AnimatedProgressSliderBarHandleContainer = animated(ProgressSliderBarHandleContainer);
|
||||
|
||||
return (
|
||||
<ProgressSliderBody ref={bodyRef}>
|
||||
|
||||
|
||||
<ProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
|
||||
<ProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
||||
<AnimatedProgressSliderBar style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} />
|
||||
<AnimatedProgressSliderBarHandleContainer {...bindBarPos()} style={{ x: barPos.x }}>
|
||||
<ProgressSliderBarHandle />
|
||||
</ProgressSliderBarHandleContainer>
|
||||
|
||||
</AnimatedProgressSliderBarHandleContainer>
|
||||
</ProgressSliderBody>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { animated } from "@react-spring/web";
|
||||
import styled from "styled-components";
|
||||
|
||||
export const ProgressSliderBody = styled.div`
|
||||
@@ -20,10 +19,9 @@ type ProgressSliderBarProps = {
|
||||
bodyWidth: number,
|
||||
color?: string,
|
||||
};
|
||||
export const ProgressSliderBar = styled(animated.div)<ProgressSliderBarProps>`
|
||||
export const ProgressSliderBar = styled.div<ProgressSliderBarProps>`
|
||||
position: absolute;
|
||||
left: ${({ bodyWidth }) => `${-bodyWidth}px`};
|
||||
/* left: -359px; */
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: ${({ color }) => (color ?? (p => p.theme.colors.activeGreen))};
|
||||
@@ -31,21 +29,30 @@ export const ProgressSliderBar = styled(animated.div)<ProgressSliderBarProps>`
|
||||
ProgressSliderBar.displayName = "ProgressSliderBar";
|
||||
|
||||
|
||||
export const ProgressSliderBarHandleContainer = styled(animated.div)`
|
||||
position: absolute;
|
||||
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: 1.2em;
|
||||
background-color: black;
|
||||
margin-top: 1px;
|
||||
border-radius: 3px;
|
||||
height: 80%;
|
||||
border-radius: 2px;
|
||||
|
||||
opacity: 0.5;
|
||||
background-color: white;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
|
||||
Reference in new issue
Block a user