UNPKG

4.22 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
9var _react = require('react');
10
11var _react2 = _interopRequireDefault(_react);
12
13var _classnames2 = require('classnames');
14
15var _classnames3 = _interopRequireDefault(_classnames2);
16
17var _utils = require('./utils');
18
19var _propTypes = require('prop-types');
20
21var _propTypes2 = _interopRequireDefault(_propTypes);
22
23var _createReactClass = require('create-react-class');
24
25var _createReactClass2 = _interopRequireDefault(_createReactClass);
26
27function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
28
29function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /**
30 * This source code is quoted from rc-tabs.
31 * homepage: https://github.com/react-component/tabs
32 */
33
34
35var TabContent = (0, _createReactClass2["default"])({
36 propTypes: {
37 animated: _propTypes2["default"].bool,
38 animatedWithMargin: _propTypes2["default"].bool,
39 clsPrefix: _propTypes2["default"].string,
40 children: _propTypes2["default"].any,
41 activeKey: _propTypes2["default"].string,
42 style: _propTypes2["default"].any,
43 tabBarPosition: _propTypes2["default"].string
44 },
45 getDefaultProps: function getDefaultProps() {
46 return {
47 animated: true
48 };
49 },
50 getTabPanes: function getTabPanes() {
51 var props = this.props;
52 var activeKey = props.activeKey;
53 var children = props.children;
54 var newChildren = [];
55
56 _react2["default"].Children.forEach(children, function (child) {
57 if (!child) {
58 return;
59 }
60 var key = child.key;
61 var active = activeKey === key;
62 newChildren.push(_react2["default"].cloneElement(child, {
63 active: active,
64 destroyInactiveTabPane: props.destroyInactiveTabPane,
65 rootclsPrefix: props.clsPrefix
66 }));
67 });
68
69 return newChildren;
70 },
71 render: function render() {
72 var _classnames;
73
74 var props = this.props;
75 var clsPrefix = props.clsPrefix,
76 children = props.children,
77 activeKey = props.activeKey,
78 tabBarPosition = props.tabBarPosition,
79 animated = props.animated,
80 animatedWithMargin = props.animatedWithMargin;
81 var style = props.style;
82
83 var classes = (0, _classnames3["default"])((_classnames = {}, _defineProperty(_classnames, clsPrefix + '-content', true), _defineProperty(_classnames, animated ? clsPrefix + '-content-animated' : clsPrefix + '-content-no-animated', true), _classnames));
84 if (animated) {
85 var activeIndex = (0, _utils.getActiveIndex)(children, activeKey);
86 if (activeIndex !== -1) {
87 var animatedStyle = animatedWithMargin ? (0, _utils.getMarginStyle)(activeIndex, tabBarPosition) : (0, _utils.getTransformPropValue)((0, _utils.getTransformByIndex)(activeIndex, tabBarPosition));
88 style = _extends({}, style, animatedStyle);
89 } else {
90 style = _extends({}, style, {
91 display: 'none'
92 });
93 }
94 }
95 return _react2["default"].createElement(
96 'div',
97 {
98 className: classes,
99 style: style
100 },
101 this.getTabPanes()
102 );
103 }
104});
105
106exports["default"] = TabContent;
107module.exports = exports['default'];
\No newline at end of file