@txdfe/at
Version:
一个设计体系组件库
226 lines (169 loc) • 14.1 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", "span", "offset", "fixedSpan", "fixedOffset", "hidden", "align", "xxs", "xs", "s", "m", "l", "xl", "component", "className", "children", "rtl"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 _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); }
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; }
var breakPoints = ['xxs', 'xs', 's', 'm', 'l', 'xl'];
/**
* Grid.Col
* @order 2
*/
var Col = /*#__PURE__*/function (_Component) {
_inherits(Col, _Component);
var _super = _createSuper(Col);
function Col() {
_classCallCheck(this, Col);
return _super.apply(this, arguments);
}
_createClass(Col, [{
key: "render",
value: function render() {
var _this = this,
_objectSpread2;
/* eslint-disable no-unused-vars */
var _this$props = this.props,
prefix = _this$props.prefix,
pure = _this$props.pure,
span = _this$props.span,
offset = _this$props.offset,
fixedSpan = _this$props.fixedSpan,
fixedOffset = _this$props.fixedOffset,
hidden = _this$props.hidden,
align = _this$props.align,
xxs = _this$props.xxs,
xs = _this$props.xs,
s = _this$props.s,
m = _this$props.m,
l = _this$props.l,
xl = _this$props.xl,
Tag = _this$props.component,
className = _this$props.className,
children = _this$props.children,
rtl = _this$props.rtl,
others = _objectWithoutProperties(_this$props, _excluded);
/* eslint-enable no-unused-vars */
var pointClassObj = breakPoints.reduce(function (ret, point) {
var pointProps = {};
if (_typeof(_this.props[point]) === 'object') {
pointProps = _this.props[point];
} else {
pointProps.span = _this.props[point];
}
ret["".concat(prefix, "col-").concat(point, "-").concat(pointProps.span)] = !!pointProps.span;
ret["".concat(prefix, "col-").concat(point, "-offset-").concat(pointProps.offset)] = !!pointProps.offset;
return ret;
}, {});
var hiddenClassObj;
if (hidden === true) {
hiddenClassObj = _defineProperty({}, "".concat(prefix, "col-hidden"), true);
} else if (typeof hidden === 'string') {
hiddenClassObj = _defineProperty({}, "".concat(prefix, "col-").concat(hidden, "-hidden"), !!hidden);
} else if (Array.isArray(hidden)) {
hiddenClassObj = hidden.reduce(function (ret, point) {
ret["".concat(prefix, "col-").concat(point, "-hidden")] = !!point;
return ret;
}, {});
}
var classes = (0, _classnames["default"])(_objectSpread(_objectSpread(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(prefix, "col"), true), _defineProperty(_objectSpread2, "".concat(prefix, "col-").concat(span), !!span), _defineProperty(_objectSpread2, "".concat(prefix, "col-fixed-").concat(fixedSpan), !!fixedSpan), _defineProperty(_objectSpread2, "".concat(prefix, "col-offset-").concat(offset), !!offset), _defineProperty(_objectSpread2, "".concat(prefix, "col-offset-fixed-").concat(fixedOffset), !!fixedOffset), _defineProperty(_objectSpread2, "".concat(prefix, "col-").concat(align), !!align), _objectSpread2), pointClassObj), hiddenClassObj), {}, _defineProperty({}, className, className)));
return /*#__PURE__*/_react["default"].createElement(Tag, _extends({
dir: rtl ? 'rtl' : 'ltr',
role: "gridcell",
className: classes
}, others), children);
}
}]);
return Col;
}(_react.Component);
exports["default"] = Col;
_defineProperty(Col, "isNextCol", true);
_defineProperty(Col, "propTypes", {
prefix: _propTypes["default"].string,
pure: _propTypes["default"].bool,
rtl: _propTypes["default"].bool,
className: _propTypes["default"].string,
/**
* 列内容
*/
children: _propTypes["default"].node,
/**
* 列宽度<br><br>**可选值**:<br>1, 2, 3, ..., 22, 23, 24
*/
span: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/**
* 固定列宽度,宽度值为20 * 栅格数<br><br>**可选值**:<br>1, 2, 3, ..., 28, 29, 30
*/
fixedSpan: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/**
* (不支持IE9浏览器)列偏移<br><br>**可选值**:<br>1, 2, 3, ..., 22, 23, 24
*/
offset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/**
* (不支持IE9浏览器)固定列偏移,宽度值为20 * 栅格数<br><br>**可选值**:<br>1, 2, 3, ..., 28, 29, 30
*/
fixedOffset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/**
* (不支持IE9浏览器)多列垂直方向对齐方式,可覆盖Row的align属性
*/
align: _propTypes["default"].oneOf(['top', 'center', 'bottom', 'baseline', 'stretch']),
/**
* 列在不同断点下的显示与隐藏<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]),
/**
* >=320px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
xxs: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* >=480px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
xs: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* >=720px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
s: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* >=990px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
m: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* >=1200px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
l: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* >=1500px,响应式栅格,可为栅格数(span)或一个包含栅格数(span)和偏移栅格数(offset)对象
*/
xl: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].object]),
/**
* 指定以何种元素渲染该节点,默认为 'div'
*/
component: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func])
});
_defineProperty(Col, "defaultProps", {
prefix: 'next-',
pure: false,
component: 'div'
});