@synerise/ds-slider 1.1.12 → 1.1.14
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/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 +8 -8
|
@@ -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;
|
|
@@ -1,54 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Tooltip from
|
|
3
|
-
import { Text } from
|
|
4
|
-
import
|
|
5
|
-
import { useSliderContext } from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
onMouseDown: !disabled && !blocked ? onMouseDownHandler : undefined,
|
|
38
|
-
onTouchStart: !disabled && !blocked ? onTouchStart : undefined,
|
|
39
|
-
role: "slider",
|
|
40
|
-
"aria-valuemin": rangerInstance.options.min,
|
|
41
|
-
"aria-valuemax": rangerInstance.options.max,
|
|
42
|
-
"aria-valuenow": value,
|
|
43
|
-
isActive: isActive
|
|
44
|
-
}), type !== 'allocation' && tipFormatter !== false && /*#__PURE__*/React.createElement(S.SliderHandleValue, {
|
|
45
|
-
ref: function ref(node) {
|
|
46
|
-
return node && rangerHandles.current && (rangerHandles.current[i] = node);
|
|
47
|
-
},
|
|
48
|
-
isActive: isActive
|
|
49
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
50
|
-
size: "medium"
|
|
51
|
-
}, tipFormatter ? tipFormatter(value) : value)));
|
|
52
|
-
return blocked && blockedTooltipProps ? /*#__PURE__*/React.createElement(Tooltip, blockedTooltipProps, handle) : handle;
|
|
53
|
-
}));
|
|
54
|
-
};
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Tooltip from "@synerise/ds-tooltip";
|
|
3
|
+
import { Text } from "@synerise/ds-typography";
|
|
4
|
+
import { EventTrap, SliderHandleWrapper, SliderHandle, SliderHandleValue } from "../Slider.styles.js";
|
|
5
|
+
import { useSliderContext } from "../context/SliderContext.js";
|
|
6
|
+
const SliderHandles = ({
|
|
7
|
+
disabled,
|
|
8
|
+
handlersConfig,
|
|
9
|
+
tipFormatter,
|
|
10
|
+
type
|
|
11
|
+
}) => {
|
|
12
|
+
const {
|
|
13
|
+
rangerInstance,
|
|
14
|
+
rangerHandles
|
|
15
|
+
} = useSliderContext();
|
|
16
|
+
return /* @__PURE__ */ jsx(EventTrap, { "data-testid": "ds-slider-handles", onClick: (e) => e.stopPropagation(), children: rangerInstance.handles().map(({
|
|
17
|
+
value,
|
|
18
|
+
onKeyDownHandler,
|
|
19
|
+
onMouseDownHandler,
|
|
20
|
+
onTouchStart,
|
|
21
|
+
isActive
|
|
22
|
+
}, i) => {
|
|
23
|
+
const {
|
|
24
|
+
blocked,
|
|
25
|
+
blockedTooltipProps
|
|
26
|
+
} = handlersConfig && handlersConfig[i + 1] ? handlersConfig[i + 1] : {};
|
|
27
|
+
const handle = /* @__PURE__ */ jsxs(SliderHandleWrapper, { $left: rangerInstance.getPercentageForValue(value), children: [
|
|
28
|
+
/* @__PURE__ */ jsx(SliderHandle, { "data-testid": "ds-slider-handle", "data-index": i, $disabled: disabled, $blocked: blocked, onKeyDown: !disabled && !blocked ? onKeyDownHandler : void 0, onMouseDown: !disabled && !blocked ? onMouseDownHandler : void 0, onTouchStart: !disabled && !blocked ? onTouchStart : void 0, role: "slider", "aria-valuemin": rangerInstance.options.min, "aria-valuemax": rangerInstance.options.max, "aria-valuenow": value, isActive }),
|
|
29
|
+
type !== "allocation" && tipFormatter !== false && /* @__PURE__ */ jsx(SliderHandleValue, { ref: (node) => node && rangerHandles.current && (rangerHandles.current[i] = node), isActive, children: /* @__PURE__ */ jsx(Text, { size: "medium", children: tipFormatter ? tipFormatter(value) : value }) })
|
|
30
|
+
] }, `slider-handle-${i}`);
|
|
31
|
+
return blocked && blockedTooltipProps ? /* @__PURE__ */ jsx(Tooltip, { ...blockedTooltipProps, children: handle }) : handle;
|
|
32
|
+
}) });
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
SliderHandles
|
|
36
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React,
|
|
2
|
-
import {
|
|
1
|
+
import { default as React, MouseEvent } from 'react';
|
|
2
|
+
import { BaseSliderProps, ColorMap, HandlerConfig, SharedSliderProps } from '../Slider.types';
|
|
3
3
|
type SliderHandlesProps = Pick<SharedSliderProps, 'disabled' | 'dots' | 'thick'> & Pick<BaseSliderProps, 'inverted' | 'tipFormatter' | 'reverse'> & {
|
|
4
4
|
type: 'allocation' | 'range' | 'default';
|
|
5
5
|
tracksColorMap: ColorMap;
|
|
@@ -1,46 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { useInvertedColors } from
|
|
4
|
-
import { SliderDots } from
|
|
5
|
-
import { SliderHandles } from
|
|
6
|
-
import { SliderSections } from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"data-testid": "ds-slider-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
tracksColorMap: tracksColorMap,
|
|
36
|
-
type: type
|
|
37
|
-
})), dots && /*#__PURE__*/React.createElement(SliderDots, {
|
|
38
|
-
type: type,
|
|
39
|
-
tracksColorMap: tracksColorMap
|
|
40
|
-
}), /*#__PURE__*/React.createElement(SliderHandles, {
|
|
41
|
-
type: type,
|
|
42
|
-
handlersConfig: handlersConfig,
|
|
43
|
-
disabled: disabled,
|
|
44
|
-
tipFormatter: tipFormatter
|
|
45
|
-
}));
|
|
46
|
-
};
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { SliderBar, SliderLine as SliderLine$1 } from "../Slider.styles.js";
|
|
3
|
+
import { useInvertedColors } from "../hooks/useInvertedColors.js";
|
|
4
|
+
import { SliderDots } from "./SliderDots.js";
|
|
5
|
+
import { SliderHandles } from "./SliderHandles.js";
|
|
6
|
+
import { SliderSections } from "./SliderSections.js";
|
|
7
|
+
const SliderLine = ({
|
|
8
|
+
disabled,
|
|
9
|
+
onLineClick,
|
|
10
|
+
tracksColorMap: colorMap,
|
|
11
|
+
thick,
|
|
12
|
+
type,
|
|
13
|
+
handlersConfig,
|
|
14
|
+
inverted,
|
|
15
|
+
tipFormatter,
|
|
16
|
+
reverse,
|
|
17
|
+
dots
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
lineColor,
|
|
21
|
+
tracksColorMap
|
|
22
|
+
} = useInvertedColors({
|
|
23
|
+
inverted: !!inverted,
|
|
24
|
+
colorMap
|
|
25
|
+
});
|
|
26
|
+
return /* @__PURE__ */ jsxs(SliderBar, { "data-inverted": inverted ? "true" : "false", $type: type, "data-testid": "ds-slider-bar", onClick: onLineClick, children: [
|
|
27
|
+
/* @__PURE__ */ jsx(SliderLine$1, { "data-testid": "ds-slider-line", lineColor, thick, children: /* @__PURE__ */ jsx(SliderSections, { reverse, tracksColorMap, type }) }),
|
|
28
|
+
dots && /* @__PURE__ */ jsx(SliderDots, { type, tracksColorMap }),
|
|
29
|
+
/* @__PURE__ */ jsx(SliderHandles, { type, handlersConfig, disabled, tipFormatter })
|
|
30
|
+
] });
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
SliderLine
|
|
34
|
+
};
|