Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
import { ExternalLinkIcon } from '@heroicons/react/outline'
|
|
import clsx from 'clsx'
|
|
import Link from 'next/link'
|
|
|
|
import { track } from 'web/lib/service/analytics'
|
|
|
|
export type NavItem = {
|
|
name: string
|
|
trackingEventName?: string
|
|
href?: string
|
|
onClick?: () => void
|
|
icon?: React.ComponentType<{ className?: string }>
|
|
solidIcon?: React.ComponentType<{ className?: string }>
|
|
iconClassName?: string
|
|
external?: boolean
|
|
alwaysShowName?: boolean
|
|
prefetch?: boolean
|
|
children?: React.ReactNode
|
|
/** Optional secondary label rendered next to `name` (hidden on very narrow viewports). */
|
|
subLabel?: string
|
|
/** Optional class applied to the nav item container (e.g. for tighter padding). */
|
|
itemClassName?: string
|
|
}
|
|
|
|
export function SidebarItem(props: { item: NavItem; currentPage?: string }) {
|
|
const { item, currentPage } = props
|
|
|
|
const currentBasePath = '/' + (currentPage?.split('/')[1] ?? '')
|
|
const queryCleanedHref =
|
|
(item.href?.includes('?') ? item.href.split('?')[0] : item.href) ?? ''
|
|
const segmentCleanedHref =
|
|
queryCleanedHref.split('/').length > 2
|
|
? '/' + queryCleanedHref.split('/')[1]
|
|
: queryCleanedHref
|
|
const isCurrentPage =
|
|
currentBasePath === segmentCleanedHref && !item.href?.startsWith('https://')
|
|
|
|
const onClick = () => {
|
|
track('sidebar: ' + item.name)
|
|
item.onClick?.()
|
|
}
|
|
|
|
const sidebarClass = clsx(
|
|
isCurrentPage
|
|
? 'bg-primary-100 text-primary-700'
|
|
: 'text-ink-500 hover:bg-canvas-100 hover:text-ink-900',
|
|
'group flex w-full items-center rounded-lg px-3 py-2.5 text-sm font-medium transition-colors',
|
|
'focus-visible:bg-primary-100 outline-none'
|
|
)
|
|
|
|
const sidebarItem = (
|
|
<>
|
|
{item.icon && (
|
|
<item.icon
|
|
className={clsx(
|
|
isCurrentPage
|
|
? 'text-primary-700'
|
|
: 'text-ink-400 group-hover:text-ink-700',
|
|
' -ml-1 mr-3 h-6 w-6 flex-shrink-0',
|
|
item.iconClassName
|
|
)}
|
|
aria-hidden="true"
|
|
/>
|
|
)}
|
|
<span className="truncate">{item.children ?? item.name}</span>
|
|
{item.external && (
|
|
<ExternalLinkIcon className="ml-2 h-4 w-4" aria-hidden="true" />
|
|
)}
|
|
</>
|
|
)
|
|
|
|
if (item.href) {
|
|
return (
|
|
<Link
|
|
href={item.href}
|
|
aria-current={isCurrentPage ? 'page' : undefined}
|
|
onClick={onClick}
|
|
className={sidebarClass}
|
|
target={
|
|
item.external || !item.href.startsWith('/') ? '_blank' : undefined
|
|
}
|
|
>
|
|
{sidebarItem}
|
|
</Link>
|
|
)
|
|
} else {
|
|
return (
|
|
<button type="button" onClick={onClick} className={sidebarClass}>
|
|
{sidebarItem}
|
|
</button>
|
|
)
|
|
}
|
|
}
|