Browse Source

Add slash prop, close #641

pull/653/head
afc163 9 years ago
parent
commit
a068e58dd4
  1. 20
      components/breadcrumb/demo/slash.md
  2. 61
      components/breadcrumb/index.jsx
  3. 11
      components/breadcrumb/index.md

20
components/breadcrumb/demo/slash.md

@ -0,0 +1,20 @@
# 分隔符
- order: 3
使用 `slash=">"` 可以自定义分隔符。
---
````jsx
import { Breadcrumb } from 'antd';
ReactDOM.render(
<Breadcrumb slash=">">
<Breadcrumb.Item>首页</Breadcrumb.Item>
<Breadcrumb.Item href="">应用中心</Breadcrumb.Item>
<Breadcrumb.Item href="">应用列表</Breadcrumb.Item>
<Breadcrumb.Item>某应用</Breadcrumb.Item>
</Breadcrumb>
, document.getElementById('components-breadcrumb-demo-slash'));
````

61
components/breadcrumb/index.jsx

@ -1,52 +1,79 @@
import React from 'react';
import React, { cloneElement } from 'react';
let prefixCls = 'ant-breadcrumb';
let BreadcrumbItem = React.createClass({
const BreadcrumbItem = React.createClass({
getDefaultProps() {
return {
prefixCls: 'ant-breadcrumb',
slash: '/',
};
},
propTypes: {
href: React.PropTypes.string
prefixCls: React.PropTypes.string,
slash: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element,
]),
href: React.PropTypes.string,
},
render() {
let link = <a className={prefixCls + '-link'} {...this.props}>{this.props.children}</a>;
let slash = <span className={prefixCls + '-slash'}>/</span>;
const { prefixCls, slash, children } = this.props;
let link = <a className={prefixCls + '-link'} {...this.props}>{children}</a>;
if (typeof this.props.href === 'undefined') {
link = <span className={prefixCls + '-link'} {...this.props}>{this.props.children}</span>;
link = <span className={prefixCls + '-link'} {...this.props}>{children}</span>;
}
return <span>{link}{slash}</span>;
return <span>
{link}
<span className={prefixCls + '-slash'}>{slash}</span>
</span>;
}
});
let Breadcrumb = React.createClass({
const Breadcrumb = React.createClass({
getDefaultProps() {
return {
prefixCls: 'ant-breadcrumb',
slash: '/',
};
},
propTypes: {
prefixCls: React.PropTypes.string,
slash: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element,
]),
router: React.PropTypes.object,
routes: React.PropTypes.array,
params: React.PropTypes.object
},
render() {
let crumbs;
let ReactRouter = this.props.router;
let routes = this.props.routes;
let params = this.props.params;
const { slash, prefixCls, router, routes, params, children } = this.props;
const ReactRouter = router;
if (routes && routes.length > 0 && ReactRouter) {
let Link = ReactRouter.Link;
crumbs = routes.map(function(route, i) {
if (!route.breadcrumbName) {
return null;
}
let name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) {
const name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) {
return params[key] || replacement;
});
let link;
let path = route.path.indexOf('/') === 0 ? route.path : ('/' + route.path);
const path = route.path.indexOf('/') === 0 ? route.path : ('/' + route.path);
if (i === routes.length - 1) {
link = <span>{name}</span>;
} else {
link = <Link to={path} params={params}>{name}</Link>;
}
return <BreadcrumbItem key={name}>{link}</BreadcrumbItem>;
return <BreadcrumbItem slash={slash} key={name}>{link}</BreadcrumbItem>;
});
} else {
crumbs = this.props.children;
crumbs = React.Children.map(children, (element, index) => {
return cloneElement(element, {
slash,
key: index,
});
});
}
return (
<div className={prefixCls}>

11
components/breadcrumb/index.md

@ -27,11 +27,12 @@
### Breadcrumb
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|-----------|------------------------------------------|------------|---------|--------|
| router | 可传入 react-router 的实例 | Object | | - |
| routes | router 的路由栈信息 | Array | | - |
| params | 路由的参数 | Object | | - |
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|-----------|-----------------------------------|-------------------|---------|--------|
| router | 可传入 react-router 的实例 | Object | | - |
| routes | router 的路由栈信息 | Array | | - |
| params | 路由的参数 | Object | | - |
| slash | 分隔符自定义 | String or Element | | '/' |
### Breadcrumb.Item

Loading…
Cancel
Save