@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,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
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { SliderMarksProps } from '../Slider.types';
|
|
3
3
|
export declare const SliderMarks: ({ marks, handlesWithValue, }: SliderMarksProps) => React.JSX.Element;
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
var updateMeasurements = useCallback(function () {
|
|
28
|
-
var element = sliderElementRef.current;
|
|
29
|
-
if (element != null && element.clientWidth) {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useCallback, useEffect } from "react";
|
|
3
|
+
import { Text } from "@synerise/ds-typography";
|
|
4
|
+
import { useResizeObserver } from "@synerise/ds-utils";
|
|
5
|
+
import { SliderMarks as SliderMarks$1, SliderMark } from "../Slider.styles.js";
|
|
6
|
+
import { useSliderContext } from "../context/SliderContext.js";
|
|
7
|
+
import { getTranslateX, isMarksObjType } from "../utils/Slider.utils.js";
|
|
8
|
+
const HANDLE_HALF_WIDTH = 22;
|
|
9
|
+
const SliderMarks = ({
|
|
10
|
+
marks,
|
|
11
|
+
handlesWithValue = true
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
rangerInstance,
|
|
15
|
+
rangerHandles
|
|
16
|
+
} = useSliderContext();
|
|
17
|
+
const [sliderWidth, setSliderWidth] = useState();
|
|
18
|
+
const [markAreas, setMarkAreas] = useState({});
|
|
19
|
+
const markRefs = useRef({});
|
|
20
|
+
const sliderElementRef = useRef();
|
|
21
|
+
const marksData = Object.entries(marks);
|
|
22
|
+
const handles = rangerInstance.handles().map((handle) => handle.value);
|
|
23
|
+
const updateMeasurements = useCallback(() => {
|
|
24
|
+
const element = sliderElementRef.current;
|
|
25
|
+
if (element?.clientWidth) {
|
|
30
26
|
setSliderWidth(element.clientWidth);
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
Object.keys(markRefs.current).forEach(
|
|
34
|
-
|
|
28
|
+
const areas = {};
|
|
29
|
+
Object.keys(markRefs.current).forEach((index) => {
|
|
30
|
+
const markElement = markRefs.current[index];
|
|
35
31
|
areas[index] = {
|
|
36
32
|
left: markElement.offsetLeft + getTranslateX(markElement),
|
|
37
33
|
width: markElement.clientWidth
|
|
@@ -39,47 +35,35 @@ export var SliderMarks = function SliderMarks(_ref) {
|
|
|
39
35
|
});
|
|
40
36
|
setMarkAreas(areas);
|
|
41
37
|
}, []);
|
|
42
|
-
useEffect(
|
|
43
|
-
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const element = rangerInstance.options.getRangerElement();
|
|
44
40
|
if (element) {
|
|
45
41
|
sliderElementRef.current = element;
|
|
46
42
|
}
|
|
47
43
|
updateMeasurements();
|
|
48
44
|
}, [rangerInstance, updateMeasurements]);
|
|
49
45
|
useResizeObserver(sliderElementRef, updateMeasurements);
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const isNearHandle = useCallback((index) => {
|
|
47
|
+
const markArea = markAreas[index];
|
|
52
48
|
if (!markArea || !sliderWidth) {
|
|
53
49
|
return false;
|
|
54
50
|
}
|
|
55
|
-
return handlesWithValue && handles.some(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var handleLowerThanMark = handleLeftPx < markArea.left;
|
|
51
|
+
return handlesWithValue && handles.some((handleValue, handleIndex) => {
|
|
52
|
+
const tooltipHalfWidth = rangerHandles.current?.[handleIndex] ? rangerHandles.current?.[handleIndex].clientWidth / 2 : HANDLE_HALF_WIDTH;
|
|
53
|
+
const handleLeft = rangerInstance.getPercentageForValue(handleValue);
|
|
54
|
+
const handleLeftPx = handleLeft * sliderWidth / 100;
|
|
55
|
+
const handleLowerThanMark = handleLeftPx < markArea.left;
|
|
61
56
|
return handleLowerThanMark && handleLeftPx + tooltipHalfWidth > markArea.left || !handleLowerThanMark && handleLeftPx - tooltipHalfWidth < markArea.left + markArea.width;
|
|
62
57
|
});
|
|
63
58
|
}, [handles, handlesWithValue, markAreas, rangerHandles, rangerInstance, sliderWidth]);
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return node && (markRefs.current[index] = node);
|
|
76
|
-
},
|
|
77
|
-
isNear: isNearHandle(index),
|
|
78
|
-
$left: left,
|
|
79
|
-
key: "slider-mark-" + index
|
|
80
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
81
|
-
size: "medium",
|
|
82
|
-
style: labelStyle
|
|
83
|
-
}, labelContent));
|
|
84
|
-
}));
|
|
85
|
-
};
|
|
59
|
+
return /* @__PURE__ */ jsx(SliderMarks$1, { "data-testid": "ds-slider-marks", children: marksData.map(([mark, markLabel], index) => {
|
|
60
|
+
const markValue = parseFloat(mark);
|
|
61
|
+
const left = rangerInstance.getPercentageForValue(markValue);
|
|
62
|
+
const labelStyle = isMarksObjType(markLabel) ? markLabel.style : void 0;
|
|
63
|
+
const labelContent = isMarksObjType(markLabel) ? markLabel.label : markLabel;
|
|
64
|
+
return /* @__PURE__ */ jsx(SliderMark, { ref: (node) => node && (markRefs.current[index] = node), isNear: isNearHandle(index), $left: left, children: /* @__PURE__ */ jsx(Text, { size: "medium", style: labelStyle, children: labelContent }) }, `slider-mark-${index}`);
|
|
65
|
+
}) });
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
SliderMarks
|
|
69
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ColorMap } from '../Slider.types';
|
|
3
3
|
type SliderSectionsProps = {
|
|
4
4
|
type: 'range' | 'allocation' | 'default';
|
|
5
5
|
tracksColorMap: ColorMap;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useTheme } from
|
|
3
|
-
import
|
|
4
|
-
import { useSliderContext } from
|
|
5
|
-
import { getVisibleSectionsForType } from
|
|
6
|
-
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "@synerise/ds-core";
|
|
3
|
+
import { SliderSection } from "../Slider.styles.js";
|
|
4
|
+
import { useSliderContext } from "../context/SliderContext.js";
|
|
5
|
+
import { getVisibleSectionsForType } from "../utils/Slider.utils.js";
|
|
6
|
+
const normalizeReversed = (section, reverse) => {
|
|
7
7
|
return reverse ? {
|
|
8
8
|
width: -section.width,
|
|
9
9
|
left: section.left + section.width
|
|
10
10
|
} : section;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
rangerInstance
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
$color: theme.palette[tracksColorMap[index]]
|
|
31
|
-
});
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
12
|
+
const SliderSections = ({
|
|
13
|
+
tracksColorMap,
|
|
14
|
+
type = "default",
|
|
15
|
+
reverse
|
|
16
|
+
}) => {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const {
|
|
19
|
+
rangerInstance
|
|
20
|
+
} = useSliderContext();
|
|
21
|
+
const steps = rangerInstance.getSteps();
|
|
22
|
+
return /* @__PURE__ */ jsx(Fragment, { children: steps.filter(getVisibleSectionsForType(type, steps.length)).map((section, index) => {
|
|
23
|
+
const normalisedSection = normalizeReversed(section, reverse);
|
|
24
|
+
return /* @__PURE__ */ jsx(SliderSection, { "data-testid": `ds-slider-section`, "data-index": index, $left: normalisedSection.left, $width: normalisedSection.width, "data-color": tracksColorMap[index], $color: theme.palette[tracksColorMap[index]] }, `slider-section-${index}`);
|
|
25
|
+
}) });
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
SliderSections
|
|
29
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React,
|
|
2
|
-
import
|
|
1
|
+
import { default as React, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { Ranger } from '@tanstack/react-ranger';
|
|
3
3
|
interface SliderContextType {
|
|
4
4
|
rangerInstance: Ranger<HTMLDivElement>;
|
|
5
5
|
rangerHandles: RefObject<Record<number, HTMLElement>>;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, children);
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const SliderContext = createContext(void 0);
|
|
4
|
+
const SliderProvider = ({
|
|
5
|
+
children,
|
|
6
|
+
rangerInstance,
|
|
7
|
+
rangerHandles
|
|
8
|
+
}) => {
|
|
9
|
+
return /* @__PURE__ */ jsx(SliderContext.Provider, { value: {
|
|
10
|
+
rangerInstance,
|
|
11
|
+
rangerHandles
|
|
12
|
+
}, children });
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const useSliderContext = () => {
|
|
15
|
+
const context = useContext(SliderContext);
|
|
16
16
|
if (!context) {
|
|
17
|
-
throw new Error(
|
|
17
|
+
throw new Error("useSliderContext must be used within a SliderProvider");
|
|
18
18
|
}
|
|
19
19
|
return context;
|
|
20
|
-
};
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
SliderProvider,
|
|
23
|
+
useSliderContext
|
|
24
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColorMap } from '../Slider.types';
|
|
2
2
|
export declare const useColorMap: (count: number, type: "default" | "allocation" | "range", customMap?: ColorMap) => ColorMap;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { useMemo } from
|
|
2
|
-
import { getDefaultColorMap } from
|
|
3
|
-
|
|
4
|
-
return useMemo(
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { getDefaultColorMap } from "../utils/Slider.utils.js";
|
|
3
|
+
const useColorMap = (count, type, customMap) => {
|
|
4
|
+
return useMemo(() => {
|
|
5
5
|
return customMap || getDefaultColorMap(count, type);
|
|
6
6
|
}, [customMap, count, type]);
|
|
7
|
-
};
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
useColorMap
|
|
10
|
+
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const useInvertedColors = ({
|
|
2
|
+
inverted,
|
|
3
|
+
colorMap
|
|
4
|
+
}) => {
|
|
5
|
+
const GREY_200 = "grey-200";
|
|
6
|
+
const lineColor = inverted ? colorMap[0] : GREY_200;
|
|
7
|
+
const tracksColorMap = inverted ? {
|
|
7
8
|
0: GREY_200
|
|
8
9
|
} : colorMap;
|
|
9
10
|
return {
|
|
10
|
-
lineColor
|
|
11
|
-
tracksColorMap
|
|
11
|
+
lineColor,
|
|
12
|
+
tracksColorMap
|
|
12
13
|
};
|
|
13
|
-
};
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
useInvertedColors
|
|
17
|
+
};
|
package/dist/index.js
CHANGED
package/dist/modules.d.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
File without changes
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Maps values from right to left (max on left, min on right)
|
|
4
|
-
*/
|
|
5
|
-
export var reversedInterpolator = {
|
|
6
|
-
getPercentageForValue: function getPercentageForValue(val, min, max) {
|
|
1
|
+
const reversedInterpolator = {
|
|
2
|
+
getPercentageForValue: (val, min, max) => {
|
|
7
3
|
if (max === min) {
|
|
8
4
|
return 0;
|
|
9
5
|
}
|
|
10
|
-
// Reverse the percentage calculation
|
|
11
6
|
return (max - val) / (max - min) * 100;
|
|
12
7
|
},
|
|
13
|
-
getValueForClientX:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var percentage = Math.min(Math.max(relativePosition / trackDims.width, 0), 1);
|
|
18
|
-
// Reverse: percentage from left becomes percentage from right
|
|
19
|
-
var reversedPercentage = 1 - percentage;
|
|
20
|
-
// Convert back to value
|
|
8
|
+
getValueForClientX: (clientX, trackDims, min, max) => {
|
|
9
|
+
const relativePosition = clientX - trackDims.left;
|
|
10
|
+
const percentage = Math.min(Math.max(relativePosition / trackDims.width, 0), 1);
|
|
11
|
+
const reversedPercentage = 1 - percentage;
|
|
21
12
|
return min + reversedPercentage * (max - min);
|
|
22
13
|
}
|
|
23
|
-
};
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
reversedInterpolator
|
|
17
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ColorMap, MarkObj } from '../Slider.types';
|
|
3
3
|
export declare const getDefaultTooltipPopupContainer: () => HTMLElement;
|
|
4
4
|
export declare const couldBeInverted: (value: number | readonly number[], inverted?: boolean) => boolean;
|
|
5
5
|
export declare const getDefaultColorMap: (handleCount: number, type: "default" | "allocation" | "range") => ColorMap;
|