1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import classNames from 'classnames';
|
4 | import { TabContext } from './TabContext';
|
5 | import { mapToCssModules, tagPropType } from './utils';
|
6 |
|
7 | const propTypes = {
|
8 | tag: tagPropType,
|
9 | className: PropTypes.string,
|
10 | cssModule: PropTypes.object,
|
11 | tabId: PropTypes.any,
|
12 | };
|
13 |
|
14 | const defaultProps = {
|
15 | tag: 'div',
|
16 | };
|
17 |
|
18 | export 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 | }
|
33 | TabPane.propTypes = propTypes;
|
34 | TabPane.defaultProps = defaultProps;
|
35 |
|