1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 |
|
4 | export function toArrayChildren(children) {
|
5 | var ret = [];
|
6 | React.Children.forEach(children, function (c) {
|
7 | ret.push(c);
|
8 | });
|
9 | return ret;
|
10 | }
|
11 |
|
12 | export function dataToArray(vars) {
|
13 | if (!vars && vars !== 0) {
|
14 | return [];
|
15 | }
|
16 | if (Array.isArray(vars)) {
|
17 | return vars;
|
18 | }
|
19 | return [vars];
|
20 | }
|
21 |
|
22 | export function setAnimCompToTagComp(item, i) {
|
23 | if (!item) {
|
24 | return null;
|
25 | }
|
26 | var itemProps = item.props;
|
27 | var props = {};
|
28 | props.key = item.key || i;
|
29 |
|
30 | var domAttrArray = ['accesskey', 'classname', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title'];
|
31 | Object.keys(itemProps).forEach(function (key) {
|
32 | if (domAttrArray.indexOf(key.toLocaleLowerCase()) >= 0 || key.match('data-')) {
|
33 | props[key] = itemProps[key];
|
34 | }
|
35 | });
|
36 | return React.createElement(itemProps.component, props, itemProps.children);
|
37 | }
|
38 | setAnimCompToTagComp.propTypes = {
|
39 | key: PropTypes.string
|
40 | };
|
41 |
|
42 | export function currentScrollTop() {
|
43 | return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
|
44 | }
|
45 |
|
46 | export function currentScrollLeft() {
|
47 | return window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
|
48 | }
|
49 |
|
50 | export function windowHeight() {
|
51 | return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
52 | }
|
53 |
|
54 | export function switchChildren(hideProps, item) {
|
55 | if (!hideProps) {
|
56 | return item;
|
57 | }
|
58 | if (item.type.isTweenOne) {
|
59 | return React.cloneElement(item, { reverse: true });
|
60 | }
|
61 | return React.cloneElement(item, item.props, null);
|
62 | } |
\ | No newline at end of file |