Range Slider

General


Show Code
import React from "react";
import RangeSlider from 'funda-ui/RangeSlider';
 
// component styles
import 'funda-ui/RangeSlider/index.css';
 
export default () => {
 
    return (
        <>
 
            <RangeSlider
                label="String"
                minName="name"
                min={0}
                max={100}
                step={5}
                value={{min: 15, max: 100}} 
                onChange={(e, res) => {
                    console.log(`value: ${res.min}`);
                }}
                onlyOne
            />
 
 
            <RangeSlider 
                label="String"
                minName="name-1"
                maxName="name-2"
                min={0} 
                max={100} 
                step={5} 
                onChange={(e, res) => {
                    console.log(`min: ${res.min} | max: ${res.max}`);
                }} 
            />
 
 
            <RangeSlider 
                label="String"
                minName="name-1"
                maxName="name-2"
                min={0} 
                max={100} 
                step={5} 
                value={{min: 25, max: 55}} 
                onChange={(e, res) => {
                    console.log(`min: ${res.min} | max: ${res.max}`);
                }} 
            />
 
 
        </>
    );
}

No spacing


Show Code
import React from "react";
import RangeSlider from 'funda-ui/RangeSlider';
 
// component styles
import 'funda-ui/RangeSlider/index.css';
 
export default () => {
 
 
    return (
        <>
 
            <RangeSlider
                ...
                wrapperClassName="position-relative"
                ...
            />
 
             <RangeSlider
                ...
                wrapperClassName=""
                ...
            />
 
        </>
    );
}

Asynchronous & Complex State Problem Solving

Prevent collapsing problems caused by re-rendering of sub-component. You need to use useMemo() hook to solve.


Age: 15 ~ 75
Show Code
import React, { useEffect, useState, useMemo } from "react";
import RangeSlider from 'funda-ui/RangeSlider';
 
// component styles
import 'funda-ui/RangeSlider/index.css';
 
// DO NOT move `useMemo` to component
function RangeSliderMemo(props: any) {
    const {callback, data} = props;
    return useMemo(() => {
        return <>
       
            <RangeSlider
                minName="age_min"
                maxName="age_max"
                min={0}
                max={100}
                step={1}
                value={{ min: data ? data.age_min : 3, max: data ? data.age_max : 80 }}
                onChange={(e, res) => {
                    callback({
                        min: res.min,
                        max: res.max
                    });
                }}
            />
 
        </>
        
        
    }, [data, callback]);
}
 
 
 
export default () => {
 
    
    const [data, setData] = useState<any>({
        age_min: 15,
        age_max: 75
    });
    const [age, setAge] = useState<any>({
        min: data ? data.age_min : 3,
        max: data ? data.age_max : 80
    });
 
    useEffect(() => {
        
        // update age
        setAge({
            min: data.age_min,
            max: data.age_max
        });
 
    }, [data]);
 
 
    return (
        <>
 
 
            <div className="row">
                <div className="col-auto" style={{width: '150px'}}>
                    Age: {age.min} ~ {age.max}
                </div>
           
                <div className="col">
                    <RangeSliderMemo data={data} callback={setAge}/>
                </div>
            </div>
        </>
    )
}

API

Range Slider

import RangeSlider from 'funda-ui/RangeSlider';
PropertyTypeDefaultDescriptionRequired
wrapperClassNamestringmb-3 position-relativeThe class name of the control wrapper.-
controlClassNamestringform-controlThe class name of the control.-
controlExClassNamestring-The extended class name of controlClassName.-
onlyOnebooleanfalseOnly one numeric control is allowed.-
valueJSON Object-Set a default value for this control. Such as { min: 0, max: 100 }-
labelstring | ReactNode-It is used to specify a label for an element of a form.
Support html tags
-
minNamestring-Name is not deprecated when used with form fields. Specify the name of minimizing rang control.-
maxNamestring-Name is not deprecated when used with form fields. Specify the name of maximizing rang control.-
stepnumber | string1Specified legal number intervals.-
minnumber | string-The minimum value to accept-
maxnumber | string-The maximum value to accept-
disabledbooleanfalseWhether it is disabled-
onChangefunction-Call a function when the value of an HTML element is changed. It returns two callback values.
  1. The first is the Control Event (Event)
  2. The second is the composition event (Boolean)
-