@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +29 -49
  3. package/dist/Slider.d.ts +2 -2
  4. package/dist/Slider.js +15 -13
  5. package/dist/Slider.styles.d.ts +12 -12
  6. package/dist/Slider.styles.js +37 -67
  7. package/dist/Slider.types.d.ts +2 -2
  8. package/dist/Slider.types.js +1 -1
  9. package/dist/components/AllocationMarks.d.ts +2 -2
  10. package/dist/components/AllocationMarks.js +37 -42
  11. package/dist/components/AllocationMarks.styles.d.ts +5 -5
  12. package/dist/components/AllocationMarks.styles.js +16 -17
  13. package/dist/components/AllocationSlider.d.ts +2 -2
  14. package/dist/components/AllocationSlider.js +65 -88
  15. package/dist/components/DefaultSlider.d.ts +2 -2
  16. package/dist/components/DefaultSlider.js +58 -79
  17. package/dist/components/RangeSlider.d.ts +2 -2
  18. package/dist/components/RangeSlider.js +63 -88
  19. package/dist/components/SliderAbove.d.ts +1 -1
  20. package/dist/components/SliderAbove.js +15 -14
  21. package/dist/components/SliderDots.d.ts +2 -2
  22. package/dist/components/SliderDots.js +28 -31
  23. package/dist/components/SliderHandles.d.ts +2 -2
  24. package/dist/components/SliderHandles.js +36 -54
  25. package/dist/components/SliderLine.d.ts +2 -2
  26. package/dist/components/SliderLine.js +34 -46
  27. package/dist/components/SliderMarks.d.ts +2 -2
  28. package/dist/components/SliderMarks.js +48 -64
  29. package/dist/components/SliderSections.d.ts +2 -2
  30. package/dist/components/SliderSections.js +24 -28
  31. package/dist/context/SliderContext.d.ts +2 -2
  32. package/dist/context/SliderContext.js +20 -16
  33. package/dist/hooks/useColorMap.d.ts +1 -1
  34. package/dist/hooks/useColorMap.js +8 -5
  35. package/dist/hooks/useInvertedColors.d.ts +1 -1
  36. package/dist/hooks/useInvertedColors.js +13 -9
  37. package/dist/index.js +4 -2
  38. package/dist/modules.d.js +1 -1
  39. package/dist/modules.d.ts +0 -0
  40. package/dist/utils/Slider.interpolators.d.ts +1 -1
  41. package/dist/utils/Slider.interpolators.js +10 -16
  42. package/dist/utils/Slider.utils.d.ts +2 -2
  43. package/dist/utils/Slider.utils.js +36 -33
  44. package/dist/utils/allocation.utils.d.ts +2 -2
  45. package/dist/utils/allocation.utils.js +30 -63
  46. package/dist/utils/allocationHandlers.utils.d.ts +1 -1
  47. package/dist/utils/allocationHandlers.utils.js +17 -18
  48. package/package.json +10 -10
@@ -1,29 +1,25 @@
1
- import { defaultColorsOrder } from '@synerise/ds-core';
2
- export var getDefaultTooltipPopupContainer = function getDefaultTooltipPopupContainer() {
3
- return document.querySelector(".ant-slider");
4
- };
5
- export var couldBeInverted = function couldBeInverted(value, inverted) {
6
- return Boolean(inverted && (typeof value === 'number' || value.length < 3));
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(function (item, index) {
9
+ defaultColorsOrder.forEach((item, index) => {
14
10
  colorMap[index] = item;
15
11
  });
16
12
  }
17
13
  return colorMap;
18
14
  };
19
- export var isMarksObjType = function isMarksObjType(item) {
20
- return Boolean(item && typeof item === 'object' && 'label' in item);
15
+ const isMarksObjType = (item) => {
16
+ return Boolean(item && typeof item === "object" && "label" in item);
21
17
  };
22
- export var getClosestIndex = function getClosestIndex(values, targetValue) {
23
- var closestIndex = 0;
24
- var minDistance = Math.abs(values[0] - targetValue);
25
- for (var i = 1; i < values.length; i++) {
26
- var distance = Math.abs(values[i] - targetValue);
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
- export var getVisibleSectionsForType = function getVisibleSectionsForType(type, total) {
35
- return function (_, index) {
36
- if (type === 'range') {
37
- return index !== 0 && index !== total - 1;
38
- }
39
- if (type === 'default') {
40
- return index !== total - 1;
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
- export var getTranslateX = function getTranslateX(element) {
46
- var style = window.getComputedStyle(element);
47
- var matrix = new WebKitCSSMatrix(style.transform);
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 { type ReactNode } from 'react';
2
- import { type AllocationVariant } from '../Slider.types';
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
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- export var countControlGroupAllocation = function countControlGroupAllocation(userAllocation) {
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
- var allocation = [].concat(variants.map(function (v) {
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
- export var mergeAllocationWithVariants = function mergeAllocationWithVariants(variants, allocation) {
26
- if (variants === void 0) {
27
- variants = [];
28
- }
29
- return variants.map(function (v, index) {
30
- return _extends({}, v, {
31
- percentage: allocation[index]
32
- });
33
- });
34
- };
35
- export var mapUserAllocationToHandles = function mapUserAllocationToHandles(userAllocation) {
36
- return userAllocation.reduce(function (result, item, index) {
37
- return [].concat(result, [parseInt(item, 10) + parseInt(result[index - 1] || 0, 10)]);
38
- }, []).slice(0, userAllocation.length - 1);
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
- var DEFAULT_MIN_PERCENTAGE = 1;
69
- export var checkIsPercentageInBoundaries = function checkIsPercentageInBoundaries(variants) {
70
- return !variants.some(function (variant) {
71
- var _variant$minPercentag;
72
- return variant.percentage < ((_variant$minPercentag = variant.minPercentage) != null ? _variant$minPercentag : DEFAULT_MIN_PERCENTAGE);
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 { type AllocationVariant, type HandlerConfig } from '../Slider.types';
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
- export var calculateHandlersPercentagePosition = function calculateHandlersPercentagePosition(variants) {
1
+ const calculateHandlersPercentagePosition = (variants) => {
2
2
  if (!variants) {
3
3
  return [];
4
4
  }
5
- return variants == null ? void 0 : variants.reduce(function (prev, curr) {
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
- export var getBlockedHandlersKeys = function getBlockedHandlersKeys(handlers) {
7
+ const getBlockedHandlersKeys = (handlers) => {
10
8
  if (!handlers) {
11
9
  return [];
12
10
  }
13
- var blockedHandlersKeys = Object.keys(handlers).filter(function (handlerKey) {
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
- export var checkIsBlockedHandlersConfigEnabled = function checkIsBlockedHandlersConfigEnabled(handlers) {
19
- return !!handlers && Object.values(handlers).some(function (_ref) {
20
- var blocked = _ref.blocked;
21
- return blocked;
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.11",
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": "pnpm run build:js && pnpm run build:css && pnpm run defs",
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": "pnpm run build:js -- --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": "pnpm run 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.8",
39
- "@synerise/ds-tooltip": "^1.4.8",
40
- "@synerise/ds-typography": "^1.1.11",
41
- "@synerise/ds-utils": "^1.6.0",
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": "8dfafc5d7278f09d430f1e7499782d05c76b47c0"
54
+ "gitHead": "e4ecca8944fc9b41c1b9d59c8bcad5e5e2013225"
55
55
  }