import React, { PropTypes } from 'react'; import { Link } from 'react-router'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { Select, Menu, Row, Col, Icon, Button, Popover } from 'antd'; import * as utils from '../utils'; const Option = Select.Option; export default class Header extends React.Component { static contextTypes = { router: PropTypes.object.isRequired, intl: PropTypes.object.isRequired, } state = { menuMode: 'horizontal', }; componentDidMount() { /* eslint-disable global-require */ require('enquire.js') .register('only screen and (min-width: 320px) and (max-width: 1024px)', { match: () => { this.setState({ menuMode: 'inline' }); }, unmatch: () => { this.setState({ menuMode: 'horizontal' }); }, }); /* eslint-enable global-require */ } handleSearch = (value) => { const { intl, router } = this.context; router.push({ pathname: utils.getLocalizedPathname(`${value}/`, intl.locale === 'zh-CN') }); } handleSelectFilter = (value, option) => { return option.props['data-label'].indexOf(value.toLowerCase()) > -1; } handleLangChange = () => { const pathname = this.props.location.pathname; location.pathname = utils.getLocalizedPathname(pathname, !utils.isZhCN(pathname)); } render() { const { location, picked, isFirstScreen } = this.props; const components = picked.components; const module = location.pathname.replace(/(^\/|\/$)/g, '').split('/').slice(0, -1).join('/'); let activeMenuItem = module || 'home'; if (activeMenuItem === 'components' || location.pathname === 'changelog') { activeMenuItem = 'docs/react'; } const locale = this.context.intl.locale; const isZhCN = locale === 'zh-CN'; const excludedSuffix = isZhCN ? 'en-US.md' : 'zh-CN.md'; const options = components .filter(({ meta }) => !meta.filename.endsWith(excludedSuffix)) .map(({ meta }) => { const pathSnippet = meta.filename.split('/')[1]; const url = `/components/${pathSnippet}`; const subtitle = meta.subtitle; return ( ); }); const headerClassName = classNames({ clearfix: true, 'home-nav-white': !isFirstScreen, }); const menuMode = this.state.menuMode; const menu = [ , , ]; const searchPlaceholder = locale === 'zh-CN' ? '搜索组件...' : 'Search Components...'; return ( ); } }