diff --git a/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx b/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx index d7183b0..47881b2 100644 --- a/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx +++ b/src/components/Common/Inputs/ProgressSlider/ProgressSlider.tsx @@ -10,6 +10,11 @@ import { ProgressSliderBody, } from "./styles"; +/** + * This component isn't 100% amazing. Consider that the number indicator + * component may be bugged when loading with a value that isn't 1. + */ + const MARGIN_WIDTH = 15; const percentage = (value: number) => `${Math.floor(value * 100)}%`; @@ -18,16 +23,25 @@ type ProgressSliderProps = { onChange: (value: number) => void, disabled?: boolean, formatter?: (value: number) => string, + barColor?: string, + labelColor?: string, + handleColor?: string, }; export function ProgressSlider({ value, onChange, disabled = false, formatter = percentage, + barColor, + labelColor, + handleColor, }: ProgressSliderProps) { const [bodyRef, { width: bodyWidth, }] = useMeasure(); + const [labelRef, { + width: labelWidth, + }] = useMeasure(); const barPos = useSpring({ x: ((bodyWidth - 2 * MARGIN_WIDTH) * value) + MARGIN_WIDTH }); const bindBarPos = useDrag((params) => { const newPos = clamp( @@ -41,6 +55,8 @@ export function ProgressSlider({ onChange(newValue); }, { enabled: !disabled }); + console.log(bodyWidth, labelWidth, value, barPos.x.get()); + const AnimatedProgressSliderBar = animated(ProgressSliderBar); return ( @@ -49,9 +65,22 @@ export function ProgressSlider({ {...bindBarPos()} style={{ x: barPos.x }} bodyWidth={bodyWidth - MARGIN_WIDTH} + disabled={disabled} + color={barColor} > - - 45 || barPos.x.get() < 0}> + + labelWidth * 1.5 + || barPos.x.get() < 0 + || value === 1 + ) ? -1 : value > 0.1 ? 4 : 3 // Tuned fitting considerations. + } + disabled={disabled} + onBarColor={labelColor} + > {formatter(value)} diff --git a/src/components/Common/Inputs/ProgressSlider/styles.ts b/src/components/Common/Inputs/ProgressSlider/styles.ts index 76d0c58..1b1df95 100644 --- a/src/components/Common/Inputs/ProgressSlider/styles.ts +++ b/src/components/Common/Inputs/ProgressSlider/styles.ts @@ -1,4 +1,4 @@ -import styled, { css } from "styled-components"; +import styled from "styled-components"; export const ProgressSliderBody = styled.div` position: relative; @@ -17,6 +17,7 @@ export const ProgressSliderBody = styled.div` type ProgressSliderBarProps = { bodyWidth: number, + disabled: boolean, color?: string, }; export const ProgressSliderBar = styled.div` @@ -24,11 +25,18 @@ export const ProgressSliderBar = styled.div` left: ${({ bodyWidth }) => `${-bodyWidth}px`}; height: 100%; width: 100%; - background-color: ${({ color }) => (color ?? (p => p.theme.colors.activeGreen))}; + background-color: ${({ color, disabled }) => ( + disabled ? (p => p.theme.colors.lightGrey) : + color ?? (p => p.theme.colors.activeGreen) + )}; + transition: background-color 0.2s ease; `; ProgressSliderBar.displayName = "ProgressSliderBar"; -export const ProgressSliderBarHandle = styled.div` +type ProgressSliderBarHandleProps = { + color?: string, +}; +export const ProgressSliderBarHandle = styled.div` position: relative; float: right; @@ -41,7 +49,8 @@ export const ProgressSliderBarHandle = styled.div` border-radius: 2px; opacity: 0.5; - background-color: white; + background-color: ${({ color = "white" }) => color}; + transition: background-color 0.2s ease; cursor: pointer; &:hover { @@ -51,18 +60,25 @@ export const ProgressSliderBarHandle = styled.div` ProgressSliderBarHandle.displayName = "ProgressSliderBarHandle"; type ProgressSliderBarIndicatorProps = { - left: boolean, + left: number, + disabled: boolean, onBarColor?: string, }; export const ProgressSliderBarIndicator = styled.span` display: block; position: relative; float: right; - left: ${({ left }) => left ? -1 : 3}ch; + left: ${({ left }) => left}ch; font-family: ${p => p.theme.fonts.f1Regular}; font-size: 0.9em; - color: ${({ onBarColor, left }) => left ? onBarColor ?? "white" : "black"}; + color: ${({ onBarColor, left, disabled }) => ( + left < 0 + ? disabled + ? (p => p.theme.colors.darkGrey) + : onBarColor ?? "white" + : (p => p.theme.colors.darkGrey) + )}; transition-property: left, color; transition-timing-function: ease;