mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* chore(root): menu and select components in progress * chore(root): merged with main * feat(menu): stories created * feat(dropdown): menu migrated to menu component * feat(select): base implementation in progress * feat(select): listbox implemented * feat(select): scroll overflow and auto scroll added * feat(select): colors & variants improved, inside placement complete, outside pending * feat(scroll-shadow): new component in progress * feat(select): scroll shadow integrated * fix(select): popover implementation, more scroll shadow stories added * feat(listbox): custom styles example added to stories * chore(listbox): overflow hidden removed * feat(select): variants and styles completed * chore(select): description story added * feat(select): more stories added * fix(select): dynamic collections inference, styles improved, more stories added * fix(select): auto scroll to selected item, scroll padding added * chore(select): scroll behavior changed to nearest * feat(select): custom item story added * fix(select): autoscroll fixed * feat(select): multi select support added * feat(select): more examples added, clean-package modified to remove dev packages * chore(modal): useImperativeHandle removed * feat(select): render value story improved * feat(docs): listbox & scroll shadow docs done * feat(docs): select documentation in progress * fix: select aria label (#1425) * feat(docs): more examples added * feat(docs): select multiple added, storybook favicon changed * fix: added value to aria label of select (#1431) * feat(select): more examples added, storybook favicon changed * fix(popover): dialog role removed * feat(select): api added, async loading exampled added * fix: fixed list box on click not working with sr click (#1439) * feat(select): async items loading support added and documented * feat(root): input styles updated to be as the select ones * chore(root): listbox and scroll shadow readme updated * feat(select): ts examples added, banner updated * fix(popover): voiceover closes when focusing an item fixed * chore(select): focus scope removed * fix(popover): free solo popover added to use without a trigger * feat(select): blog post added * chore(docs): search meta generated, multi controlled onchange example fixed * chore(root): changeset added --------- Co-authored-by: Jakob Guddas <github@jguddas.de>
315 lines
10 KiB
TypeScript
315 lines
10 KiB
TypeScript
"use client";
|
|
|
|
import {useRef, useState, FC, ReactNode, Key} from "react";
|
|
import {
|
|
link,
|
|
Navbar as NextUINavbar,
|
|
NavbarContent,
|
|
NavbarMenu,
|
|
NavbarMenuToggle,
|
|
NavbarBrand,
|
|
NavbarItem,
|
|
Link,
|
|
Button,
|
|
Kbd,
|
|
Dropdown,
|
|
DropdownMenu,
|
|
DropdownItem,
|
|
DropdownTrigger,
|
|
Chip,
|
|
} from "@nextui-org/react";
|
|
import {dataFocusVisibleClasses} from "@nextui-org/theme";
|
|
import {ChevronDownIcon, LinkIcon} from "@nextui-org/shared-icons";
|
|
import {isAppleDevice} from "@react-aria/utils";
|
|
import {clsx} from "@nextui-org/shared-utils";
|
|
import NextLink from "next/link";
|
|
import {usePathname} from "next/navigation";
|
|
import {includes} from "lodash";
|
|
import {motion, AnimatePresence} from "framer-motion";
|
|
import {useEffect} from "react";
|
|
import {usePress} from "@react-aria/interactions";
|
|
import {useFocusRing} from "@react-aria/focus";
|
|
|
|
import {currentVersion} from "@/utils/version";
|
|
import {siteConfig} from "@/config/site";
|
|
import {Route} from "@/libs/docs/page";
|
|
import {LargeLogo, SmallLogo, ThemeSwitch} from "@/components";
|
|
import {
|
|
TwitterIcon,
|
|
GithubIcon,
|
|
DiscordIcon,
|
|
HeartFilledIcon,
|
|
SearchLinearIcon,
|
|
} from "@/components/icons";
|
|
import {useIsMounted} from "@/hooks/use-is-mounted";
|
|
import {DocsSidebar} from "@/components/docs/sidebar";
|
|
import {useCmdkStore} from "@/components/cmdk";
|
|
|
|
export interface NavbarProps {
|
|
routes: Route[];
|
|
mobileRoutes?: Route[];
|
|
tag?: string;
|
|
slug?: string;
|
|
children?: ReactNode;
|
|
}
|
|
|
|
export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], slug, tag}) => {
|
|
const [isMenuOpen, setIsMenuOpen] = useState<boolean | undefined>(false);
|
|
const [commandKey, setCommandKey] = useState<"ctrl" | "command">("command");
|
|
|
|
const ref = useRef<HTMLElement>(null);
|
|
const isMounted = useIsMounted();
|
|
|
|
const pathname = usePathname();
|
|
|
|
const cmdkStore = useCmdkStore();
|
|
|
|
useEffect(() => {
|
|
if (isMenuOpen) {
|
|
setIsMenuOpen(false);
|
|
}
|
|
}, [pathname]);
|
|
|
|
useEffect(() => {
|
|
setCommandKey(isAppleDevice() ? "command" : "ctrl");
|
|
}, []);
|
|
|
|
const {pressProps} = usePress({
|
|
onPress: () => cmdkStore.onOpen(),
|
|
});
|
|
const {focusProps, isFocusVisible} = useFocusRing();
|
|
|
|
const docsPaths = [
|
|
"/docs/guide/introduction",
|
|
"/docs/guide/installation",
|
|
"/docs/guide/upgrade-to-v2",
|
|
];
|
|
|
|
const searchButton = (
|
|
<Button
|
|
aria-label="Quick search"
|
|
className="text-sm font-normal text-default-500 bg-default-400/20 dark:bg-default-500/20"
|
|
endContent={
|
|
<Kbd className="hidden py-0.5 px-2 lg:inline-block" keys={commandKey}>
|
|
K
|
|
</Kbd>
|
|
}
|
|
startContent={
|
|
<SearchLinearIcon
|
|
className="text-base text-default-400 pointer-events-none flex-shrink-0"
|
|
size={18}
|
|
strokeWidth={2}
|
|
/>
|
|
}
|
|
onPress={() => cmdkStore.onOpen()}
|
|
>
|
|
Quick Search...
|
|
</Button>
|
|
);
|
|
|
|
if (pathname.includes("/examples")) {
|
|
return null;
|
|
}
|
|
|
|
const navLinkClasses = clsx(link({color: "foreground"}), "data-[active=true]:text-primary");
|
|
|
|
const handleVersionChange = (key: Key) => {
|
|
if (key === "v1") {
|
|
const newWindow = window.open("https://v1.nextui.org", "_blank", "noopener,noreferrer");
|
|
|
|
if (newWindow) newWindow.opener = null;
|
|
}
|
|
};
|
|
|
|
return (
|
|
<NextUINavbar
|
|
ref={ref}
|
|
className={clsx({
|
|
"z-[100001]": isMenuOpen,
|
|
})}
|
|
isMenuOpen={isMenuOpen}
|
|
maxWidth="xl"
|
|
position="sticky"
|
|
onMenuOpenChange={setIsMenuOpen}
|
|
>
|
|
<NavbarContent className="basis-1/5 sm:basis-full" justify="start">
|
|
<NavbarBrand as="li" className="gap-3 max-w-fit">
|
|
<NextLink
|
|
aria-label="Home"
|
|
className="flex justify-start items-center gap-2 tap-highlight-transparent transition-opacity active:opacity-50"
|
|
href="/"
|
|
>
|
|
<SmallLogo className="w-6 h-6 md:hidden" />
|
|
<LargeLogo className="h-5 md:h-6" />
|
|
</NextLink>
|
|
{ref.current ? (
|
|
<Dropdown placement="bottom-start" portalContainer={ref.current}>
|
|
<AnimatePresence>
|
|
{isMounted && (
|
|
<motion.div animate={{opacity: 1}} exit={{opacity: 0}} initial={{opacity: 0}}>
|
|
<DropdownTrigger>
|
|
<Button
|
|
className="hidden text-xs h-6 w-[74px] py-1 min-w-fit sm:flex gap-0.5 bg-default-400/20 dark:bg-default-500/20"
|
|
endContent={<ChevronDownIcon className="text-tiny" />}
|
|
radius="full"
|
|
size="sm"
|
|
variant="flat"
|
|
>
|
|
v{currentVersion}
|
|
</Button>
|
|
</DropdownTrigger>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
<DropdownMenu
|
|
aria-label="NextUI versions"
|
|
defaultSelectedKeys={["v2"]}
|
|
selectionMode="single"
|
|
onAction={handleVersionChange}
|
|
>
|
|
<DropdownItem key="v2">v{currentVersion}</DropdownItem>
|
|
<DropdownItem key="v1" endContent={<LinkIcon />}>
|
|
v1.0.0
|
|
</DropdownItem>
|
|
</DropdownMenu>
|
|
</Dropdown>
|
|
) : (
|
|
<div className="w-[74px]" />
|
|
)}
|
|
</NavbarBrand>
|
|
<ul className="hidden lg:flex gap-4 justify-start items-center">
|
|
<NavbarItem>
|
|
<NextLink
|
|
className={navLinkClasses}
|
|
color="foreground"
|
|
data-active={includes(docsPaths, pathname)}
|
|
href="/docs/guide/introduction"
|
|
>
|
|
Docs
|
|
</NextLink>
|
|
</NavbarItem>
|
|
<NavbarItem>
|
|
<NextLink
|
|
className={navLinkClasses}
|
|
color="foreground"
|
|
data-active={includes(pathname, "components")}
|
|
href="/docs/components/avatar"
|
|
>
|
|
Components
|
|
</NextLink>
|
|
</NavbarItem>
|
|
<NavbarItem>
|
|
<NextLink
|
|
className={navLinkClasses}
|
|
color="foreground"
|
|
data-active={includes(pathname, "blog")}
|
|
href="/blog"
|
|
>
|
|
Blog
|
|
</NextLink>
|
|
</NavbarItem>
|
|
<NavbarItem>
|
|
<NextLink
|
|
className={navLinkClasses}
|
|
color="foreground"
|
|
data-active={includes(pathname, "figma")}
|
|
href="/figma"
|
|
>
|
|
Figma
|
|
</NextLink>
|
|
</NavbarItem>
|
|
<NavbarItem>
|
|
<Chip
|
|
as={NextLink}
|
|
className="hover:bg-default-100 border-default-200/80 dark:border-default-100/80 transition-colors cursor-pointer"
|
|
color="secondary"
|
|
href="/blog/v2.1.0"
|
|
variant="dot"
|
|
>
|
|
New components v2.1.0
|
|
<span aria-label="party emoji" role="img">
|
|
🎉
|
|
</span>
|
|
</Chip>
|
|
</NavbarItem>
|
|
</ul>
|
|
</NavbarContent>
|
|
|
|
<NavbarContent className="flex w-full gap-2 sm:hidden" justify="end">
|
|
<NavbarItem className="flex h-full items-center">
|
|
<Link
|
|
isExternal
|
|
aria-label="Github"
|
|
className="p-1"
|
|
href="https://github.com/nextui-org/nextui"
|
|
>
|
|
<GithubIcon className="text-default-600 dark:text-default-500" />
|
|
</Link>
|
|
</NavbarItem>
|
|
<NavbarItem className="flex h-full items-center">
|
|
<ThemeSwitch />
|
|
</NavbarItem>
|
|
<NavbarItem className="flex h-full items-center">
|
|
<button
|
|
className={clsx(
|
|
"transition-opacity p-1 hover:opacity-80 rounded-full cursor-pointer outline-none",
|
|
// focus ring
|
|
...dataFocusVisibleClasses,
|
|
)}
|
|
data-focus-visible={isFocusVisible}
|
|
{...focusProps}
|
|
{...pressProps}
|
|
>
|
|
<SearchLinearIcon className="mt-px text-default-600 dark:text-default-500" size={20} />
|
|
</button>
|
|
</NavbarItem>
|
|
<NavbarItem className="w-10 h-full">
|
|
<NavbarMenuToggle
|
|
aria-label={isMenuOpen ? "Close menu" : "Open menu"}
|
|
className="w-full h-full pt-1"
|
|
/>
|
|
</NavbarItem>
|
|
</NavbarContent>
|
|
|
|
<NavbarContent className="hidden sm:flex basis-1/5 sm:basis-full" justify="end">
|
|
<NavbarItem className="hidden sm:flex">
|
|
<Link isExternal aria-label="Twitter" className="p-1" href={siteConfig.links.twitter}>
|
|
<TwitterIcon className="text-default-600 dark:text-default-500" />
|
|
</Link>
|
|
<Link isExternal aria-label="Discord" className="p-1" href={siteConfig.links.discord}>
|
|
<DiscordIcon className="text-default-600 dark:text-default-500" />
|
|
</Link>
|
|
<Link isExternal aria-label="Github" className="p-1" href={siteConfig.links.github}>
|
|
<GithubIcon className="text-default-600 dark:text-default-500" />
|
|
</Link>
|
|
<ThemeSwitch />
|
|
</NavbarItem>
|
|
<NavbarItem className="hidden lg:flex">{searchButton}</NavbarItem>
|
|
<NavbarItem className="hidden md:flex">
|
|
<Button
|
|
isExternal
|
|
as={Link}
|
|
className="group text-sm font-normal text-default-600 bg-default-400/20 dark:bg-default-500/20"
|
|
href={siteConfig.links.sponsor}
|
|
startContent={
|
|
<HeartFilledIcon className="text-danger group-data-[hover=true]:animate-heartbeat" />
|
|
}
|
|
variant="flat"
|
|
>
|
|
Sponsor
|
|
</Button>
|
|
</NavbarItem>
|
|
<NavbarMenuToggle
|
|
aria-label={isMenuOpen ? "Close menu" : "Open menu"}
|
|
className="hidden sm:flex lg:hidden ml-4"
|
|
/>
|
|
</NavbarContent>
|
|
|
|
<NavbarMenu>
|
|
<DocsSidebar className="mt-4" routes={[...mobileRoutes, ...routes]} slug={slug} tag={tag} />
|
|
{children}
|
|
</NavbarMenu>
|
|
</NextUINavbar>
|
|
);
|
|
};
|