funda-ui 1.0.600 → 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.
@@ -27,10 +27,12 @@ var _require = __webpack_require__(711),
27
27
  *
28
28
  * @param {HTMLElement} curElement - Element of animation.
29
29
  * @param {?JSON} config - Configuration of animation
30
- * @param {?string} easeType - Types of easing animation.
30
+ * @param {?string} easeType - Types of easing animation.
31
+ * @param {?Function} callback - Callback after animation ends
31
32
  */
32
33
  function animateStyles(curElement, config) {
33
34
  var easeType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'linear';
35
+ var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
34
36
  if (_typeof(curElement) === ( true ? "undefined" : 0)) return;
35
37
 
36
38
  // Set a default configuration
@@ -88,6 +90,7 @@ function animateStyles(curElement, config) {
88
90
  } else {
89
91
  // change height
90
92
  curElement.style.height = _endHeight + 'px';
93
+ if (typeof callback === 'function') callback();
91
94
 
92
95
  //
93
96
  window.cancelAnimationFrame(requestId);
@@ -440,7 +443,8 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
440
443
  ;// CONCATENATED MODULE: ./src/AccordionItem.tsx
441
444
 
442
445
  var AccordionItem = function AccordionItem(props) {
443
- var index = props.index,
446
+ var heightObserver = props.heightObserver,
447
+ index = props.index,
444
448
  itemClassName = props.itemClassName,
445
449
  itemContentWrapperClassName = props.itemContentWrapperClassName,
446
450
  itemContentClassName = props.itemContentClassName,
@@ -455,6 +459,27 @@ var AccordionItem = function AccordionItem(props) {
455
459
  triggerType = props.triggerType,
456
460
  children = props.children;
457
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]);
458
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", {
459
484
  "data-index": index,
460
485
  className: "custom-accordion-item ".concat(itemClassName || itemClassName === '' ? itemClassName : "accordion-item", " ").concat(activedClassName),
@@ -471,6 +496,7 @@ var AccordionItem = function AccordionItem(props) {
471
496
  className: "custom-accordion-trigger ".concat(itemTriggerClassName || itemTriggerClassName === '' ? itemTriggerClassName : "accordion-button", " ").concat(activedClassName === '' ? 'collapsed' : 'active'),
472
497
  type: "button"
473
498
  }, title), itemTriggerIcon), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
499
+ ref: contentWrapperRef,
474
500
  className: "custom-accordion-content__wrapper ".concat(itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"),
475
501
  role: "tabpanel",
476
502
  style: {
@@ -478,7 +504,8 @@ var AccordionItem = function AccordionItem(props) {
478
504
  overflow: 'hidden'
479
505
  }
480
506
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
481
- className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body")
507
+ className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"),
508
+ ref: contentRef
482
509
  }, children))));
483
510
  };
484
511
  /* harmony default export */ const src_AccordionItem = (AccordionItem);
