@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,112 +1,89 @@
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
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { useRanger } from '@tanstack/react-ranger';
4
- import * as S from '../Slider.styles';
5
- import { SliderProvider } from '../context/SliderContext';
6
- import { useColorMap } from '../hooks/useColorMap';
7
- import { getClosestIndex } from '../utils/Slider.utils';
8
- import { checkIsPercentageInBoundaries, countAllocation, mapSliderValueToVariants, mapUserAllocationToHandles } from '../utils/allocation.utils';
9
- import { calculateHandlersPercentagePosition, checkIsBlockedHandlersConfigEnabled, checkIsBlockedVariantsChange, getBlockedHandlersKeys } from '../utils/allocationHandlers.utils';
10
- import { AllocationMarks } from './AllocationMarks';
11
- import { SliderAbove } from './SliderAbove';
12
- import { SliderLine } from './SliderLine';
13
- export var AllocationSlider = function AllocationSlider(_ref) {
14
- var _variants$length;
15
- var allocationConfig = _ref.allocationConfig,
16
- tracksColorMap = _ref.tracksColorMap,
17
- description = _ref.description,
18
- handlers = _ref.handlers,
19
- _ref$step = _ref.step,
20
- step = _ref$step === void 0 ? 1 : _ref$step,
21
- label = _ref.label,
22
- thick = _ref.thick,
23
- disabled = _ref.disabled,
24
- dots = _ref.dots;
25
- var rangerHandlesRef = useRef({});
26
- var variants = allocationConfig.variants,
27
- onAllocationChange = allocationConfig.onAllocationChange,
28
- controlGroupEnabled = allocationConfig.controlGroupEnabled;
29
- var _useState = useState(countAllocation(variants, controlGroupEnabled)),
30
- allocations = _useState[0],
31
- setAllocations = _useState[1];
32
- useEffect(function () {
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect, useMemo, useCallback } from "react";
3
+ import { useRanger } from "@tanstack/react-ranger";
4
+ import { SliderWrapper } from "../Slider.styles.js";
5
+ import { SliderProvider } from "../context/SliderContext.js";
6
+ import { useColorMap } from "../hooks/useColorMap.js";
7
+ import { getClosestIndex } from "../utils/Slider.utils.js";
8
+ import { countAllocation, mapSliderValueToVariants, checkIsPercentageInBoundaries, mapUserAllocationToHandles } from "../utils/allocation.utils.js";
9
+ import { checkIsBlockedHandlersConfigEnabled, getBlockedHandlersKeys, calculateHandlersPercentagePosition, checkIsBlockedVariantsChange } from "../utils/allocationHandlers.utils.js";
10
+ import { AllocationMarks } from "./AllocationMarks.js";
11
+ import { SliderAbove } from "./SliderAbove.js";
12
+ import { SliderLine } from "./SliderLine.js";
13
+ const AllocationSlider = ({
14
+ allocationConfig,
15
+ tracksColorMap,
16
+ description,
17
+ handlers,
18
+ step = 1,
19
+ label,
20
+ thick,
21
+ disabled,
22
+ dots
23
+ }) => {
24
+ const rangerHandlesRef = useRef({});
25
+ const {
26
+ variants,
27
+ onAllocationChange,
28
+ controlGroupEnabled
29
+ } = allocationConfig;
30
+ const [allocations, setAllocations] = useState(countAllocation(variants, controlGroupEnabled));
31
+ useEffect(() => {
33
32
  setAllocations(countAllocation(variants, controlGroupEnabled));
34
33
  }, [variants, controlGroupEnabled]);
35
- var rangerRef = useRef(null);
36
- var _useMemo = useMemo(function () {
37
- return {
38
- blockedHandlersKeys: getBlockedHandlersKeys(handlers),
39
- isBlockedHandlersConfigEnabled: checkIsBlockedHandlersConfigEnabled(handlers)
40
- };
41
- }, [handlers]),
42
- blockedHandlersKeys = _useMemo.blockedHandlersKeys,
43
- isBlockedHandlersConfigEnabled = _useMemo.isBlockedHandlersConfigEnabled;
44
- var colorMap = useColorMap((_variants$length = variants == null ? void 0 : variants.length) != null ? _variants$length : 9, 'allocation', tracksColorMap);
45
- var currentHandlersPercentagePositions = calculateHandlersPercentagePosition(variants);
46
- var handleChange = useCallback(function (value) {
47
- var calculatedVariants = mapSliderValueToVariants(value, variants);
34
+ const rangerRef = useRef(null);
35
+ const {
36
+ blockedHandlersKeys,
37
+ isBlockedHandlersConfigEnabled
38
+ } = useMemo(() => ({
39
+ blockedHandlersKeys: getBlockedHandlersKeys(handlers),
40
+ isBlockedHandlersConfigEnabled: checkIsBlockedHandlersConfigEnabled(handlers)
41
+ }), [handlers]);
42
+ const colorMap = useColorMap(variants?.length ?? 9, "allocation", tracksColorMap);
43
+ const currentHandlersPercentagePositions = calculateHandlersPercentagePosition(variants);
44
+ const handleChange = useCallback((value) => {
45
+ const calculatedVariants = mapSliderValueToVariants(value, variants);
48
46
  if (!checkIsPercentageInBoundaries(calculatedVariants)) {
49
47
  return;
50
48
  }
51
49
  if (isBlockedHandlersConfigEnabled) {
52
- var afterChangeHandlersPercentagePositions = calculateHandlersPercentagePosition(calculatedVariants);
53
- var isBlockedVariantChanged = checkIsBlockedVariantsChange(blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions);
50
+ const afterChangeHandlersPercentagePositions = calculateHandlersPercentagePosition(calculatedVariants);
51
+ const isBlockedVariantChanged = checkIsBlockedVariantsChange(blockedHandlersKeys, currentHandlersPercentagePositions, afterChangeHandlersPercentagePositions);
54
52
  if (isBlockedVariantChanged) {
55
53
  return;
56
54
  }
57
55
  }
58
56
  setAllocations(countAllocation(variants, controlGroupEnabled));
59
- onAllocationChange == null || onAllocationChange(calculatedVariants);
57
+ onAllocationChange?.(calculatedVariants);
60
58
  }, [blockedHandlersKeys, controlGroupEnabled, currentHandlersPercentagePositions, isBlockedHandlersConfigEnabled, onAllocationChange, variants]);
61
- var rangerInstance = useRanger({
62
- getRangerElement: function getRangerElement() {
63
- return rangerRef.current;
64
- },
59
+ const rangerInstance = useRanger({
60
+ getRangerElement: () => rangerRef.current,
65
61
  values: mapUserAllocationToHandles(allocations),
66
62
  min: 0,
67
63
  max: 100,
68
64
  stepSize: step,
69
65
  tickSize: step,
70
- onDrag: function onDrag(instance) {
66
+ onDrag: (instance) => {
71
67
  handleChange(instance.sortedValues);
72
68
  },
73
- onChange: function onChange(instance) {
69
+ onChange: (instance) => {
74
70
  handleChange(instance.sortedValues);
75
71
  }
76
72
  });
77
- var handleLineClick = function handleLineClick(event) {
78
- var clicked = rangerInstance.getValueForClientX(event.clientX);
79
- var newValue = rangerInstance.roundToStep(clicked);
80
- var handleValues = mapUserAllocationToHandles(allocations);
81
- var closestIndex = getClosestIndex(handleValues, clicked);
82
- var updatedValues = handleValues.map(function (item, index) {
83
- return index === closestIndex ? newValue : item;
84
- }).sort(function (a, b) {
85
- return a - b;
86
- });
73
+ const handleLineClick = (event) => {
74
+ const clicked = rangerInstance.getValueForClientX(event.clientX);
75
+ const newValue = rangerInstance.roundToStep(clicked);
76
+ const handleValues = mapUserAllocationToHandles(allocations);
77
+ const closestIndex = getClosestIndex(handleValues, clicked);
78
+ const updatedValues = handleValues.map((item, index) => index === closestIndex ? newValue : item).sort((a, b) => a - b);
87
79
  handleChange(updatedValues);
88
80
  };
89
- return /*#__PURE__*/React.createElement(SliderProvider, {
90
- rangerInstance: rangerInstance,
91
- rangerHandles: rangerHandlesRef
92
- }, /*#__PURE__*/React.createElement(S.SliderWrapper, {
93
- ref: rangerRef,
94
- $disabled: disabled
95
- }, /*#__PURE__*/React.createElement(SliderAbove, {
96
- label: label,
97
- description: description
98
- }), /*#__PURE__*/React.createElement(SliderLine, {
99
- onLineClick: !disabled ? handleLineClick : undefined,
100
- type: "allocation",
101
- tracksColorMap: colorMap,
102
- thick: thick,
103
- disabled: disabled,
104
- handlersConfig: handlers,
105
- dots: dots
106
- }), /*#__PURE__*/React.createElement(AllocationMarks, _extends({
107
- variants: []
108
- }, allocationConfig, {
109
- tracksColorMap: colorMap,
110
- allocations: allocations
111
- }))));
112
- };
81
+ return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { ref: rangerRef, $disabled: disabled, children: [
82
+ /* @__PURE__ */ jsx(SliderAbove, { label, description }),
83
+ /* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, type: "allocation", tracksColorMap: colorMap, thick, disabled, handlersConfig: handlers, dots }),
84
+ /* @__PURE__ */ jsx(AllocationMarks, { variants: [], ...allocationConfig, tracksColorMap: colorMap, allocations })
85
+ ] }) });
86
+ };
87
+ export {
88
+ AllocationSlider
89
+ };
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- import { type DefaultSliderProps } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { DefaultSliderProps } from '../Slider.types';
3
3
  export declare const DefaultSlider: (props: DefaultSliderProps) => React.JSX.Element;
@@ -1,91 +1,70 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import { useRanger } from '@tanstack/react-ranger';
3
- import * as S from '../Slider.styles';
4
- import { SliderProvider } from '../context/SliderContext';
5
- import { useColorMap } from '../hooks/useColorMap';
6
- import { reversedInterpolator } from '../utils/Slider.interpolators';
7
- import { couldBeInverted } from '../utils/Slider.utils';
8
- import { SliderAbove } from './SliderAbove';
9
- import { SliderLine } from './SliderLine';
10
- import { SliderMarks } from './SliderMarks';
11
- export var DefaultSlider = function DefaultSlider(props) {
12
- var label = props.label,
13
- inverted = props.inverted,
14
- reverse = props.reverse,
15
- customColorMap = props.tracksColorMap,
16
- thick = props.thick,
17
- description = props.description,
18
- disabled = props.disabled,
19
- _props$max = props.max,
20
- max = _props$max === void 0 ? 100 : _props$max,
21
- _props$min = props.min,
22
- min = _props$min === void 0 ? 0 : _props$min,
23
- _props$value = props.value,
24
- initialValue = _props$value === void 0 ? 50 : _props$value,
25
- tipFormatter = props.tipFormatter,
26
- dots = props.dots,
27
- _props$step = props.step,
28
- step = _props$step === void 0 ? 1 : _props$step,
29
- marks = props.marks,
30
- onChange = props.onChange,
31
- onAfterChange = props.onAfterChange;
32
- var tracksColorMap = useColorMap(1, 'default', customColorMap);
33
- var rangerRef = useRef(null);
34
- var rangerHandlesRef = useRef({});
35
- var _useState = useState(initialValue),
36
- value = _useState[0],
37
- setValue = _useState[1];
38
- useEffect(function () {
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect } from "react";
3
+ import { useRanger } from "@tanstack/react-ranger";
4
+ import { SliderWrapper } from "../Slider.styles.js";
5
+ import { SliderProvider } from "../context/SliderContext.js";
6
+ import { useColorMap } from "../hooks/useColorMap.js";
7
+ import { reversedInterpolator } from "../utils/Slider.interpolators.js";
8
+ import { couldBeInverted } from "../utils/Slider.utils.js";
9
+ import { SliderAbove } from "./SliderAbove.js";
10
+ import { SliderLine } from "./SliderLine.js";
11
+ import { SliderMarks } from "./SliderMarks.js";
12
+ const DefaultSlider = (props) => {
13
+ const {
14
+ label,
15
+ inverted,
16
+ reverse,
17
+ tracksColorMap: customColorMap,
18
+ thick,
19
+ description,
20
+ disabled,
21
+ max = 100,
22
+ min = 0,
23
+ value: initialValue = 50,
24
+ tipFormatter,
25
+ dots,
26
+ step = 1,
27
+ marks,
28
+ onChange,
29
+ onAfterChange
30
+ } = props;
31
+ const tracksColorMap = useColorMap(1, "default", customColorMap);
32
+ const rangerRef = useRef(null);
33
+ const rangerHandlesRef = useRef({});
34
+ const [value, setValue] = useState(initialValue);
35
+ useEffect(() => {
39
36
  setValue(initialValue);
40
37
  }, [initialValue]);
41
- var rangerInstance = useRanger({
42
- getRangerElement: function getRangerElement() {
43
- return rangerRef.current;
44
- },
38
+ const rangerInstance = useRanger({
39
+ getRangerElement: () => rangerRef.current,
45
40
  values: [value],
46
- min: min,
47
- max: max,
41
+ min,
42
+ max,
48
43
  stepSize: step,
49
44
  tickSize: step,
50
- onDrag: function onDrag(instance) {
45
+ onDrag: (instance) => {
51
46
  setValue(instance.sortedValues[0]);
52
- onChange == null || onChange(instance.sortedValues[0]);
47
+ onChange?.(instance.sortedValues[0]);
53
48
  },
54
- onChange: function onChange(instance) {
49
+ onChange: (instance) => {
55
50
  setValue(instance.sortedValues[0]);
56
- onAfterChange == null || onAfterChange(instance.sortedValues[0]);
51
+ onAfterChange?.(instance.sortedValues[0]);
57
52
  },
58
- interpolator: reverse ? reversedInterpolator : undefined
53
+ interpolator: reverse ? reversedInterpolator : void 0
59
54
  });
60
- var handleLineClick = function handleLineClick(event) {
61
- var clicked = rangerInstance.getValueForClientX(event.clientX);
62
- var newValue = rangerInstance.roundToStep(clicked);
55
+ const handleLineClick = (event) => {
56
+ const clicked = rangerInstance.getValueForClientX(event.clientX);
57
+ const newValue = rangerInstance.roundToStep(clicked);
63
58
  setValue(newValue);
64
- onChange == null || onChange(newValue);
65
- onAfterChange == null || onAfterChange(newValue);
59
+ onChange?.(newValue);
60
+ onAfterChange?.(newValue);
66
61
  };
67
- return /*#__PURE__*/React.createElement(SliderProvider, {
68
- rangerInstance: rangerInstance,
69
- rangerHandles: rangerHandlesRef
70
- }, /*#__PURE__*/React.createElement(S.SliderWrapper, {
71
- withoutMarks: !marks,
72
- ref: rangerRef,
73
- $disabled: disabled
74
- }, /*#__PURE__*/React.createElement(SliderAbove, {
75
- label: label,
76
- description: description
77
- }), /*#__PURE__*/React.createElement(SliderLine, {
78
- onLineClick: !disabled ? handleLineClick : undefined,
79
- thick: thick,
80
- tracksColorMap: tracksColorMap,
81
- type: "default",
82
- disabled: disabled,
83
- dots: dots,
84
- tipFormatter: tipFormatter,
85
- inverted: couldBeInverted(value, inverted),
86
- reverse: reverse
87
- }), marks && /*#__PURE__*/React.createElement(SliderMarks, {
88
- handlesWithValue: tipFormatter !== false,
89
- marks: marks
90
- })));
91
- };
62
+ return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { withoutMarks: !marks, ref: rangerRef, $disabled: disabled, children: [
63
+ /* @__PURE__ */ jsx(SliderAbove, { label, description }),
64
+ /* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, thick, tracksColorMap, type: "default", disabled, dots, tipFormatter, inverted: couldBeInverted(value, inverted), reverse }),
65
+ marks && /* @__PURE__ */ jsx(SliderMarks, { handlesWithValue: tipFormatter !== false, marks })
66
+ ] }) });
67
+ };
68
+ export {
69
+ DefaultSlider
70
+ };
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- import { type RangeSliderProps } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { RangeSliderProps } from '../Slider.types';
3
3
  export declare const RangeSlider: (props: Omit<RangeSliderProps, "range">) => React.JSX.Element;
@@ -1,99 +1,74 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import { useRanger } from '@tanstack/react-ranger';
3
- import * as S from '../Slider.styles';
4
- import { SliderProvider } from '../context/SliderContext';
5
- import { useColorMap } from '../hooks/useColorMap';
6
- import { reversedInterpolator } from '../utils/Slider.interpolators';
7
- import { couldBeInverted, getClosestIndex } from '../utils/Slider.utils';
8
- import { SliderAbove } from './SliderAbove';
9
- import { SliderLine } from './SliderLine';
10
- import { SliderMarks } from './SliderMarks';
11
- export var RangeSlider = function RangeSlider(props) {
12
- var label = props.label,
13
- inverted = props.inverted,
14
- tracksColorMap = props.tracksColorMap,
15
- thick = props.thick,
16
- description = props.description,
17
- disabled = props.disabled,
18
- _props$max = props.max,
19
- max = _props$max === void 0 ? 100 : _props$max,
20
- _props$min = props.min,
21
- min = _props$min === void 0 ? 0 : _props$min,
22
- _props$value = props.value,
23
- initialValue = _props$value === void 0 ? [] : _props$value,
24
- _props$step = props.step,
25
- step = _props$step === void 0 ? 1 : _props$step,
26
- marks = props.marks,
27
- onChange = props.onChange,
28
- onAfterChange = props.onAfterChange,
29
- tipFormatter = props.tipFormatter,
30
- dots = props.dots,
31
- reverse = props.reverse;
32
- var colorMap = useColorMap(initialValue.length, 'range', tracksColorMap);
33
- var rangerRef = useRef(null);
34
- var rangerHandlesRef = useRef({});
35
- var _useState = useState(initialValue),
36
- values = _useState[0],
37
- setValues = _useState[1];
38
- useEffect(function () {
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect } from "react";
3
+ import { useRanger } from "@tanstack/react-ranger";
4
+ import { SliderWrapper } from "../Slider.styles.js";
5
+ import { SliderProvider } from "../context/SliderContext.js";
6
+ import { useColorMap } from "../hooks/useColorMap.js";
7
+ import { reversedInterpolator } from "../utils/Slider.interpolators.js";
8
+ import { couldBeInverted, getClosestIndex } from "../utils/Slider.utils.js";
9
+ import { SliderAbove } from "./SliderAbove.js";
10
+ import { SliderLine } from "./SliderLine.js";
11
+ import { SliderMarks } from "./SliderMarks.js";
12
+ const RangeSlider = (props) => {
13
+ const {
14
+ label,
15
+ inverted,
16
+ tracksColorMap,
17
+ thick,
18
+ description,
19
+ disabled,
20
+ max = 100,
21
+ min = 0,
22
+ value: initialValue = [],
23
+ step = 1,
24
+ marks,
25
+ onChange,
26
+ onAfterChange,
27
+ tipFormatter,
28
+ dots,
29
+ reverse
30
+ } = props;
31
+ const colorMap = useColorMap(initialValue.length, "range", tracksColorMap);
32
+ const rangerRef = useRef(null);
33
+ const rangerHandlesRef = useRef({});
34
+ const [values, setValues] = useState(initialValue);
35
+ useEffect(() => {
39
36
  setValues(initialValue);
40
37
  }, [initialValue]);
41
- var rangerInstance = useRanger({
42
- getRangerElement: function getRangerElement() {
43
- return rangerRef.current;
44
- },
45
- values: values,
46
- min: min,
47
- max: max,
38
+ const rangerInstance = useRanger({
39
+ getRangerElement: () => rangerRef.current,
40
+ values,
41
+ min,
42
+ max,
48
43
  stepSize: step,
49
44
  tickSize: step,
50
- onDrag: function onDrag(instance) {
51
- var roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
45
+ onDrag: (instance) => {
46
+ const roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
52
47
  setValues(roundedValues);
53
- onChange == null || onChange(roundedValues);
48
+ onChange?.(roundedValues);
54
49
  },
55
- onChange: function onChange(instance) {
56
- var roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
50
+ onChange: (instance) => {
51
+ const roundedValues = instance.sortedValues.map(rangerInstance.roundToStep);
57
52
  setValues(roundedValues);
58
- onAfterChange == null || onAfterChange(roundedValues);
53
+ onAfterChange?.(roundedValues);
59
54
  },
60
- interpolator: reverse ? reversedInterpolator : undefined
55
+ interpolator: reverse ? reversedInterpolator : void 0
61
56
  });
62
- var handleLineClick = function handleLineClick(event) {
63
- var clicked = rangerInstance.getValueForClientX(event.clientX);
64
- var newValue = rangerInstance.roundToStep(clicked);
65
- var closestIndex = getClosestIndex(values, clicked);
66
- var updatedValues = values.map(function (item, index) {
67
- return index === closestIndex ? newValue : item;
68
- }).sort(function (a, b) {
69
- return a - b;
70
- });
57
+ const handleLineClick = (event) => {
58
+ const clicked = rangerInstance.getValueForClientX(event.clientX);
59
+ const newValue = rangerInstance.roundToStep(clicked);
60
+ const closestIndex = getClosestIndex(values, clicked);
61
+ const updatedValues = values.map((item, index) => index === closestIndex ? newValue : item).sort((a, b) => a - b);
71
62
  setValues(updatedValues);
72
- onChange == null || onChange(updatedValues);
73
- onAfterChange == null || onAfterChange(updatedValues);
63
+ onChange?.(updatedValues);
64
+ onAfterChange?.(updatedValues);
74
65
  };
75
- return /*#__PURE__*/React.createElement(SliderProvider, {
76
- rangerInstance: rangerInstance,
77
- rangerHandles: rangerHandlesRef
78
- }, /*#__PURE__*/React.createElement(S.SliderWrapper, {
79
- withoutMarks: !marks,
80
- ref: rangerRef,
81
- $disabled: disabled
82
- }, /*#__PURE__*/React.createElement(SliderAbove, {
83
- label: label,
84
- description: description
85
- }), /*#__PURE__*/React.createElement(SliderLine, {
86
- onLineClick: !disabled ? handleLineClick : undefined,
87
- thick: thick,
88
- tracksColorMap: colorMap,
89
- type: "range",
90
- disabled: disabled,
91
- dots: dots,
92
- tipFormatter: tipFormatter,
93
- inverted: couldBeInverted(values, inverted),
94
- reverse: reverse
95
- }), marks && /*#__PURE__*/React.createElement(SliderMarks, {
96
- handlesWithValue: tipFormatter !== false,
97
- marks: marks
98
- })));
99
- };
66
+ return /* @__PURE__ */ jsx(SliderProvider, { rangerInstance, rangerHandles: rangerHandlesRef, children: /* @__PURE__ */ jsxs(SliderWrapper, { withoutMarks: !marks, ref: rangerRef, $disabled: disabled, children: [
67
+ /* @__PURE__ */ jsx(SliderAbove, { label, description }),
68
+ /* @__PURE__ */ jsx(SliderLine, { onLineClick: !disabled ? handleLineClick : void 0, thick, tracksColorMap: colorMap, type: "range", disabled, dots, tipFormatter, inverted: couldBeInverted(values, inverted), reverse }),
69
+ marks && /* @__PURE__ */ jsx(SliderMarks, { handlesWithValue: tipFormatter !== false, marks })
70
+ ] }) });
71
+ };
72
+ export {
73
+ RangeSlider
74
+ };
@@ -1,4 +1,4 @@
1
- import React, { type ReactNode } from 'react';
1
+ import { default as React, ReactNode } from 'react';
2
2
  type SliderAboveProps = {
3
3
  label?: ReactNode;
4
4
  description?: ReactNode;
@@ -1,14 +1,15 @@
1
- import React from 'react';
2
- import { ContentBelowElement, FormFieldLabel } from '@synerise/ds-form-field';
3
- import * as S from '../Slider.styles';
4
- export var SliderAbove = function SliderAbove(_ref) {
5
- var label = _ref.label,
6
- description = _ref.description;
7
- return (label || description) && /*#__PURE__*/React.createElement(S.SliderLabel, {
8
- "data-testid": "ds-slider-details"
9
- }, label && /*#__PURE__*/React.createElement(FormFieldLabel, {
10
- label: label
11
- }), description && /*#__PURE__*/React.createElement(ContentBelowElement, {
12
- description: description
13
- }));
14
- };
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { FormFieldLabel, ContentBelowElement } from "@synerise/ds-form-field";
3
+ import { SliderLabel } from "../Slider.styles.js";
4
+ const SliderAbove = ({
5
+ label,
6
+ description
7
+ }) => {
8
+ return (label || description) && /* @__PURE__ */ jsxs(SliderLabel, { "data-testid": "ds-slider-details", children: [
9
+ label && /* @__PURE__ */ jsx(FormFieldLabel, { label }),
10
+ description && /* @__PURE__ */ jsx(ContentBelowElement, { description })
11
+ ] });
12
+ };
13
+ export {
14
+ SliderAbove
15
+ };
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { type ColorMap } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { ColorMap } from '../Slider.types';
3
3
  type SliderDotsProps = {
4
4
  tracksColorMap: ColorMap;
5
5
  type: 'default' | 'range' | 'allocation';
@@ -1,36 +1,33 @@
1
- import React, { useMemo } from 'react';
2
- import * as S from '../Slider.styles';
3
- import { useSliderContext } from '../context/SliderContext';
4
- import { getVisibleSectionsForType } from '../utils/Slider.utils';
5
- export var SliderDots = function SliderDots(_ref) {
6
- var _rangerInstance$optio;
7
- var tracksColorMap = _ref.tracksColorMap,
8
- type = _ref.type;
9
- var _useSliderContext = useSliderContext(),
10
- rangerInstance = _useSliderContext.rangerInstance;
11
- var dots = rangerInstance.getTicks();
12
- var steps = rangerInstance.getSteps();
13
- var tickSize = (_rangerInstance$optio = rangerInstance.options.tickSize) != null ? _rangerInstance$optio : 1;
14
- var dotColorMap = useMemo(function () {
15
- var map = {};
16
- steps.filter(getVisibleSectionsForType(type, steps.length)).forEach(function (step, stepIndex) {
17
- var start = step.left;
18
- var end = start + step.width;
19
- for (var i = start; i < end; i += tickSize) {
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { SliderDot } from "../Slider.styles.js";
4
+ import { useSliderContext } from "../context/SliderContext.js";
5
+ import { getVisibleSectionsForType } from "../utils/Slider.utils.js";
6
+ const SliderDots = ({
7
+ tracksColorMap,
8
+ type
9
+ }) => {
10
+ const {
11
+ rangerInstance
12
+ } = useSliderContext();
13
+ const dots = rangerInstance.getTicks();
14
+ const steps = rangerInstance.getSteps();
15
+ const tickSize = rangerInstance.options.tickSize ?? 1;
16
+ const dotColorMap = useMemo(() => {
17
+ const map = {};
18
+ steps.filter(getVisibleSectionsForType(type, steps.length)).forEach((step, stepIndex) => {
19
+ const start = step.left;
20
+ const end = start + step.width;
21
+ for (let i = start; i < end; i += tickSize) {
20
22
  map[i] = tracksColorMap[stepIndex];
21
23
  }
22
24
  });
23
25
  return map;
24
26
  }, [steps, tickSize, tracksColorMap, type]);
25
- return /*#__PURE__*/React.createElement("div", {
26
- "data-testid": "ds-slider-dots"
27
- }, dots.map(function (dot, index) {
28
- return /*#__PURE__*/React.createElement(S.SliderDot, {
29
- key: "slider-dot-" + dot.key,
30
- "data-testid": "ds-slider-dot",
31
- "data-index": index,
32
- $left: dot.percentage,
33
- $color: dotColorMap[dot.value]
34
- });
35
- }));
36
- };
27
+ return /* @__PURE__ */ jsx("div", { "data-testid": "ds-slider-dots", children: dots.map((dot, index) => {
28
+ return /* @__PURE__ */ jsx(SliderDot, { "data-testid": `ds-slider-dot`, "data-index": index, $left: dot.percentage, $color: dotColorMap[dot.value] }, `slider-dot-${dot.key}`);
29
+ }) });
30
+ };
31
+ export {
32
+ SliderDots
33
+ };
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { type BaseSliderProps, type HandlerConfig } from '../Slider.types';
1
+ import { default as React } from 'react';
2
+ import { BaseSliderProps, HandlerConfig } from '../Slider.types';
3
3
  type SliderHandlesProps = Pick<BaseSliderProps, 'tipFormatter'> & {
4
4
  disabled?: boolean;
5
5
  handlersConfig?: HandlerConfig;