mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
Merge branch 'master' of https://github.com/plandem/ant-design into plandem-master
This commit is contained in:
commit
378b6b84a5
@ -1,12 +1,24 @@
|
|||||||
import React, { cloneElement } from 'react';
|
import React, { cloneElement } from 'react';
|
||||||
import BreadcrumbItem from './BreadcrumbItem';
|
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 {
|
export default class Breadcrumb extends React.Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
prefixCls: 'ant-breadcrumb',
|
prefixCls: 'ant-breadcrumb',
|
||||||
separator: '/',
|
separator: '/',
|
||||||
linkRender: (href, name) => <a href={`#${href}`}>{name}</a>,
|
linkRender: (paths, name) => <a href={`#/${paths.join('/')}`}>{name}</a>,
|
||||||
nameRender: (name) => <span>{name}</span>,
|
nameRender: (name) => <span>{name}</span>,
|
||||||
|
nameFormatter: defaultNameFormatter,
|
||||||
}
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -19,13 +31,15 @@ export default class Breadcrumb extends React.Component {
|
|||||||
params: React.PropTypes.object,
|
params: React.PropTypes.object,
|
||||||
linkRender: React.PropTypes.func,
|
linkRender: React.PropTypes.func,
|
||||||
nameRender: React.PropTypes.func,
|
nameRender: React.PropTypes.func,
|
||||||
|
nameFormatter: React.PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let crumbs;
|
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) {
|
if (routes && routes.length > 0) {
|
||||||
const paths = [];
|
const paths = [];
|
||||||
|
const lastPath = routes.length - 1;
|
||||||
crumbs = routes.map((route, i) => {
|
crumbs = routes.map((route, i) => {
|
||||||
route.path = route.path || '';
|
route.path = route.path || '';
|
||||||
let path = route.path.replace(/^\//, '');
|
let path = route.path.replace(/^\//, '');
|
||||||
@ -36,20 +50,13 @@ export default class Breadcrumb extends React.Component {
|
|||||||
paths.push(path);
|
paths.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!route.breadcrumbName) {
|
const name = nameFormatter(route, params);
|
||||||
return null;
|
if (name) {
|
||||||
|
const link = (i === lastPath) ? nameRender(name) : linkRender(paths, name);
|
||||||
|
return <BreadcrumbItem separator={separator} key={name}>{link}</BreadcrumbItem>;
|
||||||
}
|
}
|
||||||
const name = route.breadcrumbName.replace(/:(.*)/g, (replacement, key) => {
|
|
||||||
return params[key] || replacement;
|
|
||||||
});
|
|
||||||
|
|
||||||
let link;
|
return null;
|
||||||
if (i === routes.length - 1) {
|
|
||||||
link = nameRender(name);
|
|
||||||
} else {
|
|
||||||
link = linkRender(`/${paths.join('/')}`, name);
|
|
||||||
}
|
|
||||||
return <BreadcrumbItem separator={separator} key={name}>{link}</BreadcrumbItem>;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
crumbs = React.Children.map(children, (element, index) => {
|
crumbs = React.Children.map(children, (element, index) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user