chowa
Version:
UI component library based on React
44 lines (43 loc) • 1.58 kB
JavaScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const PropTypes = require("prop-types");
const classnames_1 = require("classnames");
const utils_1 = require("../utils");
const breadcrumb_item_1 = require("./breadcrumb-item");
const Breadcrumb = ({ children, className, style, separator }) => {
const componentClass = classnames_1.default({
[utils_1.preClass('breadcrumb')]: true,
[className]: utils_1.isExist(className)
});
const count = React.Children.count(children);
const nodes = [];
React.Children.forEach(children, (child, key) => {
if (!utils_1.isReactElement(child) || child.type !== breadcrumb_item_1.default) {
return;
}
nodes.push(React.cloneElement(child, { key }));
if (key < count - 1) {
nodes.push(React.createElement("li", { key: count + key, className: utils_1.preClass('breadcrumb-separator') }, separator));
}
});
return (React.createElement("ul", { style: style, className: componentClass }, nodes));
};
Breadcrumb.propTypes = {
className: PropTypes.string,
style: PropTypes.object,
separator: PropTypes.node.isRequired
};
Breadcrumb.defaultProps = {
separator: '/'
};
Breadcrumb.Item = breadcrumb_item_1.default;
exports.default = Breadcrumb;