You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
8.2 KiB

import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'bisheng/router';
import { FormattedMessage } from 'react-intl';
9 years ago
import classNames from 'classnames';
import { Select, Menu, Row, Col, Icon, Popover, Input, Button, Badge } from 'antd';
import Santa from './Santa';
import * as utils from '../utils';
import { version as antdVersion } from '../../../../package.json';
const { Option } = Select;
let docsearch;
if (typeof window !== 'undefined') {
docsearch = require('docsearch.js'); // eslint-disable-line
}
function initDocSearch(locale) {
if (!docsearch) {
return;
}
const lang = locale === 'zh-CN' ? 'cn' : 'en';
docsearch({
apiKey: '60ac2c1a7d26ab713757e4a081e133d0',
indexName: 'ant_design',
inputSelector: '#search-box input',
algoliaOptions: { facetFilters: [`tags:${lang}`] },
transformData(hits) {
6 years ago
hits.forEach(hit => {
hit.url = hit.url.replace('ant.design', window.location.host); // eslint-disable-line
hit.url = hit.url.replace('https:', window.location.protocol); // eslint-disable-line
});
return hits;
},
debug: false, // Set debug to true if you want to inspect the dropdown
});
}
export default class Header extends React.Component {
static contextTypes = {
router: PropTypes.object.isRequired,
intl: PropTypes.object.isRequired,
7 years ago
isMobile: PropTypes.bool.isRequired,
6 years ago
};
state = {
menuVisible: false,
};
9 years ago
componentDidMount() {
const { intl, router } = this.context;
router.listen(this.handleHideMenu);
const { searchInput } = this;
6 years ago
document.addEventListener('keyup', event => {
if (event.keyCode === 83 && event.target === document.body) {
searchInput.focus();
}
});
initDocSearch(intl.locale);
}
handleShowMenu = () => {
this.setState({
menuVisible: true,
});
6 years ago
};
handleHideMenu = () => {
this.setState({
menuVisible: false,
});
6 years ago
};
6 years ago
onMenuVisibleChange = visible => {
this.setState({
menuVisible: visible,
});
6 years ago
};
6 years ago
handleVersionChange = url => {
const currentUrl = window.location.href;
const currentPathname = window.location.pathname;
6 years ago
window.location.href = currentUrl
.replace(window.location.origin, url)
.replace(currentPathname, utils.getLocalizedPathname(currentPathname));
6 years ago
};
handleLangChange = () => {
6 years ago
const {
location: { pathname },
} = this.props;
const currentProtocol = `${window.location.protocol}//`;
const currentHref = window.location.href.substr(currentProtocol.length);
if (