feat: menu item classes

This commit is contained in:
2025-04-02 16:54:45 +03:00
parent 0843e4b20d
commit cd618e4d1d
2 changed files with 15 additions and 3 deletions

View File

@@ -5,5 +5,5 @@
}
.menu_item {
@apply w-full cursor-pointer rounded-md bg-gray-100 px-6 py-2 text-center hover:bg-gray-200;
@apply w-full cursor-pointer rounded-md px-6 py-2 text-center hover:bg-gray-200;
}

View File

@@ -1,6 +1,6 @@
import { cn } from "@/utils/class-merge";
import { FunctionComponent } from "preact";
import { useLocation } from "preact-iso";
import { tv } from "tailwind-variants";
import classes from "./menu.module.scss";
interface MenuItemProps {
@@ -11,8 +11,20 @@ interface MenuItemProps {
const MenuItem: FunctionComponent<MenuItemProps> = ({ title, link }: MenuItemProps) => {
const location = useLocation();
const active = location.path === link;
const menuItemClasses = tv({
base: classes.menu_item,
variants: {
activity: {
active: "bg-gray-200",
inactive: "bg-gray-100",
},
},
defaultVariants: {
activity: "inactive",
},
});
return (
<div class={cn(classes.menu_item, { "bg-gray-200": active })} onClick={() => location.route(link)}>
<div class={menuItemClasses({ activity: active ? "active" : "inactive" })} onClick={() => location.route(link)}>
{title}
</div>
);