funda-ui 1.0.580 → 1.0.605

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.
@@ -12,52 +12,91 @@ return /******/ (() => { // webpackBootstrap
12
12
  /******/ var __webpack_modules__ = ({
13
13
 
14
14
  /***/ 710:
15
- /***/ ((module) => {
15
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
16
16
 
17
17
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
18
+ var _require = __webpack_require__(711),
19
+ easeLinear = _require.easeLinear,
20
+ easeInQuad = _require.easeInQuad,
21
+ easeOutQuad = _require.easeOutQuad,
22
+ easeInOutQuad = _require.easeInOutQuad;
23
+
18
24
  /**
19
25
  * Element Animate
20
26
  * @public
21
27
  *
22
28
  * @param {HTMLElement} curElement - Element of animation.
23
29
  * @param {?JSON} config - Configuration of animation
30
+ * @param {?string} easeType - Types of easing animation.
31
+ * @param {?Function} callback - Callback after animation ends
24
32
  */
25
33
  function animateStyles(curElement, config) {
34
+ var easeType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'linear';
35
+ var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
26
36
  if (_typeof(curElement) === ( true ? "undefined" : 0)) return;
27
37
 
28
38
  // Set a default configuration
29
39
  config = setDefaultOptions({
30
40
  "startHeight": 0,
41
+ // node.scrollHeight
31
42
  "endHeight": 0,
32
- "speed": 200,
33
- //ms
34
- "fps": 1000 / 60 // 60FPS
43
+ "speed": 200 //ms
35
44
  }, config);
36
45
 
37
46
  //
38
47
  var _endHeight = config.endHeight,
39
- _speed = config.speed,
40
- _fps = config.fps;
48
+ _speed = config.speed;
41
49
  var _startHeight = config.startHeight;
42
- var timer = null;
43
- var startTime = Date.now();
44
- var deltaHeight = curElement.clientHeight < _endHeight ? _endHeight / _speed * _fps : _startHeight / _speed * _fps;
45
- timer = setInterval(function () {
46
- var elapsed = Date.now() - startTime; //Work out the elapsed time
50
+ var duration = _speed;
51
+ var start = new Date().getTime();
52
+ var from = 0;
53
+ var to = 100;
54
+ var requestId;
55
+ var loop = function loop() {
56
+ //easing
57
+ var time = new Date().getTime() - start; //Work out the elapsed time
58
+ var val;
59
+ switch (easeType) {
60
+ case "linear":
61
+ val = easeLinear(time, from, to - from, duration);
62
+ break;
63
+ case "ease-in":
64
+ val = easeInQuad(time, from, to - from, duration);
65
+ break;
66
+ case "ease-out":
67
+ val = easeOutQuad(time, from, to - from, duration);
68
+ break;
69
+ case "ease-in-out":
70
+ val = easeInOutQuad(time, from, to - from, duration);
71
+ break;
72
+ default:
73
+ val = easeLinear(time, from, to - from, duration);
74
+ }
75
+
76
+ // Elapsed time in miliseconds
77
+ var percent = val / 100;
78
+
79
+ // change height
80
+ if (curElement.clientHeight < _endHeight) {
81
+ curElement.style.height = _endHeight * percent + 'px';
82
+ } else {
83
+ if (_startHeight > 0) curElement.style.height = _startHeight - _startHeight * percent + 'px';
84
+ }
47
85
 
48
86
  //If the elapsed time is less than the speed (ms)
49
- if (elapsed < _speed) {
50
- if (curElement.clientHeight < _endHeight) {
51
- _startHeight = _startHeight + deltaHeight;
52
- } else {
53
- _startHeight = _startHeight - deltaHeight;
54
- }
55
- curElement.style.height = _startHeight + 'px';
87
+ if (time < duration) {
88
+ //
89
+ requestId = window.requestAnimationFrame(loop);
56
90
  } else {
91
+ // change height
57
92
  curElement.style.height = _endHeight + 'px';
58
- clearInterval(timer);
93
+ if (typeof callback === 'function') callback();
94
+
95
+ //
96
+ window.cancelAnimationFrame(requestId);
59
97
  }
60
- }, _fps);
98
+ };
99
+ requestId = window.requestAnimationFrame(loop);
61
100
  }
62
101
 
63
102
  /**
@@ -137,6 +176,178 @@ module.exports = animateStyles;
137
176
 
138
177
  /***/ }),
139
178
 
179
+ /***/ 711:
180
+ /***/ ((module) => {
181
+
182
+ /*
183
+ * All easing functions
184
+ * @link: https://easings.net
185
+ * @param {Number} t - time (Amount of time that has passed since the beginning of the animation. Usually starts at 0 and is slowly increased using a game loop or other update function.)
186
+ * @param {Number} b - beginning value (The starting point of the animation. Usually it's a static value, you can start at 0 for example.)
187
+ * @param {Number} c - change in value (The amount of change needed to go from starting point to end point. It's also usually a static value.)
188
+ * @param {Number} d - duration (Amount of time the animation will take. Usually a static value aswell.)
189
+ * @return {Number}
190
+ */
191
+ function easeLinear(t, b, c, d) {
192
+ return c * t / d + b;
193
+ }
194
+ function easeInQuad(t, b, c, d) {
195
+ return c * (t /= d) * t + b;
196
+ }
197
+ function easeOutQuad(t, b, c, d) {
198
+ return -c * (t /= d) * (t - 2) + b;
199
+ }
200
+ function easeInOutQuad(t, b, c, d) {
201
+ if ((t /= d / 2) < 1) return c / 2 * t * t + b;
202
+ return -c / 2 * (--t * (t - 2) - 1) + b;
203
+ }
204
+ function easeInSine(t, b, c, d) {
205
+ return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
206
+ }
207
+ function easeOutSine(t, b, c, d) {
208
+ return c * Math.sin(t / d * (Math.PI / 2)) + b;
209
+ }
210
+ function easeInOutSine(t, b, c, d) {
211
+ return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
212
+ }
213
+ function easeInExpo(t, b, c, d) {
214
+ return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
215
+ }
216
+ function easeOutExpo(t, b, c, d) {
217
+ return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
218
+ }
219
+ function easeInOutExpo(t, b, c, d) {
220
+ if (t == 0) return b;
221
+ if (t == d) return b + c;
222
+ if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
223
+ return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
224
+ }
225
+ function easeInCirc(t, b, c, d) {
226
+ return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
227
+ }
228
+ function easeOutCirc(t, b, c, d) {
229
+ return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
230
+ }
231
+ function easeInOutCirc(t, b, c, d) {
232
+ if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
233
+ return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
234
+ }
235
+ function easeInCubic(t, b, c, d) {
236
+ return c * (t /= d) * t * t + b;
237
+ }
238
+ function easeOutCubic(t, b, c, d) {
239
+ return c * ((t = t / d - 1) * t * t + 1) + b;
240
+ }
241
+ function easeInOutCubic(t, b, c, d) {
242
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
243
+ return c / 2 * ((t -= 2) * t * t + 2) + b;
244
+ }
245
+ function easeInQuart(t, b, c, d) {
246
+ return c * (t /= d) * t * t * t + b;
247
+ }
248
+ function easeOutQuart(t, b, c, d) {
249
+ return -c * ((t = t / d - 1) * t * t * t - 1) + b;
250
+ }
251
+ function easeInOutQuart(t, b, c, d) {
252
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
253
+ return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
254
+ }
255
+ function easeInQuint(t, b, c, d) {
256
+ return c * (t /= d) * t * t * t * t + b;
257
+ }
258
+ function easeOutQuint(t, b, c, d) {
259
+ return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
260
+ }
261
+ function easeInOutQuint(t, b, c, d) {
262
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
263
+ return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
264
+ }
265
+ function easeInElastic(t, b, c, d) {
266
+ var s = 1.70158;
267
+ var p = 0;
268
+ var a = c;
269
+ if (t == 0) return b;
270
+ if ((t /= d) == 1) return b + c;
271
+ if (!p) p = d * .3;
272
+ if (a < Math.abs(c)) {
273
+ a = c;
274
+ var s = p / 4;
275
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
276
+ return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
277
+ }
278
+ function easeOutElastic(t, b, c, d) {
279
+ var s = 1.70158;
280
+ var p = 0;
281
+ var a = c;
282
+ if (t == 0) return b;
283
+ if ((t /= d) == 1) return b + c;
284
+ if (!p) p = d * .3;
285
+ if (a < Math.abs(c)) {
286
+ a = c;
287
+ var s = p / 4;
288
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
289
+ return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
290
+ }
291
+ function easeInOutElastic(t, b, c, d) {
292
+ var s = 1.70158;
293
+ var p = 0;
294
+ var a = c;
295
+ if (t == 0) return b;
296
+ if ((t /= d / 2) == 2) return b + c;
297
+ if (!p) p = d * (.3 * 1.5);
298
+ if (a < Math.abs(c)) {
299
+ a = c;
300
+ var s = p / 4;
301
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
302
+ if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
303
+ return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
304
+ }
305
+ function easeInBack(t, b, c, d) {
306
+ if (s == undefined) s = 1.70158;
307
+ return c * (t /= d) * t * ((s + 1) * t - s) + b;
308
+ }
309
+ function easeOutBack(t, b, c, d) {
310
+ if (s == undefined) s = 1.70158;
311
+ return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
312
+ }
313
+ function easeInOutBack(t, b, c, d) {
314
+ if (s == undefined) s = 1.70158;
315
+ if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
316
+ return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
317
+ }
318
+ module.exports = {
319
+ easeLinear: easeLinear,
320
+ easeInQuad: easeInQuad,
321
+ easeOutQuad: easeOutQuad,
322
+ easeInOutQuad: easeInOutQuad,
323
+ easeInSine: easeInSine,
324
+ easeOutSine: easeOutSine,
325
+ easeInOutSine: easeInOutSine,
326
+ easeInExpo: easeInExpo,
327
+ easeOutExpo: easeOutExpo,
328
+ easeInOutExpo: easeInOutExpo,
329
+ easeInCirc: easeInCirc,
330
+ easeOutCirc: easeOutCirc,
331
+ easeInOutCirc: easeInOutCirc,
332
+ easeInCubic: easeInCubic,
333
+ easeOutCubic: easeOutCubic,
334
+ easeInOutCubic: easeInOutCubic,
335
+ easeInQuart: easeInQuart,
336
+ easeOutQuart: easeOutQuart,
337
+ easeInOutQuart: easeInOutQuart,
338
+ easeInQuint: easeInQuint,
339
+ easeOutQuint: easeOutQuint,
340
+ easeInOutQuint: easeInOutQuint,
341
+ easeInElastic: easeInElastic,
342
+ easeOutElastic: easeOutElastic,
343
+ easeInOutElastic: easeInOutElastic,
344
+ easeInBack: easeInBack,
345
+ easeOutBack: easeOutBack,
346
+ easeInOutBack: easeInOutBack
347
+ };
348
+
349
+ /***/ }),
350
+
140
351
  /***/ 787:
141
352
  /***/ ((module) => {
142
353
 
@@ -232,7 +443,8 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
232
443
  ;// CONCATENATED MODULE: ./src/AccordionItem.tsx
233
444
 
234
445
  var AccordionItem = function AccordionItem(props) {
235
- var index = props.index,
446
+ var heightObserver = props.heightObserver,
447
+ index = props.index,
236
448
  itemClassName = props.itemClassName,
237
449
  itemContentWrapperClassName = props.itemContentWrapperClassName,
238
450
  itemContentClassName = props.itemContentClassName,
@@ -247,6 +459,27 @@ var AccordionItem = function AccordionItem(props) {
247
459
  triggerType = props.triggerType,
248
460
  children = props.children;
249
461
  var activedClassName = typeof defaultActive !== 'undefined' && defaultActive !== false ? ' active' : '';
462
+ var observer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
463
+ var contentWrapperRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
464
+ var contentRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
465
+ (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
466
+ if (parseFloat(heightObserver) !== index) return;
467
+
468
+ // When the content height changes dynamically, change the height of the wrapper
469
+ if (contentRef.current && contentWrapperRef.current) {
470
+ var _contentPadding = window.getComputedStyle(contentRef.current).getPropertyValue('padding-bottom');
471
+ observer.current = new ResizeObserver(function (entries) {
472
+ entries.forEach(function (entry) {
473
+ contentWrapperRef.current.style.height = entry.contentRect.bottom + parseFloat(_contentPadding) + 'px';
474
+ });
475
+ });
476
+ observer.current.observe(contentRef.current);
477
+ }
478
+ return function () {
479
+ var _observer$current;
480
+ if (contentRef.current) (_observer$current = observer.current) === null || _observer$current === void 0 ? void 0 : _observer$current.unobserve(contentRef.current);
481
+ };
482
+ }, [heightObserver]);
250
483
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
251
484
  "data-index": index,
252
485
  className: "custom-accordion-item ".concat(itemClassName || itemClassName === '' ? itemClassName : "accordion-item", " ").concat(activedClassName),
@@ -263,6 +496,7 @@ var AccordionItem = function AccordionItem(props) {
263
496
  className: "custom-accordion-trigger ".concat(itemTriggerClassName || itemTriggerClassName === '' ? itemTriggerClassName : "accordion-button", " ").concat(activedClassName === '' ? 'collapsed' : 'active'),
264
497
  type: "button"
265
498
  }, title), itemTriggerIcon), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
499
+ ref: contentWrapperRef,
266
500
  className: "custom-accordion-content__wrapper ".concat(itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"),
267
501
  role: "tabpanel",
268
502
  style: {
@@ -270,7 +504,8 @@ var AccordionItem = function AccordionItem(props) {
270
504
  overflow: 'hidden'
271
505
  }
272
506
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
273
- className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body")
507
+ className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"),
508
+ ref: contentRef
274
509
  }, children))));
275
510
  };
276
511
  /* harmony default export */ const src_AccordionItem = (AccordionItem);
@@ -294,24 +529,41 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
294
529
 
295
530
 
296
531
 
532
+
533
+ // Adapt the easing parameters of TweenMax
534
+ var EasingList = /*#__PURE__*/function (EasingList) {
535
+ EasingList["linear"] = "linear";
536
+ EasingList["easeIn"] = "ease-in";
537
+ EasingList["easeOut"] = "ease-out";
538
+ EasingList["easeInOut"] = "ease-in-out";
539
+ return EasingList;
540
+ }(EasingList || {});
297
541
  var Accordion = function Accordion(props) {
298
542
  var wrapperClassName = props.wrapperClassName,
299
543
  triggerType = props.triggerType,
300
544
  displayTheFirstItem = props.displayTheFirstItem,
545
+ displayAllItems = props.displayAllItems,
301
546
  duration = props.duration,
547
+ easing = props.easing,
302
548
  alternateCollapse = props.alternateCollapse,
303
549
  onChange = props.onChange,
304
550
  children = props.children;
551
+ var easeType = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing];
305
552
  var ALTER = typeof alternateCollapse === 'undefined' ? true : alternateCollapse;
306
553
  var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
307
554
  var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
308
555
  _useState2 = _slicedToArray(_useState, 2),
309
556
  animOK = _useState2[0],
310
557
  setAnimOK = _useState2[1];
558
+ var _useState3 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(-1),
559
+ _useState4 = _slicedToArray(_useState3, 2),
560
+ heightObserver = _useState4[0],
561
+ setHeightObserver = _useState4[1];
311
562
  function handleClickItem(e) {
312
563
  e.preventDefault();
313
564
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
314
565
  e.stopPropagation();
566
+ if (e.target.closest('.custom-accordion-header') === null) return;
315
567
  if (animOK) return;
316
568
 
317
569
  //
@@ -336,7 +588,7 @@ var Accordion = function Accordion(props) {
336
588
  startHeight: node.scrollHeight,
337
589
  endHeight: 0,
338
590
  speed: animSpeed
339
- });
591
+ }, easeType);
340
592
  }
341
593
  });
