-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathTabBarTabsNode.js
More file actions
93 lines (84 loc) · 2.25 KB
/
Copy pathTabBarTabsNode.js
File metadata and controls
93 lines (84 loc) · 2.25 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import warning from 'warning';
import PropTypes from 'prop-types';
import { isVertical } from './utils';
export default class TabBarTabsNode extends React.Component {
render() {
const {
panels: children,
activeKey,
prefixCls,
tabBarGutter,
saveRef,
tabBarPosition,
renderTabBarNode,
} = this.props;
const rst = [];
React.Children.forEach(children, (child, index) => {
if (!child) {
return;
}
const key = child.key;
let cls = activeKey === key ? `${prefixCls}-tab-active` : '';
cls += ` ${prefixCls}-tab`;
let events = {};
if (child.props.disabled) {
cls += ` ${prefixCls}-tab-disabled`;
} else {
events = {
onClick: this.props.onTabClick.bind(this, key),
};
}
const ref = {};
if (activeKey === key) {
ref.ref = saveRef('activeTab');
}
const gutter = tabBarGutter && index === children.length - 1 ? 0 : tabBarGutter;
const style = {
[isVertical(tabBarPosition) ? 'marginBottom' : 'marginRight']: gutter,
};
warning('tab' in child.props, 'There must be `tab` property on children of Tabs.');
let node = (
<div
role="tab"
aria-disabled={child.props.disabled ? 'true' : 'false'}
aria-selected={activeKey === key ? 'true' : 'false'}
{...events}
className={cls}
key={key}
style={ style }
{...ref}
{...(typeof child.props.tab === 'string' ? {'data-tab': child.props.tab}: {})}
>
{child.props.tab}
</div>
);
if (renderTabBarNode) {
node = renderTabBarNode(node);
}
rst.push(node);
});
return (
<div ref={saveRef('navTabsContainer')}>
{rst}
</div>
);
}
}
TabBarTabsNode.propTypes = {
activeKey: PropTypes.string,
panels: PropTypes.node,
prefixCls: PropTypes.string,
tabBarGutter: PropTypes.number,
onTabClick: PropTypes.func,
saveRef: PropTypes.func,
renderTabBarNode: PropTypes.func,
tabBarPosition: PropTypes.string,
};
TabBarTabsNode.defaultProps = {
panels: [],
prefixCls: [],
tabBarGutter: null,
onTabClick: () => {},
saveRef: () => {},
};