Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imporve the user experience of the official site #4457

Merged
merged 3 commits into from Jan 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 38 additions & 8 deletions site/theme/template/Layout/Header.jsx
Expand Up @@ -14,6 +14,8 @@ export default class Header extends React.Component {
}

state = {
inputValue: '',
menuVisible: false,
menuMode: 'horizontal',
};

Expand All @@ -33,7 +35,30 @@ export default class Header extends React.Component {

handleSearch = (value) => {
const { intl, router } = this.context;
router.push({ pathname: utils.getLocalizedPathname(`${value}/`, intl.locale === 'zh-CN') });

this.setState({
inputValue: '',
}, () => {
router.push({ pathname: utils.getLocalizedPathname(`${value}/`, intl.locale === 'zh-CN') });
});
}

handleInputChange = (value) => {
this.setState({
inputValue: value,
});
}

handleShowMenu = () => {
this.setState({
menuVisible: true,
});
}

handleHideMenu = () => {
this.setState({
menuVisible: false,
});
}

handleSelectFilter = (value, option) => {
Expand All @@ -46,6 +71,7 @@ export default class Header extends React.Component {
}

render() {
const { inputValue, menuMode, menuVisible } = this.state;
const { location, picked, isFirstScreen } = this.props;
const components = picked.components;
const module = location.pathname.replace(/(^\/|\/$)/g, '').split('/').slice(0, -1).join('/');
Expand Down Expand Up @@ -76,39 +102,38 @@ export default class Header extends React.Component {
'home-nav-white': !isFirstScreen,
});

const menuMode = this.state.menuMode;
const menu = [
<Button className="lang" type="ghost" size="small" onClick={this.handleLangChange} key="lang">
<FormattedMessage id="app.header.lang" />
</Button>,
<Menu mode={menuMode} selectedKeys={[activeMenuItem]} id="nav" key="nav">
<Menu.Item key="home">
<Link to={utils.getLocalizedPathname('/', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/', isZhCN)}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样绑定貌似略多余,试试监听 url 变化如何?

remix-run/react-router#964 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯 我明天试一下

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisheng 把 browserHistory 封装起来了,用这种方法监听吧: https://github.com/ant-design/ant-design/blob/master/site/theme/template/Layout/index.jsx#L41

<FormattedMessage id="app.header.menu.home" />
</Link>
</Menu.Item>
<Menu.Item key="docs/spec">
<Link to={utils.getLocalizedPathname('/docs/spec/introduce', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/docs/spec/introduce', isZhCN)}>
<FormattedMessage id="app.header.menu.spec" />
</Link>
</Menu.Item>
<Menu.Item key="docs/react">
<Link to={utils.getLocalizedPathname('/docs/react/introduce', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/docs/react/introduce', isZhCN)}>
<FormattedMessage id="app.header.menu.components" />
</Link>
</Menu.Item>
<Menu.Item key="docs/pattern">
<Link to={utils.getLocalizedPathname('/docs/pattern/navigation', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/docs/pattern/navigation', isZhCN)}>
<FormattedMessage id="app.header.menu.pattern" />
</Link>
</Menu.Item>
<Menu.Item key="docs/practice">
<Link to={utils.getLocalizedPathname('/docs/practice/cases', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/docs/practice/cases', isZhCN)}>
<FormattedMessage id="app.header.menu.practice" />
</Link>
</Menu.Item>
<Menu.Item key="docs/resource">
<Link to={utils.getLocalizedPathname('/docs/resource/download', isZhCN)}>
<Link onClick={this.handleHideMenu} to={utils.getLocalizedPathname('/docs/resource/download', isZhCN)}>
<FormattedMessage id="app.header.menu.resource" />
</Link>
</Menu.Item>
Expand All @@ -123,11 +148,13 @@ export default class Header extends React.Component {
placement="bottomRight"
content={menu}
trigger="click"
visible={menuVisible}
arrowPointAtCenter
>
<Icon
className="nav-phone-icon"
type="menu"
onClick={this.handleShowMenu}
/>
</Popover> : null}
<Row>
Expand All @@ -141,12 +168,15 @@ export default class Header extends React.Component {
<div id="search-box">
<Select
combobox
value={inputValue}
dropdownStyle={{ display: inputValue ? 'block' : 'none' }}
dropdownClassName="component-select"
placeholder={searchPlaceholder}
optionFilterProp="data-label"
optionLabelProp="data-label"
filterOption={this.handleSelectFilter}
onSelect={this.handleSearch}
onSearch={this.handleInputChange}
getPopupContainer={trigger => trigger.parentNode}
>
{options}
Expand Down