342
594
 
@@ -358,6 +610,9 @@ var Accordion = function Accordion(props) {
358
610
  startHeight: 0,
359
611
  endHeight: $curContent.scrollHeight,
360
612
  speed: animSpeed
613
+ }, easeType, function () {
614
+ // content height observer
615
+ setHeightObserver(curIndex);
361
616
  });
362
617
  } else {
363
618
  if (e.type == 'click') {
@@ -371,7 +626,7 @@ var Accordion = function Accordion(props) {
371
626
  startHeight: $curContent.scrollHeight,
372
627
  endHeight: 0,
373
628
  speed: animSpeed
374
- });
629
+ }, easeType);
375
630
  }
376
631
  }
377
632
  if (typeof onChange === 'function') {
@@ -388,7 +643,8 @@ var Accordion = function Accordion(props) {
388
643
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, _extends({
389
644
  key: "item" + i,
390
645
  index: i,
391
- defaultActive: _defaultActive,
646
+ heightObserver: heightObserver,
647
+ defaultActive: typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems,
392
648
  triggerType: triggerType || 'click',
393
649
  onToggleEv: handleClickItem
394
650
  }, childProps));
@@ -12,52 +12,91 @@ return /******/ (() => { // webpackBootstrap
12
12
  /******/ var __webpack_modules__ = ({
13
13
 
14
14
  /***/ 710:
15
- /***/ ((module) => {
15
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
16
16
 
17
17
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
18
+ var _require = __webpack_require__(711),
19
+ easeLinear = _require.easeLinear,
20
+ easeInQuad = _require.easeInQuad,
21
+ easeOutQuad = _require.easeOutQuad,
22
+ easeInOutQuad = _require.easeInOutQuad;
23
+
18
24
  /**
19
25
  * Element Animate
20
26
  * @public
21
27
  *
22
28
  * @param {HTMLElement} curElement - Element of animation.
23
29
  * @param {?JSON} config - Configuration of animation
30
+ * @param {?string} easeType - Types of easing animation.
31
+ * @param {?Function} callback - Callback after animation ends
24
32
  */
25
33
  function animateStyles(curElement, config) {
34
+ var easeType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'linear';
35
+ var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
26
36
  if (_typeof(curElement) === ( true ? "undefined" : 0)) return;
27
37
 
28
38
  // Set a default configuration
29
39
  config = setDefaultOptions({
30
40
  "startHeight": 0,
41
+ // node.scrollHeight
31
42
  "endHeight": 0,
32
- "speed": 200,
33
- //ms
34
- "fps": 1000 / 60 // 60FPS
43
+ "speed": 200 //ms
35
44
  }, config);
36
45
 
37
46
  //
38
47
  var _endHeight = config.endHeight,
39
- _speed = config.speed,
40
- _fps = config.fps;
48
+ _speed = config.speed;
41
49
  var _startHeight = config.startHeight;
42
- var timer = null;
43
- var startTime = Date.now();
44
- var deltaHeight = curElement.clientHeight < _endHeight ? _endHeight / _speed * _fps : _startHeight / _speed * _fps;
45
- timer = setInterval(function () {
46
- var elapsed = Date.now() - startTime; //Work out the elapsed time
50
+ var duration = _speed;
51
+ var start = new Date().getTime();
52
+ var from = 0;
53
+ var to = 100;
54
+ var requestId;
55
+ var loop = function loop() {
56
+ //easing
57
+ var time = new Date().getTime() - start; //Work out the elapsed time
58
+ var val;
59
+ switch (easeType) {
60
+ case "linear":
61
+ val = easeLinear(time, from, to - from, duration);
62
+ break;
63
+ case "ease-in":
64
+ val = easeInQuad(time, from, to - from, duration);
65
+ break;
66
+ case "ease-out":
67
+ val = easeOutQuad(time, from, to - from, duration);
68
+ break;
69
+ case "ease-in-out":
70
+ val = easeInOutQuad(time, from, to - from, duration);
71
+ break;
72
+ default:
73
+ val = easeLinear(time, from, to - from, duration);
74
+ }
75
+
76
+ // Elapsed time in miliseconds
77
+ var percent = val / 100;
78
+
79
+ // change height
80
+ if (curElement.clientHeight < _endHeight) {
81
+ curElement.style.height = _endHeight * percent + 'px';
82
+ } else {
83
+ if (_startHeight > 0) curElement.style.height = _startHeight - _startHeight * percent + 'px';
84
+ }
47
85
 
48
86
  //If the elapsed time is less than the speed (ms)
49
- if (elapsed < _speed) {
50
- if (curElement.clientHeight < _endHeight) {
51
- _startHeight = _startHeight + deltaHeight;
52
- } else {
53
- _startHeight = _startHeight - deltaHeight;
54
- }
55
- curElement.style.height = _startHeight + 'px';
87
+ if (time < duration) {
88
+ //
89
+ requestId = window.requestAnimationFrame(loop);
56
90
  } else {
91
+ // change height
57
92
  curElement.style.height = _endHeight + 'px';
58
- clearInterval(timer);
93
+ if (typeof callback === 'function') callback();
94
+
95
+ //
96
+ window.cancelAnimationFrame(requestId);
59
97
  }
60
- }, _fps);
98
+ };
99
+ requestId = window.requestAnimationFrame(loop);
61
100
  }
62
101
 
63
102
  /**
@@ -137,6 +176,178 @@ module.exports = animateStyles;
137
176
 
138
177
  /***/ }),
139
178
 
179
+ /***/ 711:
180
+ /***/ ((module) => {
181
+
182
+ /*
183
+ * All easing functions
184
+ * @link: https://easings.net
185
+ * @param {Number} t - time (Amount of time that has passed since the beginning of the animation. Usually starts at 0 and is slowly increased using a game loop or other update function.)
186
+ * @param {Number} b - beginning value (The starting point of the animation. Usually it's a static value, you can start at 0 for example.)
187
+ * @param {Number} c - change in value (The amount of change needed to go from starting point to end point. It's also usually a static value.)
188
+ * @param {Number} d - duration (Amount of time the animation will take. Usually a static value aswell.)
189
+ * @return {Number}
190
+ */
191
+ function easeLinear(t, b, c, d) {
192
+ return c * t / d + b;
193
+ }
194
+ function easeInQuad(t, b, c, d) {
195
+ return c * (t /= d) * t + b;
196
+ }
197
+ function easeOutQuad(t, b, c, d) {
198
+ return -c * (t /= d) * (t - 2) + b;
199
+ }
200
+ function easeInOutQuad(t, b, c, d) {
201
+ if ((t /= d / 2) < 1) return c / 2 * t * t + b;
202
+ return -c / 2 * (--t * (t - 2) - 1) + b;
203
+ }
204
+ function easeInSine(t, b, c, d) {
205
+ return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
206
+ }
207
+ function easeOutSine(t, b, c, d) {
208
+ return c * Math.sin(t / d * (Math.PI / 2)) + b;
209
+ }
210
+ function easeInOutSine(t, b, c, d) {
211
+ return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
212
+ }
213
+ function easeInExpo(t, b, c, d) {
214
+ return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
215
+ }
216
+ function easeOutExpo(t, b, c, d) {
217
+ return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
218
+ }
219
+ function easeInOutExpo(t, b, c, d) {
220
+ if (t == 0) return b;
221
+ if (t == d) return b + c;
222
+ if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
223
+ return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
224
+ }
225
+ function easeInCirc(t, b, c, d) {
226
+ return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
227
+ }
228
+ function easeOutCirc(t, b, c, d) {
229
+ return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
230
+ }
231
+ function easeInOutCirc(t, b, c, d) {
232
+ if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
233
+ return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
234
+ }
235
+ function easeInCubic(t, b, c, d) {
236
+ return c * (t /= d) * t * t + b;
237
+ }
238
+ function easeOutCubic(t, b, c, d) {
239
+ return c * ((t = t / d - 1) * t * t + 1) + b;
240
+ }
241
+ function easeInOutCubic(t, b, c, d) {
242
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
243
+ return c / 2 * ((t -= 2) * t * t + 2) + b;
244
+ }
245
+ function easeInQuart(t, b, c, d) {
246
+ return c * (t /= d) * t * t * t + b;
247
+ }
248
+ function easeOutQuart(t, b, c, d) {
249
+ return -c * ((t = t / d - 1) * t * t * t - 1) + b;
250
+ }
251
+ function easeInOutQuart(t, b, c, d) {
252
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
253
+ return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
254
+ }
255
+ function easeInQuint(t, b, c, d) {
256
+ return c * (t /= d) * t * t * t * t + b;
257
+ }
258
+ function easeOutQuint(t, b, c, d) {
259
+ return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
260
+ }
261
+ function easeInOutQuint(t, b, c, d) {
262
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
263
+ return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
264
+ }
265
+ function easeInElastic(t, b, c, d) {
266
+ var s = 1.70158;
267
+ var p = 0;
268
+ var a = c;
269
+ if (t == 0) return b;
270
+ if ((t /= d) == 1) return b + c;
271
+ if (!p) p = d * .3;
272
+ if (a < Math.abs(c)) {
273
+ a = c;
274
+ var s = p / 4;
275
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
276
+ return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
277
+ }
278
+ function easeOutElastic(t, b, c, d) {
279
+ var s = 1.70158;
280
+ var p = 0;
281
+ var a = c;
282
+ if (t == 0) return b;
283
+ if ((t /= d) == 1) return b + c;
284
+ if (!p) p = d * .3;
285
+ if (a < Math.abs(c)) {
286
+ a = c;
287
+ var s = p / 4;
288
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
289
+ return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
290
+ }
291
+ function easeInOutElastic(t, b, c, d) {
292
+ var s = 1.70158;
293
+ var p = 0;
294
+ var a = c;
295
+ if (t == 0) return b;
296
+ if ((t /= d / 2) == 2) return b + c;
297
+ if (!p) p = d * (.3 * 1.5);
298
+ if (a < Math.abs(c)) {
299
+ a = c;
300
+ var s = p / 4;
301
+ } else var s = p / (2 * Math.PI) * Math.asin(c / a);
302
+ if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
303
+ return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
304
+ }
305
+ function easeInBack(t, b, c, d) {
306
+ if (s == undefined) s = 1.70158;
307
+ return c * (t /= d) * t * ((s + 1) * t - s) + b;
308
+ }
309
+ function easeOutBack(t, b, c, d) {
310
+ if (s == undefined) s = 1.70158;
311
+ return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
312
+ }
313
+ function easeInOutBack(t, b, c, d) {
314
+ if (s == undefined) s = 1.70158;
315
+ if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
316
+ return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
317
+ }
318
+ module.exports = {
319
+ easeLinear: easeLinear,
320
+ easeInQuad: easeInQuad,
321
+ easeOutQuad: easeOutQuad,
322
+ easeInOutQuad: easeInOutQuad,
323
+ easeInSine: easeInSine,
324
+ easeOutSine: easeOutSine,
325
+ easeInOutSine: easeInOutSine,
326
+ easeInExpo: easeInExpo,
327
+ easeOutExpo: easeOutExpo,
328
+ easeInOutExpo: easeInOutExpo,
329
+ easeInCirc: easeInCirc,
330
+ easeOutCirc: easeOutCirc,
331
+ easeInOutCirc: easeInOutCirc,
332
+ easeInCubic: easeInCubic,
333
+ easeOutCubic: easeOutCubic,
334
+ easeInOutCubic: easeInOutCubic,
335
+ easeInQuart: easeInQuart,
336
+ easeOutQuart: easeOutQuart,
337
+ easeInOutQuart: easeInOutQuart,
338
+ easeInQuint: easeInQuint,
339
+ easeOutQuint: easeOutQuint,
340
+ easeInOutQuint: easeInOutQuint,
341
+ easeInElastic: easeInElastic,
342
+ easeOutElastic: easeOutElastic,
343
+ easeInOutElastic: easeInOutElastic,
344
+ easeInBack: easeInBack,
345
+ easeOutBack: easeOutBack,
346
+ easeInOutBack: easeInOutBack
347
+ };
348
+
349
+ /***/ }),
350
+
140
351
  /***/ 787:
141
352
  /***/ ((module) => {
142
353
 
@@ -232,7 +443,8 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
232
443
  ;// CONCATENATED MODULE: ./src/AccordionItem.tsx
233
444
 
234
445
  var AccordionItem = function AccordionItem(props) {
235
- var index = props.index,
446
+ var heightObserver = props.heightObserver,
447
+ index = props.index,
236
448
  itemClassName = props.itemClassName,
237
449
  itemContentWrapperClassName = props.itemContentWrapperClassName,
238
450
  itemContentClassName = props.itemContentClassName,
@@ -247,6 +459,27 @@ var AccordionItem = function AccordionItem(props) {
247
459
  triggerType = props.triggerType,
248
460
  children = props.children;
249
461
  var activedClassName = typeof defaultActive !== 'undefined' && defaultActive !== false ? ' active' : '';
462
+ var observer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
463
+ var contentWrapperRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
464
+ var contentRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
465
+ (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
466
+ if (parseFloat(heightObserver) !== index) return;
467
+
468
+ // When the content height changes dynamically, change the height of the wrapper
469
+ if (contentRef.current && contentWrapperRef.current) {
470
+ var _contentPadding = window.getComputedStyle(contentRef.current).getPropertyValue('padding-bottom');
471
+ observer.current = new ResizeObserver(function (entries) {
472
+ entries.forEach(function (entry) {
473
+ contentWrapperRef.current.style.height = entry.contentRect.bottom + parseFloat(_contentPadding) + 'px';
474
+ });
475
+ });
476
+ observer.current.observe(contentRef.current);
477
+ }
478
+ return function () {
479
+ var _observer$current;
480
+ if (contentRef.current) (_observer$current = observer.current) === null || _observer$current === void 0 ? void 0 : _observer$current.unobserve(contentRef.current);
481
+ };
482
+ }, [heightObserver]);
250
483
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
251
484
  "data-index": index,
252
485
  className: "custom-accordion-item ".concat(itemClassName || itemClassName === '' ? itemClassName : "accordion-item", " ").concat(activedClassName),
@@ -263,6 +496,7 @@ var AccordionItem = function AccordionItem(props) {
263
496
  className: "custom-accordion-trigger ".concat(itemTriggerClassName || itemTriggerClassName === '' ? itemTriggerClassName : "accordion-button", " ").concat(activedClassName === '' ? 'collapsed' : 'active'),
264
497
  type: "button"
265
498
  }, title), itemTriggerIcon), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
499
+ ref: contentWrapperRef,
266
500
  className: "custom-accordion-content__wrapper ".concat(itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"),
267
501
  role: "tabpanel",
268
502
  style: {
@@ -270,7 +504,8 @@ var AccordionItem = function AccordionItem(props) {
270
504
  overflow: 'hidden'
271
505
  }
272
506
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
273
- className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body")
507
+ className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"),
508
+ ref: contentRef
274
509
  }, children))));
275
510
  };
276
511
  /* harmony default export */ const src_AccordionItem = (AccordionItem);
@@ -294,24 +529,41 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
294
529
 
295
530
 
296
531
 
532
+
533
+ // Adapt the easing parameters of TweenMax
534
+ var EasingList = /*#__PURE__*/function (EasingList) {
535
+ EasingList["linear"] = "linear";
536
+ EasingList["easeIn"] = "ease-in";
537
+ EasingList["easeOut"] = "ease-out";
538
+ EasingList["easeInOut"] = "ease-in-out";
539
+ return EasingList;
540
+ }(EasingList || {});
297
541
  var Accordion = function Accordion(props) {
298
542
  var wrapperClassName = props.wrapperClassName,
299
543
  triggerType = props.triggerType,
300
544
  displayTheFirstItem = props.displayTheFirstItem,
545
+ displayAllItems = props.displayAllItems,
301
546
  duration = props.duration,
547
+ easing = props.easing,
302
548
  alternateCollapse = props.alternateCollapse,
303
549
  onChange = props.onChange,
304
550
  children = props.children;
551
+ var easeType = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing];
305
552
  var ALTER = typeof alternateCollapse === 'undefined' ? true : alternateCollapse;
306
553
  var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
307
554
  var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
308
555
  _useState2 = _slicedToArray(_useState, 2),
309
556
  animOK = _useState2[0],
310
557
  setAnimOK = _useState2[1];
558
+ var _useState3 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(-1),
559
+ _useState4 = _slicedToArray(_useState3, 2),
560
+ heightObserver = _useState4[0],
561
+ setHeightObserver = _useState4[1];
311
562
  function handleClickItem(e) {
312
563
  e.preventDefault();
313
564
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
314
565
  e.stopPropagation();
566
+ if (e.target.closest('.custom-accordion-header') === null) return;
315
567
  if (animOK) return;
316
568
 
317
569
  //
@@ -336,7 +588,7 @@ var Accordion = function Accordion(props) {
336
588
  startHeight: node.scrollHeight,
337
589
  endHeight: 0,
338
590
  speed: animSpeed
339
- });
591
+ }, easeType);
340
592
  }
341
593
  });
