Merge branch 'master' of https://github.com/plandem/ant-design into plandem-master

This commit is contained in:
afc163 2016-06-11 15:16:10 +08:00
commit 378b6b84a5

View File

@ -1,12 +1,24 @@
import React, { cloneElement } from 'react';
import BreadcrumbItem from './BreadcrumbItem';
const defaultNameFormatter = (route, params) => {
if (!route.breadcrumbName) {
return null;
}
const name = route.breadcrumbName.replace(/:(.*)/g, (replacement, key) => {
return params[key] || replacement;
});
return name;
};
export default class Breadcrumb extends React.Component {
static defaultProps = {
prefixCls: 'ant-breadcrumb',
separator: '/',
linkRender: (href, name) => <a href={`#${href}`}>{name}</a>,
linkRender: (paths, name) => <a href={`#/${paths.join('/')}`}>{name}</a>,
nameRender: (name) => <span>{name}</span>,
nameFormatter: defaultNameFormatter,
}
static propTypes = {
@ -19,13 +31,15 @@ export default class Breadcrumb extends React.Component {
params: React.PropTypes.object,
linkRender: React.PropTypes.func,
nameRender: React.PropTypes.func,
nameFormatter: React.PropTypes.func,
}
render() {
let crumbs;
const { separator, prefixCls, routes, params, children, linkRender, nameRender } = this.props;
const { separator, prefixCls, routes, params, children, linkRender, nameRender, nameFormatter } = this.props;
if (routes && routes.length > 0) {
const paths = [];
const lastPath = routes.length - 1;
crumbs = routes.map((route, i) => {
route.path = route.path || '';
let path = route.path.replace(/^\//, '');
@ -36,20 +50,13 @@ export default class Breadcrumb extends React.Component {
paths.push(path);
}
if (!route.breadcrumbName) {
return null;
}
const name = route.breadcrumbName.replace(/:(.*)/g, (replacement, key) => {
return params[key] || replacement;
});
let link;
if (i === routes.length - 1) {
link = nameRender(name);
} else {
link = linkRender(`/${paths.join('/')}`, name);
}
const name = nameFormatter(route, params);
if (name) {
const link = (i === lastPath) ? nameRender(name) : linkRender(paths, name);
return <BreadcrumbItem separator={separator} key={name}>{link}</BreadcrumbItem>;
}
return null;
});
} else {
crumbs = React.Children.map(children, (element, index) => {