@synerise/ds-slider 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +29 -49
- package/dist/Slider.d.ts +2 -2
- package/dist/Slider.js +15 -13
- package/dist/Slider.styles.d.ts +12 -12
- package/dist/Slider.styles.js +37 -67
- package/dist/Slider.types.d.ts +2 -2
- package/dist/Slider.types.js +1 -1
- package/dist/components/AllocationMarks.d.ts +2 -2
- package/dist/components/AllocationMarks.js +37 -42
- package/dist/components/AllocationMarks.styles.d.ts +5 -5
- package/dist/components/AllocationMarks.styles.js +16 -17
- package/dist/components/AllocationSlider.d.ts +2 -2
- package/dist/components/AllocationSlider.js +65 -88
- package/dist/components/DefaultSlider.d.ts +2 -2
- package/dist/components/DefaultSlider.js +58 -79
- package/dist/components/RangeSlider.d.ts +2 -2
- package/dist/components/RangeSlider.js +63 -88
- package/dist/components/SliderAbove.d.ts +1 -1
- package/dist/components/SliderAbove.js +15 -14
- package/dist/components/SliderDots.d.ts +2 -2
- package/dist/components/SliderDots.js +28 -31
- package/dist/components/SliderHandles.d.ts +2 -2
- package/dist/components/SliderHandles.js +36 -54
- package/dist/components/SliderLine.d.ts +2 -2
- package/dist/components/SliderLine.js +34 -46
- package/dist/components/SliderMarks.d.ts +2 -2
- package/dist/components/SliderMarks.js +48 -64
- package/dist/components/SliderSections.d.ts +2 -2
- package/dist/components/SliderSections.js +24 -28
- package/dist/context/SliderContext.d.ts +2 -2
- package/dist/context/SliderContext.js +20 -16
- package/dist/hooks/useColorMap.d.ts +1 -1
- package/dist/hooks/useColorMap.js +8 -5
- package/dist/hooks/useInvertedColors.d.ts +1 -1
- package/dist/hooks/useInvertedColors.js +13 -9
- package/dist/index.js +4 -2
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/utils/Slider.interpolators.d.ts +1 -1
- package/dist/utils/Slider.interpolators.js +10 -16
- package/dist/utils/Slider.utils.d.ts +2 -2
- package/dist/utils/Slider.utils.js +36 -33
- package/dist/utils/allocation.utils.d.ts +2 -2
- package/dist/utils/allocation.utils.js +30 -63
- package/dist/utils/allocationHandlers.utils.d.ts +1 -1
- package/dist/utils/allocationHandlers.utils.js +17 -18
- package/package.json +10 -10
|
@@ -1,112 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { useRanger } from
|
|
4
|
-
import
|
|
5
|
-
import { SliderProvider } from
|
|
6
|
-
import { useColorMap } from
|
|
7
|
-
import { getClosestIndex } from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { AllocationMarks } from
|
|
11
|
-
import { SliderAbove } from
|
|
12
|
-
import { SliderLine } from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
onAllocationChange
|
|
28
|
-
controlGroupEnabled
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
useEffect(function () {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect, useMemo, useCallback } from "react";
|
|
3
|
+
import { useRanger } from "@tanstack/react-ranger";
|
|
4
|
+
import { SliderWrapper } from "../Slider.styles.js";
|
|
5
|
+
import { SliderProvider } from "../context/SliderContext.js";
|
|
6
|
+
import { useColorMap } from "../hooks/useColorMap.js";
|
|
7
|
+
import { getClosestIndex } from "../utils/Slider.utils.js";
|
|
8
|
+
import { countAllocation, mapSliderValueToVariants, checkIsPercentageInBoundaries, mapUserAllocationToHandles } from "../utils/allocation.utils.js";
|
|
9
|
+
import { checkIsBlockedHandlersConfigEnabled, getBlockedHandlersKeys, calculateHandlersPercentagePosition, checkIsBlockedVariantsChange } from "../utils/allocationHandlers.utils.js";
|
|
10
|
+
import { AllocationMarks } from "./AllocationMarks.js";
|
|
11
|
+
import { SliderAbove } from "./SliderAbove.js";
|
|
12
|
+
import { SliderLine } from "./SliderLine.js";
|
|
13
|
+
const AllocationSlider = ({
|
|
14
|
+
allocationConfig,
|
|
15
|
+
tracksColorMap,
|
|
16
|
+
description,
|
|
17
|
+
handlers,
|
|
18
|
+
step = 1,
|
|
19
|
+
label,
|
|
20
|
+
thick,
|
|
21
|
+
disabled,
|
|
22
|
+
dots
|
|
23
|
+
}) => {
|
|
24
|
+
const rangerHandlesRef = useRef({});
|
|
25
|
+
const {
|
|
26
|
+
variants,
|
|
27
|
+
onAllocationChange,
|
|
28
|
+
controlGroupEnabled
|
|
29
|
+
} = allocationConfig;
|
|
30
|
+
const [allocations, setAllocations] = useState(countAllocation(variants, controlGroupEnabled));
|
|
31
|
+
useEffect(() => {
|
|
33
32
|
setAllocations(countAllocation(variants, controlGroupEnabled));
|
|
34
33
|
}, [variants, controlGroupEnabled]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var calculatedVariants = mapSliderValueToVariants(value, variants);
|
|
34
|
+
const rangerRef = useRef(null);
|
|
35
|
+
const {
|
|
36
|
+
blockedHandlersKeys,
|
|
37
|
+
isBlockedHandlersConfigEnabled
|
|
38
|
+
} = useMemo(() => ({
|
|
39
|
+
blockedHandlersKeys: getBlockedHandlersKeys(handlers),
|
|
40
|
+
isBlockedHandlersConfigEnabled: checkIsBlockedHandlersConfigEnabled(handlers)
|
|
41
|
+
}), [handlers]);
|
|
42
|
+
const colorMap = useColorMap(variants?.length ?? 9, "allocation", tracksColorMap);
|
|
43
|
+
const currentHandlersPercentagePositions = calculateHandlersPercentagePosition(variants);
|
|
44
|
+
const handleChange = useCallback((value) => {
|
|
45
|
+
const calculatedVariants = mapSliderValueToVariants(value, variants);
|
|
48
46
|
if (!checkIsPercentageInBoundaries(calculatedVariants)) {
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
51
49
|
if (isBlockedHandlersConfigEnabled) {
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const afterChangeHandlersPercentagePositions = calculateHandlersPercentagePosition(calculatedVariants);
|
|
51
|
+
const isBlockedVariantChanged = checkIsBlockedVariantsChange(blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions);
|
|
54
52
|
if (isBlockedVariantChanged) {
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
setAllocations(countAllocation(variants, controlGroupEnabled));
|
|
59
|
-
onAllocationChange
|
|
57
|
+
onAllocationChange?.(calculatedVariants);
|
|
60
58
|
}, [blockedHandlersKeys, controlGroupEnabled, currentHandlersPercentagePositions, isBlockedHandlersConfigEnabled, onAllocationChange, variants]);
|
|
61
|
-
|
|
62
|
-
getRangerElement:
|
|
63
|
-
return rangerRef.current;
|
|
64
|
-
},
|
|
59
|
+
const rangerInstance = useRanger({
|
|
60
|
+
getRangerElement: () => rangerRef.current,
|
|
65
61
|
values: mapUserAllocationToHandles(allocations),
|
|
66
62
|
min: 0,
|
|
67
63
|
max: 100,
|
|
68
64
|
stepSize: step,
|
|
69
65
|
tickSize: step,
|
|
70
|
-
onDrag:
|
|
66
|
+
onDrag: (instance) => {
|
|
71
67
|
handleChange(instance.sortedValues);
|
|
72
68
|
},
|
|
73
|
-
onChange:
|
|
69
|
+
onChange: (instance) => {
|
|
74
70
|
handleChange(instance.sortedValues);
|
|
75
71
|
}
|
|
76
72
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return index === closestIndex ? newValue : item;
|
|
84
|
-
}).sort(function (a, b) {
|
|
85
|
-
return a - b;
|
|
86
|
-
});
|
|
73
|
+
const handleLineClick = (event) => {
|
|
74
|
+
const clicked = rangerInstance.getValueForClientX(event.clientX);
|
|
75
|
+
const newValue = rangerInstance.roundToStep(clicked);
|
|
76
|
+
const handleValues = mapUserAllocationToHandles(allocations);
|
|
77
|
+
const closestIndex = getClosestIndex(handleValues, clicked);
|
|
78
|
+
const updatedValues = handleValues.map((item, index) => index === closestIndex ? newValue : item).sort((a, b) => a - b);
|
|
87
79
|
handleChange(updatedValues);
|
|
88
80
|
};
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}), /*#__PURE__*/React.createElement(SliderLine, {
|
|
99
|
-
onLineClick: !disabled ? handleLineClick : undefined,
|
|
100
|
-
type: "allocation",
|
|
101
|
-
tracksColorMap: colorMap,
|
|
102
|
-
thick: thick,
|
|
103
|
-
disabled: disabled,
|
|
104
|
-
handlersConfig: handlers,
|
|
105
|
-
dots: dots
|
|
106
|
-
}), /*#__PURE__*/React.createElement(AllocationMarks, _extends({
|
|
107
|
-
variants: []
|
|
108
|
-
}, allocationConfig, {
|
|
109
|
-
tracksColorMap: colorMap,
|
|
110
|
-
allocations: allocations
|
|
111
|
-
}))));
|
|
112
|
-
};
|
|
81
|
+
return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { ref: rangerRef, $disabled: disabled, children: [
|
|
82
|
+
/* @__PURE__ */ jsx(SliderAbove, { label, description }),
|
|
83
|
+
/* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, type: "allocation", tracksColorMap: colorMap, thick, disabled, handlersConfig: handlers, dots }),
|
|
84
|
+
/* @__PURE__ */ jsx(AllocationMarks, { variants: [], ...allocationConfig, tracksColorMap: colorMap, allocations })
|
|
85
|
+
] }) });
|
|
86
|
+
};
|
|
87
|
+
export {
|
|
88
|
+
AllocationSlider
|
|
89
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { DefaultSliderProps } from '../Slider.types';
|
|
3
3
|
export declare const DefaultSlider: (props: DefaultSliderProps) => React.JSX.Element;
|
|
@@ -1,91 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
min =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
value = _useState[0],
|
|
37
|
-
setValue = _useState[1];
|
|
38
|
-
useEffect(function () {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect } from "react";
|
|
3
|
+
import { useRanger } from "@tanstack/react-ranger";
|
|
4
|
+
import { SliderWrapper } from "../Slider.styles.js";
|
|
5
|
+
import { SliderProvider } from "../context/SliderContext.js";
|
|
6
|
+
import { useColorMap } from "../hooks/useColorMap.js";
|
|
7
|
+
import { reversedInterpolator } from "../utils/Slider.interpolators.js";
|
|
8
|
+
import { couldBeInverted } from "../utils/Slider.utils.js";
|
|
9
|
+
import { SliderAbove } from "./SliderAbove.js";
|
|
10
|
+
import { SliderLine } from "./SliderLine.js";
|
|
11
|
+
import { SliderMarks } from "./SliderMarks.js";
|
|
12
|
+
const DefaultSlider = (props) => {
|
|
13
|
+
const {
|
|
14
|
+
label,
|
|
15
|
+
inverted,
|
|
16
|
+
reverse,
|
|
17
|
+
tracksColorMap: customColorMap,
|
|
18
|
+
thick,
|
|
19
|
+
description,
|
|
20
|
+
disabled,
|
|
21
|
+
max = 100,
|
|
22
|
+
min = 0,
|
|
23
|
+
value: initialValue = 50,
|
|
24
|
+
tipFormatter,
|
|
25
|
+
dots,
|
|
26
|
+
step = 1,
|
|
27
|
+
marks,
|
|
28
|
+
onChange,
|
|
29
|
+
onAfterChange
|
|
30
|
+
} = props;
|
|
31
|
+
const tracksColorMap = useColorMap(1, "default", customColorMap);
|
|
32
|
+
const rangerRef = useRef(null);
|
|
33
|
+
const rangerHandlesRef = useRef({});
|
|
34
|
+
const [value, setValue] = useState(initialValue);
|
|
35
|
+
useEffect(() => {
|
|
39
36
|
setValue(initialValue);
|
|
40
37
|
}, [initialValue]);
|
|
41
|
-
|
|
42
|
-
getRangerElement:
|
|
43
|
-
return rangerRef.current;
|
|
44
|
-
},
|
|
38
|
+
const rangerInstance = useRanger({
|
|
39
|
+
getRangerElement: () => rangerRef.current,
|
|
45
40
|
values: [value],
|
|
46
|
-
min
|
|
47
|
-
max
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
48
43
|
stepSize: step,
|
|
49
44
|
tickSize: step,
|
|
50
|
-
onDrag:
|
|
45
|
+
onDrag: (instance) => {
|
|
51
46
|
setValue(instance.sortedValues[0]);
|
|
52
|
-
onChange
|
|
47
|
+
onChange?.(instance.sortedValues[0]);
|
|
53
48
|
},
|
|
54
|
-
onChange:
|
|
49
|
+
onChange: (instance) => {
|
|
55
50
|
setValue(instance.sortedValues[0]);
|
|
56
|
-
onAfterChange
|
|
51
|
+
onAfterChange?.(instance.sortedValues[0]);
|
|
57
52
|
},
|
|
58
|
-
interpolator: reverse ? reversedInterpolator :
|
|
53
|
+
interpolator: reverse ? reversedInterpolator : void 0
|
|
59
54
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const handleLineClick = (event) => {
|
|
56
|
+
const clicked = rangerInstance.getValueForClientX(event.clientX);
|
|
57
|
+
const newValue = rangerInstance.roundToStep(clicked);
|
|
63
58
|
setValue(newValue);
|
|
64
|
-
onChange
|
|
65
|
-
onAfterChange
|
|
59
|
+
onChange?.(newValue);
|
|
60
|
+
onAfterChange?.(newValue);
|
|
66
61
|
};
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
description: description
|
|
77
|
-
}), /*#__PURE__*/React.createElement(SliderLine, {
|
|
78
|
-
onLineClick: !disabled ? handleLineClick : undefined,
|
|
79
|
-
thick: thick,
|
|
80
|
-
tracksColorMap: tracksColorMap,
|
|
81
|
-
type: "default",
|
|
82
|
-
disabled: disabled,
|
|
83
|
-
dots: dots,
|
|
84
|
-
tipFormatter: tipFormatter,
|
|
85
|
-
inverted: couldBeInverted(value, inverted),
|
|
86
|
-
reverse: reverse
|
|
87
|
-
}), marks && /*#__PURE__*/React.createElement(SliderMarks, {
|
|
88
|
-
handlesWithValue: tipFormatter !== false,
|
|
89
|
-
marks: marks
|
|
90
|
-
})));
|
|
91
|
-
};
|
|
62
|
+
return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { withoutMarks: !marks, ref: rangerRef, $disabled: disabled, children: [
|
|
63
|
+
/* @__PURE__ */ jsx(SliderAbove, { label, description }),
|
|
64
|
+
/* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, thick, tracksColorMap, type: "default", disabled, dots, tipFormatter, inverted: couldBeInverted(value, inverted), reverse }),
|
|
65
|
+
marks && /* @__PURE__ */ jsx(SliderMarks, { handlesWithValue: tipFormatter !== false, marks })
|
|
66
|
+
] }) });
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
DefaultSlider
|
|
70
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { RangeSliderProps } from '../Slider.types';
|
|
3
3
|
export declare const RangeSlider: (props: Omit<RangeSliderProps, "range">) => React.JSX.Element;
|
|
@@ -1,99 +1,74 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
min =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
values = _useState[0],
|
|
37
|
-
setValues = _useState[1];
|
|
38
|
-
useEffect(function () {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect } from "react";
|
|
3
|
+
import { useRanger } from "@tanstack/react-ranger";
|
|
4
|
+
import { SliderWrapper } from "../Slider.styles.js";
|
|
5
|
+
import { SliderProvider } from "../context/SliderContext.js";
|
|
6
|
+
import { useColorMap } from "../hooks/useColorMap.js";
|
|
7
|
+
import { reversedInterpolator } from "../utils/Slider.interpolators.js";
|
|
8
|
+
import { couldBeInverted, getClosestIndex } from "../utils/Slider.utils.js";
|
|
9
|
+
import { SliderAbove } from "./SliderAbove.js";
|
|
10
|
+
import { SliderLine } from "./SliderLine.js";
|
|
11
|
+
import { SliderMarks } from "./SliderMarks.js";
|
|
12
|
+
const RangeSlider = (props) => {
|
|
13
|
+
const {
|
|
14
|
+
label,
|
|
15
|
+
inverted,
|
|
16
|
+
tracksColorMap,
|
|
17
|
+
thick,
|
|
18
|
+
description,
|
|
19
|
+
disabled,
|
|
20
|
+
max = 100,
|
|
21
|
+
min = 0,
|
|
22
|
+
value: initialValue = [],
|
|
23
|
+
step = 1,
|
|
24
|
+
marks,
|
|
25
|
+
onChange,
|
|
26
|
+
onAfterChange,
|
|
27
|
+
tipFormatter,
|
|
28
|
+
dots,
|
|
29
|
+
reverse
|
|
30
|
+
} = props;
|
|
31
|
+
const colorMap = useColorMap(initialValue.length, "range", tracksColorMap);
|
|
32
|
+
const rangerRef = useRef(null);
|
|
33
|
+
const rangerHandlesRef = useRef({});
|
|
34
|
+
const [values, setValues] = useState(initialValue);
|
|
35
|
+
useEffect(() => {
|
|
39
36
|
setValues(initialValue);
|
|
40
37
|
}, [initialValue]);
|
|
41
|
-
|
|
42
|
-
getRangerElement:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
min: min,
|
|
47
|
-
max: max,
|
|
38
|
+
const rangerInstance = useRanger({
|
|
39
|
+
getRangerElement: () => rangerRef.current,
|
|
40
|
+
values,
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
48
43
|
stepSize: step,
|
|
49
44
|
tickSize: step,
|
|
50
|
-
onDrag:
|
|
51
|
-
|
|
45
|
+
onDrag: (instance) => {
|
|
46
|
+
const roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
|
|
52
47
|
setValues(roundedValues);
|
|
53
|
-
onChange
|
|
48
|
+
onChange?.(roundedValues);
|
|
54
49
|
},
|
|
55
|
-
onChange:
|
|
56
|
-
|
|
50
|
+
onChange: (instance) => {
|
|
51
|
+
const roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
|
|
57
52
|
setValues(roundedValues);
|
|
58
|
-
onAfterChange
|
|
53
|
+
onAfterChange?.(roundedValues);
|
|
59
54
|
},
|
|
60
|
-
interpolator: reverse ? reversedInterpolator :
|
|
55
|
+
interpolator: reverse ? reversedInterpolator : void 0
|
|
61
56
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return index === closestIndex ? newValue : item;
|
|
68
|
-
}).sort(function (a, b) {
|
|
69
|
-
return a - b;
|
|
70
|
-
});
|
|
57
|
+
const handleLineClick = (event) => {
|
|
58
|
+
const clicked = rangerInstance.getValueForClientX(event.clientX);
|
|
59
|
+
const newValue = rangerInstance.roundToStep(clicked);
|
|
60
|
+
const closestIndex = getClosestIndex(values, clicked);
|
|
61
|
+
const updatedValues = values.map((item, index) => index === closestIndex ? newValue : item).sort((a, b) => a - b);
|
|
71
62
|
setValues(updatedValues);
|
|
72
|
-
onChange
|
|
73
|
-
onAfterChange
|
|
63
|
+
onChange?.(updatedValues);
|
|
64
|
+
onAfterChange?.(updatedValues);
|
|
74
65
|
};
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
description: description
|
|
85
|
-
}), /*#__PURE__*/React.createElement(SliderLine, {
|
|
86
|
-
onLineClick: !disabled ? handleLineClick : undefined,
|
|
87
|
-
thick: thick,
|
|
88
|
-
tracksColorMap: colorMap,
|
|
89
|
-
type: "range",
|
|
90
|
-
disabled: disabled,
|
|
91
|
-
dots: dots,
|
|
92
|
-
tipFormatter: tipFormatter,
|
|
93
|
-
inverted: couldBeInverted(values, inverted),
|
|
94
|
-
reverse: reverse
|
|
95
|
-
}), marks && /*#__PURE__*/React.createElement(SliderMarks, {
|
|
96
|
-
handlesWithValue: tipFormatter !== false,
|
|
97
|
-
marks: marks
|
|
98
|
-
})));
|
|
99
|
-
};
|
|
66
|
+
return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { withoutMarks: !marks, ref: rangerRef, $disabled: disabled, children: [
|
|
67
|
+
/* @__PURE__ */ jsx(SliderAbove, { label, description }),
|
|
68
|
+
/* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, thick, tracksColorMap: colorMap, type: "range", disabled, dots, tipFormatter, inverted: couldBeInverted(values, inverted), reverse }),
|
|
69
|
+
marks && /* @__PURE__ */ jsx(SliderMarks, { handlesWithValue: tipFormatter !== false, marks })
|
|
70
|
+
] }) });
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
RangeSlider
|
|
74
|
+
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FormFieldLabel, ContentBelowElement } from "@synerise/ds-form-field";
|
|
3
|
+
import { SliderLabel } from "../Slider.styles.js";
|
|
4
|
+
const SliderAbove = ({
|
|
5
|
+
label,
|
|
6
|
+
description
|
|
7
|
+
}) => {
|
|
8
|
+
return (label || description) && /* @__PURE__ */ jsxs(SliderLabel, { "data-testid": "ds-slider-details", children: [
|
|
9
|
+
label && /* @__PURE__ */ jsx(FormFieldLabel, { label }),
|
|
10
|
+
description && /* @__PURE__ */ jsx(ContentBelowElement, { description })
|
|
11
|
+
] });
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
SliderAbove
|
|
15
|
+
};
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { SliderDot } from "../Slider.styles.js";
|
|
4
|
+
import { useSliderContext } from "../context/SliderContext.js";
|
|
5
|
+
import { getVisibleSectionsForType } from "../utils/Slider.utils.js";
|
|
6
|
+
const SliderDots = ({
|
|
7
|
+
tracksColorMap,
|
|
8
|
+
type
|
|
9
|
+
}) => {
|
|
10
|
+
const {
|
|
11
|
+
rangerInstance
|
|
12
|
+
} = useSliderContext();
|
|
13
|
+
const dots = rangerInstance.getTicks();
|
|
14
|
+
const steps = rangerInstance.getSteps();
|
|
15
|
+
const tickSize = rangerInstance.options.tickSize ?? 1;
|
|
16
|
+
const dotColorMap = useMemo(() => {
|
|
17
|
+
const map = {};
|
|
18
|
+
steps.filter(getVisibleSectionsForType(type, steps.length)).forEach((step, stepIndex) => {
|
|
19
|
+
const start = step.left;
|
|
20
|
+
const end = start + step.width;
|
|
21
|
+
for (let i = start; i < end; i += tickSize) {
|
|
20
22
|
map[i] = tracksColorMap[stepIndex];
|
|
21
23
|
}
|
|
22
24
|
});
|
|
23
25
|
return map;
|
|
24
26
|
}, [steps, tickSize, tracksColorMap, type]);
|
|
25
|
-
return
|
|
26
|
-
"data-testid":
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
$left: dot.percentage,
|
|
33
|
-
$color: dotColorMap[dot.value]
|
|
34
|
-
});
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
27
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": "ds-slider-dots", children: dots.map((dot, index) => {
|
|
28
|
+
return /* @__PURE__ */ jsx(SliderDot, { "data-testid": `ds-slider-dot`, "data-index": index, $left: dot.percentage, $color: dotColorMap[dot.value] }, `slider-dot-${dot.key}`);
|
|
29
|
+
}) });
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
SliderDots
|
|
33
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseSliderProps, HandlerConfig } from '../Slider.types';
|
|
3
3
|
type SliderHandlesProps = Pick<BaseSliderProps, 'tipFormatter'> & {
|
|
4
4
|
disabled?: boolean;
|
|
5
5
|
handlersConfig?: HandlerConfig;
|