Skip to content

Commit

Permalink
refactor(saas): sidebar external link items
Browse files Browse the repository at this point in the history
  • Loading branch information
alifarooq9 committed Apr 28, 2024
1 parent fd23537 commit 23eee85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions starterkits/saas/src/app/(app)/_components/sidebar-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { ChevronDown } from "lucide-react";
import { ChevronDown, ExternalLinkIcon } from "lucide-react";
import { sidebarConfig } from "@/config/sidebar";
import { type VariantProps } from "class-variance-authority";

Expand Down Expand Up @@ -248,6 +248,7 @@ type NavLinkProps = {
active?: boolean;
isCollapsed?: boolean;
size?: ButtonProps["size"];
external?: boolean;
};

function NavLink({
Expand All @@ -258,16 +259,33 @@ function NavLink({
active,
size = "default",
isCollapsed,
external,
}: NavLinkProps) {
const isExternal = href.startsWith("http") ?? external;

const linkTarget = isExternal ? "_blank" : "_self";

return (
<Link href={href} className={linkStyle({ active, disabled, size })}>
<Link
href={href}
className={linkStyle({ active, disabled, size })}
target={linkTarget}
rel="noreferrer"
>
<Icon
className={cn(
"flex-shrink-0",
isCollapsed ? "h-5 w-5" : "h-4 w-4 ",
)}
/>
{!isCollapsed && <span className="truncate">{label}</span>}
{!isCollapsed && (
<span className="flex-grow truncate text-left">{label}</span>
)}
{isExternal && (
<span className="text-muted-foreground">
<ExternalLinkIcon className="ml-2 h-3 w-3" />
</span>
)}
</Link>
);
}
2 changes: 2 additions & 0 deletions starterkits/saas/src/config/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type NavItemBase = {

type NavItemWithHref = NavItemBase & {
href: string;
external?: boolean;
subMenu?: never;
};

Expand All @@ -50,6 +51,7 @@ type NavItemWithSubMenu = NavItemBase & {
label: string;
href: string;
icon: React.ComponentType<IconProps>;
external?: boolean;
disabled?: boolean;
}[];
};
Expand Down

0 comments on commit 23eee85

Please sign in to comment.