From 8170ba3f8689ecbcd63c72be259367b8cb35d929 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Tue, 18 Jan 2022 15:42:43 -0500 Subject: [PATCH] ISSUE-021 - Discovered the animated() wrapper solution to using Styled-Components that solves some problems. Currently working on making the draggable activation area larger. --- .../Inputs/ProgressSlider/ProgressSlider.tsx | 26 +++++++++---------- .../Common/Inputs/ProgressSlider/styles.ts | 25 +++++++++++------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx b/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx index 9d0712c..81543c2 100644 --- a/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx +++ b/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx @@ -20,10 +20,14 @@ export function ProgressSlider({ const [bodyRef, { width: bodyWidth, }] = useMeasure(); - const barPos = useSpring({ x: (bodyWidth - 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); + 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 ( - - - - + + - - + ); } diff --git a/src/components/Common/Inputs/ProgressSlider/styles.ts b/src/components/Common/Inputs/ProgressSlider/styles.ts index ff3447d..706322a 100644 --- a/src/components/Common/Inputs/ProgressSlider/styles.ts +++ b/src/components/Common/Inputs/ProgressSlider/styles.ts @@ -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)` +export const ProgressSliderBar = styled.div` 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)` 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 {