UNPKG

4.86 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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; };
8
9var _classnames = require('classnames');
10
11var _classnames2 = _interopRequireDefault(_classnames);
12
13var _react = require('react');
14
15var _react2 = _interopRequireDefault(_react);
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18
19function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
20
21function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
22
23function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
27function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
28
29var propTypes = {
30 componentClass: _react.PropTypes.oneOfType([_react2["default"].PropTypes.element, _react2["default"].PropTypes.string]),
31
32 /**
33 * xs显示列数
34 */
35 xs: _react.PropTypes.number,
36 /**
37 * sm显示列数
38 */
39 sm: _react.PropTypes.number,
40 /**
41 * md显示列数
42 */
43 md: _react.PropTypes.number,
44 /**
45 * lg显示列数
46 */
47 lg: _react.PropTypes.number,
48 /**
49 * xs偏移列数
50 */
51 xsOffset: _react.PropTypes.number,
52 /**
53 * sm偏移列数
54 */
55 smOffset: _react.PropTypes.number,
56 /**
57 * md偏移列数
58 */
59 mdOffset: _react.PropTypes.number,
60 /**
61 * lg偏移列数
62 */
63 lgOffset: _react.PropTypes.number,
64 /**
65 * xs右偏移列数
66 */
67 xsPush: _react.PropTypes.number,
68 /**
69 * sm右偏移列数
70 */
71 smPush: _react.PropTypes.number,
72 /**
73 * md右偏移列数
74 */
75 mdPush: _react.PropTypes.number,
76 /**
77 * lg右偏移列数
78 */
79 lgPush: _react.PropTypes.number,
80 /**
81 * xs左偏移列数
82 */
83 xsPull: _react.PropTypes.number,
84 /**
85 * sm左偏移列数
86 */
87 smPull: _react.PropTypes.number,
88 /**
89 * md左偏移列数
90 */
91 mdPull: _react.PropTypes.number,
92 /**
93 * lg左偏移列数
94 */
95 lgPull: _react.PropTypes.number
96};
97
98var defaultProps = {
99 componentClass: 'div',
100 clsPrefix: 'u-col'
101};
102
103var DEVICE_SIZES = ['lg', 'md', 'sm', 'xs'];
104
105var Col = function (_Component) {
106 _inherits(Col, _Component);
107
108 function Col() {
109 _classCallCheck(this, Col);
110
111 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
112 }
113
114 Col.prototype.render = function render() {
115 var _props = this.props,
116 Component = _props.componentClass,
117 className = _props.className,
118 clsPrefix = _props.clsPrefix,
119 others = _objectWithoutProperties(_props, ['componentClass', 'className', 'clsPrefix']);
120
121 var tbClass = [];
122 /**
123 * 对传入props做样式转化
124 * @type {[type]}
125 */
126 DEVICE_SIZES.forEach(function (size) {
127 function popProp(propSuffix, modifier) {
128 var propName = '' + size + propSuffix;
129 var propValue = others[propName];
130
131 if (propValue != undefined && propValue != null) {
132 tbClass.push(clsPrefix + '-' + size + modifier + '-' + propValue);
133 }
134
135 delete others[propName];
136 }
137
138 popProp('', '');
139 popProp('Offset', '-offset');
140 popProp('Push', '-push');
141 popProp('Pull', '-pull');
142 });
143
144 return _react2["default"].createElement(
145 Component,
146 _extends({
147 className: (0, _classnames2["default"])(tbClass, className)
148 }, others),
149 this.props.children
150 );
151 };
152
153 return Col;
154}(_react.Component);
155
156Col.propTypes = propTypes;
157Col.defaultProps = defaultProps;
158
159exports["default"] = Col;
160module.exports = exports['default'];
\No newline at end of file