@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,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;
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
const calculateHandlersPercentagePosition = (variants) => {
|
|
2
2
|
if (!variants) {
|
|
3
3
|
return [];
|
|
4
4
|
}
|
|
5
|
-
return variants
|
|
6
|
-
return [].concat(prev, [curr.percentage + (prev.length ? prev[prev.length - 1] : 0)]);
|
|
7
|
-
}, []).slice(0, -1);
|
|
5
|
+
return variants?.reduce((prev, curr) => [...prev, curr.percentage + (prev.length ? prev[prev.length - 1] : 0)], []).slice(0, -1);
|
|
8
6
|
};
|
|
9
|
-
|
|
7
|
+
const getBlockedHandlersKeys = (handlers) => {
|
|
10
8
|
if (!handlers) {
|
|
11
9
|
return [];
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
return handlers[parseInt(handlerKey)].blocked;
|
|
15
|
-
});
|
|
11
|
+
const blockedHandlersKeys = Object.keys(handlers).filter((handlerKey) => handlers[parseInt(handlerKey)].blocked);
|
|
16
12
|
return blockedHandlersKeys.map(Number);
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
return !!handlers && Object.values(handlers).some(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const checkIsBlockedHandlersConfigEnabled = (handlers) => {
|
|
15
|
+
return !!handlers && Object.values(handlers).some(({
|
|
16
|
+
blocked
|
|
17
|
+
}) => blocked);
|
|
18
|
+
};
|
|
19
|
+
const checkIsBlockedVariantsChange = (blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions) => {
|
|
20
|
+
return blockedHandlersKeys.some((blockedHandlerKey) => currentHandlersPercentagePositions[blockedHandlerKey - 1] !== afterChangeHandlersPercentagePositions[blockedHandlerKey - 1]);
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
calculateHandlersPercentagePosition,
|
|
24
|
+
checkIsBlockedHandlersConfigEnabled,
|
|
25
|
+
checkIsBlockedVariantsChange,
|
|
26
|
+
getBlockedHandlersKeys
|
|
23
27
|
};
|
|
24
|
-
export var checkIsBlockedVariantsChange = function checkIsBlockedVariantsChange(blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions) {
|
|
25
|
-
return blockedHandlersKeys.some(function (blockedHandlerKey) {
|
|
26
|
-
return currentHandlersPercentagePositions[blockedHandlerKey - 1] !== afterChangeHandlersPercentagePositions[blockedHandlerKey - 1];
|
|
27
|
-
});
|
|
28
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-slider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"description": "Slider UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "vite build",
|
|
20
20
|
"build:css": "node ../../../scripts/style/less.js",
|
|
21
21
|
"build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
|
|
22
|
-
"build:watch": "
|
|
22
|
+
"build:watch": "vite build --watch",
|
|
23
23
|
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
24
24
|
"pack:ci": "pnpm pack --pack-destination ../../storybook/storybook-static/static",
|
|
25
25
|
"prepublish": "pnpm run build",
|
|
26
|
-
"test": "vitest",
|
|
27
|
-
"test:watch": "
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
28
|
"types": "tsc --noEmit",
|
|
29
29
|
"check:circular-dependencies": "madge --circular --extensions ts,tsx,js,jsx --ts-config tsconfig.json src/ --exclude '/dist/'",
|
|
30
30
|
"upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
],
|
|
36
36
|
"types": "dist/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@synerise/ds-form-field": "^1.3.
|
|
39
|
-
"@synerise/ds-tooltip": "^1.4.
|
|
40
|
-
"@synerise/ds-typography": "^1.1.
|
|
41
|
-
"@synerise/ds-utils": "^1.
|
|
38
|
+
"@synerise/ds-form-field": "^1.3.10",
|
|
39
|
+
"@synerise/ds-tooltip": "^1.4.10",
|
|
40
|
+
"@synerise/ds-typography": "^1.1.13",
|
|
41
|
+
"@synerise/ds-utils": "^1.7.1",
|
|
42
42
|
"@tanstack/react-ranger": "^0.0.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"react-intl": ">=3.12.0 <= 6.8",
|
|
52
52
|
"styled-components": "^5.3.3"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "e4ecca8944fc9b41c1b9d59c8bcad5e5e2013225"
|
|
55
55
|
}
|