@betterinternship/components 3.1.4 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/app-header.js +5 -5
- package/dist/components/app-header.js.map +1 -1
- package/dist/components/autocomplete.js +5 -5
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/context-menu.js +8 -8
- package/dist/components/context-menu.js.map +1 -1
- package/dist/components/dropdown-menu.js +8 -8
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/dropdown.js +3 -3
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/option-list.d.ts +40 -0
- package/dist/components/option-list.js +39 -0
- package/dist/components/option-list.js.map +1 -0
- package/dist/components/select.js +3 -3
- package/dist/components/select.js.map +1 -1
- package/dist/components/table.js +1 -1
- package/dist/components/table.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/theme.css +6 -0
|
@@ -60,13 +60,13 @@ function AppHeader({ siteName, homeHref, nav, links = [], userPrimary, userSecon
|
|
|
60
60
|
: ''), children: [jsx("div", { className: "flex h-6 w-6 items-center justify-center overflow-hidden rounded-full bg-gray-100", children: userAvatarUrl ? (jsx("img", { src: userAvatarUrl, alt: "", className: "h-full w-full object-contain" })) : (jsx(UserRound, { className: "h-5 w-5 text-gray-500" })) }), jsxs("div", { className: "flex items-center gap-0.5", children: [jsx("span", { className: "text-xs", children: "Account" }), jsx(ChevronDown, { className: "h-3! w-3! transition-transform group-data-[state=open]:rotate-180" })] })] }) }), jsxs(DropdownMenuContent, { align: "end", className: "w-max min-w-44", children: [userPrimary && (jsxs("div", { className: "px-2 py-1.5", children: [jsx("div", { className: "text-center text-sm font-medium", children: userPrimary }), userSecondary && (jsx("div", { className: "text-muted-foreground text-center text-xs", children: userSecondary }))] })), jsx(DropdownMenuSeparator, {}), profileHref && (jsx(DropdownMenuItem, { asChild: true, children: jsxs(Link, { href: profileHref, children: [jsx(UserRound, { className: "h-4 w-4" }), "Profile"] }) })), accountNav.map((item) => {
|
|
61
61
|
const Icon = item.icon ?? labelIcon(item.label);
|
|
62
62
|
return (jsx(DropdownMenuItem, { asChild: true, children: jsxs(Link, { href: item.href, children: [jsx(Icon, { className: "h-4 w-4" }), item.label] }) }, item.href));
|
|
63
|
-
}), (profileHref || accountNav.length > 0) && (jsx(DropdownMenuSeparator, {})), jsxs(DropdownMenuItem, { variant: "destructive", disabled: logout.isPending, onClick: () => logout.mutate(), children: [jsx(LogOut, { className: "h-4 w-4" }), logout.isPending ? 'Logging out...' : 'Sign Out'] })] })] })] }), jsxs("div", { className: "flex items-center gap-1 md:hidden", children: [onSearchClick && (jsx("button", { type: "button", "aria-label": "Search", className: "inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50", onClick: onSearchClick, children: jsx(Search, { className: "h-5 w-5" }) })), showMobileMenu && (jsx("button", { type: "button", "aria-label": isDrawerOpen ? 'Close menu' : 'Open menu', className: "inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50", onClick: () => setIsDrawerOpen(!isDrawerOpen), children: isDrawerOpen ? (jsx(X, { className: "h-5 w-5" })) : (jsx(Menu, { className: "h-5 w-5" })) }))] })] }), showMobileMenu && isDrawerOpen && (jsx("div", { className: "fixed inset-0 z-[30] duration-200 md:hidden", onClick: () => setIsDrawerOpen(false) })), showMobileMenu && (jsx("div", { className: cn('fixed top-0 right-0 z-[31] h-[100svh] w-full max-w-[92%] border-l border-border bg-white shadow-xl sm:max-w-[420px] md:hidden', 'transition-transform duration-250 ease-out', isDrawerOpen ? 'translate-x-0' : 'translate-x-full'), role: "dialog", "aria-modal": "true", "aria-label": "Mobile menu", children: jsxs("div", { className: "flex h-full flex-col", children: [jsxs("div", { className: "mt-1 flex items-center justify-between border-b px-4 py-3", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx(Image, { src: logoPath, alt: "", width: 25, height: 25, className: "h-6 w-6 rounded object-contain" }), jsx("span", { className: "text-sm font-semibold", children: brand }), jsx("span", { className: "rounded border border-border bg-gray-50 px-1 py-0 text-xs font-medium text-gray-400 leading-none", children: siteName })] }), jsx("button", { type: "button", "aria-label": "Close menu", className: "inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors hover:bg-gray-100", onClick: () => setIsDrawerOpen(false), children: jsx(X, { className: "h-5 w-5" }) })] }), jsxs("div", { className: "flex-1 overflow-y-auto p-4", children: [userPrimary && (jsxs("div", { className: "flex items-center gap-2 pb-2", children: [jsx(UserRound, { className: "h-5 w-5 text-gray-500" }), jsx("span", { className: "text-sm font-semibold text-gray-900", children: userPrimary })] })), jsx(Divider, { className: "my-4" }), actions && jsx("div", { className: "mb-2", children: actions }), jsx("nav", { className: "
|
|
63
|
+
}), (profileHref || accountNav.length > 0) && (jsx(DropdownMenuSeparator, {})), jsxs(DropdownMenuItem, { variant: "destructive", disabled: logout.isPending, onClick: () => logout.mutate(), children: [jsx(LogOut, { className: "h-4 w-4" }), logout.isPending ? 'Logging out...' : 'Sign Out'] })] })] })] }), jsxs("div", { className: "flex items-center gap-1 md:hidden", children: [onSearchClick && (jsx("button", { type: "button", "aria-label": "Search", className: "inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50", onClick: onSearchClick, children: jsx(Search, { className: "h-5 w-5" }) })), showMobileMenu && (jsx("button", { type: "button", "aria-label": isDrawerOpen ? 'Close menu' : 'Open menu', className: "inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50", onClick: () => setIsDrawerOpen(!isDrawerOpen), children: isDrawerOpen ? (jsx(X, { className: "h-5 w-5" })) : (jsx(Menu, { className: "h-5 w-5" })) }))] })] }), showMobileMenu && isDrawerOpen && (jsx("div", { className: "fixed inset-0 z-[30] duration-200 md:hidden", onClick: () => setIsDrawerOpen(false) })), showMobileMenu && (jsx("div", { className: cn('fixed top-0 right-0 z-[31] h-[100svh] w-full max-w-[92%] border-l border-border bg-white shadow-xl sm:max-w-[420px] md:hidden', 'transition-transform duration-250 ease-out', isDrawerOpen ? 'translate-x-0' : 'translate-x-full'), role: "dialog", "aria-modal": "true", "aria-label": "Mobile menu", children: jsxs("div", { className: "flex h-full flex-col", children: [jsxs("div", { className: "mt-1 flex items-center justify-between border-b px-4 py-3", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx(Image, { src: logoPath, alt: "", width: 25, height: 25, className: "h-6 w-6 rounded object-contain" }), jsx("span", { className: "text-sm font-semibold", children: brand }), jsx("span", { className: "rounded border border-border bg-gray-50 px-1 py-0 text-xs font-medium text-gray-400 leading-none", children: siteName })] }), jsx("button", { type: "button", "aria-label": "Close menu", className: "inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors hover:bg-gray-100", onClick: () => setIsDrawerOpen(false), children: jsx(X, { className: "h-5 w-5" }) })] }), jsxs("div", { className: "flex-1 overflow-y-auto p-4", children: [userPrimary && (jsxs("div", { className: "flex items-center gap-2 pb-2", children: [jsx(UserRound, { className: "h-5 w-5 text-gray-500" }), jsx("span", { className: "text-sm font-semibold text-gray-900", children: userPrimary })] })), jsx(Divider, { className: "my-4" }), actions && jsx("div", { className: "mb-2", children: actions }), jsx("nav", { className: "flex flex-col gap-option-gap", children: nav.map((item) => {
|
|
64
64
|
const Icon = item.icon ?? labelIcon(item.label);
|
|
65
|
-
return (jsx(Link, { href: item.href, className: "block w-full", children: jsxs("button", { className: "flex w-full items-center justify-between rounded-
|
|
66
|
-
}) })] }), jsxs("div", { className: "mt-auto border-t px-4 py-3
|
|
65
|
+
return (jsx(Link, { href: item.href, className: "block w-full", children: jsxs("button", { className: "flex min-h-option-row w-full items-center justify-between rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx(Icon, { className: "h-4 w-4 text-muted-foreground" }), jsx("span", { children: item.label }), !!item.badge && (jsx("span", { className: "inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 text-xs font-bold leading-none text-amber-900", children: "!" }))] }), jsx(ChevronRight, { className: "h-4 w-4 text-muted-foreground/60" })] }) }, item.href));
|
|
66
|
+
}) })] }), jsxs("div", { className: "mt-auto flex flex-col gap-option-gap border-t border-border px-4 py-3", children: [profileHref && (jsx(Link, { href: profileHref, className: "block w-full", children: jsxs("button", { className: "flex min-h-option-row w-full items-center gap-2 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted", children: [jsx(UserRound, { className: "h-4 w-4" }), "Profile"] }) })), accountNav.map((item) => {
|
|
67
67
|
const Icon = item.icon ?? labelIcon(item.label);
|
|
68
|
-
return (jsx(Link, { href: item.href, className: "block w-full", children: jsxs("button", { className: "flex w-full items-center gap-2 rounded-
|
|
69
|
-
}), jsxs("button", { onClick: () => logout.mutate(), disabled: logout.isPending, className: "flex w-full items-center justify-center gap-2 rounded-
|
|
68
|
+
return (jsx(Link, { href: item.href, className: "block w-full", children: jsxs("button", { className: "flex min-h-option-row w-full items-center gap-2 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted", children: [jsx(Icon, { className: "h-4 w-4" }), item.label] }) }, item.href));
|
|
69
|
+
}), jsxs("button", { onClick: () => logout.mutate(), disabled: logout.isPending, className: "flex min-h-option-row w-full items-center justify-center gap-2 rounded-control-sm px-option-x py-2 font-medium text-destructive transition-colors hover:bg-destructive/10", children: [jsx(LogOut, { className: "h-4 w-4" }), logout.isPending ? 'Logging out...' : 'Sign Out'] })] })] }) }))] }));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export { AppHeader };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-header.js","sources":["../../src/components/app-header.tsx"],"sourcesContent":["'use client';\n\nimport Link from 'next/link';\nimport Image from 'next/image';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuSeparator,\n} from '@/components/dropdown-menu';\nimport { Button } from '@/components/button';\nimport { Divider } from '@/components/divider';\nimport { cn } from '@/utils';\nimport {\n LogOut,\n Menu,\n Search,\n X,\n UserRound,\n ChevronDown,\n ChevronRight,\n Handshake,\n Mail,\n History,\n FileText,\n Users,\n LayoutDashboard,\n FileSignature,\n GraduationCap,\n Building2,\n SearchCheck,\n} from 'lucide-react';\nimport { useState, useEffect } from 'react';\nimport type { ReactNode } from 'react';\nimport type { LucideIcon } from 'lucide-react';\n\nexport interface NavItem {\n href: string;\n label: string;\n badge?: number;\n icon?: LucideIcon;\n}\n\ninterface AppHeaderProps {\n /** Optional site name. */\n siteName?: string;\n homeHref: string;\n nav: NavItem[];\n /** Optional desktop links displayed next to the brand. */\n links?: NavItem[];\n userPrimary?: string;\n userSecondary?: string;\n logout: () => Promise<unknown>;\n postLogoutPath: string;\n profileHref?: string;\n userAvatarUrl?: string | null;\n accountNav?: NavItem[];\n /** Overrides the hardcoded \"Partners\" brand text. */\n brand?: string;\n /** Overrides the hardcoded \"/betterinternship-logo.png\" logo path. */\n logoPath?: string;\n /** Extra controls rendered next to the nav (desktop) and inside the drawer (mobile). */\n actions?: ReactNode;\n /**\n * Inline search control rendered in the header's center region on desktop\n * (`md` and up only). Purely a layout slot — the consumer owns all search\n * state and behavior. For mobile, pair with `onSearchClick`.\n */\n search?: ReactNode;\n /**\n * When set, renders a search icon button on mobile immediately left of the\n * hamburger. Typically opens a full-screen search overlay owned by the\n * consumer.\n */\n onSearchClick?: () => void;\n /**\n * Set to false to hide the mobile hamburger button and its side drawer\n * entirely — for consumers that provide their own mobile navigation (e.g.\n * a bottom tab bar) and don't want the nav/profile/logout items duplicated.\n * Defaults to true.\n */\n showMobileMenu?: boolean;\n}\n\nfunction labelIcon(label: string): LucideIcon {\n const map: Record<string, LucideIcon> = {\n Partners: Handshake,\n Invites: Mail,\n Invitations: Mail,\n Accounts: Users,\n 'Activity Log': History,\n 'MOA Templates': FileText,\n Universities: GraduationCap,\n Companies: Building2,\n 'Company Reviews': SearchCheck,\n 'Request MOA': FileSignature,\n Dashboard: LayoutDashboard,\n };\n return map[label] ?? Handshake;\n}\n\nexport function AppHeader({\n siteName,\n homeHref,\n nav,\n links = [],\n userPrimary,\n userSecondary,\n logout: logoutFn,\n postLogoutPath,\n profileHref,\n userAvatarUrl,\n accountNav = [],\n brand = 'Partners',\n logoPath = '/betterinternship-logo.png',\n actions,\n search,\n onSearchClick,\n showMobileMenu = true,\n}: AppHeaderProps) {\n const pathname = usePathname() ?? '';\n const router = useRouter();\n const queryClient = useQueryClient();\n const [isDrawerOpen, setIsDrawerOpen] = useState(false);\n\n useEffect(() => {\n setIsDrawerOpen(false);\n }, [pathname]);\n\n useEffect(() => {\n document.body.style.overflow = isDrawerOpen ? 'hidden' : '';\n return () => {\n document.body.style.overflow = '';\n };\n }, [isDrawerOpen]);\n\n const logout = useMutation({\n mutationFn: logoutFn,\n onSettled: () => {\n queryClient.clear();\n router.replace(postLogoutPath);\n },\n });\n\n const isActive = (href: string) =>\n pathname === href || pathname.startsWith(`${href}/`);\n\n return (\n <header className=\"sticky top-0 z-40 w-full bg-white\">\n <div className=\"flex min-h-[76px] w-full items-center gap-7 px-4 md:px-6 max-md:min-h-[72px] max-md:gap-3 max-md:py-3\">\n {/* Brand */}\n <Link\n href={homeHref}\n aria-label={brand}\n className=\"inline-flex shrink-0 items-center gap-3 text-lg font-[750] leading-[1.5] tracking-[-.0375rem] text-landing-navy focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-landing-blue max-md:gap-1.5 max-md:text-base\"\n >\n <div className=\"flex items-center gap-3 max-md:gap-1.5\">\n <Image\n src={logoPath}\n alt=\"\"\n width={24}\n height={24}\n className=\"flex-none\"\n />\n {/* Wordmark hides below md — the logo carries the link, which keeps\n its name via the aria-label above. */}\n <div className=\"hidden items-center md:flex\">\n <span>\n {brand}\n </span>\n {siteName && (\n <>\n <span className=\"mx-2.5 text-gray-300\" aria-hidden=\"true\">\n |\n </span>\n <span className=\"font-display text-gray-500\">{siteName}</span>\n </>\n )}\n </div>\n </div>\n </Link>\n\n {links.length > 0 && (\n <nav aria-label=\"Resources\" className=\"hidden shrink-0 items-center gap-4 text-sm font-[550] text-landing-nav md:flex xl:gap-7\">\n {links.map((item) => (\n <Link\n key={item.href}\n href={item.href}\n aria-current={isActive(item.href) ? 'page' : undefined}\n className=\"flex min-h-11 items-center rounded-sm text-landing-nav transition-colors duration-[180ms] hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-landing-blue aria-[current=page]:text-landing-blue\"\n >\n {item.label}\n </Link>\n ))}\n </nav>\n )}\n\n {/* Desktop center: inline search slot. The empty div doubles as the\n spacer that keeps the right cluster right-aligned when no search\n is passed. */}\n <div className=\"hidden min-w-0 flex-1 md:flex md:items-center\">\n {search}\n </div>\n\n {/* Desktop right side: nav buttons + user */}\n <div className=\"ml-auto hidden shrink-0 items-center gap-1 md:flex\">\n {nav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Button\n key={item.href}\n variant=\"ghost\"\n className={cn(\n 'relative min-h-12 min-w-0 flex-col items-center justify-center gap-1 rounded-[.33em] px-3 py-1 text-xs font-normal text-gray-600 hover:bg-gray-100 hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-landing-blue',\n isActive(item.href)\n ? 'text-landing-blue'\n : '',\n )}\n onClick={() => router.push(item.href)}\n >\n <Icon className=\"h-6! w-6!\" strokeWidth={1.7} />\n <span className=\"text-xs\">{item.label}</span>\n {!!item.badge && (\n <span className=\"absolute -top-0.5 right-5.5 inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 text-xs font-bold leading-none text-amber-900\">\n {item.badge}\n </span>\n )}\n </Button>\n );\n })}\n\n {actions}\n\n {/* User dropdown */}\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <Button\n variant=\"ghost\"\n className={cn(\n 'group min-h-12 w-20 flex-col items-center justify-center gap-1 rounded-[.33em] px-2 py-1 text-xs font-normal text-gray-600 hover:bg-gray-100 hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-landing-blue',\n (profileHref && isActive(profileHref)) ||\n accountNav.some((item) => isActive(item.href))\n ? 'text-landing-blue'\n : '',\n )}\n >\n <div className=\"flex h-6 w-6 items-center justify-center overflow-hidden rounded-full bg-gray-100\">\n {userAvatarUrl ? (\n <img\n src={userAvatarUrl}\n alt=\"\"\n className=\"h-full w-full object-contain\"\n />\n ) : (\n <UserRound className=\"h-5 w-5 text-gray-500\" />\n )}\n </div>\n <div className=\"flex items-center gap-0.5\">\n <span className=\"text-xs\">Account</span>\n <ChevronDown className=\"h-3! w-3! transition-transform group-data-[state=open]:rotate-180\" />\n </div>\n </Button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-max min-w-44\">\n {userPrimary && (\n <div className=\"px-2 py-1.5\">\n <div className=\"text-center text-sm font-medium\">\n {userPrimary}\n </div>\n {userSecondary && (\n <div className=\"text-muted-foreground text-center text-xs\">\n {userSecondary}\n </div>\n )}\n </div>\n )}\n <DropdownMenuSeparator />\n {profileHref && (\n <DropdownMenuItem asChild>\n <Link href={profileHref}>\n <UserRound className=\"h-4 w-4\" />\n Profile\n </Link>\n </DropdownMenuItem>\n )}\n {accountNav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <DropdownMenuItem key={item.href} asChild>\n <Link href={item.href}>\n <Icon className=\"h-4 w-4\" />\n {item.label}\n </Link>\n </DropdownMenuItem>\n );\n })}\n {(profileHref || accountNav.length > 0) && (\n <DropdownMenuSeparator />\n )}\n <DropdownMenuItem\n variant=\"destructive\"\n disabled={logout.isPending}\n onClick={() => logout.mutate()}\n >\n <LogOut className=\"h-4 w-4\" />\n {logout.isPending ? 'Logging out...' : 'Sign Out'}\n </DropdownMenuItem>\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n\n {/* Mobile: search trigger + hamburger */}\n <div className=\"flex items-center gap-1 md:hidden\">\n {onSearchClick && (\n <button\n type=\"button\"\n aria-label=\"Search\"\n className=\"inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50\"\n onClick={onSearchClick}\n >\n <Search className=\"h-5 w-5\" />\n </button>\n )}\n {showMobileMenu && (\n <button\n type=\"button\"\n aria-label={isDrawerOpen ? 'Close menu' : 'Open menu'}\n className=\"inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50\"\n onClick={() => setIsDrawerOpen(!isDrawerOpen)}\n >\n {isDrawerOpen ? (\n <X className=\"h-5 w-5\" />\n ) : (\n <Menu className=\"h-5 w-5\" />\n )}\n </button>\n )}\n </div>\n </div>\n\n {/* Mobile right drawer */}\n {showMobileMenu && isDrawerOpen && (\n <div\n className=\"fixed inset-0 z-[30] duration-200 md:hidden\"\n onClick={() => setIsDrawerOpen(false)}\n />\n )}\n\n {showMobileMenu && (\n <div\n className={cn(\n 'fixed top-0 right-0 z-[31] h-[100svh] w-full max-w-[92%] border-l border-border bg-white shadow-xl sm:max-w-[420px] md:hidden',\n 'transition-transform duration-250 ease-out',\n isDrawerOpen ? 'translate-x-0' : 'translate-x-full',\n )}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Mobile menu\"\n >\n <div className=\"flex h-full flex-col\">\n <div className=\"mt-1 flex items-center justify-between border-b px-4 py-3\">\n <div className=\"flex items-center gap-2\">\n <Image\n src={logoPath}\n alt=\"\"\n width={25}\n height={25}\n className=\"h-6 w-6 rounded object-contain\"\n />\n <span className=\"text-sm font-semibold\">{brand}</span>\n <span className=\"rounded border border-border bg-gray-50 px-1 py-0 text-xs font-medium text-gray-400 leading-none\">\n {siteName}\n </span>\n </div>\n <button\n type=\"button\"\n aria-label=\"Close menu\"\n className=\"inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors hover:bg-gray-100\"\n onClick={() => setIsDrawerOpen(false)}\n >\n <X className=\"h-5 w-5\" />\n </button>\n </div>\n\n <div className=\"flex-1 overflow-y-auto p-4\">\n {userPrimary && (\n <div className=\"flex items-center gap-2 pb-2\">\n <UserRound className=\"h-5 w-5 text-gray-500\" />\n <span className=\"text-sm font-semibold text-gray-900\">\n {userPrimary}\n </span>\n </div>\n )}\n\n <Divider className=\"my-4\" />\n\n {actions && <div className=\"mb-2\">{actions}</div>}\n\n <nav className=\"space-y-1\">\n {nav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Link\n key={item.href}\n href={item.href}\n className=\"block w-full\"\n >\n <button className=\"flex w-full items-center justify-between rounded-md border border-transparent px-3 py-2 text-sm transition-colors hover:border-border-hover hover:bg-gray-50\">\n <div className=\"flex items-center gap-2\">\n <Icon className=\"h-4 w-4 text-gray-500\" />\n <span>{item.label}</span>\n {!!item.badge && (\n <span className=\"inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 text-xs font-bold leading-none text-amber-900\">\n !\n </span>\n )}\n </div>\n <ChevronRight className=\"h-4 w-4 text-gray-300\" />\n </button>\n </Link>\n );\n })}\n </nav>\n </div>\n\n <div className=\"mt-auto border-t px-4 py-3 space-y-1\">\n {profileHref && (\n <Link href={profileHref} className=\"block w-full\">\n <button className=\"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-gray-50\">\n <UserRound className=\"h-4 w-4\" />\n Profile\n </button>\n </Link>\n )}\n {accountNav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Link\n key={item.href}\n href={item.href}\n className=\"block w-full\"\n >\n <button className=\"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-gray-50\">\n <Icon className=\"h-4 w-4\" />\n {item.label}\n </button>\n </Link>\n );\n })}\n <button\n onClick={() => logout.mutate()}\n disabled={logout.isPending}\n className=\"flex w-full items-center justify-center gap-2 rounded-md py-2 font-medium text-red-600 transition-colors hover:bg-red-50\"\n >\n <LogOut className=\"h-4 w-4\" />\n {logout.isPending ? 'Logging out...' : 'Sign Out'}\n </button>\n </div>\n </div>\n </div>\n )}\n </header>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAuFA;AACE;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEF;AACF;AAEM;AAmBJ;AACA;AACA;;;;AAKA;;AAGE;AACA;;AAEA;AACF;;AAGE;;;AAGE;;AAEH;AAED;AAGA;AA4DU;AACA;AAOQ;AACA;AAaV;AAYU;AACA;AACA;AA2CJ;AACA;AAQF;AAyGI;AACA;;AAkCF;AACA;;AA2BhB;;"}
|
|
1
|
+
{"version":3,"file":"app-header.js","sources":["../../src/components/app-header.tsx"],"sourcesContent":["'use client';\n\nimport Link from 'next/link';\nimport Image from 'next/image';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuSeparator,\n} from '@/components/dropdown-menu';\nimport { Button } from '@/components/button';\nimport { Divider } from '@/components/divider';\nimport { cn } from '@/utils';\nimport {\n LogOut,\n Menu,\n Search,\n X,\n UserRound,\n ChevronDown,\n ChevronRight,\n Handshake,\n Mail,\n History,\n FileText,\n Users,\n LayoutDashboard,\n FileSignature,\n GraduationCap,\n Building2,\n SearchCheck,\n} from 'lucide-react';\nimport { useState, useEffect } from 'react';\nimport type { ReactNode } from 'react';\nimport type { LucideIcon } from 'lucide-react';\n\nexport interface NavItem {\n href: string;\n label: string;\n badge?: number;\n icon?: LucideIcon;\n}\n\ninterface AppHeaderProps {\n /** Optional site name. */\n siteName?: string;\n homeHref: string;\n nav: NavItem[];\n /** Optional desktop links displayed next to the brand. */\n links?: NavItem[];\n userPrimary?: string;\n userSecondary?: string;\n logout: () => Promise<unknown>;\n postLogoutPath: string;\n profileHref?: string;\n userAvatarUrl?: string | null;\n accountNav?: NavItem[];\n /** Overrides the hardcoded \"Partners\" brand text. */\n brand?: string;\n /** Overrides the hardcoded \"/betterinternship-logo.png\" logo path. */\n logoPath?: string;\n /** Extra controls rendered next to the nav (desktop) and inside the drawer (mobile). */\n actions?: ReactNode;\n /**\n * Inline search control rendered in the header's center region on desktop\n * (`md` and up only). Purely a layout slot — the consumer owns all search\n * state and behavior. For mobile, pair with `onSearchClick`.\n */\n search?: ReactNode;\n /**\n * When set, renders a search icon button on mobile immediately left of the\n * hamburger. Typically opens a full-screen search overlay owned by the\n * consumer.\n */\n onSearchClick?: () => void;\n /**\n * Set to false to hide the mobile hamburger button and its side drawer\n * entirely — for consumers that provide their own mobile navigation (e.g.\n * a bottom tab bar) and don't want the nav/profile/logout items duplicated.\n * Defaults to true.\n */\n showMobileMenu?: boolean;\n}\n\nfunction labelIcon(label: string): LucideIcon {\n const map: Record<string, LucideIcon> = {\n Partners: Handshake,\n Invites: Mail,\n Invitations: Mail,\n Accounts: Users,\n 'Activity Log': History,\n 'MOA Templates': FileText,\n Universities: GraduationCap,\n Companies: Building2,\n 'Company Reviews': SearchCheck,\n 'Request MOA': FileSignature,\n Dashboard: LayoutDashboard,\n };\n return map[label] ?? Handshake;\n}\n\nexport function AppHeader({\n siteName,\n homeHref,\n nav,\n links = [],\n userPrimary,\n userSecondary,\n logout: logoutFn,\n postLogoutPath,\n profileHref,\n userAvatarUrl,\n accountNav = [],\n brand = 'Partners',\n logoPath = '/betterinternship-logo.png',\n actions,\n search,\n onSearchClick,\n showMobileMenu = true,\n}: AppHeaderProps) {\n const pathname = usePathname() ?? '';\n const router = useRouter();\n const queryClient = useQueryClient();\n const [isDrawerOpen, setIsDrawerOpen] = useState(false);\n\n useEffect(() => {\n setIsDrawerOpen(false);\n }, [pathname]);\n\n useEffect(() => {\n document.body.style.overflow = isDrawerOpen ? 'hidden' : '';\n return () => {\n document.body.style.overflow = '';\n };\n }, [isDrawerOpen]);\n\n const logout = useMutation({\n mutationFn: logoutFn,\n onSettled: () => {\n queryClient.clear();\n router.replace(postLogoutPath);\n },\n });\n\n const isActive = (href: string) =>\n pathname === href || pathname.startsWith(`${href}/`);\n\n return (\n <header className=\"sticky top-0 z-40 w-full bg-white\">\n <div className=\"flex min-h-[76px] w-full items-center gap-7 px-4 md:px-6 max-md:min-h-[72px] max-md:gap-3 max-md:py-3\">\n {/* Brand */}\n <Link\n href={homeHref}\n aria-label={brand}\n className=\"inline-flex shrink-0 items-center gap-3 text-lg font-[750] leading-[1.5] tracking-[-.0375rem] text-landing-navy focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-landing-blue max-md:gap-1.5 max-md:text-base\"\n >\n <div className=\"flex items-center gap-3 max-md:gap-1.5\">\n <Image\n src={logoPath}\n alt=\"\"\n width={24}\n height={24}\n className=\"flex-none\"\n />\n {/* Wordmark hides below md — the logo carries the link, which keeps\n its name via the aria-label above. */}\n <div className=\"hidden items-center md:flex\">\n <span>\n {brand}\n </span>\n {siteName && (\n <>\n <span className=\"mx-2.5 text-gray-300\" aria-hidden=\"true\">\n |\n </span>\n <span className=\"font-display text-gray-500\">{siteName}</span>\n </>\n )}\n </div>\n </div>\n </Link>\n\n {links.length > 0 && (\n <nav aria-label=\"Resources\" className=\"hidden shrink-0 items-center gap-4 text-sm font-[550] text-landing-nav md:flex xl:gap-7\">\n {links.map((item) => (\n <Link\n key={item.href}\n href={item.href}\n aria-current={isActive(item.href) ? 'page' : undefined}\n className=\"flex min-h-11 items-center rounded-sm text-landing-nav transition-colors duration-[180ms] hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-landing-blue aria-[current=page]:text-landing-blue\"\n >\n {item.label}\n </Link>\n ))}\n </nav>\n )}\n\n {/* Desktop center: inline search slot. The empty div doubles as the\n spacer that keeps the right cluster right-aligned when no search\n is passed. */}\n <div className=\"hidden min-w-0 flex-1 md:flex md:items-center\">\n {search}\n </div>\n\n {/* Desktop right side: nav buttons + user */}\n <div className=\"ml-auto hidden shrink-0 items-center gap-1 md:flex\">\n {nav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Button\n key={item.href}\n variant=\"ghost\"\n className={cn(\n 'relative min-h-12 min-w-0 flex-col items-center justify-center gap-1 rounded-[.33em] px-3 py-1 text-xs font-normal text-gray-600 hover:bg-gray-100 hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-landing-blue',\n isActive(item.href)\n ? 'text-landing-blue'\n : '',\n )}\n onClick={() => router.push(item.href)}\n >\n <Icon className=\"h-6! w-6!\" strokeWidth={1.7} />\n <span className=\"text-xs\">{item.label}</span>\n {!!item.badge && (\n <span className=\"absolute -top-0.5 right-5.5 inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 text-xs font-bold leading-none text-amber-900\">\n {item.badge}\n </span>\n )}\n </Button>\n );\n })}\n\n {actions}\n\n {/* User dropdown */}\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <Button\n variant=\"ghost\"\n className={cn(\n 'group min-h-12 w-20 flex-col items-center justify-center gap-1 rounded-[.33em] px-2 py-1 text-xs font-normal text-gray-600 hover:bg-gray-100 hover:text-landing-blue focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-landing-blue',\n (profileHref && isActive(profileHref)) ||\n accountNav.some((item) => isActive(item.href))\n ? 'text-landing-blue'\n : '',\n )}\n >\n <div className=\"flex h-6 w-6 items-center justify-center overflow-hidden rounded-full bg-gray-100\">\n {userAvatarUrl ? (\n <img\n src={userAvatarUrl}\n alt=\"\"\n className=\"h-full w-full object-contain\"\n />\n ) : (\n <UserRound className=\"h-5 w-5 text-gray-500\" />\n )}\n </div>\n <div className=\"flex items-center gap-0.5\">\n <span className=\"text-xs\">Account</span>\n <ChevronDown className=\"h-3! w-3! transition-transform group-data-[state=open]:rotate-180\" />\n </div>\n </Button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-max min-w-44\">\n {userPrimary && (\n <div className=\"px-2 py-1.5\">\n <div className=\"text-center text-sm font-medium\">\n {userPrimary}\n </div>\n {userSecondary && (\n <div className=\"text-muted-foreground text-center text-xs\">\n {userSecondary}\n </div>\n )}\n </div>\n )}\n <DropdownMenuSeparator />\n {profileHref && (\n <DropdownMenuItem asChild>\n <Link href={profileHref}>\n <UserRound className=\"h-4 w-4\" />\n Profile\n </Link>\n </DropdownMenuItem>\n )}\n {accountNav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <DropdownMenuItem key={item.href} asChild>\n <Link href={item.href}>\n <Icon className=\"h-4 w-4\" />\n {item.label}\n </Link>\n </DropdownMenuItem>\n );\n })}\n {(profileHref || accountNav.length > 0) && (\n <DropdownMenuSeparator />\n )}\n <DropdownMenuItem\n variant=\"destructive\"\n disabled={logout.isPending}\n onClick={() => logout.mutate()}\n >\n <LogOut className=\"h-4 w-4\" />\n {logout.isPending ? 'Logging out...' : 'Sign Out'}\n </DropdownMenuItem>\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n\n {/* Mobile: search trigger + hamburger */}\n <div className=\"flex items-center gap-1 md:hidden\">\n {onSearchClick && (\n <button\n type=\"button\"\n aria-label=\"Search\"\n className=\"inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50\"\n onClick={onSearchClick}\n >\n <Search className=\"h-5 w-5\" />\n </button>\n )}\n {showMobileMenu && (\n <button\n type=\"button\"\n aria-label={isDrawerOpen ? 'Close menu' : 'Open menu'}\n className=\"inline-flex h-10 w-10 items-center justify-center rounded-md border border-border hover:bg-gray-50\"\n onClick={() => setIsDrawerOpen(!isDrawerOpen)}\n >\n {isDrawerOpen ? (\n <X className=\"h-5 w-5\" />\n ) : (\n <Menu className=\"h-5 w-5\" />\n )}\n </button>\n )}\n </div>\n </div>\n\n {/* Mobile right drawer */}\n {showMobileMenu && isDrawerOpen && (\n <div\n className=\"fixed inset-0 z-[30] duration-200 md:hidden\"\n onClick={() => setIsDrawerOpen(false)}\n />\n )}\n\n {showMobileMenu && (\n <div\n className={cn(\n 'fixed top-0 right-0 z-[31] h-[100svh] w-full max-w-[92%] border-l border-border bg-white shadow-xl sm:max-w-[420px] md:hidden',\n 'transition-transform duration-250 ease-out',\n isDrawerOpen ? 'translate-x-0' : 'translate-x-full',\n )}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Mobile menu\"\n >\n <div className=\"flex h-full flex-col\">\n <div className=\"mt-1 flex items-center justify-between border-b px-4 py-3\">\n <div className=\"flex items-center gap-2\">\n <Image\n src={logoPath}\n alt=\"\"\n width={25}\n height={25}\n className=\"h-6 w-6 rounded object-contain\"\n />\n <span className=\"text-sm font-semibold\">{brand}</span>\n <span className=\"rounded border border-border bg-gray-50 px-1 py-0 text-xs font-medium text-gray-400 leading-none\">\n {siteName}\n </span>\n </div>\n <button\n type=\"button\"\n aria-label=\"Close menu\"\n className=\"inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors hover:bg-gray-100\"\n onClick={() => setIsDrawerOpen(false)}\n >\n <X className=\"h-5 w-5\" />\n </button>\n </div>\n\n <div className=\"flex-1 overflow-y-auto p-4\">\n {userPrimary && (\n <div className=\"flex items-center gap-2 pb-2\">\n <UserRound className=\"h-5 w-5 text-gray-500\" />\n <span className=\"text-sm font-semibold text-gray-900\">\n {userPrimary}\n </span>\n </div>\n )}\n\n <Divider className=\"my-4\" />\n\n {actions && <div className=\"mb-2\">{actions}</div>}\n\n <nav className=\"flex flex-col gap-option-gap\">\n {nav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Link\n key={item.href}\n href={item.href}\n className=\"block w-full\"\n >\n <button className=\"flex min-h-option-row w-full items-center justify-between rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted\">\n <div className=\"flex items-center gap-2\">\n <Icon className=\"h-4 w-4 text-muted-foreground\" />\n <span>{item.label}</span>\n {!!item.badge && (\n <span className=\"inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 text-xs font-bold leading-none text-amber-900\">\n !\n </span>\n )}\n </div>\n <ChevronRight className=\"h-4 w-4 text-muted-foreground/60\" />\n </button>\n </Link>\n );\n })}\n </nav>\n </div>\n\n <div className=\"mt-auto flex flex-col gap-option-gap border-t border-border px-4 py-3\">\n {profileHref && (\n <Link href={profileHref} className=\"block w-full\">\n <button className=\"flex min-h-option-row w-full items-center gap-2 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted\">\n <UserRound className=\"h-4 w-4\" />\n Profile\n </button>\n </Link>\n )}\n {accountNav.map((item) => {\n const Icon = item.icon ?? labelIcon(item.label);\n return (\n <Link\n key={item.href}\n href={item.href}\n className=\"block w-full\"\n >\n <button className=\"flex min-h-option-row w-full items-center gap-2 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted\">\n <Icon className=\"h-4 w-4\" />\n {item.label}\n </button>\n </Link>\n );\n })}\n <button\n onClick={() => logout.mutate()}\n disabled={logout.isPending}\n className=\"flex min-h-option-row w-full items-center justify-center gap-2 rounded-control-sm px-option-x py-2 font-medium text-destructive transition-colors hover:bg-destructive/10\"\n >\n <LogOut className=\"h-4 w-4\" />\n {logout.isPending ? 'Logging out...' : 'Sign Out'}\n </button>\n </div>\n </div>\n </div>\n )}\n </header>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAuFA;AACE;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEF;AACF;AAEM;AAmBJ;AACA;AACA;;;;AAKA;;AAGE;AACA;;AAEA;AACF;;AAGE;;;AAGE;;AAEH;AAED;AAGA;AA4DU;AACA;AAOQ;AACA;AAaV;AAYU;AACA;AACA;AA2CJ;AACA;AAQF;AAyGI;AACA;;AAkCF;AACA;;AA2BhB;;"}
|
|
@@ -282,17 +282,17 @@ function AutocompleteBase({ required, options, value = [], setter, placeholder,
|
|
|
282
282
|
if (e.key === "Escape") {
|
|
283
283
|
setIsOpen(false);
|
|
284
284
|
}
|
|
285
|
-
} })] })), jsxs("ul", { className: cn(useMobileSheet && "min-h-0 flex-1 overflow-y-auto overscroll-contain"), children: [allowCustomValue && (jsx("li", { className: "
|
|
285
|
+
} })] })), jsxs("ul", { className: cn("flex flex-col gap-option-gap p-option-inset", useMobileSheet && "min-h-0 flex-1 overflow-y-auto overscroll-contain"), children: [allowCustomValue && (jsx("li", { className: "pointer-events-none px-option-x pb-1 pt-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground", children: "Suggestions" })), filtered.length ? (filtered.map((option, index) => {
|
|
286
286
|
const active = selectedSet.has(option.id);
|
|
287
287
|
const group = options.find((item) => item.children?.some((child) => child.id === option.id));
|
|
288
288
|
const firstInGroup = group && !filtered.slice(0, index).some((item) => group.children?.some((child) => child.id === item.id));
|
|
289
|
-
return (jsxs(Fragment, { children: [firstInGroup && group && (jsx("li", { children: multiple ? (jsxs("button", { type: "button", "aria-pressed": group.children.every((child) => selectedSet.has(child.id)), className: "flex min-h-
|
|
289
|
+
return (jsxs(Fragment, { children: [firstInGroup && group && (jsx("li", { children: multiple ? (jsxs("button", { type: "button", "aria-pressed": group.children.every((child) => selectedSet.has(child.id)), className: "flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm font-medium text-foreground transition-colors hover:bg-muted max-md:min-h-11", onClick: () => {
|
|
290
290
|
const ids = group.children.map((child) => child.id);
|
|
291
291
|
const next = new Set(value ?? []);
|
|
292
292
|
const allSelected = ids.every((id) => next.has(id));
|
|
293
293
|
ids.forEach((id) => allSelected ? next.delete(id) : next.add(id));
|
|
294
294
|
setter(Array.from(next));
|
|
295
|
-
}, children: [jsx(CheckboxVisual, { checked: group.children.every((child) => selectedSet.has(child.id)) ? true : group.children.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false }), group.name] })) : jsx("div", { className: "px-
|
|
295
|
+
}, children: [jsx(CheckboxVisual, { checked: group.children.every((child) => selectedSet.has(child.id)) ? true : group.children.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false }), group.name] })) : jsx("div", { className: "px-option-x py-2 text-sm font-medium text-foreground", children: group.name }) })), jsx("li", { children: jsxs("button", { type: "button", "aria-pressed": multiple ? active : undefined, onClick: () => {
|
|
296
296
|
toggle(option.id);
|
|
297
297
|
if (multiple) {
|
|
298
298
|
// keep open for rapid multi-pick
|
|
@@ -305,8 +305,8 @@ function AutocompleteBase({ required, options, value = [], setter, placeholder,
|
|
|
305
305
|
setQuery("");
|
|
306
306
|
setIsOpen(false);
|
|
307
307
|
}
|
|
308
|
-
}, className: cn("w-full
|
|
309
|
-
})) : (!allowCustomValue || !query.trim() ? (jsx("li", { className: "
|
|
308
|
+
}, className: cn("flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-muted", useMobileSheet && "min-h-12", group && "pl-8", active && "bg-primary-tint"), children: [multiple ? (jsx(CheckboxVisual, { checked: active })) : null, option.name] }) })] }, String(option.id)));
|
|
309
|
+
})) : (!allowCustomValue || !query.trim() ? (jsx("li", { className: "px-option-x py-2 text-sm text-muted-foreground", children: emptyText })) : null), allowCustomValue && query.trim() && !findExactOption(query) && (jsx("li", { children: jsxs("button", { type: "button", className: "flex min-h-11 w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-sm text-primary transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-primary", onMouseDown: (event) => event.preventDefault(), onClick: () => {
|
|
310
310
|
const text = query.trim();
|
|
311
311
|
if (multiple) {
|
|
312
312
|
setter(Array.from(new Set([...(value ?? []), text])));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","sources":["../../src/components/autocomplete.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { Input } from \"./input\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\nimport { cn } from \"@/utils\";\nimport { ChevronDown, PlusCircleIcon, Search, X } from \"lucide-react\";\nimport { Label } from \"./label\";\nimport { Button } from \"./button\";\nimport { CheckboxVisual } from \"./checkbox\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport {\n FieldChromeContext,\n fieldFocusOutlineClassName,\n fieldInteractionClassName,\n useFieldFocus,\n} from \"@/hooks/use-field-focus\";\n\nexport interface IAutocompleteOption<ID extends number | string> {\n id: ID;\n name: string;\n keywords?: string[];\n /** Child options; in multiple mode the group can select all its children. */\n children?: IAutocompleteOption<ID>[];\n}\n\ntype MobileDropdownMode = \"sheet\" | \"inline\";\ntype InputIcons = boolean | \"search\" | \"dropdown\";\n\n/* -------------------------------------------------------\n * Base component (array-based). Single uses length 0..1.\n * -----------------------------------------------------*/\nfunction AutocompleteBase<ID extends number | string>({\n required,\n options,\n value = [],\n setter,\n placeholder,\n className,\n multiple = true,\n label,\n labelAddon,\n allowCustomValue = false,\n preserveOptionOrder = false,\n emptyText = \"No matching options\",\n mobileDropdownMode = \"sheet\",\n inputIcons = false,\n ...props\n}: {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n value?: ID[]; // single => 0..1 items, multi => any length\n setter: (next: ID[]) => void; // set the whole selection\n placeholder?: string;\n className?: string;\n multiple?: boolean;\n label?: React.ReactNode;\n labelAddon?: React.ReactNode;\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n}) {\n const [query, setQuery] = useState(\"\");\n const [isOpen, setIsOpen] = useState(false);\n const [dropdownMaxHeight, setDropdownMaxHeight] = useState<number>();\n const isMobile = useMobile();\n const clickOutsideRef = useDetectClickOutside({\n onTriggered: () => {\n // Radix owns outside dismissal for the portalled modal sheet.\n if (isMobile && mobileDropdownMode === 'sheet') return;\n setIsOpen(false);\n },\n });\n const rootRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const sheetInputRef = useRef<HTMLInputElement | null>(null);\n const sheetRef = useRef<HTMLDivElement | null>(null);\n const sheetCloseRef = useRef<HTMLButtonElement | null>(null);\n const lastSelectionRef = useRef(0);\n // Show the Button focus outline only for keyboard focus, not clicks.\n const { keyboardFocus, focusProps: fieldFocusProps } = useFieldFocus();\n\n const inputId = useId();\n const flatOptions = useMemo(\n () => options.flatMap((option) => option.children?.length ? option.children : [option]),\n [options],\n );\n\n const findExactOption = (value: string) => {\n const normalizedValue = value.trim().toLowerCase();\n return flatOptions.find(\n (o) =>\n o.name?.trim().toLowerCase() === normalizedValue ||\n o.keywords?.some((k) => k === normalizedValue),\n );\n };\n\n const resolveQuerySelection = (nextQuery: string, matchKeywords = true) => {\n const text = nextQuery.trim();\n if (!text) return false;\n\n const exact = matchKeywords\n ? findExactOption(text)\n : flatOptions.find(\n (o) => o.name?.trim().toLowerCase() === text.toLowerCase(),\n );\n if (exact) {\n setter([exact.id]);\n setQuery(\"\");\n return true;\n }\n\n if (allowCustomValue) {\n setter([text as unknown as ID]);\n setQuery(\"\");\n return true;\n }\n\n return false;\n };\n\n const selectedSet = useMemo(() => new Set(value ?? []), [value]);\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n const base = q\n ? flatOptions.filter(\n (o) =>\n o.name?.toLowerCase().includes(q) ||\n options.some((group) => group.children?.some((child) => child.id === o.id) && group.name.toLowerCase().includes(q)) ||\n o.keywords?.some((k) => k.includes(q)),\n )\n : flatOptions;\n return preserveOptionOrder || options.some((option) => option.children?.length)\n ? base\n : base.slice().sort((a, b) => a.name.localeCompare(b.name));\n }, [query, flatOptions, options, preserveOptionOrder]);\n\n const toggle = (id: ID) => {\n lastSelectionRef.current = Date.now();\n if (!multiple) {\n setter([id]); // single-select\n setIsOpen(false);\n setQuery(\"\");\n return;\n }\n const set = new Set(value ?? []);\n if (set.has(id)) set.delete(id);\n else set.add(id);\n setter(Array.from(set));\n };\n\n const removeAt = (id: ID) => {\n const set = new Set(value ?? []);\n set.delete(id);\n setter(Array.from(set));\n };\n\n const selectedLabels = useMemo(\n () =>\n (value ?? [])\n .map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name;\n return label ?? (allowCustomValue ? String(id) : undefined);\n })\n .filter(Boolean) as string[],\n [value, flatOptions, allowCustomValue],\n );\n\n const singleDisplay = !multiple && (selectedLabels[0] ?? \"\");\n const useMobileSheet = isMobile && mobileDropdownMode === \"sheet\";\n const sheetViewport = useMobileSheetViewport(isOpen && useMobileSheet);\n const useInlineMobileDropdown = isMobile && mobileDropdownMode === \"inline\";\n\n\n useEffect(() => {\n if (!isOpen || !useInlineMobileDropdown) {\n setDropdownMaxHeight(undefined);\n return;\n }\n\n const updateDropdownMaxHeight = () => {\n const rootRect = rootRef.current?.getBoundingClientRect();\n if (!rootRect) return;\n\n const viewportHeight =\n window.visualViewport?.height ?? window.innerHeight;\n const gap = 8;\n const availableHeight = viewportHeight - rootRect.bottom - gap;\n setDropdownMaxHeight(Math.max(0, Math.min(400, availableHeight)));\n };\n\n updateDropdownMaxHeight();\n window.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"scroll\", updateDropdownMaxHeight);\n\n return () => {\n window.removeEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.removeEventListener(\n \"resize\",\n updateDropdownMaxHeight,\n );\n window.visualViewport?.removeEventListener(\n \"scroll\",\n updateDropdownMaxHeight,\n );\n };\n }, [isOpen, useInlineMobileDropdown]);\n\n const suppressMobileKeyboard =\n isMobile && (useMobileSheet || (mobileDropdownMode === \"inline\" && !allowCustomValue));\n\n // --- keyboard helpers for multi\n const onMultiKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!multiple) return;\n if (allowCustomValue && e.key === \"Enter\" && query.trim().length > 0 && !findExactOption(query)) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n const set = new Set(value ?? []);\n set.add(nextId);\n setter(Array.from(set));\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n return;\n }\n if (\n e.key === \"Backspace\" &&\n query.length === 0 &&\n (value?.length ?? 0) > 0\n ) {\n const last = value[value.length - 1];\n removeAt(last);\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n const first = filtered[0];\n if (first) {\n toggle(first.id);\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n }\n }\n if (e.key === \"ArrowDown\") setIsOpen(true);\n if (e.key === \"Escape\") setIsOpen(false);\n };\n\n // Same hover lift and press feedback as the Dropdown trigger.\n const fieldClassName = cn(\n fieldInteractionClassName,\n keyboardFocus && fieldFocusOutlineClassName,\n );\n\n const decorateSingleInput = (input: React.ReactNode) =>\n inputIcons ? (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n {inputIcons !== \"search\" && inputIcons !== \"dropdown\" && (\n <Search\n className=\"pointer-events-none absolute left-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n )}\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n {inputIcons === \"search\" ? (\n <Search\n className=\"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n ) : (\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n )}\n </div>\n ) : (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n </div>\n );\n\n const OptionsSurface = useMobileSheet ? SheetContent : 'div';\n const sheetProps = useMobileSheet ? {\n side: 'bottom' as const,\n showCloseButton: false,\n overlayClassName: 'z-[1090] bg-black/25 backdrop-blur-[1px]',\n 'aria-describedby': undefined,\n onOpenAutoFocus: (event: Event) => { event.preventDefault(); sheetCloseRef.current?.focus(); },\n onCloseAutoFocus: (event: Event) => { event.preventDefault(); inputRef.current?.focus(); },\n } : {};\n return (\n <div\n className={cn(\"relative w-full overflow-visible\", className)}\n ref={(node) => {\n rootRef.current = node;\n (\n clickOutsideRef as React.MutableRefObject<HTMLDivElement | null>\n ).current = node;\n }}\n >\n {label ? (\n <Label\n label={label}\n required={required}\n labelAddon={labelAddon}\n />\n ) : null}\n\n {multiple ? (\n // ---------- MULTI: chips inline inside the box ----------\n <div\n className={cn(\n \"relative flex min-h-form-control w-full flex-wrap items-center gap-1 rounded-control-lg border border-input bg-background px-[0.75em] pr-10 hover:border-input-hover\",\n fieldClassName,\n )}\n {...fieldFocusProps}\n onClick={() => {\n setIsOpen(true);\n if (!suppressMobileKeyboard) {\n inputRef.current?.focus();\n }\n }}\n >\n {(value ?? []).map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name ?? String(id);\n return (\n <span\n key={String(id)}\n className=\"my-0.5 flex items-center gap-1 rounded-control-sm border border-input bg-muted px-2 text-xs\"\n >\n {label}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n className=\"ml-1 h-5 min-h-0 w-5 p-0 hover:bg-muted\"\n onClick={(event) => { event.stopPropagation(); removeAt(id); }}\n aria-label={`Remove ${label}`}\n >\n <X className=\"h-3.5 w-3.5\" />\n </Button>\n </span>\n );\n })}\n <input\n id={inputId}\n ref={inputRef}\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // Delay slightly to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (allowCustomValue && query.trim().length > 0) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n setter(Array.from(new Set([...(value ?? []), nextId])));\n setQuery(\"\");\n }\n }, 150);\n }}\n onKeyDown={onMultiKeyDown}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n readOnly={suppressMobileKeyboard}\n placeholder={(value?.length ?? 0) === 0 ? placeholder : \"\"}\n className={cn(\n \"h-[calc(var(--spacing-form-control)-2px)] min-w-[8ch] flex-1 border-none bg-transparent p-0 text-base outline-none focus:ring-0\",\n \"placeholder:text-muted-foreground/40\",\n )}\n {...props}\n />\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n </div>\n ) : (\n // ---------- SINGLE: regular input ----------\n decorateSingleInput(\n <Input\n id={inputId}\n value={singleDisplay || query}\n className={cn(\n \"border-input\",\n inputIcons === \"search\" || inputIcons === \"dropdown\" ? \"pr-10\" : inputIcons && \"px-10\",\n )}\n placeholder={placeholder}\n readOnly={suppressMobileKeyboard}\n onChange={(e) => {\n const nextQuery = e.target.value;\n\n if ((value?.length ?? 0) > 0) {\n setter([]);\n }\n\n const exact = findExactOption(nextQuery);\n // Only auto-fill on an exact NAME match; keyword/acronym matches\n // (e.g. \"dlsu\") require an explicit Enter, blur, or click.\n if (\n exact &&\n exact.name.trim().toLowerCase() ===\n nextQuery.trim().toLowerCase()\n ) {\n setter([exact.id]);\n setQuery(\"\");\n } else {\n setQuery(nextQuery);\n }\n\n setIsOpen(true);\n }}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n onClick={(e) => {\n setIsOpen(true);\n if (suppressMobileKeyboard) {\n e.currentTarget.blur();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && resolveQuerySelection(query, true)) {\n setIsOpen(false);\n e.preventDefault();\n }\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // slight delay to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (!resolveQuerySelection(query, false)) setQuery(\"\");\n }, 150);\n }}\n />,\n )\n )}\n\n {isOpen && (\n <Sheet open={useMobileSheet && isOpen} onOpenChange={next => { if (!next) { setQuery(''); setIsOpen(false); } }}>\n <OptionsSurface\n {...sheetProps}\n ref={useMobileSheet ? sheetRef : undefined}\n role={useMobileSheet ? \"dialog\" : undefined}\n aria-modal={useMobileSheet ? true : undefined}\n aria-label={useMobileSheet ? (typeof label === \"string\" ? label : \"Choose options\") : undefined}\n className={cn(\n \"bg-background text-sm shadow-card border border-border\",\n useMobileSheet\n ? \"fixed left-0 right-0 z-[1100] flex flex-col gap-0 overflow-hidden rounded-t-control-lg border-b-0 p-0\"\n : \"absolute left-0 right-0 z-50 mt-1 max-h-[400px] overflow-y-auto overscroll-contain rounded-control-lg\",\n )}\n style={\n useMobileSheet\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport ? Math.min(sheetViewport.height, 640) : \"80dvh\",\n }\n : undefined\n }\n >\n {useMobileSheet && (\n <div className=\"shrink-0 px-4 pb-3 pt-4\">\n <div className=\"mb-3 flex items-center justify-between gap-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">{label || \"Choose options\"}</SheetTitle>\n <button ref={sheetCloseRef} type=\"button\" aria-label=\"Close options\" className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\" onClick={() => { setQuery(\"\"); setIsOpen(false); }}>\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <Input\n ref={sheetInputRef}\n aria-label={typeof label === \"string\" ? `Search ${label}` : \"Search options\"}\n value={query}\n placeholder={placeholder ?? \"Search\"}\n className=\"h-10 min-h-10 max-h-none text-base\"\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n if ((value?.length ?? 0) > 0 && !multiple) {\n setter([]);\n }\n }}\n onKeyDown={(e) => {\n if (multiple) {\n onMultiKeyDown(e);\n return;\n }\n\n if (e.key === \"Enter\" && resolveQuerySelection(query)) {\n setIsOpen(false);\n e.preventDefault();\n }\n\n if (e.key === \"Escape\") {\n setIsOpen(false);\n }\n }}\n />\n </div>\n )}\n <ul className={cn(useMobileSheet && \"min-h-0 flex-1 overflow-y-auto overscroll-contain\")}>\n {allowCustomValue && (\n <li className=\"w-full text-left px-4 py-2 text-sm text-muted-foreground bg-muted pointer-events-none\">\n Suggestions\n </li>\n )}\n {filtered.length ? (\n filtered.map((option, index) => {\n const active = selectedSet.has(option.id);\n const group = options.find((item) => item.children?.some((child) => child.id === option.id));\n const firstInGroup = group && !filtered.slice(0, index).some((item) => group.children?.some((child) => child.id === item.id));\n return (\n <Fragment key={String(option.id)}>\n {firstInGroup && group && (\n <li>\n {multiple ? (\n <button type=\"button\" aria-pressed={group.children!.every((child) => selectedSet.has(child.id))} className=\"flex min-h-11 w-full items-center gap-2 px-4 py-2 text-left text-sm font-medium text-foreground hover:bg-muted\" onClick={() => {\n const ids = group.children!.map((child) => child.id);\n const next = new Set(value ?? []);\n const allSelected = ids.every((id) => next.has(id));\n ids.forEach((id) => allSelected ? next.delete(id) : next.add(id));\n setter(Array.from(next));\n }}>\n <CheckboxVisual checked={group.children!.every((child) => selectedSet.has(child.id)) ? true : group.children!.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false} />\n {group.name}\n </button>\n ) : <div className=\"px-4 py-2 text-sm font-medium text-foreground\">{group.name}</div>}\n </li>\n )}\n <li>\n <button\n type=\"button\"\n aria-pressed={multiple ? active : undefined}\n onClick={() => {\n toggle(option.id);\n if (multiple) {\n // keep open for rapid multi-pick\n setQuery(\"\");\n if (!useMobileSheet) {\n inputRef.current?.focus();\n }\n } else {\n setQuery(\"\");\n setIsOpen(false);\n }\n }}\n className={cn(\n \"w-full text-left px-4 py-2 text-sm text-muted-foreground transition-colors flex items-center gap-2 cursor-pointer hover:bg-muted\",\n useMobileSheet && \"min-h-12\",\n group && \"pl-8\",\n active && \"bg-primary-tint\",\n )}\n >\n {multiple ? (\n <CheckboxVisual checked={active} />\n ) : null}\n {option.name}\n </button>\n </li>\n </Fragment>\n );\n })\n ) : (\n !allowCustomValue || !query.trim() ? (\n <li className=\"w-full text-left px-4 py-2 text-sm text-muted-foreground\">\n {emptyText}\n </li>\n ) : null\n )}\n {allowCustomValue && query.trim() && !findExactOption(query) && (\n <li>\n <button\n type=\"button\"\n className=\"flex min-h-11 w-full items-center gap-2 px-4 py-2 text-left text-sm text-primary hover:bg-muted focus-visible:outline-2 focus-visible:outline-primary\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n const text = query.trim();\n if (multiple) {\n setter(Array.from(new Set([...(value ?? []), text as unknown as ID])));\n setQuery(\"\");\n } else {\n resolveQuerySelection(text);\n setIsOpen(false);\n }\n }}\n >\n <PlusCircleIcon className=\"h-4 w-4\" aria-hidden=\"true\" />\n Add “{query.trim()}”\n </button>\n </li>\n )}\n </ul>\n {useMobileSheet && multiple && (\n <div className=\"shrink-0 border-t border-border bg-background px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]\">\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"min-h-11 w-full\"\n onClick={() => {\n setQuery(\"\");\n setIsOpen(false);\n }}\n >\n Done\n </Button>\n </div>\n )}\n </OptionsSurface>\n </Sheet>\n )}\n </div>\n );\n}\n\ntype AutocompleteCommonProps<ID extends number | string> = {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n placeholder?: string;\n className?: string;\n label?: React.ReactNode;\n props?: any[];\n /** Allow a user to add their own text. Custom values are strings. */\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n};\n\nexport type AutocompleteProps<ID extends number | string> = AutocompleteCommonProps<ID> & (\n | { multiple?: false; value?: ID | null; setter: (value?: ID | null) => void }\n | { multiple: true; value?: ID[]; setter: (value: ID[]) => void }\n);\n\nexport const Autocomplete = <ID extends number | string>(config: AutocompleteProps<ID>) => {\n const { required, options, placeholder, className, label, props, allowCustomValue = false,\n preserveOptionOrder = false, emptyText, mobileDropdownMode, inputIcons } = config;\n return (\n <AutocompleteBase<ID>\n required={required}\n options={options}\n multiple={config.multiple === true}\n value={config.multiple === true ? config.value ?? [] : config.value != null ? [config.value] : []}\n setter={(arr) => {\n if (config.multiple === true) config.setter(arr);\n else config.setter(arr[0] ?? null);\n }}\n placeholder={placeholder}\n className={className}\n label={label}\n allowCustomValue={allowCustomValue}\n preserveOptionOrder={preserveOptionOrder}\n emptyText={emptyText}\n mobileDropdownMode={mobileDropdownMode}\n inputIcons={inputIcons}\n {...props}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+BA;;AAE0D;AAC1D;;;;AAmCE;;;;AAII;;;;AAGH;AACD;AACA;AACA;AACA;AACA;AACA;;;AAIA;AACA;AAKA;;AAEE;AAGI;AAEN;;AAGE;AACA;AAAW;;AAGT;;;AAKA;;AAEA;;;AAIA;;AAEA;;AAGF;AACF;AAEA;AAEA;;;;AAMY;AACA;;AAGV;AACE;;;AAIJ;AACE;;AAEE;;;;;;AAMF;AAAiB;;AACZ;;AAEP;AAEA;;AAEE;;AAEF;;AAKO;AACC;AACA;AACF;AACC;AAIP;AACA;;AAEA;;AAIE;;;;;;AAOE;;;;;AAMA;AACF;AAEA;AACA;;;AAIA;AACE;;;AASF;AACF;AAEA;;AAIA;AACE;;;AAEE;AACA;AACA;;AAEA;;;;;;;AAOF;;;;;;;AASA;AACE;;AAEE;;;;;;AAMJ;;AACA;;AACF;;;;;AAwCA;AACE;AACA;AACA;AACA;;;;AAIF;AAIM;AAEE;AAEJ;;AAYE;;;AASM;;AAEJ;;AAIE;;AAwBE;;AAEF;AAEE;;;;;;;;AAOI;AACA;AACA;;;;;AAKN;AAEsC;;;AA8BpC;;;;AAMA;;;AAGA;AAEE;AACE;AAEF;;;;;;;;AAQkC;;;AAIlC;;AAEJ;AAEE;;;;AAIF;AAEE;;;;;;;AAME;;;;;;AAQoG;AAUnG;AACA;AAID;AACI;AACA;AACD;;AAmBC;;AAEA;;;AAGF;;;;;;;;;AAYE;;;AAGF;;AAaF;AACA;;AAOU;;AAEA;AACA;;;AAcJ;;;;;AAKI;;;;;;;;AAsBZ;AAeM;;;;;;;;;;;;;AAoCpB;AAsBO;AACL;AAEA;AAOM;AAA8B;;;AAEhC;AAYN;;"}
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sources":["../../src/components/autocomplete.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { Input } from \"./input\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\nimport { cn } from \"@/utils\";\nimport { ChevronDown, PlusCircleIcon, Search, X } from \"lucide-react\";\nimport { Label } from \"./label\";\nimport { Button } from \"./button\";\nimport { CheckboxVisual } from \"./checkbox\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport {\n FieldChromeContext,\n fieldFocusOutlineClassName,\n fieldInteractionClassName,\n useFieldFocus,\n} from \"@/hooks/use-field-focus\";\n\nexport interface IAutocompleteOption<ID extends number | string> {\n id: ID;\n name: string;\n keywords?: string[];\n /** Child options; in multiple mode the group can select all its children. */\n children?: IAutocompleteOption<ID>[];\n}\n\ntype MobileDropdownMode = \"sheet\" | \"inline\";\ntype InputIcons = boolean | \"search\" | \"dropdown\";\n\n/* -------------------------------------------------------\n * Base component (array-based). Single uses length 0..1.\n * -----------------------------------------------------*/\nfunction AutocompleteBase<ID extends number | string>({\n required,\n options,\n value = [],\n setter,\n placeholder,\n className,\n multiple = true,\n label,\n labelAddon,\n allowCustomValue = false,\n preserveOptionOrder = false,\n emptyText = \"No matching options\",\n mobileDropdownMode = \"sheet\",\n inputIcons = false,\n ...props\n}: {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n value?: ID[]; // single => 0..1 items, multi => any length\n setter: (next: ID[]) => void; // set the whole selection\n placeholder?: string;\n className?: string;\n multiple?: boolean;\n label?: React.ReactNode;\n labelAddon?: React.ReactNode;\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n}) {\n const [query, setQuery] = useState(\"\");\n const [isOpen, setIsOpen] = useState(false);\n const [dropdownMaxHeight, setDropdownMaxHeight] = useState<number>();\n const isMobile = useMobile();\n const clickOutsideRef = useDetectClickOutside({\n onTriggered: () => {\n // Radix owns outside dismissal for the portalled modal sheet.\n if (isMobile && mobileDropdownMode === 'sheet') return;\n setIsOpen(false);\n },\n });\n const rootRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const sheetInputRef = useRef<HTMLInputElement | null>(null);\n const sheetRef = useRef<HTMLDivElement | null>(null);\n const sheetCloseRef = useRef<HTMLButtonElement | null>(null);\n const lastSelectionRef = useRef(0);\n // Show the Button focus outline only for keyboard focus, not clicks.\n const { keyboardFocus, focusProps: fieldFocusProps } = useFieldFocus();\n\n const inputId = useId();\n const flatOptions = useMemo(\n () => options.flatMap((option) => option.children?.length ? option.children : [option]),\n [options],\n );\n\n const findExactOption = (value: string) => {\n const normalizedValue = value.trim().toLowerCase();\n return flatOptions.find(\n (o) =>\n o.name?.trim().toLowerCase() === normalizedValue ||\n o.keywords?.some((k) => k === normalizedValue),\n );\n };\n\n const resolveQuerySelection = (nextQuery: string, matchKeywords = true) => {\n const text = nextQuery.trim();\n if (!text) return false;\n\n const exact = matchKeywords\n ? findExactOption(text)\n : flatOptions.find(\n (o) => o.name?.trim().toLowerCase() === text.toLowerCase(),\n );\n if (exact) {\n setter([exact.id]);\n setQuery(\"\");\n return true;\n }\n\n if (allowCustomValue) {\n setter([text as unknown as ID]);\n setQuery(\"\");\n return true;\n }\n\n return false;\n };\n\n const selectedSet = useMemo(() => new Set(value ?? []), [value]);\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n const base = q\n ? flatOptions.filter(\n (o) =>\n o.name?.toLowerCase().includes(q) ||\n options.some((group) => group.children?.some((child) => child.id === o.id) && group.name.toLowerCase().includes(q)) ||\n o.keywords?.some((k) => k.includes(q)),\n )\n : flatOptions;\n return preserveOptionOrder || options.some((option) => option.children?.length)\n ? base\n : base.slice().sort((a, b) => a.name.localeCompare(b.name));\n }, [query, flatOptions, options, preserveOptionOrder]);\n\n const toggle = (id: ID) => {\n lastSelectionRef.current = Date.now();\n if (!multiple) {\n setter([id]); // single-select\n setIsOpen(false);\n setQuery(\"\");\n return;\n }\n const set = new Set(value ?? []);\n if (set.has(id)) set.delete(id);\n else set.add(id);\n setter(Array.from(set));\n };\n\n const removeAt = (id: ID) => {\n const set = new Set(value ?? []);\n set.delete(id);\n setter(Array.from(set));\n };\n\n const selectedLabels = useMemo(\n () =>\n (value ?? [])\n .map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name;\n return label ?? (allowCustomValue ? String(id) : undefined);\n })\n .filter(Boolean) as string[],\n [value, flatOptions, allowCustomValue],\n );\n\n const singleDisplay = !multiple && (selectedLabels[0] ?? \"\");\n const useMobileSheet = isMobile && mobileDropdownMode === \"sheet\";\n const sheetViewport = useMobileSheetViewport(isOpen && useMobileSheet);\n const useInlineMobileDropdown = isMobile && mobileDropdownMode === \"inline\";\n\n\n useEffect(() => {\n if (!isOpen || !useInlineMobileDropdown) {\n setDropdownMaxHeight(undefined);\n return;\n }\n\n const updateDropdownMaxHeight = () => {\n const rootRect = rootRef.current?.getBoundingClientRect();\n if (!rootRect) return;\n\n const viewportHeight =\n window.visualViewport?.height ?? window.innerHeight;\n const gap = 8;\n const availableHeight = viewportHeight - rootRect.bottom - gap;\n setDropdownMaxHeight(Math.max(0, Math.min(400, availableHeight)));\n };\n\n updateDropdownMaxHeight();\n window.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"scroll\", updateDropdownMaxHeight);\n\n return () => {\n window.removeEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.removeEventListener(\n \"resize\",\n updateDropdownMaxHeight,\n );\n window.visualViewport?.removeEventListener(\n \"scroll\",\n updateDropdownMaxHeight,\n );\n };\n }, [isOpen, useInlineMobileDropdown]);\n\n const suppressMobileKeyboard =\n isMobile && (useMobileSheet || (mobileDropdownMode === \"inline\" && !allowCustomValue));\n\n // --- keyboard helpers for multi\n const onMultiKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!multiple) return;\n if (allowCustomValue && e.key === \"Enter\" && query.trim().length > 0 && !findExactOption(query)) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n const set = new Set(value ?? []);\n set.add(nextId);\n setter(Array.from(set));\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n return;\n }\n if (\n e.key === \"Backspace\" &&\n query.length === 0 &&\n (value?.length ?? 0) > 0\n ) {\n const last = value[value.length - 1];\n removeAt(last);\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n const first = filtered[0];\n if (first) {\n toggle(first.id);\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n }\n }\n if (e.key === \"ArrowDown\") setIsOpen(true);\n if (e.key === \"Escape\") setIsOpen(false);\n };\n\n // Same hover lift and press feedback as the Dropdown trigger.\n const fieldClassName = cn(\n fieldInteractionClassName,\n keyboardFocus && fieldFocusOutlineClassName,\n );\n\n const decorateSingleInput = (input: React.ReactNode) =>\n inputIcons ? (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n {inputIcons !== \"search\" && inputIcons !== \"dropdown\" && (\n <Search\n className=\"pointer-events-none absolute left-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n )}\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n {inputIcons === \"search\" ? (\n <Search\n className=\"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n ) : (\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n )}\n </div>\n ) : (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n </div>\n );\n\n const OptionsSurface = useMobileSheet ? SheetContent : 'div';\n const sheetProps = useMobileSheet ? {\n side: 'bottom' as const,\n showCloseButton: false,\n overlayClassName: 'z-[1090] bg-black/25 backdrop-blur-[1px]',\n 'aria-describedby': undefined,\n onOpenAutoFocus: (event: Event) => { event.preventDefault(); sheetCloseRef.current?.focus(); },\n onCloseAutoFocus: (event: Event) => { event.preventDefault(); inputRef.current?.focus(); },\n } : {};\n return (\n <div\n className={cn(\"relative w-full overflow-visible\", className)}\n ref={(node) => {\n rootRef.current = node;\n (\n clickOutsideRef as React.MutableRefObject<HTMLDivElement | null>\n ).current = node;\n }}\n >\n {label ? (\n <Label\n label={label}\n required={required}\n labelAddon={labelAddon}\n />\n ) : null}\n\n {multiple ? (\n // ---------- MULTI: chips inline inside the box ----------\n <div\n className={cn(\n \"relative flex min-h-form-control w-full flex-wrap items-center gap-1 rounded-control-lg border border-input bg-background px-[0.75em] pr-10 hover:border-input-hover\",\n fieldClassName,\n )}\n {...fieldFocusProps}\n onClick={() => {\n setIsOpen(true);\n if (!suppressMobileKeyboard) {\n inputRef.current?.focus();\n }\n }}\n >\n {(value ?? []).map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name ?? String(id);\n return (\n <span\n key={String(id)}\n className=\"my-0.5 flex items-center gap-1 rounded-control-sm border border-input bg-muted px-2 text-xs\"\n >\n {label}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n className=\"ml-1 h-5 min-h-0 w-5 p-0 hover:bg-muted\"\n onClick={(event) => { event.stopPropagation(); removeAt(id); }}\n aria-label={`Remove ${label}`}\n >\n <X className=\"h-3.5 w-3.5\" />\n </Button>\n </span>\n );\n })}\n <input\n id={inputId}\n ref={inputRef}\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // Delay slightly to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (allowCustomValue && query.trim().length > 0) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n setter(Array.from(new Set([...(value ?? []), nextId])));\n setQuery(\"\");\n }\n }, 150);\n }}\n onKeyDown={onMultiKeyDown}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n readOnly={suppressMobileKeyboard}\n placeholder={(value?.length ?? 0) === 0 ? placeholder : \"\"}\n className={cn(\n \"h-[calc(var(--spacing-form-control)-2px)] min-w-[8ch] flex-1 border-none bg-transparent p-0 text-base outline-none focus:ring-0\",\n \"placeholder:text-muted-foreground/40\",\n )}\n {...props}\n />\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n </div>\n ) : (\n // ---------- SINGLE: regular input ----------\n decorateSingleInput(\n <Input\n id={inputId}\n value={singleDisplay || query}\n className={cn(\n \"border-input\",\n inputIcons === \"search\" || inputIcons === \"dropdown\" ? \"pr-10\" : inputIcons && \"px-10\",\n )}\n placeholder={placeholder}\n readOnly={suppressMobileKeyboard}\n onChange={(e) => {\n const nextQuery = e.target.value;\n\n if ((value?.length ?? 0) > 0) {\n setter([]);\n }\n\n const exact = findExactOption(nextQuery);\n // Only auto-fill on an exact NAME match; keyword/acronym matches\n // (e.g. \"dlsu\") require an explicit Enter, blur, or click.\n if (\n exact &&\n exact.name.trim().toLowerCase() ===\n nextQuery.trim().toLowerCase()\n ) {\n setter([exact.id]);\n setQuery(\"\");\n } else {\n setQuery(nextQuery);\n }\n\n setIsOpen(true);\n }}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n onClick={(e) => {\n setIsOpen(true);\n if (suppressMobileKeyboard) {\n e.currentTarget.blur();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && resolveQuerySelection(query, true)) {\n setIsOpen(false);\n e.preventDefault();\n }\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // slight delay to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (!resolveQuerySelection(query, false)) setQuery(\"\");\n }, 150);\n }}\n />,\n )\n )}\n\n {isOpen && (\n <Sheet open={useMobileSheet && isOpen} onOpenChange={next => { if (!next) { setQuery(''); setIsOpen(false); } }}>\n <OptionsSurface\n {...sheetProps}\n ref={useMobileSheet ? sheetRef : undefined}\n role={useMobileSheet ? \"dialog\" : undefined}\n aria-modal={useMobileSheet ? true : undefined}\n aria-label={useMobileSheet ? (typeof label === \"string\" ? label : \"Choose options\") : undefined}\n className={cn(\n \"bg-background text-sm shadow-card border border-border\",\n useMobileSheet\n ? \"fixed left-0 right-0 z-[1100] flex flex-col gap-0 overflow-hidden rounded-t-control-lg border-b-0 p-0\"\n : \"absolute left-0 right-0 z-50 mt-1 max-h-[400px] overflow-y-auto overscroll-contain rounded-control-lg\",\n )}\n style={\n useMobileSheet\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport ? Math.min(sheetViewport.height, 640) : \"80dvh\",\n }\n : undefined\n }\n >\n {useMobileSheet && (\n <div className=\"shrink-0 px-4 pb-3 pt-4\">\n <div className=\"mb-3 flex items-center justify-between gap-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">{label || \"Choose options\"}</SheetTitle>\n <button ref={sheetCloseRef} type=\"button\" aria-label=\"Close options\" className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\" onClick={() => { setQuery(\"\"); setIsOpen(false); }}>\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <Input\n ref={sheetInputRef}\n aria-label={typeof label === \"string\" ? `Search ${label}` : \"Search options\"}\n value={query}\n placeholder={placeholder ?? \"Search\"}\n className=\"h-10 min-h-10 max-h-none text-base\"\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n if ((value?.length ?? 0) > 0 && !multiple) {\n setter([]);\n }\n }}\n onKeyDown={(e) => {\n if (multiple) {\n onMultiKeyDown(e);\n return;\n }\n\n if (e.key === \"Enter\" && resolveQuerySelection(query)) {\n setIsOpen(false);\n e.preventDefault();\n }\n\n if (e.key === \"Escape\") {\n setIsOpen(false);\n }\n }}\n />\n </div>\n )}\n <ul className={cn(\"flex flex-col gap-option-gap p-option-inset\", useMobileSheet && \"min-h-0 flex-1 overflow-y-auto overscroll-contain\")}>\n {allowCustomValue && (\n <li className=\"pointer-events-none px-option-x pb-1 pt-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground\">\n Suggestions\n </li>\n )}\n {filtered.length ? (\n filtered.map((option, index) => {\n const active = selectedSet.has(option.id);\n const group = options.find((item) => item.children?.some((child) => child.id === option.id));\n const firstInGroup = group && !filtered.slice(0, index).some((item) => group.children?.some((child) => child.id === item.id));\n return (\n <Fragment key={String(option.id)}>\n {firstInGroup && group && (\n <li>\n {multiple ? (\n <button type=\"button\" aria-pressed={group.children!.every((child) => selectedSet.has(child.id))} className=\"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm font-medium text-foreground transition-colors hover:bg-muted max-md:min-h-11\" onClick={() => {\n const ids = group.children!.map((child) => child.id);\n const next = new Set(value ?? []);\n const allSelected = ids.every((id) => next.has(id));\n ids.forEach((id) => allSelected ? next.delete(id) : next.add(id));\n setter(Array.from(next));\n }}>\n <CheckboxVisual checked={group.children!.every((child) => selectedSet.has(child.id)) ? true : group.children!.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false} />\n {group.name}\n </button>\n ) : <div className=\"px-option-x py-2 text-sm font-medium text-foreground\">{group.name}</div>}\n </li>\n )}\n <li>\n <button\n type=\"button\"\n aria-pressed={multiple ? active : undefined}\n onClick={() => {\n toggle(option.id);\n if (multiple) {\n // keep open for rapid multi-pick\n setQuery(\"\");\n if (!useMobileSheet) {\n inputRef.current?.focus();\n }\n } else {\n setQuery(\"\");\n setIsOpen(false);\n }\n }}\n className={cn(\n \"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-muted\",\n useMobileSheet && \"min-h-12\",\n group && \"pl-8\",\n active && \"bg-primary-tint\",\n )}\n >\n {multiple ? (\n <CheckboxVisual checked={active} />\n ) : null}\n {option.name}\n </button>\n </li>\n </Fragment>\n );\n })\n ) : (\n !allowCustomValue || !query.trim() ? (\n <li className=\"px-option-x py-2 text-sm text-muted-foreground\">\n {emptyText}\n </li>\n ) : null\n )}\n {allowCustomValue && query.trim() && !findExactOption(query) && (\n <li>\n <button\n type=\"button\"\n className=\"flex min-h-11 w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-sm text-primary transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-primary\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n const text = query.trim();\n if (multiple) {\n setter(Array.from(new Set([...(value ?? []), text as unknown as ID])));\n setQuery(\"\");\n } else {\n resolveQuerySelection(text);\n setIsOpen(false);\n }\n }}\n >\n <PlusCircleIcon className=\"h-4 w-4\" aria-hidden=\"true\" />\n Add “{query.trim()}”\n </button>\n </li>\n )}\n </ul>\n {useMobileSheet && multiple && (\n <div className=\"shrink-0 border-t border-border bg-background px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]\">\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"min-h-11 w-full\"\n onClick={() => {\n setQuery(\"\");\n setIsOpen(false);\n }}\n >\n Done\n </Button>\n </div>\n )}\n </OptionsSurface>\n </Sheet>\n )}\n </div>\n );\n}\n\ntype AutocompleteCommonProps<ID extends number | string> = {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n placeholder?: string;\n className?: string;\n label?: React.ReactNode;\n props?: any[];\n /** Allow a user to add their own text. Custom values are strings. */\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n};\n\nexport type AutocompleteProps<ID extends number | string> = AutocompleteCommonProps<ID> & (\n | { multiple?: false; value?: ID | null; setter: (value?: ID | null) => void }\n | { multiple: true; value?: ID[]; setter: (value: ID[]) => void }\n);\n\nexport const Autocomplete = <ID extends number | string>(config: AutocompleteProps<ID>) => {\n const { required, options, placeholder, className, label, props, allowCustomValue = false,\n preserveOptionOrder = false, emptyText, mobileDropdownMode, inputIcons } = config;\n return (\n <AutocompleteBase<ID>\n required={required}\n options={options}\n multiple={config.multiple === true}\n value={config.multiple === true ? config.value ?? [] : config.value != null ? [config.value] : []}\n setter={(arr) => {\n if (config.multiple === true) config.setter(arr);\n else config.setter(arr[0] ?? null);\n }}\n placeholder={placeholder}\n className={className}\n label={label}\n allowCustomValue={allowCustomValue}\n preserveOptionOrder={preserveOptionOrder}\n emptyText={emptyText}\n mobileDropdownMode={mobileDropdownMode}\n inputIcons={inputIcons}\n {...props}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+BA;;AAE0D;AAC1D;;;;AAmCE;;;;AAII;;;;AAGH;AACD;AACA;AACA;AACA;AACA;AACA;;;AAIA;AACA;AAKA;;AAEE;AAGI;AAEN;;AAGE;AACA;AAAW;;AAGT;;;AAKA;;AAEA;;;AAIA;;AAEA;;AAGF;AACF;AAEA;AAEA;;;;AAMY;AACA;;AAGV;AACE;;;AAIJ;AACE;;AAEE;;;;;;AAMF;AAAiB;;AACZ;;AAEP;AAEA;;AAEE;;AAEF;;AAKO;AACC;AACA;AACF;AACC;AAIP;AACA;;AAEA;;AAIE;;;;;;AAOE;;;;;AAMA;AACF;AAEA;AACA;;;AAIA;AACE;;;AASF;AACF;AAEA;;AAIA;AACE;;;AAEE;AACA;AACA;;AAEA;;;;;;;AAOF;;;;;;;AASA;AACE;;AAEE;;;;;;AAMJ;;AACA;;AACF;;;;;AAwCA;AACE;AACA;AACA;AACA;;;;AAIF;AAIM;AAEE;AAEJ;;AAYE;;;AASM;;AAEJ;;AAIE;;AAwBE;;AAEF;AAEE;;;;;;;;AAOI;AACA;AACA;;;;;AAKN;AAEsC;;;AA8BpC;;;;AAMA;;;AAGA;AAEE;AACE;AAEF;;;;;;;;AAQkC;;;AAIlC;;AAEJ;AAEE;;;;AAIF;AAEE;;;;;;;AAME;;;;;;AAQoG;AAUnG;AACA;AAID;AACI;AACA;AACD;;AAmBC;;AAEA;;;AAGF;;;;;;;;;AAYE;;;AAGF;;AAaF;AACA;;AAOU;;AAEA;AACA;;;AAcJ;;;;;AAKI;;;;;;;;AAsBZ;AAeM;;;;;;;;;;;;;AAoCpB;AAsBO;AACL;AAEA;AAOM;AAA8B;;;AAEhC;AAYN;;"}
|
|
@@ -11,22 +11,22 @@ const ContextMenuGroup = ContextMenuPrimitive.Group;
|
|
|
11
11
|
const ContextMenuPortal = ContextMenuPrimitive.Portal;
|
|
12
12
|
const ContextMenuSub = ContextMenuPrimitive.Sub;
|
|
13
13
|
const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup;
|
|
14
|
-
const ContextMenuSubTrigger = React.forwardRef(({ className, inset, children, ...props }, ref) => (jsxs(ContextMenuPrimitive.SubTrigger, { ref: ref, className: cn("flex cursor-pointer select-none items-center pointer-coarse:min-h-11 rounded-control-sm px-
|
|
14
|
+
const ContextMenuSubTrigger = React.forwardRef(({ className, inset, children, ...props }, ref) => (jsxs(ContextMenuPrimitive.SubTrigger, { ref: ref, className: cn("flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm px-option-x py-2 text-sm outline-none focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground", inset && "pl-9", className), ...props, children: [children, jsx(ChevronRight, { className: "ml-auto h-4 w-4" })] })));
|
|
15
15
|
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName;
|
|
16
|
-
const ContextMenuSubContent = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.SubContent, { ref: ref, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-
|
|
16
|
+
const ContextMenuSubContent = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.SubContent, { ref: ref, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-option-inset text-popover-foreground shadow-card data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props })));
|
|
17
17
|
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName;
|
|
18
|
-
const ContextMenuContent = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.Portal, { children: jsx(ContextMenuPrimitive.Content, { ref: ref, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-
|
|
18
|
+
const ContextMenuContent = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.Portal, { children: jsx(ContextMenuPrimitive.Content, { ref: ref, className: cn("z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-option-inset text-popover-foreground shadow-card animate-in motion-reduce:animate-none fade-in-80 data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }) })));
|
|
19
19
|
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName;
|
|
20
|
-
const ContextMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (jsx(ContextMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center pointer-coarse:min-h-11 rounded-control-sm px-
|
|
20
|
+
const ContextMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (jsx(ContextMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm px-option-x py-2 text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", inset && "pl-9", className), ...props })));
|
|
21
21
|
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName;
|
|
22
|
-
const ContextMenuCheckboxItem = React.forwardRef(({ className, children, checked, ...props }, ref) => (jsxs(ContextMenuPrimitive.CheckboxItem, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center pointer-coarse:min-h-11 rounded-control-sm py-
|
|
22
|
+
const ContextMenuCheckboxItem = React.forwardRef(({ className, children, checked, ...props }, ref) => (jsxs(ContextMenuPrimitive.CheckboxItem, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm py-2 pl-9 pr-option-x text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), checked: checked, ...props, children: [jsx("span", { className: "absolute left-option-x flex h-3.5 w-3.5 items-center justify-center", children: jsx(ContextMenuPrimitive.ItemIndicator, { children: jsx(Check, { className: "h-4 w-4" }) }) }), children] })));
|
|
23
23
|
ContextMenuCheckboxItem.displayName =
|
|
24
24
|
ContextMenuPrimitive.CheckboxItem.displayName;
|
|
25
|
-
const ContextMenuRadioItem = React.forwardRef(({ className, children, ...props }, ref) => (jsxs(ContextMenuPrimitive.RadioItem, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center pointer-coarse:min-h-11 rounded-control-sm py-
|
|
25
|
+
const ContextMenuRadioItem = React.forwardRef(({ className, children, ...props }, ref) => (jsxs(ContextMenuPrimitive.RadioItem, { ref: ref, className: cn("relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm py-2 pl-9 pr-option-x text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: [jsx("span", { className: "absolute left-option-x flex h-3.5 w-3.5 items-center justify-center", children: jsx(ContextMenuPrimitive.ItemIndicator, { children: jsx(Circle, { className: "h-2 w-2 fill-current" }) }) }), children] })));
|
|
26
26
|
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName;
|
|
27
|
-
const ContextMenuLabel = React.forwardRef(({ className, inset, ...props }, ref) => (jsx(ContextMenuPrimitive.Label, { ref: ref, className: cn("px-2 py-1.5 text-sm font-semibold text-foreground", inset && "pl-
|
|
27
|
+
const ContextMenuLabel = React.forwardRef(({ className, inset, ...props }, ref) => (jsx(ContextMenuPrimitive.Label, { ref: ref, className: cn("px-2 py-1.5 text-sm font-semibold text-foreground", inset && "pl-9", className), ...props })));
|
|
28
28
|
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName;
|
|
29
|
-
const ContextMenuSeparator = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.Separator, { ref: ref, className: cn("-mx-
|
|
29
|
+
const ContextMenuSeparator = React.forwardRef(({ className, ...props }, ref) => (jsx(ContextMenuPrimitive.Separator, { ref: ref, className: cn("-mx-option-inset my-1 h-px bg-border", className), ...props })));
|
|
30
30
|
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName;
|
|
31
31
|
const ContextMenuShortcut = ({ className, ...props }) => {
|
|
32
32
|
return (jsx("span", { className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className), ...props }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu.js","sources":["../../src/components/context-menu.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as ContextMenuPrimitive from \"@radix-ui/react-context-menu\";\nimport { Check, ChevronRight, Circle } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\n\nconst ContextMenu = ContextMenuPrimitive.Root;\n\nconst ContextMenuTrigger = ContextMenuPrimitive.Trigger;\n\nconst ContextMenuGroup = ContextMenuPrimitive.Group;\n\nconst ContextMenuPortal = ContextMenuPrimitive.Portal;\n\nconst ContextMenuSub = ContextMenuPrimitive.Sub;\n\nconst ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup;\n\nconst ContextMenuSubTrigger = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n }\n>(({ className, inset, children, ...props }, ref) => (\n <ContextMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n \"flex cursor-pointer select-none items-center pointer-coarse:min-h-11 rounded-control-sm px-
|
|
1
|
+
{"version":3,"file":"context-menu.js","sources":["../../src/components/context-menu.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as ContextMenuPrimitive from \"@radix-ui/react-context-menu\";\nimport { Check, ChevronRight, Circle } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\n\nconst ContextMenu = ContextMenuPrimitive.Root;\n\nconst ContextMenuTrigger = ContextMenuPrimitive.Trigger;\n\nconst ContextMenuGroup = ContextMenuPrimitive.Group;\n\nconst ContextMenuPortal = ContextMenuPrimitive.Portal;\n\nconst ContextMenuSub = ContextMenuPrimitive.Sub;\n\nconst ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup;\n\nconst ContextMenuSubTrigger = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n }\n>(({ className, inset, children, ...props }, ref) => (\n <ContextMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n \"flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm px-option-x py-2 text-sm outline-none focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground\",\n inset && \"pl-9\",\n className,\n )}\n {...props}\n >\n {children}\n <ChevronRight className=\"ml-auto h-4 w-4\" />\n </ContextMenuPrimitive.SubTrigger>\n));\nContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName;\n\nconst ContextMenuSubContent = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>\n>(({ className, ...props }, ref) => (\n <ContextMenuPrimitive.SubContent\n ref={ref}\n className={cn(\n \"z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-option-inset text-popover-foreground shadow-card data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2\",\n className,\n )}\n {...props}\n />\n));\nContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName;\n\nconst ContextMenuContent = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>\n>(({ className, ...props }, ref) => (\n <ContextMenuPrimitive.Portal>\n <ContextMenuPrimitive.Content\n ref={ref}\n className={cn(\n \"z-50 min-w-[8rem] overflow-hidden rounded-control-lg border border-border bg-popover p-option-inset text-popover-foreground shadow-card animate-in motion-reduce:animate-none fade-in-80 data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2\",\n className,\n )}\n {...props}\n />\n </ContextMenuPrimitive.Portal>\n));\nContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName;\n\nconst ContextMenuItem = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <ContextMenuPrimitive.Item\n ref={ref}\n className={cn(\n \"relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm px-option-x py-2 text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n inset && \"pl-9\",\n className,\n )}\n {...props}\n />\n));\nContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName;\n\nconst ContextMenuCheckboxItem = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.CheckboxItem>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>\n>(({ className, children, checked, ...props }, ref) => (\n <ContextMenuPrimitive.CheckboxItem\n ref={ref}\n className={cn(\n \"relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm py-2 pl-9 pr-option-x text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n className,\n )}\n checked={checked}\n {...props}\n >\n <span className=\"absolute left-option-x flex h-3.5 w-3.5 items-center justify-center\">\n <ContextMenuPrimitive.ItemIndicator>\n <Check className=\"h-4 w-4\" />\n </ContextMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </ContextMenuPrimitive.CheckboxItem>\n));\nContextMenuCheckboxItem.displayName =\n ContextMenuPrimitive.CheckboxItem.displayName;\n\nconst ContextMenuRadioItem = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.RadioItem>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>\n>(({ className, children, ...props }, ref) => (\n <ContextMenuPrimitive.RadioItem\n ref={ref}\n className={cn(\n \"relative flex cursor-pointer select-none items-center min-h-option-row pointer-coarse:min-h-11 rounded-control-sm py-2 pl-9 pr-option-x text-sm outline-none focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n className,\n )}\n {...props}\n >\n <span className=\"absolute left-option-x flex h-3.5 w-3.5 items-center justify-center\">\n <ContextMenuPrimitive.ItemIndicator>\n <Circle className=\"h-2 w-2 fill-current\" />\n </ContextMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </ContextMenuPrimitive.RadioItem>\n));\nContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName;\n\nconst ContextMenuLabel = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.Label>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <ContextMenuPrimitive.Label\n ref={ref}\n className={cn(\n \"px-2 py-1.5 text-sm font-semibold text-foreground\",\n inset && \"pl-9\",\n className,\n )}\n {...props}\n />\n));\nContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName;\n\nconst ContextMenuSeparator = React.forwardRef<\n React.ElementRef<typeof ContextMenuPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <ContextMenuPrimitive.Separator\n ref={ref}\n className={cn(\"-mx-option-inset my-1 h-px bg-border\", className)}\n {...props}\n />\n));\nContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName;\n\nconst ContextMenuShortcut = ({\n className,\n ...props\n}: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span\n className={cn(\n \"ml-auto text-xs tracking-widest text-muted-foreground\",\n className,\n )}\n {...props}\n />\n );\n};\nContextMenuShortcut.displayName = \"ContextMenuShortcut\";\n\nexport {\n ContextMenu,\n ContextMenuTrigger,\n ContextMenuContent,\n ContextMenuItem,\n ContextMenuCheckboxItem,\n ContextMenuRadioItem,\n ContextMenuLabel,\n ContextMenuSeparator,\n ContextMenuShortcut,\n ContextMenuGroup,\n ContextMenuPortal,\n ContextMenuSub,\n ContextMenuSubContent,\n ContextMenuSubTrigger,\n ContextMenuRadioGroup,\n};\n"],"names":[],"mappings":";;;;;;;AAQA;AAEA;AAEA;AAEA;AAEA;AAEA;AAEA;AAmBA;AAEA;AAaA;AAEA;AAeA;AAEA;AAgBA;AAEA;AAqBA;AACE;AAEF;AAoBA;AAEA;AAgBA;AAEA;AAUA;AAEA;AAIE;AASF;AACA;;"}
|
|
@@ -19,28 +19,28 @@ function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
|
|
|
19
19
|
// this portals to document.body as a sibling of it, so it needs
|
|
20
20
|
// to clear that to render above a modal. Matches the same fix
|
|
21
21
|
// already applied to SelectContent (components/select.tsx).
|
|
22
|
-
'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-control-lg border border-border shadow-card', className), ...props }) }));
|
|
22
|
+
'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-control-lg border border-border p-option-inset shadow-card', className), ...props }) }));
|
|
23
23
|
}
|
|
24
24
|
function DropdownMenuGroup({ ...props }) {
|
|
25
25
|
return (jsx(DropdownMenuPrimitive.Group, { "data-slot": "dropdown-menu-group", ...props }));
|
|
26
26
|
}
|
|
27
27
|
function DropdownMenuItem({ className, inset, variant = 'default', ...props }) {
|
|
28
|
-
return (jsx(DropdownMenuPrimitive.Item, { "data-slot": "dropdown-menu-item", "data-inset": inset, "data-variant": variant, className: cn("focus:bg-muted focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-pointer select-none items-center gap-2 px-
|
|
28
|
+
return (jsx(DropdownMenuPrimitive.Item, { "data-slot": "dropdown-menu-item", "data-inset": inset, "data-variant": variant, className: cn("focus:bg-muted focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-2 rounded-control-sm px-option-x py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-9 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...props }));
|
|
29
29
|
}
|
|
30
30
|
function DropdownMenuCheckboxItem({ className, children, checked, ...props }) {
|
|
31
|
-
return (jsxs(DropdownMenuPrimitive.CheckboxItem, { "data-slot": "dropdown-menu-checkbox-item", className: cn("focus:bg-muted focus:text-foreground relative flex w-full cursor-pointer items-center gap-2 py-2 pr-
|
|
31
|
+
return (jsxs(DropdownMenuPrimitive.CheckboxItem, { "data-slot": "dropdown-menu-checkbox-item", className: cn("focus:bg-muted focus:text-foreground relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm py-2 pr-option-x pl-9 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), checked: checked, ...props, children: [jsx("span", { className: "pointer-events-none absolute left-option-x flex size-4 items-center justify-center", children: jsx(DropdownMenuPrimitive.ItemIndicator, { children: jsx(CheckIcon, { className: "size-4" }) }) }), children] }));
|
|
32
32
|
}
|
|
33
33
|
function DropdownMenuRadioGroup({ ...props }) {
|
|
34
34
|
return (jsx(DropdownMenuPrimitive.RadioGroup, { "data-slot": "dropdown-menu-radio-group", ...props }));
|
|
35
35
|
}
|
|
36
36
|
function DropdownMenuRadioItem({ className, children, ...props }) {
|
|
37
|
-
return (jsxs(DropdownMenuPrimitive.RadioItem, { "data-slot": "dropdown-menu-radio-item", className: cn("focus:bg-muted focus:text-foreground relative flex w-full cursor-pointer items-center gap-2 py-2 pr-
|
|
37
|
+
return (jsxs(DropdownMenuPrimitive.RadioItem, { "data-slot": "dropdown-menu-radio-item", className: cn("focus:bg-muted focus:text-foreground relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm py-2 pr-option-x pl-9 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...props, children: [jsx("span", { className: "pointer-events-none absolute left-option-x flex size-4 items-center justify-center", children: jsx(DropdownMenuPrimitive.ItemIndicator, { children: jsx(CircleIcon, { className: "size-2 fill-current" }) }) }), children] }));
|
|
38
38
|
}
|
|
39
39
|
function DropdownMenuLabel({ className, inset, ...props }) {
|
|
40
|
-
return (jsx(DropdownMenuPrimitive.Label, { "data-slot": "dropdown-menu-label", "data-inset": inset, className: cn('px-
|
|
40
|
+
return (jsx(DropdownMenuPrimitive.Label, { "data-slot": "dropdown-menu-label", "data-inset": inset, className: cn('px-option-x py-2 text-sm font-semibold text-foreground data-[inset]:pl-9', className), ...props }));
|
|
41
41
|
}
|
|
42
42
|
function DropdownMenuSeparator({ className, ...props }) {
|
|
43
|
-
return (jsx(DropdownMenuPrimitive.Separator, { "data-slot": "dropdown-menu-separator", className: cn('bg-border h-px', className), ...props }));
|
|
43
|
+
return (jsx(DropdownMenuPrimitive.Separator, { "data-slot": "dropdown-menu-separator", className: cn('bg-border -mx-option-inset my-1 h-px', className), ...props }));
|
|
44
44
|
}
|
|
45
45
|
function DropdownMenuShortcut({ className, ...props }) {
|
|
46
46
|
return (jsx("span", { "data-slot": "dropdown-menu-shortcut", className: cn('text-muted-foreground ml-auto text-xs tracking-widest', className), ...props }));
|
|
@@ -49,12 +49,12 @@ function DropdownMenuSub({ ...props }) {
|
|
|
49
49
|
return jsx(DropdownMenuPrimitive.Sub, { "data-slot": "dropdown-menu-sub", ...props });
|
|
50
50
|
}
|
|
51
51
|
function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
|
|
52
|
-
return (jsxs(DropdownMenuPrimitive.SubTrigger, { "data-slot": "dropdown-menu-sub-trigger", "data-inset": inset, className: cn('focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground flex cursor-pointer items-center gap-2 px-
|
|
52
|
+
return (jsxs(DropdownMenuPrimitive.SubTrigger, { "data-slot": "dropdown-menu-sub-trigger", "data-inset": inset, className: cn('focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground flex min-h-option-row cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[inset]:pl-9', className), ...props, children: [children, jsx(ChevronRightIcon, { className: "ml-auto size-4 text-muted-foreground" })] }));
|
|
53
53
|
}
|
|
54
54
|
function DropdownMenuSubContent({ className, ...props }) {
|
|
55
55
|
return (jsx(DropdownMenuPrimitive.SubContent, { "data-slot": "dropdown-menu-sub-content", className: cn(
|
|
56
56
|
// z-[1100] — see the matching note on DropdownMenuContent above.
|
|
57
|
-
'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-control-lg border border-border shadow-card', className), ...props }));
|
|
57
|
+
'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-control-lg border border-border p-option-inset shadow-card', className), ...props }));
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-menu.js","sources":["../../src/components/dropdown-menu.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';\n\nimport { cn } from '@/utils';\n\nfunction DropdownMenu({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {\n return <DropdownMenuPrimitive.Root data-slot=\"dropdown-menu\" {...props} />;\n}\n\nfunction DropdownMenuPortal({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {\n return (\n <DropdownMenuPrimitive.Portal data-slot=\"dropdown-menu-portal\" {...props} />\n );\n}\n\nfunction DropdownMenuTrigger({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {\n return (\n <DropdownMenuPrimitive.Trigger\n data-slot=\"dropdown-menu-trigger\"\n {...props}\n />\n );\n}\n\nfunction DropdownMenuContent({\n className,\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n data-slot=\"dropdown-menu-content\"\n sideOffset={sideOffset}\n className={cn(\n // z-[1100] (not the default z-50) — the shared modal system's\n // backdrop is z-[1000] (app/providers/modal-provider.tsx), and\n // this portals to document.body as a sibling of it, so it needs\n // to clear that to render above a modal. Matches the same fix\n // already applied to SelectContent (components/select.tsx).\n 'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-control-lg border border-border shadow-card',\n className,\n )}\n {...props}\n />\n </DropdownMenuPrimitive.Portal>\n );\n}\n\nfunction DropdownMenuGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {\n return (\n <DropdownMenuPrimitive.Group data-slot=\"dropdown-menu-group\" {...props} />\n );\n}\n\nfunction DropdownMenuItem({\n className,\n inset,\n variant = 'default',\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n variant?: 'default' | 'destructive';\n}) {\n return (\n <DropdownMenuPrimitive.Item\n data-slot=\"dropdown-menu-item\"\n data-inset={inset}\n data-variant={variant}\n className={cn(\n \"focus:bg-muted focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-pointer select-none items-center gap-2 px-4 py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-10 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuCheckboxItem({\n className,\n children,\n checked,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {\n return (\n <DropdownMenuPrimitive.CheckboxItem\n data-slot=\"dropdown-menu-checkbox-item\"\n className={cn(\n \"focus:bg-muted focus:text-foreground relative flex w-full cursor-pointer items-center gap-2 py-2 pr-4 pl-10 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n checked={checked}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-4 flex size-4 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CheckIcon className=\"size-4\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.CheckboxItem>\n );\n}\n\nfunction DropdownMenuRadioGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {\n return (\n <DropdownMenuPrimitive.RadioGroup\n data-slot=\"dropdown-menu-radio-group\"\n {...props}\n />\n );\n}\n\nfunction DropdownMenuRadioItem({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {\n return (\n <DropdownMenuPrimitive.RadioItem\n data-slot=\"dropdown-menu-radio-item\"\n className={cn(\n \"focus:bg-muted focus:text-foreground relative flex w-full cursor-pointer items-center gap-2 py-2 pr-4 pl-10 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-4 flex size-4 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CircleIcon className=\"size-2 fill-current\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.RadioItem>\n );\n}\n\nfunction DropdownMenuLabel({\n className,\n inset,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {\n inset?: boolean;\n}) {\n return (\n <DropdownMenuPrimitive.Label\n data-slot=\"dropdown-menu-label\"\n data-inset={inset}\n className={cn(\n 'px-4 py-2 text-sm font-semibold text-foreground data-[inset]:pl-10',\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuSeparator({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {\n return (\n <DropdownMenuPrimitive.Separator\n data-slot=\"dropdown-menu-separator\"\n className={cn('bg-border h-px', className)}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuShortcut({\n className,\n ...props\n}: React.ComponentProps<'span'>) {\n return (\n <span\n data-slot=\"dropdown-menu-shortcut\"\n className={cn(\n 'text-muted-foreground ml-auto text-xs tracking-widest',\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuSub({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {\n return <DropdownMenuPrimitive.Sub data-slot=\"dropdown-menu-sub\" {...props} />;\n}\n\nfunction DropdownMenuSubTrigger({\n className,\n inset,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n}) {\n return (\n <DropdownMenuPrimitive.SubTrigger\n data-slot=\"dropdown-menu-sub-trigger\"\n data-inset={inset}\n className={cn(\n 'focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground flex cursor-pointer items-center gap-2 px-4 py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[inset]:pl-10',\n className,\n )}\n {...props}\n >\n {children}\n <ChevronRightIcon className=\"ml-auto size-4 text-muted-foreground\" />\n </DropdownMenuPrimitive.SubTrigger>\n );\n}\n\nfunction DropdownMenuSubContent({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {\n return (\n <DropdownMenuPrimitive.SubContent\n data-slot=\"dropdown-menu-sub-content\"\n className={cn(\n // z-[1100] — see the matching note on DropdownMenuContent above.\n 'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-control-lg border border-border shadow-card',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport {\n DropdownMenu,\n DropdownMenuPortal,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuLabel,\n DropdownMenuItem,\n DropdownMenuCheckboxItem,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuShortcut,\n DropdownMenuSub,\n DropdownMenuSubTrigger,\n DropdownMenuSubContent,\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AAMA,SAAS,YAAY,CAAC,EACpB,GAAG,KAAK,EACgD,EAAA;IACxD,OAAOA,GAAA,CAAC,qBAAqB,CAAC,IAAI,iBAAW,eAAe,EAAA,GAAK,KAAK,EAAA,CAAI;AAC5E;AAEA,SAAS,kBAAkB,CAAC,EAC1B,GAAG,KAAK,EACkD,EAAA;IAC1D,QACEA,GAAA,CAAC,qBAAqB,CAAC,MAAM,EAAA,EAAA,WAAA,EAAW,sBAAsB,EAAA,GAAK,KAAK,EAAA,CAAI;AAEhF;AAEA,SAAS,mBAAmB,CAAC,EAC3B,GAAG,KAAK,EACmD,EAAA;IAC3D,QACEA,GAAA,CAAC,qBAAqB,CAAC,OAAO,EAAA,EAAA,WAAA,EAClB,uBAAuB,EAAA,GAC7B,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,mBAAmB,CAAC,EAC3B,SAAS,EACT,UAAU,GAAG,CAAC,EACd,GAAG,KAAK,EACmD,EAAA;AAC3D,IAAA,QACEA,GAAA,CAAC,qBAAqB,CAAC,MAAM,EAAA,EAAA,QAAA,EAC3BA,IAAC,qBAAqB,CAAC,OAAO,EAAA,EAAA,WAAA,EAClB,uBAAuB,EACjC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,EAAE;;;;;;YAMX,2mBAA2mB,EAC3mB,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT,EAAA,CAC2B;AAEnC;AAEA,SAAS,iBAAiB,CAAC,EACzB,GAAG,KAAK,EACiD,EAAA;IACzD,QACEA,GAAA,CAAC,qBAAqB,CAAC,KAAK,EAAA,EAAA,WAAA,EAAW,qBAAqB,EAAA,GAAK,KAAK,EAAA,CAAI;AAE9E;AAEA,SAAS,gBAAgB,CAAC,EACxB,SAAS,EACT,KAAK,EACL,OAAO,GAAG,SAAS,EACnB,GAAG,KAAK,EAIT,EAAA;IACC,QACEA,GAAA,CAAC,qBAAqB,CAAC,IAAI,iBACf,oBAAoB,EAAA,YAAA,EAClB,KAAK,EAAA,cAAA,EACH,OAAO,EACrB,SAAS,EAAE,EAAE,CACX,4tBAA4tB,EAC5tB,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,wBAAwB,CAAC,EAChC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,GAAG,KAAK,EACwD,EAAA;IAChE,QACEC,KAAC,qBAAqB,CAAC,YAAY,EAAA,EAAA,WAAA,EACvB,6BAA6B,EACvC,SAAS,EAAE,EAAE,CACX,6ZAA6Z,EAC7Z,SAAS,CACV,EACD,OAAO,EAAE,OAAO,EAAA,GACZ,KAAK,EAAA,QAAA,EAAA,CAETD,cAAM,SAAS,EAAC,6EAA6E,EAAA,QAAA,EAC3FA,GAAA,CAAC,qBAAqB,CAAC,aAAa,cAClCA,GAAA,CAAC,SAAS,IAAC,SAAS,EAAC,QAAQ,EAAA,CAAG,EAAA,CACI,GACjC,EACN,QAAQ,CAAA,EAAA,CAC0B;AAEzC;AAEA,SAAS,sBAAsB,CAAC,EAC9B,GAAG,KAAK,EACsD,EAAA;IAC9D,QACEA,GAAA,CAAC,qBAAqB,CAAC,UAAU,EAAA,EAAA,WAAA,EACrB,2BAA2B,EAAA,GACjC,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,qBAAqB,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACqD,EAAA;AAC7D,IAAA,QACEC,IAAA,CAAC,qBAAqB,CAAC,SAAS,EAAA,EAAA,WAAA,EACpB,0BAA0B,EACpC,SAAS,EAAE,EAAE,CACX,6ZAA6Z,EAC7Z,SAAS,CACV,EAAA,GACG,KAAK,aAETD,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,6EAA6E,YAC3FA,GAAA,CAAC,qBAAqB,CAAC,aAAa,EAAA,EAAA,QAAA,EAClCA,IAAC,UAAU,EAAA,EAAC,SAAS,EAAC,qBAAqB,GAAG,EAAA,CACV,EAAA,CACjC,EACN,QAAQ,CAAA,EAAA,CACuB;AAEtC;AAEA,SAAS,iBAAiB,CAAC,EACzB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EAGT,EAAA;IACC,QACEA,IAAC,qBAAqB,CAAC,KAAK,EAAA,EAAA,WAAA,EAChB,qBAAqB,EAAA,YAAA,EACnB,KAAK,EACjB,SAAS,EAAE,EAAE,CACX,oEAAoE,EACpE,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,qBAAqB,CAAC,EAC7B,SAAS,EACT,GAAG,KAAK,EACqD,EAAA;IAC7D,QACEA,IAAC,qBAAqB,CAAC,SAAS,EAAA,EAAA,WAAA,EACpB,yBAAyB,EACnC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,KACtC,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,oBAAoB,CAAC,EAC5B,SAAS,EACT,GAAG,KAAK,EACqB,EAAA;AAC7B,IAAA,QACEA,GAAA,CAAA,MAAA,EAAA,EAAA,WAAA,EACY,wBAAwB,EAClC,SAAS,EAAE,EAAE,CACX,uDAAuD,EACvD,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,eAAe,CAAC,EACvB,GAAG,KAAK,EAC+C,EAAA;IACvD,OAAOA,GAAA,CAAC,qBAAqB,CAAC,GAAG,iBAAW,mBAAmB,EAAA,GAAK,KAAK,EAAA,CAAI;AAC/E;AAEA,SAAS,sBAAsB,CAAC,EAC9B,SAAS,EACT,KAAK,EACL,QAAQ,EACR,GAAG,KAAK,EAGT,EAAA;AACC,IAAA,QACEC,IAAA,CAAC,qBAAqB,CAAC,UAAU,EAAA,EAAA,WAAA,EACrB,2BAA2B,EAAA,YAAA,EACzB,KAAK,EACjB,SAAS,EAAE,EAAE,CACX,sUAAsU,EACtU,SAAS,CACV,EAAA,GACG,KAAK,EAAA,QAAA,EAAA,CAER,QAAQ,EACTD,GAAA,CAAC,gBAAgB,EAAA,EAAC,SAAS,EAAC,sCAAsC,EAAA,CAAG,CAAA,EAAA,CACpC;AAEvC;AAEA,SAAS,sBAAsB,CAAC,EAC9B,SAAS,EACT,GAAG,KAAK,EACsD,EAAA;IAC9D,QACEA,GAAA,CAAC,qBAAqB,CAAC,UAAU,iBACrB,2BAA2B,EACrC,SAAS,EAAE,EAAE;;AAEX,QAAA,kiBAAkiB,EACliB,SAAS,CACV,KACG,KAAK,EAAA,CACT;AAEN;;;;"}
|
|
1
|
+
{"version":3,"file":"dropdown-menu.js","sources":["../../src/components/dropdown-menu.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';\n\nimport { cn } from '@/utils';\n\nfunction DropdownMenu({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {\n return <DropdownMenuPrimitive.Root data-slot=\"dropdown-menu\" {...props} />;\n}\n\nfunction DropdownMenuPortal({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {\n return (\n <DropdownMenuPrimitive.Portal data-slot=\"dropdown-menu-portal\" {...props} />\n );\n}\n\nfunction DropdownMenuTrigger({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {\n return (\n <DropdownMenuPrimitive.Trigger\n data-slot=\"dropdown-menu-trigger\"\n {...props}\n />\n );\n}\n\nfunction DropdownMenuContent({\n className,\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n data-slot=\"dropdown-menu-content\"\n sideOffset={sideOffset}\n className={cn(\n // z-[1100] (not the default z-50) — the shared modal system's\n // backdrop is z-[1000] (app/providers/modal-provider.tsx), and\n // this portals to document.body as a sibling of it, so it needs\n // to clear that to render above a modal. Matches the same fix\n // already applied to SelectContent (components/select.tsx).\n 'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-control-lg border border-border p-option-inset shadow-card',\n className,\n )}\n {...props}\n />\n </DropdownMenuPrimitive.Portal>\n );\n}\n\nfunction DropdownMenuGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {\n return (\n <DropdownMenuPrimitive.Group data-slot=\"dropdown-menu-group\" {...props} />\n );\n}\n\nfunction DropdownMenuItem({\n className,\n inset,\n variant = 'default',\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n variant?: 'default' | 'destructive';\n}) {\n return (\n <DropdownMenuPrimitive.Item\n data-slot=\"dropdown-menu-item\"\n data-inset={inset}\n data-variant={variant}\n className={cn(\n \"focus:bg-muted focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-2 rounded-control-sm px-option-x py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-9 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuCheckboxItem({\n className,\n children,\n checked,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {\n return (\n <DropdownMenuPrimitive.CheckboxItem\n data-slot=\"dropdown-menu-checkbox-item\"\n className={cn(\n \"focus:bg-muted focus:text-foreground relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm py-2 pr-option-x pl-9 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n checked={checked}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-option-x flex size-4 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CheckIcon className=\"size-4\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.CheckboxItem>\n );\n}\n\nfunction DropdownMenuRadioGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {\n return (\n <DropdownMenuPrimitive.RadioGroup\n data-slot=\"dropdown-menu-radio-group\"\n {...props}\n />\n );\n}\n\nfunction DropdownMenuRadioItem({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {\n return (\n <DropdownMenuPrimitive.RadioItem\n data-slot=\"dropdown-menu-radio-item\"\n className={cn(\n \"focus:bg-muted focus:text-foreground relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm py-2 pr-option-x pl-9 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className,\n )}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-option-x flex size-4 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CircleIcon className=\"size-2 fill-current\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.RadioItem>\n );\n}\n\nfunction DropdownMenuLabel({\n className,\n inset,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {\n inset?: boolean;\n}) {\n return (\n <DropdownMenuPrimitive.Label\n data-slot=\"dropdown-menu-label\"\n data-inset={inset}\n className={cn(\n 'px-option-x py-2 text-sm font-semibold text-foreground data-[inset]:pl-9',\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuSeparator({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {\n return (\n <DropdownMenuPrimitive.Separator\n data-slot=\"dropdown-menu-separator\"\n className={cn('bg-border -mx-option-inset my-1 h-px', className)}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuShortcut({\n className,\n ...props\n}: React.ComponentProps<'span'>) {\n return (\n <span\n data-slot=\"dropdown-menu-shortcut\"\n className={cn(\n 'text-muted-foreground ml-auto text-xs tracking-widest',\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction DropdownMenuSub({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {\n return <DropdownMenuPrimitive.Sub data-slot=\"dropdown-menu-sub\" {...props} />;\n}\n\nfunction DropdownMenuSubTrigger({\n className,\n inset,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n}) {\n return (\n <DropdownMenuPrimitive.SubTrigger\n data-slot=\"dropdown-menu-sub-trigger\"\n data-inset={inset}\n className={cn(\n 'focus:bg-muted focus:text-foreground data-[state=open]:bg-muted data-[state=open]:text-foreground flex min-h-option-row cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pointer-coarse:min-h-11 text-sm text-muted-foreground transition-colors duration-state hover:bg-muted motion-reduce:transition-none outline-hidden select-none data-[inset]:pl-9',\n className,\n )}\n {...props}\n >\n {children}\n <ChevronRightIcon className=\"ml-auto size-4 text-muted-foreground\" />\n </DropdownMenuPrimitive.SubTrigger>\n );\n}\n\nfunction DropdownMenuSubContent({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {\n return (\n <DropdownMenuPrimitive.SubContent\n data-slot=\"dropdown-menu-sub-content\"\n className={cn(\n // z-[1100] — see the matching note on DropdownMenuContent above.\n 'bg-popover text-popover-foreground data-[state=open]:animate-in motion-reduce:animate-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[1100] min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-control-lg border border-border p-option-inset shadow-card',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport {\n DropdownMenu,\n DropdownMenuPortal,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuLabel,\n DropdownMenuItem,\n DropdownMenuCheckboxItem,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuShortcut,\n DropdownMenuSub,\n DropdownMenuSubTrigger,\n DropdownMenuSubContent,\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AAMA,SAAS,YAAY,CAAC,EACpB,GAAG,KAAK,EACgD,EAAA;IACxD,OAAOA,GAAA,CAAC,qBAAqB,CAAC,IAAI,iBAAW,eAAe,EAAA,GAAK,KAAK,EAAA,CAAI;AAC5E;AAEA,SAAS,kBAAkB,CAAC,EAC1B,GAAG,KAAK,EACkD,EAAA;IAC1D,QACEA,GAAA,CAAC,qBAAqB,CAAC,MAAM,EAAA,EAAA,WAAA,EAAW,sBAAsB,EAAA,GAAK,KAAK,EAAA,CAAI;AAEhF;AAEA,SAAS,mBAAmB,CAAC,EAC3B,GAAG,KAAK,EACmD,EAAA;IAC3D,QACEA,GAAA,CAAC,qBAAqB,CAAC,OAAO,EAAA,EAAA,WAAA,EAClB,uBAAuB,EAAA,GAC7B,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,mBAAmB,CAAC,EAC3B,SAAS,EACT,UAAU,GAAG,CAAC,EACd,GAAG,KAAK,EACmD,EAAA;AAC3D,IAAA,QACEA,GAAA,CAAC,qBAAqB,CAAC,MAAM,EAAA,EAAA,QAAA,EAC3BA,IAAC,qBAAqB,CAAC,OAAO,EAAA,EAAA,WAAA,EAClB,uBAAuB,EACjC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,EAAE;;;;;;YAMX,0nBAA0nB,EAC1nB,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT,EAAA,CAC2B;AAEnC;AAEA,SAAS,iBAAiB,CAAC,EACzB,GAAG,KAAK,EACiD,EAAA;IACzD,QACEA,GAAA,CAAC,qBAAqB,CAAC,KAAK,EAAA,EAAA,WAAA,EAAW,qBAAqB,EAAA,GAAK,KAAK,EAAA,CAAI;AAE9E;AAEA,SAAS,gBAAgB,CAAC,EACxB,SAAS,EACT,KAAK,EACL,OAAO,GAAG,SAAS,EACnB,GAAG,KAAK,EAIT,EAAA;IACC,QACEA,GAAA,CAAC,qBAAqB,CAAC,IAAI,iBACf,oBAAoB,EAAA,YAAA,EAClB,KAAK,EAAA,cAAA,EACH,OAAO,EACrB,SAAS,EAAE,EAAE,CACX,swBAAswB,EACtwB,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,wBAAwB,CAAC,EAChC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,GAAG,KAAK,EACwD,EAAA;IAChE,QACEC,KAAC,qBAAqB,CAAC,YAAY,EAAA,EAAA,WAAA,EACvB,6BAA6B,EACvC,SAAS,EAAE,EAAE,CACX,ucAAuc,EACvc,SAAS,CACV,EACD,OAAO,EAAE,OAAO,EAAA,GACZ,KAAK,EAAA,QAAA,EAAA,CAETD,cAAM,SAAS,EAAC,oFAAoF,EAAA,QAAA,EAClGA,GAAA,CAAC,qBAAqB,CAAC,aAAa,cAClCA,GAAA,CAAC,SAAS,IAAC,SAAS,EAAC,QAAQ,EAAA,CAAG,EAAA,CACI,GACjC,EACN,QAAQ,CAAA,EAAA,CAC0B;AAEzC;AAEA,SAAS,sBAAsB,CAAC,EAC9B,GAAG,KAAK,EACsD,EAAA;IAC9D,QACEA,GAAA,CAAC,qBAAqB,CAAC,UAAU,EAAA,EAAA,WAAA,EACrB,2BAA2B,EAAA,GACjC,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,qBAAqB,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACqD,EAAA;AAC7D,IAAA,QACEC,IAAA,CAAC,qBAAqB,CAAC,SAAS,EAAA,EAAA,WAAA,EACpB,0BAA0B,EACpC,SAAS,EAAE,EAAE,CACX,ucAAuc,EACvc,SAAS,CACV,EAAA,GACG,KAAK,aAETD,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,oFAAoF,YAClGA,GAAA,CAAC,qBAAqB,CAAC,aAAa,EAAA,EAAA,QAAA,EAClCA,IAAC,UAAU,EAAA,EAAC,SAAS,EAAC,qBAAqB,GAAG,EAAA,CACV,EAAA,CACjC,EACN,QAAQ,CAAA,EAAA,CACuB;AAEtC;AAEA,SAAS,iBAAiB,CAAC,EACzB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EAGT,EAAA;IACC,QACEA,IAAC,qBAAqB,CAAC,KAAK,EAAA,EAAA,WAAA,EAChB,qBAAqB,EAAA,YAAA,EACnB,KAAK,EACjB,SAAS,EAAE,EAAE,CACX,0EAA0E,EAC1E,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,qBAAqB,CAAC,EAC7B,SAAS,EACT,GAAG,KAAK,EACqD,EAAA;IAC7D,QACEA,IAAC,qBAAqB,CAAC,SAAS,EAAA,EAAA,WAAA,EACpB,yBAAyB,EACnC,SAAS,EAAE,EAAE,CAAC,sCAAsC,EAAE,SAAS,CAAC,KAC5D,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,oBAAoB,CAAC,EAC5B,SAAS,EACT,GAAG,KAAK,EACqB,EAAA;AAC7B,IAAA,QACEA,GAAA,CAAA,MAAA,EAAA,EAAA,WAAA,EACY,wBAAwB,EAClC,SAAS,EAAE,EAAE,CACX,uDAAuD,EACvD,SAAS,CACV,EAAA,GACG,KAAK,EAAA,CACT;AAEN;AAEA,SAAS,eAAe,CAAC,EACvB,GAAG,KAAK,EAC+C,EAAA;IACvD,OAAOA,GAAA,CAAC,qBAAqB,CAAC,GAAG,iBAAW,mBAAmB,EAAA,GAAK,KAAK,EAAA,CAAI;AAC/E;AAEA,SAAS,sBAAsB,CAAC,EAC9B,SAAS,EACT,KAAK,EACL,QAAQ,EACR,GAAG,KAAK,EAGT,EAAA;AACC,IAAA,QACEC,IAAA,CAAC,qBAAqB,CAAC,UAAU,EAAA,EAAA,WAAA,EACrB,2BAA2B,EAAA,YAAA,EACzB,KAAK,EACjB,SAAS,EAAE,EAAE,CACX,gXAAgX,EAChX,SAAS,CACV,EAAA,GACG,KAAK,EAAA,QAAA,EAAA,CAER,QAAQ,EACTD,GAAA,CAAC,gBAAgB,EAAA,EAAC,SAAS,EAAC,sCAAsC,EAAA,CAAG,CAAA,EAAA,CACpC;AAEvC;AAEA,SAAS,sBAAsB,CAAC,EAC9B,SAAS,EACT,GAAG,KAAK,EACsD,EAAA;IAC9D,QACEA,GAAA,CAAC,qBAAqB,CAAC,UAAU,iBACrB,2BAA2B,EACrC,SAAS,EAAE,EAAE;;AAEX,QAAA,ijBAAijB,EACjjB,SAAS,CACV,KACG,KAAK,EAAA,CACT;AAEN;;;;"}
|
|
@@ -59,7 +59,7 @@ const DropdownOptionButton = ({ children, set_is_open, size = "xs", }) => {
|
|
|
59
59
|
}, [onTouchStart]);
|
|
60
60
|
return (jsx("button", {
|
|
61
61
|
// @ts-ignore
|
|
62
|
-
ref: dropdown_button_ref, className: cn("w-full cursor-pointer
|
|
62
|
+
ref: dropdown_button_ref, className: cn("flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-muted-foreground transition-colors hover:bg-muted", is_mobile ? "min-h-12 py-3 active:bg-muted touch-manipulation" : "", `text-${size}`, children.props.highlighted ? "bg-primary-tint" : ""), onClick: (e) => !scrolling && handleClick(e), children: jsx("div", { className: "w-full", children: children }) }));
|
|
63
63
|
};
|
|
64
64
|
/**
|
|
65
65
|
* This component creates a context provider for dropdowns inside it to use.
|
|
@@ -167,7 +167,7 @@ const GroupableRadioDropdown = ({ name, options, onChange, disabled, defaultValu
|
|
|
167
167
|
? Math.min(sheetViewport.height, 640)
|
|
168
168
|
: "80dvh",
|
|
169
169
|
}
|
|
170
|
-
: undefined, children: [isMobile && (jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-2 pt-4", children: [jsx("h2", { className: "text-base font-semibold text-foreground", children: fallback }), jsx("button", { ref: sheetCloseRef, type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: closeSheet, children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] })), jsx("div", { role: "listbox", className: cn("relative overflow-y-auto overscroll-contain touch-pan-y [-webkit-overflow-scrolling:touch] [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]", isMobile ? "min-h-0 flex-1" : "max-h-[400px]"), children: options.map((option, index) => (jsx(DropdownOptionButton, { set_is_open: setIsOpen, size: size, children: jsx(DropdownOption, { highlighted: value === option.id, on_click: () => handleChange(option.id), children: jsx("span", { className: "block whitespace-normal wrap-break-word pr-2", children: option.name }) }) }, index))) })] })] }))] }));
|
|
170
|
+
: undefined, children: [isMobile && (jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-2 pt-4", children: [jsx("h2", { className: "text-base font-semibold text-foreground", children: fallback }), jsx("button", { ref: sheetCloseRef, type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: closeSheet, children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] })), jsx("div", { role: "listbox", className: cn("relative flex flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset touch-pan-y [-webkit-overflow-scrolling:touch] [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]", isMobile ? "min-h-0 flex-1" : "max-h-[400px]"), children: options.map((option, index) => (jsx(DropdownOptionButton, { set_is_open: setIsOpen, size: size, children: jsx(DropdownOption, { highlighted: value === option.id, on_click: () => handleChange(option.id), children: jsx("span", { className: "block whitespace-normal wrap-break-word pr-2", children: option.name }) }) }, index))) })] })] }))] }));
|
|
171
171
|
};
|
|
172
172
|
/**
|
|
173
173
|
* This creates a dropdown menu for navigating with improved mobile support.
|
|
@@ -253,7 +253,7 @@ const GroupableNavDropdown = ({ display, content, children, className = "", show
|
|
|
253
253
|
set_is_open(!is_open);
|
|
254
254
|
}, [is_open]);
|
|
255
255
|
return (jsxs("div", { className: cn("relative z-[100]", className), ref: dropdownRef, children: [jsxs(Button, { ref: buttonRef, type: "button", variant: "ghost", className: "relative flex items-center gap-2 h-12 px-3 z-[1000]", onClick: handleButtonClick, onTouchEnd: (e) => e.stopPropagation(), children: [display, showArrow && (jsx(ChevronDown, { className: cn("w-4 h-4 text-muted-foreground transition-transform", is_open ? "rotate-180" : "") }))] }), is_open && (jsx("div", { className: cn("absolute right-0 mt-2 bg-background border border-border rounded-control-lg overflow-hidden shadow-card z-[1000]", is_mobile ? "w-56" : "w-48", // Slightly wider on mobile for better touch targets
|
|
256
|
-
className), onClick: handleDropdownInteraction, onTouchStart: handleDropdownInteraction, onTouchEnd: handleDropdownInteraction, children: jsxs("div", { className: cn("relative z-[1000] max-h-64 overflow-y-auto overscroll-contain [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]", is_mobile ? "max-h-80" : "max-h-64"), children: [content, Children.map(children, (child, index) => {
|
|
256
|
+
className), onClick: handleDropdownInteraction, onTouchStart: handleDropdownInteraction, onTouchEnd: handleDropdownInteraction, children: jsxs("div", { className: cn("relative z-[1000] flex max-h-64 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]", is_mobile ? "max-h-80" : "max-h-64"), children: [content, Children.map(children, (child, index) => {
|
|
257
257
|
return (jsx(DropdownOptionButton, { set_is_open: set_is_open, children: child ? child : jsx(Fragment, {}) }, index));
|
|
258
258
|
})] }) }))] }));
|
|
259
259
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.js","sources":["../../src/components/dropdown.tsx"],"sourcesContent":["'use client';\n\n/**\n * @ Author: BetterInternship\n * @ Create Time: 2025-06-14 23:30:09\n * @ Modified time: 2025-10-31 18:13:16\n * @ Description:\n *\n * Stateful dropdown group component.\n */\n\nimport { Button } from \"./button\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport { MobileSheetPortal } from \"./mobile-sheet-portal\";\nimport { cn } from \"@/utils\";\nimport { fieldTriggerClassName } from \"@/hooks/use-field-focus\";\nimport { ChevronDown, X } from \"lucide-react\";\nimport { useRouter } from \"next/navigation\";\nimport React, {\n Children,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\n\n/**\n * The group context interface.\n * What's available in the group context to other components.\n */\ninterface IDropdownGroupContext {\n activeDropdown: string;\n setActiveDropdown: (dropdown: string) => void;\n}\nconst DropdownGroupContext = createContext<IDropdownGroupContext>(\n {} as IDropdownGroupContext,\n);\n\n/**\n * A wrapper around the contents of a dropdown option.\n *\n * @component\n */\ntype IDropdownOptionProps = {\n children?: React.ReactNode;\n highlighted?: boolean;\n disabled?: boolean;\n href?: string;\n on_click?: () => void;\n};\nexport const DropdownOption = ({ children }: IDropdownOptionProps) => {\n return <>{children}</>;\n};\n\n/**\n * Creates a standard button dropdowns must use with mobile optimization.\n * Not meant to be used elsewhere.\n *\n * @component\n */\nconst DropdownOptionButton = ({\n children,\n set_is_open,\n size = \"xs\",\n}: {\n children: React.ReactElement<IDropdownOptionProps>;\n set_is_open: (is_open: boolean) => void;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\";\n}) => {\n const router = useRouter();\n const is_mobile = useMobile();\n const [scrolling, setScrolling] = useState(false);\n const dropdown_button_ref = useRef<HTMLInputElement>({} as HTMLInputElement);\n\n const handleClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n set_is_open(false);\n children.props.on_click && children.props.on_click();\n children.props.href && router.push(children.props.href);\n },\n [children.props, router, set_is_open],\n );\n\n const onTouchStart = (e: any) => {\n e.stopPropagation();\n setScrolling(true);\n };\n\n const onTouchEnd = (e: any) => {\n e.stopPropagation();\n setScrolling(false);\n };\n\n useEffect(() => {\n const dropdown_button = dropdown_button_ref.current;\n if (!dropdown_button) return;\n\n // Attach passive touchstart handler\n dropdown_button.addEventListener(\"touchstart\", onTouchStart, {\n passive: true,\n });\n\n dropdown_button.addEventListener(\"touchend\", onTouchEnd, {\n passive: true,\n });\n\n // Cleanup on unmount\n return () => {\n dropdown_button.removeEventListener(\"touchstart\", onTouchStart);\n dropdown_button.removeEventListener(\"touchend\", onTouchEnd);\n };\n }, [onTouchStart]);\n\n return (\n <button\n // @ts-ignore\n ref={dropdown_button_ref}\n className={cn(\n \"w-full cursor-pointer text-left px-4 py-2 text-muted-foreground hover:bg-muted transition-colors flex items-center gap-2\",\n is_mobile ? \"min-h-12 py-3 active:bg-muted touch-manipulation\" : \"\",\n `text-${size}`,\n children.props.highlighted ? \"bg-primary-tint\" : \"\",\n )}\n onClick={(e) => !scrolling && handleClick(e)}\n >\n <div className=\"w-full\">{children}</div>\n </button>\n );\n};\n\n/**\n * This component creates a context provider for dropdowns inside it to use.\n * The dropdowns inside can modify the active dropdown when they're clicked.\n * This way, only one dropdown in the group is active at a time.\n *\n * @component\n */\nexport const DropdownGroup = ({ children }: { children: React.ReactNode }) => {\n const [activeDropdown, setActiveDropdown] = useState(\"\");\n const group_dropdown_context: IDropdownGroupContext = {\n activeDropdown,\n setActiveDropdown,\n };\n\n return (\n <DropdownGroupContext value={group_dropdown_context}>\n {children}\n </DropdownGroupContext>\n );\n};\n\ninterface IRadioDropdownOption<ID> {\n id: ID;\n name: string;\n}\n\n/**\n * This represents a single dropdown inside the group with mobile optimization.\n * Inherits the provided context (if there is none, that's fine).\n *\n * @component\n */\nexport const GroupableRadioDropdown = <ID extends number | string>({\n name,\n options,\n onChange,\n disabled,\n defaultValue = null,\n size = \"sm\",\n className = \"\",\n fallback = \"Select option\",\n}: {\n name: string;\n options: IRadioDropdownOption<ID>[];\n onChange: (option: ID) => void;\n defaultValue?: ID | ID[] | null;\n disabled?: boolean | undefined;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\";\n className?: string;\n fallback?: string;\n}) => {\n const isMobile = useMobile();\n const { activeDropdown, setActiveDropdown } =\n useContext(DropdownGroupContext);\n const [isOpen, setIsOpen] = useState(false);\n const sheetViewport = useMobileSheetViewport(isOpen && isMobile);\n const [value, setValue] = useState(defaultValue);\n const ref = useDetectClickOutside({ onTriggered: () => setIsOpen(false) });\n const triggerRef = useRef<HTMLButtonElement>(null);\n const sheetRef = useRef<HTMLDivElement>(null);\n const sheetCloseRef = useRef<HTMLButtonElement>(null);\n const useSheet = isOpen && isMobile;\n\n const closeSheet = useCallback(() => {\n setIsOpen(false);\n triggerRef.current?.focus();\n }, []);\n\n // While the mobile sheet is open: lock page scroll and move focus into it.\n useEffect(() => {\n if (!useSheet) return;\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n const frame = window.requestAnimationFrame(() =>\n sheetCloseRef.current?.focus(),\n );\n return () => {\n window.cancelAnimationFrame(frame);\n document.body.style.overflow = overflow;\n };\n }, [useSheet]);\n\n // Just so it's not stuck at the first default when the default changes\n useEffect(() => {\n setValue(defaultValue);\n }, [defaultValue]);\n\n /**\n * Activates dropdown\n */\n const handleClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n setIsOpen(!isOpen);\n setActiveDropdown(name);\n },\n [isOpen, name, setActiveDropdown],\n );\n\n /**\n * Changes dropdown value\n */\n const handleChange = useCallback(\n (option: ID) => {\n setValue(option);\n onChange(option);\n setIsOpen(false);\n },\n [onChange],\n );\n\n // Check if it's still the active dropdown\n useEffect(() => {\n if (activeDropdown !== name) setIsOpen(false);\n }, [activeDropdown, name]);\n\n const selected =\n value || value === 0 ? options.find((o) => o.id === value) : undefined;\n\n return (\n <div\n className={cn(\"relative w-full max-w-svw min-w-0\", className)}\n ref={ref}\n >\n <Button\n ref={triggerRef}\n type=\"button\"\n variant=\"outline\"\n disabled={disabled}\n size={size}\n onClick={handleClick}\n onTouchEnd={(e) => e.stopPropagation()}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n className={cn(\n \"w-full max-w-full min-w-0\",\n \"h-auto py-1\",\n fieldTriggerClassName,\n \"flex items-center justify-between gap-2\",\n )}\n >\n {/* shrinkable text container */}\n <span className=\"flex-1 min-w-0 text-left pr-2 leading-relaxed\">\n {selected ? (\n <span className=\"block whitespace-normal wrap-break-word\">\n {selected.name}\n </span>\n ) : (\n <span className=\"text-muted-foreground/40 font-normal\">\n {fallback}\n </span>\n )}\n </span>\n\n <ChevronDown\n className={cn(\n \"shrink-0 w-4 h-4 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen ? \"rotate-180\" : \"\",\n )}\n />\n </Button>\n\n {isOpen && (\n <MobileSheetPortal enabled={isMobile}>\n {isMobile && (\n <button\n type=\"button\"\n aria-label=\"Close options\"\n tabIndex={-1}\n className=\"fixed inset-0 z-[1090] bg-black/25 backdrop-blur-[1px]\"\n onClick={closeSheet}\n />\n )}\n <div\n ref={isMobile ? sheetRef : undefined}\n role={isMobile ? \"dialog\" : undefined}\n aria-modal={isMobile ? true : undefined}\n aria-label={isMobile ? fallback : undefined}\n onKeyDown={\n isMobile\n ? (event) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeSheet();\n }\n if (event.key !== \"Tab\") return;\n const focusable =\n sheetRef.current?.querySelectorAll<HTMLElement>(\n \"button:not([disabled]):not([tabindex='-1'])\",\n );\n if (!focusable?.length) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (\n !event.shiftKey &&\n document.activeElement === last\n ) {\n event.preventDefault();\n first.focus();\n }\n }\n : undefined\n }\n className={cn(\n \"border border-border bg-background shadow-card\",\n isMobile\n ? \"fixed left-0 right-0 z-[1100] flex flex-col overflow-hidden rounded-t-control-lg border-b-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n : \"absolute left-0 right-0 top-full z-[9999] mt-1 max-w-full overflow-hidden rounded-control-lg\",\n )}\n style={\n isMobile\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport\n ? Math.min(sheetViewport.height, 640)\n : \"80dvh\",\n }\n : undefined\n }\n >\n {isMobile && (\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-2 pt-4\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {fallback}\n </h2>\n <button\n ref={sheetCloseRef}\n type=\"button\"\n aria-label=\"Close options\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={closeSheet}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n )}\n <div\n role=\"listbox\"\n className={cn(\n \"relative overflow-y-auto overscroll-contain touch-pan-y [-webkit-overflow-scrolling:touch] [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]\",\n isMobile ? \"min-h-0 flex-1\" : \"max-h-[400px]\",\n )}\n >\n {options.map((option, index) => (\n <DropdownOptionButton\n key={index}\n set_is_open={setIsOpen}\n size={size}\n >\n <DropdownOption\n highlighted={value === option.id}\n on_click={() => handleChange(option.id)}\n >\n <span className=\"block whitespace-normal wrap-break-word pr-2\">\n {option.name}\n </span>\n </DropdownOption>\n </DropdownOptionButton>\n ))}\n </div>\n </div>\n </MobileSheetPortal>\n )}\n </div>\n );\n};\n\n/**\n * This creates a dropdown menu for navigating with improved mobile support.\n *\n * @component\n */\nexport const GroupableNavDropdown = ({\n display,\n content,\n children,\n className = \"\",\n showArrow = true,\n}: {\n display?: React.ReactNode;\n content?: React.ReactNode;\n children?:\n | React.ReactElement<IDropdownOptionProps>\n | React.ReactElement<IDropdownOptionProps>[];\n className?: string;\n showArrow?: boolean;\n}) => {\n const is_mobile = useMobile();\n const [is_open, set_is_open] = useState(false);\n const dropdownRef = useRef<HTMLDivElement>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const touchStartRef = useRef<{\n x: number;\n y: number;\n target: EventTarget | null;\n } | null>(null);\n\n // Close dropdown handler\n const closeDropdown = useCallback(() => {\n set_is_open(false);\n }, []);\n\n // Handle clicks outside dropdown\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (\n !is_mobile &&\n dropdownRef.current &&\n !dropdownRef.current.contains(event.target as Node) &&\n buttonRef.current &&\n !buttonRef.current.contains(event.target as Node)\n ) {\n closeDropdown();\n }\n };\n\n if (is_open && !is_mobile) {\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () =>\n document.removeEventListener(\"mousedown\", handleClickOutside);\n }\n }, [is_open, is_mobile, closeDropdown]);\n\n // Mobile touch handlers\n const handleTouchStart = useCallback(\n (e: TouchEvent) => {\n if (!is_mobile || !is_open) return;\n\n const touch = e.touches[0];\n touchStartRef.current = {\n x: touch.clientX,\n y: touch.clientY,\n target: e.target,\n };\n },\n [is_mobile, is_open],\n );\n\n const handleTouchEnd = useCallback(\n (e: TouchEvent) => {\n if (!is_mobile || !is_open || !touchStartRef.current) return;\n\n const touch = e.changedTouches[0];\n const startTouch = touchStartRef.current;\n\n // Calculate touch movement\n const deltaX = Math.abs(touch.clientX - startTouch.x);\n const deltaY = Math.abs(touch.clientY - startTouch.y);\n const isSwipe = deltaX > 10 || deltaY > 10;\n\n // Check if touch is outside dropdown area\n const target = e.target as Element;\n const isOutsideDropdown =\n dropdownRef.current &&\n !dropdownRef.current.contains(target) &&\n buttonRef.current &&\n !buttonRef.current.contains(target);\n\n // Close if touch ended outside and wasn't a swipe\n if (!isSwipe && isOutsideDropdown) {\n closeDropdown();\n }\n\n touchStartRef.current = null;\n },\n [is_mobile, is_open, closeDropdown],\n );\n\n // Set up mobile touch listeners\n useEffect(() => {\n if (is_mobile && is_open) {\n document.addEventListener(\"touchstart\", handleTouchStart);\n document.addEventListener(\"touchend\", handleTouchEnd);\n\n return () => {\n document.removeEventListener(\"touchstart\", handleTouchStart);\n document.removeEventListener(\"touchend\", handleTouchEnd);\n };\n }\n }, [is_mobile, is_open, handleTouchStart, handleTouchEnd]);\n\n // Prevent event propagation for dropdown content\n const handleDropdownInteraction = useCallback(\n (e: React.MouseEvent | React.TouchEvent) => {\n e.stopPropagation();\n },\n [],\n );\n\n // Toggle dropdown\n const handleButtonClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n set_is_open(!is_open);\n },\n [is_open],\n );\n\n return (\n <div className={cn(\"relative z-[100]\", className)} ref={dropdownRef}>\n <Button\n ref={buttonRef}\n type=\"button\"\n variant=\"ghost\"\n className=\"relative flex items-center gap-2 h-12 px-3 z-[1000]\"\n onClick={handleButtonClick}\n onTouchEnd={(e) => e.stopPropagation()}\n >\n {display}\n {showArrow && (\n <ChevronDown\n className={cn(\n \"w-4 h-4 text-muted-foreground transition-transform\",\n is_open ? \"rotate-180\" : \"\",\n )}\n />\n )}\n </Button>\n\n {is_open && (\n <div\n className={cn(\n \"absolute right-0 mt-2 bg-background border border-border rounded-control-lg overflow-hidden shadow-card z-[1000]\",\n is_mobile ? \"w-56\" : \"w-48\", // Slightly wider on mobile for better touch targets\n className,\n )}\n onClick={handleDropdownInteraction}\n onTouchStart={handleDropdownInteraction}\n onTouchEnd={handleDropdownInteraction}\n >\n <div\n className={cn(\n \"relative z-[1000] max-h-64 overflow-y-auto overscroll-contain [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]\",\n is_mobile ? \"max-h-80\" : \"max-h-64\",\n )}\n >\n {content}\n\n {Children.map(children, (child, index) => {\n return (\n <DropdownOptionButton key={index} set_is_open={set_is_open}>\n {child ? child : <></>}\n </DropdownOptionButton>\n );\n })}\n </div>\n </div>\n )}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAsCA;;;AAkBA;AAEA;;;;;AAKG;AACH;AASE;AACA;;AAEA;AAEA;;;;AAKI;;AAKJ;;;AAGA;AAEA;;;AAGA;;AAGE;AACA;;;AAGA;AACE;AACD;AAED;AACE;AACD;;AAGD;AACE;AACA;AACF;AACF;AAEA;;AAGI;AAYN;AAEA;;;;;;AAMG;;;AAGD;;;;;AAUF;AAOA;;;;;AAKG;AACI;AAmBL;;;;;AAMA;AACA;AACA;AACA;AACA;AAEA;;AAEE;;;;AAKA;;;;AAGA;AAGA;AACE;;AAEF;AACF;;;;AAKA;AAEA;;AAEG;AACH;;AAGI;;;AAMJ;;AAEG;AACH;;;;AAKE;;;;;AAOF;AAEA;;AAgEc;AACI;;AAEE;;AAEF;;;;;AAMA;;;;;;;AAOE;;;;;;AAWN;AACA;AAIA;AACI;AACA;;AAEE;AACH;AACH;AAgDhB;AAEA;;;;AAIG;;AAgBD;;AAEA;AACA;AACA;;AAOA;;;;;AAME;AACE;AAEE;;AAEA;;AAGA;;AAEJ;AAEA;AACE;;;;;AAOJ;AAEI;;;;;;;;AAQF;AAIF;;;;AAKI;;AAGA;AACA;;;AAIA;AACA;AAEE;AACA;;;AAIF;AACE;;AAGF;;;;AAOF;AACE;AACA;AAEA;AACE;AACA;AACF;;;;AAKJ;;;;AAQA;;AAGI;AACF;;;;AAkDQ;AAMZ;;"}
|
|
1
|
+
{"version":3,"file":"dropdown.js","sources":["../../src/components/dropdown.tsx"],"sourcesContent":["'use client';\n\n/**\n * @ Author: BetterInternship\n * @ Create Time: 2025-06-14 23:30:09\n * @ Modified time: 2025-10-31 18:13:16\n * @ Description:\n *\n * Stateful dropdown group component.\n */\n\nimport { Button } from \"./button\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport { MobileSheetPortal } from \"./mobile-sheet-portal\";\nimport { cn } from \"@/utils\";\nimport { fieldTriggerClassName } from \"@/hooks/use-field-focus\";\nimport { ChevronDown, X } from \"lucide-react\";\nimport { useRouter } from \"next/navigation\";\nimport React, {\n Children,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\n\n/**\n * The group context interface.\n * What's available in the group context to other components.\n */\ninterface IDropdownGroupContext {\n activeDropdown: string;\n setActiveDropdown: (dropdown: string) => void;\n}\nconst DropdownGroupContext = createContext<IDropdownGroupContext>(\n {} as IDropdownGroupContext,\n);\n\n/**\n * A wrapper around the contents of a dropdown option.\n *\n * @component\n */\ntype IDropdownOptionProps = {\n children?: React.ReactNode;\n highlighted?: boolean;\n disabled?: boolean;\n href?: string;\n on_click?: () => void;\n};\nexport const DropdownOption = ({ children }: IDropdownOptionProps) => {\n return <>{children}</>;\n};\n\n/**\n * Creates a standard button dropdowns must use with mobile optimization.\n * Not meant to be used elsewhere.\n *\n * @component\n */\nconst DropdownOptionButton = ({\n children,\n set_is_open,\n size = \"xs\",\n}: {\n children: React.ReactElement<IDropdownOptionProps>;\n set_is_open: (is_open: boolean) => void;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\";\n}) => {\n const router = useRouter();\n const is_mobile = useMobile();\n const [scrolling, setScrolling] = useState(false);\n const dropdown_button_ref = useRef<HTMLInputElement>({} as HTMLInputElement);\n\n const handleClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n set_is_open(false);\n children.props.on_click && children.props.on_click();\n children.props.href && router.push(children.props.href);\n },\n [children.props, router, set_is_open],\n );\n\n const onTouchStart = (e: any) => {\n e.stopPropagation();\n setScrolling(true);\n };\n\n const onTouchEnd = (e: any) => {\n e.stopPropagation();\n setScrolling(false);\n };\n\n useEffect(() => {\n const dropdown_button = dropdown_button_ref.current;\n if (!dropdown_button) return;\n\n // Attach passive touchstart handler\n dropdown_button.addEventListener(\"touchstart\", onTouchStart, {\n passive: true,\n });\n\n dropdown_button.addEventListener(\"touchend\", onTouchEnd, {\n passive: true,\n });\n\n // Cleanup on unmount\n return () => {\n dropdown_button.removeEventListener(\"touchstart\", onTouchStart);\n dropdown_button.removeEventListener(\"touchend\", onTouchEnd);\n };\n }, [onTouchStart]);\n\n return (\n <button\n // @ts-ignore\n ref={dropdown_button_ref}\n className={cn(\n \"flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-muted-foreground transition-colors hover:bg-muted\",\n is_mobile ? \"min-h-12 py-3 active:bg-muted touch-manipulation\" : \"\",\n `text-${size}`,\n children.props.highlighted ? \"bg-primary-tint\" : \"\",\n )}\n onClick={(e) => !scrolling && handleClick(e)}\n >\n <div className=\"w-full\">{children}</div>\n </button>\n );\n};\n\n/**\n * This component creates a context provider for dropdowns inside it to use.\n * The dropdowns inside can modify the active dropdown when they're clicked.\n * This way, only one dropdown in the group is active at a time.\n *\n * @component\n */\nexport const DropdownGroup = ({ children }: { children: React.ReactNode }) => {\n const [activeDropdown, setActiveDropdown] = useState(\"\");\n const group_dropdown_context: IDropdownGroupContext = {\n activeDropdown,\n setActiveDropdown,\n };\n\n return (\n <DropdownGroupContext value={group_dropdown_context}>\n {children}\n </DropdownGroupContext>\n );\n};\n\ninterface IRadioDropdownOption<ID> {\n id: ID;\n name: string;\n}\n\n/**\n * This represents a single dropdown inside the group with mobile optimization.\n * Inherits the provided context (if there is none, that's fine).\n *\n * @component\n */\nexport const GroupableRadioDropdown = <ID extends number | string>({\n name,\n options,\n onChange,\n disabled,\n defaultValue = null,\n size = \"sm\",\n className = \"\",\n fallback = \"Select option\",\n}: {\n name: string;\n options: IRadioDropdownOption<ID>[];\n onChange: (option: ID) => void;\n defaultValue?: ID | ID[] | null;\n disabled?: boolean | undefined;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\";\n className?: string;\n fallback?: string;\n}) => {\n const isMobile = useMobile();\n const { activeDropdown, setActiveDropdown } =\n useContext(DropdownGroupContext);\n const [isOpen, setIsOpen] = useState(false);\n const sheetViewport = useMobileSheetViewport(isOpen && isMobile);\n const [value, setValue] = useState(defaultValue);\n const ref = useDetectClickOutside({ onTriggered: () => setIsOpen(false) });\n const triggerRef = useRef<HTMLButtonElement>(null);\n const sheetRef = useRef<HTMLDivElement>(null);\n const sheetCloseRef = useRef<HTMLButtonElement>(null);\n const useSheet = isOpen && isMobile;\n\n const closeSheet = useCallback(() => {\n setIsOpen(false);\n triggerRef.current?.focus();\n }, []);\n\n // While the mobile sheet is open: lock page scroll and move focus into it.\n useEffect(() => {\n if (!useSheet) return;\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n const frame = window.requestAnimationFrame(() =>\n sheetCloseRef.current?.focus(),\n );\n return () => {\n window.cancelAnimationFrame(frame);\n document.body.style.overflow = overflow;\n };\n }, [useSheet]);\n\n // Just so it's not stuck at the first default when the default changes\n useEffect(() => {\n setValue(defaultValue);\n }, [defaultValue]);\n\n /**\n * Activates dropdown\n */\n const handleClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n setIsOpen(!isOpen);\n setActiveDropdown(name);\n },\n [isOpen, name, setActiveDropdown],\n );\n\n /**\n * Changes dropdown value\n */\n const handleChange = useCallback(\n (option: ID) => {\n setValue(option);\n onChange(option);\n setIsOpen(false);\n },\n [onChange],\n );\n\n // Check if it's still the active dropdown\n useEffect(() => {\n if (activeDropdown !== name) setIsOpen(false);\n }, [activeDropdown, name]);\n\n const selected =\n value || value === 0 ? options.find((o) => o.id === value) : undefined;\n\n return (\n <div\n className={cn(\"relative w-full max-w-svw min-w-0\", className)}\n ref={ref}\n >\n <Button\n ref={triggerRef}\n type=\"button\"\n variant=\"outline\"\n disabled={disabled}\n size={size}\n onClick={handleClick}\n onTouchEnd={(e) => e.stopPropagation()}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n className={cn(\n \"w-full max-w-full min-w-0\",\n \"h-auto py-1\",\n fieldTriggerClassName,\n \"flex items-center justify-between gap-2\",\n )}\n >\n {/* shrinkable text container */}\n <span className=\"flex-1 min-w-0 text-left pr-2 leading-relaxed\">\n {selected ? (\n <span className=\"block whitespace-normal wrap-break-word\">\n {selected.name}\n </span>\n ) : (\n <span className=\"text-muted-foreground/40 font-normal\">\n {fallback}\n </span>\n )}\n </span>\n\n <ChevronDown\n className={cn(\n \"shrink-0 w-4 h-4 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen ? \"rotate-180\" : \"\",\n )}\n />\n </Button>\n\n {isOpen && (\n <MobileSheetPortal enabled={isMobile}>\n {isMobile && (\n <button\n type=\"button\"\n aria-label=\"Close options\"\n tabIndex={-1}\n className=\"fixed inset-0 z-[1090] bg-black/25 backdrop-blur-[1px]\"\n onClick={closeSheet}\n />\n )}\n <div\n ref={isMobile ? sheetRef : undefined}\n role={isMobile ? \"dialog\" : undefined}\n aria-modal={isMobile ? true : undefined}\n aria-label={isMobile ? fallback : undefined}\n onKeyDown={\n isMobile\n ? (event) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeSheet();\n }\n if (event.key !== \"Tab\") return;\n const focusable =\n sheetRef.current?.querySelectorAll<HTMLElement>(\n \"button:not([disabled]):not([tabindex='-1'])\",\n );\n if (!focusable?.length) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (\n !event.shiftKey &&\n document.activeElement === last\n ) {\n event.preventDefault();\n first.focus();\n }\n }\n : undefined\n }\n className={cn(\n \"border border-border bg-background shadow-card\",\n isMobile\n ? \"fixed left-0 right-0 z-[1100] flex flex-col overflow-hidden rounded-t-control-lg border-b-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n : \"absolute left-0 right-0 top-full z-[9999] mt-1 max-w-full overflow-hidden rounded-control-lg\",\n )}\n style={\n isMobile\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport\n ? Math.min(sheetViewport.height, 640)\n : \"80dvh\",\n }\n : undefined\n }\n >\n {isMobile && (\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-2 pt-4\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {fallback}\n </h2>\n <button\n ref={sheetCloseRef}\n type=\"button\"\n aria-label=\"Close options\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={closeSheet}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n )}\n <div\n role=\"listbox\"\n className={cn(\n \"relative flex flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset touch-pan-y [-webkit-overflow-scrolling:touch] [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]\",\n isMobile ? \"min-h-0 flex-1\" : \"max-h-[400px]\",\n )}\n >\n {options.map((option, index) => (\n <DropdownOptionButton\n key={index}\n set_is_open={setIsOpen}\n size={size}\n >\n <DropdownOption\n highlighted={value === option.id}\n on_click={() => handleChange(option.id)}\n >\n <span className=\"block whitespace-normal wrap-break-word pr-2\">\n {option.name}\n </span>\n </DropdownOption>\n </DropdownOptionButton>\n ))}\n </div>\n </div>\n </MobileSheetPortal>\n )}\n </div>\n );\n};\n\n/**\n * This creates a dropdown menu for navigating with improved mobile support.\n *\n * @component\n */\nexport const GroupableNavDropdown = ({\n display,\n content,\n children,\n className = \"\",\n showArrow = true,\n}: {\n display?: React.ReactNode;\n content?: React.ReactNode;\n children?:\n | React.ReactElement<IDropdownOptionProps>\n | React.ReactElement<IDropdownOptionProps>[];\n className?: string;\n showArrow?: boolean;\n}) => {\n const is_mobile = useMobile();\n const [is_open, set_is_open] = useState(false);\n const dropdownRef = useRef<HTMLDivElement>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const touchStartRef = useRef<{\n x: number;\n y: number;\n target: EventTarget | null;\n } | null>(null);\n\n // Close dropdown handler\n const closeDropdown = useCallback(() => {\n set_is_open(false);\n }, []);\n\n // Handle clicks outside dropdown\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (\n !is_mobile &&\n dropdownRef.current &&\n !dropdownRef.current.contains(event.target as Node) &&\n buttonRef.current &&\n !buttonRef.current.contains(event.target as Node)\n ) {\n closeDropdown();\n }\n };\n\n if (is_open && !is_mobile) {\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () =>\n document.removeEventListener(\"mousedown\", handleClickOutside);\n }\n }, [is_open, is_mobile, closeDropdown]);\n\n // Mobile touch handlers\n const handleTouchStart = useCallback(\n (e: TouchEvent) => {\n if (!is_mobile || !is_open) return;\n\n const touch = e.touches[0];\n touchStartRef.current = {\n x: touch.clientX,\n y: touch.clientY,\n target: e.target,\n };\n },\n [is_mobile, is_open],\n );\n\n const handleTouchEnd = useCallback(\n (e: TouchEvent) => {\n if (!is_mobile || !is_open || !touchStartRef.current) return;\n\n const touch = e.changedTouches[0];\n const startTouch = touchStartRef.current;\n\n // Calculate touch movement\n const deltaX = Math.abs(touch.clientX - startTouch.x);\n const deltaY = Math.abs(touch.clientY - startTouch.y);\n const isSwipe = deltaX > 10 || deltaY > 10;\n\n // Check if touch is outside dropdown area\n const target = e.target as Element;\n const isOutsideDropdown =\n dropdownRef.current &&\n !dropdownRef.current.contains(target) &&\n buttonRef.current &&\n !buttonRef.current.contains(target);\n\n // Close if touch ended outside and wasn't a swipe\n if (!isSwipe && isOutsideDropdown) {\n closeDropdown();\n }\n\n touchStartRef.current = null;\n },\n [is_mobile, is_open, closeDropdown],\n );\n\n // Set up mobile touch listeners\n useEffect(() => {\n if (is_mobile && is_open) {\n document.addEventListener(\"touchstart\", handleTouchStart);\n document.addEventListener(\"touchend\", handleTouchEnd);\n\n return () => {\n document.removeEventListener(\"touchstart\", handleTouchStart);\n document.removeEventListener(\"touchend\", handleTouchEnd);\n };\n }\n }, [is_mobile, is_open, handleTouchStart, handleTouchEnd]);\n\n // Prevent event propagation for dropdown content\n const handleDropdownInteraction = useCallback(\n (e: React.MouseEvent | React.TouchEvent) => {\n e.stopPropagation();\n },\n [],\n );\n\n // Toggle dropdown\n const handleButtonClick = useCallback(\n (e: React.MouseEvent) => {\n e.stopPropagation();\n set_is_open(!is_open);\n },\n [is_open],\n );\n\n return (\n <div className={cn(\"relative z-[100]\", className)} ref={dropdownRef}>\n <Button\n ref={buttonRef}\n type=\"button\"\n variant=\"ghost\"\n className=\"relative flex items-center gap-2 h-12 px-3 z-[1000]\"\n onClick={handleButtonClick}\n onTouchEnd={(e) => e.stopPropagation()}\n >\n {display}\n {showArrow && (\n <ChevronDown\n className={cn(\n \"w-4 h-4 text-muted-foreground transition-transform\",\n is_open ? \"rotate-180\" : \"\",\n )}\n />\n )}\n </Button>\n\n {is_open && (\n <div\n className={cn(\n \"absolute right-0 mt-2 bg-background border border-border rounded-control-lg overflow-hidden shadow-card z-[1000]\",\n is_mobile ? \"w-56\" : \"w-48\", // Slightly wider on mobile for better touch targets\n className,\n )}\n onClick={handleDropdownInteraction}\n onTouchStart={handleDropdownInteraction}\n onTouchEnd={handleDropdownInteraction}\n >\n <div\n className={cn(\n \"relative z-[1000] flex max-h-64 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset [scrollbar-width:thin] [scrollbar-color:var(--color-border-hover)_var(--muted)]\",\n is_mobile ? \"max-h-80\" : \"max-h-64\",\n )}\n >\n {content}\n\n {Children.map(children, (child, index) => {\n return (\n <DropdownOptionButton key={index} set_is_open={set_is_open}>\n {child ? child : <></>}\n </DropdownOptionButton>\n );\n })}\n </div>\n </div>\n )}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAsCA;;;AAkBA;AAEA;;;;;AAKG;AACH;AASE;AACA;;AAEA;AAEA;;;;AAKI;;AAKJ;;;AAGA;AAEA;;;AAGA;;AAGE;AACA;;;AAGA;AACE;AACD;AAED;AACE;AACD;;AAGD;AACE;AACA;AACF;AACF;AAEA;;AAGI;AAYN;AAEA;;;;;;AAMG;;;AAGD;;;;;AAUF;AAOA;;;;;AAKG;AACI;AAmBL;;;;;AAMA;AACA;AACA;AACA;AACA;AAEA;;AAEE;;;;AAKA;;;;AAGA;AAGA;AACE;;AAEF;AACF;;;;AAKA;AAEA;;AAEG;AACH;;AAGI;;;AAMJ;;AAEG;AACH;;;;AAKE;;;;;AAOF;AAEA;;AAgEc;AACI;;AAEE;;AAEF;;;;;AAMA;;;;;;;AAOE;;;;;;AAWN;AACA;AAIA;AACI;AACA;;AAEE;AACH;AACH;AAgDhB;AAEA;;;;AAIG;;AAgBD;;AAEA;AACA;AACA;;AAOA;;;;;AAME;AACE;AAEE;;AAEA;;AAGA;;AAEJ;AAEA;AACE;;;;;AAOJ;AAEI;;;;;;;;AAQF;AAIF;;;;AAKI;;AAGA;AACA;;;AAIA;AACA;AAEE;AACA;;;AAIF;AACE;;AAGF;;;;AAOF;AACE;AACA;AAEA;AACE;AACA;AACF;;;;AAKJ;;;;AAQA;;AAGI;AACF;;;;AAkDQ;AAMZ;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** Padding + row gap for a list of options inside a popover or sheet. */
|
|
3
|
+
export declare const optionListClassName = "flex flex-col gap-option-gap p-option-inset";
|
|
4
|
+
/** One option row. Pair with a hover/focus or selected state as needed. */
|
|
5
|
+
export declare const optionRowClassName = "relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11";
|
|
6
|
+
export type CheckboxListItem = {
|
|
7
|
+
label: React.ReactNode;
|
|
8
|
+
checked: boolean;
|
|
9
|
+
onCheckedChange: (checked: boolean) => void;
|
|
10
|
+
/** Indents the row under a group heading row. */
|
|
11
|
+
indent?: boolean;
|
|
12
|
+
/** Bolder label, e.g. a group's "All …" row. */
|
|
13
|
+
strong?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** A list of checkbox rows in the shared option style. */
|
|
17
|
+
export declare function CheckboxList({ items, className, "aria-label": label, }: {
|
|
18
|
+
items: CheckboxListItem[];
|
|
19
|
+
className?: string;
|
|
20
|
+
"aria-label"?: string;
|
|
21
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export type FilterMenuOption = {
|
|
23
|
+
label: React.ReactNode;
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A filter chip that opens a checklist: each tick applies immediately, and
|
|
28
|
+
* the chip shows how many are on (in the selected, secondary style).
|
|
29
|
+
*/
|
|
30
|
+
export declare function FilterMenu({ label, options, value, onValueChange, size, align, className, contentClassName, }: {
|
|
31
|
+
label: React.ReactNode;
|
|
32
|
+
options: FilterMenuOption[];
|
|
33
|
+
/** The selected option values. */
|
|
34
|
+
value: string[];
|
|
35
|
+
onValueChange: (value: string[]) => void;
|
|
36
|
+
size?: "xs" | "sm" | "md";
|
|
37
|
+
align?: "start" | "center" | "end";
|
|
38
|
+
className?: string;
|
|
39
|
+
contentClassName?: string;
|
|
40
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
import { Checkbox } from './checkbox.js';
|
|
6
|
+
import { FilterChip } from './filter-chip.js';
|
|
7
|
+
import { Popover, PopoverTrigger, PopoverContent } from './popover.js';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* The shared look for every list of options (menus, selects, dropdowns,
|
|
11
|
+
* autocomplete, filter menus): the list is inset from its container's edge,
|
|
12
|
+
* and each row is its own rounded box with a little space between rows, so
|
|
13
|
+
* hover and selection read as distinct pills rather than full-bleed stripes.
|
|
14
|
+
*/
|
|
15
|
+
/** Padding + row gap for a list of options inside a popover or sheet. */
|
|
16
|
+
const optionListClassName = "flex flex-col gap-option-gap p-option-inset";
|
|
17
|
+
/** One option row. Pair with a hover/focus or selected state as needed. */
|
|
18
|
+
const optionRowClassName = "relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11";
|
|
19
|
+
/** A list of checkbox rows in the shared option style. */
|
|
20
|
+
function CheckboxList({ items, className, "aria-label": label, }) {
|
|
21
|
+
return (jsx("ul", { "aria-label": label, className: cn("m-0 list-none", optionListClassName, className), children: items.map((item, index) => (jsx("li", { children: jsxs("label", { className: cn(optionRowClassName, item.indent && "pl-8", item.strong && "font-medium", item.disabled && "pointer-events-none opacity-50"), children: [jsx(Checkbox, { checked: item.checked, disabled: item.disabled, onCheckedChange: (checked) => item.onCheckedChange(checked === true) }), jsx("span", { className: "min-w-0 flex-1", children: item.label })] }) }, index))) }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A filter chip that opens a checklist: each tick applies immediately, and
|
|
25
|
+
* the chip shows how many are on (in the selected, secondary style).
|
|
26
|
+
*/
|
|
27
|
+
function FilterMenu({ label, options, value, onValueChange, size = "sm", align = "start", className, contentClassName, }) {
|
|
28
|
+
const count = value.length;
|
|
29
|
+
return (jsxs(Popover, { children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(FilterChip, { size: size, selected: count > 0, count: count || undefined, className: className, children: [label, jsx(ChevronDown, { size: 14, "aria-hidden": "true", className: "-mr-1" })] }) }), jsx(PopoverContent, { align: align, className: cn("w-56 p-0", contentClassName), children: jsx(CheckboxList, { "aria-label": typeof label === "string" ? label : undefined, items: options.map((option) => ({
|
|
30
|
+
label: option.label,
|
|
31
|
+
checked: value.includes(option.value),
|
|
32
|
+
onCheckedChange: (on) => onValueChange(on
|
|
33
|
+
? [...value, option.value]
|
|
34
|
+
: value.filter((item) => item !== option.value)),
|
|
35
|
+
})) }) })] }));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { CheckboxList, FilterMenu, optionListClassName, optionRowClassName };
|
|
39
|
+
//# sourceMappingURL=option-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-list.js","sources":["../../src/components/option-list.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\n\n/*\n * The shared look for every list of options (menus, selects, dropdowns,\n * autocomplete, filter menus): the list is inset from its container's edge,\n * and each row is its own rounded box with a little space between rows, so\n * hover and selection read as distinct pills rather than full-bleed stripes.\n */\n\n/** Padding + row gap for a list of options inside a popover or sheet. */\nexport const optionListClassName = \"flex flex-col gap-option-gap p-option-inset\";\n\n/** One option row. Pair with a hover/focus or selected state as needed. */\nexport const optionRowClassName =\n \"relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11\";\n\nexport type CheckboxListItem = {\n label: React.ReactNode;\n checked: boolean;\n onCheckedChange: (checked: boolean) => void;\n /** Indents the row under a group heading row. */\n indent?: boolean;\n /** Bolder label, e.g. a group's \"All …\" row. */\n strong?: boolean;\n disabled?: boolean;\n};\n\n/** A list of checkbox rows in the shared option style. */\nexport function CheckboxList({\n items,\n className,\n \"aria-label\": label,\n}: {\n items: CheckboxListItem[];\n className?: string;\n \"aria-label\"?: string;\n}) {\n return (\n <ul\n aria-label={label}\n className={cn(\"m-0 list-none\", optionListClassName, className)}\n >\n {items.map((item, index) => (\n <li key={index}>\n <label\n className={cn(\n optionRowClassName,\n item.indent && \"pl-8\",\n item.strong && \"font-medium\",\n item.disabled && \"pointer-events-none opacity-50\",\n )}\n >\n <Checkbox\n checked={item.checked}\n disabled={item.disabled}\n onCheckedChange={(checked) =>\n item.onCheckedChange(checked === true)\n }\n />\n <span className=\"min-w-0 flex-1\">{item.label}</span>\n </label>\n </li>\n ))}\n </ul>\n );\n}\n\nexport type FilterMenuOption = { label: React.ReactNode; value: string };\n\n/**\n * A filter chip that opens a checklist: each tick applies immediately, and\n * the chip shows how many are on (in the selected, secondary style).\n */\nexport function FilterMenu({\n label,\n options,\n value,\n onValueChange,\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n}: {\n label: React.ReactNode;\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n}) {\n const count = value.length;\n return (\n <Popover>\n <PopoverTrigger asChild>\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n </PopoverTrigger>\n <PopoverContent\n align={align}\n className={cn(\"w-56 p-0\", contentClassName)}\n >\n <CheckboxList\n aria-label={typeof label === \"string\" ? label : undefined}\n items={options.map((option) => ({\n label: option.label,\n checked: value.includes(option.value),\n onCheckedChange: (on) =>\n onValueChange(\n on\n ? [...value, option.value]\n : value.filter((item) => item !== option.value),\n ),\n }))}\n />\n </PopoverContent>\n </Popover>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAUA;;;;;AAKG;AAEH;AACO;AAEP;AACO;AAcP;AACM;;AAqCN;AAIA;;;AAGG;AACG;AAoBJ;;;;;;AA2BgB;AAEP;AAKX;;"}
|
|
@@ -37,12 +37,12 @@ const SelectContent = React.forwardRef(({ className, children, position = 'poppe
|
|
|
37
37
|
: 'z-50 max-h-[400px] min-w-[8rem] rounded-control-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95', className), position: mobile ? 'popper' : position, sideOffset: 4, style: {
|
|
38
38
|
...(mobile ? { maxHeight: viewport ? Math.min(viewport.height, 640) : '80dvh' } : {}),
|
|
39
39
|
...style,
|
|
40
|
-
}, ...props, children: [mobile && (jsxs("div", { role: "presentation", className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4", children: [jsx("h2", { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onPointerDown: (event) => event.stopPropagation(), onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] })), !mobile && jsx(SelectScrollUpButton, {}), jsx(SelectPrimitive.Viewport, { className: cn('min-h-0 overflow-y-auto overscroll-contain', mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]'), children: children }), !mobile && jsx(SelectScrollDownButton, {})] })] }) }));
|
|
40
|
+
}, ...props, children: [mobile && (jsxs("div", { role: "presentation", className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4", children: [jsx("h2", { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onPointerDown: (event) => event.stopPropagation(), onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] })), !mobile && jsx(SelectScrollUpButton, {}), jsx(SelectPrimitive.Viewport, { className: cn('flex min-h-0 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset', mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]'), children: children }), !mobile && jsx(SelectScrollDownButton, {})] })] }) }));
|
|
41
41
|
});
|
|
42
42
|
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
43
|
-
const SelectLabel = React.forwardRef(({ className, ...props }, ref) => (jsx(SelectPrimitive.Label, { ref: ref, className: cn('
|
|
43
|
+
const SelectLabel = React.forwardRef(({ className, ...props }, ref) => (jsx(SelectPrimitive.Label, { ref: ref, className: cn('px-option-x py-2 text-sm font-semibold text-foreground', className), ...props })));
|
|
44
44
|
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
45
|
-
const SelectItem = React.forwardRef(({ className, children, ...props }, ref) => (jsxs(SelectPrimitive.Item, { ref: ref, className: cn('relative flex w-full cursor-pointer items-center gap-2 px-
|
|
45
|
+
const SelectItem = React.forwardRef(({ className, children, ...props }, ref) => (jsxs(SelectPrimitive.Item, { ref: ref, className: cn('relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pr-9 text-sm text-muted-foreground outline-none select-none transition-colors duration-interactive ease-out-strong focus:bg-muted data-[state=checked]:bg-primary-tint data-[disabled]:pointer-events-none data-[disabled]:opacity-50 motion-reduce:transition-none max-md:min-h-12', className), ...props, children: [jsx("span", { className: "absolute right-option-x flex h-4 w-4 items-center justify-center", children: jsx(SelectPrimitive.ItemIndicator, { children: jsx(Check, { className: "h-4 w-4" }) }) }), jsx(SelectPrimitive.ItemText, { children: children })] })));
|
|
46
46
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
47
47
|
const SelectSeparator = React.forwardRef(({ className, ...props }, ref) => (jsx(SelectPrimitive.Separator, { ref: ref, className: cn('bg-border h-px', className), ...props })));
|
|
48
48
|
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sources":["../../src/components/select.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as SelectPrimitive from '@radix-ui/react-select';\nimport { Check, ChevronDown, ChevronUp, X } from 'lucide-react';\n\nimport { cn } from '@/utils';\nimport { fieldInteractionClassName } from '@/hooks/use-field-focus';\nimport { useMobile } from '@/hooks/use-mobile';\nimport { useMobileSheetViewport } from '@/hooks/use-mobile-sheet-viewport';\n\nconst SelectContext = React.createContext({ open: false, setOpen: (_open: boolean) => {} });\n\nfunction Select({ open: controlledOpen, defaultOpen = false, onOpenChange, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {\n const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? internalOpen;\n const setOpen = (next: boolean) => {\n if (controlledOpen === undefined) setInternalOpen(next);\n onOpenChange?.(next);\n };\n\n return (\n <SelectContext.Provider value={{ open, setOpen }}>\n <SelectPrimitive.Root {...props} open={open} onOpenChange={setOpen}>\n {children}\n </SelectPrimitive.Root>\n </SelectContext.Provider>\n );\n}\n\nconst SelectGroup = SelectPrimitive.Group;\n\nconst SelectValue = SelectPrimitive.Value;\n\nconst SelectTrigger = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Trigger>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>\n>(({ className, children, ...props }, ref) => (\n <SelectPrimitive.Trigger\n ref={ref}\n className={cn(\n 'group bg-background text-foreground placeholder:text-muted-foreground/40 data-[placeholder]:text-muted-foreground/40 border-input enabled:hover:border-input-hover flex h-form-control min-h-form-control max-h-form-control w-full cursor-pointer items-center justify-between gap-2 rounded-control-lg border px-field-padding-x py-0 text-base font-normal outline-none aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',\n 'focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue',\n fieldInteractionClassName,\n className,\n )}\n {...props}\n >\n {children}\n <SelectPrimitive.Icon asChild>\n <ChevronDown className=\"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-interactive ease-out-strong group-data-[state=open]:rotate-180 motion-reduce:transition-none\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n));\nSelectTrigger.displayName = SelectPrimitive.Trigger.displayName;\n\nconst SelectScrollUpButton = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.ScrollUpButton\n ref={ref}\n className={cn(\n 'flex cursor-default items-center justify-center py-1',\n className,\n )}\n {...props}\n >\n <ChevronUp className=\"h-4 w-4\" />\n </SelectPrimitive.ScrollUpButton>\n));\nSelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;\n\nconst SelectScrollDownButton = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.ScrollDownButton\n ref={ref}\n className={cn(\n 'flex cursor-default items-center justify-center py-1',\n className,\n )}\n {...props}\n >\n <ChevronDown className=\"h-4 w-4\" />\n </SelectPrimitive.ScrollDownButton>\n));\nSelectScrollDownButton.displayName =\n SelectPrimitive.ScrollDownButton.displayName;\n\nconst SelectContent = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & { title?: string }\n>(({ className, children, position = 'popper', title = 'Choose an option', style, ...props }, ref) => {\n const mobile = useMobile();\n const { open, setOpen } = React.useContext(SelectContext);\n const viewport = useMobileSheetViewport(open && mobile);\n\n return (\n <SelectPrimitive.Portal>\n <div\n className={mobile ? '[&>[data-radix-popper-content-wrapper]]:!fixed [&>[data-radix-popper-content-wrapper]]:!inset-x-0 [&>[data-radix-popper-content-wrapper]]:!top-auto [&>[data-radix-popper-content-wrapper]]:!bottom-[var(--select-sheet-bottom)] [&>[data-radix-popper-content-wrapper]]:!transform-none [&>[data-radix-popper-content-wrapper]]:!z-[1100] [&>[data-radix-popper-content-wrapper]]:!min-w-0' : undefined}\n style={{ '--select-sheet-bottom': `${viewport?.bottom ?? 0}px` } as React.CSSProperties}\n >\n {mobile && open && (\n <div aria-hidden=\"true\" className=\"fixed inset-0 z-[1090] bg-black/25 backdrop-blur-[1px]\" />\n )}\n <SelectPrimitive.Content\n ref={ref}\n className={cn(\n 'relative flex flex-col overflow-hidden border border-border bg-background text-sm text-foreground shadow-card duration-interactive ease-out-strong motion-reduce:animate-none',\n mobile\n ? 'w-full rounded-t-control-lg border-b-0 pb-[env(safe-area-inset-bottom)]'\n : 'z-50 max-h-[400px] min-w-[8rem] rounded-control-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n className,\n )}\n position={mobile ? 'popper' : position}\n sideOffset={4}\n style={{\n ...(mobile ? { maxHeight: viewport ? Math.min(viewport.height, 640) : '80dvh' } : {}),\n ...style,\n }}\n {...props}\n >\n {mobile && (\n <div role=\"presentation\" className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4\">\n <h2 className=\"text-base font-semibold text-foreground\">{title}</h2>\n <button\n type=\"button\"\n aria-label=\"Close options\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onPointerDown={(event) => event.stopPropagation()}\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n )}\n {!mobile && <SelectScrollUpButton />}\n <SelectPrimitive.Viewport\n className={cn(\n 'min-h-0 overflow-y-auto overscroll-contain',\n mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]',\n )}\n >\n {children}\n </SelectPrimitive.Viewport>\n {!mobile && <SelectScrollDownButton />}\n </SelectPrimitive.Content>\n </div>\n </SelectPrimitive.Portal>\n );\n});\nSelectContent.displayName = SelectPrimitive.Content.displayName;\n\nconst SelectLabel = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Label>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.Label\n ref={ref}\n className={cn('
|
|
1
|
+
{"version":3,"file":"select.js","sources":["../../src/components/select.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as SelectPrimitive from '@radix-ui/react-select';\nimport { Check, ChevronDown, ChevronUp, X } from 'lucide-react';\n\nimport { cn } from '@/utils';\nimport { fieldInteractionClassName } from '@/hooks/use-field-focus';\nimport { useMobile } from '@/hooks/use-mobile';\nimport { useMobileSheetViewport } from '@/hooks/use-mobile-sheet-viewport';\n\nconst SelectContext = React.createContext({ open: false, setOpen: (_open: boolean) => {} });\n\nfunction Select({ open: controlledOpen, defaultOpen = false, onOpenChange, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {\n const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? internalOpen;\n const setOpen = (next: boolean) => {\n if (controlledOpen === undefined) setInternalOpen(next);\n onOpenChange?.(next);\n };\n\n return (\n <SelectContext.Provider value={{ open, setOpen }}>\n <SelectPrimitive.Root {...props} open={open} onOpenChange={setOpen}>\n {children}\n </SelectPrimitive.Root>\n </SelectContext.Provider>\n );\n}\n\nconst SelectGroup = SelectPrimitive.Group;\n\nconst SelectValue = SelectPrimitive.Value;\n\nconst SelectTrigger = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Trigger>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>\n>(({ className, children, ...props }, ref) => (\n <SelectPrimitive.Trigger\n ref={ref}\n className={cn(\n 'group bg-background text-foreground placeholder:text-muted-foreground/40 data-[placeholder]:text-muted-foreground/40 border-input enabled:hover:border-input-hover flex h-form-control min-h-form-control max-h-form-control w-full cursor-pointer items-center justify-between gap-2 rounded-control-lg border px-field-padding-x py-0 text-base font-normal outline-none aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',\n 'focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue',\n fieldInteractionClassName,\n className,\n )}\n {...props}\n >\n {children}\n <SelectPrimitive.Icon asChild>\n <ChevronDown className=\"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-interactive ease-out-strong group-data-[state=open]:rotate-180 motion-reduce:transition-none\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n));\nSelectTrigger.displayName = SelectPrimitive.Trigger.displayName;\n\nconst SelectScrollUpButton = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.ScrollUpButton\n ref={ref}\n className={cn(\n 'flex cursor-default items-center justify-center py-1',\n className,\n )}\n {...props}\n >\n <ChevronUp className=\"h-4 w-4\" />\n </SelectPrimitive.ScrollUpButton>\n));\nSelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;\n\nconst SelectScrollDownButton = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.ScrollDownButton\n ref={ref}\n className={cn(\n 'flex cursor-default items-center justify-center py-1',\n className,\n )}\n {...props}\n >\n <ChevronDown className=\"h-4 w-4\" />\n </SelectPrimitive.ScrollDownButton>\n));\nSelectScrollDownButton.displayName =\n SelectPrimitive.ScrollDownButton.displayName;\n\nconst SelectContent = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & { title?: string }\n>(({ className, children, position = 'popper', title = 'Choose an option', style, ...props }, ref) => {\n const mobile = useMobile();\n const { open, setOpen } = React.useContext(SelectContext);\n const viewport = useMobileSheetViewport(open && mobile);\n\n return (\n <SelectPrimitive.Portal>\n <div\n className={mobile ? '[&>[data-radix-popper-content-wrapper]]:!fixed [&>[data-radix-popper-content-wrapper]]:!inset-x-0 [&>[data-radix-popper-content-wrapper]]:!top-auto [&>[data-radix-popper-content-wrapper]]:!bottom-[var(--select-sheet-bottom)] [&>[data-radix-popper-content-wrapper]]:!transform-none [&>[data-radix-popper-content-wrapper]]:!z-[1100] [&>[data-radix-popper-content-wrapper]]:!min-w-0' : undefined}\n style={{ '--select-sheet-bottom': `${viewport?.bottom ?? 0}px` } as React.CSSProperties}\n >\n {mobile && open && (\n <div aria-hidden=\"true\" className=\"fixed inset-0 z-[1090] bg-black/25 backdrop-blur-[1px]\" />\n )}\n <SelectPrimitive.Content\n ref={ref}\n className={cn(\n 'relative flex flex-col overflow-hidden border border-border bg-background text-sm text-foreground shadow-card duration-interactive ease-out-strong motion-reduce:animate-none',\n mobile\n ? 'w-full rounded-t-control-lg border-b-0 pb-[env(safe-area-inset-bottom)]'\n : 'z-50 max-h-[400px] min-w-[8rem] rounded-control-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n className,\n )}\n position={mobile ? 'popper' : position}\n sideOffset={4}\n style={{\n ...(mobile ? { maxHeight: viewport ? Math.min(viewport.height, 640) : '80dvh' } : {}),\n ...style,\n }}\n {...props}\n >\n {mobile && (\n <div role=\"presentation\" className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4\">\n <h2 className=\"text-base font-semibold text-foreground\">{title}</h2>\n <button\n type=\"button\"\n aria-label=\"Close options\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onPointerDown={(event) => event.stopPropagation()}\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n )}\n {!mobile && <SelectScrollUpButton />}\n <SelectPrimitive.Viewport\n className={cn(\n 'flex min-h-0 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset',\n mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]',\n )}\n >\n {children}\n </SelectPrimitive.Viewport>\n {!mobile && <SelectScrollDownButton />}\n </SelectPrimitive.Content>\n </div>\n </SelectPrimitive.Portal>\n );\n});\nSelectContent.displayName = SelectPrimitive.Content.displayName;\n\nconst SelectLabel = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Label>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.Label\n ref={ref}\n className={cn('px-option-x py-2 text-sm font-semibold text-foreground', className)}\n {...props}\n />\n));\nSelectLabel.displayName = SelectPrimitive.Label.displayName;\n\nconst SelectItem = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>\n>(({ className, children, ...props }, ref) => (\n <SelectPrimitive.Item\n ref={ref}\n className={cn(\n 'relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pr-9 text-sm text-muted-foreground outline-none select-none transition-colors duration-interactive ease-out-strong focus:bg-muted data-[state=checked]:bg-primary-tint data-[disabled]:pointer-events-none data-[disabled]:opacity-50 motion-reduce:transition-none max-md:min-h-12',\n className,\n )}\n {...props}\n >\n <span className=\"absolute right-option-x flex h-4 w-4 items-center justify-center\">\n <SelectPrimitive.ItemIndicator>\n <Check className=\"h-4 w-4\" />\n </SelectPrimitive.ItemIndicator>\n </span>\n\n <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n));\nSelectItem.displayName = SelectPrimitive.Item.displayName;\n\nconst SelectSeparator = React.forwardRef<\n React.ElementRef<typeof SelectPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <SelectPrimitive.Separator\n ref={ref}\n className={cn('bg-border h-px', className)}\n {...props}\n />\n));\nSelectSeparator.displayName = SelectPrimitive.Separator.displayName;\n\nexport {\n Select,\n SelectGroup,\n SelectValue,\n SelectTrigger,\n SelectContent,\n SelectLabel,\n SelectItem,\n SelectSeparator,\n SelectScrollUpButton,\n SelectScrollDownButton,\n};\n"],"names":[],"mappings":";;;;;;;;;;AAWA;AAEA;AACE;AACA;AACA;;;AAEE;AACF;AAEA;AAOF;AAEA;AAEA;AAEA;AAoBA;AAEA;AAeA;AAEA;AAeA;AACE;AAEF;AAIE;AACA;;AAGA;AAcQ;;AAOF;AACA;;AAgCR;AACA;AAEA;AAUA;AAEA;AAqBA;AAEA;AAUA;;"}
|
package/dist/components/table.js
CHANGED
|
@@ -29,7 +29,7 @@ function ResourceFilterPanel({ groups, draftValue, draftActiveCount, toggleOptio
|
|
|
29
29
|
return (jsxs(Fragment, { children: [jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2", children: [jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Filters" }), draftActiveCount > 0 && (jsx("button", { type: "button", onClick: clearDraft, className: "shrink-0 text-sm font-medium text-gray-600 hover:text-primary", children: "Clear all" }))] }), jsx("div", { className: "min-h-0 flex-1 space-y-3 overflow-y-auto p-3", children: groups.map((group) => {
|
|
30
30
|
const activeValues = draftValue[group.id] ?? [];
|
|
31
31
|
const allSelected = activeValues.length === group.options.length;
|
|
32
|
-
return (jsxs("section", { className: "overflow-hidden rounded-
|
|
32
|
+
return (jsxs("section", { className: "overflow-hidden rounded-control-lg border border-border bg-background", children: [jsxs("div", { className: "flex items-center justify-between border-b border-border px-4 py-2.5", children: [jsx("span", { className: "text-sm font-semibold text-foreground", children: group.label }), jsx("button", { type: "button", onClick: () => toggleGroup(group.id), className: "text-sm font-medium text-muted-foreground hover:text-primary", children: allSelected ? "Clear" : "Select all" })] }), jsx("div", { className: "flex flex-col gap-option-gap p-option-inset", children: group.options.map((option) => (jsxs("label", { className: "flex min-h-option-row cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted active:bg-muted", children: [jsx("span", { className: "flex-1", children: option.label }), typeof option.count === "number" && (jsx("span", { className: "text-muted-foreground", children: option.count })), jsx(Checkbox, { checked: activeValues.includes(option.value), onCheckedChange: (checked) => toggleOption(group.id, option.value, checked === true) })] }, option.value))) })] }, group.id));
|
|
33
33
|
}) }), jsxs("div", { className: "flex items-center justify-end gap-2 border-t bg-white px-3 py-2.5", children: [jsx(Button, { variant: "outline", onClick: cancel, children: "Cancel" }), jsx(Button, { onClick: apply, children: "Apply" })] })] }));
|
|
34
34
|
}
|
|
35
35
|
function ResourceTable({ table, columns = table.columns, renderMobileRow, emptyState, noResultsState, rowLabelSingular, rowLabelPlural, className, contentClassName, listClassName, paginationClassName, toolbarStart, toolbarLeading, showSelectionRatio = true, selectionColumnClassName, rowSelectionCheckboxClassName, rowSelectionUnavailableClassName, getRowSelectionUnavailableReason, selectionIndicatorClassName, headerSelectionCheckboxClassName, onRowClick, getRowClassName, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sources":["../../src/components/table.tsx"],"sourcesContent":["// REVIEW SNAPSHOT: bi-iom/IOM-Client/components/ui/resource-table.tsx\n// Source SHA-256: 9772e5fbce1e3adc3af1e8bf8184c4ef3546a0608cce43154aeecad56ca58fd6\n// Generated by playground/review/snapshot.mjs; import paths normalized for isolated review.\n\"use client\";\n\nimport { type ReactNode } from \"react\";\nimport {\n ChevronDown,\n ChevronLeft,\n ChevronRight,\n ChevronUp,\n ChevronsUpDown,\n Filter,\n Search,\n X,\n} from \"lucide-react\";\n\nimport { Button } from \"@/components/button\";\nimport { Checkbox } from \"@/components/checkbox\";\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"@/components/popover\";\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@/components/select\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@/components/tooltip\";\nimport { cn } from \"@/utils\";\nimport type {\n ResourceFilterGroup,\n ResourceTableColumn,\n ResourceTableState,\n} from \"@/hooks/use-resource-table\";\n\nexport type { ResourceTableColumn } from \"@/hooks/use-resource-table\";\n\ntype ResourceEmptyState = {\n title: string;\n description?: ReactNode;\n action?: ReactNode;\n};\n\n// Sized up from the Checkbox default (size-4) and given a visible hover cue\n// — these sit in a dense, easy-to-miss leading column. UnselectableMark\n// matches the same size so a column of checkboxes stays aligned.\nconst SELECTION_CHECKBOX_CLASS =\n \"size-5 border-gray-400 hover:border-primary hover:ring-2 hover:ring-primary/15\";\n\n/**\n * Stands in for the selection checkbox on rows the caller marked\n * unselectable. A disabled Radix checkbox only fades — with no indicator\n * shown, it reads as barely-there. This is always visibly crossed out\n * instead, so \"you can't pick this row\" doesn't depend on noticing a\n * subtle opacity change.\n */\nfunction UnselectableMark({\n className,\n reason = \"Not selectable\",\n}: {\n className?: string;\n reason?: ReactNode;\n}) {\n return (\n <Tooltip>\n <TooltipTrigger asChild>\n <span\n className={cn(\n \"flex size-5 shrink-0 items-center justify-center rounded-[4px] border border-gray-300 bg-gray-100\",\n className,\n )}\n role=\"img\"\n tabIndex={0}\n aria-label=\"Not selectable\"\n >\n <X\n className=\"size-3.5 text-gray-400\"\n strokeWidth={3}\n aria-hidden=\"true\"\n />\n </span>\n </TooltipTrigger>\n <TooltipContent side=\"right\" sideOffset={6}>\n {reason}\n </TooltipContent>\n </Tooltip>\n );\n}\n\n\n\nfunction ResourceFilterPanel({\n groups,\n draftValue,\n draftActiveCount,\n toggleOption,\n toggleGroup,\n clearDraft,\n cancel,\n apply,\n}: {\n groups: ResourceFilterGroup[];\n draftValue: Record<string, string[]>;\n draftActiveCount: number;\n toggleOption: (\n groupId: string,\n optionValue: string,\n checked: boolean,\n ) => void;\n toggleGroup: (groupId: string) => void;\n clearDraft: () => void;\n cancel: () => void;\n apply: () => void;\n}) {\n return (\n <>\n <div className=\"flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2\">\n <span className=\"text-sm font-semibold text-gray-900\">Filters</span>\n {draftActiveCount > 0 && (\n <button\n type=\"button\"\n onClick={clearDraft}\n className=\"shrink-0 text-sm font-medium text-gray-600 hover:text-primary\"\n >\n Clear all\n </button>\n )}\n </div>\n\n <div className=\"min-h-0 flex-1 space-y-3 overflow-y-auto p-3\">\n {groups.map((group) => {\n const activeValues = draftValue[group.id] ?? [];\n const allSelected = activeValues.length === group.options.length;\n\n return (\n <section\n key={group.id}\n className=\"overflow-hidden rounded-[0.33em] border border-gray-200 bg-white\"\n >\n <div className=\"flex items-center justify-between border-b border-gray-200 px-4 py-2.5\">\n <span className=\"text-sm font-semibold text-gray-800\">\n {group.label}\n </span>\n <button\n type=\"button\"\n onClick={() => toggleGroup(group.id)}\n className=\"text-sm font-medium text-gray-600 hover:text-primary\"\n >\n {allSelected ? \"Clear\" : \"Select all\"}\n </button>\n </div>\n {group.options.map((option) => (\n <label\n key={option.value}\n className=\"flex cursor-pointer items-center gap-3 px-4 py-2.5 text-sm text-gray-800 hover:bg-gray-50 active:bg-gray-100\"\n >\n <span className=\"flex-1\">{option.label}</span>\n {typeof option.count === \"number\" && (\n <span className=\"text-muted-foreground\">\n {option.count}\n </span>\n )}\n <Checkbox\n checked={activeValues.includes(option.value)}\n onCheckedChange={(checked) =>\n toggleOption(group.id, option.value, checked === true)\n }\n />\n </label>\n ))}\n </section>\n );\n })}\n </div>\n\n <div className=\"flex items-center justify-end gap-2 border-t bg-white px-3 py-2.5\">\n <Button variant=\"outline\" onClick={cancel}>\n Cancel\n </Button>\n <Button onClick={apply}>Apply</Button>\n </div>\n </>\n );\n}\n\nexport function ResourceTable<TData>({\n table,\n columns = table.columns,\n renderMobileRow,\n emptyState,\n noResultsState,\n rowLabelSingular,\n rowLabelPlural,\n className,\n contentClassName,\n listClassName,\n paginationClassName,\n toolbarStart,\n toolbarLeading,\n showSelectionRatio = true,\n selectionColumnClassName,\n rowSelectionCheckboxClassName,\n rowSelectionUnavailableClassName,\n getRowSelectionUnavailableReason,\n selectionIndicatorClassName,\n headerSelectionCheckboxClassName,\n onRowClick,\n getRowClassName,\n}: {\n table: ResourceTableState<TData>;\n columns?: Array<ResourceTableColumn<TData>>;\n renderMobileRow: (row: TData) => ReactNode;\n emptyState: ResourceEmptyState;\n noResultsState?: ResourceEmptyState;\n rowLabelSingular: string;\n rowLabelPlural: string;\n className?: string;\n contentClassName?: string;\n listClassName?: string;\n paginationClassName?: string;\n toolbarStart?: ReactNode;\n toolbarLeading?: ReactNode;\n showSelectionRatio?: boolean;\n selectionColumnClassName?: string;\n rowSelectionCheckboxClassName?: string;\n rowSelectionUnavailableClassName?: string;\n getRowSelectionUnavailableReason?: (row: TData) => ReactNode;\n selectionIndicatorClassName?: string;\n headerSelectionCheckboxClassName?: string;\n onRowClick?: (row: TData) => void;\n getRowClassName?: (row: TData) => string | undefined;\n}) {\n const hasToolbar =\n !!toolbarStart || !!toolbarLeading || !!table.search || !!table.filters;\n const hasRows = table.pagedRows.length > 0;\n const hasAnyData = table.dataCount > 0;\n const hasDesktopTable = !!columns?.length;\n const resolvedEmptyState = hasAnyData\n ? (noResultsState ?? emptyState)\n : emptyState;\n\n const selection = table.selection;\n const selectablePageRows = selection\n ? table.pagedRows.filter(selection.isRowSelectable)\n : [];\n const headerCheckedState = selection\n ? selection.isAllPageSelected\n ? true\n : selectablePageRows.some((row) => selection.isSelected(row))\n ? \"indeterminate\"\n : false\n : false;\n const showSelectAllMatchingBanner =\n !!selection &&\n hasRows &&\n selection.isAllPageSelected &&\n selection.selectableMatchingCount > selection.selectablePageCount;\n const showAllMatchingSelectedBanner =\n !!selection &&\n hasRows &&\n selection.isAllMatchingSelected &&\n selection.selectableMatchingCount > selection.selectablePageCount;\n\n const renderHeaderCell = (column: ResourceTableColumn<TData>) => {\n const sortColumn = table.sort?.columns.find(\n (item) => item.id === column.id,\n );\n const isSortable =\n !!table.sort && column.sortable !== false && !!sortColumn;\n const isActive = table.sort?.column === column.id;\n const isDesc = isActive && table.sort?.direction === \"desc\";\n\n return (\n <th\n key={column.id}\n className={cn(\n \"px-5 py-3 font-medium\",\n column.align === \"center\" && \"text-center\",\n column.align === \"right\" && \"text-right\",\n column.width,\n )}\n >\n {isSortable ? (\n <button\n type=\"button\"\n className={cn(\n \"inline-flex cursor-pointer items-center gap-1.5 text-left hover:text-gray-900\",\n column.align === \"center\" && \"justify-center\",\n column.align === \"right\" && \"justify-end\",\n isActive && \"text-primary\",\n )}\n onClick={() =>\n table.sort?.setSort(column.id, column.defaultSortDirection)\n }\n >\n {column.header}\n {isDesc ? (\n <ChevronDown className=\"h-3.5 w-3.5\" />\n ) : isActive ? (\n <ChevronUp className=\"h-3.5 w-3.5\" />\n ) : (\n <ChevronsUpDown className=\"text-muted-foreground/60 h-3.5 w-3.5\" />\n )}\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n };\n\n return (\n <div className={cn(\"space-y-5\", className)}>\n {hasToolbar && (\n <div\n className={cn(\n \"flex flex-wrap items-center gap-2\",\n toolbarStart && \"min-w-0 lg:flex-nowrap\",\n )}\n >\n {toolbarStart && (\n <div className=\"min-w-0 max-w-full overflow-hidden\">\n {toolbarStart}\n </div>\n )}\n\n <div\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-2\",\n toolbarStart && \"w-full justify-end lg:ml-auto lg:w-auto\",\n )}\n >\n {table.search && (\n <div\n className={cn(\n \"relative min-w-0 flex-1\",\n toolbarStart ? \"lg:w-80 lg:flex-none\" : \"w-full max-w-xl\",\n )}\n >\n <Search className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-4 z-20 h-4 w-4 -translate-y-1/2\" />\n <input\n type=\"search\"\n value={table.search.value}\n onChange={(event) =>\n table.search?.setValue(event.target.value)\n }\n placeholder={table.search.placeholder}\n aria-label={table.search.ariaLabel}\n className=\"placeholder:text-muted-foreground/60 focus:border-primary h-11 w-full rounded-[0.33em] border border-gray-200 bg-white pr-4 pl-11 text-sm outline-none transition-colors focus:ring-2 focus:ring-primary/10\"\n />\n </div>\n )}\n\n {table.filters && (\n <Popover\n open={table.filters.open}\n onOpenChange={table.filters.setOpen}\n >\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n size=\"sm\"\n className={cn(\n \"relative h-11 w-11 shrink-0 border-gray-200 bg-white text-gray-600 hover:text-primary\",\n table.filters.activeCount > 0 && \"text-primary\",\n )}\n aria-label=\"Filter results\"\n aria-expanded={table.filters.open}\n >\n <Filter />\n {table.filters.activeCount > 0 && (\n <span className=\"bg-primary text-primary-foreground absolute top-0 right-0 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[11px] font-semibold\">\n {table.filters.activeCount}\n </span>\n )}\n </Button>\n </PopoverTrigger>\n <PopoverContent\n align=\"start\"\n sideOffset={6}\n className=\"flex max-h-[70vh] w-[calc(100vw-2rem)] flex-col overflow-hidden rounded-[0.33em] border border-gray-200 bg-white p-0 shadow-lg sm:w-[445px]\"\n >\n <ResourceFilterPanel\n groups={table.filters.groups}\n draftValue={table.filters.draftValue}\n draftActiveCount={table.filters.draftActiveCount}\n toggleOption={table.filters.toggleDraftOption}\n toggleGroup={table.filters.toggleDraftGroup}\n clearDraft={table.filters.clearDraft}\n cancel={table.filters.cancel}\n apply={table.filters.apply}\n />\n </PopoverContent>\n </Popover>\n )}\n\n {toolbarLeading}\n </div>\n </div>\n )}\n\n {hasRows ? (\n <div\n className={cn(\n \"overflow-hidden rounded-[0.33em] border border-gray-200 bg-white\",\n contentClassName,\n )}\n >\n {(showSelectAllMatchingBanner || showAllMatchingSelectedBanner) && (\n <div className=\"bg-primary/5 flex items-center justify-center gap-2 border-b border-gray-200 px-4 py-2 text-sm text-gray-700\">\n {showAllMatchingSelectedBanner ? (\n <>\n <span>\n All {selection!.selectableMatchingCount} matching rows are\n selected.\n </span>\n <button\n type=\"button\"\n onClick={selection!.clear}\n className=\"text-primary cursor-pointer font-medium hover:underline\"\n >\n Clear selection\n </button>\n </>\n ) : (\n <>\n <span>\n All {selection!.selectablePageCount} on this page are\n selected.\n </span>\n <button\n type=\"button\"\n onClick={selection!.selectAllMatching}\n className=\"text-primary cursor-pointer font-medium hover:underline\"\n >\n Select all {selection!.selectableMatchingCount} matching\n rows\n </button>\n </>\n )}\n </div>\n )}\n\n {hasDesktopTable && (\n <div className=\"hidden overflow-x-auto md:block\">\n <table className=\"w-full table-fixed border-collapse text-left\">\n <thead className=\"bg-gray-50 text-sm font-medium text-gray-700\">\n <tr className=\"border-b border-gray-200\">\n {selection && (\n <th\n className={cn(\n \"w-16 px-3 py-3\",\n selectionColumnClassName,\n )}\n >\n <div className=\"flex flex-col items-start gap-0.5\">\n <Checkbox\n checked={headerCheckedState}\n onCheckedChange={() =>\n selection.isAllPageSelected\n ? selection.deselectPage()\n : selection.selectPage()\n }\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n selectionIndicatorClassName,\n headerSelectionCheckboxClassName,\n )}\n aria-label=\"Select all rows on this page\"\n />\n {showSelectionRatio &&\n selection.selectablePageCount <\n table.pagedRows.length && (\n <span className=\"text-muted-foreground text-[10px] leading-tight font-normal\">\n {selection.selectablePageCount}/\n {table.pagedRows.length}\n </span>\n )}\n </div>\n </th>\n )}\n {columns.map(renderHeaderCell)}\n </tr>\n </thead>\n <tbody>\n {table.pagedRows.map((row) => {\n const rowSelectable =\n selection?.isRowSelectable(row) ?? true;\n return (\n <tr\n key={table.getRowId(row)}\n className={cn(\n \"group border-b border-gray-200 transition-colors last:border-b-0 hover:bg-primary/[0.035] focus-within:bg-primary/[0.035]\",\n onRowClick && \"cursor-pointer\",\n getRowClassName?.(row),\n )}\n onClick={onRowClick ? () => onRowClick(row) : undefined}\n >\n {selection && (\n <td\n className={cn(\n \"px-3 py-4\",\n selectionColumnClassName,\n )}\n onClick={(event) => event.stopPropagation()}\n >\n {rowSelectable ? (\n <span className=\"flex size-5 items-center justify-center\">\n <Checkbox\n checked={selection.isSelected(row)}\n onCheckedChange={() => selection.toggle(row)}\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n rowSelectionCheckboxClassName,\n selectionIndicatorClassName,\n )}\n aria-label=\"Select row\"\n />\n </span>\n ) : (\n <UnselectableMark\n reason={getRowSelectionUnavailableReason?.(row)}\n className={cn(\n selectionIndicatorClassName,\n rowSelectionUnavailableClassName,\n )}\n />\n )}\n </td>\n )}\n {columns.map((column) => (\n <td\n key={column.id}\n className={cn(\n \"px-5 py-4\",\n column.align === \"center\" && \"text-center\",\n column.align === \"right\" && \"text-right\",\n )}\n >\n {column.render(row)}\n </td>\n ))}\n </tr>\n );\n })}\n </tbody>\n </table>\n </div>\n )}\n\n <div\n className={cn(\n \"divide-y divide-gray-200\",\n hasDesktopTable && \"md:hidden\",\n listClassName,\n )}\n >\n {table.pagedRows.map((row) => {\n const rowSelectable = selection?.isRowSelectable(row) ?? true;\n return (\n <div key={table.getRowId(row)} className=\"flex items-start\">\n {selection && (\n <div\n className=\"flex shrink-0 items-center self-stretch pl-4\"\n onClick={(event) => event.stopPropagation()}\n >\n {rowSelectable ? (\n <span className=\"flex size-5 items-center justify-center\">\n <Checkbox\n checked={selection.isSelected(row)}\n onCheckedChange={() => selection.toggle(row)}\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n rowSelectionCheckboxClassName,\n selectionIndicatorClassName,\n )}\n aria-label=\"Select row\"\n />\n </span>\n ) : (\n <UnselectableMark\n reason={getRowSelectionUnavailableReason?.(row)}\n className={cn(\n selectionIndicatorClassName,\n rowSelectionUnavailableClassName,\n )}\n />\n )}\n </div>\n )}\n <div className=\"min-w-0 flex-1\">{renderMobileRow(row)}</div>\n </div>\n );\n })}\n </div>\n\n <div\n className={cn(\n \"flex flex-col items-center justify-between gap-3 border-t border-gray-200 px-5 py-4 sm:flex-row\",\n paginationClassName,\n )}\n >\n <p className=\"text-muted-foreground text-sm\">\n Showing {table.pageStart + 1} to {table.pageEnd} of{\" \"}\n {table.totalCount}{\" \"}\n {table.totalCount === 1 ? rowLabelSingular : rowLabelPlural}\n </p>\n <div className=\"flex flex-wrap items-center justify-center gap-3\">\n <label className=\"text-muted-foreground flex items-center gap-2 text-sm whitespace-nowrap\">\n Rows per page\n <Select\n value={String(table.pagination.pageSize)}\n onValueChange={(value) =>\n table.pagination.setPageSize(Number(value))\n }\n >\n <SelectTrigger className=\"w-20\" aria-label=\"Rows per page\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent align=\"end\">\n {table.pagination.pageSizeOptions.map((pageSize) => (\n <SelectItem key={pageSize} value={String(pageSize)}>\n {pageSize}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </label>\n\n {table.pageCount > 1 && (\n <div\n className=\"flex items-center gap-1\"\n aria-label=\"Pagination\"\n >\n <Button\n variant=\"ghost\"\n size=\"sm\"\n disabled={table.page === 1}\n onClick={() => table.pagination.setPage(table.page - 1)}\n aria-label=\"Previous page\"\n >\n <ChevronLeft />\n </Button>\n {Array.from(\n { length: table.pageCount },\n (_, index) => index + 1,\n )\n .filter(\n (page) =>\n page === 1 ||\n page === table.pageCount ||\n Math.abs(page - table.page) <= 1,\n )\n .map((page, index, pages) => (\n <span key={page} className=\"flex items-center gap-1\">\n {index > 0 && page - pages[index - 1] > 1 && (\n <span className=\"text-muted-foreground px-1\">\n ...\n </span>\n )}\n <Button\n variant={page === table.page ? \"outline\" : \"ghost\"}\n scheme={page === table.page ? \"primary\" : undefined}\n size=\"sm\"\n className=\"h-9 w-9\"\n onClick={() => table.pagination.setPage(page)}\n aria-label={`Page ${page}`}\n aria-current={\n page === table.page ? \"page\" : undefined\n }\n >\n {page}\n </Button>\n </span>\n ))}\n <Button\n variant=\"ghost\"\n size=\"sm\"\n disabled={table.page === table.pageCount}\n onClick={() => table.pagination.setPage(table.page + 1)}\n aria-label=\"Next page\"\n >\n <ChevronRight />\n </Button>\n </div>\n )}\n </div>\n </div>\n </div>\n ) : (\n <div className=\"rounded-[0.33em] border border-dashed border-gray-300 bg-white px-6 py-12 text-center\">\n <p className=\"text-sm font-medium text-gray-700\">\n {resolvedEmptyState.title}\n </p>\n {resolvedEmptyState.description && (\n <p className=\"text-muted-foreground mt-1 text-sm\">\n {resolvedEmptyState.description}\n </p>\n )}\n {resolvedEmptyState.action && (\n <div className=\"mt-4\">{resolvedEmptyState.action}</div>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport const Table = ResourceTable;\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAiDA;AACA;AACA;AACA;AAGA;;;;;;AAMG;AACH;AAOE;AAwBF;AAIA;;;;AA2CU;AAsCF;AAWR;AAEM;;;AAkDJ;AACA;;AAEE;;AAGF;;;;;;AAMI;AACA;AACE;AACA;;AAEN;;AAGE;AACA;AACF;;AAGE;AACA;AAEF;;AAIE;;;AAKA;AAqCF;;AAuJ8B;;AAWJ;;;;AAyEV;;;;;;;;AAkKlB;AAEO;;"}
|
|
1
|
+
{"version":3,"file":"table.js","sources":["../../src/components/table.tsx"],"sourcesContent":["// REVIEW SNAPSHOT: bi-iom/IOM-Client/components/ui/resource-table.tsx\n// Source SHA-256: 9772e5fbce1e3adc3af1e8bf8184c4ef3546a0608cce43154aeecad56ca58fd6\n// Generated by playground/review/snapshot.mjs; import paths normalized for isolated review.\n\"use client\";\n\nimport { type ReactNode } from \"react\";\nimport {\n ChevronDown,\n ChevronLeft,\n ChevronRight,\n ChevronUp,\n ChevronsUpDown,\n Filter,\n Search,\n X,\n} from \"lucide-react\";\n\nimport { Button } from \"@/components/button\";\nimport { Checkbox } from \"@/components/checkbox\";\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"@/components/popover\";\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@/components/select\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@/components/tooltip\";\nimport { cn } from \"@/utils\";\nimport type {\n ResourceFilterGroup,\n ResourceTableColumn,\n ResourceTableState,\n} from \"@/hooks/use-resource-table\";\n\nexport type { ResourceTableColumn } from \"@/hooks/use-resource-table\";\n\ntype ResourceEmptyState = {\n title: string;\n description?: ReactNode;\n action?: ReactNode;\n};\n\n// Sized up from the Checkbox default (size-4) and given a visible hover cue\n// — these sit in a dense, easy-to-miss leading column. UnselectableMark\n// matches the same size so a column of checkboxes stays aligned.\nconst SELECTION_CHECKBOX_CLASS =\n \"size-5 border-gray-400 hover:border-primary hover:ring-2 hover:ring-primary/15\";\n\n/**\n * Stands in for the selection checkbox on rows the caller marked\n * unselectable. A disabled Radix checkbox only fades — with no indicator\n * shown, it reads as barely-there. This is always visibly crossed out\n * instead, so \"you can't pick this row\" doesn't depend on noticing a\n * subtle opacity change.\n */\nfunction UnselectableMark({\n className,\n reason = \"Not selectable\",\n}: {\n className?: string;\n reason?: ReactNode;\n}) {\n return (\n <Tooltip>\n <TooltipTrigger asChild>\n <span\n className={cn(\n \"flex size-5 shrink-0 items-center justify-center rounded-[4px] border border-gray-300 bg-gray-100\",\n className,\n )}\n role=\"img\"\n tabIndex={0}\n aria-label=\"Not selectable\"\n >\n <X\n className=\"size-3.5 text-gray-400\"\n strokeWidth={3}\n aria-hidden=\"true\"\n />\n </span>\n </TooltipTrigger>\n <TooltipContent side=\"right\" sideOffset={6}>\n {reason}\n </TooltipContent>\n </Tooltip>\n );\n}\n\n\n\nfunction ResourceFilterPanel({\n groups,\n draftValue,\n draftActiveCount,\n toggleOption,\n toggleGroup,\n clearDraft,\n cancel,\n apply,\n}: {\n groups: ResourceFilterGroup[];\n draftValue: Record<string, string[]>;\n draftActiveCount: number;\n toggleOption: (\n groupId: string,\n optionValue: string,\n checked: boolean,\n ) => void;\n toggleGroup: (groupId: string) => void;\n clearDraft: () => void;\n cancel: () => void;\n apply: () => void;\n}) {\n return (\n <>\n <div className=\"flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2\">\n <span className=\"text-sm font-semibold text-gray-900\">Filters</span>\n {draftActiveCount > 0 && (\n <button\n type=\"button\"\n onClick={clearDraft}\n className=\"shrink-0 text-sm font-medium text-gray-600 hover:text-primary\"\n >\n Clear all\n </button>\n )}\n </div>\n\n <div className=\"min-h-0 flex-1 space-y-3 overflow-y-auto p-3\">\n {groups.map((group) => {\n const activeValues = draftValue[group.id] ?? [];\n const allSelected = activeValues.length === group.options.length;\n\n return (\n <section\n key={group.id}\n className=\"overflow-hidden rounded-control-lg border border-border bg-background\"\n >\n <div className=\"flex items-center justify-between border-b border-border px-4 py-2.5\">\n <span className=\"text-sm font-semibold text-foreground\">\n {group.label}\n </span>\n <button\n type=\"button\"\n onClick={() => toggleGroup(group.id)}\n className=\"text-sm font-medium text-muted-foreground hover:text-primary\"\n >\n {allSelected ? \"Clear\" : \"Select all\"}\n </button>\n </div>\n <div className=\"flex flex-col gap-option-gap p-option-inset\">\n {group.options.map((option) => (\n <label\n key={option.value}\n className=\"flex min-h-option-row cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted active:bg-muted\"\n >\n <span className=\"flex-1\">{option.label}</span>\n {typeof option.count === \"number\" && (\n <span className=\"text-muted-foreground\">\n {option.count}\n </span>\n )}\n <Checkbox\n checked={activeValues.includes(option.value)}\n onCheckedChange={(checked) =>\n toggleOption(group.id, option.value, checked === true)\n }\n />\n </label>\n ))}\n </div>\n </section>\n );\n })}\n </div>\n\n <div className=\"flex items-center justify-end gap-2 border-t bg-white px-3 py-2.5\">\n <Button variant=\"outline\" onClick={cancel}>\n Cancel\n </Button>\n <Button onClick={apply}>Apply</Button>\n </div>\n </>\n );\n}\n\nexport function ResourceTable<TData>({\n table,\n columns = table.columns,\n renderMobileRow,\n emptyState,\n noResultsState,\n rowLabelSingular,\n rowLabelPlural,\n className,\n contentClassName,\n listClassName,\n paginationClassName,\n toolbarStart,\n toolbarLeading,\n showSelectionRatio = true,\n selectionColumnClassName,\n rowSelectionCheckboxClassName,\n rowSelectionUnavailableClassName,\n getRowSelectionUnavailableReason,\n selectionIndicatorClassName,\n headerSelectionCheckboxClassName,\n onRowClick,\n getRowClassName,\n}: {\n table: ResourceTableState<TData>;\n columns?: Array<ResourceTableColumn<TData>>;\n renderMobileRow: (row: TData) => ReactNode;\n emptyState: ResourceEmptyState;\n noResultsState?: ResourceEmptyState;\n rowLabelSingular: string;\n rowLabelPlural: string;\n className?: string;\n contentClassName?: string;\n listClassName?: string;\n paginationClassName?: string;\n toolbarStart?: ReactNode;\n toolbarLeading?: ReactNode;\n showSelectionRatio?: boolean;\n selectionColumnClassName?: string;\n rowSelectionCheckboxClassName?: string;\n rowSelectionUnavailableClassName?: string;\n getRowSelectionUnavailableReason?: (row: TData) => ReactNode;\n selectionIndicatorClassName?: string;\n headerSelectionCheckboxClassName?: string;\n onRowClick?: (row: TData) => void;\n getRowClassName?: (row: TData) => string | undefined;\n}) {\n const hasToolbar =\n !!toolbarStart || !!toolbarLeading || !!table.search || !!table.filters;\n const hasRows = table.pagedRows.length > 0;\n const hasAnyData = table.dataCount > 0;\n const hasDesktopTable = !!columns?.length;\n const resolvedEmptyState = hasAnyData\n ? (noResultsState ?? emptyState)\n : emptyState;\n\n const selection = table.selection;\n const selectablePageRows = selection\n ? table.pagedRows.filter(selection.isRowSelectable)\n : [];\n const headerCheckedState = selection\n ? selection.isAllPageSelected\n ? true\n : selectablePageRows.some((row) => selection.isSelected(row))\n ? \"indeterminate\"\n : false\n : false;\n const showSelectAllMatchingBanner =\n !!selection &&\n hasRows &&\n selection.isAllPageSelected &&\n selection.selectableMatchingCount > selection.selectablePageCount;\n const showAllMatchingSelectedBanner =\n !!selection &&\n hasRows &&\n selection.isAllMatchingSelected &&\n selection.selectableMatchingCount > selection.selectablePageCount;\n\n const renderHeaderCell = (column: ResourceTableColumn<TData>) => {\n const sortColumn = table.sort?.columns.find(\n (item) => item.id === column.id,\n );\n const isSortable =\n !!table.sort && column.sortable !== false && !!sortColumn;\n const isActive = table.sort?.column === column.id;\n const isDesc = isActive && table.sort?.direction === \"desc\";\n\n return (\n <th\n key={column.id}\n className={cn(\n \"px-5 py-3 font-medium\",\n column.align === \"center\" && \"text-center\",\n column.align === \"right\" && \"text-right\",\n column.width,\n )}\n >\n {isSortable ? (\n <button\n type=\"button\"\n className={cn(\n \"inline-flex cursor-pointer items-center gap-1.5 text-left hover:text-gray-900\",\n column.align === \"center\" && \"justify-center\",\n column.align === \"right\" && \"justify-end\",\n isActive && \"text-primary\",\n )}\n onClick={() =>\n table.sort?.setSort(column.id, column.defaultSortDirection)\n }\n >\n {column.header}\n {isDesc ? (\n <ChevronDown className=\"h-3.5 w-3.5\" />\n ) : isActive ? (\n <ChevronUp className=\"h-3.5 w-3.5\" />\n ) : (\n <ChevronsUpDown className=\"text-muted-foreground/60 h-3.5 w-3.5\" />\n )}\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n };\n\n return (\n <div className={cn(\"space-y-5\", className)}>\n {hasToolbar && (\n <div\n className={cn(\n \"flex flex-wrap items-center gap-2\",\n toolbarStart && \"min-w-0 lg:flex-nowrap\",\n )}\n >\n {toolbarStart && (\n <div className=\"min-w-0 max-w-full overflow-hidden\">\n {toolbarStart}\n </div>\n )}\n\n <div\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-2\",\n toolbarStart && \"w-full justify-end lg:ml-auto lg:w-auto\",\n )}\n >\n {table.search && (\n <div\n className={cn(\n \"relative min-w-0 flex-1\",\n toolbarStart ? \"lg:w-80 lg:flex-none\" : \"w-full max-w-xl\",\n )}\n >\n <Search className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-4 z-20 h-4 w-4 -translate-y-1/2\" />\n <input\n type=\"search\"\n value={table.search.value}\n onChange={(event) =>\n table.search?.setValue(event.target.value)\n }\n placeholder={table.search.placeholder}\n aria-label={table.search.ariaLabel}\n className=\"placeholder:text-muted-foreground/60 focus:border-primary h-11 w-full rounded-[0.33em] border border-gray-200 bg-white pr-4 pl-11 text-sm outline-none transition-colors focus:ring-2 focus:ring-primary/10\"\n />\n </div>\n )}\n\n {table.filters && (\n <Popover\n open={table.filters.open}\n onOpenChange={table.filters.setOpen}\n >\n <PopoverTrigger asChild>\n <Button\n variant=\"outline\"\n size=\"sm\"\n className={cn(\n \"relative h-11 w-11 shrink-0 border-gray-200 bg-white text-gray-600 hover:text-primary\",\n table.filters.activeCount > 0 && \"text-primary\",\n )}\n aria-label=\"Filter results\"\n aria-expanded={table.filters.open}\n >\n <Filter />\n {table.filters.activeCount > 0 && (\n <span className=\"bg-primary text-primary-foreground absolute top-0 right-0 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[11px] font-semibold\">\n {table.filters.activeCount}\n </span>\n )}\n </Button>\n </PopoverTrigger>\n <PopoverContent\n align=\"start\"\n sideOffset={6}\n className=\"flex max-h-[70vh] w-[calc(100vw-2rem)] flex-col overflow-hidden rounded-[0.33em] border border-gray-200 bg-white p-0 shadow-lg sm:w-[445px]\"\n >\n <ResourceFilterPanel\n groups={table.filters.groups}\n draftValue={table.filters.draftValue}\n draftActiveCount={table.filters.draftActiveCount}\n toggleOption={table.filters.toggleDraftOption}\n toggleGroup={table.filters.toggleDraftGroup}\n clearDraft={table.filters.clearDraft}\n cancel={table.filters.cancel}\n apply={table.filters.apply}\n />\n </PopoverContent>\n </Popover>\n )}\n\n {toolbarLeading}\n </div>\n </div>\n )}\n\n {hasRows ? (\n <div\n className={cn(\n \"overflow-hidden rounded-[0.33em] border border-gray-200 bg-white\",\n contentClassName,\n )}\n >\n {(showSelectAllMatchingBanner || showAllMatchingSelectedBanner) && (\n <div className=\"bg-primary/5 flex items-center justify-center gap-2 border-b border-gray-200 px-4 py-2 text-sm text-gray-700\">\n {showAllMatchingSelectedBanner ? (\n <>\n <span>\n All {selection!.selectableMatchingCount} matching rows are\n selected.\n </span>\n <button\n type=\"button\"\n onClick={selection!.clear}\n className=\"text-primary cursor-pointer font-medium hover:underline\"\n >\n Clear selection\n </button>\n </>\n ) : (\n <>\n <span>\n All {selection!.selectablePageCount} on this page are\n selected.\n </span>\n <button\n type=\"button\"\n onClick={selection!.selectAllMatching}\n className=\"text-primary cursor-pointer font-medium hover:underline\"\n >\n Select all {selection!.selectableMatchingCount} matching\n rows\n </button>\n </>\n )}\n </div>\n )}\n\n {hasDesktopTable && (\n <div className=\"hidden overflow-x-auto md:block\">\n <table className=\"w-full table-fixed border-collapse text-left\">\n <thead className=\"bg-gray-50 text-sm font-medium text-gray-700\">\n <tr className=\"border-b border-gray-200\">\n {selection && (\n <th\n className={cn(\n \"w-16 px-3 py-3\",\n selectionColumnClassName,\n )}\n >\n <div className=\"flex flex-col items-start gap-0.5\">\n <Checkbox\n checked={headerCheckedState}\n onCheckedChange={() =>\n selection.isAllPageSelected\n ? selection.deselectPage()\n : selection.selectPage()\n }\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n selectionIndicatorClassName,\n headerSelectionCheckboxClassName,\n )}\n aria-label=\"Select all rows on this page\"\n />\n {showSelectionRatio &&\n selection.selectablePageCount <\n table.pagedRows.length && (\n <span className=\"text-muted-foreground text-[10px] leading-tight font-normal\">\n {selection.selectablePageCount}/\n {table.pagedRows.length}\n </span>\n )}\n </div>\n </th>\n )}\n {columns.map(renderHeaderCell)}\n </tr>\n </thead>\n <tbody>\n {table.pagedRows.map((row) => {\n const rowSelectable =\n selection?.isRowSelectable(row) ?? true;\n return (\n <tr\n key={table.getRowId(row)}\n className={cn(\n \"group border-b border-gray-200 transition-colors last:border-b-0 hover:bg-primary/[0.035] focus-within:bg-primary/[0.035]\",\n onRowClick && \"cursor-pointer\",\n getRowClassName?.(row),\n )}\n onClick={onRowClick ? () => onRowClick(row) : undefined}\n >\n {selection && (\n <td\n className={cn(\n \"px-3 py-4\",\n selectionColumnClassName,\n )}\n onClick={(event) => event.stopPropagation()}\n >\n {rowSelectable ? (\n <span className=\"flex size-5 items-center justify-center\">\n <Checkbox\n checked={selection.isSelected(row)}\n onCheckedChange={() => selection.toggle(row)}\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n rowSelectionCheckboxClassName,\n selectionIndicatorClassName,\n )}\n aria-label=\"Select row\"\n />\n </span>\n ) : (\n <UnselectableMark\n reason={getRowSelectionUnavailableReason?.(row)}\n className={cn(\n selectionIndicatorClassName,\n rowSelectionUnavailableClassName,\n )}\n />\n )}\n </td>\n )}\n {columns.map((column) => (\n <td\n key={column.id}\n className={cn(\n \"px-5 py-4\",\n column.align === \"center\" && \"text-center\",\n column.align === \"right\" && \"text-right\",\n )}\n >\n {column.render(row)}\n </td>\n ))}\n </tr>\n );\n })}\n </tbody>\n </table>\n </div>\n )}\n\n <div\n className={cn(\n \"divide-y divide-gray-200\",\n hasDesktopTable && \"md:hidden\",\n listClassName,\n )}\n >\n {table.pagedRows.map((row) => {\n const rowSelectable = selection?.isRowSelectable(row) ?? true;\n return (\n <div key={table.getRowId(row)} className=\"flex items-start\">\n {selection && (\n <div\n className=\"flex shrink-0 items-center self-stretch pl-4\"\n onClick={(event) => event.stopPropagation()}\n >\n {rowSelectable ? (\n <span className=\"flex size-5 items-center justify-center\">\n <Checkbox\n checked={selection.isSelected(row)}\n onCheckedChange={() => selection.toggle(row)}\n className={cn(\n SELECTION_CHECKBOX_CLASS,\n rowSelectionCheckboxClassName,\n selectionIndicatorClassName,\n )}\n aria-label=\"Select row\"\n />\n </span>\n ) : (\n <UnselectableMark\n reason={getRowSelectionUnavailableReason?.(row)}\n className={cn(\n selectionIndicatorClassName,\n rowSelectionUnavailableClassName,\n )}\n />\n )}\n </div>\n )}\n <div className=\"min-w-0 flex-1\">{renderMobileRow(row)}</div>\n </div>\n );\n })}\n </div>\n\n <div\n className={cn(\n \"flex flex-col items-center justify-between gap-3 border-t border-gray-200 px-5 py-4 sm:flex-row\",\n paginationClassName,\n )}\n >\n <p className=\"text-muted-foreground text-sm\">\n Showing {table.pageStart + 1} to {table.pageEnd} of{\" \"}\n {table.totalCount}{\" \"}\n {table.totalCount === 1 ? rowLabelSingular : rowLabelPlural}\n </p>\n <div className=\"flex flex-wrap items-center justify-center gap-3\">\n <label className=\"text-muted-foreground flex items-center gap-2 text-sm whitespace-nowrap\">\n Rows per page\n <Select\n value={String(table.pagination.pageSize)}\n onValueChange={(value) =>\n table.pagination.setPageSize(Number(value))\n }\n >\n <SelectTrigger className=\"w-20\" aria-label=\"Rows per page\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent align=\"end\">\n {table.pagination.pageSizeOptions.map((pageSize) => (\n <SelectItem key={pageSize} value={String(pageSize)}>\n {pageSize}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </label>\n\n {table.pageCount > 1 && (\n <div\n className=\"flex items-center gap-1\"\n aria-label=\"Pagination\"\n >\n <Button\n variant=\"ghost\"\n size=\"sm\"\n disabled={table.page === 1}\n onClick={() => table.pagination.setPage(table.page - 1)}\n aria-label=\"Previous page\"\n >\n <ChevronLeft />\n </Button>\n {Array.from(\n { length: table.pageCount },\n (_, index) => index + 1,\n )\n .filter(\n (page) =>\n page === 1 ||\n page === table.pageCount ||\n Math.abs(page - table.page) <= 1,\n )\n .map((page, index, pages) => (\n <span key={page} className=\"flex items-center gap-1\">\n {index > 0 && page - pages[index - 1] > 1 && (\n <span className=\"text-muted-foreground px-1\">\n ...\n </span>\n )}\n <Button\n variant={page === table.page ? \"outline\" : \"ghost\"}\n scheme={page === table.page ? \"primary\" : undefined}\n size=\"sm\"\n className=\"h-9 w-9\"\n onClick={() => table.pagination.setPage(page)}\n aria-label={`Page ${page}`}\n aria-current={\n page === table.page ? \"page\" : undefined\n }\n >\n {page}\n </Button>\n </span>\n ))}\n <Button\n variant=\"ghost\"\n size=\"sm\"\n disabled={table.page === table.pageCount}\n onClick={() => table.pagination.setPage(table.page + 1)}\n aria-label=\"Next page\"\n >\n <ChevronRight />\n </Button>\n </div>\n )}\n </div>\n </div>\n </div>\n ) : (\n <div className=\"rounded-[0.33em] border border-dashed border-gray-300 bg-white px-6 py-12 text-center\">\n <p className=\"text-sm font-medium text-gray-700\">\n {resolvedEmptyState.title}\n </p>\n {resolvedEmptyState.description && (\n <p className=\"text-muted-foreground mt-1 text-sm\">\n {resolvedEmptyState.description}\n </p>\n )}\n {resolvedEmptyState.action && (\n <div className=\"mt-4\">{resolvedEmptyState.action}</div>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport const Table = ResourceTable;\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAiDA;AACA;AACA;AACA;AAGA;;;;;;AAMG;AACH;AAOE;AAwBF;AAIA;;;;AA2CU;AAwCF;AAWR;AAEM;;;AAkDJ;AACA;;AAEE;;AAGF;;;;;;AAMI;AACA;AACE;AACA;;AAEN;;AAGE;AACA;AACF;;AAGE;AACA;AAEF;;AAIE;;;AAKA;AAqCF;;AAuJ8B;;AAWJ;;;;AAyEV;;;;;;;;AAkKlB;AAEO;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * from './components/dialog';
|
|
|
22
22
|
export * from './components/dropdown-menu';
|
|
23
23
|
export * from './components/file-upload';
|
|
24
24
|
export * from './components/filter-chip';
|
|
25
|
+
export * from './components/option-list';
|
|
25
26
|
export * from './components/select';
|
|
26
27
|
export * from './components/label';
|
|
27
28
|
export * from './components/form-field';
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { Dialog, DialogBottomSheet, DialogClose, DialogContent, DialogDescriptio
|
|
|
19
19
|
export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from './components/dropdown-menu.js';
|
|
20
20
|
export { FileUpload } from './components/file-upload.js';
|
|
21
21
|
export { FilterChip, FilterChipGroup } from './components/filter-chip.js';
|
|
22
|
+
export { CheckboxList, FilterMenu, optionListClassName, optionRowClassName } from './components/option-list.js';
|
|
22
23
|
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue } from './components/select.js';
|
|
23
24
|
export { FieldLabel, Label } from './components/label.js';
|
|
24
25
|
export { FormField } from './components/form-field.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterinternship/components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"workspaces": [
|
|
5
5
|
"playground"
|
|
6
6
|
],
|
|
@@ -106,6 +106,10 @@
|
|
|
106
106
|
"import": "./dist/components/filter-chip.js",
|
|
107
107
|
"types": "./dist/components/filter-chip.d.ts"
|
|
108
108
|
},
|
|
109
|
+
"./option-list": {
|
|
110
|
+
"import": "./dist/components/option-list.js",
|
|
111
|
+
"types": "./dist/components/option-list.d.ts"
|
|
112
|
+
},
|
|
109
113
|
"./select": {
|
|
110
114
|
"import": "./dist/components/select.js",
|
|
111
115
|
"types": "./dist/components/select.d.ts"
|
package/theme.css
CHANGED
|
@@ -84,6 +84,12 @@
|
|
|
84
84
|
@theme {
|
|
85
85
|
/* Default height for single-line form controls. */
|
|
86
86
|
--spacing-form-control: 2.25rem;
|
|
87
|
+
/* Option lists (menus, selects, dropdowns, autocomplete, filter menus):
|
|
88
|
+
an inset list of rounded rows with a little space between them. */
|
|
89
|
+
--spacing-option-inset: 0.375rem;
|
|
90
|
+
--spacing-option-gap: 0.125rem;
|
|
91
|
+
--spacing-option-x: 0.625rem;
|
|
92
|
+
--spacing-option-row: 2.5rem;
|
|
87
93
|
--spacing-field-label-gap: 0.25rem;
|
|
88
94
|
--text-page-heading: 2rem;
|
|
89
95
|
--text-page-heading--line-height: 1.2;
|