UNPKG

2.1 kBJavaScriptView Raw
1import _typeof from 'babel-runtime/helpers/typeof';
2import React from 'react';
3
4export var triggerEvents = {
5 CLICK: 'click',
6 HOVER: 'hover'
7};
8
9export function getOffsetWH(node, tabPosition) {
10 var prop = 'width';
11 if (tabPosition === 'left' || tabPosition === 'right') {
12 prop = 'height';
13 }
14 return node ? node.getBoundingClientRect()[prop] : 0;
15}
16
17export function getOffsetLT(node, tabPosition) {
18 var prop = 'left';
19 if (tabPosition === 'left' || tabPosition === 'right') {
20 prop = 'top';
21 }
22 return node.getBoundingClientRect()[prop];
23}
24
25export function isTransformSupported(style) {
26 return 'transform' in style || 'webkitTransform' in style || 'MozTransform' in style;
27}
28
29export function toArray(children) {
30 var ret = [];
31 React.Children.forEach(children, function (child, index) {
32 if (React.isValidElement(child)) {
33 ret.push(React.cloneElement(child, {
34 key: child.key || index,
35 title: child.props.title || child.props.tab
36 }));
37 }
38 });
39 return ret;
40}
41
42/**
43 * tab数组浅比较
44 * @param {Array} arrA 更新后的数组
45 * @param {Array} arrB 原数组
46 * @return {Boolean} 数组浅比较是否相等
47 * @example
48 * arr.tabsArrayShallowEqual(['2','3','4'], ['2','5','4']); // false
49 */
50
51export function tabsArrayShallowEqual(arrA, arrB) {
52 // 相同地址的返回true,不需要更新数据(更新数据的基础是props数据与当前获取的值不同)
53 if (arrA === arrB) {
54 return true;
55 }
56
57 // 判断:调用的值/是否为数组/数组的长度
58 if (!arrA || !arrB || (typeof arrA === 'undefined' ? 'undefined' : _typeof(arrA)) + (typeof arrB === 'undefined' ? 'undefined' : _typeof(arrB)) !== 'objectobject' || arrA.length !== arrB.length) {
59 return false;
60 }
61
62 // 判断tabs的key与title是否更改
63 for (var i = 0; i < arrA.length; i++) {
64 if (arrA[i].key !== arrB[i].key || arrA[i].props.title !== arrB[i].props.title) {
65 return false;
66 }
67 }
68 return true;
69}
\No newline at end of file