@elliemae/ds-slider 2.3.0-alpha.8 → 2.3.0-next.2
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 -0
- package/cjs/components/SliderImp.js +199 -0
- package/cjs/components/Thumb.js +71 -0
- package/cjs/components/TickMarks.js +46 -0
- package/cjs/components/TickMarksValues.js +43 -0
- package/cjs/components/Track.js +67 -0
- package/cjs/components/context.js +13 -0
- package/cjs/components/styled.js +61 -0
- package/cjs/components/utils.js +49 -0
- package/cjs/index.js +11 -0
- package/cjs/prop-types.js +64 -0
- package/esm/DSSlider.js +23 -0
- package/esm/components/SliderImp.js +192 -0
- package/esm/components/Thumb.js +64 -0
- package/esm/components/TickMarks.js +39 -0
- package/esm/components/TickMarksValues.js +36 -0
- package/esm/components/Track.js +59 -0
- package/esm/components/context.js +5 -0
- package/esm/components/styled.js +47 -0
- package/esm/components/utils.js +44 -0
- package/esm/index.js +1 -0
- package/esm/prop-types.js +59 -0
- package/package.json +41 -43
- package/types/DSSlider.d.ts +107 -0
- package/types/components/SliderImp.d.ts +3 -0
- package/types/components/Thumb.d.ts +14 -0
- package/types/components/TickMarks.d.ts +3 -0
- package/types/components/TickMarksValues.d.ts +3 -0
- package/types/components/Track.d.ts +6 -0
- package/types/components/context.d.ts +2 -0
- package/types/components/styled.d.ts +8 -0
- package/types/components/utils.d.ts +2 -0
- package/types/index.d.ts +2 -0
- package/types/prop-types.d.ts +109 -0
- package/dist/cjs/DSSlider.js +0 -48
- package/dist/cjs/DSSlider.js.map +0 -7
- package/dist/cjs/components/SliderImp.js +0 -195
- package/dist/cjs/components/SliderImp.js.map +0 -7
- package/dist/cjs/components/Thumb.js +0 -72
- package/dist/cjs/components/Thumb.js.map +0 -7
- package/dist/cjs/components/TickMarks.js +0 -87
- package/dist/cjs/components/TickMarks.js.map +0 -7
- package/dist/cjs/components/TickMarksValues.js +0 -64
- package/dist/cjs/components/TickMarksValues.js.map +0 -7
- package/dist/cjs/components/Track.js +0 -78
- package/dist/cjs/components/Track.js.map +0 -7
- package/dist/cjs/components/context.js +0 -36
- package/dist/cjs/components/context.js.map +0 -7
- package/dist/cjs/components/styled.js +0 -96
- package/dist/cjs/components/styled.js.map +0 -7
- package/dist/cjs/components/utils.js +0 -59
- package/dist/cjs/components/utils.js.map +0 -7
- package/dist/cjs/index.js +0 -36
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/prop-types.js +0 -67
- package/dist/cjs/prop-types.js.map +0 -7
- package/dist/esm/DSSlider.js +0 -19
- package/dist/esm/DSSlider.js.map +0 -7
- package/dist/esm/components/SliderImp.js +0 -173
- package/dist/esm/components/SliderImp.js.map +0 -7
- package/dist/esm/components/Thumb.js +0 -43
- package/dist/esm/components/Thumb.js.map +0 -7
- package/dist/esm/components/TickMarks.js +0 -58
- package/dist/esm/components/TickMarks.js.map +0 -7
- package/dist/esm/components/TickMarksValues.js +0 -35
- package/dist/esm/components/TickMarksValues.js.map +0 -7
- package/dist/esm/components/Track.js +0 -49
- package/dist/esm/components/Track.js.map +0 -7
- package/dist/esm/components/context.js +0 -7
- package/dist/esm/components/context.js.map +0 -7
- package/dist/esm/components/styled.js +0 -67
- package/dist/esm/components/styled.js.map +0 -7
- package/dist/esm/components/utils.js +0 -30
- package/dist/esm/components/utils.js.map +0 -7
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/prop-types.js +0 -38
- package/dist/esm/prop-types.js.map +0 -7
package/esm/DSSlider.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
19
|
+
DSSlider.defaultProps = defaultProps;
|
|
20
|
+
const DSSliderWithSchema = describe(DSSlider);
|
|
21
|
+
DSSliderWithSchema.propTypes = sliderPropTypes;
|
|
22
|
+
|
|
23
|
+
export { DSSlider, DSSliderWithSchema, DSSlider as default };
|
|
@@ -0,0 +1,192 @@
|
|
|
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;
|
|
19
|
+
const trueMinVal = isCustomTickMarksValues ? arr[minVal] : minVal;
|
|
20
|
+
const minIndex = arr.findIndex(el => el === trueMinVal);
|
|
21
|
+
|
|
22
|
+
if (maxVal !== undefined) {
|
|
23
|
+
// if two handlers, return the found slice
|
|
24
|
+
const trueMaxVal = isCustomTickMarksValues ? arr[maxVal] : maxVal;
|
|
25
|
+
const maxIndex = arr.findIndex(el => el === trueMaxVal);
|
|
26
|
+
if (minIndex >= 0 && maxIndex > minIndex) return arr.slice(minIndex, maxIndex + 1);
|
|
27
|
+
return [];
|
|
28
|
+
} // if only one handler, return the value in an array
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return [trueMinVal];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const SliderImp = props => {
|
|
35
|
+
var _ref$current3;
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
containerProps,
|
|
39
|
+
disabled,
|
|
40
|
+
label,
|
|
41
|
+
labelWithValue,
|
|
42
|
+
minValue,
|
|
43
|
+
maxValue,
|
|
44
|
+
step,
|
|
45
|
+
onChange,
|
|
46
|
+
withTickMarks,
|
|
47
|
+
withTickMarksValues,
|
|
48
|
+
withTwoHandles,
|
|
49
|
+
customTickMarksValues,
|
|
50
|
+
zIndex
|
|
51
|
+
} = props;
|
|
52
|
+
const ref = useRef();
|
|
53
|
+
const [width, setWidth] = useState(0);
|
|
54
|
+
const sliderUUID = useMemo(() => v4(), []);
|
|
55
|
+
const parsedMinValue = useMemo(() => {
|
|
56
|
+
// ensure this works correctly with customTickMarksValues array
|
|
57
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return 0;
|
|
58
|
+
return minValue;
|
|
59
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, minValue]);
|
|
60
|
+
const parsedMaxValue = useMemo(() => {
|
|
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;
|
|
63
|
+
return maxValue;
|
|
64
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, maxValue]);
|
|
65
|
+
const parsedStep = useMemo(() => {
|
|
66
|
+
// ensure this works correctly with customTickMarksValues array
|
|
67
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return 1;
|
|
68
|
+
return step;
|
|
69
|
+
}, [customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length, step]);
|
|
70
|
+
const parsedValuesArray = useMemo(() => {
|
|
71
|
+
// ensure this works correctly with customTickMarksValues array
|
|
72
|
+
if (customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length) return customTickMarksValues;
|
|
73
|
+
const newLength = Math.ceil(maxValue / step);
|
|
74
|
+
const valuesArray = [];
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i <= newLength; i += 1) {
|
|
77
|
+
valuesArray.push(step * i);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return valuesArray;
|
|
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
|
+
|
|
85
|
+
const [fullSelectedValues, setFullSelectedValues] = useState([]);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const selectedRangeValues = getSubArrayFromRange(parsedValuesArray, rangeValues, !!(customTickMarksValues !== null && customTickMarksValues !== void 0 && customTickMarksValues.length));
|
|
88
|
+
setFullSelectedValues(selectedRangeValues);
|
|
89
|
+
}, [parsedValuesArray, rangeValues, customTickMarksValues === null || customTickMarksValues === void 0 ? void 0 : customTickMarksValues.length]);
|
|
90
|
+
const prevWithTwoHandles = usePrevious(withTwoHandles);
|
|
91
|
+
|
|
92
|
+
const resizeHandler = () => {
|
|
93
|
+
var _ref$current;
|
|
94
|
+
|
|
95
|
+
setWidth(0);
|
|
96
|
+
setWidth((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
window.addEventListener('resize', resizeHandler);
|
|
101
|
+
return () => window.removeEventListener('resize', resizeHandler);
|
|
102
|
+
});
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!prevWithTwoHandles && withTwoHandles) {
|
|
105
|
+
setRangeValues([parsedMinValue, parsedMaxValue]);
|
|
106
|
+
} else if (prevWithTwoHandles && !withTwoHandles) {
|
|
107
|
+
setRangeValues([parsedMinValue]);
|
|
108
|
+
}
|
|
109
|
+
}, [withTwoHandles]);
|
|
110
|
+
useEffect(() => {
|
|
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, {
|
|
156
|
+
step: parsedStep,
|
|
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 };
|
|
@@ -0,0 +1,64 @@
|
|
|
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 _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
9
|
+
import { useState, useContext } from 'react';
|
|
10
|
+
import { TooltipText } from '@elliemae/ds-tooltip';
|
|
11
|
+
import { SliderContext } from './context.js';
|
|
12
|
+
import { conformedThumbLabel } from './utils.js';
|
|
13
|
+
import { ThumbStyled, TooltipContainerStyled, TooltipArrow } from './styled.js';
|
|
14
|
+
import { jsx } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
var _TooltipArrow;
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
const Thumb = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
index,
|
|
25
|
+
props,
|
|
26
|
+
isDragged
|
|
27
|
+
} = _ref;
|
|
28
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
29
|
+
const {
|
|
30
|
+
disabled,
|
|
31
|
+
rangeValues,
|
|
32
|
+
zIndex,
|
|
33
|
+
customTickMarksValues,
|
|
34
|
+
step,
|
|
35
|
+
minValue
|
|
36
|
+
} = useContext(SliderContext);
|
|
37
|
+
|
|
38
|
+
const cleanedProps = _objectSpread({}, props); // delete cleanedProps.key;
|
|
39
|
+
// delete cleanedProps.draggable;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
/*#__PURE__*/
|
|
44
|
+
// ...props is needed because it's received from the library
|
|
45
|
+
// ...props.style has it own style from the library but has a bug with the zIndex for two thumbs, so that's why it has to be overwrite
|
|
46
|
+
jsx(ThumbStyled, _objectSpread(_objectSpread({}, cleanedProps), {}, {
|
|
47
|
+
"data-testid": "slider-thumb",
|
|
48
|
+
disabled: disabled // eslint-disable-next-line react/prop-types
|
|
49
|
+
,
|
|
50
|
+
style: _objectSpread(_objectSpread({}, cleanedProps.style), {}, {
|
|
51
|
+
zIndex
|
|
52
|
+
}),
|
|
53
|
+
index: index,
|
|
54
|
+
onMouseEnter: () => setIsHovered(true),
|
|
55
|
+
onMouseLeave: () => setIsHovered(false),
|
|
56
|
+
children: /*#__PURE__*/_jsx(TooltipContainerStyled, {
|
|
57
|
+
isDragged: isDragged,
|
|
58
|
+
isHovered: isHovered
|
|
59
|
+
}, void 0, /*#__PURE__*/_jsx(TooltipText, {}, void 0, conformedThumbLabel(rangeValues, customTickMarksValues, index, step, minValue)), _TooltipArrow || (_TooltipArrow = /*#__PURE__*/_jsx(TooltipArrow, {})))
|
|
60
|
+
}))
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { Thumb as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { __UNSAFE_SPACE_TO_DIMSUM } from '@elliemae/ds-system';
|
|
5
|
+
import { SliderContext } from './context.js';
|
|
6
|
+
|
|
7
|
+
const TickMarks = () => {
|
|
8
|
+
const {
|
|
9
|
+
minValue,
|
|
10
|
+
maxValue,
|
|
11
|
+
rangeValues,
|
|
12
|
+
step,
|
|
13
|
+
withTwoHandles,
|
|
14
|
+
zIndex
|
|
15
|
+
} = useContext(SliderContext);
|
|
16
|
+
const dots = [];
|
|
17
|
+
|
|
18
|
+
for (let index = minValue || 0; index <= maxValue; index += step) {
|
|
19
|
+
const isActive = withTwoHandles ? rangeValues[0] <= index && index < rangeValues[1] : rangeValues[0] > index;
|
|
20
|
+
dots.push( /*#__PURE__*/_jsx(Dot, {
|
|
21
|
+
"data-testid": "slider-dot",
|
|
22
|
+
isActive: isActive
|
|
23
|
+
}, index));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return /*#__PURE__*/_jsx(DotsContainer, {
|
|
27
|
+
"data-testid": "slider-tick-marks",
|
|
28
|
+
zIndex: zIndex
|
|
29
|
+
}, void 0, dots);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const Dot = /*#__PURE__*/styled.div.withConfig({
|
|
33
|
+
componentId: "sc-15z2sh4-0"
|
|
34
|
+
})(["&:after{content:'';background:", ";border-radius:", ";display:block;position:relative;width:2px;height:2px;}"], props => props.isActive ? props.theme.colors.brand[300] : props.theme.colors.neutral[400], props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs));
|
|
35
|
+
const DotsContainer = /*#__PURE__*/styled.div.withConfig({
|
|
36
|
+
componentId: "sc-15z2sh4-1"
|
|
37
|
+
})(["padding:0 calc(", " * 0.5);align-items:center;display:flex;justify-content:space-between;pointer-events:none;position:absolute;top:0;left:0;right:0;bottom:0;z-index:", ";"], props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => props.zIndex - 1);
|
|
38
|
+
|
|
39
|
+
export { TickMarks as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
4
|
+
import { useContext, useMemo } from 'react';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
import { __UNSAFE_SPACE_TO_DIMSUM } from '@elliemae/ds-system';
|
|
7
|
+
import { SliderContext } from './context.js';
|
|
8
|
+
|
|
9
|
+
const TickMarks = () => {
|
|
10
|
+
var _TickMarksContainer;
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
parsedValuesArray,
|
|
14
|
+
fullSelectedValues,
|
|
15
|
+
sliderUUID
|
|
16
|
+
} = useContext(SliderContext);
|
|
17
|
+
const TickMarksLabels = useMemo(() => parsedValuesArray.map(value => {
|
|
18
|
+
const isSelected = fullSelectedValues.findIndex(selectedVal => selectedVal === value) >= 0;
|
|
19
|
+
return /*#__PURE__*/_jsx(TickMarkValue, {
|
|
20
|
+
isSelected: isSelected
|
|
21
|
+
}, "".concat(sliderUUID, "-").concat(value), value);
|
|
22
|
+
}), [parsedValuesArray, sliderUUID, fullSelectedValues]);
|
|
23
|
+
const PureTickMArksValues = useMemo(() => _TickMarksContainer || (_TickMarksContainer = /*#__PURE__*/_jsx(TickMarksContainer, {
|
|
24
|
+
"data-testid": "slider-tick-marks-values"
|
|
25
|
+
}, void 0, TickMarksLabels)), [TickMarksLabels]);
|
|
26
|
+
return PureTickMArksValues;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const TickMarkValue = /*#__PURE__*/styled.div.withConfig({
|
|
30
|
+
componentId: "sc-lq3yel-0"
|
|
31
|
+
})(["margin:", " 0;overflow:visible;transform:translateX(-100%);width:", ";color:", ";"], props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.s), props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => props.isSelected ? props.theme.colors.neutral[800] : props.theme.colors.neutral[500]);
|
|
32
|
+
const TickMarksContainer = /*#__PURE__*/styled.div.withConfig({
|
|
33
|
+
componentId: "sc-lq3yel-1"
|
|
34
|
+
})(["display:flex;justify-content:space-between;"]);
|
|
35
|
+
|
|
36
|
+
export { TickMarks as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
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 _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
8
|
+
import { useContext } from 'react';
|
|
9
|
+
import { getTrackBackground } from 'react-range';
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
import { __UNSAFE_SPACE_TO_DIMSUM } from '@elliemae/ds-system';
|
|
12
|
+
import TickMarks$1 from './TickMarks.js';
|
|
13
|
+
import TickMarks from './TickMarksValues.js';
|
|
14
|
+
import { SliderContext } from './context.js';
|
|
15
|
+
import { jsxs, Fragment } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
var _TickMarks, _TickMarksValues;
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
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; }
|
|
22
|
+
|
|
23
|
+
const Track = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
children,
|
|
26
|
+
props
|
|
27
|
+
} = _ref;
|
|
28
|
+
const {
|
|
29
|
+
disabled,
|
|
30
|
+
minValue,
|
|
31
|
+
maxValue,
|
|
32
|
+
rangeValues,
|
|
33
|
+
withTickMarks,
|
|
34
|
+
withTickMarksValues,
|
|
35
|
+
withTwoHandles
|
|
36
|
+
} = useContext(SliderContext);
|
|
37
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
38
|
+
children: [/*#__PURE__*/jsxs(TrackStyled, _objectSpread(_objectSpread({}, props), {}, {
|
|
39
|
+
// This is needed because it's received from the library
|
|
40
|
+
disabled: disabled,
|
|
41
|
+
minValue: minValue,
|
|
42
|
+
maxValue: maxValue,
|
|
43
|
+
rangeValues: rangeValues,
|
|
44
|
+
withTwoHandles: withTwoHandles,
|
|
45
|
+
children: [children, withTickMarks && !disabled && (_TickMarks || (_TickMarks = /*#__PURE__*/_jsx(TickMarks$1, {})))]
|
|
46
|
+
})), withTickMarksValues && (_TickMarksValues || (_TickMarksValues = /*#__PURE__*/_jsx(TickMarks, {})))]
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const TrackStyled = /*#__PURE__*/styled.div.withConfig({
|
|
51
|
+
componentId: "sc-13fbuj5-0"
|
|
52
|
+
})(["position:relative;height:", ";width:100%;min-width:", ";border-radius:", ";background:", ";"], props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxl), props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => props.disabled ? props.theme.colors.neutral[100] : getTrackBackground({
|
|
53
|
+
values: props.rangeValues,
|
|
54
|
+
colors: props.withTwoHandles ? [props.theme.colors.neutral[100], props.theme.colors.brand[600], props.theme.colors.neutral[100]] : [props.theme.colors.brand[600], props.theme.colors.neutral[100]],
|
|
55
|
+
min: props.minValue,
|
|
56
|
+
max: props.maxValue
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
export { Track as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { __UNSAFE_SPACE_TO_DIMSUM } from '@elliemae/ds-system';
|
|
3
|
+
import { TooltipContainer } from '@elliemae/ds-tooltip';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable indent */
|
|
6
|
+
const ThumbStyled = /*#__PURE__*/styled.div.withConfig({
|
|
7
|
+
componentId: "sc-24in0j-0"
|
|
8
|
+
})(["height:20px;width:20px;background-color:", ";border-radius:10px;border:1px solid ", ";:focus{border:1px solid ", ";outline:unset;}:hover{background-color:", ";}"], props => props.disabled ? props.theme.colors.neutral[100] : props.theme.colors.neutral['000'], props => props.disabled ? props.theme.colors.neutral[100] : props.theme.colors.neutral[400], props => props.theme.colors.brand[600], _ref => {
|
|
9
|
+
let {
|
|
10
|
+
disabled,
|
|
11
|
+
theme
|
|
12
|
+
} = _ref;
|
|
13
|
+
return disabled ? theme.colors.neutral[100] : theme.colors.brand[200];
|
|
14
|
+
});
|
|
15
|
+
const TooltipContainerStyled = /*#__PURE__*/styled(TooltipContainer).withConfig({
|
|
16
|
+
componentId: "sc-24in0j-1"
|
|
17
|
+
})(["position:relative;display:flex;align-items:center;flex-direction:column;top:-35px;width:max-content;left:50%;transform:translateX(-50%);visibility:", ";"], _ref2 => {
|
|
18
|
+
let {
|
|
19
|
+
isDragged,
|
|
20
|
+
isHovered
|
|
21
|
+
} = _ref2;
|
|
22
|
+
return isDragged || isHovered ? 'visible' : 'hidden';
|
|
23
|
+
}); // TODO: didn't work with DSTooltip, see how to improve
|
|
24
|
+
|
|
25
|
+
const TooltipArrow = /*#__PURE__*/styled.div.withConfig({
|
|
26
|
+
componentId: "sc-24in0j-2"
|
|
27
|
+
})(["position:absolute;width:0;height:0;top:20px;border-left:calc(", " * 2.5) solid transparent;border-right:calc(", " * 2.5) solid transparent;border-top:calc(", " * 2.5) solid ", ";"], props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => __UNSAFE_SPACE_TO_DIMSUM(props.theme.space.xxs), props => props.theme.colors.neutral[0]);
|
|
28
|
+
const LabelWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
29
|
+
componentId: "sc-24in0j-3"
|
|
30
|
+
})(["margin-bottom:", ";max-width:100%;width:", ";"], props => props.theme.space.xxs, props => "".concat(props.width || 0, "px"));
|
|
31
|
+
const LabelText = /*#__PURE__*/styled.span.withConfig({
|
|
32
|
+
componentId: "sc-24in0j-4"
|
|
33
|
+
})(["color:", ";"], props => props.theme.colors.neutral[600]);
|
|
34
|
+
const ValueText = /*#__PURE__*/styled.span.withConfig({
|
|
35
|
+
componentId: "sc-24in0j-5"
|
|
36
|
+
})(["color:", ";"], _ref3 => {
|
|
37
|
+
let {
|
|
38
|
+
disabled,
|
|
39
|
+
theme
|
|
40
|
+
} = _ref3;
|
|
41
|
+
return theme.colors.neutral[disabled ? 500 : 800];
|
|
42
|
+
});
|
|
43
|
+
const StyledRangeWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
44
|
+
componentId: "sc-24in0j-6"
|
|
45
|
+
})(["min-height:28px;margin:0 10px;"]);
|
|
46
|
+
|
|
47
|
+
export { LabelText, LabelWrapper, StyledRangeWrapper, ThumbStyled, TooltipArrow, TooltipContainerStyled, ValueText };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isEmpty } from '@elliemae/ds-utilities';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable max-params */
|
|
4
|
+
const conformedLabel = function (rangeValues) {
|
|
5
|
+
let label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
6
|
+
let labelWithValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
7
|
+
let withTwoHandles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
8
|
+
let customTickMarksValues = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
9
|
+
let step = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
|
10
|
+
let minValue = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
11
|
+
const msg = label.trim();
|
|
12
|
+
let value = '';
|
|
13
|
+
|
|
14
|
+
if (!isEmpty(customTickMarksValues) && labelWithValue && label) {
|
|
15
|
+
const firstValue = customTickMarksValues[(rangeValues[0] - minValue) / step];
|
|
16
|
+
const secondValue = customTickMarksValues[(rangeValues[1] - minValue) / step];
|
|
17
|
+
value = "".concat(firstValue || rangeValues[0].toFixed(1), " ").concat(withTwoHandles ? ", ".concat(secondValue || rangeValues[1].toFixed(1)) : '', " ");
|
|
18
|
+
} else if (labelWithValue && label) {
|
|
19
|
+
var _rangeValues$;
|
|
20
|
+
|
|
21
|
+
value = "".concat(rangeValues[0].toFixed(1), " ").concat(withTwoHandles ? ", ".concat((_rangeValues$ = rangeValues[1]) === null || _rangeValues$ === void 0 ? void 0 : _rangeValues$.toFixed(1)) : '', " ");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
value = value.trim();
|
|
25
|
+
return [msg, value];
|
|
26
|
+
};
|
|
27
|
+
const conformedThumbLabel = function (rangeValues) {
|
|
28
|
+
let customTickMarksValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
29
|
+
let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
30
|
+
let step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
31
|
+
let minValue = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
32
|
+
let msg = "Value: ";
|
|
33
|
+
|
|
34
|
+
if (!isEmpty(customTickMarksValues)) {
|
|
35
|
+
const foundValue = customTickMarksValues[(rangeValues[index] - minValue) / step];
|
|
36
|
+
msg += "".concat(foundValue || rangeValues[index].toFixed(1));
|
|
37
|
+
} else {
|
|
38
|
+
msg += "".concat(rangeValues[index].toFixed(1));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return msg;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { conformedLabel, conformedThumbLabel };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DSSlider, DSSliderWithSchema, DSSlider as default } from './DSSlider.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { PropTypes } from 'react-desc';
|
|
2
|
+
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
containerProps: {},
|
|
5
|
+
disabled: false,
|
|
6
|
+
label: '',
|
|
7
|
+
labelWithValue: false,
|
|
8
|
+
minValue: 0,
|
|
9
|
+
maxValue: 100,
|
|
10
|
+
step: 5,
|
|
11
|
+
onChange: () => {},
|
|
12
|
+
withTickMarks: false,
|
|
13
|
+
withTickMarksValues: false,
|
|
14
|
+
withTwoHandles: false,
|
|
15
|
+
customTickMarksValues: [],
|
|
16
|
+
zIndex: 0
|
|
17
|
+
};
|
|
18
|
+
const sliderPropTypes = {
|
|
19
|
+
/** props to inject to slider wrapper */
|
|
20
|
+
containerProps: PropTypes.shape({}).description('props to inject to slider wrapper'),
|
|
21
|
+
|
|
22
|
+
/** disable slider */
|
|
23
|
+
disabled: PropTypes.bool.description('disable slider'),
|
|
24
|
+
|
|
25
|
+
/** label for slider */
|
|
26
|
+
label: PropTypes.string.description('label for slider'),
|
|
27
|
+
|
|
28
|
+
/** if the label comes with value attached for slider or not */
|
|
29
|
+
labelWithValue: PropTypes.bool.description('if the label comes with value attached for slider or not'),
|
|
30
|
+
|
|
31
|
+
/** min value for slider */
|
|
32
|
+
minValue: PropTypes.number.description('min value for slider'),
|
|
33
|
+
|
|
34
|
+
/** max value for slider */
|
|
35
|
+
maxValue: PropTypes.number.description('max value for slider'),
|
|
36
|
+
|
|
37
|
+
/** steps of values from min to max */
|
|
38
|
+
step: PropTypes.number.description('steps of values from min to max'),
|
|
39
|
+
|
|
40
|
+
/** change handler */
|
|
41
|
+
onChange: PropTypes.func.description('change handler'),
|
|
42
|
+
|
|
43
|
+
/** add tick marks between steps */
|
|
44
|
+
withTickMarks: PropTypes.bool.description('add tick marks between steps'),
|
|
45
|
+
|
|
46
|
+
/** add step value to tickmark */
|
|
47
|
+
withTickMarksValues: PropTypes.bool.description('add step value to tickmark'),
|
|
48
|
+
|
|
49
|
+
/** add two handles */
|
|
50
|
+
withTwoHandles: PropTypes.bool.description('add two handles'),
|
|
51
|
+
|
|
52
|
+
/** change manually tickmark values */
|
|
53
|
+
customTickMarksValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])).description('change manually tickmark values'),
|
|
54
|
+
|
|
55
|
+
/** z index for thumb */
|
|
56
|
+
zIndex: PropTypes.number.description('z index for thumb')
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { defaultProps, sliderPropTypes };
|