|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var React = require('react'); |
| 4 | +var constants = require('../utils/constants.cjs'); |
| 5 | +var bem = require('../utils/bem.cjs'); |
| 6 | +var mergeProps = require('../utils/mergeProps.cjs'); |
| 7 | +var useAccordionItem = require('../hooks/useAccordionItem.cjs'); |
| 8 | +var useHeightTransition = require('../hooks/useHeightTransition.cjs'); |
| 9 | +var useMergeRef = require('../hooks/useMergeRef.cjs'); |
| 10 | +var withAccordionItem = require('./withAccordionItem.cjs'); |
| 11 | +var jsxRuntime = require('react/jsx-runtime'); |
| 12 | + |
| 13 | +const getRenderNode = (nodeOrFunc, props) => typeof nodeOrFunc === 'function' ? nodeOrFunc(props) : nodeOrFunc; |
| 14 | +const WrappedItem = /*#__PURE__*/React.memo(({ |
| 15 | + forwardedRef, |
| 16 | + itemRef, |
| 17 | + state, |
| 18 | + toggle, |
| 19 | + className, |
| 20 | + disabled, |
| 21 | + header, |
| 22 | + headingTag: Heading = 'h3', |
| 23 | + headingProps, |
| 24 | + buttonProps, |
| 25 | + contentProps, |
| 26 | + panelProps, |
| 27 | + children, |
| 28 | + ...rest |
| 29 | +}) => { |
| 30 | + const itemState = { |
| 31 | + state, |
| 32 | + toggle, |
| 33 | + disabled |
| 34 | + }; |
| 35 | + const { |
| 36 | + buttonProps: _buttonProps, |
| 37 | + panelProps: _panelProps |
| 38 | + } = useAccordionItem.useAccordionItem(itemState); |
| 39 | + const [transitionStyle, _panelRef] = useHeightTransition.useHeightTransition(state); |
| 40 | + const panelRef = useMergeRef.useMergeRef(panelProps?.ref, _panelRef); |
| 41 | + const { |
| 42 | + status, |
| 43 | + isMounted, |
| 44 | + isEnter |
| 45 | + } = state; |
| 46 | + return /*#__PURE__*/jsxRuntime.jsxs("div", { |
| 47 | + ...rest, |
| 48 | + ref: useMergeRef.useMergeRef(forwardedRef, itemRef), |
| 49 | + className: bem.bem(constants.ACCORDION_BLOCK, 'item', { |
| 50 | + status, |
| 51 | + expanded: isEnter |
| 52 | + })(className, state), |
| 53 | + children: [/*#__PURE__*/jsxRuntime.jsx(Heading, { |
| 54 | + ...headingProps, |
| 55 | + style: { |
| 56 | + margin: 0, |
| 57 | + ...headingProps?.style |
| 58 | + }, |
| 59 | + className: bem.bem(constants.ACCORDION_BLOCK, 'item-heading')(headingProps?.className, state), |
| 60 | + children: /*#__PURE__*/jsxRuntime.jsx("button", { |
| 61 | + ...mergeProps.mergeProps(_buttonProps, buttonProps), |
| 62 | + type: "button", |
| 63 | + className: bem.bem(constants.ACCORDION_BLOCK, 'item-btn')(buttonProps?.className, state), |
| 64 | + children: getRenderNode(header, itemState) |
| 65 | + }) |
| 66 | + }), isMounted && /*#__PURE__*/jsxRuntime.jsx("div", { |
| 67 | + ...contentProps, |
| 68 | + style: { |
| 69 | + display: status === 'exited' ? 'none' : undefined, |
| 70 | + ...transitionStyle, |
| 71 | + ...contentProps?.style |
| 72 | + }, |
| 73 | + className: bem.bem(constants.ACCORDION_BLOCK, 'item-content')(contentProps?.className, state), |
| 74 | + children: /*#__PURE__*/jsxRuntime.jsx("div", { |
| 75 | + ...mergeProps.mergeProps(_panelProps, panelProps), |
| 76 | + ref: panelRef, |
| 77 | + className: bem.bem(constants.ACCORDION_BLOCK, 'item-panel')(panelProps?.className, state), |
| 78 | + children: getRenderNode(children, itemState) |
| 79 | + }) |
| 80 | + })] |
| 81 | + }); |
| 82 | +}); |
| 83 | +WrappedItem.displayName = 'AccordionItem'; |
| 84 | +const AccordionItem = /*#__PURE__*/withAccordionItem.withAccordionItem(WrappedItem); |
| 85 | + |
| 86 | +exports.AccordionItem = AccordionItem; |
0 commit comments