@txdfe/at
Version:
一个设计体系组件库
159 lines (157 loc) • 11.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _excluded = ["prefix", "pure", "wrap", "fixed", "gutter", "fixedWidth", "align", "justify", "hidden", "className", "component", "children", "rtl"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
* Grid.Row
* @order 1
*/
var Row = exports["default"] = /*#__PURE__*/function (_Component) {
function Row() {
_classCallCheck(this, Row);
return _callSuper(this, Row, arguments);
}
_inherits(Row, _Component);
return _createClass(Row, [{
key: "render",
value: function render() {
/* 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 = (0, _classnames["default"])(_objectSpread(_objectSpread(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefix, "row"), true), "".concat(prefix, "row-wrap"), wrap), "".concat(prefix, "row-fixed"), fixed), "".concat(prefix, "row-fixed-").concat(fixedWidth), !!fixedWidth), "".concat(prefix, "row-justify-").concat(justify), !!justify), "".concat(prefix, "row-align-").concat(align), !!align), 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 = _react.Children.map(children, function (child) {
if (child && child.type && typeof child.type === 'function' && child.type.isNextCol) {
var newChild = /*#__PURE__*/(0, _react.cloneElement)(child, {
style: _objectSpread({
paddingLeft: halfGutterString,
paddingRight: halfGutterString
}, child.style || {})
});
return newChild;
}
return child;
});
}
return /*#__PURE__*/_react["default"].createElement(Tag, _extends({
dir: rtl ? 'rtl' : 'ltr',
role: "row",
className: newClassName
}, others), newChildren);
}
}]);
}(_react.Component);
_defineProperty(Row, "propTypes", {
prefix: _propTypes["default"].string,
pure: _propTypes["default"].bool,
rtl: _propTypes["default"].bool,
className: _propTypes["default"].string,
style: _propTypes["default"].object,
/**
* 行内容
*/
children: _propTypes["default"].node,
/**
* 列间隔
*/
gutter: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/**
* 列在行中宽度溢出后是否换行
*/
wrap: _propTypes["default"].bool,
/**
* 行在某一断点下宽度是否保持不变(默认行宽度随视口变化而变化)
*/
fixed: _propTypes["default"].bool,
/**
* 固定行的宽度为某一断点的宽度,不受视口影响而变动
* @enumdesc 320px, 480px, 720px, 990px, 1200px, 1500px
*/
fixedWidth: _propTypes["default"].oneOf(['xxs', 'xs', 's', 'm', 'l', 'xl']),
/**
* (不支持IE9浏览器)多列垂直方向对齐方式
* @enumdesc 顶部对齐, 居中对齐, 底部对齐, 按第一行文字基线对齐, 未设置高度或设为 auto,将占满整个容器的高度
*/
align: _propTypes["default"].oneOf(['top', 'center', 'bottom', 'baseline', 'stretch']),
/**
* (不支持IE9浏览器)行内具有多余空间时的布局方式
* @enumdesc 左对齐, 居中对齐, 右对齐, 两端对齐,列之间间距相等, 每列具有相同的左右间距,行两端间距是列间距的二分之一
*/
justify: _propTypes["default"].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["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].string, _propTypes["default"].array]),
/**
* 指定以何种元素渲染该节点
* - 默认为 'div'
*/
component: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func])
});
_defineProperty(Row, "defaultProps", {
prefix: 'next-',
pure: false,
fixed: false,
gutter: 0,
wrap: false,
component: 'div'
});