From a068e58dd4c48f98151f19a1705ff889f88b2656 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 7 Dec 2015 12:13:13 +0800 Subject: [PATCH] Add slash prop, close #641 --- components/breadcrumb/demo/slash.md | 20 ++++++++++ components/breadcrumb/index.jsx | 61 +++++++++++++++++++++-------- components/breadcrumb/index.md | 11 +++--- 3 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 components/breadcrumb/demo/slash.md diff --git a/components/breadcrumb/demo/slash.md b/components/breadcrumb/demo/slash.md new file mode 100644 index 0000000000..0221b4b7ab --- /dev/null +++ b/components/breadcrumb/demo/slash.md @@ -0,0 +1,20 @@ +# 分隔符 + +- order: 3 + +使用 `slash=">"` 可以自定义分隔符。 + +--- + +````jsx +import { Breadcrumb } from 'antd'; + +ReactDOM.render( + + 首页 + 应用中心 + 应用列表 + 某应用 + +, document.getElementById('components-breadcrumb-demo-slash')); +```` diff --git a/components/breadcrumb/index.jsx b/components/breadcrumb/index.jsx index 546b39b5e8..23ce805a36 100644 --- a/components/breadcrumb/index.jsx +++ b/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 = {this.props.children}; - let slash = /; + const { prefixCls, slash, children } = this.props; + let link = {children}; if (typeof this.props.href === 'undefined') { - link = {this.props.children}; + link = {children}; } - return {link}{slash}; + return + {link} + {slash} + ; } }); -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, functio