hy-checkbox
Version:
checkbox & radio ui components for react
182 lines (161 loc) • 9.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _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; };
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('./breadcrumb.less');
var _reactRouter = require('react-router');
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; } /*
* @Author: SiMeiyu
* @Date: 2017-07-04 09:56:23
*/
var Breadcrumb = function (_React$Component) {
_inherits(Breadcrumb, _React$Component);
function Breadcrumb(props) {
_classCallCheck(this, Breadcrumb);
var _this = _possibleConstructorReturn(this, (Breadcrumb.__proto__ || Object.getPrototypeOf(Breadcrumb)).call(this, props));
var routeList = void 0;
if (props.routes) {
routeList = _this.props.routes.filter(function (route) {
return route.path;
}).map(function (route, index, array) {
if (index == 0) {
return _extends({}, route, {
path: ""
});
} else {
var route_path = route.path.split("/");
var changePath = route_path.map(function (path) {
if (path.indexOf(":") >= 0) {
var start = path.indexOf(":") + 1;
var end = path.length;
var pathName = path.slice(start, end);
var pathId = _this.props.param['' + pathName];
return pathId;
}
return path;
});
var newPath = changePath.join("/");
return _extends({}, route, {
path: newPath
});
}
});
} else if (props.options) {
routeList = props.options;
}
_this.state = {
routeList: routeList
};
return _this;
}
_createClass(Breadcrumb, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.routes) {
this.setState({
routeList: nextProps.routes.filter(function (route) {
return route.path;
}).map(function (route, index, array) {
if (index == 0) {
return _extends({}, route, {
path: ""
});
} else {
var route_path = route.path.split("/");
var changePath = route_path.map(function (path) {
if (path.indexOf(":") >= 0) {
var start = path.indexOf(":") + 1;
var end = path.length;
var pathName = path.slice(start, end);
var pathId = nextProps.param['' + pathName];
return pathId;
}
return path;
});
var newPath = changePath.join("/");
return _extends({}, route, {
path: newPath
});
}
})
});
} else if (nextProps.options) {
this.setState({
routeList: nextProps.options
});
}
}
}, {
key: 'renderItems',
value: function renderItems() {
var _props = this.props,
routes = _props.routes,
param = _props.param,
options = _props.options;
var routeList = this.state.routeList;
// console.log("routeList-->", routeList);
if (routeList.length > 1) {
return routeList.map(function (item, index, array) {
if (index < array.length - 1) {
return _react2.default.createElement(
'li',
{ key: item.name },
_react2.default.createElement(
_reactRouter.Link,
{ to: item.path },
item.name
)
);
} else {
return _react2.default.createElement(
'li',
{ key: item.name },
item.name
);
}
});
}
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
prefixCls = _props2.prefixCls,
options = _props2.options;
var routeList = this.state.routeList;
var title = routeList.length > 1 ? routeList[1].name : routeList[0].name;
return _react2.default.createElement(
'div',
{ className: prefixCls + '-breadcrumb' },
_react2.default.createElement(
'h2',
null,
title
),
_react2.default.createElement(
'ul',
null,
this.renderItems()
)
);
}
}]);
return Breadcrumb;
}(_react2.default.Component);
Breadcrumb.propTypes = {
prefixCls: _react2.default.PropTypes.string,
routes: _react2.default.PropTypes.array,
param: _react2.default.PropTypes.object,
options: _react2.default.PropTypes.array
};
Breadcrumb.defaultProps = {
prefixCls: 'ult'
};
exports.default = Breadcrumb;
;