This commit is contained in:
tangly1024
2023-03-08 22:38:24 +08:00
parent 147c92b3fb
commit 7576f85b75

View File

@@ -1,5 +1,6 @@
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import { useRouter } from 'next/router'
import { useState } from 'react'
import CONFIG_SIMPLE from '../config_simple'
import { DropMenu } from './DropMenu'
@@ -12,11 +13,21 @@ import { DropMenu } from './DropMenu'
export const Nav = ({ customNav, customMenu }) => {
const { locale } = useGlobal()
const [showSearchInput, changeShowSearchInput] = useState(false)
const router = useRouter()
const toggleShowSearchInput = () => {
changeShowSearchInput(!showSearchInput)
}
const onKeyUp = (e) => {
if (e.keyCode === 13) {
const search = document.getElementById('theme-simple-search').value
if (search) {
router.push({ pathname: '/search/' + search })
}
}
}
let links = [
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_SIMPLE.MENU_SEARCH },
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_SIMPLE.MENU_ARCHIVE },
@@ -39,7 +50,7 @@ export const Nav = ({ customNav, customMenu }) => {
<nav className="w-full bg-white md:pt-0 px-6 relative z-20 shadow-md border-t border-gray-100 dark:border-hexo-black-gray dark:bg-black">
<div className="container mx-auto max-w-8xl md:flex justify-between items-center text-sm md:text-md md:justify-start">
<div className="w-full h-12 text-center md:text-left flex flex-wrap justify-center items-stretch md:justify-start md:items-start space-x-4">
{showSearchInput && <input className='h-full px-4 w-full' aria-label="Submit search" type="search" name="s" autoComplete="off" placeholder="Type then hit enter to search..."/>}
{showSearchInput && <input id="theme-simple-search" onKeyUp={onKeyUp} className='h-full px-4 w-full' aria-label="Submit search" type="search" name="s" autoComplete="off" placeholder="Type then hit enter to search..."/>}
{!showSearchInput && links?.map(link => {
if (link?.show) {
@@ -52,7 +63,7 @@ export const Nav = ({ customNav, customMenu }) => {
<div className="w-full md:w-1/3 text-center md:text-right hidden md:block">
{/* <!-- extra links --> */}
<i className="fa-solid fa-magnifying-glass cursor-pointer" onClick={toggleShowSearchInput}></i>
<i className={showSearchInput ? 'fa-regular fa-circle-xmark' : 'fa-solid fa-magnifying-glass ' + ' cursor-pointer'} onClick={toggleShowSearchInput}></i>
</div>
</div>
</nav>