@@ -515,6 +542,7 @@ var Accordion = function Accordion(props) {
515
542
  var wrapperClassName = props.wrapperClassName,
516
543
  triggerType = props.triggerType,
517
544
  displayTheFirstItem = props.displayTheFirstItem,
545
+ displayAllItems = props.displayAllItems,
518
546
  duration = props.duration,
519
547
  easing = props.easing,
520
548
  alternateCollapse = props.alternateCollapse,
@@ -527,10 +555,15 @@ var Accordion = function Accordion(props) {
527
555
  _useState2 = _slicedToArray(_useState, 2),
528
556
  animOK = _useState2[0],
529
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];
530
562
  function handleClickItem(e) {
531
563
  e.preventDefault();
532
564
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
533
565
  e.stopPropagation();
566
+ if (e.target.closest('.custom-accordion-header') === null) return;
534
567
  if (animOK) return;
535
568
 
536
569
  //
@@ -577,7 +610,10 @@ var Accordion = function Accordion(props) {
577
610
  startHeight: 0,
578
611
  endHeight: $curContent.scrollHeight,
579
612
  speed: animSpeed
580
- }, easeType);
613
+ }, easeType, function () {
614
+ // content height observer
615
+ setHeightObserver(curIndex);
616
+ });
581
617
  } else {
582
618
  if (e.type == 'click') {
583
619
  var _reactDomEl$querySele3, _reactDomEl$querySele4;
@@ -607,7 +643,8 @@ var Accordion = function Accordion(props) {
607
643
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, _extends({
608
644
  key: "item" + i,
609
645
  index: i,
610
- defaultActive: _defaultActive,
646
+ heightObserver: heightObserver,
647
+ defaultActive: typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems,
611
648
  triggerType: triggerType || 'click',
612
649
  onToggleEv: handleClickItem
613
650
  }, childProps));
@@ -27,10 +27,12 @@ var _require = __webpack_require__(711),
27
27
  *
28
28
  * @param {HTMLElement} curElement - Element of animation.
29
29
  * @param {?JSON} config - Configuration of animation
30
- * @param {?string} easeType - Types of easing animation.
30
+ * @param {?string} easeType - Types of easing animation.
31
+ * @param {?Function} callback - Callback after animation ends
31
32
  */
32
33
  function animateStyles(curElement, config) {
33
34
  var easeType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'linear';
35
+ var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
34
36
  if (_typeof(curElement) === ( true ? "undefined" : 0)) return;
35
37
 
36
38
  // Set a default configuration
@@ -88,6 +90,7 @@ function animateStyles(curElement, config) {
88
90
  } else {
89
91
  // change height
90
92
  curElement.style.height = _endHeight + 'px';
93
+ if (typeof callback === 'function') callback();
91
94
 
92
95
  //
93
96
  window.cancelAnimationFrame(requestId);
@@ -440,7 +443,8 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
440
443
  ;// CONCATENATED MODULE: ./src/AccordionItem.tsx
441
444
 
442
445
  var AccordionItem = function AccordionItem(props) {
443
- var index = props.index,
446
+ var heightObserver = props.heightObserver,
447
+ index = props.index,
444
448
  itemClassName = props.itemClassName,
445
449
  itemContentWrapperClassName = props.itemContentWrapperClassName,
446
450
  itemContentClassName = props.itemContentClassName,
@@ -455,6 +459,27 @@ var AccordionItem = function AccordionItem(props) {
455
459
  triggerType = props.triggerType,
456
460
  children = props.children;
457
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]);
458
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", {
459
484
  "data-index": index,
460
485
  className: "custom-accordion-item ".concat(itemClassName || itemClassName === '' ? itemClassName : "accordion-item", " ").concat(activedClassName),
@@ -471,6 +496,7 @@ var AccordionItem = function AccordionItem(props) {
471
496
  className: "custom-accordion-trigger ".concat(itemTriggerClassName || itemTriggerClassName === '' ? itemTriggerClassName : "accordion-button", " ").concat(activedClassName === '' ? 'collapsed' : 'active'),
472
497
  type: "button"
473
498
  }, title), itemTriggerIcon), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
499
+ ref: contentWrapperRef,
474
500
  className: "custom-accordion-content__wrapper ".concat(itemContentWrapperClassName || itemContentWrapperClassName === '' ? itemContentWrapperClassName : "accordion-collapse"),
475
501
  role: "tabpanel",
476
502
  style: {
@@ -478,7 +504,8 @@ var AccordionItem = function AccordionItem(props) {
478
504
  overflow: 'hidden'
479
505
  }
480
506
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
481
- className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body")
507
+ className: "custom-accordion-content ".concat(itemContentClassName || itemContentClassName === '' ? itemContentClassName : "accordion-body"),
508
+ ref: contentRef
482
509
  }, children))));
483
510
  };
484
511
  /* harmony default export */ const src_AccordionItem = (AccordionItem);
