etudes 1.2.0 → 2.0.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 +1 -1
- package/lib/Accordion.d.ts +80 -71
- package/lib/Accordion.js +173 -183
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +20 -7
- package/lib/BurgerButton.js +113 -20
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +2 -3
- package/lib/Conditional.js +0 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +14 -23
- package/lib/DebugConsole.js +86 -87
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +53 -16
- package/lib/Dial.js +121 -35
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +68 -83
- package/lib/Dropdown.js +226 -161
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +2 -2
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +5 -4
- package/lib/ExtractChild.js +13 -11
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +2 -2
- package/lib/ExtractChildren.js +7 -5
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +30 -25
- package/lib/FlatSVG.js +28 -37
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +97 -54
- package/lib/List.js +124 -63
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +27 -15
- package/lib/MasonryGrid.js +163 -148
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +100 -21
- package/lib/Panorama.js +45 -44
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +65 -23
- package/lib/PanoramaSlider.js +150 -45
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +29 -89
- package/lib/RangeSlider.js +272 -286
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +4 -3
- package/lib/Repeat.js +3 -2
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +38 -36
- package/lib/RotatingGallery.js +47 -17
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +13 -4
- package/lib/SelectableButton.js +3 -14
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +103 -41
- package/lib/Slider.js +182 -82
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +146 -59
- package/lib/StepwiseSlider.js +248 -142
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +13 -5
- package/lib/SwipeContainer.js +5 -15
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js +5 -15
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +30 -51
- package/lib/Video.js +77 -119
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +16 -18
- package/lib/WithTooltip.js +167 -101
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDocumentTitle.d.ts +2 -1
- package/lib/hooks/useDocumentTitle.js +2 -1
- package/lib/hooks/useDocumentTitle.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +25 -16
- package/lib/hooks/useDragEffect.js +30 -20
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -1
- package/lib/hooks/useElementRect.js +5 -4
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +2 -2
- package/lib/hooks/useInterval.js +1 -1
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +6 -6
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +6 -0
- package/lib/hooks/usePrevious.js +17 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useResizeEffect.d.ts +2 -2
- package/lib/hooks/useResizeEffect.js +5 -8
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +10 -7
- package/lib/hooks/useSearchParamState.js +14 -10
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/utils/asClassNameDict.d.ts +3 -0
- package/lib/utils/asClassNameDict.js +7 -0
- package/lib/utils/asClassNameDict.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +5 -0
- package/lib/utils/asComponentDict.js +23 -0
- package/lib/utils/asComponentDict.js.map +1 -0
- package/lib/utils/asStyleDict.d.ts +4 -0
- package/lib/utils/asStyleDict.js +7 -0
- package/lib/utils/asStyleDict.js.map +1 -0
- package/lib/utils/cloneStyledElement.d.ts +18 -0
- package/lib/utils/cloneStyledElement.js +63 -0
- package/lib/utils/cloneStyledElement.js.map +1 -0
- package/lib/utils/styles.d.ts +2 -0
- package/lib/utils/styles.js +22 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/utils/useDebug.d.ts +2 -0
- package/lib/utils/useDebug.js +46 -0
- package/lib/utils/useDebug.js.map +1 -0
- package/package.json +25 -33
- package/lib/AbstractSelectableCollection.d.ts +0 -94
- package/lib/AbstractSelectableCollection.js +0 -151
- package/lib/AbstractSelectableCollection.js.map +0 -1
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
package/lib/RangeSlider.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
15
10
|
};
|
|
16
|
-
|
|
17
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
18
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
19
|
-
return cooked;
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
20
12
|
};
|
|
21
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
14
|
if (k2 === undefined) k2 = k;
|
|
@@ -41,6 +33,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
41
33
|
__setModuleDefault(result, mod);
|
|
42
34
|
return result;
|
|
43
35
|
};
|
|
36
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
|
+
var t = {};
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
39
|
+
t[p] = s[p];
|
|
40
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
41
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
42
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
43
|
+
t[p[i]] = s[p[i]];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
44
47
|
var __read = (this && this.__read) || function (o, n) {
|
|
45
48
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
46
49
|
if (!m) return o;
|
|
@@ -57,190 +60,40 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
57
60
|
}
|
|
58
61
|
return ar;
|
|
59
62
|
};
|
|
63
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
64
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
65
|
+
if (ar || !(i in from)) {
|
|
66
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
67
|
+
ar[i] = from[i];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
71
|
+
};
|
|
60
72
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
73
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
74
|
};
|
|
63
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
|
|
76
|
+
exports.RangeSliderKnob = exports.RangeSliderHighlight = exports.RangeSliderLabel = exports.RangeSliderGutter = void 0;
|
|
77
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
78
|
+
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
65
79
|
var react_1 = __importStar(require("react"));
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
isDraggingEndingKnob: false,
|
|
84
|
-
isReleasingEndingKnob: false,
|
|
85
|
-
};
|
|
86
|
-
return _this;
|
|
87
|
-
}
|
|
88
|
-
Object.defineProperty(RangeSlider.prototype, "rect", {
|
|
89
|
-
get: function () {
|
|
90
|
-
var _a;
|
|
91
|
-
return (_a = spase_1.Rect.from(this.nodeRefs.root.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
|
|
92
|
-
},
|
|
93
|
-
enumerable: false,
|
|
94
|
-
configurable: true
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(RangeSlider.prototype, "highlightLength", {
|
|
97
|
-
get: function () {
|
|
98
|
-
var _a = __read(this.state.range, 2), valA = _a[0], valB = _a[1];
|
|
99
|
-
var a = this.getDisplacementByValue(valA);
|
|
100
|
-
var b = this.getDisplacementByValue(valB);
|
|
101
|
-
return (b - a);
|
|
102
|
-
},
|
|
103
|
-
enumerable: false,
|
|
104
|
-
configurable: true
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(RangeSlider.prototype, "breakpoints", {
|
|
107
|
-
get: function () {
|
|
108
|
-
var _a = this.props, min = _a.min, max = _a.max, steps = _a.steps;
|
|
109
|
-
var breakpoints = [min];
|
|
110
|
-
for (var i = 0; i < steps; i++) {
|
|
111
|
-
breakpoints.push(min + (i + 1) * (max - min) / (1 + steps));
|
|
112
|
-
}
|
|
113
|
-
breakpoints.push(max);
|
|
114
|
-
return breakpoints;
|
|
115
|
-
},
|
|
116
|
-
enumerable: false,
|
|
117
|
-
configurable: true
|
|
118
|
-
});
|
|
119
|
-
RangeSlider.prototype.componentDidMount = function () {
|
|
120
|
-
this.reconfigureInteractivityIfNeeded();
|
|
121
|
-
if (this.props.steps < 0) {
|
|
122
|
-
this.props.onRangeChange(this.state.range);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
this.snapToClosestBreakpoint();
|
|
126
|
-
}
|
|
127
|
-
this.forceUpdate();
|
|
128
|
-
};
|
|
129
|
-
RangeSlider.prototype.componentDidUpdate = function (prevProps, prevState) {
|
|
130
|
-
if (!this.areRangesEqual(prevState.range, this.state.range)) {
|
|
131
|
-
this.props.onRangeChange(this.state.range);
|
|
132
|
-
}
|
|
133
|
-
if (prevProps.orientation !== this.props.orientation) {
|
|
134
|
-
this.forceUpdate();
|
|
135
|
-
}
|
|
136
|
-
this.reconfigureInteractivityIfNeeded();
|
|
137
|
-
};
|
|
138
|
-
RangeSlider.prototype.render = function () {
|
|
139
|
-
return (react_1.default.createElement(StyledRoot, { className: this.props.className, orientation: this.props.orientation, ref: this.nodeRefs.root, style: this.props.style },
|
|
140
|
-
react_1.default.createElement(StyledGutter, { extendedCSS: this.props.cssGutter }),
|
|
141
|
-
react_1.default.createElement(StyledKnob, { ref: this.nodeRefs.knobA, radius: this.props.knobRadius, tintColor: this.props.tintColor, hitboxPadding: this.props.hitboxPadding, isDragging: this.state.isDraggingStartingKnob, isReleasing: this.state.isReleasingStartingKnob, isDisabled: (this.state.range[1] === this.props.min) && (this.state.range[0] === this.props.min), style: this.props.orientation === 'horizontal' ? {
|
|
142
|
-
marginLeft: "".concat(this.getDisplacementByValue(this.state.range[0]), "px"),
|
|
143
|
-
} : {
|
|
144
|
-
marginTop: "".concat(this.getDisplacementByValue(this.state.range[0]), "px"),
|
|
145
|
-
}, extendedCSS: this.props.cssKnob }),
|
|
146
|
-
this.props.areLabelsVisible && (react_1.default.createElement(StyledLabel, { knobRadius: this.props.knobRadius, orientation: this.props.orientation, isDragging: this.state.isDraggingStartingKnob, isReleasing: this.state.isReleasingStartingKnob, style: this.props.orientation === 'horizontal' ? {
|
|
147
|
-
transform: "translate3d(calc(-50% + ".concat(this.getDisplacementByValue(this.state.range[0]), "px), 0, 0)"),
|
|
148
|
-
} : {
|
|
149
|
-
transform: "translate3d(0, calc(-50% + ".concat(this.getDisplacementByValue(this.state.range[0]), "px), 0)"),
|
|
150
|
-
}, extendedCSS: this.props.cssLabel }, Number(this.state.range[0].toFixed(this.props.decimalPlaces)).toLocaleString())),
|
|
151
|
-
react_1.default.createElement(StyledHighlight, { tintColor: this.props.tintColor, isDragging: this.state.isDraggingStartingKnob || this.state.isDraggingEndingKnob, isReleasing: this.state.isReleasingStartingKnob || this.state.isReleasingEndingKnob, style: this.props.orientation === 'horizontal' ? {
|
|
152
|
-
width: "".concat(this.highlightLength, "px"),
|
|
153
|
-
transform: "translate3d(".concat(this.getDisplacementByValue(this.state.range[0]), "px, 0, 0)"),
|
|
154
|
-
} : {
|
|
155
|
-
height: "".concat(this.highlightLength, "px"),
|
|
156
|
-
transform: "translate3d(0, ".concat(this.getDisplacementByValue(this.state.range[0]), "px, 0)"),
|
|
157
|
-
}, extendedCSS: this.props.cssHighlight }),
|
|
158
|
-
react_1.default.createElement(StyledKnob, { ref: this.nodeRefs.knobB, radius: this.props.knobRadius, tintColor: this.props.tintColor, hitboxPadding: this.props.hitboxPadding, isDragging: this.state.isDraggingEndingKnob, isReleasing: this.state.isReleasingEndingKnob, isDisabled: (this.state.range[1] === this.props.max) && (this.state.range[0] === this.props.max), style: this.props.orientation === 'horizontal' ? {
|
|
159
|
-
marginLeft: "".concat(this.getDisplacementByValue(this.state.range[1]), "px"),
|
|
160
|
-
} : {
|
|
161
|
-
marginTop: "".concat(this.getDisplacementByValue(this.state.range[1]), "px"),
|
|
162
|
-
}, extendedCSS: this.props.cssKnob }),
|
|
163
|
-
this.props.areLabelsVisible && (react_1.default.createElement(StyledLabel, { knobRadius: this.props.knobRadius, orientation: this.props.orientation, isDragging: this.state.isDraggingStartingKnob || this.state.isDraggingEndingKnob, isReleasing: this.state.isReleasingStartingKnob || this.state.isReleasingEndingKnob, style: this.props.orientation === 'horizontal' ? {
|
|
164
|
-
transform: "translate3d(calc(-50% + ".concat(this.getDisplacementByValue(this.state.range[1]), "px), 0, 0)"),
|
|
165
|
-
} : {
|
|
166
|
-
transform: "translate3d(0, calc(-50% + ".concat(this.getDisplacementByValue(this.state.range[1]), "px), 0)"),
|
|
167
|
-
}, extendedCSS: this.props.cssLabel }, Number(this.state.range[1].toFixed(this.props.decimalPlaces)).toLocaleString()))));
|
|
168
|
-
};
|
|
169
|
-
RangeSlider.prototype.reconfigureInteractivityIfNeeded = function () {
|
|
170
|
-
var _this = this;
|
|
171
|
-
var knobANode = this.nodeRefs.knobA.current;
|
|
172
|
-
var knobBNode = this.nodeRefs.knobB.current;
|
|
173
|
-
if (knobANode && !interactjs_1.default.isSet(knobANode)) {
|
|
174
|
-
(0, interactjs_1.default)(knobANode).draggable({
|
|
175
|
-
inertia: true,
|
|
176
|
-
onstart: function () { return _this.onKnobADragStart(); },
|
|
177
|
-
onmove: function (_a) {
|
|
178
|
-
var dx = _a.dx, dy = _a.dy;
|
|
179
|
-
return _this.onKnobADragMove(_this.props.orientation === 'horizontal' ? dx : dy);
|
|
180
|
-
},
|
|
181
|
-
onend: function () { return _this.onKnobADragEnd(); },
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (knobBNode && !interactjs_1.default.isSet(knobBNode)) {
|
|
185
|
-
(0, interactjs_1.default)(knobBNode).draggable({
|
|
186
|
-
inertia: true,
|
|
187
|
-
onstart: function () { return _this.onKnobBDragStart(); },
|
|
188
|
-
onmove: function (_a) {
|
|
189
|
-
var dx = _a.dx, dy = _a.dy;
|
|
190
|
-
return _this.onKnobBDragMove(_this.props.orientation === 'horizontal' ? dx : dy);
|
|
191
|
-
},
|
|
192
|
-
onend: function () { return _this.onKnobBDragEnd(); },
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
RangeSlider.prototype.snapToClosestBreakpoint = function () {
|
|
197
|
-
if (this.props.steps < 0)
|
|
198
|
-
return;
|
|
199
|
-
this.setState({
|
|
200
|
-
range: [this.getClosestSteppedValueOfValue(this.state.range[0]), this.getClosestSteppedValueOfValue(this.state.range[1])],
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
RangeSlider.prototype.areRangesEqual = function (range1, range2) {
|
|
204
|
-
if (!range1)
|
|
205
|
-
return false;
|
|
206
|
-
if (!range2)
|
|
207
|
-
return false;
|
|
208
|
-
if (range1[0] !== range2[0])
|
|
209
|
-
return false;
|
|
210
|
-
if (range1[1] !== range2[1])
|
|
211
|
-
return false;
|
|
212
|
-
return true;
|
|
213
|
-
};
|
|
214
|
-
RangeSlider.prototype.getPositionByValue = function (value) {
|
|
215
|
-
var _a = this.props, min = _a.min, max = _a.max;
|
|
216
|
-
return (value - min) / (max - min);
|
|
217
|
-
};
|
|
218
|
-
RangeSlider.prototype.getDisplacementByPosition = function (position) {
|
|
219
|
-
if (this.props.orientation === 'horizontal') {
|
|
220
|
-
return position * this.rect.width;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
return position * this.rect.height;
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
RangeSlider.prototype.getDisplacementByValue = function (value) {
|
|
227
|
-
var position = this.getPositionByValue(value);
|
|
228
|
-
return this.getDisplacementByPosition(position);
|
|
229
|
-
};
|
|
230
|
-
RangeSlider.prototype.getPositionByDisplacement = function (displacement) {
|
|
231
|
-
if (this.props.orientation === 'horizontal') {
|
|
232
|
-
return displacement / this.rect.width;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
return displacement / this.rect.height;
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
RangeSlider.prototype.getValueByPosition = function (position) {
|
|
239
|
-
var _a = this.props, min = _a.min, max = _a.max;
|
|
240
|
-
return (position * (max - min)) + min;
|
|
241
|
-
};
|
|
242
|
-
RangeSlider.prototype.getClosestSteppedValueOfValue = function (value) {
|
|
243
|
-
var breakpoints = this.breakpoints;
|
|
80
|
+
var useDragEffect_1 = __importDefault(require("./hooks/useDragEffect"));
|
|
81
|
+
var useResizeEffect_1 = __importDefault(require("./hooks/useResizeEffect"));
|
|
82
|
+
var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
|
|
83
|
+
var asComponentDict_1 = __importDefault(require("./utils/asComponentDict"));
|
|
84
|
+
var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
|
|
85
|
+
var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
|
|
86
|
+
var styles_1 = __importDefault(require("./utils/styles"));
|
|
87
|
+
exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
88
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
89
|
+
var children = _a.children, className = _a.className, _k = _a.areLabelsVisible, areLabelsVisible = _k === void 0 ? true : _k, _l = _a.decimalPlaces, decimalPlaces = _l === void 0 ? 2 : _l, _m = _a.knobPadding, knobPadding = _m === void 0 ? 20 : _m, maxValue = _a.max, minValue = _a.min, _o = _a.orientation, orientation = _o === void 0 ? 'vertical' : _o, externalRange = _a.range, _p = _a.steps, steps = _p === void 0 ? -1 : _p, onRangeChange = _a.onRangeChange, props = __rest(_a, ["children", "className", "areLabelsVisible", "decimalPlaces", "knobPadding", "max", "min", "orientation", "range", "steps", "onRangeChange"]);
|
|
90
|
+
var getPositionByValue = function (value) { return (value - minValue) / (maxValue - minValue); };
|
|
91
|
+
var getPositionByDisplacement = function (displacement) { return displacement / (orientation === 'horizontal' ? size.width : size.height); };
|
|
92
|
+
var getValueByPosition = function (position) { return position * (maxValue - minValue) + minValue; };
|
|
93
|
+
var getValueByDisplacement = function (displacement) { return getValueByPosition(getPositionByDisplacement(displacement)); };
|
|
94
|
+
var getDisplacementByPosition = function (position) { return position * (orientation === 'horizontal' ? size.width : size.height); };
|
|
95
|
+
var getDisplacementByValue = function (value) { return getDisplacementByPosition(getPositionByValue(value)); };
|
|
96
|
+
var getClosestSteppedValue = function (value) {
|
|
244
97
|
var n = breakpoints.length;
|
|
245
98
|
var idx = 0;
|
|
246
99
|
var diff = Infinity;
|
|
@@ -254,94 +107,227 @@ var RangeSlider = /** @class */ (function (_super) {
|
|
|
254
107
|
}
|
|
255
108
|
return breakpoints[idx];
|
|
256
109
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
110
|
+
var bodyRef = (0, react_1.useRef)(null);
|
|
111
|
+
var startKnobRef = (0, react_1.useRef)(null);
|
|
112
|
+
var endKnobRef = (0, react_1.useRef)(null);
|
|
113
|
+
var _q = __read((0, useResizeEffect_1.default)(bodyRef), 1), size = _q[0];
|
|
114
|
+
var _r = __read((0, react_1.useState)(externalRange !== null && externalRange !== void 0 ? externalRange : [minValue, maxValue]), 2), range = _r[0], setRange = _r[1];
|
|
115
|
+
var _s = (0, useDragEffect_1.default)(startKnobRef, {
|
|
116
|
+
initialValue: (_b = externalRange === null || externalRange === void 0 ? void 0 : externalRange[0]) !== null && _b !== void 0 ? _b : minValue,
|
|
117
|
+
transform: function (value, dx, dy) {
|
|
118
|
+
var delta = orientation === 'horizontal' ? dx : dy;
|
|
119
|
+
var dMin = getDisplacementByValue(minValue);
|
|
120
|
+
var dMax = getDisplacementByValue(range[1]);
|
|
121
|
+
var dCurr = getDisplacementByValue(value) + delta;
|
|
122
|
+
return getValueByDisplacement(Math.max(dMin, Math.min(dMax, dCurr)));
|
|
123
|
+
},
|
|
124
|
+
}, [minValue, orientation, size, range[1]]), _t = __read(_s.isDragging, 1), isDraggingStartKnob = _t[0], _u = __read(_s.isReleasing, 1), isReleasingStartKnob = _u[0], _v = __read(_s.value, 2), startValue = _v[0], setStartValue = _v[1];
|
|
125
|
+
var _w = (0, useDragEffect_1.default)(endKnobRef, {
|
|
126
|
+
initialValue: (_c = externalRange === null || externalRange === void 0 ? void 0 : externalRange[1]) !== null && _c !== void 0 ? _c : maxValue,
|
|
127
|
+
transform: function (value, dx, dy) {
|
|
128
|
+
var delta = orientation === 'horizontal' ? dx : dy;
|
|
129
|
+
var dMin = getDisplacementByValue(range[0]);
|
|
130
|
+
var dMax = getDisplacementByValue(maxValue);
|
|
131
|
+
var dCurr = getDisplacementByValue(value) + delta;
|
|
132
|
+
return getValueByDisplacement(Math.max(dMin, Math.min(dMax, dCurr)));
|
|
133
|
+
},
|
|
134
|
+
}, [maxValue, orientation, size, range[0]]), _x = __read(_w.isDragging, 1), isDraggingEndKnob = _x[0], _y = __read(_w.isReleasing, 1), isReleasingEndKnob = _y[0], _z = __read(_w.value, 2), endValue = _z[0], setEndValue = _z[1];
|
|
135
|
+
var breakpoints = __spreadArray(__spreadArray([minValue], __read(__spreadArray([], __read(Array(steps)), false).map(function (v, i) { return minValue + (i + 1) * (maxValue - minValue) / (1 + steps); })), false), [maxValue], false);
|
|
136
|
+
var _0 = __read(range.map(getDisplacementByValue), 2), start = _0[0], end = _0[1];
|
|
137
|
+
var highlightLength = end - start;
|
|
138
|
+
(0, react_1.useEffect)(function () {
|
|
139
|
+
if (range[0] === startValue)
|
|
140
|
+
return;
|
|
141
|
+
setRange([startValue, range[1]]);
|
|
142
|
+
onRangeChange === null || onRangeChange === void 0 ? void 0 : onRangeChange(range);
|
|
143
|
+
}, [startValue]);
|
|
144
|
+
(0, react_1.useEffect)(function () {
|
|
145
|
+
if (range[1] === endValue)
|
|
146
|
+
return;
|
|
147
|
+
setRange([range[0], endValue]);
|
|
148
|
+
onRangeChange === null || onRangeChange === void 0 ? void 0 : onRangeChange(range);
|
|
149
|
+
}, [endValue]);
|
|
150
|
+
(0, react_1.useEffect)(function () {
|
|
151
|
+
if (isDraggingStartKnob || isDraggingEndKnob || (0, fast_deep_equal_1.default)(externalRange, range))
|
|
152
|
+
return;
|
|
153
|
+
setRange(externalRange !== null && externalRange !== void 0 ? externalRange : [minValue, maxValue]);
|
|
154
|
+
}, [externalRange]);
|
|
155
|
+
(0, react_1.useEffect)(function () {
|
|
156
|
+
if (steps < 0)
|
|
157
|
+
return;
|
|
158
|
+
setStartValue(getClosestSteppedValue(startValue));
|
|
159
|
+
}, [isReleasingStartKnob]);
|
|
160
|
+
(0, react_1.useEffect)(function () {
|
|
161
|
+
if (steps < 0 || !isReleasingEndKnob)
|
|
162
|
+
return;
|
|
163
|
+
setEndValue(getClosestSteppedValue(endValue));
|
|
164
|
+
}, [isReleasingEndKnob]);
|
|
165
|
+
var components = (0, asComponentDict_1.default)(children, {
|
|
166
|
+
gutter: exports.RangeSliderGutter,
|
|
167
|
+
highlight: exports.RangeSliderHighlight,
|
|
168
|
+
knob: exports.RangeSliderKnob,
|
|
169
|
+
label: exports.RangeSliderLabel,
|
|
170
|
+
});
|
|
171
|
+
var fixedClassNames = (0, asClassNameDict_1.default)({
|
|
172
|
+
root: (0, classnames_1.default)(orientation),
|
|
173
|
+
gutter: (0, classnames_1.default)(orientation),
|
|
174
|
+
highlight: (0, classnames_1.default)(orientation),
|
|
175
|
+
knob: (0, classnames_1.default)(orientation),
|
|
176
|
+
label: (0, classnames_1.default)(orientation),
|
|
177
|
+
});
|
|
178
|
+
var fixedStyles = (0, asStyleDict_1.default)({
|
|
179
|
+
body: {
|
|
180
|
+
height: '100%',
|
|
181
|
+
width: '100%',
|
|
182
|
+
},
|
|
183
|
+
gutter: {
|
|
184
|
+
display: 'block',
|
|
185
|
+
top: '0',
|
|
186
|
+
left: '0',
|
|
187
|
+
position: 'absolute',
|
|
188
|
+
width: '100%',
|
|
189
|
+
height: '100%',
|
|
190
|
+
},
|
|
191
|
+
highlight: __assign({ height: '100%', left: '0', position: 'absolute', top: '0' }, orientation === 'horizontal' ? {
|
|
192
|
+
width: "".concat(highlightLength, "px"),
|
|
193
|
+
transform: "translate3d(".concat(start, "px, 0, 0)"),
|
|
194
|
+
} : {
|
|
195
|
+
height: "".concat(highlightLength, "px"),
|
|
196
|
+
transform: "translate3d(0, ".concat(start, "px, 0)"),
|
|
197
|
+
}),
|
|
198
|
+
knob: {
|
|
199
|
+
bottom: '0',
|
|
200
|
+
left: '0',
|
|
201
|
+
margin: 'auto',
|
|
202
|
+
position: 'absolute',
|
|
203
|
+
right: '0',
|
|
204
|
+
top: '0',
|
|
205
|
+
touchAction: 'none',
|
|
206
|
+
zIndex: '1',
|
|
207
|
+
},
|
|
208
|
+
knobHitbox: {
|
|
209
|
+
background: 'transparent',
|
|
210
|
+
height: "calc(100% + ".concat(knobPadding * 2, "px)"),
|
|
211
|
+
left: "-".concat(knobPadding, "px"),
|
|
212
|
+
padding: "".concat(knobPadding, "px"),
|
|
213
|
+
position: 'absolute',
|
|
214
|
+
top: "-".concat(knobPadding, "px"),
|
|
215
|
+
width: "calc(100% + ".concat(knobPadding * 2, "px)"),
|
|
216
|
+
},
|
|
217
|
+
label: {
|
|
218
|
+
pointerEvents: 'none',
|
|
219
|
+
position: 'relative',
|
|
220
|
+
userSelect: 'none',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
var defaultStyles = (0, asStyleDict_1.default)({
|
|
224
|
+
gutter: {
|
|
225
|
+
background: 'rgba(255, 255, 255, .2)',
|
|
226
|
+
},
|
|
227
|
+
highlight: {
|
|
228
|
+
background: '#fff',
|
|
229
|
+
transitionDuration: '100ms',
|
|
230
|
+
transitionProperty: (isReleasingStartKnob ? !isReleasingEndKnob : isReleasingEndKnob) ? 'opacity, width, transform' : 'opacity',
|
|
231
|
+
transitionTimingFunction: 'ease-out',
|
|
232
|
+
},
|
|
233
|
+
knob: {
|
|
234
|
+
alignItems: 'center',
|
|
235
|
+
background: '#fff',
|
|
236
|
+
borderRadius: '10px',
|
|
237
|
+
boxSizing: 'border-box',
|
|
238
|
+
display: 'flex',
|
|
239
|
+
height: '20px',
|
|
240
|
+
justifyContent: 'center',
|
|
241
|
+
transitionDuration: '100ms',
|
|
242
|
+
transitionTimingFunction: 'ease-out',
|
|
243
|
+
width: '20px',
|
|
244
|
+
},
|
|
245
|
+
label: __assign({ background: 'transparent', color: '#fff', textAlign: 'center', transitionDuration: '100ms', transitionTimingFunction: 'ease-out' }, orientation === 'horizontal' ? {
|
|
246
|
+
top: 'calc(100% + 10px)',
|
|
247
|
+
} : {
|
|
248
|
+
left: 'calc(100% + 10px)',
|
|
249
|
+
}),
|
|
250
|
+
});
|
|
251
|
+
return (react_1.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root) }),
|
|
252
|
+
react_1.default.createElement("div", { ref: bodyRef, style: fixedStyles.body },
|
|
253
|
+
(0, cloneStyledElement_1.default)((_d = components.gutter) !== null && _d !== void 0 ? _d : react_1.default.createElement(exports.RangeSliderGutter, { style: defaultStyles.gutter }), {
|
|
254
|
+
className: (0, classnames_1.default)(fixedClassNames.gutter),
|
|
255
|
+
style: (0, styles_1.default)(fixedStyles.gutter),
|
|
256
|
+
}),
|
|
257
|
+
(0, cloneStyledElement_1.default)((_e = components.highlight) !== null && _e !== void 0 ? _e : react_1.default.createElement(exports.RangeSliderHighlight, { style: defaultStyles.highlight }), {
|
|
258
|
+
className: (0, classnames_1.default)(fixedClassNames.highlight),
|
|
259
|
+
style: (0, styles_1.default)(fixedStyles.highlight),
|
|
260
|
+
}),
|
|
261
|
+
(0, cloneStyledElement_1.default)((_f = components.knob) !== null && _f !== void 0 ? _f : react_1.default.createElement(exports.RangeSliderKnob, { style: (0, styles_1.default)(defaultStyles.knob, {
|
|
262
|
+
transitionProperty: isReleasingStartKnob ? 'opacity, transform' : 'opacity',
|
|
263
|
+
}) }), {
|
|
264
|
+
ref: startKnobRef,
|
|
265
|
+
disabled: (0, fast_deep_equal_1.default)([startValue, endValue], [maxValue, maxValue]),
|
|
266
|
+
className: (0, classnames_1.default)(fixedClassNames.knob, {
|
|
267
|
+
dragging: isDraggingStartKnob,
|
|
268
|
+
releasing: isReleasingStartKnob,
|
|
269
|
+
}),
|
|
270
|
+
style: (0, styles_1.default)(fixedStyles.knob, {
|
|
271
|
+
pointerEvents: (0, fast_deep_equal_1.default)([startValue, endValue], [minValue, minValue]) ? 'none' : 'auto',
|
|
272
|
+
}, orientation === 'horizontal' ? {
|
|
273
|
+
marginLeft: "".concat(start, "px"),
|
|
274
|
+
} : {
|
|
275
|
+
marginTop: "".concat(start, "px"),
|
|
276
|
+
}),
|
|
277
|
+
}, react_1.default.createElement("div", { style: fixedStyles.knobHitbox }), areLabelsVisible &&
|
|
278
|
+
(0, cloneStyledElement_1.default)((_g = components.label) !== null && _g !== void 0 ? _g : react_1.default.createElement(exports.RangeSliderLabel, { style: (0, styles_1.default)(defaultStyles.label, {
|
|
279
|
+
transitionProperty: isReleasingStartKnob ? 'opacity, transform' : 'opacity',
|
|
280
|
+
}) }), {
|
|
281
|
+
className: (0, classnames_1.default)(fixedClassNames.label, {
|
|
282
|
+
dragging: isDraggingStartKnob || isDraggingEndKnob,
|
|
283
|
+
releasing: isReleasingStartKnob || isReleasingEndKnob,
|
|
284
|
+
}),
|
|
285
|
+
style: (0, styles_1.default)(fixedStyles.label),
|
|
286
|
+
}, Number(startValue.toFixed(decimalPlaces)).toLocaleString())),
|
|
287
|
+
(0, cloneStyledElement_1.default)((_h = components.knob) !== null && _h !== void 0 ? _h : react_1.default.createElement(exports.RangeSliderKnob, { style: (0, styles_1.default)(defaultStyles.knob, {
|
|
288
|
+
transitionProperty: isReleasingEndKnob ? 'opacity, transform' : 'opacity',
|
|
289
|
+
}) }), {
|
|
290
|
+
ref: endKnobRef,
|
|
291
|
+
disabled: (0, fast_deep_equal_1.default)([startValue, endValue], [maxValue, maxValue]),
|
|
292
|
+
className: (0, classnames_1.default)(fixedClassNames.knob, {
|
|
293
|
+
dragging: isDraggingEndKnob,
|
|
294
|
+
releasing: isDraggingEndKnob,
|
|
295
|
+
}),
|
|
296
|
+
style: (0, styles_1.default)(fixedStyles.knob, {
|
|
297
|
+
pointerEvents: (0, fast_deep_equal_1.default)([startValue, endValue], [maxValue, maxValue]) ? 'none' : 'auto',
|
|
298
|
+
}, orientation === 'horizontal' ? {
|
|
299
|
+
marginLeft: "".concat(end, "px"),
|
|
300
|
+
} : {
|
|
301
|
+
marginTop: "".concat(end, "px"),
|
|
302
|
+
}),
|
|
303
|
+
}, react_1.default.createElement("div", { style: fixedStyles.knobHitbox }), areLabelsVisible &&
|
|
304
|
+
(0, cloneStyledElement_1.default)((_j = components.label) !== null && _j !== void 0 ? _j : react_1.default.createElement(exports.RangeSliderLabel, { style: (0, styles_1.default)(defaultStyles.label, {
|
|
305
|
+
transitionProperty: isReleasingEndKnob ? 'opacity, transform' : 'opacity',
|
|
306
|
+
}) }), {
|
|
307
|
+
className: (0, classnames_1.default)(fixedClassNames.label, {
|
|
308
|
+
dragging: isDraggingEndKnob,
|
|
309
|
+
releasing: isReleasingEndKnob,
|
|
310
|
+
}),
|
|
311
|
+
style: (0, styles_1.default)(fixedStyles.label),
|
|
312
|
+
}, Number(endValue.toFixed(decimalPlaces)).toLocaleString())))));
|
|
313
|
+
});
|
|
314
|
+
var RangeSliderGutter = function (_a) {
|
|
315
|
+
var props = __rest(_a, []);
|
|
316
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
317
|
+
};
|
|
318
|
+
exports.RangeSliderGutter = RangeSliderGutter;
|
|
319
|
+
var RangeSliderLabel = function (_a) {
|
|
320
|
+
var props = __rest(_a, []);
|
|
321
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
322
|
+
};
|
|
323
|
+
exports.RangeSliderLabel = RangeSliderLabel;
|
|
324
|
+
var RangeSliderHighlight = function (_a) {
|
|
325
|
+
var props = __rest(_a, []);
|
|
326
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
327
|
+
};
|
|
328
|
+
exports.RangeSliderHighlight = RangeSliderHighlight;
|
|
329
|
+
exports.RangeSliderKnob = (0, react_1.forwardRef)(function (_a, ref) {
|
|
330
|
+
var props = __rest(_a, []);
|
|
331
|
+
return react_1.default.createElement("div", __assign({}, props, { ref: ref }));
|
|
332
|
+
});
|
|
347
333
|
//# sourceMappingURL=RangeSlider.js.map
|