From dafec66d90ebfc2fcb9d1ad7ef2d826427eef6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Sat, 21 Feb 2026 15:35:34 +0100 Subject: [PATCH] nicolium: add slight slider animation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/pl-fe/src/components/ui/slider.tsx | 48 +++++++++++++++++-- .../pl-fe/src/components/ui/step-slider.tsx | 2 +- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/pl-fe/src/components/ui/slider.tsx b/packages/pl-fe/src/components/ui/slider.tsx index 80418695d..371d1d93c 100644 --- a/packages/pl-fe/src/components/ui/slider.tsx +++ b/packages/pl-fe/src/components/ui/slider.tsx @@ -1,5 +1,6 @@ +import clsx from 'clsx'; import throttle from 'lodash/throttle'; -import React, { useCallback, useRef } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { getPointerPosition } from '@/features/video'; @@ -13,8 +14,34 @@ interface ISlider { /** Draggable slider component. */ const Slider: React.FC = ({ value, onChange }) => { const node = useRef(null); + const keyboardAnimationTimeout = useRef(null); + const [animateKeyboardInput, setAnimateKeyboardInput] = useState(false); + + const clearKeyboardAnimation = useCallback(() => { + if (keyboardAnimationTimeout.current !== null) { + window.clearTimeout(keyboardAnimationTimeout.current); + keyboardAnimationTimeout.current = null; + } + + setAnimateKeyboardInput(false); + }, []); + + const triggerKeyboardAnimation = useCallback(() => { + setAnimateKeyboardInput(true); + + if (keyboardAnimationTimeout.current !== null) { + window.clearTimeout(keyboardAnimationTimeout.current); + } + + keyboardAnimationTimeout.current = window.setTimeout(() => { + setAnimateKeyboardInput(false); + keyboardAnimationTimeout.current = null; + }, 120); + }, []); const handleMouseDown: React.MouseEventHandler = (e) => { + clearKeyboardAnimation(); + document.addEventListener('mousemove', handleMouseSlide, true); document.addEventListener('mouseup', handleMouseUp, true); document.addEventListener('touchmove', handleMouseSlide, true); @@ -86,10 +113,19 @@ const Slider: React.FC = ({ value, onChange }) => { nextValue = 1; } + triggerKeyboardAnimation(); onChange(nextValue); } }; + useEffect(() => { + return () => { + if (keyboardAnimationTimeout.current !== null) { + window.clearTimeout(keyboardAnimationTimeout.current); + } + }; + }, []); + return (
= ({ value, onChange }) => { >
= ({ value, steps, onChange }) => { /> ))}