diff --git a/apps/web/content/docs/components/navbar.mdx b/apps/web/content/docs/components/navbar.mdx index b186babd3..aee36aa16 100644 --- a/apps/web/content/docs/components/navbar.mdx +++ b/apps/web/content/docs/components/navbar.mdx @@ -35,6 +35,12 @@ Use this example to feature a dropdown menu when clicking on the user avatar ins +## Navbar with Custom Bar/Menu Icon + +Use this example to use the custom Open Menu/Bar Icon + + + ## Theme To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme). diff --git a/apps/web/examples/navbar/index.ts b/apps/web/examples/navbar/index.ts index c06f4cf41..8c8f3732b 100644 --- a/apps/web/examples/navbar/index.ts +++ b/apps/web/examples/navbar/index.ts @@ -1,3 +1,4 @@ export { root } from "./navbar.root"; export { withCTAButton } from "./navbar.withCTAButton"; +export { withCustomMenuIcon } from "./navbar.withCustomMenuIcon"; export { withDropdown } from "./navbar.withDropdown"; diff --git a/apps/web/examples/navbar/navbar.withCustomMenuIcon.tsx b/apps/web/examples/navbar/navbar.withCustomMenuIcon.tsx new file mode 100644 index 000000000..3b8138018 --- /dev/null +++ b/apps/web/examples/navbar/navbar.withCustomMenuIcon.tsx @@ -0,0 +1,104 @@ +"use client"; + +import { Navbar, NavbarBrand, NavbarCollapse, NavbarLink, NavbarToggle } from "flowbite-react"; +import { CiMenuFries } from "react-icons/ci"; +import { type CodeData } from "~/components/code-demo"; + +const code = ` +"use client"; + +import { Navbar } from "flowbite-react"; + +export function Component() { + return ( + + + Flowbite React Logo + Flowbite React + + + + + Home + + + About + + Services + Pricing + Contact + + + ); +} +`; + +const codeRSC = ` +import { Navbar, NavbarBrand, NavbarCollapse, NavbarLink, NavbarToggle } from "flowbite-react"; + +export function Component() { + return ( + + + Flowbite React Logo + Flowbite React + + + + + Home + + + About + + Services + Pricing + Contact + + + ); +} +`; + +export function Component() { + return ( + + + Flowbite React Logo + Flowbite React + + + + + Home + + About + Services + Pricing + Contact + + + ); +} + +export const withCustomMenuIcon: CodeData = { + type: "single", + code: [ + { + fileName: "client", + language: "tsx", + code, + }, + { + fileName: "server", + language: "tsx", + code: codeRSC, + }, + ], + githubSlug: "navbar/navbar.withCustomMenuIcon.tsx", + component: , + iframe: { + height: 300, + noPadding: true, + }, +}; diff --git a/packages/ui/src/components/Navbar/Navbar.stories.tsx b/packages/ui/src/components/Navbar/Navbar.stories.tsx index 039d8eece..21d3be8dd 100644 --- a/packages/ui/src/components/Navbar/Navbar.stories.tsx +++ b/packages/ui/src/components/Navbar/Navbar.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryFn } from "@storybook/react"; +import { CiMenuFries } from "react-icons/ci"; import { Avatar } from "../Avatar"; import { Button } from "../Button"; import { Dropdown } from "../Dropdown"; @@ -104,3 +105,26 @@ WithDropdown.args = { ), }; + +export const CustomToggleMenuIconNavbar = Template.bind({}); +CustomToggleMenuIconNavbar.storyName = "Custom Toggle Menu Icon"; +CustomToggleMenuIconNavbar.args = { + children: ( + <> + + Flowbite Logo + Flowbite + + + + + Home + + About + Services + Pricing + Contact + + + ), +}; diff --git a/packages/ui/src/components/Navbar/NavbarToggle.tsx b/packages/ui/src/components/Navbar/NavbarToggle.tsx index 3c1b58159..f7e98ccb7 100644 --- a/packages/ui/src/components/Navbar/NavbarToggle.tsx +++ b/packages/ui/src/components/Navbar/NavbarToggle.tsx @@ -2,6 +2,7 @@ import type { ComponentProps, FC } from "react"; import { FaBars } from "react-icons/fa"; +import { IoMdClose } from "react-icons/io"; import { twMerge } from "tailwind-merge"; import { mergeDeep } from "../../helpers/merge-deep"; import type { DeepPartial } from "../../types"; @@ -14,11 +15,13 @@ export interface FlowbiteNavbarToggleTheme { export interface NavbarToggleProps extends ComponentProps<"button"> { barIcon?: FC>; + closeIcon?: FC>; theme?: DeepPartial; } export const NavbarToggle: FC = ({ barIcon: BarIcon = FaBars, + closeIcon: CloseIcon = IoMdClose, className, theme: customTheme = {}, ...props @@ -38,8 +41,8 @@ export const NavbarToggle: FC = ({ className={twMerge(theme.base, className)} {...props} > - Open main menu - + {isOpen ? "Close" : "Open"} main menu + {isOpen ? : } ); };