@hitachivantara/uikit-react-core 3.66.2 → 3.67.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/dist/BaseInput/BaseInput.js +6 -1
- package/dist/BaseInput/BaseInput.js.map +1 -1
- package/dist/BaseInput/styles.js +3 -0
- package/dist/BaseInput/styles.js.map +1 -1
- package/dist/FilterGroup/Counter/Counter.js +9 -7
- package/dist/FilterGroup/Counter/Counter.js.map +1 -1
- package/dist/FilterGroup/FilterContent/FilterContent.js +1 -1
- package/dist/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/FilterGroup/FilterGroup.d.ts +4 -7
- package/dist/FilterGroup/RightPanel/RightPanel.js +2 -1
- package/dist/FilterGroup/RightPanel/RightPanel.js.map +1 -1
- package/dist/Forms/FormElement/index.d.ts +4 -0
- package/dist/Forms/FormElement/index.js +14 -0
- package/dist/Forms/FormElement/index.js.map +1 -1
- package/dist/Slider/Slider.d.ts +185 -0
- package/dist/Slider/Slider.js +803 -0
- package/dist/Slider/Slider.js.map +1 -0
- package/dist/Slider/SliderInput/SliderInput.js +194 -0
- package/dist/Slider/SliderInput/SliderInput.js.map +1 -0
- package/dist/Slider/SliderInput/index.d.ts +1 -0
- package/dist/Slider/SliderInput/index.js +16 -0
- package/dist/Slider/SliderInput/index.js.map +1 -0
- package/dist/Slider/SliderInput/styles.js +24 -0
- package/dist/Slider/SliderInput/styles.js.map +1 -0
- package/dist/Slider/index.d.ts +2 -0
- package/dist/Slider/index.js +16 -0
- package/dist/Slider/index.js.map +1 -0
- package/dist/Slider/styles.js +239 -0
- package/dist/Slider/styles.js.map +1 -0
- package/dist/Slider/utils.js +413 -0
- package/dist/Slider/utils.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/legacy/BaseInput/BaseInput.js +6 -1
- package/dist/legacy/BaseInput/BaseInput.js.map +1 -1
- package/dist/legacy/BaseInput/styles.js +3 -0
- package/dist/legacy/BaseInput/styles.js.map +1 -1
- package/dist/legacy/FilterGroup/Counter/Counter.js +8 -6
- package/dist/legacy/FilterGroup/Counter/Counter.js.map +1 -1
- package/dist/legacy/FilterGroup/FilterContent/FilterContent.js +1 -1
- package/dist/legacy/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/legacy/FilterGroup/FilterGroup.d.ts +4 -7
- package/dist/legacy/FilterGroup/RightPanel/RightPanel.js +2 -1
- package/dist/legacy/FilterGroup/RightPanel/RightPanel.js.map +1 -1
- package/dist/legacy/Forms/FormElement/index.d.ts +4 -0
- package/dist/legacy/Forms/FormElement/index.js +1 -0
- package/dist/legacy/Forms/FormElement/index.js.map +1 -1
- package/dist/legacy/Slider/Slider.d.ts +185 -0
- package/dist/legacy/Slider/Slider.js +752 -0
- package/dist/legacy/Slider/Slider.js.map +1 -0
- package/dist/legacy/Slider/SliderInput/SliderInput.js +151 -0
- package/dist/legacy/Slider/SliderInput/SliderInput.js.map +1 -0
- package/dist/legacy/Slider/SliderInput/index.d.ts +1 -0
- package/dist/legacy/Slider/SliderInput/index.js +2 -0
- package/dist/legacy/Slider/SliderInput/index.js.map +1 -0
- package/dist/legacy/Slider/SliderInput/styles.js +16 -0
- package/dist/legacy/Slider/SliderInput/styles.js.map +1 -0
- package/dist/legacy/Slider/index.d.ts +2 -0
- package/dist/legacy/Slider/index.js +2 -0
- package/dist/legacy/Slider/index.js.map +1 -0
- package/dist/legacy/Slider/styles.js +222 -0
- package/dist/legacy/Slider/styles.js.map +1 -0
- package/dist/legacy/Slider/utils.js +347 -0
- package/dist/legacy/Slider/utils.js.map +1 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +1 -0
- package/dist/legacy/index.js.map +1 -1
- package/dist/modern/BaseInput/BaseInput.js +6 -1
- package/dist/modern/BaseInput/BaseInput.js.map +1 -1
- package/dist/modern/BaseInput/styles.js +3 -0
- package/dist/modern/BaseInput/styles.js.map +1 -1
- package/dist/modern/FilterGroup/Counter/Counter.js +4 -4
- package/dist/modern/FilterGroup/Counter/Counter.js.map +1 -1
- package/dist/modern/FilterGroup/FilterContent/FilterContent.js +1 -1
- package/dist/modern/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/modern/FilterGroup/FilterGroup.d.ts +4 -7
- package/dist/modern/FilterGroup/RightPanel/RightPanel.js +1 -1
- package/dist/modern/FilterGroup/RightPanel/RightPanel.js.map +1 -1
- package/dist/modern/Forms/FormElement/index.d.ts +4 -0
- package/dist/modern/Forms/FormElement/index.js +1 -0
- package/dist/modern/Forms/FormElement/index.js.map +1 -1
- package/dist/modern/Slider/Slider.d.ts +185 -0
- package/dist/modern/Slider/Slider.js +689 -0
- package/dist/modern/Slider/Slider.js.map +1 -0
- package/dist/modern/Slider/SliderInput/SliderInput.js +129 -0
- package/dist/modern/Slider/SliderInput/SliderInput.js.map +1 -0
- package/dist/modern/Slider/SliderInput/index.d.ts +1 -0
- package/dist/modern/Slider/SliderInput/index.js +2 -0
- package/dist/modern/Slider/SliderInput/index.js.map +1 -0
- package/dist/modern/Slider/SliderInput/styles.js +16 -0
- package/dist/modern/Slider/SliderInput/styles.js.map +1 -0
- package/dist/modern/Slider/index.d.ts +2 -0
- package/dist/modern/Slider/index.js +2 -0
- package/dist/modern/Slider/index.js.map +1 -0
- package/dist/modern/Slider/styles.js +215 -0
- package/dist/modern/Slider/styles.js.map +1 -0
- package/dist/modern/Slider/utils.js +302 -0
- package/dist/modern/Slider/utils.js.map +1 -0
- package/dist/modern/index.d.ts +3 -0
- package/dist/modern/index.js +1 -0
- package/dist/modern/index.js.map +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
const _excluded = ["id", "className", "name", "label", "status", "statusMessage", "disabled", "required", "requiredMessage", "readOnly", "aria-errormessage", "classes", "hideInput", "markProperties", "markStep", "markDigits", "knobProperties", "values", "defaultValues", "inputProps", "theme", "maxPointValue", "minPointValue", "divisionQuantity", "formatMark", "noOverlap", "onChange", "onBlur", "onBeforeChange", "onAfterChange", "formatTooltip", "sliderProps", "knobProps"],
|
|
4
|
+
_excluded2 = ["className", "style"];
|
|
5
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
|
+
import "core-js/modules/es.array.includes.js";
|
|
7
|
+
import React, { useCallback, useEffect, useRef, useState, useMemo } from "react";
|
|
8
|
+
import clsx from "clsx";
|
|
9
|
+
import PropTypes from "prop-types";
|
|
10
|
+
import Slider from "rc-slider";
|
|
11
|
+
import Tooltip from "rc-tooltip";
|
|
12
|
+
import "rc-slider/assets/index.css";
|
|
13
|
+
import { withStyles } from "@material-ui/core";
|
|
14
|
+
import { HvFormElement, useControlled, useUniqueId, HvLabel, setId, HvWarningText } from "..";
|
|
15
|
+
import validationStates from "../Forms/FormElement/validationStates";
|
|
16
|
+
import { knobsPositionToScaledValue, calculateStepValue, createKnobStyles, createTrackStyles, createMark, knobsValuesToKnobsPositions, knobsPositionsToKnobsValues, scaledValueToKnobsPositionValue, generateDefaultKnobProperties, isSingleSlider, ensureValuesConsistency, convertStatusToArray, statusArrayToFormStatus } from "./utils";
|
|
17
|
+
import styleCreator from "./styles";
|
|
18
|
+
import SliderInput from "./SliderInput";
|
|
19
|
+
/**
|
|
20
|
+
* Sliders reflect a range of values along a bar, from which users may select a single value. They are ideal for adjusting settings such as volume, brightness, or applying image filters. Still in development
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const HvSlider = props => {
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
className,
|
|
27
|
+
name,
|
|
28
|
+
label,
|
|
29
|
+
status,
|
|
30
|
+
statusMessage,
|
|
31
|
+
disabled,
|
|
32
|
+
required = false,
|
|
33
|
+
requiredMessage = "The value is required",
|
|
34
|
+
readOnly = false,
|
|
35
|
+
"aria-errormessage": ariaErrorMessage,
|
|
36
|
+
classes,
|
|
37
|
+
hideInput = false,
|
|
38
|
+
markProperties = [],
|
|
39
|
+
markStep = 20,
|
|
40
|
+
markDigits = 0,
|
|
41
|
+
knobProperties: knobPropertiesProp,
|
|
42
|
+
values: valuesProp,
|
|
43
|
+
defaultValues = [undefined],
|
|
44
|
+
inputProps,
|
|
45
|
+
theme,
|
|
46
|
+
maxPointValue = 100,
|
|
47
|
+
minPointValue = 0,
|
|
48
|
+
divisionQuantity = 100,
|
|
49
|
+
formatMark,
|
|
50
|
+
noOverlap = true,
|
|
51
|
+
onChange,
|
|
52
|
+
onBlur,
|
|
53
|
+
onBeforeChange,
|
|
54
|
+
onAfterChange,
|
|
55
|
+
formatTooltip,
|
|
56
|
+
sliderProps,
|
|
57
|
+
knobProps
|
|
58
|
+
} = props,
|
|
59
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
60
|
+
|
|
61
|
+
const styles = styleCreator(theme);
|
|
62
|
+
const stepValue = useMemo(() => calculateStepValue(maxPointValue, minPointValue, divisionQuantity), [divisionQuantity, maxPointValue, minPointValue]);
|
|
63
|
+
const inverseStepValue = 1 / stepValue;
|
|
64
|
+
const isSingle = useMemo(() => isSingleSlider(valuesProp, defaultValues), [defaultValues, valuesProp]);
|
|
65
|
+
const defaultKnobsPositions = useMemo(() => knobsValuesToKnobsPositions(defaultValues, inverseStepValue, minPointValue, isSingle), [defaultValues, inverseStepValue, isSingle, minPointValue]);
|
|
66
|
+
const value = useMemo(() => (valuesProp === null || valuesProp === void 0 ? void 0 : valuesProp.length) > 0 ? knobsValuesToKnobsPositions(valuesProp, inverseStepValue, minPointValue, isSingle) : undefined, [inverseStepValue, isSingle, minPointValue, valuesProp]);
|
|
67
|
+
const [knobsPositions, setKnobsPositions] = useControlled(value, defaultKnobsPositions);
|
|
68
|
+
const [isDraggingTrack, setIsDraggingTrack] = useState(false); // signals that the user has manually edited the input value
|
|
69
|
+
|
|
70
|
+
const isDirty = useRef(false);
|
|
71
|
+
const elementId = useUniqueId(id, "hvSlider"); // miscellaneous state
|
|
72
|
+
|
|
73
|
+
const hasLabel = label != null; // validation related state
|
|
74
|
+
|
|
75
|
+
const {
|
|
76
|
+
arrayStatus,
|
|
77
|
+
arrayDefaultStatus
|
|
78
|
+
} = useMemo(() => convertStatusToArray(status, knobsPositions.length), [knobsPositions.length, status]);
|
|
79
|
+
const [validationStatus, setValidationState] = useControlled(arrayStatus, arrayDefaultStatus);
|
|
80
|
+
const [validationMessage, setValidationMessage] = useControlled(statusMessage, "");
|
|
81
|
+
const canShowError = ariaErrorMessage == null && (status !== undefined && statusMessage !== undefined || status === undefined && required);
|
|
82
|
+
const knobProperties = generateDefaultKnobProperties(knobPropertiesProp, knobsPositions.length, disabled, theme);
|
|
83
|
+
const trackStyles = createTrackStyles(knobProperties, styles);
|
|
84
|
+
const knobStyles = createKnobStyles(knobProperties, styles);
|
|
85
|
+
const marks = useMemo(() => createMark(markProperties, markStep, divisionQuantity, minPointValue, stepValue, markDigits, formatMark, disabled, styles), [disabled, divisionQuantity, formatMark, markDigits, markProperties, markStep, minPointValue, stepValue, styles]);
|
|
86
|
+
const rangesCount = knobProperties.length - 1;
|
|
87
|
+
const performValidation = useCallback(() => {
|
|
88
|
+
let invalid = false;
|
|
89
|
+
const newValidationState = knobsPositions.map(position => {
|
|
90
|
+
if (position == null || Number.isNaN(position)) {
|
|
91
|
+
invalid = true;
|
|
92
|
+
return validationStates.invalid;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return validationStates.valid;
|
|
96
|
+
});
|
|
97
|
+
setValidationState([...newValidationState]);
|
|
98
|
+
|
|
99
|
+
if (invalid) {
|
|
100
|
+
setValidationMessage(requiredMessage);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setValidationMessage("");
|
|
105
|
+
}, [knobsPositions, requiredMessage, setValidationMessage, setValidationState]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const stepVl = calculateStepValue(maxPointValue, minPointValue, divisionQuantity);
|
|
108
|
+
const inverseStepVl = 1 / stepVl;
|
|
109
|
+
|
|
110
|
+
if ((valuesProp === null || valuesProp === void 0 ? void 0 : valuesProp.length) > 0) {
|
|
111
|
+
setKnobsPositions(knobsValuesToKnobsPositions(valuesProp.length > 0 ? valuesProp : defaultValues, inverseStepVl, minPointValue));
|
|
112
|
+
}
|
|
113
|
+
}, [defaultValues, divisionQuantity, maxPointValue, minPointValue, setKnobsPositions, valuesProp]);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!isDirty.current) {
|
|
116
|
+
// skip validation if currently focused or if empty and
|
|
117
|
+
// the user never manually edited the input value
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
performValidation(knobsPositions, requiredMessage);
|
|
122
|
+
}, [knobsPositions, requiredMessage, performValidation]);
|
|
123
|
+
/**
|
|
124
|
+
* Generates an object which posses the current value and position of the knobs.
|
|
125
|
+
*
|
|
126
|
+
* @param {Array} knobsCurrentPosition - An array containing the current positions of the knobs.
|
|
127
|
+
* @returns {Object} - An object with the positions and values of the knobs.
|
|
128
|
+
* @memberof HvSlider
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
const generateKnobsPositionAndValues = knobsCurrentPosition => {
|
|
132
|
+
const newKnobsPosition = knobsCurrentPosition.slice();
|
|
133
|
+
const knobsValues = [];
|
|
134
|
+
let duplicatedValue = null;
|
|
135
|
+
const findDuplicated = newKnobsPosition.filter((item, index) => newKnobsPosition.indexOf(item) !== index);
|
|
136
|
+
|
|
137
|
+
if (noOverlap && findDuplicated.length > 0) {
|
|
138
|
+
[duplicatedValue] = findDuplicated;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
newKnobsPosition.forEach((position, index, array) => {
|
|
142
|
+
const newArray = array;
|
|
143
|
+
let newPosition = position;
|
|
144
|
+
|
|
145
|
+
if (noOverlap && newPosition === duplicatedValue) {
|
|
146
|
+
const previousValue = knobsPositions[index];
|
|
147
|
+
|
|
148
|
+
if (previousValue !== newPosition) {
|
|
149
|
+
newPosition += newPosition > previousValue ? -1 : 1;
|
|
150
|
+
newArray[index] = newPosition;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
knobsValues[index] = knobsPositionToScaledValue(newPosition, minPointValue, stepValue);
|
|
155
|
+
}, this);
|
|
156
|
+
return {
|
|
157
|
+
knobsPosition: newKnobsPosition,
|
|
158
|
+
knobsValues
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Function executed while the knobs changes.
|
|
163
|
+
*
|
|
164
|
+
* executes the callback provided by the user with the values and position of the knobs,
|
|
165
|
+
* also lock the value of the knob in case one is fixed.
|
|
166
|
+
*
|
|
167
|
+
* @param {Array} knobsPosition - An array containing the current positions of the knobs.
|
|
168
|
+
* @memberof HvSlider
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
const onChangeHandler = knobsPosition => {
|
|
173
|
+
isDirty.current = true;
|
|
174
|
+
const knobs = generateKnobsPositionAndValues(knobsPosition);
|
|
175
|
+
knobProperties.forEach((knobProperty, index) => {
|
|
176
|
+
if (knobProperty.fixed) {
|
|
177
|
+
knobs.knobsPosition[index] = scaledValueToKnobsPositionValue(defaultValues[index], minPointValue, inverseStepValue);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
if (disabled || readOnly) return;
|
|
181
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(knobs.knobsValues);
|
|
182
|
+
setKnobsPositions(knobs.knobsPosition);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const onInputChangeHandler = (inputValues, index) => {
|
|
186
|
+
let newKnobPositions = knobsValuesToKnobsPositions(inputValues, inverseStepValue, minPointValue);
|
|
187
|
+
newKnobPositions = ensureValuesConsistency(newKnobPositions, index);
|
|
188
|
+
onChangeHandler(newKnobPositions);
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Function executed before a change.
|
|
192
|
+
*
|
|
193
|
+
* executes the callback provided by the user with the values and position of the knobs
|
|
194
|
+
*
|
|
195
|
+
* @param {Array} knobsPosition - An array containing the current positions of the knobs.
|
|
196
|
+
* @memberof HvSlider
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
const onBeforeChangeHandler = knobsPosition => {
|
|
201
|
+
const knobs = generateKnobsPositionAndValues(knobsPosition);
|
|
202
|
+
onBeforeChange === null || onBeforeChange === void 0 ? void 0 : onBeforeChange(knobs.knobsValues);
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Function executed after a change.
|
|
206
|
+
*
|
|
207
|
+
* executes the callback provided by the user with the values and position of the knobs
|
|
208
|
+
*
|
|
209
|
+
* @param {Array} knobsPosition - An array containing the current positions of the knobs.
|
|
210
|
+
* @memberof HvSlider
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
const onAfterChangeHandler = knobsPosition => {
|
|
215
|
+
const knobs = generateKnobsPositionAndValues(knobsPosition);
|
|
216
|
+
onAfterChange === null || onAfterChange === void 0 ? void 0 : onAfterChange(knobs.knobsValues);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const onMouseDownHandler = event => {
|
|
220
|
+
if (event.target.className.includes("track")) {
|
|
221
|
+
setIsDraggingTrack(true);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const onMouseUpHandler = () => {
|
|
226
|
+
setIsDraggingTrack(false);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const onBlurHandler = event => {
|
|
230
|
+
const knobs = generateKnobsPositionAndValues(knobsPositions);
|
|
231
|
+
performValidation(knobsPositions, requiredMessage);
|
|
232
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event, knobs.knobsValues, status);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const sliderInputId = setId(elementId, "input");
|
|
236
|
+
/**
|
|
237
|
+
* Function used to create a custom knob for the slider.
|
|
238
|
+
*
|
|
239
|
+
* TODO: This should be isolated because is creating a sub component,
|
|
240
|
+
* but there were some problems regarding the underlying component losing
|
|
241
|
+
* references of the handlers disabling the focus.
|
|
242
|
+
*
|
|
243
|
+
* @param {Object} props - An object containing the properties of the knobs.
|
|
244
|
+
* @memberof HvSlider
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
const createKnob = (knobNode, params) => {
|
|
248
|
+
const {
|
|
249
|
+
value: knobValue,
|
|
250
|
+
dragging,
|
|
251
|
+
index
|
|
252
|
+
} = params;
|
|
253
|
+
|
|
254
|
+
const _knobNode$props = knobNode.props,
|
|
255
|
+
{
|
|
256
|
+
className: knobClassName,
|
|
257
|
+
style
|
|
258
|
+
} = _knobNode$props,
|
|
259
|
+
restProps = _objectWithoutProperties(_knobNode$props, _excluded2);
|
|
260
|
+
|
|
261
|
+
const scaledKnobValue = knobsPositionToScaledValue(knobValue, minPointValue, stepValue).toFixed(markDigits);
|
|
262
|
+
|
|
263
|
+
if (dragging) {
|
|
264
|
+
style.backgroundColor = knobProperties[index].dragColor;
|
|
265
|
+
} else {
|
|
266
|
+
style.backgroundColor = knobProperties[index].color;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const isEmpty = Number.isNaN(knobsPositions[index]) || knobsPositions[index] == null;
|
|
270
|
+
const handleId = setId(elementId, "knob");
|
|
271
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
272
|
+
key: index,
|
|
273
|
+
className: clsx((isEmpty || readOnly) && classes.handleHiddenContainer, !isEmpty && (disabled ? classes.handleContainerDisabled : classes.handleContainer))
|
|
274
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
275
|
+
prefixCls: "rc-slider-tooltip",
|
|
276
|
+
overlay: (formatTooltip === null || formatTooltip === void 0 ? void 0 : formatTooltip(scaledKnobValue)) || scaledKnobValue,
|
|
277
|
+
visible: dragging,
|
|
278
|
+
placement: "top",
|
|
279
|
+
overlayClassName: classes.sliderTooltip
|
|
280
|
+
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
281
|
+
id: setId(handleId, index),
|
|
282
|
+
style: style,
|
|
283
|
+
className: clsx(knobClassName, classes.handle)
|
|
284
|
+
}, restProps, {
|
|
285
|
+
"aria-label": `${label}-knob-${index}`,
|
|
286
|
+
"aria-valuenow": knobsPositionToScaledValue(knobValue, minPointValue, stepValue),
|
|
287
|
+
"aria-valuemin": minPointValue,
|
|
288
|
+
"aria-valuemax": maxPointValue
|
|
289
|
+
}, knobProps === null || knobProps === void 0 ? void 0 : knobProps[index]))));
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
return /*#__PURE__*/React.createElement(HvFormElement, _extends({
|
|
293
|
+
className: clsx(className, classes.root, !readOnly && !disabled && !isSingle && [isDraggingTrack && classes.trackDragging, !isDraggingTrack && classes.trackStandBy], disabled && classes.rootDisabled),
|
|
294
|
+
id: id,
|
|
295
|
+
name: name,
|
|
296
|
+
status: statusArrayToFormStatus(validationStatus),
|
|
297
|
+
disabled: disabled,
|
|
298
|
+
required: required,
|
|
299
|
+
readOnly: readOnly,
|
|
300
|
+
onMouseDown: onMouseDownHandler,
|
|
301
|
+
onMouseUp: onMouseUpHandler,
|
|
302
|
+
onBlur: onBlurHandler
|
|
303
|
+
}, others), (hasLabel || !hideInput) && /*#__PURE__*/React.createElement("div", {
|
|
304
|
+
className: clsx(classes.labelContainer, hasLabel ? classes.labelIncluded : classes.onlyInput)
|
|
305
|
+
}, hasLabel && /*#__PURE__*/React.createElement(HvLabel, {
|
|
306
|
+
id: setId(elementId, "label"),
|
|
307
|
+
className: classes.label,
|
|
308
|
+
htmlFor: setId(elementId, "slider"),
|
|
309
|
+
label: label
|
|
310
|
+
}), !hideInput && /*#__PURE__*/React.createElement(SliderInput, {
|
|
311
|
+
id: sliderInputId,
|
|
312
|
+
label: label,
|
|
313
|
+
values: knobsPositionsToKnobsValues(knobsPositions, stepValue, minPointValue),
|
|
314
|
+
onChange: onInputChangeHandler,
|
|
315
|
+
status: validationStatus,
|
|
316
|
+
disabled: disabled,
|
|
317
|
+
readOnly: readOnly,
|
|
318
|
+
markDigits: markDigits,
|
|
319
|
+
inputProps: inputProps
|
|
320
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
321
|
+
className: classes.sliderContainer
|
|
322
|
+
}, isSingle && /*#__PURE__*/React.createElement(Slider, _extends({
|
|
323
|
+
id: setId(elementId, "slider"),
|
|
324
|
+
handleRender: createKnob,
|
|
325
|
+
className: clsx(classes.sliderRoot),
|
|
326
|
+
min: 0,
|
|
327
|
+
max: divisionQuantity,
|
|
328
|
+
step: 1,
|
|
329
|
+
marks: marks,
|
|
330
|
+
dotStyle: disabled ? styles.dotDisabled : styles.dot,
|
|
331
|
+
onChange: singleValue => onChangeHandler([singleValue]),
|
|
332
|
+
onBeforeChange: singleValue => onBeforeChangeHandler([singleValue]),
|
|
333
|
+
onAfterChange: singleValue => onAfterChangeHandler([singleValue]),
|
|
334
|
+
value: knobsPositions.length > 0 ? knobsPositions[0] : undefined,
|
|
335
|
+
allowCross: false,
|
|
336
|
+
disabled: disabled,
|
|
337
|
+
count: rangesCount,
|
|
338
|
+
railStyle: styles.rail,
|
|
339
|
+
handleStyle: knobStyles.knobInner,
|
|
340
|
+
trackStyle: trackStyles
|
|
341
|
+
}, sliderProps)), !isSingle && /*#__PURE__*/React.createElement(Slider, _extends({
|
|
342
|
+
id: setId(elementId, "slider"),
|
|
343
|
+
range: true,
|
|
344
|
+
handleRender: createKnob,
|
|
345
|
+
className: clsx(classes.sliderRoot, !isSingle && classes.rootRange),
|
|
346
|
+
min: 0,
|
|
347
|
+
max: divisionQuantity,
|
|
348
|
+
step: 1,
|
|
349
|
+
marks: marks,
|
|
350
|
+
disabled: disabled,
|
|
351
|
+
dotStyle: disabled ? styles.dotDisabled : styles.dot,
|
|
352
|
+
onChange: onChangeHandler,
|
|
353
|
+
onBeforeChange: onBeforeChangeHandler,
|
|
354
|
+
onAfterChange: onAfterChangeHandler,
|
|
355
|
+
value: knobsPositions.length > 0 ? [...knobsPositions] : undefined,
|
|
356
|
+
allowCross: false,
|
|
357
|
+
count: rangesCount,
|
|
358
|
+
railStyle: styles.rail,
|
|
359
|
+
handleStyle: knobStyles.knobInner,
|
|
360
|
+
trackStyle: trackStyles,
|
|
361
|
+
draggableTrack: !readOnly && !isSingle
|
|
362
|
+
}, sliderProps))), canShowError && /*#__PURE__*/React.createElement(HvWarningText, {
|
|
363
|
+
id: setId(elementId, "error"),
|
|
364
|
+
className: classes.error,
|
|
365
|
+
disableBorder: true
|
|
366
|
+
}, validationMessage));
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
process.env.NODE_ENV !== "production" ? HvSlider.propTypes = {
|
|
370
|
+
/**
|
|
371
|
+
* Class names to be applied.
|
|
372
|
+
*/
|
|
373
|
+
className: PropTypes.string,
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Id to be applied to the slider root node.
|
|
377
|
+
*/
|
|
378
|
+
id: PropTypes.string,
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* The slider name.
|
|
382
|
+
*/
|
|
383
|
+
name: PropTypes.string,
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The label of the slider.
|
|
387
|
+
*
|
|
388
|
+
* If not provided, an aria-label or aria-labelledby must be inputted via sliderProps.
|
|
389
|
+
*/
|
|
390
|
+
label: PropTypes.node,
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Indicates that the slider is disabled.
|
|
394
|
+
*/
|
|
395
|
+
disabled: PropTypes.bool,
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Indicates that the slider is not editable.
|
|
399
|
+
*/
|
|
400
|
+
readOnly: PropTypes.bool,
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Indicates that user slider is required on the form element.
|
|
404
|
+
*/
|
|
405
|
+
required: PropTypes.bool,
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* What message to render when the value is required.
|
|
409
|
+
*/
|
|
410
|
+
requiredMessage: PropTypes.string,
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* if `true` the input that controls the slider is hidden.
|
|
414
|
+
*/
|
|
415
|
+
hideInput: PropTypes.bool,
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Attributes applied to the slider element.
|
|
419
|
+
*/
|
|
420
|
+
sliderProps: PropTypes.instanceOf(Object),
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The status of the slider.
|
|
424
|
+
*
|
|
425
|
+
* Valid is correct, invalid is incorrect and standBy means no validations have run.
|
|
426
|
+
*
|
|
427
|
+
* When uncontrolled and unspecified it will default to "standBy" and change to either "valid"
|
|
428
|
+
* or "invalid" after any change to `checked`, depending of the values of both `required` and `checked`.
|
|
429
|
+
*/
|
|
430
|
+
status: PropTypes.oneOf(["standBy", "valid", "invalid"]),
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* The error message to show when `status` is "invalid".
|
|
434
|
+
*/
|
|
435
|
+
statusMessage: PropTypes.string,
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* The values array to apply to the component
|
|
439
|
+
*/
|
|
440
|
+
values: PropTypes.arrayOf(PropTypes.number),
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* The default values array to apply to the component
|
|
444
|
+
*/
|
|
445
|
+
defaultValues: PropTypes.arrayOf(PropTypes.number),
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* The object used to set the knob properties,
|
|
449
|
+
* for every item in the array a new knob will be created.
|
|
450
|
+
*/
|
|
451
|
+
knobProperties: PropTypes.arrayOf(PropTypes.shape({
|
|
452
|
+
color: PropTypes.string,
|
|
453
|
+
hoverColor: PropTypes.string,
|
|
454
|
+
trackColor: PropTypes.string,
|
|
455
|
+
dragColor: PropTypes.string,
|
|
456
|
+
knobRingColor: PropTypes.string,
|
|
457
|
+
defaultValue: PropTypes.number,
|
|
458
|
+
hidden: PropTypes.bool,
|
|
459
|
+
fixed: PropTypes.bool
|
|
460
|
+
})),
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The object used to set the mark properties individually.
|
|
464
|
+
*/
|
|
465
|
+
markProperties: PropTypes.arrayOf(PropTypes.shape({
|
|
466
|
+
position: PropTypes.number,
|
|
467
|
+
label: PropTypes.string
|
|
468
|
+
})),
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* the function executed before a change will occur in the slider.
|
|
472
|
+
*/
|
|
473
|
+
onBeforeChange: PropTypes.func,
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* the function executed while a change is occurring in the slider.
|
|
477
|
+
*/
|
|
478
|
+
onChange: PropTypes.func,
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* the function executed after a change ocurred in the slider.
|
|
482
|
+
*/
|
|
483
|
+
onAfterChange: PropTypes.func,
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* the function executed after a blur ocurred in the slider.
|
|
487
|
+
*/
|
|
488
|
+
onBlur: PropTypes.func,
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* the separation in points between marks.
|
|
492
|
+
* example: if 10 divisions and a markstep of 2 there will be 5 marks.
|
|
493
|
+
*/
|
|
494
|
+
markStep: PropTypes.number,
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* how many subdivisions there are in the slider.
|
|
498
|
+
*/
|
|
499
|
+
divisionQuantity: PropTypes.number,
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* the value of the first point in the slider from left to right.
|
|
503
|
+
*/
|
|
504
|
+
minPointValue: PropTypes.number,
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* the value of the last point in the slider from left to right.
|
|
508
|
+
*/
|
|
509
|
+
maxPointValue: PropTypes.number,
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* the max number of decimals if no format function is applied
|
|
513
|
+
*/
|
|
514
|
+
markDigits: PropTypes.number,
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* a formatting function used to add format to the marks in the track,
|
|
518
|
+
* the function receives the mark text
|
|
519
|
+
*/
|
|
520
|
+
formatMark: PropTypes.func,
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* a formatting function used to add format to the tooltip in the track,
|
|
524
|
+
* the function receives the mark text
|
|
525
|
+
*/
|
|
526
|
+
formatTooltip: PropTypes.func,
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* if `true` the knobs can't have the same value, if `false` knobs can have the same value.
|
|
530
|
+
*/
|
|
531
|
+
noOverlap: PropTypes.bool,
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* the classes object to be applied into the root object.
|
|
535
|
+
*/
|
|
536
|
+
classes: PropTypes.shape({
|
|
537
|
+
/**
|
|
538
|
+
* Style applied to the root of the component.
|
|
539
|
+
*/
|
|
540
|
+
root: PropTypes.string,
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Style applied to the root of the component when in range mode.
|
|
544
|
+
*/
|
|
545
|
+
rootRange: PropTypes.string,
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Style applied to the container holding the label.
|
|
549
|
+
*/
|
|
550
|
+
labelContainer: PropTypes.string,
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Style applied to the label.
|
|
554
|
+
*/
|
|
555
|
+
label: PropTypes.string,
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Style applied to the knob.
|
|
559
|
+
*/
|
|
560
|
+
handle: PropTypes.string,
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Style applied to the container that has the knob used to move.
|
|
564
|
+
*/
|
|
565
|
+
handleContainer: PropTypes.string,
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Style applied to the div where the slider is placed.
|
|
569
|
+
*/
|
|
570
|
+
sliderRoot: PropTypes.string,
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Style applied when the user is dragging the range track.
|
|
574
|
+
*/
|
|
575
|
+
trackDragging: PropTypes.string,
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Style applied when root container is disabled.
|
|
579
|
+
*/
|
|
580
|
+
rootDisabled: PropTypes.string,
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Style applied when the user is not dragging the range track.
|
|
584
|
+
*/
|
|
585
|
+
trackStandBy: PropTypes.string,
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Style applied to the warning container.
|
|
589
|
+
*/
|
|
590
|
+
error: PropTypes.string,
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Style applied to the handle container when it is hidden.
|
|
594
|
+
*/
|
|
595
|
+
handleHiddenContainer: PropTypes.string,
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Style applied to the handle container when it is disabled.
|
|
599
|
+
*/
|
|
600
|
+
handleContainerDisabled: PropTypes.string,
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Style applied when the label element is present.
|
|
604
|
+
*/
|
|
605
|
+
labelIncluded: PropTypes.string,
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Style applied when only the input element is present.
|
|
609
|
+
*/
|
|
610
|
+
onlyInput: PropTypes.string,
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Style applied to the dot.
|
|
614
|
+
*/
|
|
615
|
+
dot: PropTypes.string,
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Style applied to the rail.
|
|
619
|
+
*/
|
|
620
|
+
rail: PropTypes.string,
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Style applied to the inner of the knob.
|
|
624
|
+
*/
|
|
625
|
+
knobInner: PropTypes.string,
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Style applied to the outside of the knob.
|
|
629
|
+
*/
|
|
630
|
+
knobOuter: PropTypes.string,
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Style applied when the knob is hidden.
|
|
634
|
+
*/
|
|
635
|
+
knobHidden: PropTypes.string,
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Style applied last hidden knob.
|
|
639
|
+
*/
|
|
640
|
+
knobHiddenLast: PropTypes.string,
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Style applied to the track.
|
|
644
|
+
*/
|
|
645
|
+
track: PropTypes.string,
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Style applied to the mark.
|
|
649
|
+
*/
|
|
650
|
+
mark: PropTypes.string,
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Style applied to the tooltip.
|
|
654
|
+
*/
|
|
655
|
+
sliderTooltip: PropTypes.string,
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Style applied to the container of the tooltip.
|
|
659
|
+
*/
|
|
660
|
+
sliderContainer: PropTypes.string
|
|
661
|
+
}).isRequired,
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Identifies the element that provides an error message for the slider.
|
|
665
|
+
*
|
|
666
|
+
* Will only be used when the validation status is invalid.
|
|
667
|
+
*/
|
|
668
|
+
"aria-errormessage": PropTypes.string,
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Attributes applied to the input element.
|
|
672
|
+
*/
|
|
673
|
+
inputProps: PropTypes.arrayOf(PropTypes.instanceOf(Object)),
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Attributes applied to the input element.
|
|
677
|
+
*/
|
|
678
|
+
knobProps: PropTypes.arrayOf(PropTypes.instanceOf(Object)),
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Theme object required to style the slider.
|
|
682
|
+
*/
|
|
683
|
+
theme: PropTypes.any.isRequired
|
|
684
|
+
} : void 0;
|
|
685
|
+
export default withStyles(styleCreator, {
|
|
686
|
+
name: "HvSlider",
|
|
687
|
+
withTheme: true
|
|
688
|
+
})(HvSlider);
|
|
689
|
+
//# sourceMappingURL=Slider.js.map
|