-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
navbar.tsx
51 lines (41 loc) · 1.43 KB
/
navbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {forwardRef} from "@nextui-org/system";
import {pickChildren} from "@nextui-org/react-utils";
import {motion} from "framer-motion";
import {mergeProps} from "@react-aria/utils";
import {hideOnScrollVariants} from "./navbar-transitions";
import {UseNavbarProps, useNavbar} from "./use-navbar";
import {NavbarProvider} from "./navbar-context";
import NavbarMenu from "./navbar-menu";
export interface NavbarProps extends Omit<UseNavbarProps, "hideOnScroll"> {
children?: React.ReactNode | React.ReactNode[];
}
const Navbar = forwardRef<"div", NavbarProps>((props, ref) => {
const {children, ...otherProps} = props;
const context = useNavbar({...otherProps, ref});
const Component = context.Component;
const [childrenWithoutMenu, menu] = pickChildren(children, NavbarMenu);
const content = (
<>
<header {...context.getWrapperProps()}>{childrenWithoutMenu}</header>
{menu}
</>
);
return (
<NavbarProvider value={context}>
{context.shouldHideOnScroll ? (
<motion.nav
animate={context.isHidden ? "hidden" : "visible"}
initial={false}
variants={hideOnScrollVariants}
{...mergeProps(context.getBaseProps(), context.motionProps)}
>
{content}
</motion.nav>
) : (
<Component {...context.getBaseProps()}>{content}</Component>
)}
</NavbarProvider>
);
});
Navbar.displayName = "NextUI.Navbar";
export default Navbar;