import React, { useState } from 'react' import { Flex, Box, Text, BoxProps } from 'theme-ui' import { MenuTrigger } from './MenuTrigger' import { NAV_HEIGHT } from './Navbar' import { Transition } from 'react-transition-group' import { useScrollSwipe } from '../hooks/use-scroll-swipe' import { RenderInBody } from './RenderInBody' import classnames from 'classnames' import BackgroundImage from 'gatsby-background-image' export const Menu: React.FunctionComponent = (props) => { const [menuVisible, setMenuVisible] = useState(false) useScrollSwipe(() => { setMenuVisible(false) }) return ( <> setMenuVisible(val)} /> {(state) => { const onEnter = state === 'entering' || state === 'entered' return ( {props.children} ) }} ) } export interface MenuItemProps { backgroundImage: any text: string /** 类型,垂直仅在 PC 端显示,水平仅在移动端显示 */ type?: 'horizontal' | 'vertical' | 'all' /** 是否处于激活状态 */ active?: boolean /** 激活状态文字颜色 */ activeColor?: any } export const MenuItem: React.FunctionComponent = (props) => { const { active, backgroundImage, activeColor, text, type } = props let itemDisplay = ['flex'] if (type === 'vertical') { itemDisplay = ['none', 'none', 'flex'] } else if (type === 'horizontal') { itemDisplay = ['flex', 'flex', 'none'] } return ( {(type === 'vertical' || type === 'all') && ( {text} )} {(type === 'horizontal' || type === 'all') && ( {text} )} ) } MenuItem.defaultProps = { active: false, type: 'all' }