forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabPane.js
More file actions
34 lines (31 loc) · 891 Bytes
/
TabPane.js
File metadata and controls
34 lines (31 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { TabContext } from './TabContext';
import { mapToCssModules, tagPropType } from './utils';
const propTypes = {
tag: tagPropType,
className: PropTypes.string,
cssModule: PropTypes.object,
tabId: PropTypes.any,
};
const defaultProps = {
tag: 'div',
};
export default function TabPane(props) {
const { className, cssModule, tabId, tag: Tag, ...attributes } = props;
const getClasses = (activeTabId) =>
mapToCssModules(
classNames('tab-pane', className, { active: tabId === activeTabId }),
cssModule,
);
return (
<TabContext.Consumer>
{({ activeTabId }) => (
<Tag {...attributes} className={getClasses(activeTabId)} />
)}
</TabContext.Consumer>
);
}
TabPane.propTypes = propTypes;
TabPane.defaultProps = defaultProps;