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.
Files changed (120) hide show
  1. package/README.md +1 -1
  2. package/lib/Accordion.d.ts +80 -71
  3. package/lib/Accordion.js +173 -183
  4. package/lib/Accordion.js.map +1 -1
  5. package/lib/BurgerButton.d.ts +20 -7
  6. package/lib/BurgerButton.js +113 -20
  7. package/lib/BurgerButton.js.map +1 -1
  8. package/lib/Conditional.d.ts +2 -3
  9. package/lib/Conditional.js +0 -1
  10. package/lib/Conditional.js.map +1 -1
  11. package/lib/DebugConsole.d.ts +14 -23
  12. package/lib/DebugConsole.js +86 -87
  13. package/lib/DebugConsole.js.map +1 -1
  14. package/lib/Dial.d.ts +53 -16
  15. package/lib/Dial.js +121 -35
  16. package/lib/Dial.js.map +1 -1
  17. package/lib/Dropdown.d.ts +68 -83
  18. package/lib/Dropdown.js +226 -161
  19. package/lib/Dropdown.js.map +1 -1
  20. package/lib/Each.d.ts +2 -2
  21. package/lib/Each.js.map +1 -1
  22. package/lib/ExtractChild.d.ts +5 -4
  23. package/lib/ExtractChild.js +13 -11
  24. package/lib/ExtractChild.js.map +1 -1
  25. package/lib/ExtractChildren.d.ts +2 -2
  26. package/lib/ExtractChildren.js +7 -5
  27. package/lib/ExtractChildren.js.map +1 -1
  28. package/lib/FlatSVG.d.ts +30 -25
  29. package/lib/FlatSVG.js +28 -37
  30. package/lib/FlatSVG.js.map +1 -1
  31. package/lib/List.d.ts +97 -54
  32. package/lib/List.js +124 -63
  33. package/lib/List.js.map +1 -1
  34. package/lib/MasonryGrid.d.ts +27 -15
  35. package/lib/MasonryGrid.js +163 -148
  36. package/lib/MasonryGrid.js.map +1 -1
  37. package/lib/Panorama.d.ts +100 -21
  38. package/lib/Panorama.js +45 -44
  39. package/lib/Panorama.js.map +1 -1
  40. package/lib/PanoramaSlider.d.ts +65 -23
  41. package/lib/PanoramaSlider.js +150 -45
  42. package/lib/PanoramaSlider.js.map +1 -1
  43. package/lib/RangeSlider.d.ts +29 -89
  44. package/lib/RangeSlider.js +272 -286
  45. package/lib/RangeSlider.js.map +1 -1
  46. package/lib/Repeat.d.ts +4 -3
  47. package/lib/Repeat.js +3 -2
  48. package/lib/Repeat.js.map +1 -1
  49. package/lib/RotatingGallery.d.ts +38 -36
  50. package/lib/RotatingGallery.js +47 -17
  51. package/lib/RotatingGallery.js.map +1 -1
  52. package/lib/SelectableButton.d.ts +13 -4
  53. package/lib/SelectableButton.js +3 -14
  54. package/lib/SelectableButton.js.map +1 -1
  55. package/lib/Slider.d.ts +103 -41
  56. package/lib/Slider.js +182 -82
  57. package/lib/Slider.js.map +1 -1
  58. package/lib/StepwiseSlider.d.ts +146 -59
  59. package/lib/StepwiseSlider.js +248 -142
  60. package/lib/StepwiseSlider.js.map +1 -1
  61. package/lib/SwipeContainer.d.ts +13 -5
  62. package/lib/SwipeContainer.js +5 -15
  63. package/lib/SwipeContainer.js.map +1 -1
  64. package/lib/TextField.d.ts +1 -1
  65. package/lib/TextField.js +5 -15
  66. package/lib/TextField.js.map +1 -1
  67. package/lib/Video.d.ts +30 -51
  68. package/lib/Video.js +77 -119
  69. package/lib/Video.js.map +1 -1
  70. package/lib/WithTooltip.d.ts +16 -18
  71. package/lib/WithTooltip.js +167 -101
  72. package/lib/WithTooltip.js.map +1 -1
  73. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  74. package/lib/hooks/useDocumentTitle.js +2 -1
  75. package/lib/hooks/useDocumentTitle.js.map +1 -1
  76. package/lib/hooks/useDragEffect.d.ts +25 -16
  77. package/lib/hooks/useDragEffect.js +30 -20
  78. package/lib/hooks/useDragEffect.js.map +1 -1
  79. package/lib/hooks/useElementRect.d.ts +2 -1
  80. package/lib/hooks/useElementRect.js +5 -4
  81. package/lib/hooks/useElementRect.js.map +1 -1
  82. package/lib/hooks/useInterval.d.ts +2 -2
  83. package/lib/hooks/useInterval.js +1 -1
  84. package/lib/hooks/useInterval.js.map +1 -1
  85. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  86. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  87. package/lib/hooks/usePrevious.d.ts +6 -0
  88. package/lib/hooks/usePrevious.js +17 -0
  89. package/lib/hooks/usePrevious.js.map +1 -0
  90. package/lib/hooks/useResizeEffect.d.ts +2 -2
  91. package/lib/hooks/useResizeEffect.js +5 -8
  92. package/lib/hooks/useResizeEffect.js.map +1 -1
  93. package/lib/hooks/useSearchParamState.d.ts +10 -7
  94. package/lib/hooks/useSearchParamState.js +14 -10
  95. package/lib/hooks/useSearchParamState.js.map +1 -1
  96. package/lib/utils/asClassNameDict.d.ts +3 -0
  97. package/lib/utils/asClassNameDict.js +7 -0
  98. package/lib/utils/asClassNameDict.js.map +1 -0
  99. package/lib/utils/asComponentDict.d.ts +5 -0
  100. package/lib/utils/asComponentDict.js +23 -0
  101. package/lib/utils/asComponentDict.js.map +1 -0
  102. package/lib/utils/asStyleDict.d.ts +4 -0
  103. package/lib/utils/asStyleDict.js +7 -0
  104. package/lib/utils/asStyleDict.js.map +1 -0
  105. package/lib/utils/cloneStyledElement.d.ts +18 -0
  106. package/lib/utils/cloneStyledElement.js +63 -0
  107. package/lib/utils/cloneStyledElement.js.map +1 -0
  108. package/lib/utils/styles.d.ts +2 -0
  109. package/lib/utils/styles.js +22 -0
  110. package/lib/utils/styles.js.map +1 -0
  111. package/lib/utils/useDebug.d.ts +2 -0
  112. package/lib/utils/useDebug.js +46 -0
  113. package/lib/utils/useDebug.js.map +1 -0
  114. package/package.json +25 -33
  115. package/lib/AbstractSelectableCollection.d.ts +0 -94
  116. package/lib/AbstractSelectableCollection.js +0 -151
  117. package/lib/AbstractSelectableCollection.js.map +0 -1
  118. package/lib/types/index.d.ts +0 -7
  119. package/lib/types/index.js +0 -3
  120. package/lib/types/index.js.map +0 -1
