UNPKG

871 BJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { TabContext } from './TabContext';
5import { mapToCssModules, tagPropType } from './utils';
6
7const propTypes = {
8 tag: tagPropType,
9 className: PropTypes.string,
10 cssModule: PropTypes.object,
11 tabId: PropTypes.any,
12};
13
14const defaultProps = {
15 tag: 'div',
16};
17
18export default function TabPane(props) {
19 const {
20 className,
21 cssModule,
22 tabId,
23 tag: Tag,
24 ...attributes
25 } = props;
26 const getClasses = (activeTabId) => mapToCssModules(classNames('tab-pane', className, { active: tabId === activeTabId }), cssModule);
27 return (
28 <TabContext.Consumer>
29 {({activeTabId}) => <Tag {...attributes} className={getClasses(activeTabId)} />}
30 </TabContext.Consumer>
31 );
32}
33TabPane.propTypes = propTypes;
34TabPane.defaultProps = defaultProps;
35