@synerise/ds-slider 0.14.1 → 0.14.3
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 +19 -0
- package/dist/Allocation/Allocation.js +22 -40
- package/dist/Allocation/Allocation.styles.js +3 -12
- package/dist/Allocation/BlockedHandlersWithTooltip/BlockedHandlersWithTooltip.js +2 -3
- package/dist/Slider.js +21 -41
- package/dist/Slider.types.js +0 -1
- package/dist/utils/allocation.utils.js +0 -18
- package/dist/utils/allocationHandlers.utils.js +0 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.14.3](https://github.com/Synerise/synerise-design/compare/@synerise/ds-slider@0.14.2...@synerise/ds-slider@0.14.3) (2024-11-28)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-slider
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.14.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-slider@0.14.1...@synerise/ds-slider@0.14.2) (2024-11-21)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **core:** onError fn types ([c34bdfe](https://github.com/Synerise/synerise-design/commit/c34bdfe9da898d7999c605f9fbcbba4716dfb6d4))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.14.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-slider@0.14.0...@synerise/ds-slider@0.14.1) (2024-11-12)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @synerise/ds-slider
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var _excluded = ["allocationConfig", "tracksColorMap", "description", "tipFormatter", "handlers"];
|
|
2
|
-
|
|
3
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
|
|
5
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
4
|
import React, { useState, useEffect, useMemo } from 'react';
|
|
8
5
|
import { useIntl } from 'react-intl';
|
|
9
6
|
import Tooltip from '@synerise/ds-tooltip';
|
|
@@ -13,32 +10,27 @@ import { checkIsPercentageInBoundaries, countAllocation, mapSliderValueToVariant
|
|
|
13
10
|
import { BlockedHandlersWithTooltip } from './BlockedHandlersWithTooltip';
|
|
14
11
|
import { calculateHandlersPercentagePosition, checkIsBlockedHandlersConfigEnabled, checkIsBlockedVariantsChange, getBlockedHandlersKeys } from '../utils/allocationHandlers.utils';
|
|
15
12
|
import * as S from './Allocation.styles';
|
|
16
|
-
|
|
17
13
|
var Allocation = function Allocation(_ref) {
|
|
18
14
|
var allocationConfig = _ref.allocationConfig,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
_ref$tracksColorMap = _ref.tracksColorMap,
|
|
16
|
+
tracksColorMap = _ref$tracksColorMap === void 0 ? buildDefaultTracksColorMap() : _ref$tracksColorMap,
|
|
17
|
+
description = _ref.description,
|
|
18
|
+
_tipFormatter = _ref.tipFormatter,
|
|
19
|
+
handlers = _ref.handlers,
|
|
20
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
26
21
|
var _ref2 = allocationConfig,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
variants = _ref2.variants,
|
|
23
|
+
onAllocationChange = _ref2.onAllocationChange,
|
|
24
|
+
controlGroupEnabled = _ref2.controlGroupEnabled,
|
|
25
|
+
controlGroupLabel = _ref2.controlGroupLabel,
|
|
26
|
+
controlGroupTooltip = _ref2.controlGroupTooltip;
|
|
33
27
|
var _useState = useState(countAllocation(variants, controlGroupEnabled)),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
allocations = _useState[0],
|
|
29
|
+
setAllocations = _useState[1];
|
|
37
30
|
var intl = useIntl();
|
|
38
31
|
useEffect(function () {
|
|
39
32
|
setAllocations(countAllocation(variants, controlGroupEnabled));
|
|
40
33
|
}, [variants, controlGroupEnabled]);
|
|
41
|
-
|
|
42
34
|
var markRenderer = function markRenderer(value, index, allocationVariants) {
|
|
43
35
|
return /*#__PURE__*/React.createElement(S.Mark, {
|
|
44
36
|
className: "slider-mark"
|
|
@@ -59,42 +51,33 @@ var Allocation = function Allocation(_ref) {
|
|
|
59
51
|
defaultMessage: 'CG'
|
|
60
52
|
}))));
|
|
61
53
|
};
|
|
62
|
-
|
|
63
54
|
var currentHandlersPercentagePositions = calculateHandlersPercentagePosition(variants);
|
|
64
|
-
|
|
65
55
|
var _useMemo = useMemo(function () {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
56
|
+
return {
|
|
57
|
+
blockedHandlersKeys: getBlockedHandlersKeys(handlers),
|
|
58
|
+
isBlockedHandlersConfigEnabled: checkIsBlockedHandlersConfigEnabled(handlers)
|
|
59
|
+
};
|
|
60
|
+
}, [handlers]),
|
|
61
|
+
blockedHandlersKeys = _useMemo.blockedHandlersKeys,
|
|
62
|
+
isBlockedHandlersConfigEnabled = _useMemo.isBlockedHandlersConfigEnabled;
|
|
74
63
|
var handleChange = function handleChange(value) {
|
|
75
64
|
if (typeof value === 'number') {
|
|
76
65
|
return;
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
var calculatedVariants = mapSliderValueToVariants(value, variants);
|
|
80
|
-
|
|
81
68
|
if (!checkIsPercentageInBoundaries(calculatedVariants)) {
|
|
82
69
|
return;
|
|
83
70
|
}
|
|
84
|
-
|
|
85
71
|
if (isBlockedHandlersConfigEnabled) {
|
|
86
72
|
var afterChangeHandlersPercentagePositions = calculateHandlersPercentagePosition(calculatedVariants);
|
|
87
73
|
var isBlockedVariantChanged = checkIsBlockedVariantsChange(blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions);
|
|
88
|
-
|
|
89
74
|
if (isBlockedVariantChanged) {
|
|
90
75
|
return;
|
|
91
76
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line no-unused-expressions
|
|
95
79
|
onAllocationChange == null || onAllocationChange(calculatedVariants);
|
|
96
80
|
};
|
|
97
|
-
|
|
98
81
|
return /*#__PURE__*/React.createElement(S.AllocationSlider, _extends({}, rest, {
|
|
99
82
|
useColorPalette: true,
|
|
100
83
|
tracksColorMap: tracksColorMap,
|
|
@@ -129,5 +112,4 @@ var Allocation = function Allocation(_ref) {
|
|
|
129
112
|
);
|
|
130
113
|
})));
|
|
131
114
|
};
|
|
132
|
-
|
|
133
115
|
export default Allocation;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
2
|
import { AntdSlider, createTracksStyles } from '../Slider.styles';
|
|
3
3
|
import { buildDefaultTracksColorMap } from '../Slider';
|
|
4
|
-
|
|
5
4
|
var defineCssSelectorWithRule = function defineCssSelectorWithRule(_ref) {
|
|
6
5
|
var indexes = _ref.indexes,
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
classConstPart = _ref.classConstPart,
|
|
7
|
+
cssRule = _ref.cssRule;
|
|
9
8
|
var variantsSize = indexes.length;
|
|
10
|
-
|
|
11
9
|
if (variantsSize === 0) {
|
|
12
10
|
return '';
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
var definedClassSpecificity = indexes.reduce(function (result, item, index) {
|
|
16
13
|
return "" + result + classConstPart + item + (index + 1 === variantsSize ? '' : ', ');
|
|
17
14
|
}, '');
|
|
18
15
|
return definedClassSpecificity + " { " + cssRule + " }";
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
export var INDEX_MAP = {
|
|
22
18
|
'0': 'cyan-600',
|
|
23
19
|
'1': 'yellow-600',
|
|
@@ -39,7 +35,7 @@ export var AllocationSlider = styled(AntdSlider).withConfig({
|
|
|
39
35
|
return createTracksStyles(props, props.tracksColorMap ? props.tracksColorMap : INDEX_MAP);
|
|
40
36
|
}, function (_ref2) {
|
|
41
37
|
var blockedHandlersKeys = _ref2.blockedHandlersKeys,
|
|
42
|
-
|
|
38
|
+
theme = _ref2.theme;
|
|
43
39
|
return defineCssSelectorWithRule({
|
|
44
40
|
indexes: blockedHandlersKeys,
|
|
45
41
|
classConstPart: '.ant-slider-handle-',
|
|
@@ -50,21 +46,16 @@ export var Mark = styled.div.withConfig({
|
|
|
50
46
|
displayName: "Allocationstyles__Mark",
|
|
51
47
|
componentId: "y7ylxd-1"
|
|
52
48
|
})(["text-align:center;"]);
|
|
53
|
-
|
|
54
49
|
var getColor = function getColor(props, defaultColor) {
|
|
55
50
|
if (defaultColor === void 0) {
|
|
56
51
|
defaultColor = 'grey-800';
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
var colors = buildDefaultTracksColorMap();
|
|
60
|
-
|
|
61
54
|
if (props.isCustomColor) {
|
|
62
55
|
return props.getColor && props.getColor(props.index) || defaultColor;
|
|
63
56
|
}
|
|
64
|
-
|
|
65
57
|
return props.theme.palette[(colors || INDEX_MAP)[props.index] || defaultColor];
|
|
66
58
|
};
|
|
67
|
-
|
|
68
59
|
export var MarkLetter = styled.div.withConfig({
|
|
69
60
|
displayName: "Allocationstyles__MarkLetter",
|
|
70
61
|
componentId: "y7ylxd-2"
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import Tooltip from '@synerise/ds-tooltip';
|
|
5
4
|
import * as S from './BlockedHandlerWthTooltip.styles';
|
|
6
5
|
export var BlockedHandlersWithTooltip = function BlockedHandlersWithTooltip(_ref) {
|
|
7
6
|
var blockedHandlersKeys = _ref.blockedHandlersKeys,
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
handlers = _ref.handlers,
|
|
8
|
+
handlersPosition = _ref.handlersPosition;
|
|
10
9
|
return /*#__PURE__*/React.createElement(React.Fragment, null, blockedHandlersKeys.map(function (blockedHandlerKey) {
|
|
11
10
|
return /*#__PURE__*/React.createElement(S.BlockedHandlerWithTooltipWrapper, {
|
|
12
11
|
key: blockedHandlerKey
|
package/dist/Slider.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var _excluded = ["useColorPalette", "label", "inverted", "getTooltipPopupContainer", "tracksColorMap", "type", "thickness", "description", "tipFormatter", "allocationConfig", "hideMinAndMaxMarks", "disabled", "max", "min", "value", "range"];
|
|
2
|
-
|
|
3
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
|
|
5
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
4
|
import React from 'react';
|
|
8
5
|
import { Label } from '@synerise/ds-typography';
|
|
9
6
|
import '@synerise/ds-core/dist/js/style';
|
|
@@ -12,18 +9,14 @@ import "./style/index.css";
|
|
|
12
9
|
import * as S from './Slider.styles';
|
|
13
10
|
import { SliderTypes } from './Slider.types';
|
|
14
11
|
import Allocation from './Allocation/Allocation';
|
|
15
|
-
|
|
16
12
|
var getDefaultTooltipPopupContainer = function getDefaultTooltipPopupContainer() {
|
|
17
13
|
return document.querySelector(".ant-slider");
|
|
18
14
|
};
|
|
19
|
-
|
|
20
15
|
var couldBeInverted = function couldBeInverted(value, inverted) {
|
|
21
16
|
return inverted && (typeof value === 'number' || value.length < 3);
|
|
22
17
|
};
|
|
23
|
-
|
|
24
18
|
var mapToColor = function mapToColor(_, idx) {
|
|
25
19
|
var _ref;
|
|
26
|
-
|
|
27
20
|
return _ref = {}, _ref[idx] = defaultColorsOrder[idx], _ref;
|
|
28
21
|
};
|
|
29
22
|
/**
|
|
@@ -31,63 +24,53 @@ var mapToColor = function mapToColor(_, idx) {
|
|
|
31
24
|
* into `{"0": "blue-600", "1": "yellow-600"}`.
|
|
32
25
|
* @returns Object Record<string, string>
|
|
33
26
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
27
|
export var buildDefaultTracksColorMap = function buildDefaultTracksColorMap() {
|
|
37
28
|
return Object.assign.apply(Object, [{}].concat(defaultColorsOrder.map(mapToColor)));
|
|
38
29
|
};
|
|
39
|
-
|
|
40
30
|
var Slider = function Slider(props) {
|
|
41
31
|
var useColorPalette = props.useColorPalette,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
label = props.label,
|
|
33
|
+
inverted = props.inverted,
|
|
34
|
+
getTooltipPopupContainer = props.getTooltipPopupContainer,
|
|
35
|
+
_props$tracksColorMap = props.tracksColorMap,
|
|
36
|
+
tracksColorMap = _props$tracksColorMap === void 0 ? buildDefaultTracksColorMap() : _props$tracksColorMap,
|
|
37
|
+
type = props.type,
|
|
38
|
+
thickness = props.thickness,
|
|
39
|
+
description = props.description,
|
|
40
|
+
_tipFormatter = props.tipFormatter,
|
|
41
|
+
allocationConfig = props.allocationConfig,
|
|
42
|
+
hideMinAndMaxMarks = props.hideMinAndMaxMarks,
|
|
43
|
+
disabled = props.disabled,
|
|
44
|
+
max = props.max,
|
|
45
|
+
min = props.min,
|
|
46
|
+
value = props.value,
|
|
47
|
+
range = props.range,
|
|
48
|
+
antdProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
60
49
|
var _React$useState = React.useState(false),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
reachedEnd = _React$useState[0],
|
|
51
|
+
setReachedEnd = _React$useState[1];
|
|
64
52
|
var _React$useState2 = React.useState(false),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
reachedStart = _React$useState2[0],
|
|
54
|
+
setReachedStart = _React$useState2[1];
|
|
68
55
|
var calcHandlePosition = React.useCallback(function () {
|
|
69
56
|
var handler = document.querySelectorAll('.ant-slider-handle');
|
|
70
57
|
var markTexts = document.querySelectorAll('.ant-slider-mark-text');
|
|
71
|
-
|
|
72
58
|
if (handler && markTexts != null && markTexts.length) {
|
|
73
59
|
var firstMark = markTexts[0].getBoundingClientRect();
|
|
74
60
|
var lastMark = markTexts[markTexts.length - 1].getBoundingClientRect();
|
|
75
61
|
var firstHandler = handler[0].getBoundingClientRect();
|
|
76
62
|
var lastHandler = handler[handler.length - 1].getBoundingClientRect();
|
|
77
|
-
|
|
78
63
|
if (firstMark.x + 10 + firstMark.width > firstHandler.x || firstMark.x + 10 + firstMark.width > lastHandler.x) {
|
|
79
64
|
setReachedStart(true);
|
|
80
65
|
} else {
|
|
81
66
|
setReachedStart(false);
|
|
82
67
|
}
|
|
83
|
-
|
|
84
68
|
if (lastMark.x - 30 < firstHandler.x || lastMark.x - 30 < lastHandler.x) {
|
|
85
69
|
setReachedEnd(true);
|
|
86
70
|
} else {
|
|
87
71
|
setReachedEnd(false);
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
|
-
|
|
91
74
|
return {
|
|
92
75
|
reachedEnd: reachedEnd,
|
|
93
76
|
reachedStart: reachedStart
|
|
@@ -101,11 +84,9 @@ var Slider = function Slider(props) {
|
|
|
101
84
|
var labelElement = React.useMemo(function () {
|
|
102
85
|
return label ? /*#__PURE__*/React.createElement(S.LabelWrapper, null, /*#__PURE__*/React.createElement(Label, null, label)) : null;
|
|
103
86
|
}, [label]);
|
|
104
|
-
|
|
105
87
|
if (type === SliderTypes.ALLOCATION && !!allocationConfig) {
|
|
106
88
|
return /*#__PURE__*/React.createElement(React.Fragment, null, labelElement, /*#__PURE__*/React.createElement(Allocation, props));
|
|
107
89
|
}
|
|
108
|
-
|
|
109
90
|
return /*#__PURE__*/React.createElement(React.Fragment, null, labelElement, /*#__PURE__*/React.createElement(S.AntdSlider, _extends({}, antdProps, {
|
|
110
91
|
min: min,
|
|
111
92
|
max: max,
|
|
@@ -128,5 +109,4 @@ var Slider = function Slider(props) {
|
|
|
128
109
|
getTooltipPopupContainer: getTooltipPopupContainer || getDefaultTooltipPopupContainer
|
|
129
110
|
})));
|
|
130
111
|
};
|
|
131
|
-
|
|
132
112
|
export default Slider;
|
package/dist/Slider.types.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
8
|
-
|
|
9
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
|
|
11
6
|
export var countControlGroupAllocation = function countControlGroupAllocation(userAllocation) {
|
|
12
7
|
return 100 - userAllocation.reduce(function (prev, curr) {
|
|
13
8
|
return prev + curr;
|
|
@@ -17,19 +12,15 @@ export var countAllocation = function countAllocation(variants, controlGroup, re
|
|
|
17
12
|
if (variants === void 0) {
|
|
18
13
|
variants = [];
|
|
19
14
|
}
|
|
20
|
-
|
|
21
15
|
if (controlGroup === void 0) {
|
|
22
16
|
controlGroup = false;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
18
|
if (recalculate === void 0) {
|
|
26
19
|
recalculate = false;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
if (variants.length === 0) {
|
|
30
22
|
return [];
|
|
31
23
|
}
|
|
32
|
-
|
|
33
24
|
if (recalculate) {
|
|
34
25
|
var numberOfVariants = controlGroup ? variants.length + 1 : variants.length;
|
|
35
26
|
var percentPerVariant = Math.floor(100 / numberOfVariants);
|
|
@@ -37,22 +28,18 @@ export var countAllocation = function countAllocation(variants, controlGroup, re
|
|
|
37
28
|
var recalculatedArr = new Array(numberOfVariants - 1).fill(percentPerVariant);
|
|
38
29
|
return [].concat(recalculatedArr, [percentPerVariant + percentLeft]);
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
var allocation = [].concat(variants.map(function (v) {
|
|
42
32
|
return v.percentage;
|
|
43
33
|
}));
|
|
44
|
-
|
|
45
34
|
if (controlGroup) {
|
|
46
35
|
allocation.push(countControlGroupAllocation(allocation));
|
|
47
36
|
}
|
|
48
|
-
|
|
49
37
|
return allocation;
|
|
50
38
|
};
|
|
51
39
|
export var mergeAllocationWithVariants = function mergeAllocationWithVariants(variants, allocation) {
|
|
52
40
|
if (variants === void 0) {
|
|
53
41
|
variants = [];
|
|
54
42
|
}
|
|
55
|
-
|
|
56
43
|
return variants.map(function (v, index) {
|
|
57
44
|
return _objectSpread({}, v, {
|
|
58
45
|
percentage: allocation[index]
|
|
@@ -63,7 +50,6 @@ export var recalculateVariantsAllocation = function recalculateVariantsAllocatio
|
|
|
63
50
|
if (controlGroup === void 0) {
|
|
64
51
|
controlGroup = false;
|
|
65
52
|
}
|
|
66
|
-
|
|
67
53
|
var allocation = countAllocation(variants, controlGroup, true);
|
|
68
54
|
return mergeAllocationWithVariants(variants, allocation);
|
|
69
55
|
};
|
|
@@ -76,7 +62,6 @@ export var mapUserAllocationToMarks = function mapUserAllocationToMarks(userAllo
|
|
|
76
62
|
if (variants === void 0) {
|
|
77
63
|
variants = [];
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
return userAllocation.map(function (a, i) {
|
|
81
66
|
return {
|
|
82
67
|
value: a + "%",
|
|
@@ -86,7 +71,6 @@ export var mapUserAllocationToMarks = function mapUserAllocationToMarks(userAllo
|
|
|
86
71
|
};
|
|
87
72
|
}).reduce(function (result, item, index) {
|
|
88
73
|
var _objectSpread2;
|
|
89
|
-
|
|
90
74
|
return _objectSpread({}, result, (_objectSpread2 = {}, _objectSpread2[item.view] = markRenderer(item.value, index, variants), _objectSpread2));
|
|
91
75
|
}, {});
|
|
92
76
|
};
|
|
@@ -94,7 +78,6 @@ export var mapSliderValueToVariants = function mapSliderValueToVariants(value, v
|
|
|
94
78
|
if (variants === void 0) {
|
|
95
79
|
variants = [];
|
|
96
80
|
}
|
|
97
|
-
|
|
98
81
|
var allocation = value.reduce(function (prev, curr) {
|
|
99
82
|
return [].concat(prev, [curr - prev.reduce(function (previous, current) {
|
|
100
83
|
return previous + current;
|
|
@@ -107,7 +90,6 @@ var DEFAULT_MIN_PERCENTAGE = 1;
|
|
|
107
90
|
export var checkIsPercentageInBoundaries = function checkIsPercentageInBoundaries(variants) {
|
|
108
91
|
return !variants.some(function (variant) {
|
|
109
92
|
var _variant$minPercentag;
|
|
110
|
-
|
|
111
93
|
return variant.percentage < ((_variant$minPercentag = variant.minPercentage) != null ? _variant$minPercentag : DEFAULT_MIN_PERCENTAGE);
|
|
112
94
|
});
|
|
113
95
|
};
|
|
@@ -2,7 +2,6 @@ export var calculateHandlersPercentagePosition = function calculateHandlersPerce
|
|
|
2
2
|
if (!variants) {
|
|
3
3
|
return [];
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
return variants == null ? void 0 : variants.reduce(function (prev, curr) {
|
|
7
6
|
return [].concat(prev, [curr.percentage + (prev.length ? prev[prev.length - 1] : 0)]);
|
|
8
7
|
}, []).slice(0, -1);
|
|
@@ -11,7 +10,6 @@ export var getBlockedHandlersKeys = function getBlockedHandlersKeys(handlers) {
|
|
|
11
10
|
if (!handlers) {
|
|
12
11
|
return [];
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
var blockedHandlersKeys = Object.keys(handlers).filter(function (handlerKey) {
|
|
16
14
|
return handlers[handlerKey].blocked;
|
|
17
15
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-slider",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Slider UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
],
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@synerise/ds-tooltip": "^0.14.
|
|
38
|
-
"@synerise/ds-typography": "^0.16.
|
|
39
|
-
"@synerise/ds-utils": "^0.31.
|
|
40
|
-
"react-intl": "6.8.4"
|
|
37
|
+
"@synerise/ds-tooltip": "^0.14.50",
|
|
38
|
+
"@synerise/ds-typography": "^0.16.7",
|
|
39
|
+
"@synerise/ds-utils": "^0.31.2"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"@synerise/ds-core": "*",
|
|
44
43
|
"antd": "4.7.0",
|
|
45
44
|
"react": ">=16.9.0 <= 17.0.2",
|
|
45
|
+
"react-intl": ">=3.12.0 <= 6.8",
|
|
46
46
|
"styled-components": "5.0.1"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4a56ee7ef816c22341ce704154dc7aa65b7d1dcc"
|
|
49
49
|
}
|