funda-ui 4.7.270 → 4.7.275
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/Accordion/index.js
CHANGED
|
@@ -895,7 +895,7 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
|
|
|
895
895
|
// EXTERNAL MODULE: ../Utils/dist/cjs/cls.js
|
|
896
896
|
var cls = __webpack_require__(188);
|
|
897
897
|
;// CONCATENATED MODULE: ./src/AccordionItem.tsx
|
|
898
|
-
var _excluded = ["heightObserver", "index", "animSpeed", "easeType", "arrowOnly", "itemClassName", "itemContentWrapperClassName", "itemContentClassName", "itemTriggerClassName", "itemHeaderClassName", "itemTriggerIcon", "itemStyle", "
|
|
898
|
+
var _excluded = ["heightObserver", "index", "animSpeed", "easeType", "arrowOnly", "itemClassName", "itemContentWrapperClassName", "itemContentClassName", "itemTriggerClassName", "itemHeaderClassName", "itemTriggerIcon", "itemStyle", "activeItem", "title", "onToggleEv", "onTransitionEnd", "onItemCollapse", "isExpanded", "children"];
|
|
899
899
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
900
900
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
901
901
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -920,7 +920,7 @@ var AccordionItem = function AccordionItem(props) {
|
|
|
920
920
|
itemHeaderClassName = props.itemHeaderClassName,
|
|
921
921
|
itemTriggerIcon = props.itemTriggerIcon,
|
|
922
922
|
itemStyle = props.itemStyle,
|
|
923
|
-
|
|
923
|
+
activeItem = props.activeItem,
|
|
924
924
|
title = props.title,
|
|
925
925
|
onToggleEv = props.onToggleEv,
|
|
926
926
|
onTransitionEnd = props.onTransitionEnd,
|
|
@@ -964,18 +964,18 @@ var AccordionItem = function AccordionItem(props) {
|
|
|
964
964
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
965
965
|
if (contentWrapperRef.current && !initialHeightSet.current) {
|
|
966
966
|
initialHeightSet.current = true;
|
|
967
|
-
var shouldBeExpanded = typeof
|
|
967
|
+
var shouldBeExpanded = typeof activeItem !== 'undefined' && activeItem !== false;
|
|
968
968
|
if (controlledExpanded === undefined) {
|
|
969
969
|
setInternalExpanded(shouldBeExpanded);
|
|
970
970
|
}
|
|
971
971
|
|
|
972
|
-
// Set initial height when
|
|
972
|
+
// Set initial height when activeItem is true
|
|
973
973
|
if (shouldBeExpanded && contentRef.current) {
|
|
974
974
|
var contentHeight = contentRef.current.offsetHeight;
|
|
975
975
|
contentWrapperRef.current.style.height = "".concat(contentHeight, "px");
|
|
976
976
|
}
|
|
977
977
|
}
|
|
978
|
-
}, [
|
|
978
|
+
}, [activeItem, controlledExpanded]);
|
|
979
979
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
980
980
|
if (parseFloat(heightObserver) !== index) return;
|
|
981
981
|
|
|
@@ -1089,6 +1089,7 @@ var Accordion = function Accordion(props) {
|
|
|
1089
1089
|
var animSpeed = duration || 200;
|
|
1090
1090
|
var easeType = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing];
|
|
1091
1091
|
var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
1092
|
+
var animPlaceholderRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
1092
1093
|
var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
|
|
1093
1094
|
_useState2 = Accordion_slicedToArray(_useState, 2),
|
|
1094
1095
|
animOK = _useState2[0],
|
|
@@ -1113,9 +1114,7 @@ var Accordion = function Accordion(props) {
|
|
|
1113
1114
|
var $li = reactDomWrapperEl.querySelectorAll('.custom-accordion-item');
|
|
1114
1115
|
var $allContent = reactDomWrapperEl.querySelectorAll('.custom-accordion-content__wrapper');
|
|
1115
1116
|
var $curContent = reactDomEl.querySelector('.custom-accordion-content__wrapper');
|
|
1116
|
-
var $trigger = reactDomEl.querySelector('.custom-accordion-trigger');
|
|
1117
1117
|
if (reactDomEl.getAttribute('aria-expanded') === 'false' || reactDomEl.getAttribute('aria-expanded') === null) {
|
|
1118
|
-
var _curIndex;
|
|
1119
1118
|
setAnimOK(true);
|
|
1120
1119
|
setTimeout(function () {
|
|
1121
1120
|
setAnimOK(false);
|
|
@@ -1148,12 +1147,6 @@ var Accordion = function Accordion(props) {
|
|
|
1148
1147
|
});
|
|
1149
1148
|
}
|
|
1150
1149
|
reactDomEl.setAttribute('aria-expanded', 'true');
|
|
1151
|
-
|
|
1152
|
-
// Call onTriggerChange if it exists in the child props
|
|
1153
|
-
var childProps = (_curIndex = children[curIndex]) === null || _curIndex === void 0 ? void 0 : _curIndex.props;
|
|
1154
|
-
if (typeof (childProps === null || childProps === void 0 ? void 0 : childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1155
|
-
childProps.onTriggerChange($trigger, true);
|
|
1156
|
-
}
|
|
1157
1150
|
anim_default()($curContent, {
|
|
1158
1151
|
startHeight: 0,
|
|
1159
1152
|
endHeight: $curContent.scrollHeight,
|
|
@@ -1163,15 +1156,8 @@ var Accordion = function Accordion(props) {
|
|
|
1163
1156
|
animationInProgress.current = false;
|
|
1164
1157
|
});
|
|
1165
1158
|
} else {
|
|
1166
|
-
var _curIndex2;
|
|
1167
1159
|
reactDomEl.setAttribute('aria-expanded', 'false');
|
|
1168
1160
|
|
|
1169
|
-
// Call onTriggerChange if it exists in the child props
|
|
1170
|
-
var _childProps = (_curIndex2 = children[curIndex]) === null || _curIndex2 === void 0 ? void 0 : _curIndex2.props;
|
|
1171
|
-
if (typeof (_childProps === null || _childProps === void 0 ? void 0 : _childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1172
|
-
_childProps.onTriggerChange($trigger, false);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
1161
|
// Remove current item from expanded items
|
|
1176
1162
|
setExpandedItems(function (prev) {
|
|
1177
1163
|
var newSet = new Set(prev);
|
|
@@ -1191,7 +1177,7 @@ var Accordion = function Accordion(props) {
|
|
|
1191
1177
|
|
|
1192
1178
|
// Initialize expanded items based on defaultActiveIndex or defaultActiveAll
|
|
1193
1179
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1194
|
-
if (defaultActiveAll && children && rootRef.current) {
|
|
1180
|
+
if (defaultActiveAll && children && rootRef.current && animPlaceholderRef.current) {
|
|
1195
1181
|
var allIndices = Array.from({
|
|
1196
1182
|
length: children.length
|
|
1197
1183
|
}, function (_, i) {
|
|
@@ -1202,22 +1188,19 @@ var Accordion = function Accordion(props) {
|
|
|
1202
1188
|
// Actually expand all items without animation
|
|
1203
1189
|
var $allItems = rootRef.current.querySelectorAll('.custom-accordion-item');
|
|
1204
1190
|
Array.prototype.forEach.call($allItems, function (node, index) {
|
|
1205
|
-
var _index;
|
|
1206
|
-
node.setAttribute('aria-expanded', 'true');
|
|
1207
1191
|
var $curContent = node.querySelector('.custom-accordion-content__wrapper');
|
|
1208
|
-
var $trigger = node.querySelector('.custom-accordion-trigger');
|
|
1209
|
-
|
|
1210
|
-
// Call onTriggerChange if it exists in the child props
|
|
1211
|
-
var childProps = (_index = children[index]) === null || _index === void 0 ? void 0 : _index.props;
|
|
1212
|
-
if (typeof (childProps === null || childProps === void 0 ? void 0 : childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1213
|
-
childProps.onTriggerChange($trigger, true);
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
// Directly set height without animation
|
|
1217
1192
|
if ($curContent) {
|
|
1218
|
-
|
|
1193
|
+
// !!! Don't use the .custom-accordion-contentwrapper height directly, it may be more than a dozen pixels
|
|
1194
|
+
$curContent.style.height = "".concat(node.querySelector('.custom-accordion-content__wrapper > .custom-accordion-content').scrollHeight, "px");
|
|
1219
1195
|
}
|
|
1220
1196
|
});
|
|
1197
|
+
anim_default()(animPlaceholderRef.current, {
|
|
1198
|
+
startHeight: 0,
|
|
1199
|
+
endHeight: 10,
|
|
1200
|
+
speed: animSpeed
|
|
1201
|
+
}, easeType, function () {
|
|
1202
|
+
setTimeout(function () {}, animSpeed);
|
|
1203
|
+
});
|
|
1221
1204
|
} else if (defaultActiveIndex !== undefined) {
|
|
1222
1205
|
var initialExpanded = new Set();
|
|
1223
1206
|
if (Array.isArray(defaultActiveIndex)) {
|
|
@@ -1231,6 +1214,12 @@ var Accordion = function Accordion(props) {
|
|
|
1231
1214
|
}
|
|
1232
1215
|
}, [defaultActiveIndex, defaultActiveAll, children]);
|
|
1233
1216
|
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", {
|
|
1217
|
+
className: "custom-accordion-anim-placeholder",
|
|
1218
|
+
style: {
|
|
1219
|
+
display: 'none'
|
|
1220
|
+
},
|
|
1221
|
+
ref: animPlaceholderRef
|
|
1222
|
+
}), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
1234
1223
|
className: (0,cls.combinedCls)('custom-accordion-item', (0,cls.clsWrite)(wrapperClassName, 'accordion')),
|
|
1235
1224
|
role: "tablist",
|
|
1236
1225
|
ref: rootRef
|
|
@@ -1245,10 +1234,11 @@ var Accordion = function Accordion(props) {
|
|
|
1245
1234
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, Accordion_extends({
|
|
1246
1235
|
key: "item" + i,
|
|
1247
1236
|
index: i,
|
|
1237
|
+
defaultActiveAll: defaultActiveAll,
|
|
1248
1238
|
animSpeed: animSpeed,
|
|
1249
1239
|
arrowOnly: arrowOnly,
|
|
1250
1240
|
heightObserver: heightObserver,
|
|
1251
|
-
|
|
1241
|
+
activeItem: _defaultActive,
|
|
1252
1242
|
onToggleEv: handleClickItem,
|
|
1253
1243
|
isExpanded: expandedItems.has(i) // Both controlled and uncontrolled modes are implemented
|
|
1254
1244
|
}, childProps));
|
|
@@ -895,7 +895,7 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__
|
|
|
895
895
|
// EXTERNAL MODULE: ../Utils/dist/cjs/cls.js
|
|
896
896
|
var cls = __webpack_require__(188);
|
|
897
897
|
;// CONCATENATED MODULE: ./src/AccordionItem.tsx
|
|
898
|
-
var _excluded = ["heightObserver", "index", "animSpeed", "easeType", "arrowOnly", "itemClassName", "itemContentWrapperClassName", "itemContentClassName", "itemTriggerClassName", "itemHeaderClassName", "itemTriggerIcon", "itemStyle", "
|
|
898
|
+
var _excluded = ["heightObserver", "index", "animSpeed", "easeType", "arrowOnly", "itemClassName", "itemContentWrapperClassName", "itemContentClassName", "itemTriggerClassName", "itemHeaderClassName", "itemTriggerIcon", "itemStyle", "activeItem", "title", "onToggleEv", "onTransitionEnd", "onItemCollapse", "isExpanded", "children"];
|
|
899
899
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
900
900
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
901
901
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -920,7 +920,7 @@ var AccordionItem = function AccordionItem(props) {
|
|
|
920
920
|
itemHeaderClassName = props.itemHeaderClassName,
|
|
921
921
|
itemTriggerIcon = props.itemTriggerIcon,
|
|
922
922
|
itemStyle = props.itemStyle,
|
|
923
|
-
|
|
923
|
+
activeItem = props.activeItem,
|
|
924
924
|
title = props.title,
|
|
925
925
|
onToggleEv = props.onToggleEv,
|
|
926
926
|
onTransitionEnd = props.onTransitionEnd,
|
|
@@ -964,18 +964,18 @@ var AccordionItem = function AccordionItem(props) {
|
|
|
964
964
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
965
965
|
if (contentWrapperRef.current && !initialHeightSet.current) {
|
|
966
966
|
initialHeightSet.current = true;
|
|
967
|
-
var shouldBeExpanded = typeof
|
|
967
|
+
var shouldBeExpanded = typeof activeItem !== 'undefined' && activeItem !== false;
|
|
968
968
|
if (controlledExpanded === undefined) {
|
|
969
969
|
setInternalExpanded(shouldBeExpanded);
|
|
970
970
|
}
|
|
971
971
|
|
|
972
|
-
// Set initial height when
|
|
972
|
+
// Set initial height when activeItem is true
|
|
973
973
|
if (shouldBeExpanded && contentRef.current) {
|
|
974
974
|
var contentHeight = contentRef.current.offsetHeight;
|
|
975
975
|
contentWrapperRef.current.style.height = "".concat(contentHeight, "px");
|
|
976
976
|
}
|
|
977
977
|
}
|
|
978
|
-
}, [
|
|
978
|
+
}, [activeItem, controlledExpanded]);
|
|
979
979
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
980
980
|
if (parseFloat(heightObserver) !== index) return;
|
|
981
981
|
|
|
@@ -1089,6 +1089,7 @@ var Accordion = function Accordion(props) {
|
|
|
1089
1089
|
var animSpeed = duration || 200;
|
|
1090
1090
|
var easeType = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing];
|
|
1091
1091
|
var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
1092
|
+
var animPlaceholderRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
1092
1093
|
var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
|
|
1093
1094
|
_useState2 = Accordion_slicedToArray(_useState, 2),
|
|
1094
1095
|
animOK = _useState2[0],
|
|
@@ -1113,9 +1114,7 @@ var Accordion = function Accordion(props) {
|
|
|
1113
1114
|
var $li = reactDomWrapperEl.querySelectorAll('.custom-accordion-item');
|
|
1114
1115
|
var $allContent = reactDomWrapperEl.querySelectorAll('.custom-accordion-content__wrapper');
|
|
1115
1116
|
var $curContent = reactDomEl.querySelector('.custom-accordion-content__wrapper');
|
|
1116
|
-
var $trigger = reactDomEl.querySelector('.custom-accordion-trigger');
|
|
1117
1117
|
if (reactDomEl.getAttribute('aria-expanded') === 'false' || reactDomEl.getAttribute('aria-expanded') === null) {
|
|
1118
|
-
var _curIndex;
|
|
1119
1118
|
setAnimOK(true);
|
|
1120
1119
|
setTimeout(function () {
|
|
1121
1120
|
setAnimOK(false);
|
|
@@ -1148,12 +1147,6 @@ var Accordion = function Accordion(props) {
|
|
|
1148
1147
|
});
|
|
1149
1148
|
}
|
|
1150
1149
|
reactDomEl.setAttribute('aria-expanded', 'true');
|
|
1151
|
-
|
|
1152
|
-
// Call onTriggerChange if it exists in the child props
|
|
1153
|
-
var childProps = (_curIndex = children[curIndex]) === null || _curIndex === void 0 ? void 0 : _curIndex.props;
|
|
1154
|
-
if (typeof (childProps === null || childProps === void 0 ? void 0 : childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1155
|
-
childProps.onTriggerChange($trigger, true);
|
|
1156
|
-
}
|
|
1157
1150
|
anim_default()($curContent, {
|
|
1158
1151
|
startHeight: 0,
|
|
1159
1152
|
endHeight: $curContent.scrollHeight,
|
|
@@ -1163,15 +1156,8 @@ var Accordion = function Accordion(props) {
|
|
|
1163
1156
|
animationInProgress.current = false;
|
|
1164
1157
|
});
|
|
1165
1158
|
} else {
|
|
1166
|
-
var _curIndex2;
|
|
1167
1159
|
reactDomEl.setAttribute('aria-expanded', 'false');
|
|
1168
1160
|
|
|
1169
|
-
// Call onTriggerChange if it exists in the child props
|
|
1170
|
-
var _childProps = (_curIndex2 = children[curIndex]) === null || _curIndex2 === void 0 ? void 0 : _curIndex2.props;
|
|
1171
|
-
if (typeof (_childProps === null || _childProps === void 0 ? void 0 : _childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1172
|
-
_childProps.onTriggerChange($trigger, false);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
1161
|
// Remove current item from expanded items
|
|
1176
1162
|
setExpandedItems(function (prev) {
|
|
1177
1163
|
var newSet = new Set(prev);
|
|
@@ -1191,7 +1177,7 @@ var Accordion = function Accordion(props) {
|
|
|
1191
1177
|
|
|
1192
1178
|
// Initialize expanded items based on defaultActiveIndex or defaultActiveAll
|
|
1193
1179
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1194
|
-
if (defaultActiveAll && children && rootRef.current) {
|
|
1180
|
+
if (defaultActiveAll && children && rootRef.current && animPlaceholderRef.current) {
|
|
1195
1181
|
var allIndices = Array.from({
|
|
1196
1182
|
length: children.length
|
|
1197
1183
|
}, function (_, i) {
|
|
@@ -1202,22 +1188,19 @@ var Accordion = function Accordion(props) {
|
|
|
1202
1188
|
// Actually expand all items without animation
|
|
1203
1189
|
var $allItems = rootRef.current.querySelectorAll('.custom-accordion-item');
|
|
1204
1190
|
Array.prototype.forEach.call($allItems, function (node, index) {
|
|
1205
|
-
var _index;
|
|
1206
|
-
node.setAttribute('aria-expanded', 'true');
|
|
1207
1191
|
var $curContent = node.querySelector('.custom-accordion-content__wrapper');
|
|
1208
|
-
var $trigger = node.querySelector('.custom-accordion-trigger');
|
|
1209
|
-
|
|
1210
|
-
// Call onTriggerChange if it exists in the child props
|
|
1211
|
-
var childProps = (_index = children[index]) === null || _index === void 0 ? void 0 : _index.props;
|
|
1212
|
-
if (typeof (childProps === null || childProps === void 0 ? void 0 : childProps.onTriggerChange) === 'function' && $trigger) {
|
|
1213
|
-
childProps.onTriggerChange($trigger, true);
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
// Directly set height without animation
|
|
1217
1192
|
if ($curContent) {
|
|
1218
|
-
|
|
1193
|
+
// !!! Don't use the .custom-accordion-contentwrapper height directly, it may be more than a dozen pixels
|
|
1194
|
+
$curContent.style.height = "".concat(node.querySelector('.custom-accordion-content__wrapper > .custom-accordion-content').scrollHeight, "px");
|
|
1219
1195
|
}
|
|
1220
1196
|
});
|
|
1197
|
+
anim_default()(animPlaceholderRef.current, {
|
|
1198
|
+
startHeight: 0,
|
|
1199
|
+
endHeight: 10,
|
|
1200
|
+
speed: animSpeed
|
|
1201
|
+
}, easeType, function () {
|
|
1202
|
+
setTimeout(function () {}, animSpeed);
|
|
1203
|
+
});
|
|
1221
1204
|
} else if (defaultActiveIndex !== undefined) {
|
|
1222
1205
|
var initialExpanded = new Set();
|
|
1223
1206
|
if (Array.isArray(defaultActiveIndex)) {
|
|
@@ -1231,6 +1214,12 @@ var Accordion = function Accordion(props) {
|
|
|
1231
1214
|
}
|
|
1232
1215
|
}, [defaultActiveIndex, defaultActiveAll, children]);
|
|
1233
1216
|
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", {
|
|
1217
|
+
className: "custom-accordion-anim-placeholder",
|
|
1218
|
+
style: {
|
|
1219
|
+
display: 'none'
|
|
1220
|
+
},
|
|
1221
|
+
ref: animPlaceholderRef
|
|
1222
|
+
}), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
1234
1223
|
className: (0,cls.combinedCls)('custom-accordion-item', (0,cls.clsWrite)(wrapperClassName, 'accordion')),
|
|
1235
1224
|
role: "tablist",
|
|
1236
1225
|
ref: rootRef
|
|
@@ -1245,10 +1234,11 @@ var Accordion = function Accordion(props) {
|
|
|
1245
1234
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_AccordionItem, Accordion_extends({
|
|
1246
1235
|
key: "item" + i,
|
|
1247
1236
|
index: i,
|
|
1237
|
+
defaultActiveAll: defaultActiveAll,
|
|
1248
1238
|
animSpeed: animSpeed,
|
|
1249
1239
|
arrowOnly: arrowOnly,
|
|
1250
1240
|
heightObserver: heightObserver,
|
|
1251
|
-
|
|
1241
|
+
activeItem: _defaultActive,
|
|
1252
1242
|
onToggleEv: handleClickItem,
|
|
1253
1243
|
isExpanded: expandedItems.has(i) // Both controlled and uncontrolled modes are implemented
|
|
1254
1244
|
}, childProps));
|
|
@@ -5,6 +5,7 @@ import Item from './AccordionItem';
|
|
|
5
5
|
import animateStyles from 'funda-utils/dist/cjs/anim';
|
|
6
6
|
import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
// Adapt the easing parameters of TweenMax
|
|
9
10
|
export enum EasingList {
|
|
10
11
|
linear = 'linear',
|
|
@@ -55,6 +56,7 @@ const Accordion = (props: AccordionProps) => {
|
|
|
55
56
|
const animSpeed = duration || 200;
|
|
56
57
|
const easeType: string = typeof alternateCollapse === 'undefined' ? EasingList['linear'] : EasingList[easing as never];
|
|
57
58
|
const rootRef = useRef<any>(null);
|
|
59
|
+
const animPlaceholderRef = useRef<HTMLDivElement>(null);
|
|
58
60
|
const [animOK, setAnimOK] = useState<boolean>(false);
|
|
59
61
|
const [heightObserver, setHeightObserver] = useState<number>(-1);
|
|
60
62
|
const [expandedItems, setExpandedItems] = useState<Set<number>>(new Set()); // Keep track of all expanded items
|
|
@@ -74,7 +76,6 @@ const Accordion = (props: AccordionProps) => {
|
|
|
74
76
|
const $li = reactDomWrapperEl.querySelectorAll('.custom-accordion-item');
|
|
75
77
|
const $allContent = reactDomWrapperEl.querySelectorAll('.custom-accordion-content__wrapper');
|
|
76
78
|
const $curContent = reactDomEl.querySelector('.custom-accordion-content__wrapper');
|
|
77
|
-
const $trigger = reactDomEl.querySelector('.custom-accordion-trigger');
|
|
78
79
|
|
|
79
80
|
if (reactDomEl.getAttribute('aria-expanded') === 'false' || reactDomEl.getAttribute('aria-expanded') === null) {
|
|
80
81
|
setAnimOK(true);
|
|
@@ -110,12 +111,7 @@ const Accordion = (props: AccordionProps) => {
|
|
|
110
111
|
|
|
111
112
|
reactDomEl.setAttribute('aria-expanded', 'true');
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
const childProps = (children as any[])[curIndex]?.props;
|
|
115
|
-
if (typeof childProps?.onTriggerChange === 'function' && $trigger) {
|
|
116
|
-
childProps.onTriggerChange($trigger, true);
|
|
117
|
-
}
|
|
118
|
-
|
|
114
|
+
|
|
119
115
|
animateStyles($curContent, {
|
|
120
116
|
startHeight: 0,
|
|
121
117
|
endHeight: $curContent.scrollHeight,
|
|
@@ -127,12 +123,6 @@ const Accordion = (props: AccordionProps) => {
|
|
|
127
123
|
} else {
|
|
128
124
|
reactDomEl.setAttribute('aria-expanded', 'false');
|
|
129
125
|
|
|
130
|
-
// Call onTriggerChange if it exists in the child props
|
|
131
|
-
const childProps = (children as any[])[curIndex]?.props;
|
|
132
|
-
if (typeof childProps?.onTriggerChange === 'function' && $trigger) {
|
|
133
|
-
childProps.onTriggerChange($trigger, false);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
126
|
// Remove current item from expanded items
|
|
137
127
|
setExpandedItems(prev => {
|
|
138
128
|
const newSet = new Set(prev);
|
|
@@ -155,29 +145,32 @@ const Accordion = (props: AccordionProps) => {
|
|
|
155
145
|
|
|
156
146
|
// Initialize expanded items based on defaultActiveIndex or defaultActiveAll
|
|
157
147
|
useEffect(() => {
|
|
158
|
-
if (defaultActiveAll && children && rootRef.current) {
|
|
148
|
+
if (defaultActiveAll && children && rootRef.current && animPlaceholderRef.current) {
|
|
159
149
|
const allIndices = Array.from({ length: (children as any[]).length }, (_, i) => i);
|
|
160
150
|
setExpandedItems(new Set(allIndices));
|
|
161
151
|
|
|
162
152
|
// Actually expand all items without animation
|
|
163
153
|
const $allItems = rootRef.current.querySelectorAll('.custom-accordion-item');
|
|
164
|
-
|
|
165
154
|
Array.prototype.forEach.call($allItems, (node, index) => {
|
|
166
|
-
node.setAttribute('aria-expanded', 'true');
|
|
167
155
|
const $curContent = node.querySelector('.custom-accordion-content__wrapper');
|
|
168
|
-
const $trigger = node.querySelector('.custom-accordion-trigger');
|
|
169
|
-
|
|
170
|
-
// Call onTriggerChange if it exists in the child props
|
|
171
|
-
const childProps = (children as any[])[index]?.props;
|
|
172
|
-
if (typeof childProps?.onTriggerChange === 'function' && $trigger) {
|
|
173
|
-
childProps.onTriggerChange($trigger, true);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Directly set height without animation
|
|
177
156
|
if ($curContent) {
|
|
178
|
-
|
|
157
|
+
// !!! Don't use the .custom-accordion-contentwrapper height directly, it may be more than a dozen pixels
|
|
158
|
+
$curContent.style.height = `${node.querySelector('.custom-accordion-content__wrapper > .custom-accordion-content').scrollHeight}px`;
|
|
179
159
|
}
|
|
180
160
|
});
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
animateStyles(animPlaceholderRef.current as HTMLDivElement, {
|
|
164
|
+
startHeight: 0,
|
|
165
|
+
endHeight: 10,
|
|
166
|
+
speed: animSpeed
|
|
167
|
+
} as never, easeType, () => {
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
|
|
170
|
+
}, animSpeed);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
|
|
181
174
|
} else if (defaultActiveIndex !== undefined) {
|
|
182
175
|
const initialExpanded = new Set<number>();
|
|
183
176
|
if (Array.isArray(defaultActiveIndex)) {
|
|
@@ -191,6 +184,7 @@ const Accordion = (props: AccordionProps) => {
|
|
|
191
184
|
|
|
192
185
|
return (
|
|
193
186
|
<>
|
|
187
|
+
<div className="custom-accordion-anim-placeholder" style={{display: 'none'}} ref={animPlaceholderRef}></div>
|
|
194
188
|
<div className={combinedCls(
|
|
195
189
|
'custom-accordion-item',
|
|
196
190
|
clsWrite(wrapperClassName, 'accordion')
|
|
@@ -208,10 +202,11 @@ const Accordion = (props: AccordionProps) => {
|
|
|
208
202
|
return <Item
|
|
209
203
|
key={"item" + i}
|
|
210
204
|
index={i}
|
|
205
|
+
defaultActiveAll={defaultActiveAll}
|
|
211
206
|
animSpeed={animSpeed}
|
|
212
207
|
arrowOnly={arrowOnly}
|
|
213
208
|
heightObserver={heightObserver}
|
|
214
|
-
|
|
209
|
+
activeItem={_defaultActive}
|
|
215
210
|
onToggleEv={handleClickItem}
|
|
216
211
|
isExpanded={expandedItems.has(i)} // Both controlled and uncontrolled modes are implemented
|
|
217
212
|
{...childProps}
|
|
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
export type AccordionItemProps = {
|
|
6
7
|
heightObserver?: number;
|
|
7
8
|
index?: number;
|
|
@@ -17,7 +18,7 @@ export type AccordionItemProps = {
|
|
|
17
18
|
itemStyle?: React.CSSProperties;
|
|
18
19
|
itemTriggerIcon?: React.ReactNode;
|
|
19
20
|
/** Set an item to activate by default */
|
|
20
|
-
|
|
21
|
+
activeItem?: string | boolean | undefined;
|
|
21
22
|
/** Specify a title */
|
|
22
23
|
title?: React.ReactNode;
|
|
23
24
|
/** Handling events for collapsing item */
|
|
@@ -49,7 +50,7 @@ const AccordionItem = (props: AccordionItemProps) => {
|
|
|
49
50
|
itemHeaderClassName,
|
|
50
51
|
itemTriggerIcon,
|
|
51
52
|
itemStyle,
|
|
52
|
-
|
|
53
|
+
activeItem,
|
|
53
54
|
title,
|
|
54
55
|
onToggleEv,
|
|
55
56
|
onTransitionEnd,
|
|
@@ -95,18 +96,18 @@ const AccordionItem = (props: AccordionItemProps) => {
|
|
|
95
96
|
useEffect(() => {
|
|
96
97
|
if (contentWrapperRef.current && !initialHeightSet.current) {
|
|
97
98
|
initialHeightSet.current = true;
|
|
98
|
-
const shouldBeExpanded = typeof
|
|
99
|
+
const shouldBeExpanded = typeof activeItem !== 'undefined' && activeItem !== false;
|
|
99
100
|
if (controlledExpanded === undefined) {
|
|
100
101
|
setInternalExpanded(shouldBeExpanded);
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
// Set initial height when
|
|
104
|
+
// Set initial height when activeItem is true
|
|
104
105
|
if (shouldBeExpanded && contentRef.current) {
|
|
105
106
|
const contentHeight = contentRef.current.offsetHeight;
|
|
106
107
|
contentWrapperRef.current.style.height = `${contentHeight}px`;
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
}, [
|
|
110
|
+
}, [activeItem, controlledExpanded]);
|
|
110
111
|
|
|
111
112
|
useEffect(() => {
|
|
112
113
|
|
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": "4.7.
|
|
5
|
+
"version": "4.7.275",
|
|
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",
|