You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/form-components/Slider/Slider.tsx

43 lines
905 B

import RcSlider from 'rc-slider';
import styles from './Slider.module.css';
import 'rc-slider/assets/index.css';
export interface Props {
min: number;
max: number;
step: number;
value: number;
onChange: (value: number) => void;
}
export function Slider({ min, max, step, value, onChange }: Props) {
const SliderWithTooltip = RcSlider.createSliderWithTooltip(RcSlider);
const marks = {
[min]: translateMinValue(min),
[max]: max.toString(),
};
return (
<div className={styles.root}>
<SliderWithTooltip
tipFormatter={translateMinValue}
min={min}
max={max}
step={step}
marks={marks}
defaultValue={value}
onAfterChange={onChange}
className={styles.slider}
/>
</div>
);
}
function translateMinValue(value: number) {
if (value === 0) {
return 'unlimited';
}
return value.toString();
}