diff --git a/README.md b/README.md index 090e52d..a54088c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,18 @@ Example Code preventWheel={false} minValue={minValue} maxValue={maxValue} + {/* optional */} + minFormatter={(e) => + `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + {/* optional */} + maxFormatter={(e) => + `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + {/* optional */} + minValueFormatter={(e) => + `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + {/* optional */} + maxValueFormatter={(e) => + `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} onInput={(e) => { handleInput(e); }} @@ -77,6 +89,8 @@ Example Code export default App; +`minFormatter`, `maxFormatter`, `minValueFormatter` and `maxValueFormatter` are assumed to be functions, which return a string or JSX Element for display. Returning a JSX Element or long strings requires overwriting the CSS for a good look. +




diff --git a/src/App.js b/src/App.js index e59f131..e27bf1b 100644 --- a/src/App.js +++ b/src/App.js @@ -27,13 +27,17 @@ function App() { ref={ref} // baseClassName='multi-range-slider-black' min={0} - max={100} + max={200} step={5} ruler={true} label={true} preventWheel={false} minValue={minValue} maxValue={maxValue} + minFormatter={(e) => `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + maxFormatter={(e) => `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + minValueFormatter={(e) => `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} + maxValueFormatter={(e) => `${Math.floor(e / 60)}:${Math.round(e % 60).toString().padStart(2, '0')}`} onInput={(e) => { handleInput(e); }} @@ -49,7 +53,7 @@ function App() { { const stepCount = (max - min) / step; let ruler = props.ruler === undefined || props.ruler === null ? true : props.ruler; let label = props.label === undefined || props.label === null ? true : props.label; + const minFormatter = props.minFormatter || ((e) => e); + const maxFormatter = props.maxFormatter || ((e) => e); + const minValueFormatter = props.minValueFormatter || ((e) => e); + const maxValueFormatter = props.maxValueFormatter || ((e) => e); ruler = ruler === 'false' || !ruler ? false : true; label = label === 'false' || !label ? false : true; @@ -261,7 +265,7 @@ const MultiRangeSlider = React.forwardRef((props, ref) => {
-
{minValue}
+
{minValueFormatter(minValue)}
@@ -269,7 +273,7 @@ const MultiRangeSlider = React.forwardRef((props, ref) => {
-
{maxValue}
+
{maxValueFormatter(maxValue)}
@@ -282,8 +286,8 @@ const MultiRangeSlider = React.forwardRef((props, ref) => { )} {label && (
-
{min}
-
{max}
+
{minFormatter(min)}
+
{maxFormatter(max)}
)}