Skip to content

Commit

Permalink
Merge pull request #55 from plezanje-net/update-tab-menu
Browse files Browse the repository at this point in the history
Add disabled option to tab-menu and update sandbox page.
  • Loading branch information
demshy authored Nov 2, 2024
2 parents 30057a7 + d7fa87e commit e4483dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import IconComment from "@/components/ui/icons/comment";
import IconGallery from "@/components/ui/icons/gallery";
import IconInfo from "@/components/ui/icons/info";
import IconRoutes from "@/components/ui/icons/routes";
import TabMenu, { TabMenuItem } from "@/components/ui/tab-menu";
import TabMenu, { TTabMenuItem } from "@/components/ui/tab-menu";
import { IconSize } from "@/components/ui/icons/icon-size";

interface Props {
Expand All @@ -16,7 +16,7 @@ interface Props {
function CragTabMenu({ crag }: Props) {
const i18nPathname = useI18nPathname();

const menuItems: TabMenuItem[] = [
const menuItems: TTabMenuItem[] = [
{
label: "Info",
link: `/plezalisce/${crag.slug}/info`,
Expand Down
15 changes: 9 additions & 6 deletions src/app/sandbox/tab-menu/[selectedTab]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use client";
import TabMenu, { TabMenuItem } from "@/components/ui/tab-menu";

interface Params {
import TabMenu, { TTabMenuItem } from "@/components/ui/tab-menu";

type TTabMenuPageParams = {
params: { selectedTab?: string };
}
};

function TabMenuPage({ params }: Params) {
const menuItems: TabMenuItem[] = [
function TabMenuPage({ params }: TTabMenuPageParams) {
const menuItems: TTabMenuItem[] = [
{
label: "Informacije",
link: "/sandbox/tab-menu/info",
Expand All @@ -25,9 +26,11 @@ function TabMenuPage({ params }: Params) {
{
label: "Galerija",
link: "/sandbox/tab-menu/galerija",
isActive: params.selectedTab === "galerija",
isActive: false,
isDisabled: true,
},
];

return (
<div className="m-8">
<h1 className="text-xl">Tab menu demo</h1>
Expand Down
52 changes: 34 additions & 18 deletions src/components/ui/tab-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Link from "next/link";
import { ReactNode } from "react";

export interface TabMenuItem {
type TTabMenuItem = {
label: string;
link: string;
isActive: boolean;
icon?: ReactNode;
}
isDisabled?: boolean;
};

interface TabMenuProps {
items: TabMenuItem[];
}
type TTabMenuProps = {
items: TTabMenuItem[];
};

function TabMenu({ items }: TabMenuProps) {
function TabMenu({ items }: TTabMenuProps) {
return (
<ul className="flex justify-center border-b border-b-neutral-200 border-t border-t-transparent">
{items.map((item, index) => (
Expand All @@ -22,27 +23,42 @@ function TabMenu({ items }: TabMenuProps) {
${
item.isActive
? "-mt-px rounded-t-lg border-l border-r border-t border-neutral-200 bg-white"
: "px-px"
: item.isDisabled
? "text-neutral-400 px-px"
: "px-px"
}
`}
>
<Link
href={item.link}
className={`flex gap-2 px-4 py-2 hover:fill-blue-500 hover:text-blue-500 ${
item.isActive && " fill-blue-500 text-blue-500"
}`}
>
{item.icon}
<span
className={`${item.icon && !item.isActive && "hidden md:inline"}`}
{!item.isDisabled ? (
<Link
href={item.link}
className={`flex gap-2 px-4 py-2 hover:fill-blue-500 hover:text-blue-500 ${
item.isActive && " fill-blue-500 text-blue-500"
}`}
>
{item.label}
{item.icon}
<span
className={`${item.icon && !item.isActive && "hidden md:inline"}`}
>
{item.label}
</span>
</Link>
) : (
<span className="flex gap-2 px-4 py-2">
{item.icon}
<span
className={`${item.icon && !item.isActive && "hidden md:inline"}`}
>
{item.label}
</span>
</span>
</Link>
)}
</li>
))}
</ul>
);
}

export default TabMenu;

export type { TTabMenuItem };

0 comments on commit e4483dd

Please sign in to comment.