@@ -515,6 +542,7 @@ var Accordion = function Accordion(props) {
515
542
  var wrapperClassName = props.wrapperClassName,
516
543
  triggerType = props.triggerType,
517
544
  displayTheFirstItem = props.displayTheFirstItem,
545
+ displayAllItems = props.displayAllItems,
518
546
  duration = props.duration,
519
547
  easing = props.easing,
520
548
  alternateCollapse = props.alternateCollapse,
@@ -527,10 +555,15 @@ var Accordion = function Accordion(props) {
527
555
  _useState2 = _slicedToArray(_useState, 2),
528
556
  animOK = _useState2[0],
529
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];
530
562
  function handleClickItem(e) {
531
563
  e.preventDefault();
532
564
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
533
565
  e.stopPropagation();
566
+ if (e.target.closest('.custom-accordion-header') === null) return;
534
567
  if (animOK) return;
535
568
 
536
569
  //
@@ -577,7 +610,10 @@ var Accordion = function Accordion(props) {
577
610
  startHeight: 0,
578
611
  endHeight: $curContent.scrollHeight,
579
612
  speed: animSpeed
580
- }, easeType);
613
+ }, easeType, function () {
614
+ // content height observer
615
+ setHeightObserver(curIndex);
616
+ });
581
617
  } else {
582
618
  if (e.type == 'click') {
583
619
  var _reactDomEl$querySele3, _reactDomEl$querySele4;
@@ -607,7 +643,8 @@ var Accordion = function Accordion(props) {
607
643
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, _extends({
608
644
  key: "item" + i,
609
645
  index: i,
610
- defaultActive: _defaultActive,
646
+ heightObserver: heightObserver,
647
+ defaultActive: typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems,
611
648
  triggerType: triggerType || 'click',
612
649
  onToggleEv: handleClickItem
613
650
  }, childProps));
@@ -29,6 +29,8 @@ type AccordionProps = {
29
29
  triggerType?: string;
30
30
  /** Display the only first item of a list */
31
31
  displayTheFirstItem?: boolean;
32
+ /** Display all items */
33
+ displayAllItems?: boolean;
32
34
  /** The number of milliseconds(ms) each iteration of the animation takes to complete */
33
35
  duration?: number;
34
36
  /** Types of easing animation */
@@ -48,6 +50,7 @@ const Accordion = (props: AccordionProps) => {
48
50
  wrapperClassName,
49
51
  triggerType,
50
52
  displayTheFirstItem,
53
+ displayAllItems,
51
54
  duration,
52
55
  easing,
53
56
  alternateCollapse,
@@ -60,17 +63,18 @@ const Accordion = (props: AccordionProps) => {
60
63
  const ALTER = typeof alternateCollapse === 'undefined' ? true : alternateCollapse;
61
64
  const rootRef = useRef<any>(null);
62
65
  const [animOK, setAnimOK] = useState<boolean>(false);
66
+ const [heightObserver, setHeightObserver] = useState<number>(-1);
63
67
 
64
-
65
-
68
+
66
69
  function handleClickItem(e: React.MouseEvent) {
67
70
  e.preventDefault();
68
71
  //Prevents further propagation of the current event in the capturing and bubbling phases(if use `e.target`).
69
72
  e.stopPropagation();
70
73
 
74
+
75
+ if ((e.target as any).closest('.custom-accordion-header') === null) return;
71
76
  if ( animOK ) return;
72
77
 
73
-
74
78
  //
75
79
  const reactDomEl: any = e.currentTarget;
76
80
  const curIndex: any = reactDomEl.dataset.index;
@@ -121,7 +125,10 @@ const Accordion = (props: AccordionProps) => {
121
125
  startHeight : 0,
122
126
  endHeight : $curContent.scrollHeight,
123
127
  speed : animSpeed
124
- } as never, easeType);
128
+ } as never, easeType, () => {
129
+ // content height observer
130
+ setHeightObserver(curIndex);
131
+ });
125
132
 
126
133
  } else {
127
134
 
@@ -158,7 +165,8 @@ const Accordion = (props: AccordionProps) => {
158
165
  return <Item
159
166
  key={"item" + i}
160
167
  index={i}
161
- defaultActive={_defaultActive}
168
+ heightObserver={heightObserver}
169
+ defaultActive={typeof displayAllItems === 'undefined' ? _defaultActive : displayAllItems}
162
170
  triggerType={triggerType || 'click'}
163
171
  onToggleEv={handleClickItem}
164
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>
@@ -13,9 +13,10 @@ const {
13
13
  *
14
14
  * @param {HTMLElement} curElement - Element of animation.
15
15
  * @param {?JSON} config - Configuration of animation
16
- * @param {?string} easeType - Types of easing animation.
16
+ * @param {?string} easeType - Types of easing animation.
17
+ * @param {?Function} callback - Callback after animation ends
17
18
  */
18
- function animateStyles(curElement, config, easeType = 'linear') {
19
+ function animateStyles(curElement, config, easeType = 'linear', callback = () => {}) {
19
20
  if (typeof curElement === typeof undefined) return;
20
21
 
21
22
  // Set a default configuration
@@ -80,6 +81,8 @@ function animateStyles(curElement, config, easeType = 'linear') {
80
81
  // change height
81
82
  curElement.style.height = _endHeight + 'px';
82
83
 
84
+ if (typeof callback === 'function') callback();
85
+
83
86
  //
84
87
  window.cancelAnimationFrame(requestId);
85
88
  }
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.600",
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",