UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

125 lines (104 loc) 4.65 kB
'use strict'; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); require('./YYLayoutPanel.less'); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _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; } function _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) : subClass.__proto__ = superClass; } var YYLayoutPanel = function (_React$Component) { _inherits(YYLayoutPanel, _React$Component); function YYLayoutPanel(props) { _classCallCheck(this, YYLayoutPanel); var _this = _possibleConstructorReturn(this, (YYLayoutPanel.__proto__ || Object.getPrototypeOf(YYLayoutPanel)).call(this, props)); _this.state = { content: '', lineClass: '' }; return _this; } _createClass(YYLayoutPanel, [{ key: 'getCondition', value: function getCondition(position, visible) { var children = this.props.children; var style = { position: position }; var panelClassName = (0, _classnames2.default)({ 'yy-layout-panel': true, 'hidden': !visible }); panelClassName = panelClassName; return panelClassName; } }, { key: 'getContent', value: function getContent(position) { var children = this.props.children; var positionContent = ''; switch (position) { case 'top': positionContent = '头部区域'; break; case 'center': positionContent = '中部区域'; break; case 'bottom': positionContent = '底部区域'; break; default: positionContent = ''; break; } this.setState({ content: positionContent, lineClass: children && children.length > 0 || position === 'center' ? "" : position }); } }, { key: 'componentDidMount', value: function componentDidMount() { var _props = this.props, RunInDesign = _props.RunInDesign, position = _props.position; if (RunInDesign) { this.getContent(position); } } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextprops) { if (nextprops.RunInDesign) { this.getContent(nextprops.position); } } }, { key: 'render', value: function render() { var _props2 = this.props, position = _props2.position, height = _props2.height, visible = _props2.visible, children = _props2.children, style = _props2.style; var _state = this.state, content = _state.content, lineClass = _state.lineClass; var panelClassName = this.getCondition(position, visible) + ' ' + lineClass; children = children && children.constructor == Array ? children : [children]; return _react2.default.createElement( 'div', { style: Object.assign({}, style, { height: height }), className: panelClassName }, children && children.length > 0 ? children : content ); } }]); return YYLayoutPanel; }(_react2.default.Component); YYLayoutPanel.defaultProps = { position: "", visible: true }; module.exports = YYLayoutPanel;