-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): make oramasearchbox as a client component
- Loading branch information
Showing
4 changed files
with
147 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,97 @@ | ||
"use client"; | ||
'use client'; | ||
|
||
import Hamburger from "@heroicons/react/24/solid/Bars3Icon"; | ||
import XMark from "@heroicons/react/24/solid/XMarkIcon"; | ||
import * as Label from "@radix-ui/react-label"; | ||
import { useState } from "react"; | ||
import type { FC, ComponentProps, HTMLAttributeAnchorTarget } from "react"; | ||
import Hamburger from '@heroicons/react/24/solid/Bars3Icon'; | ||
import XMark from '@heroicons/react/24/solid/XMarkIcon'; | ||
import * as Label from '@radix-ui/react-label'; | ||
import dynamic from 'next/dynamic'; | ||
import { useState } from 'react'; | ||
import type { FC, ComponentProps, HTMLAttributeAnchorTarget } from 'react'; | ||
|
||
import LanguageDropdown from "@/components/Common/LanguageDropDown"; | ||
import { SearchButton } from "@/components/Common/Search"; | ||
import ThemeToggle from "@/components/Common/ThemeToggle"; | ||
import NavItem from "@/components/Containers/NavBar/NavItem"; | ||
import GitHub from "@/components/Icons/Social/GitHub"; | ||
import Link from "@/components/Link"; | ||
import WithNodejsLogo from "@/components/withNodejsLogo"; | ||
import type { FormattedMessage } from "@/types"; | ||
import LanguageDropdown from '@/components/Common/LanguageDropDown'; | ||
import ThemeToggle from '@/components/Common/ThemeToggle'; | ||
import NavItem from '@/components/Containers/NavBar/NavItem'; | ||
import GitHub from '@/components/Icons/Social/GitHub'; | ||
import Link from '@/components/Link'; | ||
import WithNodejsLogo from '@/components/withNodejsLogo'; | ||
import type { FormattedMessage } from '@/types'; | ||
|
||
import style from "./index.module.css"; | ||
import style from './index.module.css'; | ||
|
||
const SearchButton = dynamic(() => import('@/components/Common/Search'), { | ||
ssr: false, | ||
}); | ||
|
||
const navInteractionIcons = { | ||
show: <Hamburger className={style.navInteractionIcon} />, | ||
close: <XMark className={style.navInteractionIcon} />, | ||
show: <Hamburger className={style.navInteractionIcon} />, | ||
close: <XMark className={style.navInteractionIcon} />, | ||
}; | ||
|
||
type NavbarProps = { | ||
navItems: Array<{ | ||
text: FormattedMessage; | ||
link: string; | ||
target?: HTMLAttributeAnchorTarget | undefined; | ||
}>; | ||
languages: ComponentProps<typeof LanguageDropdown>; | ||
onThemeTogglerClick: () => void; | ||
navItems: Array<{ | ||
text: FormattedMessage; | ||
link: string; | ||
target?: HTMLAttributeAnchorTarget | undefined; | ||
}>; | ||
languages: ComponentProps<typeof LanguageDropdown>; | ||
onThemeTogglerClick: () => void; | ||
}; | ||
|
||
const NavBar: FC<NavbarProps> = ({ | ||
navItems, | ||
languages, | ||
onThemeTogglerClick, | ||
navItems, | ||
languages, | ||
onThemeTogglerClick, | ||
}) => { | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
|
||
return ( | ||
<nav className={`${style.container}`}> | ||
<div className={style.nodeIconAndMobileItemsToggler}> | ||
<Link className={style.nodeIconWrapper} href="/" aria-label="Home"> | ||
<WithNodejsLogo /> | ||
</Link> | ||
|
||
<Label.Root | ||
onClick={() => setIsMenuOpen((prev) => !prev)} | ||
className={style.sidebarItemTogglerLabel} | ||
htmlFor="sidebarItemToggler" | ||
> | ||
{navInteractionIcons[isMenuOpen ? "close" : "show"]} | ||
</Label.Root> | ||
</div> | ||
|
||
<input className="peer hidden" id="sidebarItemToggler" type="checkbox" /> | ||
|
||
<div className={`${style.main} peer-checked:flex`}> | ||
<div className={style.navItems}> | ||
{navItems.map(({ text, link, target }) => ( | ||
<NavItem key={link} href={link} target={target}> | ||
{text} | ||
</NavItem> | ||
))} | ||
</div> | ||
|
||
<div className={style.actionsWrapper}> | ||
<SearchButton /> | ||
|
||
<ThemeToggle onClick={onThemeTogglerClick} /> | ||
|
||
<LanguageDropdown | ||
onChange={languages.onChange} | ||
availableLanguages={languages.availableLanguages} | ||
currentLanguage={languages.currentLanguage} | ||
/> | ||
|
||
<Link | ||
className={style.ghIconWrapper} | ||
href="https://github.com/nodejs/node" | ||
aria-label="Node.js Github" | ||
> | ||
<GitHub /> | ||
</Link> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
|
||
return ( | ||
<nav className={`${style.container}`}> | ||
<div className={style.nodeIconAndMobileItemsToggler}> | ||
<Link className={style.nodeIconWrapper} href="/" aria-label="Home"> | ||
<WithNodejsLogo /> | ||
</Link> | ||
|
||
<Label.Root | ||
onClick={() => setIsMenuOpen(prev => !prev)} | ||
className={style.sidebarItemTogglerLabel} | ||
htmlFor="sidebarItemToggler" | ||
> | ||
{navInteractionIcons[isMenuOpen ? 'close' : 'show']} | ||
</Label.Root> | ||
</div> | ||
|
||
<input className="peer hidden" id="sidebarItemToggler" type="checkbox" /> | ||
|
||
<div className={`${style.main} peer-checked:flex`}> | ||
<div className={style.navItems}> | ||
{navItems.map(({ text, link, target }) => ( | ||
<NavItem key={link} href={link} target={target}> | ||
{text} | ||
</NavItem> | ||
))} | ||
</div> | ||
|
||
<div className={style.actionsWrapper}> | ||
<SearchButton /> | ||
|
||
<ThemeToggle onClick={onThemeTogglerClick} /> | ||
|
||
<LanguageDropdown | ||
onChange={languages.onChange} | ||
availableLanguages={languages.availableLanguages} | ||
currentLanguage={languages.currentLanguage} | ||
/> | ||
|
||
<Link | ||
className={style.ghIconWrapper} | ||
href="https://github.com/nodejs/node" | ||
aria-label="Node.js Github" | ||
> | ||
<GitHub /> | ||
</Link> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default NavBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.