@onepercentio/one-ui 0.19.4 → 0.19.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckBox/CheckBox.module.scss +3 -0
- package/dist/components/OrderableList/OrderableList.js +91 -39
- package/dist/components/OrderableList/OrderableList.module.scss +24 -3
- package/dist/components/Radio/Radio.module.scss +3 -1
- package/dist/hooks/useHero.d.ts +2 -0
- package/dist/hooks/useHero.js +1 -0
- package/package.json +2 -1
|
@@ -10,6 +10,7 @@ exports.useOrderableEvents = useOrderableEvents;
|
|
|
10
10
|
exports.useOrderableListAnchor = useOrderableListAnchor;
|
|
11
11
|
var _throttle = _interopRequireDefault(require("lodash/throttle"));
|
|
12
12
|
var _UncontrolledTransition = _interopRequireDefault(require("../UncontrolledTransition"));
|
|
13
|
+
var _TransitionModule = _interopRequireDefault(require("../Transition/Transition.module.scss"));
|
|
13
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
14
15
|
var _useHero2 = _interopRequireDefault(require("../../hooks/useHero"));
|
|
15
16
|
var _AnimatedEntrance = _interopRequireDefault(require("../AnimatedEntrance"));
|
|
@@ -87,7 +88,7 @@ function OrderableList(_ref) {
|
|
|
87
88
|
return ("currentOrder" in props ? props.currentOrder || _order : _order).filter(function (o) {
|
|
88
89
|
return o.includes(";") || availableKeys.includes(o);
|
|
89
90
|
});
|
|
90
|
-
}, [props.currentOrder, _order]);
|
|
91
|
+
}, [props.currentOrder, _order, availableKeys.join(";")]);
|
|
91
92
|
const cleanOrder = (0, _react.useMemo)(function () {
|
|
92
93
|
return order.map(function (a) {
|
|
93
94
|
return a.split(";")[0];
|
|
@@ -96,9 +97,13 @@ function OrderableList(_ref) {
|
|
|
96
97
|
const orderId = (0, _react.useMemo)(function () {
|
|
97
98
|
return "key-" + cleanOrder.join("");
|
|
98
99
|
}, [cleanOrder]);
|
|
100
|
+
function rootEl() {
|
|
101
|
+
if (mode === OrderableListReorderMode.TWO_DIMENSIONS) return rootRef.current.lastElementChild.lastElementChild;
|
|
102
|
+
return rootRef.current;
|
|
103
|
+
}
|
|
99
104
|
const findParentElement = function findParentElement(target) {
|
|
100
105
|
let parent = target;
|
|
101
|
-
while (parent.parentElement !==
|
|
106
|
+
while (parent.parentElement !== rootEl()) {
|
|
102
107
|
if (parent.parentElement === null) break;
|
|
103
108
|
parent = parent.parentElement;
|
|
104
109
|
}
|
|
@@ -106,7 +111,7 @@ function OrderableList(_ref) {
|
|
|
106
111
|
return parent;
|
|
107
112
|
};
|
|
108
113
|
(0, _react.useLayoutEffect)(function () {
|
|
109
|
-
if (shrinkToOnOrder)
|
|
114
|
+
if (shrinkToOnOrder) rootEl().style.setProperty("--shrink-to", "".concat(shrinkToOnOrder, "px"));
|
|
110
115
|
}, [shrinkToOnOrder]);
|
|
111
116
|
const calculateReordering = (0, _react.useMemo)(function () {
|
|
112
117
|
return (0, _throttle.default)(function (e, els, currentOrder) {
|
|
@@ -117,11 +122,31 @@ function OrderableList(_ref) {
|
|
|
117
122
|
const isDraggingOwnElement = currentWorkingKey.current === keyOfTheOverElement;
|
|
118
123
|
if (indexOfKeyInCleanOrder === -1 || keyOfTheOverElement === undefined) return;
|
|
119
124
|
if (!isDraggingOwnElement) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
const _ref2 = function () {
|
|
126
|
+
if (mode === OrderableListReorderMode.TWO_DIMENSIONS) {
|
|
127
|
+
const distanceFromLeft = e.offsetX;
|
|
128
|
+
const widthOfEl = parent.clientWidth;
|
|
129
|
+
const offset = widthOfEl * 0.25;
|
|
130
|
+
const isAfter = distanceFromLeft > widthOfEl - offset;
|
|
131
|
+
const isBefore = distanceFromLeft < offset;
|
|
132
|
+
return {
|
|
133
|
+
isAfter: isAfter,
|
|
134
|
+
isBefore: isBefore
|
|
135
|
+
};
|
|
136
|
+
} else {
|
|
137
|
+
const distanceFromTop = e.offsetY;
|
|
138
|
+
const heightOfEl = parent.clientHeight;
|
|
139
|
+
const offset = heightOfEl * 0.25;
|
|
140
|
+
const isAfter = distanceFromTop > heightOfEl - offset;
|
|
141
|
+
const isBefore = distanceFromTop < offset;
|
|
142
|
+
return {
|
|
143
|
+
isAfter: isAfter,
|
|
144
|
+
isBefore: isBefore
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}(),
|
|
148
|
+
isAfter = _ref2.isAfter,
|
|
149
|
+
isBefore = _ref2.isBefore;
|
|
125
150
|
const checkIfCanMove = function checkIfCanMove(keyOfOverElement) {
|
|
126
151
|
return keyOfOverElement === undefined || keyOfOverElement !== currentWorkingKey.current;
|
|
127
152
|
};
|
|
@@ -145,15 +170,29 @@ function OrderableList(_ref) {
|
|
|
145
170
|
}, 1000 / 60);
|
|
146
171
|
}, []);
|
|
147
172
|
(0, _react.useEffect)(function () {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
173
|
+
function registerListeners() {
|
|
174
|
+
const els = Array.from(rootEl().children);
|
|
175
|
+
const calculateReorderingCall = function calculateReorderingCall(e) {
|
|
176
|
+
const els = Array.from(rootEl().children);
|
|
177
|
+
calculateReordering(e, els, cleanOrder);
|
|
178
|
+
};
|
|
179
|
+
for (let el of els) el.addEventListener("mousemove", calculateReorderingCall);
|
|
180
|
+
return function () {
|
|
181
|
+
for (let el of els) el.removeEventListener("mousemove", calculateReorderingCall);
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (mode === OrderableListReorderMode.VERTICAL) {
|
|
185
|
+
return registerListeners();
|
|
186
|
+
} else {
|
|
187
|
+
let unsubscribe;
|
|
188
|
+
let timeout = setTimeout(function () {
|
|
189
|
+
unsubscribe = registerListeners();
|
|
190
|
+
}, 250);
|
|
191
|
+
return function () {
|
|
192
|
+
clearTimeout(timeout);
|
|
193
|
+
if (unsubscribe) unsubscribe();
|
|
194
|
+
};
|
|
195
|
+
}
|
|
157
196
|
}, [cleanOrder]);
|
|
158
197
|
(0, _react.useEffect)(function () {
|
|
159
198
|
if ("onChangeKeyOrder" in props) props.onChangeKeyOrder(cleanKeys(_order));
|
|
@@ -162,12 +201,12 @@ function OrderableList(_ref) {
|
|
|
162
201
|
(0, _react.useEffect)(function () {
|
|
163
202
|
cleanOrderRef.current = cleanOrder;
|
|
164
203
|
}, [cleanOrder]);
|
|
165
|
-
const onAnchorClick = (0, _react.useCallback)(function (
|
|
166
|
-
let anchor =
|
|
204
|
+
const onAnchorClick = (0, _react.useCallback)(function (_ref3) {
|
|
205
|
+
let anchor = _ref3.target;
|
|
167
206
|
let offset;
|
|
168
207
|
const orderableListItemForAnchor = findParentElement(anchor);
|
|
169
208
|
const box = orderableListItemForAnchor.getBoundingClientRect();
|
|
170
|
-
const els = Array.from(
|
|
209
|
+
const els = Array.from(rootEl().children);
|
|
171
210
|
const elIndex = els.indexOf(orderableListItemForAnchor);
|
|
172
211
|
const clone = orderableListItemForAnchor.cloneNode(true);
|
|
173
212
|
currentClone.current = clone;
|
|
@@ -186,12 +225,12 @@ function OrderableList(_ref) {
|
|
|
186
225
|
orderableListItemForAnchor.classList.add(_OrderableListModule.default.currentOrdering);
|
|
187
226
|
orderableListItemForAnchor.classList.remove(_OrderableListModule.default.visible);
|
|
188
227
|
const movementControl = function movementControl(e) {
|
|
189
|
-
const
|
|
228
|
+
const _ref4 = "touches" in e ? {
|
|
190
229
|
x: e.touches[0].pageX,
|
|
191
230
|
y: e.touches[0].pageY
|
|
192
231
|
} : e,
|
|
193
|
-
x1 =
|
|
194
|
-
y1 =
|
|
232
|
+
x1 = _ref4.x,
|
|
233
|
+
y1 = _ref4.y;
|
|
195
234
|
if (!offset) offset = [x1 - box.left, y1 - box.top];
|
|
196
235
|
const _offset = offset,
|
|
197
236
|
_offset2 = _slicedToArray(_offset, 2),
|
|
@@ -212,18 +251,18 @@ function OrderableList(_ref) {
|
|
|
212
251
|
{
|
|
213
252
|
let cleanUp = function cleanUp() {
|
|
214
253
|
if (shrinkToOnOrder) {
|
|
215
|
-
|
|
216
|
-
|
|
254
|
+
rootEl().style.removeProperty("padding-top");
|
|
255
|
+
rootEl().style.removeProperty("min-height");
|
|
217
256
|
}
|
|
218
257
|
eventEmitter.dispatcher("order-stop");
|
|
219
|
-
|
|
220
|
-
if (reorderingClassName)
|
|
258
|
+
rootEl().classList.remove(_OrderableListModule.default.ordering);
|
|
259
|
+
if (reorderingClassName) rootEl().classList.remove(reorderingClassName);
|
|
221
260
|
for (let el of els) el.classList.remove(_OrderableListModule.default.visible);
|
|
222
261
|
clone.remove();
|
|
223
262
|
currentClone.current = null;
|
|
224
263
|
for (let el of Array.from(elInvisible.children)) el.style.height = "";
|
|
225
264
|
};
|
|
226
|
-
const els = Array.from(
|
|
265
|
+
const els = Array.from(rootEl().children);
|
|
227
266
|
const elInvisible = els.find(function (a) {
|
|
228
267
|
return !a.classList.contains(_OrderableListModule.default.visible) && a.style.maxHeight !== "0px";
|
|
229
268
|
});
|
|
@@ -259,13 +298,13 @@ function OrderableList(_ref) {
|
|
|
259
298
|
const targetHeight = elIndex * shrinkToOnOrder;
|
|
260
299
|
const currentHeight = orderableListItemForAnchor.offsetTop - els[0].offsetTop;
|
|
261
300
|
const paddingTop = currentHeight - targetHeight;
|
|
262
|
-
|
|
263
|
-
|
|
301
|
+
rootEl().style.paddingTop = "".concat(paddingTop, "px");
|
|
302
|
+
rootEl().style.minHeight = "".concat(rootEl().clientHeight, "px");
|
|
264
303
|
}
|
|
265
304
|
orderableListItemForAnchor.style.visibility = "hidden";
|
|
266
305
|
orderableListItemForAnchor.classList.remove(_OrderableListModule.default.visible);
|
|
267
|
-
|
|
268
|
-
if (reorderingClassName)
|
|
306
|
+
rootEl().classList.add(_OrderableListModule.default.ordering);
|
|
307
|
+
if (reorderingClassName) rootEl().classList.add(reorderingClassName);
|
|
269
308
|
currentWorkingKey.current = cleanOrderRef.current[elIndex];
|
|
270
309
|
eventEmitter.dispatcher("order-start");
|
|
271
310
|
window.document.body.classList.add(_OrderableListModule.default.unselectable);
|
|
@@ -276,7 +315,7 @@ function OrderableList(_ref) {
|
|
|
276
315
|
}, []);
|
|
277
316
|
(0, _react.useLayoutEffect)(function () {
|
|
278
317
|
if (currentClone.current) {
|
|
279
|
-
const els = Array.from(
|
|
318
|
+
const els = Array.from(rootEl().children);
|
|
280
319
|
const elInvisible = els.find(function (a) {
|
|
281
320
|
return !a.classList.contains(_OrderableListModule.default.visible) && a.style.maxHeight !== "0px";
|
|
282
321
|
});
|
|
@@ -299,7 +338,7 @@ function OrderableList(_ref) {
|
|
|
299
338
|
});
|
|
300
339
|
});
|
|
301
340
|
(0, _react.useLayoutEffect)(function () {
|
|
302
|
-
|
|
341
|
+
rootEl().addEventListener("touchstart", function (e) {
|
|
303
342
|
const relatedAnchor = anchorsList.find(function (anchor) {
|
|
304
343
|
return anchor.contains(e.target);
|
|
305
344
|
});
|
|
@@ -309,7 +348,7 @@ function OrderableList(_ref) {
|
|
|
309
348
|
target: relatedAnchor
|
|
310
349
|
});
|
|
311
350
|
const moveCb = (0, _throttle.default)(function () {
|
|
312
|
-
const els = Array.from(
|
|
351
|
+
const els = Array.from(rootEl().children);
|
|
313
352
|
const currentElementIdx = els.findIndex(function (c) {
|
|
314
353
|
const rect = c === null || c === void 0 ? void 0 : c.getBoundingClientRect();
|
|
315
354
|
if (!rect) return false;
|
|
@@ -360,7 +399,17 @@ function OrderableList(_ref) {
|
|
|
360
399
|
className: "".concat(_OrderableListModule.default.root, " ").concat(className, " ").concat(shrinkToOnOrder ? _OrderableListModule.default.shrinkable : "")
|
|
361
400
|
}, toSpread), mode === OrderableListReorderMode.VERTICAL ? /*#__PURE__*/_react.default.createElement(_AnimatedEntrance.default, null, childrenToRender) : /*#__PURE__*/_react.default.createElement(_UncontrolledTransition.default, {
|
|
362
401
|
className: _OrderableListModule.default.transition,
|
|
363
|
-
transitionType: _Transition.TransitionAnimationTypes.
|
|
402
|
+
transitionType: _Transition.TransitionAnimationTypes.CUSTOM,
|
|
403
|
+
config: {
|
|
404
|
+
backward: {
|
|
405
|
+
elementEntering: "",
|
|
406
|
+
elementExiting: ""
|
|
407
|
+
},
|
|
408
|
+
forward: {
|
|
409
|
+
elementEntering: _OrderableListModule.default.stubEntering,
|
|
410
|
+
elementExiting: _TransitionModule.default.fadeOut
|
|
411
|
+
}
|
|
412
|
+
},
|
|
364
413
|
contentClassName: "".concat(className)
|
|
365
414
|
}, /*#__PURE__*/_react.default.createElement(_react.Fragment, {
|
|
366
415
|
key: orderId
|
|
@@ -375,15 +424,18 @@ function OrderableList(_ref) {
|
|
|
375
424
|
}, a);
|
|
376
425
|
})))));
|
|
377
426
|
}
|
|
378
|
-
function HeroWrapper(
|
|
379
|
-
let children =
|
|
380
|
-
id =
|
|
427
|
+
function HeroWrapper(_ref6) {
|
|
428
|
+
let children = _ref6.children,
|
|
429
|
+
id = _ref6.id;
|
|
381
430
|
const _useHero = (0, _useHero2.default)(id, undefined, {
|
|
382
431
|
onHeroStart: function onHeroStart(_c, _o, t) {
|
|
383
432
|
t.querySelectorAll("img").forEach(function (img) {
|
|
384
433
|
return img.style.visibility = "hidden";
|
|
385
434
|
});
|
|
386
435
|
},
|
|
436
|
+
onHeroCloned: function onHeroCloned() {
|
|
437
|
+
// if (!clone.classList.contains(Styles.visible)) clone.style.opacity = "0";
|
|
438
|
+
},
|
|
387
439
|
onHeroEnd: function onHeroEnd() {
|
|
388
440
|
if (heroRef.current) heroRef.current.querySelectorAll("img").forEach(function (img) {
|
|
389
441
|
return img.style.visibility = "";
|
|
@@ -64,14 +64,35 @@ $fast: var(--orderable-list--speed);
|
|
|
64
64
|
.transition {
|
|
65
65
|
width: 100%;
|
|
66
66
|
align-items: flex-start !important;
|
|
67
|
+
overflow: visible !important;
|
|
67
68
|
> * {
|
|
68
69
|
flex-direction: row !important;
|
|
69
70
|
flex-wrap: wrap;
|
|
70
|
-
&:first-child {
|
|
71
|
-
|
|
72
|
-
}
|
|
71
|
+
// &:first-child {
|
|
72
|
+
// visibility: hidden;
|
|
73
|
+
// }
|
|
73
74
|
&:last-child {
|
|
74
75
|
visibility: visible;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
|
|
80
|
+
div.stub {
|
|
81
|
+
animation-name: stub;
|
|
82
|
+
position: absolute;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
opacity: 0 !important;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
div.stubEntering {
|
|
88
|
+
animation-name: stub;
|
|
89
|
+
z-index: -1;
|
|
90
|
+
}
|
|
91
|
+
@keyframes stub {
|
|
92
|
+
0% {
|
|
93
|
+
opacity: 1;
|
|
94
|
+
}
|
|
95
|
+
100% {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
package/dist/hooks/useHero.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export default function useHero(id: string, options?: Partial<{
|
|
|
26
26
|
* Usefull for triggering secondary animations
|
|
27
27
|
*/
|
|
28
28
|
onHeroEnd?: () => void;
|
|
29
|
+
/** Do somethign with the clone before it goes to the html */
|
|
30
|
+
onHeroCloned?: (clone: HTMLDivElement) => void;
|
|
29
31
|
/**
|
|
30
32
|
* Do something when the hero starts the transition
|
|
31
33
|
* Here it's usefull to switch classNames with the target.
|
package/dist/hooks/useHero.js
CHANGED
|
@@ -93,6 +93,7 @@ function useHero(id) {
|
|
|
93
93
|
}
|
|
94
94
|
const oldClone = document.querySelector("[".concat(dataProperty, "-clone=\"").concat(ID(id), "\"]"));
|
|
95
95
|
const clone = oldClone || otherElement.cloneNode(true);
|
|
96
|
+
if (events.onHeroCloned && !oldClone) events.onHeroCloned(clone);
|
|
96
97
|
|
|
97
98
|
// Clean up thos properties that can cause confusion since it's a clone
|
|
98
99
|
clone.style.visibility = "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onepercentio/one-ui",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.6",
|
|
4
4
|
"description": "A set of reusable components created through the development of Onepercent projects",
|
|
5
5
|
"repository": "git@github.com:onepercentio/one-ui.git",
|
|
6
6
|
"author": "Murilo Oliveira de Araujo <murilo.araujo@onepercent.io>",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"kill-port": "^2.0.0",
|
|
80
80
|
"lodash": "^4.17.21",
|
|
81
81
|
"prerender-loader": "^1.3.0",
|
|
82
|
+
"react-dev-utils": "^12.0.1",
|
|
82
83
|
"sharp": "^0.30.3",
|
|
83
84
|
"webpack": "^5"
|
|
84
85
|
},
|