342
594
 
@@ -358,6 +610,9 @@ var Accordion = function Accordion(props) {
358
610
  startHeight: 0,
359
611
  endHeight: $curContent.scrollHeight,
360
612
  speed: animSpeed
613
+ }, easeType, function () {
614
+ // content height observer
615
+ setHeightObserver(curIndex);
361
616
  });
362
617
  } else {
363
618
  if (e.type == 'click') {
@@ -371,7 +626,7 @@ var Accordion = function Accordion(props) {
371
626
  startHeight: $curContent.scrollHeight,
372
627
  endHeight: 0,
373
628
  speed: animSpeed
374
- });
629
+ }, easeType);
375
630
  }
376
631
  }
377
632
  if (typeof onChange === 'function') {
@@ -388,7 +643,8 @@ var Accordion = function Accordion(props) {
388
643
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, _extends({
389
644
  key: "item" + i,
390
645
  index: i,
391
- defaultActive: _defaultActive,
646
+ heightObserver: heightObserver,
647
+ defaultActive: typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems,
392
648
  triggerType: triggerType || 'click',
393
649
  onToggleEv: handleClickItem
394
650
  }, childProps));
@@ -4,6 +4,16 @@ import Item from './AccordionItem';
4
4
 
5
5
  import animateStyles from './utils/anim';
6
6
 
7
+
8
+ // Adapt the easing parameters of TweenMax
9
+ enum EasingList {
10
+ linear = 'linear',
11
+ easeIn = 'ease-in',
12
+ easeOut = 'ease-out',
13
+ easeInOut = 'ease-in-out'
14
+ }
15
+
16
+
7
17
  declare module 'react' {
8
18
  interface ReactI18NextChildren<T> {
9
19
  children?: any;
@@ -19,8 +29,12 @@ type AccordionProps = {
19
29
  triggerType?: string;
20
30
  /** Display the only first item of a list */
21
31
  displayTheFirstItem?: boolean;
32
+ /** Display all items */
33
+ displayAllItems?: boolean;
22
34
  /** The number of milliseconds(ms) each iteration of the animation takes to complete */
23
35
  duration?: number;
36
+ /** Types of easing animation */
37
+ easing?: string;
24
38
  /** Mutually exclusive alternate expansion between the levels */
25
39
  alternateCollapse?: boolean;
26
40
  /** This function is called whenever the data is updated.
@@ -36,24 +50,29 @@ const Accordion = (props: AccordionProps) => {
36
50
  wrapperClassName,
37
51
  triggerType,
38
52
  displayTheFirstItem,
53
+ displayAllItems,
39
54
  duration,
55
+ easing,
40
56
  alternateCollapse,
41
57
  onChange,
42
58
  children
43
59
  } = props;
44
60
 
45
61
 
62
+ const easeType: string = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing as never];
46
63
  const ALTER = typeof alternateCollapse === 'undefined' ? true : alternateCollapse;
47
64
  const rootRef = useRef<any>(null);
48
65
  const [animOK, setAnimOK] = useState<boolean>(false);
66
+ const [heightObserver, setHeightObserver] = useState<number>(-1);
49
67
 
50
-
51
-
68
+
52
69
  function handleClickItem(e: React.MouseEvent) {
53
70
  e.preventDefault();
54
71
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
55
72
  e.stopPropagation();
56
73
 
74
+
75
+ if ((e.target as any).closest('.custom-accordion-header') === null) return;
57
76
  if ( animOK ) return;
58
77
 
59
78
  //
@@ -81,7 +100,7 @@ const Accordion = (props: AccordionProps) => {
81
100
  startHeight : node.scrollHeight,
82
101
  endHeight : 0,
83
102
  speed : animSpeed
84
- } as never);
103
+ } as never, easeType);
85
104
  }
86
105
 
87
106
  });
@@ -106,7 +125,10 @@ const Accordion = (props: AccordionProps) => {
106
125
  startHeight : 0,
107
126
  endHeight : $curContent.scrollHeight,
108
127
  speed : animSpeed
109
- } as never);
128
+ } as never, easeType, () => {
129
+ // content height observer
130
+ setHeightObserver(curIndex);
131
+ });
110
132
 
111
133
  } else {
112
134
 
@@ -121,7 +143,7 @@ const Accordion = (props: AccordionProps) => {
121
143
  startHeight : $curContent.scrollHeight,
122
144
  endHeight : 0,
123
145
  speed : animSpeed
124
- } as never);
146
+ } as never, easeType);
125
147
  }
126
148
 
127
149
  }
@@ -143,7 +165,8 @@ const Accordion = (props: AccordionProps) => {
143
165
  return <Item
144
166
  key={"item" + i}
145
167
  index={i}
146
- defaultActive={_defaultActive}
168
+ heightObserver={heightObserver}
169
+ defaultActive={typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems}
147
170
  triggerType={triggerType || 'click'}
148
171
  onToggleEv={handleClickItem}
149
172
  {...childProps}
@@ -1,7 +1,8 @@
1
- import React from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
 
3
3
 
4
4
  type AccordionItemProps = {
5
+ heightObserver?: number;
5
6
  index?: number;
6
7
  /** Class of items */
7
8
  itemClassName?: string;
@@ -29,6 +30,7 @@ type AccordionItemProps = {
29
30
  const AccordionItem = (props: AccordionItemProps) => {
30
31
 
31
32
  const {
33
+ heightObserver,
32
34
  index,
33
35
  itemClassName,
34
36
  itemContentWrapperClassName,
@@ -45,8 +47,37 @@ const AccordionItem = (props: AccordionItemProps) => {
45
47
  children
46
48
  } = props;
47
49
 
50
+
51
+
48
52
  const activedClassName = typeof(defaultActive) !== 'undefined' && defaultActive !== false ? ' active' : '';
53
+ const observer = useRef<ResizeObserver | null>(null);
54
+ const contentWrapperRef = useRef<HTMLDivElement | null>(null);
55
+ const contentRef = useRef<HTMLDivElement | null>(null);
56
+
57
+
58
+ useEffect(() => {
59
+
60
+ if (parseFloat(heightObserver as never) !== index) return;
61
+
62
+ // When the content height changes dynamically, change the height of the wrapper
63
+ if (contentRef.current && contentWrapperRef.current) {
64
+ const _contentPadding = window.getComputedStyle(contentRef.current as HTMLDivElement).getPropertyValue('padding-bottom');
65
+
66
+ observer.current = new ResizeObserver(entries => {
67
+ entries.forEach(entry => {
68
+ (contentWrapperRef.current as HTMLDivElement).style.height = entry.contentRect.bottom + parseFloat(_contentPadding) + 'px';
69
+ });
70
+ });
71
+ observer.current.observe(contentRef.current);
72
+
73
+ }
74
+
75
+ return () => {
76
+ if (contentRef.current) observer.current?.unobserve(contentRef.current);
77
+ };
78
+
49
79
 
80
+ }, [heightObserver]);
50
81
 
51
82
  return (
52
83
  <>
@@ -68,12 +99,12 @@ const AccordionItem = (props: AccordionItemProps) => {
68
99
 
69
100
  {itemTriggerIcon}
70
101
  </div>
71
- <div className={`custom-accordion-content__wrapper ${itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"}`}
102
+ <div ref={contentWrapperRef} className={`custom-accordion-content__wrapper ${itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"}`}
72
103
  role="tabpanel" style={{
73
104
  height: defaultActive ? 'auto' : '0px',
74
105
  overflow: 'hidden'
75
106
  }}>
76
- <div className={`custom-accordion-content ${itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"}`}>
107
+ <div className={`custom-accordion-content ${itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"}`} ref={contentRef} >
77
108
  {children}
78
109
  </div>
79
110
  </div>
@@ -1,48 +1,93 @@
1
1
 
2
+ const {
3
+ easeLinear,
4
+ easeInQuad,
5
+ easeOutQuad,
6
+ easeInOutQuad
7
+ } = require('./easing');
8
+
9
+
2
10
  /**
3
11
  * Element Animate
4
12
  * @public
5
13
  *
6
14
  * @param {HTMLElement} curElement - Element of animation.
7
15
  * @param {?JSON} config - Configuration of animation
16
+ * @param {?string} easeType - Types of easing animation.
17
+ * @param {?Function} callback - Callback after animation ends
8
18
  */
9
- function animateStyles(curElement, config) {
19
+ function animateStyles(curElement, config, easeType = 'linear', callback = () => {}) {
10
20
  if (typeof curElement === typeof undefined) return;
11
21
 
12
22
  // Set a default configuration
13
23
  config = setDefaultOptions({
14
- "startHeight": 0,
24
+ "startHeight": 0, // node.scrollHeight
15
25
  "endHeight": 0,
16
26
  "speed": 200, //ms
17
- "fps": 1000 / 60 // 60FPS
18
27
  }, config);
19
28
 
20
29
  //
21
30
  const _endHeight = config.endHeight,
22
- _speed = config.speed,
23
- _fps = config.fps;
31
+ _speed = config.speed
24
32
 
25
33
  let _startHeight = config.startHeight;
26
- let timer = null;
27
- const startTime = Date.now();
28
- const deltaHeight = curElement.clientHeight < _endHeight ? (_endHeight / _speed) * _fps : (_startHeight / _speed) * _fps;
34
+
35
+ const duration = _speed;
36
+ const start = new Date().getTime();
37
+ const from = 0;
38
+ const to = 100;
39
+ let requestId;
40
+ const loop = function () {
41
+
42
+ //easing
43
+ const time = new Date().getTime() - start; //Work out the elapsed time
44
+ let val;
45
+
46
+ switch (easeType) {
47
+ case "linear":
48
+ val = easeLinear(time, from, to - from, duration);
49
+ break;
50
+ case "ease-in":
51
+ val = easeInQuad(time, from, to - from, duration);
52
+ break;
53
+ case "ease-out":
54
+ val = easeOutQuad(time, from, to - from, duration);
55
+ break;
56
+ case "ease-in-out":
57
+ val = easeInOutQuad(time, from, to - from, duration);
58
+ break;
59
+
60
+ default:
61
+ val = easeLinear(time, from, to - from, duration);
62
+ }
29
63
 
30
- timer = setInterval(() => {
31
- const elapsed = Date.now() - startTime; //Work out the elapsed time
64
+ // Elapsed time in miliseconds
65
+ const percent = val / 100;
66
+
67
+
68
+ // change height
69
+ if (curElement.clientHeight < _endHeight) {
70
+ curElement.style.height = _endHeight * percent + 'px';
71
+ } else {
72
+ if (_startHeight > 0) curElement.style.height = _startHeight - (_startHeight * percent) + 'px';
73
+ }
32
74
 
75
+
33
76
  //If the elapsed time is less than the speed (ms)
34
- if (elapsed < _speed) {
35
- if (curElement.clientHeight < _endHeight) {
36
- _startHeight = _startHeight + deltaHeight;
37
- } else {
38
- _startHeight = _startHeight - deltaHeight;
39
- }
40
- curElement.style.height = _startHeight + 'px';
77
+ if (time < duration) {
78
+ //
79
+ requestId = window.requestAnimationFrame(loop);
41
80
  } else {
81
+ // change height
42
82
  curElement.style.height = _endHeight + 'px';
43
- clearInterval(timer);
83
+
84
+ if (typeof callback === 'function') callback();
85
+
86
+ //
87
+ window.cancelAnimationFrame(requestId);
44
88
  }
45
- }, _fps);
89
+ };
90
+ requestId = window.requestAnimationFrame(loop);
46
91
 
47
92
  }
48
93
 
@@ -0,0 +1,200 @@
1
+
2
+ /*
3
+ * All easing functions
4
+ * @link: https://easings.net
5
+ * @param {Number} t - time (Amount of time that has passed since the beginning of the animation. Usually starts at 0 and is slowly increased using a game loop or other update function.)
6
+ * @param {Number} b - beginning value (The starting point of the animation. Usually it's a static value, you can start at 0 for example.)
7
+ * @param {Number} c - change in value (The amount of change needed to go from starting point to end point. It's also usually a static value.)
8
+ * @param {Number} d - duration (Amount of time the animation will take. Usually a static value aswell.)
9
+ * @return {Number}
10
+ */
11
+ function easeLinear (t, b, c, d) {
12
+ return c * t / d + b;
13
+ }
14
+
15
+ function easeInQuad (t, b, c, d) {
16
+ return c * (t /= d) * t + b;
17
+ }
18
+
19
+ function easeOutQuad (t, b, c, d) {
20
+ return -c * (t /= d) * (t - 2) + b;
21
+ }
22
+
23
+ function easeInOutQuad (t, b, c, d) {
24
+ if ((t /= d / 2) < 1) return c / 2 * t * t + b;
25
+ return -c / 2 * ((--t) * (t - 2) - 1) + b;
26
+ }
27
+
28
+ function easeInSine (t, b, c, d) {
29
+ return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
30
+ }
31
+
32
+ function easeOutSine (t, b, c, d) {
33
+ return c * Math.sin(t / d * (Math.PI / 2)) + b;
34
+ }
35
+
36
+ function easeInOutSine (t, b, c, d) {
37
+ return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
38
+ }
39
+
40
+ function easeInExpo (t, b, c, d) {
41
+ return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
42
+ }
43
+
44
+ function easeOutExpo (t, b, c, d) {
45
+ return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
46
+ }
47
+
48
+ function easeInOutExpo (t, b, c, d) {
49
+ if (t == 0) return b;
50
+ if (t == d) return b + c;
51
+ if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
52
+ return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
53
+ }
54
+
55
+ function easeInCirc (t, b, c, d) {
56
+ return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
57
+ }
58
+
59
+ function easeOutCirc (t, b, c, d) {
60
+ return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
61
+ }
62
+
63
+ function easeInOutCirc (t, b, c, d) {
64
+ if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
65
+ return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
66
+ }
67
+
68
+ function easeInCubic (t, b, c, d) {
69
+ return c * (t /= d) * t * t + b;
70
+ }
71
+
72
+ function easeOutCubic (t, b, c, d) {
73
+ return c * ((t = t / d - 1) * t * t + 1) + b;
74
+ }
75
+
76
+ function easeInOutCubic (t, b, c, d) {
77
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
78
+ return c / 2 * ((t -= 2) * t * t + 2) + b;
79
+ }
80
+
81
+ function easeInQuart (t, b, c, d) {
82
+ return c * (t /= d) * t * t * t + b;
83
+ }
84
+
85
+ function easeOutQuart (t, b, c, d) {
86
+ return -c * ((t = t / d - 1) * t * t * t - 1) + b;
87
+ }
88
+
89
+ function easeInOutQuart (t, b, c, d) {
90
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
91
+ return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
92
+ }
93
+
94
+ function easeInQuint (t, b, c, d) {
95
+ return c * (t /= d) * t * t * t * t + b;
96
+ }
97
+
98
+ function easeOutQuint (t, b, c, d) {
99
+ return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
100
+ }
101
+
102
+
103
+ function easeInOutQuint (t, b, c, d) {
104
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
105
+ return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
106
+ }
107
+
108
+ function easeInElastic (t, b, c, d) {
109
+ var s = 1.70158;
110
+ var p = 0;
111
+ var a = c;
112
+ if (t == 0) return b;
113
+ if ((t /= d) == 1) return b + c;
114
+ if (!p) p = d * .3;
115
+ if (a < Math.abs(c)) {
116
+ a = c;
117
+ var s = p / 4;
118
+ }
119
+ else var s = p / (2 * Math.PI) * Math.asin(c / a);
120
+ return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
121
+ }
122
+
123
+ function easeOutElastic (t, b, c, d) {
124
+ var s = 1.70158;
125
+ var p = 0;
126
+ var a = c;
127
+ if (t == 0) return b;
128
+ if ((t /= d) == 1) return b + c;
129
+ if (!p) p = d * .3;
130
+ if (a < Math.abs(c)) {
131
+ a = c;
132
+ var s = p / 4;
133
+ }
134
+ else var s = p / (2 * Math.PI) * Math.asin(c / a);
135
+ return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
136
+ }
137
+
138
+ function easeInOutElastic (t, b, c, d) {
139
+ var s = 1.70158;
140
+ var p = 0;
141
+ var a = c;
142
+ if (t == 0) return b;
143
+ if ((t /= d / 2) == 2) return b + c;
144
+ if (!p) p = d * (.3 * 1.5);
145
+ if (a < Math.abs(c)) {
146
+ a = c;
147
+ var s = p / 4;
148
+ }
149
+ else var s = p / (2 * Math.PI) * Math.asin(c / a);
150
+ if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
151
+ return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
152
+ }
153
+
154
+ function easeInBack (t, b, c, d) {
155
+ if (s == undefined) s = 1.70158;
156
+ return c * (t /= d) * t * ((s + 1) * t - s) + b;
157
+ }
158
+
159
+ function easeOutBack (t, b, c, d) {
160
+ if (s == undefined) s = 1.70158;
161
+ return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
162
+ }
163
+
164
+ function easeInOutBack (t, b, c, d) {
165
+ if (s == undefined) s = 1.70158;
166
+ if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
167
+ return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
168
+ }
169
+
170
+
171
+ module.exports = {
172
+ easeLinear,
173
+ easeInQuad,
174
+ easeOutQuad,
175
+ easeInOutQuad,
176
+ easeInSine,
177
+ easeOutSine,
178
+ easeInOutSine,
179
+ easeInExpo,
180
+ easeOutExpo,
181
+ easeInOutExpo,
182
+ easeInCirc,
183
+ easeOutCirc,
184
+ easeInOutCirc,
185
+ easeInCubic,
186
+ easeOutCubic,
187
+ easeInOutCubic,
188
+ easeInQuart,
189
+ easeOutQuart,
190
+ easeInOutQuart,
191
+ easeInQuint,
192
+ easeOutQuint,
193
+ easeInOutQuint,
194
+ easeInElastic,
195
+ easeOutElastic,
196
+ easeInOutElastic,
197
+ easeInBack,
198
+ easeOutBack,
199
+ easeInOutBack
200
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "UIUX Lab",
3
3
  "email": "uiuxlab@gmail.com",
4
4
  "name": "funda-ui",
5
- "version": "1.0.580",
5
+ "version": "1.0.605",
6
6
  "description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
7
7
  "repository": {
8
8
  "type": "git",