UNPKG

@coreui/react

Version:

UI Components Library for React.js

42 lines (39 loc) 2.39 kB
import { __rest, __assign } from '../../node_modules/tslib/tslib.es6.js'; import React, { forwardRef, useContext, useRef, useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import classNames from '../../_virtual/index.js'; import { CTabsContext } from './CTabsContext.js'; import { useForkedRef } from '../../hooks/useForkedRef.js'; import '@popperjs/core'; import getTransitionDurationFromElement from '../../utils/getTransitionDurationFromElement.js'; import Transition from '../../node_modules/react-transition-group/esm/Transition.js'; var CTabPanel = forwardRef(function (_a, ref) { var children = _a.children, className = _a.className, itemKey = _a.itemKey, onHide = _a.onHide, onShow = _a.onShow, _b = _a.transition, transition = _b === void 0 ? true : _b, visible = _a.visible, rest = __rest(_a, ["children", "className", "itemKey", "onHide", "onShow", "transition", "visible"]); var _c = useContext(CTabsContext), _activeItemKey = _c._activeItemKey, id = _c.id; var tabPaneRef = useRef(null); var forkedRef = useForkedRef(ref, tabPaneRef); var _d = useState(visible || _activeItemKey === itemKey), _visible = _d[0], setVisible = _d[1]; useEffect(function () { visible !== undefined && setVisible(visible); }, [visible]); useEffect(function () { setVisible(_activeItemKey === itemKey); }, [_activeItemKey]); return (React.createElement(Transition, { in: _visible, nodeRef: tabPaneRef, onEnter: onShow, onExit: onHide, timeout: tabPaneRef.current ? getTransitionDurationFromElement(tabPaneRef.current) : 0 }, function (state) { return (React.createElement("div", __assign({ className: classNames('tab-pane', { active: _visible, fade: transition, show: state === 'entered', }, className), id: "".concat(id).concat(itemKey, "-tab-pane"), role: "tabpanel", "aria-labelledby": "".concat(id).concat(itemKey, "-tab"), tabIndex: 0, ref: forkedRef }, rest), children)); })); }); CTabPanel.propTypes = { children: PropTypes.node, className: PropTypes.string, itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, onHide: PropTypes.func, onShow: PropTypes.func, transition: PropTypes.bool, visible: PropTypes.bool, }; CTabPanel.displayName = 'CTabPanel'; export { CTabPanel }; //# sourceMappingURL=CTabPanel.js.map