yapi/client/components/Subnav/Subnav.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-08-08 15:24:26 +08:00
import './Subnav.scss';
import React, { Component } from 'react';
2017-08-08 16:21:32 +08:00
import { Link } from 'react-router-dom';
2017-08-08 15:24:26 +08:00
import PropTypes from 'prop-types';
import { Menu } from 'antd';
class Subnav extends Component {
constructor(props) {
super(props)
}
2017-08-08 16:21:32 +08:00
2017-08-08 15:24:26 +08:00
static propTypes = {
2017-08-08 16:21:32 +08:00
data: PropTypes.array,
default: PropTypes.string
2017-08-08 15:24:26 +08:00
}
2017-08-08 16:21:32 +08:00
2017-08-08 15:24:26 +08:00
render () {
return (
<div className="m-subnav">
<Menu
onClick={this.handleClick}
2017-09-05 15:11:05 +08:00
selectedKeys={[this.props.default]}
2017-08-08 15:24:26 +08:00
mode="horizontal"
className="g-row m-subnav-menu"
>
{this.props.data.map((item, index) => {
2017-08-23 22:04:05 +08:00
// 若导航标题为两个字,则自动在中间加个空格
if (item.name.length === 2) {
item.name = item.name[0] + ' ' + item.name[1];
}
2017-08-08 15:24:26 +08:00
return (
2017-09-05 15:11:05 +08:00
<Menu.Item className="item" key={item.name.replace(' ', '')}>
2017-08-08 16:21:32 +08:00
<Link to={item.path}>{this.props.data[index].name}</Link>
2017-08-08 15:24:26 +08:00
</Menu.Item>
)
})}
</Menu>
</div>
)
}
}
2017-08-08 16:21:32 +08:00
export default Subnav;