@@ -1,22 +1,14 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
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
- var interactjs_1 = __importDefault(require("interactjs"));
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 spase_1 = require("spase");
67
- var styled_components_1 = __importStar(require("styled-components"));
68
- var RangeSlider = /** @class */ (function (_super) {
69
- __extends(RangeSlider, _super);
70
- function RangeSlider(props) {
71
- var _this = this;
72
- var _a;
73
- _this = _super.call(this, props) || this;
74
- _this.nodeRefs = {
75
- root: (0, react_1.createRef)(),
76
- knobA: (0, react_1.createRef)(),
77
- knobB: (0, react_1.createRef)(),
78
- };
79
- _this.state = {
80
- range: (_a = props.defaultRange) !== null && _a !== void 0 ? _a : [props.min, props.max],
81
- isDraggingStartingKnob: false,
82
- isReleasingStartingKnob: false,
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
- RangeSlider.prototype.onKnobADragStart = function () {
258
- this.setState({
259
- isDraggingStartingKnob: true,
260
- isReleasingStartingKnob: false,
261
- isDraggingEndingKnob: false,
262
- isReleasingEndingKnob: false,
263
- });
264
- };
265
- RangeSlider.prototype.onKnobADragEnd = function () {
266
- this.setState({
267
- isDraggingStartingKnob: false,
268
- isReleasingStartingKnob: true,
269
- isDraggingEndingKnob: false,
270
- isReleasingEndingKnob: false,
271
- });
272
- this.snapToClosestBreakpoint();
273
- };
274
- RangeSlider.prototype.onKnobADragMove = function (delta) {
275
- var _a = __read(this.state.range, 2), valA = _a[0], valB = _a[1];
276
- var min = this.getDisplacementByValue(this.props.min);
277
- var max = this.getDisplacementByValue(valB);
278
- var curr = this.getDisplacementByValue(valA);
279
- var next = Math.max(min, Math.min(max, curr + delta));
280
- var nextPos = this.getPositionByDisplacement(next);
281
- var nextVal = this.getValueByPosition(nextPos);
282
- this.setState({
283
- isDraggingStartingKnob: true,
284
- isReleasingStartingKnob: false,
285
- isDraggingEndingKnob: false,
286
- isReleasingEndingKnob: false,
287
- range: [nextVal, valB],
288
- });
289
- };
290
- RangeSlider.prototype.onKnobBDragStart = function () {
291
- this.setState({
292
- isDraggingStartingKnob: false,
293
- isReleasingStartingKnob: false,
294
- isDraggingEndingKnob: true,
295
- isReleasingEndingKnob: false,
296
- });
297
- };
298
- RangeSlider.prototype.onKnobBDragEnd = function () {
299
- this.setState({
300
- isDraggingStartingKnob: false,
301
- isReleasingStartingKnob: false,
302
- isDraggingEndingKnob: false,
303
- isReleasingEndingKnob: true,
304
- });
305
- this.snapToClosestBreakpoint();
306
- };
307
- RangeSlider.prototype.onKnobBDragMove = function (delta) {
308
- var _a = __read(this.state.range, 2), valA = _a[0], valB = _a[1];
309
- var min = this.getDisplacementByValue(valA);
310
- var max = this.getDisplacementByValue(this.props.max);
311
- var curr = this.getDisplacementByValue(valB);
312
- var next = Math.max(min, Math.min(max, curr + delta));
313
- var nextPos = this.getPositionByDisplacement(next);
314
- var nextVal = this.getValueByPosition(nextPos);
315
- this.setState({
316
- isDraggingStartingKnob: false,
317
- isReleasingStartingKnob: false,
318
- isDraggingEndingKnob: true,
319
- isReleasingEndingKnob: false,
320
- range: [valA, nextVal],
321
- });
322
- };
323
- RangeSlider.defaultProps = {
324
- style: {},
325
- areLabelsVisible: true,
326
- decimalPlaces: 2,
327
- hitboxPadding: 20,
328
- knobRadius: 10,
329
- steps: -1,
330
- tintColor: '#fff',
331
- orientation: 'vertical',
332
- onRangeChange: function () { },
333
- cssGutter: function () { return (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""]))); },
334
- cssHighlight: function () { return (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject([""], [""]))); },
335
- cssKnob: function () { return (0, styled_components_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject([""], [""]))); },
336
- cssLabel: function () { return (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject([""], [""]))); },
337
- };
338
- return RangeSlider;
339
- }(react_1.PureComponent));
340
- exports.default = RangeSlider;
341
- var StyledHighlight = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n top: 0;\n left: 0;\n position: absolute;\n height: 100%;\n width: 100%;\n background: ", ";\n transition-property: ", ";\n transition-duration: 100ms;\n transition-timing-function: ease-out;\n will-change: opacity, width, transform;\n ", "\n"], ["\n top: 0;\n left: 0;\n position: absolute;\n height: 100%;\n width: 100%;\n background: ", ";\n transition-property: ", ";\n transition-duration: 100ms;\n transition-timing-function: ease-out;\n will-change: opacity, width, transform;\n ", "\n"])), function (props) { return props.tintColor; }, function (props) { return props.isReleasing ? 'opacity, width, transform' : 'opacity'; }, function (props) { return props.extendedCSS(props); });
342
- var StyledLabel = styled_components_1.default.span(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n background: transparent;\n color: #fff;\n left: ", ";\n padding: 10px;\n pointer-events: none;\n position: absolute;\n text-align: center;\n top: ", ";\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n user-select: none;\n will-change: opacity, transform;\n ", "\n"], ["\n background: transparent;\n color: #fff;\n left: ", ";\n padding: 10px;\n pointer-events: none;\n position: absolute;\n text-align: center;\n top: ", ";\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n user-select: none;\n will-change: opacity, transform;\n ", "\n"])), function (props) { return props.orientation === 'horizontal' ? '0' : "".concat(props.knobRadius, "px"); }, function (props) { return props.orientation === 'horizontal' ? "".concat(props.knobRadius, "px") : '0'; }, function (props) { return props.isReleasing ? 'opacity, transform' : 'opacity'; }, function (props) { return props.extendedCSS(props); });
343
- var StyledKnob = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n background: transparent;\n box-sizing: border-box;\n display: block;\n height: ", "px;\n left: ", "px;\n padding: ", "px;\n pointer-events: ", ";\n position: absolute;\n top: ", "px;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n width: ", "px;\n will-change: opacity, transform, margin, background;\n z-index: 1;\n\n &::after {\n content: '';\n border-radius: 100%;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n width: ", "px;\n height: ", "px;\n background: ", ";\n }\n\n ", "\n"], ["\n background: transparent;\n box-sizing: border-box;\n display: block;\n height: ", "px;\n left: ", "px;\n padding: ", "px;\n pointer-events: ", ";\n position: absolute;\n top: ", "px;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n width: ", "px;\n will-change: opacity, transform, margin, background;\n z-index: 1;\n\n &::after {\n content: '';\n border-radius: 100%;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n margin: auto;\n position: absolute;\n width: ", "px;\n height: ", "px;\n background: ", ";\n }\n\n ", "\n"])), function (props) { return (props.radius + props.hitboxPadding) * 2; }, function (props) { return -props.radius - props.hitboxPadding; }, function (props) { return props.hitboxPadding; }, function (props) { return props.isDisabled ? 'none' : 'auto'; }, function (props) { return -props.radius - props.hitboxPadding; }, function (props) { return props.isReleasing ? 'background, opacity, margin, transform' : 'background, opacity, transform'; }, function (props) { return (props.radius + props.hitboxPadding) * 2; }, function (props) { return props.radius * 2; }, function (props) { return props.radius * 2; }, function (props) { return props.tintColor; }, function (props) { return props.extendedCSS(props); });
344
- var StyledGutter = styled_components_1.default.div(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n display: block;\n top: 0;\n left: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n background: rgba(255, 255, 255, .2);\n ", "\n"], ["\n display: block;\n top: 0;\n left: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n background: rgba(255, 255, 255, .2);\n ", "\n"])), function (props) { return props.extendedCSS(props); });
345
- var StyledRoot = styled_components_1.default.div(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n display: flex;\n flex: 0 0 auto;\n height: ", ";\n position: relative;\n width: ", ";\n"], ["\n display: flex;\n flex: 0 0 auto;\n height: ", ";\n position: relative;\n width: ", ";\n"])), function (props) { return props.orientation === 'horizontal' ? '2px' : '300px'; }, function (props) { return props.orientation === 'horizontal' ? '300px' : '2px'; });
346
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
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