import React from "react"; import { cn, cva } from "~/utils.js"; import type { SidebarMenuItemProps } from "./SidebarMenuRootItem.js"; import { DivButton } from "./DivButton.js"; import { SidebarMenuItemBadge } from "./SidebarMenuItemBadge.js"; import { DistributedOmit } from "type-fest"; import { useAdminUi } from "~/index.js"; const variants = cva( [ "flex w-full cursor-pointer items-center gap-sm", "text-md text-neutral-primary no-underline!", "rounded-md p-xs-plus pr-sm outline-none", "whitespace-nowrap overflow-hidden", "hover:bg-neutral-dark/5", "group-hover/menu-sub-button:bg-neutral-dark/5", "focus:bg-neutral-dark/5 focus:ring-none focus:ring-transparent", "data-[active=true]:bg-neutral-dark/5 data-[active=true]:font-semibold data-[active=true]:pointer-events-none", "group-data-[state=collapsed]:hidden" ], { variants: { variant: { "group-label": [ "uppercase font-semibold text-neutral-muted! text-sm", "pt-md pb-xs-plus pointer-events-none", "hover:bg-transparent! group-hover/menu-sub-button:bg-transparent! focus:bg-transparent! cursor-default!" ] }, disabled: { true: "pointer-events-none text-neutral-disabled!" } } } ); type SidebarMenuSubButtonProps = DistributedOmit; const SidebarMenuSubButton = ({ onClick, variant, active, disabled, icon, // oxlint-disable-next-line pinnedIcon, action, text, badge, className, to, ...linkProps }: SidebarMenuSubButtonProps) => { const { linkComponent: LinkComponent } = useAdminUi(); const sharedProps = { "data-sidebar": "menu-sub-button", "data-active": active, className: variants({ variant, disabled, className: cn(className, action && "pr-xl") }), onClick }; const textContent = {text}; const content = to ? ( {icon} {textContent} {badge && (typeof badge === "string" ? : badge)} ) : ( // We can't use the default button element here because the content of the button // can also contain a button, which is not allowed in HTML. {icon} {textContent} {badge && (typeof badge === "string" ? : badge)} ); return (
{content} {action && (
{action}
)}
); }; export { SidebarMenuSubButton };