1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _react = require('react');
|
8 |
|
9 | var _react2 = _interopRequireDefault(_react);
|
10 |
|
11 | var _propTypes = require('prop-types');
|
12 |
|
13 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
14 |
|
15 | var _classnames2 = require('classnames');
|
16 |
|
17 | var _classnames3 = _interopRequireDefault(_classnames2);
|
18 |
|
19 | var _utils = require('./utils');
|
20 |
|
21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
22 |
|
23 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
24 |
|
25 | function _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; }
|
26 |
|
27 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
28 |
|
29 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
30 |
|
31 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function _componentDidUpdate(component, init) {
|
38 | var _component$props = component.props,
|
39 | styles = _component$props.styles,
|
40 | panels = _component$props.panels,
|
41 | activeKey = _component$props.activeKey,
|
42 | direction = _component$props.direction;
|
43 |
|
44 | var rootNode = component.props.getRef('root');
|
45 | var wrapNode = component.props.getRef('nav') || rootNode;
|
46 | var inkBarNode = component.props.getRef('inkBar');
|
47 | var activeTab = component.props.getRef('activeTab');
|
48 | var inkBarNodeStyle = inkBarNode.style;
|
49 | var tabBarPosition = component.props.tabBarPosition;
|
50 | var activeIndex = (0, _utils.getActiveIndex)(panels, activeKey);
|
51 | if (init) {
|
52 |
|
53 | inkBarNodeStyle.display = 'none';
|
54 | }
|
55 | if (activeTab) {
|
56 | var tabNode = activeTab;
|
57 | var transformSupported = (0, _utils.isTransformSupported)(inkBarNodeStyle);
|
58 |
|
59 |
|
60 | (0, _utils.setTransform)(inkBarNodeStyle, '');
|
61 | inkBarNodeStyle.width = '';
|
62 | inkBarNodeStyle.height = '';
|
63 | inkBarNodeStyle.left = '';
|
64 | inkBarNodeStyle.top = '';
|
65 | inkBarNodeStyle.bottom = '';
|
66 | inkBarNodeStyle.right = '';
|
67 |
|
68 | if (tabBarPosition === 'top' || tabBarPosition === 'bottom') {
|
69 | var left = (0, _utils.getLeft)(tabNode, wrapNode);
|
70 | var width = tabNode.offsetWidth;
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | if (width === rootNode.offsetWidth) {
|
76 | width = 0;
|
77 | } else if (styles.inkBar && styles.inkBar.width !== undefined) {
|
78 | width = parseFloat(styles.inkBar.width, 10);
|
79 | if (width) {
|
80 | left += (tabNode.offsetWidth - width) / 2;
|
81 | }
|
82 | }
|
83 | if (direction === 'rtl') {
|
84 | left = (0, _utils.getStyle)(tabNode, 'margin-left') - left;
|
85 | }
|
86 |
|
87 | if (transformSupported) {
|
88 | (0, _utils.setTransform)(inkBarNodeStyle, 'translate3d(' + left + 'px,0,0)');
|
89 | } else {
|
90 | inkBarNodeStyle.left = left + 'px';
|
91 | }
|
92 | inkBarNodeStyle.width = width + 'px';
|
93 | } else {
|
94 | var top = (0, _utils.getTop)(tabNode, wrapNode, true);
|
95 | var height = tabNode.offsetHeight;
|
96 | if (styles.inkBar && styles.inkBar.height !== undefined) {
|
97 | height = parseFloat(styles.inkBar.height, 10);
|
98 | if (height) {
|
99 | top += (tabNode.offsetHeight - height) / 2;
|
100 | }
|
101 | }
|
102 | if (transformSupported) {
|
103 | (0, _utils.setTransform)(inkBarNodeStyle, 'translate3d(0,' + top + 'px,0)');
|
104 | inkBarNodeStyle.top = '0';
|
105 | } else {
|
106 | inkBarNodeStyle.top = top + 'px';
|
107 | }
|
108 | inkBarNodeStyle.height = height + 'px';
|
109 | }
|
110 | }
|
111 | inkBarNodeStyle.display = activeIndex !== -1 ? 'block' : 'none';
|
112 | }
|
113 |
|
114 | var InkTabBarNode = function (_React$Component) {
|
115 | _inherits(InkTabBarNode, _React$Component);
|
116 |
|
117 | function InkTabBarNode() {
|
118 | _classCallCheck(this, InkTabBarNode);
|
119 |
|
120 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
121 | }
|
122 |
|
123 | InkTabBarNode.prototype.componentDidMount = function componentDidMount() {
|
124 | var _this2 = this;
|
125 |
|
126 | this.timeout = setTimeout(function () {
|
127 | _componentDidUpdate(_this2, true);
|
128 | }, 0);
|
129 | };
|
130 |
|
131 | InkTabBarNode.prototype.componentDidUpdate = function componentDidUpdate() {
|
132 | _componentDidUpdate(this);
|
133 | };
|
134 |
|
135 | InkTabBarNode.prototype.componentWillUnmount = function componentWillUnmount() {
|
136 | clearTimeout(this.timeout);
|
137 | };
|
138 |
|
139 | InkTabBarNode.prototype.render = function render() {
|
140 | var _classnames;
|
141 |
|
142 | var _props = this.props,
|
143 | clsPrefix = _props.clsPrefix,
|
144 | styles = _props.styles,
|
145 | inkBarAnimated = _props.inkBarAnimated;
|
146 |
|
147 | var className = clsPrefix + '-ink-bar';
|
148 | var classes = (0, _classnames3["default"])((_classnames = {}, _defineProperty(_classnames, className, true), _defineProperty(_classnames, inkBarAnimated ? className + '-animated' : className + '-no-animated', true), _classnames));
|
149 | return _react2["default"].createElement('div', {
|
150 | style: styles.inkBar,
|
151 | className: classes,
|
152 | key: 'inkBar',
|
153 | ref: this.props.saveRef('inkBar')
|
154 | });
|
155 | };
|
156 |
|
157 | return InkTabBarNode;
|
158 | }(_react2["default"].Component);
|
159 |
|
160 | exports["default"] = InkTabBarNode;
|
161 |
|
162 |
|
163 | InkTabBarNode.propTypes = {
|
164 | clsPrefix: _propTypes2["default"].string,
|
165 | styles: _propTypes2["default"].object,
|
166 | inkBarAnimated: _propTypes2["default"].bool,
|
167 | saveRef: _propTypes2["default"].func,
|
168 | direction: _propTypes2["default"].string
|
169 | };
|
170 |
|
171 | InkTabBarNode.defaultProps = {
|
172 | clsPrefix: '',
|
173 | inkBarAnimated: true,
|
174 | styles: {},
|
175 | saveRef: function saveRef() {}
|
176 | };
|
177 | module.exports = exports['default']; |
\ | No newline at end of file |