2016-02-29 14:08:40 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { Link } from 'react-router';
|
2016-03-24 17:13:19 +08:00
|
|
|
import enquire from 'enquire.js';
|
2016-04-11 10:12:48 +08:00
|
|
|
import { Select, Menu, Row, Col, Icon } from 'antd';
|
2016-02-29 14:08:40 +08:00
|
|
|
const Option = Select.Option;
|
|
|
|
|
|
|
|
import './index.less';
|
|
|
|
|
2016-03-22 11:32:49 +08:00
|
|
|
import componentsList from '../../../_data/react-components';
|
2016-03-01 16:20:32 +08:00
|
|
|
export default class Header extends React.Component {
|
2016-03-30 17:41:17 +08:00
|
|
|
static contextTypes = {
|
|
|
|
router: React.PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
2016-03-24 17:13:19 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
menuVisible: false,
|
|
|
|
menuMode: 'horizontal',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('click', () => {
|
|
|
|
this.setState({
|
|
|
|
menuVisible: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
enquire.register('only screen and (min-width: 320px) and (max-width: 767px)', {
|
|
|
|
match: () => {
|
|
|
|
this.setState({ menuMode: 'inline' });
|
|
|
|
},
|
|
|
|
unmatch: () => {
|
|
|
|
this.setState({ menuMode: 'horizontal' });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-30 16:16:18 +08:00
|
|
|
handleMenuIconClick = (e) => {
|
2016-03-24 17:13:19 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
this.setState({
|
|
|
|
menuVisible: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-30 16:16:18 +08:00
|
|
|
handleSearch = (value) => {
|
2016-03-29 12:00:14 +08:00
|
|
|
this.context.router.push({ pathname: value });
|
2016-02-29 14:08:40 +08:00
|
|
|
}
|
|
|
|
|
2016-03-30 16:16:18 +08:00
|
|
|
handleSelectFilter = (value, option) => {
|
2016-03-28 15:08:17 +08:00
|
|
|
return option.props['data-label'].indexOf(value.toLowerCase()) > -1;
|
|
|
|
}
|
|
|
|
|
2016-03-01 16:20:32 +08:00
|
|
|
render() {
|
|
|
|
const routes = this.props.routes;
|
|
|
|
const activeMenuItem = routes[1].path || 'home';
|
|
|
|
|
2016-03-23 22:36:26 +08:00
|
|
|
const options = Object.keys(componentsList).map((key) => {
|
2016-03-04 18:06:34 +08:00
|
|
|
return componentsList[key];
|
2016-03-28 14:12:26 +08:00
|
|
|
}).filter(({ meta }) => {
|
|
|
|
return /^component/.test(meta.fileName);
|
2016-03-23 22:36:26 +08:00
|
|
|
}).map(({ meta }) => {
|
2016-03-28 14:12:26 +08:00
|
|
|
const pathSnippet = meta.fileName.split('/')[1];
|
|
|
|
const url = `/components/${pathSnippet}`;
|
2016-03-23 22:36:26 +08:00
|
|
|
return (
|
2016-03-28 15:08:17 +08:00
|
|
|
<Option value={url} key={url} data-label={`${meta.english.toLowerCase()} ${meta.chinese}`}>
|
2016-03-04 18:06:34 +08:00
|
|
|
<strong>{meta.english}</strong>
|
|
|
|
<span className="ant-component-decs">{meta.chinese}</span>
|
|
|
|
</Option>
|
|
|
|
);
|
|
|
|
});
|
2016-03-01 16:20:32 +08:00
|
|
|
|
2016-03-24 17:13:19 +08:00
|
|
|
const menuStyle = {
|
|
|
|
display: this.state.menuVisible ? 'block' : '',
|
|
|
|
};
|
|
|
|
|
2016-03-01 16:20:32 +08:00
|
|
|
return (
|
|
|
|
<header id="header" className="clearfix">
|
2016-03-01 16:33:19 +08:00
|
|
|
<Row>
|
2016-03-24 17:13:19 +08:00
|
|
|
<Col lg={4} md={6} sm={7} xs={24}>
|
|
|
|
<Icon
|
|
|
|
className="nav-phone-icon"
|
2016-03-30 16:16:18 +08:00
|
|
|
onClick={this.handleMenuIconClick}
|
2016-03-24 17:13:19 +08:00
|
|
|
type="menu" />
|
2016-03-01 16:33:19 +08:00
|
|
|
<Link to="/" id="logo">
|
2016-04-18 14:58:38 +08:00
|
|
|
<img alt="logo" src="https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg" />
|
2016-03-01 16:33:19 +08:00
|
|
|
<span>Ant Design</span>
|
2016-03-01 16:20:32 +08:00
|
|
|
</Link>
|
2016-03-01 16:33:19 +08:00
|
|
|
</Col>
|
2016-03-24 17:13:19 +08:00
|
|
|
<Col className={`nav ${this.state.menuVisible ? 'nav-show' : 'nav-hide'}`}
|
|
|
|
lg={20} md={18} sm={17} xs={0} style={menuStyle}>
|
2016-03-01 16:33:19 +08:00
|
|
|
<div id="search-box">
|
2016-03-10 16:01:39 +08:00
|
|
|
<Select combobox
|
2016-03-23 22:36:26 +08:00
|
|
|
dropdownClassName="component-select"
|
|
|
|
searchPlaceholder="搜索组件..."
|
2016-04-18 15:15:47 +08:00
|
|
|
value={undefined}
|
2016-03-28 14:12:26 +08:00
|
|
|
optionFilterProp="data-label"
|
2016-03-30 16:16:18 +08:00
|
|
|
filterOption={this.handleSelectFilter}
|
|
|
|
onSelect={this.handleSearch}>
|
2016-03-01 16:33:19 +08:00
|
|
|
{options}
|
|
|
|
</Select>
|
|
|
|
</div>
|
2016-03-24 17:13:19 +08:00
|
|
|
<Menu mode={this.state.menuMode} selectedKeys={[activeMenuItem]} id="nav">
|
2016-03-01 16:33:19 +08:00
|
|
|
<Menu.Item key="home">
|
|
|
|
<Link to="/">
|
|
|
|
首页
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Menu.Item key="docs/practice">
|
|
|
|
<Link to="/docs/practice">
|
2016-03-02 11:57:37 +08:00
|
|
|
实践
|
|
|
|
</Link>
|
2016-03-01 16:33:19 +08:00
|
|
|
</Menu.Item>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Menu.Item key="docs/pattern">
|
|
|
|
<Link to="/docs/pattern">
|
2016-03-02 11:57:37 +08:00
|
|
|
模式
|
|
|
|
</Link>
|
2016-03-01 16:33:19 +08:00
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="components">
|
|
|
|
<Link to="/components">
|
|
|
|
组件
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Menu.Item key="docs/spec">
|
|
|
|
<Link to="/docs/spec">
|
2016-03-01 16:33:19 +08:00
|
|
|
语言
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
2016-03-10 16:56:17 +08:00
|
|
|
<Menu.Item key="docs/resource">
|
|
|
|
<Link to="/docs/resource">
|
2016-03-01 16:33:19 +08:00
|
|
|
资源
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2016-03-01 16:20:32 +08:00
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
2016-02-29 14:08:40 +08:00
|
|
|
}
|