@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,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;
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import { defaultColorsOrder } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export var getDefaultColorMap = function getDefaultColorMap(handleCount, type) {
|
|
9
|
-
var colorMap = {};
|
|
10
|
-
if (type !== 'allocation' && handleCount <= 2) {
|
|
11
|
-
colorMap['0'] = 'green-600';
|
|
1
|
+
import { defaultColorsOrder } from "@synerise/ds-core";
|
|
2
|
+
const getDefaultTooltipPopupContainer = () => document.querySelector(`.ant-slider`);
|
|
3
|
+
const couldBeInverted = (value, inverted) => Boolean(inverted && (typeof value === "number" || value.length < 3));
|
|
4
|
+
const getDefaultColorMap = (handleCount, type) => {
|
|
5
|
+
const colorMap = {};
|
|
6
|
+
if (type !== "allocation" && handleCount <= 2) {
|
|
7
|
+
colorMap["0"] = "green-600";
|
|
12
8
|
} else {
|
|
13
|
-
defaultColorsOrder.forEach(
|
|
9
|
+
defaultColorsOrder.forEach((item, index) => {
|
|
14
10
|
colorMap[index] = item;
|
|
15
11
|
});
|
|
16
12
|
}
|
|
17
13
|
return colorMap;
|
|
18
14
|
};
|
|
19
|
-
|
|
20
|
-
return Boolean(item && typeof item ===
|
|
15
|
+
const isMarksObjType = (item) => {
|
|
16
|
+
return Boolean(item && typeof item === "object" && "label" in item);
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
|
|
18
|
+
const getClosestIndex = (values, targetValue) => {
|
|
19
|
+
let closestIndex = 0;
|
|
20
|
+
let minDistance = Math.abs(values[0] - targetValue);
|
|
21
|
+
for (let i = 1; i < values.length; i++) {
|
|
22
|
+
const distance = Math.abs(values[i] - targetValue);
|
|
27
23
|
if (distance < minDistance) {
|
|
28
24
|
minDistance = distance;
|
|
29
25
|
closestIndex = i;
|
|
@@ -31,19 +27,26 @@ export var getClosestIndex = function getClosestIndex(values, targetValue) {
|
|
|
31
27
|
}
|
|
32
28
|
return closestIndex;
|
|
33
29
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
30
|
+
const getVisibleSectionsForType = (type, total) => (_, index) => {
|
|
31
|
+
if (type === "range") {
|
|
32
|
+
return index !== 0 && index !== total - 1;
|
|
33
|
+
}
|
|
34
|
+
if (type === "default") {
|
|
35
|
+
return index !== total - 1;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
44
38
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
const getTranslateX = (element) => {
|
|
40
|
+
const style = window.getComputedStyle(element);
|
|
41
|
+
const matrix = new WebKitCSSMatrix(style.transform);
|
|
48
42
|
return matrix.m41;
|
|
49
|
-
};
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
couldBeInverted,
|
|
46
|
+
getClosestIndex,
|
|
47
|
+
getDefaultColorMap,
|
|
48
|
+
getDefaultTooltipPopupContainer,
|
|
49
|
+
getTranslateX,
|
|
50
|
+
getVisibleSectionsForType,
|
|
51
|
+
isMarksObjType
|
|
52
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AllocationVariant } from '../Slider.types';
|
|
3
3
|
export declare const countControlGroupAllocation: (userAllocation: number[]) => number;
|
|
4
4
|
export declare const countAllocation: (variants?: AllocationVariant[] | undefined, controlGroup?: boolean) => number[];
|
|
5
5
|
export declare const mergeAllocationWithVariants: (variants: Partial<AllocationVariant>[] | undefined, allocation: number[]) => AllocationVariant[];
|
|
@@ -1,74 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return 100 - userAllocation.reduce(function (prev, curr) {
|
|
4
|
-
return prev + curr;
|
|
5
|
-
}, 0);
|
|
6
|
-
};
|
|
7
|
-
export var countAllocation = function countAllocation(variants, controlGroup) {
|
|
8
|
-
if (variants === void 0) {
|
|
9
|
-
variants = [];
|
|
10
|
-
}
|
|
11
|
-
if (controlGroup === void 0) {
|
|
12
|
-
controlGroup = false;
|
|
13
|
-
}
|
|
1
|
+
const countControlGroupAllocation = (userAllocation) => 100 - userAllocation.reduce((prev, curr) => prev + curr, 0);
|
|
2
|
+
const countAllocation = (variants = [], controlGroup = false) => {
|
|
14
3
|
if (variants.length === 0) {
|
|
15
4
|
return [];
|
|
16
5
|
}
|
|
17
|
-
|
|
18
|
-
return v.percentage;
|
|
19
|
-
}));
|
|
6
|
+
const allocation = [...variants.map((v) => v.percentage)];
|
|
20
7
|
if (controlGroup) {
|
|
21
8
|
allocation.push(countControlGroupAllocation(allocation));
|
|
22
9
|
}
|
|
23
10
|
return allocation;
|
|
24
11
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
export var mapUserAllocationToMarks = function mapUserAllocationToMarks(userAllocation, markRenderer, variants) {
|
|
41
|
-
if (variants === void 0) {
|
|
42
|
-
variants = [];
|
|
43
|
-
}
|
|
44
|
-
return userAllocation.map(function (a, i) {
|
|
45
|
-
return {
|
|
46
|
-
value: a + "%",
|
|
47
|
-
view: a / 2 + (i ? userAllocation.slice(0, i).reduce(function (result, item) {
|
|
48
|
-
return result + item;
|
|
49
|
-
}, 0) : 0)
|
|
50
|
-
};
|
|
51
|
-
}).reduce(function (result, item, index) {
|
|
52
|
-
var _extends2;
|
|
53
|
-
return _extends({}, result, (_extends2 = {}, _extends2[item.view] = markRenderer(item.value, index, variants), _extends2));
|
|
54
|
-
}, {});
|
|
55
|
-
};
|
|
56
|
-
export var mapSliderValueToVariants = function mapSliderValueToVariants(value, variants) {
|
|
57
|
-
if (variants === void 0) {
|
|
58
|
-
variants = [];
|
|
59
|
-
}
|
|
60
|
-
var allocation = value.reduce(function (prev, curr) {
|
|
61
|
-
return [].concat(prev, [curr - prev.reduce(function (previous, current) {
|
|
62
|
-
return previous + current;
|
|
63
|
-
}, 0)]);
|
|
64
|
-
}, []);
|
|
12
|
+
const mergeAllocationWithVariants = (variants = [], allocation) => variants.map((v, index) => ({
|
|
13
|
+
...v,
|
|
14
|
+
percentage: allocation[index]
|
|
15
|
+
}));
|
|
16
|
+
const mapUserAllocationToHandles = (userAllocation) => userAllocation.reduce((result, item, index) => [...result, parseInt(item, 10) + parseInt(result[index - 1] || 0, 10)], []).slice(0, userAllocation.length - 1);
|
|
17
|
+
const mapUserAllocationToMarks = (userAllocation, markRenderer, variants = []) => userAllocation.map((a, i) => ({
|
|
18
|
+
value: `${a}%`,
|
|
19
|
+
view: a / 2 + (i ? userAllocation.slice(0, i).reduce((result, item) => result + item, 0) : 0)
|
|
20
|
+
})).reduce((result, item, index) => ({
|
|
21
|
+
...result,
|
|
22
|
+
[item.view]: markRenderer(item.value, index, variants)
|
|
23
|
+
}), {});
|
|
24
|
+
const mapSliderValueToVariants = (value, variants = []) => {
|
|
25
|
+
const allocation = value.reduce((prev, curr) => [...prev, curr - prev.reduce((previous, current) => previous + current, 0)], []);
|
|
65
26
|
allocation.push(countControlGroupAllocation(allocation));
|
|
66
27
|
return mergeAllocationWithVariants(variants, allocation);
|
|
67
28
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return !variants.some(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
const DEFAULT_MIN_PERCENTAGE = 1;
|
|
30
|
+
const checkIsPercentageInBoundaries = (variants) => {
|
|
31
|
+
return !variants.some((variant) => variant.percentage < (variant.minPercentage ?? DEFAULT_MIN_PERCENTAGE));
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
checkIsPercentageInBoundaries,
|
|
35
|
+
countAllocation,
|
|
36
|
+
countControlGroupAllocation,
|
|
37
|
+
mapSliderValueToVariants,
|
|
38
|
+
mapUserAllocationToHandles,
|
|
39
|
+
mapUserAllocationToMarks,
|
|
40
|
+
mergeAllocationWithVariants
|
|
41
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AllocationVariant, HandlerConfig } from '../Slider.types';
|
|
2
2
|
export declare const calculateHandlersPercentagePosition: (variants?: AllocationVariant[]) => number[];
|
|
3
3
|
export declare const getBlockedHandlersKeys: (handlers?: HandlerConfig) => number[];
|
|
4
4
|
export declare const checkIsBlockedHandlersConfigEnabled: (handlers?: HandlerConfig) => boolean;
|