feat: menu item classes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user