Skip to content

Commit

Permalink
feat(search): make oramasearchbox as a client component
Browse files Browse the repository at this point in the history
  • Loading branch information
rjborba committed Aug 26, 2024
1 parent 446de4a commit b279f6f
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 624 deletions.
20 changes: 7 additions & 13 deletions apps/site/components/Common/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
'use client';

import { OramaSearchBox, OramaSearchButton } from '@orama/react-components';
import { useTheme } from 'next-themes';
import type { FC } from 'react';
import { useState } from 'react';
import '@orama/searchbox/dist/index.css';
import { type FC } from 'react';

import {
ORAMA_CLOUD_ENDPOINT,
ORAMA_CLOUD_API_KEY,
} from '@/next.constants.mjs';

export const SearchButton: FC = () => {
const [isOpen, setIsOpen] = useState(false);
const SearchButton: FC = () => {
const { resolvedTheme } = useTheme();
const colorScheme = resolvedTheme as 'light' | 'dark';

return (
<>
<OramaSearchButton
id="orama-ui-search-button"
colorScheme={colorScheme}
onClick={() => setIsOpen(true)}
>
<OramaSearchButton style={{ flexGrow: 1 }} colorScheme={colorScheme}>
Search
</OramaSearchButton>

<OramaSearchBox
id="orama-ui-searchbox"
open={isOpen}
onSearchboxClosed={() => setIsOpen(false)}
colorScheme={colorScheme}
index={{ api_key: ORAMA_CLOUD_API_KEY, endpoint: ORAMA_CLOUD_ENDPOINT }}
facetProperty="siteSection"
Expand All @@ -52,3 +44,5 @@ export const SearchButton: FC = () => {
</>
);
};

export default SearchButton;
160 changes: 82 additions & 78 deletions apps/site/components/Containers/NavBar/index.tsx
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;
3 changes: 1 addition & 2 deletions apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"@mdx-js/mdx": "^3.0.1",
"@nodevu/core": "~0.1.0",
"@orama/highlight": "^0.1.6",
"@orama/react-components": "^0.0.18",
"@orama/searchbox": "^1.0.0-rc48",
"@orama/react-components": "^0.0.23",
"@oramacloud/client": "^1.3.2",
"@radix-ui/react-accessible-icon": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.4",
Expand Down
Loading

0 comments on commit b279f6f

Please sign in to comment.