Skip to content

Commit 21dab1f

Browse files
feat(Navbar): add as prop (#526) (#528)
1 parent 98342c7 commit 21dab1f

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/docs/pages/NavbarPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FC } from 'react';
2+
import { Link } from 'react-router-dom';
23
import { Avatar, Button, Dropdown, Navbar } from '../../lib';
34
import type { CodeExample } from './DemoPage';
45
import { DemoPage } from './DemoPage';
@@ -9,7 +10,7 @@ const NavbarPage: FC = () => {
910
title: 'Default navbar',
1011
code: (
1112
<Navbar fluid rounded>
12-
<Navbar.Brand href="https://flowbite.com/">
13+
<Navbar.Brand as={Link} to="/navbars">
1314
<img src="https://flowbite.com/docs/images/logo.svg" className="mr-3 h-6 sm:h-9" alt="Flowbite Logo" />
1415
<span className="self-center whitespace-nowrap text-xl font-semibold dark:text-white">Flowbite</span>
1516
</Navbar.Brand>
@@ -18,7 +19,9 @@ const NavbarPage: FC = () => {
1819
<Navbar.Link href="/navbars" active>
1920
Home
2021
</Navbar.Link>
21-
<Navbar.Link href="/navbars">About</Navbar.Link>
22+
<Navbar.Link as={Link} to={'/navbars'}>
23+
About
24+
</Navbar.Link>
2225
<Navbar.Link href="/navbars">Services</Navbar.Link>
2326
<Navbar.Link href="/navbars">Pricing</Navbar.Link>
2427
<Navbar.Link href="/navbars">Contact</Navbar.Link>
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import classNames from 'classnames';
2-
import type { ComponentProps, FC, PropsWithChildren } from 'react';
2+
import type { ComponentProps, ElementType, FC, PropsWithChildren } from 'react';
3+
import type { LinkProps } from 'react-router-dom';
34
import { DeepPartial } from '..';
45
import { mergeDeep } from '../../helpers/mergeDeep';
56
import { useTheme } from '../Flowbite/ThemeContext';
@@ -8,16 +9,24 @@ export interface FlowbiteNavbarBrandTheme {
89
base: string;
910
}
1011

11-
export interface NavbarBrandProps extends PropsWithChildren<ComponentProps<'a'>> {
12+
export interface NavbarBrandProps extends PropsWithChildren<ComponentProps<'a'>>, Partial<Pick<LinkProps, 'to'>> {
1213
theme?: DeepPartial<FlowbiteNavbarBrandTheme>;
14+
as?: ElementType;
15+
href?: string;
1316
}
1417

15-
export const NavbarBrand: FC<NavbarBrandProps> = ({ theme: customTheme = {}, children, href, className, ...props }) => {
18+
export const NavbarBrand: FC<NavbarBrandProps> = ({
19+
theme: customTheme = {},
20+
children,
21+
className,
22+
as: Component = 'a',
23+
...props
24+
}) => {
1625
const theme = mergeDeep(useTheme().theme.navbar.brand, customTheme);
1726

1827
return (
19-
<a href={href} className={classNames(theme.base, className)} {...props}>
28+
<Component className={classNames(theme.base, className)} {...props}>
2029
{children}
21-
</a>
30+
</Component>
2231
);
2332
};

src/lib/components/Navbar/NavbarLink.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import classNames from 'classnames';
2-
import type { ComponentProps, FC, PropsWithChildren } from 'react';
2+
import type { ComponentProps, ElementType, FC, PropsWithChildren } from 'react';
3+
import type { LinkProps } from 'react-router-dom';
34
import { DeepPartial } from '..';
45
import { mergeDeep } from '../../helpers/mergeDeep';
56
import { FlowbiteBoolean } from '../Flowbite/FlowbiteTheme';
@@ -11,28 +12,28 @@ export interface FlowbiteNavbarLinkTheme {
1112
disabled: FlowbiteBoolean;
1213
}
1314

14-
export interface NavbarLinkProps extends PropsWithChildren<ComponentProps<'a'>> {
15+
export interface NavbarLinkProps extends PropsWithChildren<ComponentProps<'a'>>, Partial<Pick<LinkProps, 'to'>> {
1516
active?: boolean;
1617
disabled?: boolean;
1718
href?: string;
1819
theme?: DeepPartial<FlowbiteNavbarLinkTheme>;
20+
as?: ElementType;
1921
}
2022

2123
export const NavbarLink: FC<NavbarLinkProps> = ({
2224
active,
2325
disabled,
24-
href,
2526
theme: customTheme = {},
2627
children,
2728
className,
29+
as: Component = 'a',
2830
...props
2931
}) => {
3032
const theme = mergeDeep(useTheme().theme.navbar.link, customTheme);
3133

3234
return (
3335
<li>
34-
<a
35-
href={href}
36+
<Component
3637
className={classNames(
3738
theme.base,
3839
{
@@ -45,7 +46,7 @@ export const NavbarLink: FC<NavbarLinkProps> = ({
4546
{...props}
4647
>
4748
{children}
48-
</a>
49+
</Component>
4950
</li>
5051
);
5152
};

0 commit comments

Comments
 (0)