UNPKG

6.13 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6
7var _class, _temp;
8
9import React, { Component, Children, cloneElement } from 'react';
10import PropTypes from 'prop-types';
11import cx from 'classnames';
12
13/**
14 * Grid.Row
15 * @order 1
16 */
17var Row = (_temp = _class = function (_Component) {
18 _inherits(Row, _Component);
19
20 function Row() {
21 _classCallCheck(this, Row);
22
23 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
24 }
25
26 Row.prototype.render = function render() {
27 var _extends2, _extends3;
28
29 /* eslint-disable no-unused-vars */
30 var _props = this.props,
31 prefix = _props.prefix,
32 pure = _props.pure,
33 wrap = _props.wrap,
34 fixed = _props.fixed,
35 gutter = _props.gutter,
36 fixedWidth = _props.fixedWidth,
37 align = _props.align,
38 justify = _props.justify,
39 hidden = _props.hidden,
40 className = _props.className,
41 Tag = _props.component,
42 children = _props.children,
43 rtl = _props.rtl,
44 others = _objectWithoutProperties(_props, ['prefix', 'pure', 'wrap', 'fixed', 'gutter', 'fixedWidth', 'align', 'justify', 'hidden', 'className', 'component', 'children', 'rtl']);
45 /* eslint-enable no-unused-vars */
46
47 var hiddenClassObj = void 0;
48 if (hidden === true) {
49 var _hiddenClassObj;
50
51 hiddenClassObj = (_hiddenClassObj = {}, _hiddenClassObj[prefix + 'row-hidden'] = true, _hiddenClassObj);
52 } else if (typeof hidden === 'string') {
53 var _hiddenClassObj2;
54
55 hiddenClassObj = (_hiddenClassObj2 = {}, _hiddenClassObj2[prefix + 'row-' + hidden + '-hidden'] = !!hidden, _hiddenClassObj2);
56 } else if (Array.isArray(hidden)) {
57 hiddenClassObj = hidden.reduce(function (ret, point) {
58 ret[prefix + 'row-' + point + '-hidden'] = !!point;
59 return ret;
60 }, {});
61 }
62
63 var newClassName = cx(_extends((_extends2 = {}, _extends2[prefix + 'row'] = true, _extends2[prefix + 'row-wrap'] = wrap, _extends2[prefix + 'row-fixed'] = fixed, _extends2[prefix + 'row-fixed-' + fixedWidth] = !!fixedWidth, _extends2[prefix + 'row-justify-' + justify] = !!justify, _extends2[prefix + 'row-align-' + align] = !!align, _extends2), hiddenClassObj, (_extends3 = {}, _extends3[className] = !!className, _extends3)));
64
65 var newChildren = children;
66 var gutterNumber = parseInt(gutter, 10);
67 if (gutterNumber !== 0) {
68 var halfGutterString = gutterNumber / 2 + 'px';
69 others.style = _extends({
70 marginLeft: '-' + halfGutterString,
71 marginRight: '-' + halfGutterString
72 }, others.style || {});
73 newChildren = Children.map(children, function (child) {
74 if (child && child.type && typeof child.type === 'function' && child.type.isNextCol) {
75 var newChild = cloneElement(child, {
76 style: _extends({
77 paddingLeft: halfGutterString,
78 paddingRight: halfGutterString
79 }, child.style || {})
80 });
81 return newChild;
82 }
83
84 return child;
85 });
86 }
87
88 return React.createElement(
89 Tag,
90 _extends({
91 dir: rtl ? 'rtl' : 'ltr',
92 role: 'row',
93 className: newClassName
94 }, others),
95 newChildren
96 );
97 };
98
99 return Row;
100}(Component), _class.propTypes = {
101 prefix: PropTypes.string,
102 pure: PropTypes.bool,
103 rtl: PropTypes.bool,
104 className: PropTypes.string,
105 style: PropTypes.object,
106 /**
107 * 行内容
108 */
109 children: PropTypes.node,
110 /**
111 * 列间隔
112 */
113 gutter: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
114 /**
115 * 列在行中宽度溢出后是否换行
116 */
117 wrap: PropTypes.bool,
118 /**
119 * 行在某一断点下宽度是否保持不变(默认行宽度随视口变化而变化)
120 */
121 fixed: PropTypes.bool,
122 /**
123 * 固定行的宽度为某一断点的宽度,不受视口影响而变动
124 * @enumdesc 320px, 480px, 720px, 990px, 1200px, 1500px
125 */
126 fixedWidth: PropTypes.oneOf(['xxs', 'xs', 's', 'm', 'l', 'xl']),
127 /**
128 * (不支持IE9浏览器)多列垂直方向对齐方式
129 * @enumdesc 顶部对齐, 居中对齐, 底部对齐, 按第一行文字基线对齐, 未设置高度或设为 auto,将占满整个容器的高度
130 */
131 align: PropTypes.oneOf(['top', 'center', 'bottom', 'baseline', 'stretch']),
132 /**
133 * (不支持IE9浏览器)行内具有多余空间时的布局方式
134 * @enumdesc 左对齐, 居中对齐, 右对齐, 两端对齐,列之间间距相等, 每列具有相同的左右间距,行两端间距是列间距的二分之一
135 */
136 justify: PropTypes.oneOf(['start', 'center', 'end', 'space-between', 'space-around']),
137 /**
138 * 行在不同断点下的显示与隐藏<br><br>**可选值**:<br>true(在所有断点下隐藏)<br>false(在所有断点下显示)<br>'xs'(在 xs 断点下隐藏)<br>['xxs', 'xs', 's', 'm', 'l', 'xl'](在 xxs, xs, s, m, l, xl 断点下隐藏)
139 */
140 hidden: PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.array]),
141 /**
142 * 指定以何种元素渲染该节点
143 * - 默认为 'div'
144 */
145 component: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
146}, _class.defaultProps = {
147 prefix: 'next-',
148 pure: false,
149 fixed: false,
150 gutter: 0,
151 wrap: false,
152 component: 'div'
153}, _temp);
154Row.displayName = 'Row';
155export { Row as default };
\No newline at end of file