zcomponents-ui 1.2.3 → 1.3.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/README.md +20 -0
- package/dist/{index-Cfnntm1b.js → index-BiSP8JEr.js} +1 -7
- package/dist/index-BiSP8JEr.js.map +1 -0
- package/dist/{index-BZL-Zu45.js → index-DZGmLslf.js} +1 -7
- package/dist/index-DZGmLslf.js.map +1 -0
- package/dist/index.cjs.js +576 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +121 -4
- package/dist/index.esm.js +578 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/react-hook-form.cjs.js +1 -1
- package/dist/react-hook-form.d.ts +3 -3
- package/dist/react-hook-form.esm.js +1 -1
- package/dist/types/components/ZDrop/types/zDropTypes.d.ts +2 -2
- package/dist/types/components/ZRange/components/ZRangeIndicator/index.d.ts +3 -0
- package/dist/types/components/ZRange/components/ZRangeInputs/index.d.ts +3 -0
- package/dist/types/components/ZRange/components/ZRangeLabel/index.d.ts +3 -0
- package/dist/types/components/ZRange/components/ZRangeSliderValue/index.d.ts +3 -0
- package/dist/types/components/ZRange/components/ZRangeTrack/index.d.ts +3 -0
- package/dist/types/components/ZRange/helpers/calculateStepPosition.d.ts +1 -0
- package/dist/types/components/ZRange/helpers/checkIsInputSwapAllowed.d.ts +1 -0
- package/dist/types/components/ZRange/helpers/convertToUnit.d.ts +6 -0
- package/dist/types/components/ZRange/helpers/getCssVariablePxValue.d.ts +1 -0
- package/dist/types/components/ZRange/helpers/getMinMax.d.ts +4 -0
- package/dist/types/components/ZRange/index.d.ts +3 -0
- package/dist/types/components/ZRange/rangeValue.d.ts +13 -0
- package/dist/types/components/ZRange/types/zRangeTypes.d.ts +103 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/zcomponents-ui.css +1 -1
- package/dist/zcomponents-ui.css.map +1 -1
- package/package.json +1 -1
- package/dist/index-BZL-Zu45.js.map +0 -1
- package/dist/index-Cfnntm1b.js.map +0 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-DZGmLslf.js');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
require('react-hook-form');
|
|
7
7
|
|
|
8
|
-
var styles = {"zd-button":"ZDropButton-module_zd-button__XVZ-w","zd-button__toggle":"ZDropButton-module_zd-button__toggle__0jdWn","zd-button__toggle-title":"ZDropButton-module_zd-button__toggle-title__OaiVF","zd-button__toggle-icon":"ZDropButton-module_zd-button__toggle-icon__G4tnb","zd-button__content":"ZDropButton-module_zd-button__content__FS-6m","zd-button__search":"ZDropButton-module_zd-button__search__6Nbrx","zd-button__search-input-field":"ZDropButton-module_zd-button__search-input-field__K2avH","zd-button__search-input":"ZDropButton-module_zd-button__search-input__1e643","zd-button__search-clear-btn":"ZDropButton-module_zd-button__search-clear-btn__hJo2h","zd-button__search-clear-btn-icon":"ZDropButton-module_zd-button__search-clear-btn-icon__PWwHy","zd-button__list":"ZDropButton-module_zd-button__list__prV7p","zd-button__list-item":"ZDropButton-module_zd-button__list-item__uRK0D","zd-button__list-item--active":"ZDropButton-module_zd-button__list-item--active__oPoZA","zd-button__list-item-icon":"ZDropButton-module_zd-button__list-item-icon__xgqOm","zd-button__list-item-title":"ZDropButton-module_zd-button__list-item-title__RHTpc"};
|
|
8
|
+
var styles$1 = {"zd-button":"ZDropButton-module_zd-button__XVZ-w","zd-button__toggle":"ZDropButton-module_zd-button__toggle__0jdWn","zd-button__toggle-title":"ZDropButton-module_zd-button__toggle-title__OaiVF","zd-button__toggle-icon":"ZDropButton-module_zd-button__toggle-icon__G4tnb","zd-button__content":"ZDropButton-module_zd-button__content__FS-6m","zd-button__search":"ZDropButton-module_zd-button__search__6Nbrx","zd-button__search-input-field":"ZDropButton-module_zd-button__search-input-field__K2avH","zd-button__search-input":"ZDropButton-module_zd-button__search-input__1e643","zd-button__search-clear-btn":"ZDropButton-module_zd-button__search-clear-btn__hJo2h","zd-button__search-clear-btn-icon":"ZDropButton-module_zd-button__search-clear-btn-icon__PWwHy","zd-button__list":"ZDropButton-module_zd-button__list__prV7p","zd-button__list-item":"ZDropButton-module_zd-button__list-item__uRK0D","zd-button__list-item--active":"ZDropButton-module_zd-button__list-item--active__oPoZA","zd-button__list-item-icon":"ZDropButton-module_zd-button__list-item-icon__xgqOm","zd-button__list-item-title":"ZDropButton-module_zd-button__list-item-title__RHTpc"};
|
|
9
9
|
|
|
10
10
|
const ButtonDropdownToggle = (props) => {
|
|
11
11
|
const { title, toggleIcon, toggleClassName, children, onButtonToggleClick } = props;
|
|
12
|
-
const toggleClasses = index.classNames(styles["zd-button__toggle"], toggleClassName);
|
|
12
|
+
const toggleClasses = index.classNames(styles$1["zd-button__toggle"], toggleClassName);
|
|
13
13
|
const onToggleClick = (e) => {
|
|
14
14
|
onButtonToggleClick();
|
|
15
15
|
};
|
|
16
16
|
const onToggleMouseLeave = (e) => {
|
|
17
17
|
e.currentTarget.blur();
|
|
18
18
|
};
|
|
19
|
-
return (jsxRuntime.jsxs("button", { className: toggleClasses, onMouseLeave: onToggleMouseLeave, onClick: onToggleClick, children: [toggleIcon && (jsxRuntime.jsx("div", { className: styles["zd-button__toggle-icon"], children: toggleIcon })), title && (jsxRuntime.jsx("span", { className: styles["zd-button__toggle-title"], children: title })), children] }));
|
|
19
|
+
return (jsxRuntime.jsxs("button", { className: toggleClasses, onMouseLeave: onToggleMouseLeave, onClick: onToggleClick, children: [toggleIcon && (jsxRuntime.jsx("div", { className: styles$1["zd-button__toggle-icon"], children: toggleIcon })), title && (jsxRuntime.jsx("span", { className: styles$1["zd-button__toggle-title"], children: title })), children] }));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const ZDropButtonContent = (props) => {
|
|
@@ -141,19 +141,19 @@ const ZDropButtonContent = (props) => {
|
|
|
141
141
|
if (!isOpen) {
|
|
142
142
|
return null;
|
|
143
143
|
}
|
|
144
|
-
return (jsxRuntime.jsx("div", { className: styles["zd-button__content"], style: positionStyles, ref: contentRef, children: children }));
|
|
144
|
+
return (jsxRuntime.jsx("div", { className: styles$1["zd-button__content"], style: positionStyles, ref: contentRef, children: children }));
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
const ZDropButtonList = (props) => {
|
|
148
148
|
const { children } = props;
|
|
149
|
-
return jsxRuntime.jsx("ul", { className: styles["zd-button__list"], children: children });
|
|
149
|
+
return jsxRuntime.jsx("ul", { className: styles$1["zd-button__list"], children: children });
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
const ZDropButtonListItem = (props) => {
|
|
153
153
|
const { index: index$1, title, Icon, urlPath, className, linkAs: LinkTag = "a", isActive = false, children, } = props;
|
|
154
154
|
const { addToRefs, optionsRef, onItemSelect, searchInputRef } = react.useContext(ZDropButtonContext);
|
|
155
|
-
const itemContainerClasses = (isActive) => index.classNames(styles["zd-button__list-item"], {
|
|
156
|
-
[styles["zd-button__list-item--active"]]: !urlPath && isActive,
|
|
155
|
+
const itemContainerClasses = (isActive) => index.classNames(styles$1["zd-button__list-item"], {
|
|
156
|
+
[styles$1["zd-button__list-item--active"]]: !urlPath && isActive,
|
|
157
157
|
}, className);
|
|
158
158
|
const onItemClick = (e) => {
|
|
159
159
|
if (!urlPath) {
|
|
@@ -217,15 +217,15 @@ const ZDropButtonListItem = (props) => {
|
|
|
217
217
|
};
|
|
218
218
|
const ItemTypeComponent = urlPath ? LinkTag : "div";
|
|
219
219
|
return (jsxRuntime.jsx("li", { children: jsxRuntime.jsxs(ItemTypeComponent, { ref: (el) => addToRefs === null || addToRefs === void 0 ? void 0 : addToRefs(el, index$1), className: itemContainerClasses(isActive), tabIndex: 0, onClick: onItemClick, onMouseEnter: onItemMouseEnter, onMouseLeave: onItemMouseLeave, onKeyDown: onItemKeyDown, ...(urlPath &&
|
|
220
|
-
(LinkTag === "a" ? { href: urlPath } : { to: urlPath })), children: [Icon && (jsxRuntime.jsx("div", { className: styles["zd-button__list-item-icon"], children: Icon })), jsxRuntime.jsx("span", { className: styles["zd-button__list-item-title"], children: title }), children] }) }));
|
|
220
|
+
(LinkTag === "a" ? { href: urlPath } : { to: urlPath })), children: [Icon && (jsxRuntime.jsx("div", { className: styles$1["zd-button__list-item-icon"], children: Icon })), jsxRuntime.jsx("span", { className: styles$1["zd-button__list-item-title"], children: title }), children] }) }));
|
|
221
221
|
};
|
|
222
222
|
|
|
223
223
|
const ZDropButtonSearch = (props) => {
|
|
224
224
|
const { placeholder, searchIcon, clearIcon, searchClassName, shouldFocusOnOpen = false, } = props;
|
|
225
225
|
const { onSearch, searchInputRef, optionsRef, isOpen } = react.useContext(ZDropButtonContext);
|
|
226
226
|
const [isSearchActive, setIsSearchActive] = react.useState(false);
|
|
227
|
-
const searchFormClasses = index.classNames(styles["zd-button__search"]);
|
|
228
|
-
const searchInputFieldClasses = index.classNames(styles["zd-button__search-input-field"], { active: isSearchActive }, searchClassName);
|
|
227
|
+
const searchFormClasses = index.classNames(styles$1["zd-button__search"]);
|
|
228
|
+
const searchInputFieldClasses = index.classNames(styles$1["zd-button__search-input-field"], { active: isSearchActive }, searchClassName);
|
|
229
229
|
const onInputChange = (e) => {
|
|
230
230
|
onSearch === null || onSearch === void 0 ? void 0 : onSearch(e);
|
|
231
231
|
};
|
|
@@ -269,7 +269,7 @@ const ZDropButtonSearch = (props) => {
|
|
|
269
269
|
searchInputRef.current.focus();
|
|
270
270
|
}
|
|
271
271
|
}, []);
|
|
272
|
-
return (jsxRuntime.jsx("form", { className: searchFormClasses, onMouseEnter: onSearchMouseEnter, onMouseLeave: onSearchMouseLeave, onKeyDown: onSearchKeyDown, children: jsxRuntime.jsxs("div", { className: searchInputFieldClasses, children: [searchIcon && jsxRuntime.jsx("div", { children: searchIcon }), jsxRuntime.jsx("input", { className: styles["zd-button__search-input"], onChange: onInputChange, ref: searchInputRef, placeholder: placeholder }), jsxRuntime.jsx("button", { className: styles["zd-button__search-clear-btn"], type: "button", onClick: onClearClick, children: clearIcon || (jsxRuntime.jsx("span", { className: styles["zd-button__search-clear-btn-icon"] })) })] }) }));
|
|
272
|
+
return (jsxRuntime.jsx("form", { className: searchFormClasses, onMouseEnter: onSearchMouseEnter, onMouseLeave: onSearchMouseLeave, onKeyDown: onSearchKeyDown, children: jsxRuntime.jsxs("div", { className: searchInputFieldClasses, children: [searchIcon && jsxRuntime.jsx("div", { children: searchIcon }), jsxRuntime.jsx("input", { className: styles$1["zd-button__search-input"], onChange: onInputChange, ref: searchInputRef, placeholder: placeholder }), jsxRuntime.jsx("button", { className: styles$1["zd-button__search-clear-btn"], type: "button", onClick: onClearClick, children: clearIcon || (jsxRuntime.jsx("span", { className: styles$1["zd-button__search-clear-btn-icon"] })) })] }) }));
|
|
273
273
|
};
|
|
274
274
|
|
|
275
275
|
const ZDropButtonContext = react.createContext({});
|
|
@@ -279,7 +279,7 @@ const ZDropButton = (props) => {
|
|
|
279
279
|
const optionsRef = react.useRef([]);
|
|
280
280
|
const searchInputRef = react.useRef(null);
|
|
281
281
|
const [isOpen, setIsOpen] = react.useState(false);
|
|
282
|
-
const buttonContainerClasses = index.classNames(styles["zd-button"], className);
|
|
282
|
+
const buttonContainerClasses = index.classNames(styles$1["zd-button"], className);
|
|
283
283
|
const addToRefs = (element, index) => {
|
|
284
284
|
return (optionsRef.current[index] = element);
|
|
285
285
|
};
|
|
@@ -318,7 +318,570 @@ ZDropButton.List = ZDropButtonList;
|
|
|
318
318
|
ZDropButton.Item = ZDropButtonListItem;
|
|
319
319
|
ZDropButton.Search = ZDropButtonSearch;
|
|
320
320
|
|
|
321
|
+
const thumbInteractArea = 24;
|
|
322
|
+
const checkIsInputSwapAllowed = (activeIndex, comparedIndex, clientPosition, valuePosition) => {
|
|
323
|
+
return (activeIndex === comparedIndex &&
|
|
324
|
+
clientPosition !== null &&
|
|
325
|
+
clientPosition !== undefined &&
|
|
326
|
+
clientPosition < valuePosition + thumbInteractArea &&
|
|
327
|
+
clientPosition > valuePosition - thumbInteractArea);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const getMinMax = (firstValue, secondValue) => {
|
|
331
|
+
const min = firstValue < secondValue ? firstValue : secondValue;
|
|
332
|
+
const max = firstValue > secondValue ? firstValue : secondValue;
|
|
333
|
+
return { min, max };
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// import { UnitList } from "../types/zRangeTypes";
|
|
337
|
+
const convertToUnit = (rawValue, units = [], unitDivisors = [], isIndicatorUnitHidden = false, scaleFn = (x) => x) => {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
if (!units.length)
|
|
340
|
+
return String(rawValue);
|
|
341
|
+
if (!Number.isFinite(rawValue))
|
|
342
|
+
return String(rawValue);
|
|
343
|
+
const scaled = scaleFn(rawValue);
|
|
344
|
+
const sign = scaled < 0 ? "-" : "";
|
|
345
|
+
const value = Math.abs(scaled);
|
|
346
|
+
const divisors = unitDivisors
|
|
347
|
+
.slice(0, units.length)
|
|
348
|
+
.map((d) => (d > 0 ? d : 1));
|
|
349
|
+
if (!divisors.length) {
|
|
350
|
+
return `${sign}${value.toFixed(units[0].fractionDigits)} ${units[0].unit}`;
|
|
351
|
+
}
|
|
352
|
+
let idx = 0;
|
|
353
|
+
for (let i = 0; i < units.length; i++) {
|
|
354
|
+
const d = (_a = divisors[i]) !== null && _a !== void 0 ? _a : 1;
|
|
355
|
+
if (value >= d)
|
|
356
|
+
idx = i;
|
|
357
|
+
}
|
|
358
|
+
const d = (_b = divisors[idx]) !== null && _b !== void 0 ? _b : 1;
|
|
359
|
+
const converted = value / d;
|
|
360
|
+
if (isIndicatorUnitHidden) {
|
|
361
|
+
return `${sign}${converted.toFixed(units[idx].fractionDigits)}`;
|
|
362
|
+
}
|
|
363
|
+
return `${sign}${converted.toFixed(units[idx].fractionDigits)} ${units[idx].unit}`;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const calculateStepPosition = (currentValue, element, min, max) => {
|
|
367
|
+
if (!element) {
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
return ((currentValue - min) * element.clientWidth) / (max - min);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
class ZRangeValue {
|
|
374
|
+
constructor(min, max, unitDivisors, unitList, scale) {
|
|
375
|
+
this.min = min;
|
|
376
|
+
this.max = max;
|
|
377
|
+
this.unitDivisors = unitDivisors;
|
|
378
|
+
this.unitList = unitList;
|
|
379
|
+
this.scale = scale;
|
|
380
|
+
this.min.getPosition = this.getMinPosition.bind(this);
|
|
381
|
+
this.max.getPosition = this.getMaxPosition.bind(this);
|
|
382
|
+
}
|
|
383
|
+
getMinPosition() {
|
|
384
|
+
return calculateStepPosition(this.min.value, this.min.inputRef.current, this.min.initialValue, this.max.initialValue);
|
|
385
|
+
}
|
|
386
|
+
getMaxPosition() {
|
|
387
|
+
return calculateStepPosition(this.max.value, this.max.inputRef.current, this.min.initialValue, this.max.initialValue);
|
|
388
|
+
}
|
|
389
|
+
getRangeMiddle() {
|
|
390
|
+
return (this.max.value - this.min.value) / 2;
|
|
391
|
+
}
|
|
392
|
+
getValueLabel(forValue) {
|
|
393
|
+
const value = getMinMax(this.min.value, this.max.value)[forValue];
|
|
394
|
+
const valueLabel = this.scale ? this.scale(value) : value;
|
|
395
|
+
return this.unitList
|
|
396
|
+
? convertToUnit(valueLabel, this.unitList, this.unitDivisors).toString()
|
|
397
|
+
: `${valueLabel}`;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var styles = {"z-range":"ZRange-module_z-range__z6bqS","z-range__container":"ZRange-module_z-range__container__RSKdQ","z-range__label":"ZRange-module_z-range__label__vcLKv","z-range__value-indicator-icon":"ZRange-module_z-range__value-indicator-icon__A4CDC","z-range__inputs-wrapper":"ZRange-module_z-range__inputs-wrapper__K3sk3","z-range__slider":"ZRange-module_z-range__slider__fubBh","z-range__slider-track":"ZRange-module_z-range__slider-track__m8rsi","z-range__slider-track-selected-range":"ZRange-module_z-range__slider-track-selected-range__P0Qm4","z-range__slider-values-wrapper":"ZRange-module_z-range__slider-values-wrapper__jdtV1","z-range__slider-value":"ZRange-module_z-range__slider-value__rSDuP","z-range__slider-first-value":"ZRange-module_z-range__slider-first-value__LzOA9"};
|
|
402
|
+
|
|
403
|
+
const getCssVariablePxValue = (element, cssVariableName, fallbackPx) => {
|
|
404
|
+
const rawValue = getComputedStyle(element)
|
|
405
|
+
.getPropertyValue(cssVariableName)
|
|
406
|
+
.trim();
|
|
407
|
+
const parsedPx = parseFloat(rawValue);
|
|
408
|
+
return Number.isFinite(parsedPx) ? parsedPx : fallbackPx;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const ZRangeSliderValue = (props) => {
|
|
412
|
+
const { value, icon, sliderValueClassName } = props;
|
|
413
|
+
const thumbClasses = index.classNames(styles["z-range__slider-value"], styles["z-range__slider-first-value"], sliderValueClassName);
|
|
414
|
+
return (jsxRuntime.jsxs("div", { className: thumbClasses, children: [icon && jsxRuntime.jsx("span", { children: icon }), jsxRuntime.jsx("span", { children: value })] }));
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const indicatorTopGap = 2; // px
|
|
418
|
+
const ZRangeIndicator = (props) => {
|
|
419
|
+
const { valueIndicatorRef, indicatorStyles, indicatorValue, rangeTrackRef, inputElement, scaleFunction, unitList, unitDivisors, scale, icon, iconKey, isHighlighted, isIndicatorUnitHidden = false, } = props;
|
|
420
|
+
const [valueIndicatorStyles, setValueIndicatorStyles] = react.useState({});
|
|
421
|
+
const indicatorClasses = index.classNames("z-range__value-indicator", {
|
|
422
|
+
"z-range__value-indicator--active": typeof indicatorValue === "number" && isHighlighted,
|
|
423
|
+
}, indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicator, {
|
|
424
|
+
...((indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMin)
|
|
425
|
+
? { [indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMin]: iconKey === "min" }
|
|
426
|
+
: {}),
|
|
427
|
+
...((indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMax)
|
|
428
|
+
? { [indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMax]: iconKey === "max" }
|
|
429
|
+
: {}),
|
|
430
|
+
});
|
|
431
|
+
const indicatorIconClasses = index.classNames(styles["z-range__value-indicator-icon"], indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorIcon);
|
|
432
|
+
const indicatorValueClasses = index.classNames("z-range__value-indicator-value", indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorValue);
|
|
433
|
+
react.useLayoutEffect(() => {
|
|
434
|
+
var _a;
|
|
435
|
+
if (((_a = rangeTrackRef === null || rangeTrackRef === void 0 ? void 0 : rangeTrackRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) && inputElement) {
|
|
436
|
+
setValueIndicatorStyles({
|
|
437
|
+
bottom: `${rangeTrackRef.current.offsetHeight +
|
|
438
|
+
getCssVariablePxValue(inputElement, "--thumb-size", 16) / 2 +
|
|
439
|
+
indicatorTopGap}px`,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}, [indicatorValue, valueIndicatorRef, rangeTrackRef]);
|
|
443
|
+
return (jsxRuntime.jsxs("div", { ref: valueIndicatorRef, style: valueIndicatorStyles, className: indicatorClasses, children: [icon != null && typeof indicatorValue === "number" && (jsxRuntime.jsx("div", { className: indicatorIconClasses, children: icon }, iconKey !== null && iconKey !== void 0 ? iconKey : "indicator-icon")), typeof indicatorValue === "number" && (jsxRuntime.jsx("span", { className: indicatorValueClasses, children: convertToUnit(scale ? scaleFunction(indicatorValue) : indicatorValue, unitList, unitDivisors, isIndicatorUnitHidden) }))] }));
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const ZRangeTrack = (props) => {
|
|
447
|
+
const { rangeTrackRef, selectedRangeRef, selectedRangeStyle, trackStyles } = props;
|
|
448
|
+
const { trackContainer, trackRange, trackSelected } = trackStyles;
|
|
449
|
+
const trackClasses = index.classNames(styles["z-range__slider"], trackContainer);
|
|
450
|
+
const rangeClasses = index.classNames(styles["z-range__slider-track"], trackRange);
|
|
451
|
+
const selectedRangeClasses = index.classNames(styles["z-range__slider-track-selected-range"], trackSelected);
|
|
452
|
+
return (jsxRuntime.jsxs("div", { className: trackClasses, children: [jsxRuntime.jsx("div", { ref: rangeTrackRef, className: rangeClasses }), jsxRuntime.jsx("div", { ref: selectedRangeRef, className: selectedRangeClasses, style: selectedRangeStyle })] }));
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const ZRangeInputs = (props) => {
|
|
456
|
+
const { rangeValue, min, max, step, inputMinClasses, inputMaxClasses, onInputChange, onMouseDown, onTouchStart, onMouseMove, onTouchMove, onMouseUp, onTouchEnd, } = props;
|
|
457
|
+
return (jsxRuntime.jsxs("div", { className: styles["z-range__inputs-wrapper"], children: [jsxRuntime.jsx("input", { ref: rangeValue.min.inputRef, name: "0", type: "range", min: min, max: max,
|
|
458
|
+
// step={step || 1}
|
|
459
|
+
step: "any", value: rangeValue.min.value, className: inputMinClasses, onInput: onInputChange, onMouseDown: onMouseDown, onTouchStart: onTouchStart, onMouseMove: onMouseMove, onTouchMove: onTouchMove, onMouseUp: onMouseUp, onTouchEnd: onTouchEnd }), jsxRuntime.jsx("input", { ref: rangeValue.max.inputRef, name: "1", type: "range", min: min, max: max,
|
|
460
|
+
// step={step || 1}
|
|
461
|
+
step: "any", value: rangeValue.max.value, className: inputMaxClasses, onInput: onInputChange, onMouseDown: onMouseDown, onTouchStart: onTouchStart, onMouseMove: onMouseMove, onTouchMove: onTouchMove, onMouseUp: onMouseUp, onTouchEnd: onTouchEnd })] }));
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const ZRangeLabel = (props) => {
|
|
465
|
+
const { label, labelClassName } = props;
|
|
466
|
+
const labelClasses = index.classNames(styles["z-range__label"], labelClassName);
|
|
467
|
+
return jsxRuntime.jsx("div", { className: labelClasses, children: label });
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
471
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
472
|
+
const ZRange = (props) => {
|
|
473
|
+
var _a;
|
|
474
|
+
const { value, name, min, max, step, scale, unitDivisors, unitList, label, onSelect, onChange, icons, stylesClasses, isIndicatorUnitHidden, } = props;
|
|
475
|
+
const scaleFunction = (x) =>
|
|
476
|
+
// eslint-disable-next-line no-new-func
|
|
477
|
+
scale ? new Function("x", `return ${scale}`)(x) : x;
|
|
478
|
+
const containerRef = react.useRef(null);
|
|
479
|
+
const rangeTrackRef = react.useRef(null);
|
|
480
|
+
const selectedRangeRef = react.useRef(null);
|
|
481
|
+
const valueIndicatorRef = react.useRef(null);
|
|
482
|
+
const thumbOffsetRef = react.useRef({ 0: 0, 1: 0 });
|
|
483
|
+
const [indicatorValue, setIndicatorValue] = react.useState(undefined);
|
|
484
|
+
const [activeInputIndex, setActiveInputIndex] = react.useState(0);
|
|
485
|
+
const [rangeValue, setRangeValue] = react.useState(new ZRangeValue({
|
|
486
|
+
value: typeof (value === null || value === void 0 ? void 0 : value.min) === "number" ? value.min : min,
|
|
487
|
+
initialValue: min,
|
|
488
|
+
inputRef: react.useRef(null),
|
|
489
|
+
}, {
|
|
490
|
+
value: typeof (value === null || value === void 0 ? void 0 : value.max) === "number" ? value.max : max,
|
|
491
|
+
initialValue: max,
|
|
492
|
+
inputRef: react.useRef(null),
|
|
493
|
+
}, unitDivisors, unitList, scaleFunction));
|
|
494
|
+
const [clientPositionX, setClientPositionX] = react.useState(null);
|
|
495
|
+
const [isMoving, setIsMoving] = react.useState(false);
|
|
496
|
+
const [isHighlighted, setIsHighlighted] = react.useState(false);
|
|
497
|
+
const [selectedRangeStyle, setSelectedRangeStyle] = react.useState({
|
|
498
|
+
width: 0,
|
|
499
|
+
left: 0,
|
|
500
|
+
right: 0,
|
|
501
|
+
});
|
|
502
|
+
const stepValue = typeof step === "number" && step > 0 ? step : 1;
|
|
503
|
+
const maxForInput = min + Math.ceil((max - min) / stepValue) * stepValue;
|
|
504
|
+
const mapValueToInputRange = (domainValue) => domainValue >= max ? maxForInput : domainValue;
|
|
505
|
+
const mapInputRangeToValue = (inputValue) => Math.min(inputValue, max);
|
|
506
|
+
const rangeValueForInput = react.useMemo(() => {
|
|
507
|
+
return new ZRangeValue({
|
|
508
|
+
...rangeValue.min,
|
|
509
|
+
value: mapValueToInputRange(rangeValue.min.value),
|
|
510
|
+
initialValue: min,
|
|
511
|
+
inputRef: rangeValue.min.inputRef,
|
|
512
|
+
}, {
|
|
513
|
+
...rangeValue.max,
|
|
514
|
+
value: mapValueToInputRange(rangeValue.max.value),
|
|
515
|
+
initialValue: maxForInput,
|
|
516
|
+
inputRef: rangeValue.max.inputRef,
|
|
517
|
+
}, unitDivisors, unitList, scaleFunction);
|
|
518
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
519
|
+
}, [
|
|
520
|
+
rangeValue.min.value,
|
|
521
|
+
rangeValue.max.value,
|
|
522
|
+
min,
|
|
523
|
+
max,
|
|
524
|
+
maxForInput,
|
|
525
|
+
stepValue,
|
|
526
|
+
unitDivisors,
|
|
527
|
+
unitList,
|
|
528
|
+
scale,
|
|
529
|
+
]);
|
|
530
|
+
const containerClasses = index.classNames(styles["z-range__container"], stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.container);
|
|
531
|
+
const inputMinClasses = index.classNames("z-range__input", "z-range__input-first", {
|
|
532
|
+
"z-range__input--active": activeInputIndex === 0 && isHighlighted,
|
|
533
|
+
}, stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.input, activeInputIndex === 0 && isHighlighted && (stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive)
|
|
534
|
+
? stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive
|
|
535
|
+
: "");
|
|
536
|
+
const inputMaxClasses = index.classNames("z-range__input", "z-range__input-second", { "z-range__input--active": activeInputIndex === 1 && isHighlighted }, stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.input, activeInputIndex === 1 && isHighlighted && (stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive)
|
|
537
|
+
? stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive
|
|
538
|
+
: "");
|
|
539
|
+
react.useEffect(() => {
|
|
540
|
+
if (!value)
|
|
541
|
+
return;
|
|
542
|
+
const nextMin = clamp(value.min, min, max);
|
|
543
|
+
const nextMax = clamp(value.max, min, max);
|
|
544
|
+
const nextRangeValue = new ZRangeValue({
|
|
545
|
+
...rangeValue.min,
|
|
546
|
+
value: nextMin,
|
|
547
|
+
initialValue: min,
|
|
548
|
+
inputRef: rangeValue.min.inputRef,
|
|
549
|
+
}, {
|
|
550
|
+
...rangeValue.max,
|
|
551
|
+
value: nextMax,
|
|
552
|
+
initialValue: max,
|
|
553
|
+
inputRef: rangeValue.max.inputRef,
|
|
554
|
+
}, unitDivisors, unitList, scaleFunction);
|
|
555
|
+
setRangeValue(nextRangeValue);
|
|
556
|
+
setIndicatorValue(undefined);
|
|
557
|
+
thumbOffsetRef.current[0] = 0;
|
|
558
|
+
thumbOffsetRef.current[1] = 0;
|
|
559
|
+
requestAnimationFrame(() => {
|
|
560
|
+
const val = activeInputIndex === 0 ? nextMin : nextMax;
|
|
561
|
+
setRangeValuePosition(val);
|
|
562
|
+
});
|
|
563
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
564
|
+
}, [value === null || value === void 0 ? void 0 : value.min, value === null || value === void 0 ? void 0 : value.max, min, max]);
|
|
565
|
+
const getThumbCenterXInContainer = (input, currentValueReal, containerEl) => {
|
|
566
|
+
const currentValue = mapValueToInputRange(currentValueReal);
|
|
567
|
+
const thumbTravelRatio = clamp01((currentValue - min) / (maxForInput - min));
|
|
568
|
+
const inputRect = input.getBoundingClientRect();
|
|
569
|
+
const containerRect = containerEl.getBoundingClientRect();
|
|
570
|
+
const thumbSize = getCssVariablePxValue(input, "--thumb-size", 16);
|
|
571
|
+
const usable = inputRect.width - thumbSize;
|
|
572
|
+
const thumbCenterXInInput = thumbSize / 2 + usable * thumbTravelRatio;
|
|
573
|
+
const inputLeftInContainer = inputRect.left - containerRect.left;
|
|
574
|
+
return inputLeftInContainer + thumbCenterXInInput;
|
|
575
|
+
};
|
|
576
|
+
const setRangeValuePosition = (currentValueReal, inputIndex = activeInputIndex) => {
|
|
577
|
+
var _a;
|
|
578
|
+
const indicator = valueIndicatorRef.current;
|
|
579
|
+
const container = containerRef.current;
|
|
580
|
+
const input = (_a = (inputIndex === 0
|
|
581
|
+
? rangeValue.min.inputRef.current
|
|
582
|
+
: rangeValue.max.inputRef.current)) !== null && _a !== void 0 ? _a : rangeValue.min.inputRef.current;
|
|
583
|
+
if (!indicator || !container || !input)
|
|
584
|
+
return;
|
|
585
|
+
const distanceLeft = getThumbCenterXInContainer(input, currentValueReal, container);
|
|
586
|
+
indicator.style.left = `${Math.round(distanceLeft)}px`;
|
|
587
|
+
indicator.style.transform = `translateX(-50%)`;
|
|
588
|
+
};
|
|
589
|
+
const updateRangeValues = (currentValueReal, inputIndex) => {
|
|
590
|
+
const updatedRangeValue = new ZRangeValue({
|
|
591
|
+
...(inputIndex === 0
|
|
592
|
+
? { ...rangeValue.min, value: currentValueReal }
|
|
593
|
+
: rangeValue.min),
|
|
594
|
+
}, {
|
|
595
|
+
...(inputIndex === 0
|
|
596
|
+
? rangeValue.max
|
|
597
|
+
: { ...rangeValue.max, value: currentValueReal }),
|
|
598
|
+
}, rangeValue.unitDivisors, rangeValue.unitList, rangeValue.scale);
|
|
599
|
+
setRangeValue(updatedRangeValue);
|
|
600
|
+
setIndicatorValue(currentValueReal);
|
|
601
|
+
if (!onChange)
|
|
602
|
+
return;
|
|
603
|
+
const { min: currentMin, max: currentMax } = getMinMax(updatedRangeValue.min.value, updatedRangeValue.max.value);
|
|
604
|
+
onChange({
|
|
605
|
+
...updatedRangeValue,
|
|
606
|
+
min: { ...updatedRangeValue.min, value: currentMin },
|
|
607
|
+
max: { ...updatedRangeValue.max, value: currentMax },
|
|
608
|
+
}, name);
|
|
609
|
+
};
|
|
610
|
+
const onInputChange = (e) => {
|
|
611
|
+
if (!rangeTrackRef.current ||
|
|
612
|
+
!rangeValue.min.inputRef.current ||
|
|
613
|
+
!rangeValue.max.inputRef.current) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const currentValue = mapInputRangeToValue(Number(e.target.value));
|
|
617
|
+
const rangeTrackRect = rangeTrackRef.current.getBoundingClientRect();
|
|
618
|
+
const clientPositionOnTrack = clientPositionX != null ? clientPositionX - rangeTrackRect.left : null;
|
|
619
|
+
const minValueStepPosition = rangeValue.getMinPosition();
|
|
620
|
+
const maxValueStepPosition = rangeValue.getMaxPosition();
|
|
621
|
+
if (checkIsInputSwapAllowed(activeInputIndex, 0, clientPositionOnTrack, maxValueStepPosition)) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (checkIsInputSwapAllowed(activeInputIndex, 1, clientPositionOnTrack, minValueStepPosition)) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const { min: currentMin, max: currentMax } = getMinMax(rangeValue.min.value, rangeValue.max.value);
|
|
628
|
+
const rangeMiddle = (currentMax - currentMin) / 2;
|
|
629
|
+
if (rangeValue.max.value > rangeValue.min.value) {
|
|
630
|
+
if (currentValue < currentMin + rangeMiddle) {
|
|
631
|
+
setActiveInputIndex(0);
|
|
632
|
+
setRangeValuePosition(currentValue);
|
|
633
|
+
updateRangeValues(currentValue, 0);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
if (currentValue > currentMin + rangeMiddle) {
|
|
637
|
+
setActiveInputIndex(1);
|
|
638
|
+
setRangeValuePosition(currentValue);
|
|
639
|
+
updateRangeValues(currentValue, 1);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (rangeValue.min.value > rangeValue.max.value) {
|
|
644
|
+
if (currentValue < currentMin + rangeMiddle) {
|
|
645
|
+
setActiveInputIndex(1);
|
|
646
|
+
setRangeValuePosition(currentValue);
|
|
647
|
+
updateRangeValues(currentValue, 1);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (currentValue > currentMin + rangeMiddle) {
|
|
651
|
+
setActiveInputIndex(0);
|
|
652
|
+
setRangeValuePosition(currentValue);
|
|
653
|
+
updateRangeValues(currentValue, 0);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
setRangeValuePosition(currentValue);
|
|
658
|
+
updateRangeValues(currentValue, activeInputIndex);
|
|
659
|
+
};
|
|
660
|
+
const onMoveStart = (e) => {
|
|
661
|
+
setIsMoving(true);
|
|
662
|
+
setIsHighlighted(true);
|
|
663
|
+
const clientX = "clientX" in e ? e.clientX : e.touches[0].clientX;
|
|
664
|
+
setClientPositionX(clientX);
|
|
665
|
+
const container = containerRef.current;
|
|
666
|
+
const input = activeInputIndex === 0
|
|
667
|
+
? rangeValue.min.inputRef.current
|
|
668
|
+
: rangeValue.max.inputRef.current;
|
|
669
|
+
if (container && input) {
|
|
670
|
+
const containerRect = container.getBoundingClientRect();
|
|
671
|
+
const pointerXInContainer = clientX - containerRect.left;
|
|
672
|
+
const currentValReal = activeInputIndex === 0 ? rangeValue.min.value : rangeValue.max.value;
|
|
673
|
+
const thumbXInContainer = getThumbCenterXInContainer(input, currentValReal, container);
|
|
674
|
+
const thumbSize = getCssVariablePxValue(input, "--thumb-size", 16);
|
|
675
|
+
const dist = Math.abs(pointerXInContainer - thumbXInContainer);
|
|
676
|
+
thumbOffsetRef.current[activeInputIndex] =
|
|
677
|
+
dist <= thumbSize / 2 ? pointerXInContainer - thumbXInContainer : 0;
|
|
678
|
+
}
|
|
679
|
+
if (!rangeTrackRef.current ||
|
|
680
|
+
!rangeValue.min.inputRef.current ||
|
|
681
|
+
!rangeValue.max.inputRef.current) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const rangeTrackRect = rangeTrackRef.current.getBoundingClientRect();
|
|
685
|
+
const clientPositionOnTrack = clientX - rangeTrackRect.left;
|
|
686
|
+
const minValueStepPosition = rangeValue.getMinPosition();
|
|
687
|
+
const maxValueStepPosition = rangeValue.getMaxPosition();
|
|
688
|
+
if (checkIsInputSwapAllowed(activeInputIndex, 0, clientPositionOnTrack, maxValueStepPosition)) {
|
|
689
|
+
setActiveInputIndex(1);
|
|
690
|
+
thumbOffsetRef.current[1] = 0;
|
|
691
|
+
setRangeValuePosition(rangeValue.max.value, 1);
|
|
692
|
+
updateRangeValues(rangeValue.max.value, 1);
|
|
693
|
+
}
|
|
694
|
+
if (checkIsInputSwapAllowed(activeInputIndex, 1, clientPositionOnTrack, minValueStepPosition)) {
|
|
695
|
+
setActiveInputIndex(0);
|
|
696
|
+
thumbOffsetRef.current[0] = 0;
|
|
697
|
+
setRangeValuePosition(rangeValue.min.value);
|
|
698
|
+
updateRangeValues(rangeValue.min.value, 0);
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
const onMove = (e) => {
|
|
702
|
+
var _a, _b;
|
|
703
|
+
if (!isMoving)
|
|
704
|
+
return;
|
|
705
|
+
e.preventDefault();
|
|
706
|
+
e.stopPropagation();
|
|
707
|
+
const currentPositionX = "clientX" in e ? e.clientX : (_b = (_a = e.touches) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.clientX;
|
|
708
|
+
const element = activeInputIndex === 0
|
|
709
|
+
? rangeValue.min.inputRef
|
|
710
|
+
: rangeValue.max.inputRef;
|
|
711
|
+
if (!(element.current && currentPositionX != null))
|
|
712
|
+
return;
|
|
713
|
+
const slider = element.current;
|
|
714
|
+
const sliderRect = slider.getBoundingClientRect();
|
|
715
|
+
const offsetX = currentPositionX -
|
|
716
|
+
sliderRect.left -
|
|
717
|
+
thumbOffsetRef.current[activeInputIndex];
|
|
718
|
+
const thumbSize = getCssVariablePxValue(slider, "--thumb-size", 16);
|
|
719
|
+
const usable = Math.max(1, sliderRect.width - thumbSize);
|
|
720
|
+
const posOnUsable = clamp(offsetX - thumbSize / 2, 0, usable);
|
|
721
|
+
const ratio = posOnUsable / usable;
|
|
722
|
+
const rawValue = min + ratio * (maxForInput - min);
|
|
723
|
+
const roundedValue = Math.round((rawValue - min) / stepValue) * stepValue + min;
|
|
724
|
+
const limitedInputValue = clamp(roundedValue, min, maxForInput);
|
|
725
|
+
const limitedRealValue = mapInputRangeToValue(limitedInputValue);
|
|
726
|
+
setRangeValuePosition(limitedRealValue, activeInputIndex);
|
|
727
|
+
updateRangeValues(limitedRealValue, activeInputIndex);
|
|
728
|
+
};
|
|
729
|
+
const onMoveStop = (e) => {
|
|
730
|
+
var _a, _b, _c;
|
|
731
|
+
setIsMoving(false);
|
|
732
|
+
setIsHighlighted(false);
|
|
733
|
+
if (!((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) &&
|
|
734
|
+
rangeValue.min.inputRef.current &&
|
|
735
|
+
rangeValue.max.inputRef.current) {
|
|
736
|
+
const firstValue = activeInputIndex === 0
|
|
737
|
+
? mapInputRangeToValue(Number((_b = rangeValue.min.inputRef.current) === null || _b === void 0 ? void 0 : _b.value))
|
|
738
|
+
: rangeValue.min.value;
|
|
739
|
+
const secondValue = activeInputIndex === 1
|
|
740
|
+
? mapInputRangeToValue(Number((_c = rangeValue.max.inputRef.current) === null || _c === void 0 ? void 0 : _c.value))
|
|
741
|
+
: rangeValue.max.value;
|
|
742
|
+
const { min: lastMin, max: lastMax } = getMinMax(firstValue, secondValue);
|
|
743
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect({
|
|
744
|
+
...rangeValue,
|
|
745
|
+
min: { ...rangeValue.min, value: lastMin },
|
|
746
|
+
max: { ...rangeValue.max, value: lastMax },
|
|
747
|
+
}, name);
|
|
748
|
+
updateRangeValues(activeInputIndex === 0 ? lastMin : lastMax, activeInputIndex);
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
const targetValueReal = mapInputRangeToValue(Number(e.target.value));
|
|
752
|
+
const { min: currentMin, max: currentMax } = getMinMax(e.target.name === "0"
|
|
753
|
+
? targetValueReal
|
|
754
|
+
: rangeValue.min.value, e.target.name === "0"
|
|
755
|
+
? rangeValue.max.value
|
|
756
|
+
: targetValueReal);
|
|
757
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect({
|
|
758
|
+
...rangeValue,
|
|
759
|
+
min: { ...rangeValue.min, value: currentMin },
|
|
760
|
+
max: { ...rangeValue.max, value: currentMax },
|
|
761
|
+
}, name);
|
|
762
|
+
};
|
|
763
|
+
const onMoveEnd = (e) => {
|
|
764
|
+
onMoveStop(e);
|
|
765
|
+
e.stopPropagation();
|
|
766
|
+
};
|
|
767
|
+
react.useEffect(() => {
|
|
768
|
+
if (!isMoving)
|
|
769
|
+
return;
|
|
770
|
+
const handleTouchEnd = () => {
|
|
771
|
+
setIsMoving(false);
|
|
772
|
+
setIsHighlighted(false);
|
|
773
|
+
};
|
|
774
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
775
|
+
return () => document.removeEventListener("touchend", handleTouchEnd);
|
|
776
|
+
}, [isMoving]);
|
|
777
|
+
react.useEffect(() => {
|
|
778
|
+
if (!isMoving)
|
|
779
|
+
return;
|
|
780
|
+
const handleMouseUp = () => {
|
|
781
|
+
setIsMoving(false);
|
|
782
|
+
setIsHighlighted(false);
|
|
783
|
+
};
|
|
784
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
785
|
+
return () => document.removeEventListener("mouseup", handleMouseUp);
|
|
786
|
+
}, [isMoving]);
|
|
787
|
+
const calculateSelectedRangeStyle = () => {
|
|
788
|
+
if (!rangeTrackRef.current)
|
|
789
|
+
return;
|
|
790
|
+
const innerWidth = rangeTrackRef.current.clientWidth;
|
|
791
|
+
const { min: valueMinReal, max: valueMaxReal } = getMinMax(rangeValue.min.value, rangeValue.max.value);
|
|
792
|
+
const valueMin = mapValueToInputRange(valueMinReal);
|
|
793
|
+
const valueMax = mapValueToInputRange(valueMaxReal);
|
|
794
|
+
const ratioMin = clamp01((valueMin - min) / (maxForInput - min));
|
|
795
|
+
const ratioMax = clamp01((valueMax - min) / (maxForInput - min));
|
|
796
|
+
const leftPx = innerWidth * ratioMin;
|
|
797
|
+
const rightPx = innerWidth * ratioMax;
|
|
798
|
+
setSelectedRangeStyle({
|
|
799
|
+
left: `${leftPx}px`,
|
|
800
|
+
width: `${Math.max(0, rightPx - leftPx)}px`,
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
react.useEffect(() => {
|
|
804
|
+
calculateSelectedRangeStyle();
|
|
805
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
806
|
+
}, [
|
|
807
|
+
rangeValue.min.value,
|
|
808
|
+
rangeValue.max.value,
|
|
809
|
+
min,
|
|
810
|
+
max,
|
|
811
|
+
stepValue,
|
|
812
|
+
maxForInput,
|
|
813
|
+
]);
|
|
814
|
+
react.useEffect(() => {
|
|
815
|
+
setRangeValuePosition(activeInputIndex === 0 ? rangeValue.min.value : rangeValue.max.value);
|
|
816
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
817
|
+
}, []);
|
|
818
|
+
react.useLayoutEffect(() => {
|
|
819
|
+
const track = rangeTrackRef.current;
|
|
820
|
+
if (!track)
|
|
821
|
+
return;
|
|
822
|
+
let rafId = null;
|
|
823
|
+
const updateValue = () => {
|
|
824
|
+
calculateSelectedRangeStyle();
|
|
825
|
+
const updatedValue = typeof indicatorValue === "number"
|
|
826
|
+
? indicatorValue
|
|
827
|
+
: activeInputIndex === 0
|
|
828
|
+
? rangeValue.min.value
|
|
829
|
+
: rangeValue.max.value;
|
|
830
|
+
setRangeValuePosition(updatedValue);
|
|
831
|
+
};
|
|
832
|
+
const updateSchedule = () => {
|
|
833
|
+
if (rafId !== null)
|
|
834
|
+
return;
|
|
835
|
+
rafId = requestAnimationFrame(() => {
|
|
836
|
+
rafId = null;
|
|
837
|
+
updateValue();
|
|
838
|
+
});
|
|
839
|
+
};
|
|
840
|
+
updateSchedule();
|
|
841
|
+
const observer = new ResizeObserver(updateSchedule);
|
|
842
|
+
observer.observe(track);
|
|
843
|
+
window.addEventListener("resize", updateSchedule);
|
|
844
|
+
return () => {
|
|
845
|
+
observer.disconnect();
|
|
846
|
+
window.removeEventListener("resize", updateSchedule);
|
|
847
|
+
if (rafId !== null)
|
|
848
|
+
cancelAnimationFrame(rafId);
|
|
849
|
+
};
|
|
850
|
+
}, [
|
|
851
|
+
min,
|
|
852
|
+
max,
|
|
853
|
+
stepValue,
|
|
854
|
+
maxForInput,
|
|
855
|
+
indicatorValue,
|
|
856
|
+
activeInputIndex,
|
|
857
|
+
rangeValue.min.value,
|
|
858
|
+
rangeValue.max.value,
|
|
859
|
+
]);
|
|
860
|
+
const lowValue = Math.min(rangeValue.min.value, rangeValue.max.value);
|
|
861
|
+
const indicatorIsMin = typeof indicatorValue === "number" ? indicatorValue === lowValue : false;
|
|
862
|
+
const indicatorIcon = (icons === null || icons === void 0 ? void 0 : icons.indicatorMin) && (icons === null || icons === void 0 ? void 0 : icons.indicatorMax)
|
|
863
|
+
? indicatorIsMin
|
|
864
|
+
? icons.indicatorMin
|
|
865
|
+
: icons.indicatorMax
|
|
866
|
+
: undefined;
|
|
867
|
+
const indicatorIconKey = indicatorIsMin ? "min" : "max";
|
|
868
|
+
return (jsxRuntime.jsxs("div", { className: containerClasses, children: [label && (jsxRuntime.jsx(ZRangeLabel, { label: label, labelClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.label })), jsxRuntime.jsxs("div", { ref: containerRef, className: styles["z-range"], children: [jsxRuntime.jsx(ZRangeInputs, { rangeValue: rangeValueForInput, min: min, max: maxForInput, step: stepValue, inputMinClasses: inputMinClasses, inputMaxClasses: inputMaxClasses, onInputChange: onInputChange, onMouseDown: onMoveStart, onTouchStart: onMoveStart, onMouseMove: onMove, onTouchMove: onMove, onMouseUp: onMoveEnd, onTouchEnd: onMoveEnd }), jsxRuntime.jsx(ZRangeTrack, { rangeTrackRef: rangeTrackRef, selectedRangeRef: selectedRangeRef, selectedRangeStyle: selectedRangeStyle, trackStyles: {
|
|
869
|
+
trackContainer: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackContainer,
|
|
870
|
+
trackRange: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackRange,
|
|
871
|
+
trackSelected: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackSelected,
|
|
872
|
+
} }), jsxRuntime.jsx(ZRangeIndicator, { valueIndicatorRef: valueIndicatorRef, indicatorStyles: {
|
|
873
|
+
indicator: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicator,
|
|
874
|
+
indicatorMin: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorMin,
|
|
875
|
+
indicatorMax: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorMax,
|
|
876
|
+
indicatorValue: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorValue,
|
|
877
|
+
indicatorIcon: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorIcon,
|
|
878
|
+
}, indicatorValue: indicatorValue, rangeTrackRef: rangeTrackRef, inputElement: activeInputIndex === 0
|
|
879
|
+
? rangeValue.min.inputRef.current
|
|
880
|
+
: (_a = rangeValue.max.inputRef.current) !== null && _a !== void 0 ? _a : rangeValue.min.inputRef.current, scaleFunction: scaleFunction, unitList: unitList, unitDivisors: unitDivisors, scale: scale, icon: indicatorIcon, iconKey: indicatorIconKey, isHighlighted: isHighlighted, isIndicatorUnitHidden: isIndicatorUnitHidden })] }), jsxRuntime.jsxs("div", { className: styles["z-range__slider-values-wrapper"], children: [jsxRuntime.jsx(ZRangeSliderValue, { sliderValueClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.sliderValue, value: rangeValue.getValueLabel("min"), icon: icons === null || icons === void 0 ? void 0 : icons.thumbMin }), jsxRuntime.jsx(ZRangeSliderValue, { sliderValueClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.sliderValue, value: rangeValue.getValueLabel("max"), icon: icons === null || icons === void 0 ? void 0 : icons.thumbMax })] })] }));
|
|
881
|
+
};
|
|
882
|
+
|
|
321
883
|
exports.ZDrop = index.ZDrop;
|
|
322
884
|
exports.ZDropField = index.ZDropField;
|
|
323
885
|
exports.ZDropButton = ZDropButton;
|
|
886
|
+
exports.ZRange = ZRange;
|
|
324
887
|
//# sourceMappingURL=index.cjs.js.map
|