@elliemae/ds-slider 2.2.0-alpha.2 → 2.2.0-beta.0
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/cjs/DSSlider.js +33 -48
- package/cjs/components/SliderImp.js +158 -154
- package/cjs/components/Thumb.js +63 -64
- package/cjs/components/TickMarks.js +31 -72
- package/cjs/components/TickMarksValues.js +38 -59
- package/cjs/components/Track.js +55 -66
- package/cjs/components/context.js +13 -36
- package/cjs/components/styled.js +58 -93
- package/cjs/components/utils.js +36 -46
- package/cjs/index.js +11 -36
- package/cjs/prop-types.js +49 -52
- package/esm/DSSlider.js +20 -16
- package/esm/components/SliderImp.js +139 -120
- package/esm/components/Thumb.js +54 -33
- package/esm/components/TickMarks.js +23 -42
- package/esm/components/TickMarksValues.js +31 -30
- package/esm/components/Track.js +46 -36
- package/esm/components/context.js +5 -7
- package/esm/components/styled.js +44 -64
- package/esm/components/utils.js +29 -15
- package/esm/index.js +1 -7
- package/esm/prop-types.js +44 -23
- package/package.json +6 -6
- package/types/DSSlider.d.ts +1 -1
- package/cjs/DSSlider.js.map +0 -7
- package/cjs/components/SliderImp.js.map +0 -7
- package/cjs/components/Thumb.js.map +0 -7
- package/cjs/components/TickMarks.js.map +0 -7
- package/cjs/components/TickMarksValues.js.map +0 -7
- package/cjs/components/Track.js.map +0 -7
- package/cjs/components/context.js.map +0 -7
- package/cjs/components/styled.js.map +0 -7
- package/cjs/components/utils.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/prop-types.js.map +0 -7
- package/esm/DSSlider.js.map +0 -7
- package/esm/components/SliderImp.js.map +0 -7
- package/esm/components/Thumb.js.map +0 -7
- package/esm/components/TickMarks.js.map +0 -7
- package/esm/components/TickMarksValues.js.map +0 -7
- package/esm/components/Track.js.map +0 -7
- package/esm/components/context.js.map +0 -7
- package/esm/components/styled.js.map +0 -7
- package/esm/components/utils.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/prop-types.js.map +0 -7
package/cjs/components/utils.js
CHANGED
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var utils_exports = {};
|
|
29
|
-
__export(utils_exports, {
|
|
30
|
-
conformedLabel: () => conformedLabel,
|
|
31
|
-
conformedThumbLabel: () => conformedThumbLabel
|
|
32
|
-
});
|
|
33
|
-
var React = __toESM(require("react"));
|
|
34
|
-
var import_ds_utilities = __toESM(require("@elliemae/ds-utilities"));
|
|
35
|
-
const conformedLabel = (rangeValues, label = "", labelWithValue = false, withTwoHandles = false, customTickMarksValues = [], step = 1, minValue = 0) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dsUtilities = require('@elliemae/ds-utilities');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable max-params */
|
|
8
|
+
const conformedLabel = function (rangeValues) {
|
|
9
|
+
let label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
10
|
+
let labelWithValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
11
|
+
let withTwoHandles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
12
|
+
let customTickMarksValues = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
13
|
+
let step = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
|
14
|
+
let minValue = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
36
15
|
const msg = label.trim();
|
|
37
|
-
let value =
|
|
38
|
-
|
|
16
|
+
let value = '';
|
|
17
|
+
|
|
18
|
+
if (!dsUtilities.isEmpty(customTickMarksValues) && labelWithValue && label) {
|
|
39
19
|
const firstValue = customTickMarksValues[(rangeValues[0] - minValue) / step];
|
|
40
20
|
const secondValue = customTickMarksValues[(rangeValues[1] - minValue) / step];
|
|
41
|
-
value =
|
|
21
|
+
value = "".concat(firstValue || rangeValues[0].toFixed(1), " ").concat(withTwoHandles ? ", ".concat(secondValue || rangeValues[1].toFixed(1)) : '', " ");
|
|
42
22
|
} else if (labelWithValue && label) {
|
|
43
|
-
|
|
23
|
+
var _rangeValues$;
|
|
24
|
+
|
|
25
|
+
value = "".concat(rangeValues[0].toFixed(1), " ").concat(withTwoHandles ? ", ".concat((_rangeValues$ = rangeValues[1]) === null || _rangeValues$ === void 0 ? void 0 : _rangeValues$.toFixed(1)) : '', " ");
|
|
44
26
|
}
|
|
27
|
+
|
|
45
28
|
value = value.trim();
|
|
46
29
|
return [msg, value];
|
|
47
30
|
};
|
|
48
|
-
const conformedThumbLabel = (rangeValues
|
|
49
|
-
let
|
|
50
|
-
|
|
31
|
+
const conformedThumbLabel = function (rangeValues) {
|
|
32
|
+
let customTickMarksValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
33
|
+
let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
34
|
+
let step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
35
|
+
let minValue = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
36
|
+
let msg = "Value: ";
|
|
37
|
+
|
|
38
|
+
if (!dsUtilities.isEmpty(customTickMarksValues)) {
|
|
51
39
|
const foundValue = customTickMarksValues[(rangeValues[index] - minValue) / step];
|
|
52
|
-
msg +=
|
|
40
|
+
msg += "".concat(foundValue || rangeValues[index].toFixed(1));
|
|
53
41
|
} else {
|
|
54
|
-
msg +=
|
|
42
|
+
msg += "".concat(rangeValues[index].toFixed(1));
|
|
55
43
|
}
|
|
44
|
+
|
|
56
45
|
return msg;
|
|
57
46
|
};
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
|
|
48
|
+
exports.conformedLabel = conformedLabel;
|
|
49
|
+
exports.conformedThumbLabel = conformedThumbLabel;
|
package/cjs/index.js
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var src_exports = {};
|
|
29
|
-
__export(src_exports, {
|
|
30
|
-
default: () => import_DSSlider.default
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_DSSlider = __toESM(require("./DSSlider"));
|
|
34
|
-
__reExport(src_exports, __toESM(require("./DSSlider")));
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var DSSlider = require('./DSSlider.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.DSSlider = DSSlider.DSSlider;
|
|
10
|
+
exports.DSSliderWithSchema = DSSlider.DSSliderWithSchema;
|
|
11
|
+
exports["default"] = DSSlider.DSSlider;
|
package/cjs/prop-types.js
CHANGED
|
@@ -1,47 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var prop_types_exports = {};
|
|
29
|
-
__export(prop_types_exports, {
|
|
30
|
-
defaultProps: () => defaultProps,
|
|
31
|
-
sliderPropTypes: () => sliderPropTypes
|
|
32
|
-
});
|
|
33
|
-
var React = __toESM(require("react"));
|
|
34
|
-
var import_react_desc = __toESM(require("react-desc"));
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactDesc = require('react-desc');
|
|
6
|
+
|
|
35
7
|
const defaultProps = {
|
|
36
8
|
containerProps: {},
|
|
37
9
|
disabled: false,
|
|
38
|
-
label:
|
|
10
|
+
label: '',
|
|
39
11
|
labelWithValue: false,
|
|
40
12
|
minValue: 0,
|
|
41
13
|
maxValue: 100,
|
|
42
14
|
step: 5,
|
|
43
|
-
onChange: () => {
|
|
44
|
-
},
|
|
15
|
+
onChange: () => {},
|
|
45
16
|
withTickMarks: false,
|
|
46
17
|
withTickMarksValues: false,
|
|
47
18
|
withTwoHandles: false,
|
|
@@ -49,19 +20,45 @@ const defaultProps = {
|
|
|
49
20
|
zIndex: 0
|
|
50
21
|
};
|
|
51
22
|
const sliderPropTypes = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
23
|
+
/** props to inject to slider wrapper */
|
|
24
|
+
containerProps: reactDesc.PropTypes.shape({}).description('props to inject to slider wrapper'),
|
|
25
|
+
|
|
26
|
+
/** disable slider */
|
|
27
|
+
disabled: reactDesc.PropTypes.bool.description('disable slider'),
|
|
28
|
+
|
|
29
|
+
/** label for slider */
|
|
30
|
+
label: reactDesc.PropTypes.string.description('label for slider'),
|
|
31
|
+
|
|
32
|
+
/** if the label comes with value attached for slider or not */
|
|
33
|
+
labelWithValue: reactDesc.PropTypes.bool.description('if the label comes with value attached for slider or not'),
|
|
34
|
+
|
|
35
|
+
/** min value for slider */
|
|
36
|
+
minValue: reactDesc.PropTypes.number.description('min value for slider'),
|
|
37
|
+
|
|
38
|
+
/** max value for slider */
|
|
39
|
+
maxValue: reactDesc.PropTypes.number.description('max value for slider'),
|
|
40
|
+
|
|
41
|
+
/** steps of values from min to max */
|
|
42
|
+
step: reactDesc.PropTypes.number.description('steps of values from min to max'),
|
|
43
|
+
|
|
44
|
+
/** change handler */
|
|
45
|
+
onChange: reactDesc.PropTypes.func.description('change handler'),
|
|
46
|
+
|
|
47
|
+
/** add tick marks between steps */
|
|
48
|
+
withTickMarks: reactDesc.PropTypes.bool.description('add tick marks between steps'),
|
|
49
|
+
|
|
50
|
+
/** add step value to tickmark */
|
|
51
|
+
withTickMarksValues: reactDesc.PropTypes.bool.description('add step value to tickmark'),
|
|
52
|
+
|
|
53
|
+
/** add two handles */
|
|
54
|
+
withTwoHandles: reactDesc.PropTypes.bool.description('add two handles'),
|
|
55
|
+
|
|
56
|
+
/** change manually tickmark values */
|
|
57
|
+
customTickMarksValues: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number])).description('change manually tickmark values'),
|
|
58
|
+
|
|
59
|
+
/** z index for thumb */
|
|
60
|
+
zIndex: reactDesc.PropTypes.number.description('z index for thumb')
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
|
|
63
|
+
exports.defaultProps = defaultProps;
|
|
64
|
+
exports.sliderPropTypes = sliderPropTypes;
|
package/esm/DSSlider.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import 'react';
|
|
8
|
+
import { describe } from 'react-desc';
|
|
9
|
+
import SliderImp from './components/SliderImp.js';
|
|
10
|
+
import { sliderPropTypes, defaultProps } from './prop-types.js';
|
|
11
|
+
import { jsx } from 'react/jsx-runtime';
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
const DSSlider = props => /*#__PURE__*/jsx(SliderImp, _objectSpread({}, props));
|
|
18
|
+
|
|
9
19
|
DSSlider.defaultProps = defaultProps;
|
|
10
|
-
DSSlider.propTypes = sliderPropTypes;
|
|
11
20
|
const DSSliderWithSchema = describe(DSSlider);
|
|
12
21
|
DSSliderWithSchema.propTypes = sliderPropTypes;
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
DSSlider,
|
|
16
|
-
DSSliderWithSchema,
|
|
17
|
-
DSSlider_default as default
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=DSSlider.js.map
|
|
22
|
+
|
|
23
|
+
export { DSSlider, DSSliderWithSchema, DSSlider as default };
|
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
} from
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { SliderContext } from "./context";
|
|
20
|
-
const getSubArrayFromRange = (arr, [minVal, maxVal], isCustomTickMarksValues = false) => {
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
+
import { useRef, useState, useMemo, useEffect } from 'react';
|
|
4
|
+
import { v4 } from 'uuid';
|
|
5
|
+
import { Range } from 'react-range';
|
|
6
|
+
import { usePrevious } from '@elliemae/ds-utilities';
|
|
7
|
+
import DSTruncatedTooltipText, { TooltipTextProvider } from '@elliemae/ds-truncated-tooltip-text';
|
|
8
|
+
import { Grid } from '@elliemae/ds-grid';
|
|
9
|
+
import Track from './Track.js';
|
|
10
|
+
import Thumb from './Thumb.js';
|
|
11
|
+
import { LabelWrapper, StyledRangeWrapper, LabelText, ValueText } from './styled.js';
|
|
12
|
+
import { conformedLabel } from './utils.js';
|
|
13
|
+
import { SliderContext } from './context.js';
|
|
14
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
const getSubArrayFromRange = function (arr, _ref) {
|
|
17
|
+
let [minVal, maxVal] = _ref;
|
|
18
|
+
let isCustomTickMarksValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
21
19
|
const trueMinVal = isCustomTickMarksValues ? arr[minVal] : minVal;
|
|
22
|
-
const minIndex = arr.findIndex(
|
|
23
|
-
|
|
20
|
+
const minIndex = arr.findIndex(el => el === trueMinVal);
|
|
21
|
+
|
|
22
|
+
if (maxVal !== undefined) {
|
|
23
|
+
// if two handlers, return the found slice
|
|
24
24
|
const trueMaxVal = isCustomTickMarksValues ? arr[maxVal] : maxVal;
|
|
25
|
-
const maxIndex = arr.findIndex(
|
|
26
|
-
if (minIndex >= 0 && maxIndex > minIndex)
|
|
27
|
-
return arr.slice(minIndex, maxIndex + 1);
|
|
25
|
+
const maxIndex = arr.findIndex(el => el === trueMaxVal);
|
|
26
|
+
if (minIndex >= 0 && maxIndex > minIndex) return arr.slice(minIndex, maxIndex + 1);
|
|
28
27
|
return [];
|
|
29
|
-
}
|
|
28
|
+
} // if only one handler, return the value in an array
|
|
29
|
+
|
|
30
|
+
|
|
30
31
|
return [trueMinVal];
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
const SliderImp = props => {
|
|
35
|
+
var _ref$current3;
|
|
36
|
+
|
|
33
37
|
const {
|
|
34
38
|
containerProps,
|
|
35
39
|
disabled,
|
|
@@ -47,46 +51,54 @@ const SliderImp = (props) => {
|
|
|
47
51
|
} = props;
|
|
48
52
|
const ref = useRef();
|
|
49
53
|
const [width, setWidth] = useState(0);
|
|
50
|
-
const sliderUUID = useMemo(() =>
|
|
54
|
+
const sliderUUID = useMemo(() => v4(), []);
|
|
51
55
|
const parsedMinValue = useMemo(() => {
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
// ensure this works correctly with customTickMarksValues array
|
|
57
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return 0;
|
|
54
58
|
return minValue;
|
|
55
|
-
}, [customTickMarksValues
|
|
59
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, minValue]);
|
|
56
60
|
const parsedMaxValue = useMemo(() => {
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
// ensure this works correctly with customTickMarksValues array
|
|
62
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return (customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length) - 1;
|
|
59
63
|
return maxValue;
|
|
60
|
-
}, [customTickMarksValues
|
|
64
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, maxValue]);
|
|
61
65
|
const parsedStep = useMemo(() => {
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
// ensure this works correctly with customTickMarksValues array
|
|
67
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return 1;
|
|
64
68
|
return step;
|
|
65
|
-
}, [customTickMarksValues
|
|
69
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, step]);
|
|
66
70
|
const parsedValuesArray = useMemo(() => {
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
// ensure this works correctly with customTickMarksValues array
|
|
72
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return customTickMarksValues;
|
|
69
73
|
const newLength = Math.ceil(maxValue / step);
|
|
70
74
|
const valuesArray = [];
|
|
75
|
+
|
|
71
76
|
for (let i = 0; i <= newLength; i += 1) {
|
|
72
77
|
valuesArray.push(step * i);
|
|
73
78
|
}
|
|
79
|
+
|
|
74
80
|
return valuesArray;
|
|
75
|
-
}, [customTickMarksValues
|
|
76
|
-
const [rangeValues, setRangeValues] = useState(withTwoHandles ? [parsedMinValue, parsedMaxValue] : [parsedMinValue]);
|
|
81
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, minValue, maxValue, step]);
|
|
82
|
+
const [rangeValues, setRangeValues] = useState(withTwoHandles ? [parsedMinValue, parsedMaxValue] : [parsedMinValue]); // track the full slice of values selected instead of only the limits
|
|
83
|
+
// this is important to handle the selected range labels colors
|
|
84
|
+
|
|
77
85
|
const [fullSelectedValues, setFullSelectedValues] = useState([]);
|
|
78
86
|
useEffect(() => {
|
|
79
|
-
const selectedRangeValues = getSubArrayFromRange(parsedValuesArray, rangeValues, !!customTickMarksValues
|
|
87
|
+
const selectedRangeValues = getSubArrayFromRange(parsedValuesArray, rangeValues, !!(customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length));
|
|
80
88
|
setFullSelectedValues(selectedRangeValues);
|
|
81
|
-
}, [parsedValuesArray, rangeValues, customTickMarksValues
|
|
89
|
+
}, [parsedValuesArray, rangeValues, customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length]);
|
|
82
90
|
const prevWithTwoHandles = usePrevious(withTwoHandles);
|
|
91
|
+
|
|
83
92
|
const resizeHandler = () => {
|
|
93
|
+
var _ref$current;
|
|
94
|
+
|
|
84
95
|
setWidth(0);
|
|
85
|
-
setWidth(ref.current
|
|
96
|
+
setWidth((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth);
|
|
86
97
|
};
|
|
98
|
+
|
|
87
99
|
useEffect(() => {
|
|
88
|
-
window.addEventListener(
|
|
89
|
-
return () => window.removeEventListener(
|
|
100
|
+
window.addEventListener('resize', resizeHandler);
|
|
101
|
+
return () => window.removeEventListener('resize', resizeHandler);
|
|
90
102
|
});
|
|
91
103
|
useEffect(() => {
|
|
92
104
|
if (!prevWithTwoHandles && withTwoHandles) {
|
|
@@ -96,78 +108,85 @@ const SliderImp = (props) => {
|
|
|
96
108
|
}
|
|
97
109
|
}, [withTwoHandles]);
|
|
98
110
|
useEffect(() => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
111
|
+
var _ref$current2;
|
|
112
|
+
|
|
113
|
+
setWidth((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.clientWidth);
|
|
114
|
+
}, [(_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.clientWidth]);
|
|
115
|
+
const [finalLabelText, finalValueText] = useMemo(() => conformedLabel(rangeValues, label, labelWithValue, withTwoHandles, customTickMarksValues, parsedStep), [rangeValues, label, labelWithValue, withTwoHandles, customTickMarksValues, parsedStep]);
|
|
116
|
+
|
|
117
|
+
const SliderLabel = /*#__PURE__*/jsxs(Fragment, {
|
|
118
|
+
children: [/*#__PURE__*/_jsx(LabelText, {}, void 0, finalLabelText), finalLabelText && ' ', /*#__PURE__*/_jsx(ValueText, {
|
|
119
|
+
disabled: disabled
|
|
120
|
+
}, void 0, finalValueText)]
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return /*#__PURE__*/_jsx(TooltipTextProvider, {}, void 0, /*#__PURE__*/jsx("div", {
|
|
124
|
+
ref: ref,
|
|
125
|
+
children: /*#__PURE__*/_jsx(Grid, {
|
|
126
|
+
width: "100%",
|
|
127
|
+
style: {
|
|
128
|
+
maxWidth: '100%'
|
|
129
|
+
},
|
|
130
|
+
containerProps: containerProps,
|
|
131
|
+
"data-testid": "slider",
|
|
132
|
+
rows: ['auto', 'auto']
|
|
133
|
+
}, void 0, /*#__PURE__*/_jsx(SliderContext.Provider, {
|
|
134
|
+
value: {
|
|
135
|
+
disabled,
|
|
136
|
+
sliderUUID,
|
|
137
|
+
label,
|
|
138
|
+
labelWithValue,
|
|
139
|
+
minValue: parsedMinValue,
|
|
140
|
+
maxValue: parsedMaxValue,
|
|
141
|
+
step: parsedStep,
|
|
142
|
+
parsedValuesArray,
|
|
143
|
+
withTickMarks,
|
|
144
|
+
withTickMarksValues,
|
|
145
|
+
withTwoHandles,
|
|
146
|
+
customTickMarksValues,
|
|
147
|
+
rangeValues,
|
|
148
|
+
fullSelectedValues,
|
|
149
|
+
zIndex
|
|
150
|
+
}
|
|
151
|
+
}, void 0, finalLabelText && /*#__PURE__*/_jsx(LabelWrapper, {
|
|
152
|
+
width: width
|
|
153
|
+
}, void 0, /*#__PURE__*/_jsx(DSTruncatedTooltipText, {
|
|
154
|
+
value: SliderLabel
|
|
155
|
+
})), /*#__PURE__*/_jsx(StyledRangeWrapper, {}, void 0, /*#__PURE__*/_jsx(Range, {
|
|
128
156
|
step: parsedStep,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
allowOverlap: false
|
|
167
|
-
}))))));
|
|
168
|
-
};
|
|
169
|
-
var SliderImp_default = SliderImp;
|
|
170
|
-
export {
|
|
171
|
-
SliderImp_default as default
|
|
172
|
-
};
|
|
173
|
-
//# sourceMappingURL=SliderImp.js.map
|
|
157
|
+
min: parsedMinValue,
|
|
158
|
+
max: parsedMaxValue,
|
|
159
|
+
values: rangeValues,
|
|
160
|
+
disabled: disabled,
|
|
161
|
+
onChange: values => {
|
|
162
|
+
if (withTwoHandles && values[0] === values[1]) return;
|
|
163
|
+
setRangeValues(values);
|
|
164
|
+
onChange(values);
|
|
165
|
+
},
|
|
166
|
+
renderTrack: _ref2 => {
|
|
167
|
+
let {
|
|
168
|
+
props: trackProps,
|
|
169
|
+
children
|
|
170
|
+
} = _ref2;
|
|
171
|
+
return /*#__PURE__*/_jsx(Track, {
|
|
172
|
+
props: trackProps
|
|
173
|
+
}, void 0, children);
|
|
174
|
+
},
|
|
175
|
+
renderThumb: renderArgs => {
|
|
176
|
+
const {
|
|
177
|
+
index,
|
|
178
|
+
props: thumbProps,
|
|
179
|
+
isDragged
|
|
180
|
+
} = renderArgs;
|
|
181
|
+
return /*#__PURE__*/_jsx(Thumb, {
|
|
182
|
+
props: thumbProps,
|
|
183
|
+
isDragged: isDragged,
|
|
184
|
+
index: index
|
|
185
|
+
}, "".concat(sliderUUID, "-").concat(thumbProps.key));
|
|
186
|
+
},
|
|
187
|
+
allowOverlap: false
|
|
188
|
+
}))))
|
|
189
|
+
}));
|
|
190
|
+
}; // SliderImp.propTypes = sliderPropTypes;
|
|
191
|
+
|
|
192
|
+
export { SliderImp as default };
|