forked from react-component/slider
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseRange.ts
More file actions
27 lines (23 loc) · 759 Bytes
/
useRange.ts
File metadata and controls
27 lines (23 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { warning } from '@rc-component/util/lib/warning';
import { useMemo } from 'react';
import type { SliderProps } from '../Slider';
export default function useRange(
range?: SliderProps['range'],
): [
range: boolean,
rangeEditable: boolean,
rangeDraggableTrack: boolean,
minCount: number,
maxCount?: number,
] {
return useMemo(() => {
if (range === true || !range) {
return [!!range, false, false, 0];
}
const { editable, draggableTrack, minCount, maxCount } = range;
if (process.env.NODE_ENV !== 'production') {
warning(!editable || !draggableTrack, '`editable` can not work with `draggableTrack`.');
}
return [true, editable, !editable && draggableTrack, minCount || 0, maxCount];
}, [range]);
}