diff --git a/bun.lockb b/bun.lockb index cfdfffe1..b8f32cf7 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 8dfcadc4..66fb3a15 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "react-dom": "^18.3.1", "react-icons": "^5.3.0", "react-modal": "3.16.1", + "react-slider": "^2.0.6", "react-toastify": "10.0.5", "recharts": "^2.13.3", "use-debounce": "^10.0.3" diff --git a/src/components/Form/Settings/Slider/Slider.jsx b/src/components/Form/Settings/Slider/Slider.jsx index 73c2765d..d00708a7 100644 --- a/src/components/Form/Settings/Slider/Slider.jsx +++ b/src/components/Form/Settings/Slider/Slider.jsx @@ -1,34 +1,22 @@ import variables from 'config/variables'; import { useState } from 'react'; import { toast } from 'react-toastify'; -import { Slider } from '@mui/material'; -import { MdRefresh } from 'react-icons/md'; - +import ReactSlider from 'react-slider'; +import { MdRefresh, MdSpeed } from 'react-icons/md'; import EventBus from 'utils/eventbus'; function SliderComponent(props) { - const [value, setValue] = useState(localStorage.getItem(props.name) || props.default); + const [value, setValue] = useState( + Number(localStorage.getItem(props.name)) || Number(props.default), + ); - const handleChange = (e, text) => { - let { value } = e.target; - value = Number(value); + const handleChange = (newValue) => { + if (typeof newValue !== 'number') return; - if (text) { - if (value === '') { - return setValue(0); - } + newValue = Math.min(Math.max(newValue, props.min), props.max); - if (value > props.max) { - value = props.max; - } - - if (value < props.min) { - value = props.min; - } - } - - localStorage.setItem(props.name, value); - setValue(value); + localStorage.setItem(props.name, newValue); + setValue(newValue); if (props.element) { if (!document.querySelector(props.element)) { @@ -41,38 +29,118 @@ function SliderComponent(props) { }; const resetItem = () => { - handleChange({ - target: { - value: props.default || '', - }, - }); + handleChange(Number(props.default)); toast(variables.getMessage('toasts.reset')); }; + const multiplierMarks = { + 10: '0.1x', + 100: '1x', + 200: '2x', + 400: '4x', + }; + + const handleMarkClick = (markValue) => { + handleChange(markValue); + }; + return ( - <> - - {props.title} - {Number(value)} - - - {variables.getMessage('settings:buttons.reset')} - - -
- `${value}`} - marks={props.marks || []} - /> +
+
+ {props.title} +
+ + {value} + {props.display} + + +
- + ( +
+ )} + renderMark={(props) => { + if (multiplierMarks[props.key]) { + return ( +
handleMarkClick(props.key)} + data-value={multiplierMarks[props.key]} + role="button" + tabIndex={0} + aria-label={`Set zoom to ${multiplierMarks[props.key]}`} + className={`${props.className} cursor-pointer`} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + handleMarkClick(props.key); + } + }} + /> + ); + } + return null; + }} + /> +
); }