@txdfe/at
Version:
一个设计体系组件库
195 lines (151 loc) • 11 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["prefix", "pure", "wrap", "fixed", "gutter", "fixedWidth", "align", "justify", "hidden", "className", "component", "children", "rtl"];
function _extends() { _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; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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; }
import React, { Component, Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
/**
* Grid.Row
* @order 1
*/
var Row = /*#__PURE__*/function (_Component) {
_inherits(Row, _Component);
var _super = _createSuper(Row);
function Row() {
_classCallCheck(this, Row);
return _super.apply(this, arguments);
}
_createClass(Row, [{
key: "render",
value: function render() {
var _objectSpread2;
/* eslint-disable no-unused-vars */
var _this$props = this.props,
prefix = _this$props.prefix,
pure = _this$props.pure,
wrap = _this$props.wrap,
fixed = _this$props.fixed,
gutter = _this$props.gutter,
fixedWidth = _this$props.fixedWidth,
align = _this$props.align,
justify = _this$props.justify,
hidden = _this$props.hidden,
className = _this$props.className,
Tag = _this$props.component,
children = _this$props.children,
rtl = _this$props.rtl,
others = _objectWithoutProperties(_this$props, _excluded);
/* eslint-enable no-unused-vars */
var hiddenClassObj;
if (hidden === true) {
hiddenClassObj = _defineProperty({}, "".concat(prefix, "row-hidden"), true);
} else if (typeof hidden === 'string') {
hiddenClassObj = _defineProperty({}, "".concat(prefix, "row-").concat(hidden, "-hidden"), !!hidden);
} else if (Array.isArray(hidden)) {
hiddenClassObj = hidden.reduce(function (ret, point) {
ret["".concat(prefix, "row-").concat(point, "-hidden")] = !!point;
return ret;
}, {});
}
var newClassName = cx(_objectSpread(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(prefix, "row"), true), _defineProperty(_objectSpread2, "".concat(prefix, "row-wrap"), wrap), _defineProperty(_objectSpread2, "".concat(prefix, "row-fixed"), fixed), _defineProperty(_objectSpread2, "".concat(prefix, "row-fixed-").concat(fixedWidth), !!fixedWidth), _defineProperty(_objectSpread2, "".concat(prefix, "row-justify-").concat(justify), !!justify), _defineProperty(_objectSpread2, "".concat(prefix, "row-align-").concat(align), !!align), _objectSpread2), hiddenClassObj), {}, _defineProperty({}, className, !!className)));
var newChildren = children;
var gutterNumber = parseInt(gutter, 10);
if (gutterNumber !== 0) {
var halfGutterString = "".concat(gutterNumber / 2, "px");
others.style = _objectSpread({
marginLeft: "-".concat(halfGutterString),
marginRight: "-".concat(halfGutterString)
}, others.style || {});
newChildren = Children.map(children, function (child) {
if (child && child.type && typeof child.type === 'function' && child.type.isNextCol) {
var newChild = /*#__PURE__*/cloneElement(child, {
style: _objectSpread({
paddingLeft: halfGutterString,
paddingRight: halfGutterString
}, child.style || {})
});
return newChild;
}
return child;
});
}
return /*#__PURE__*/React.createElement(Tag, _extends({
dir: rtl ? 'rtl' : 'ltr',
role: "row",
className: newClassName
}, others), newChildren);
}
}]);
return Row;
}(Component);
_defineProperty(Row, "propTypes", {
prefix: PropTypes.string,
pure: PropTypes.bool,
rtl: PropTypes.bool,
className: PropTypes.string,
style: PropTypes.object,
/**
* 行内容
*/
children: PropTypes.node,
/**
* 列间隔
*/
gutter: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* 列在行中宽度溢出后是否换行
*/
wrap: PropTypes.bool,
/**
* 行在某一断点下宽度是否保持不变(默认行宽度随视口变化而变化)
*/
fixed: PropTypes.bool,
/**
* 固定行的宽度为某一断点的宽度,不受视口影响而变动
* @enumdesc 320px, 480px, 720px, 990px, 1200px, 1500px
*/
fixedWidth: PropTypes.oneOf(['xxs', 'xs', 's', 'm', 'l', 'xl']),
/**
* (不支持IE9浏览器)多列垂直方向对齐方式
* @enumdesc 顶部对齐, 居中对齐, 底部对齐, 按第一行文字基线对齐, 未设置高度或设为 auto,将占满整个容器的高度
*/
align: PropTypes.oneOf(['top', 'center', 'bottom', 'baseline', 'stretch']),
/**
* (不支持IE9浏览器)行内具有多余空间时的布局方式
* @enumdesc 左对齐, 居中对齐, 右对齐, 两端对齐,列之间间距相等, 每列具有相同的左右间距,行两端间距是列间距的二分之一
*/
justify: PropTypes.oneOf(['start', 'center', 'end', 'space-between', 'space-around']),
/**
* 行在不同断点下的显示与隐藏<br><br>**可选值**:<br>true(在所有断点下隐藏)<br>false(在所有断点下显示)<br>'xs'(在 xs 断点下隐藏)<br>['xxs', 'xs', 's', 'm', 'l', 'xl'](在 xxs, xs, s, m, l, xl 断点下隐藏)
*/
hidden: PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.array]),
/**
* 指定以何种元素渲染该节点
* - 默认为 'div'
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
});
_defineProperty(Row, "defaultProps", {
prefix: 'next-',
pure: false,
fixed: false,
gutter: 0,
wrap: false,
component: 'div'
});
export { Row as default };