:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { Tabs } from '@base-ui/react/tabs'
import { useActions, useValues } from 'kea'
import { IconSparkles, IconX } from '@posthog/icons'
import { Tooltip } from '@posthog/lemon-ui'
import { RenderKeybind } from 'lib/components/Shortcuts/RenderKeybind'
import { keyBinds } from 'lib/components/Shortcuts/shortcuts'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
import { cn } from 'lib/utils/css-classes'
import { SidePanelTab } from '~/types'
import { sidePanelLogic } from './sidePanelLogic'
import { sidePanelStateLogic } from './sidePanelStateLogic'
import { SIDE_PANEL_TABS } from './sidePanelTabs'
interface SidePanelNavigationProps {
activeTab: SidePanelTab
onTabChange: (tab: SidePanelTab) => void
children: React.ReactNode
}
export function SidePanelNavigation({ activeTab, onTabChange, children }: SidePanelNavigationProps): JSX.Element {
const { openSidePanel, closeSidePanel } = useActions(sidePanelStateLogic)
const { visibleTabs, deprecatedTabs } = useValues(sidePanelLogic)
// The first deprecated tab takes the auto margin, which pushes it and the rest to the far end.
const firstDeprecatedTab = visibleTabs.find((tab) => deprecatedTabs.includes(tab))
return (
<Tabs.Root
className={cn(
'scene-panel-navigation bg-surface-secondary flex flex-col overflow-hidden h-full min-w-0',
'z-[var(--z-scene-panel)] lg:rounded-none '
)}
value={activeTab}
onValueChange={(value) => onTabChange(value as SidePanelTab)}
>
{/* Tab buttons */}
<Tabs.List className="h-[50px] flex items-center justify-between gap-1 pl-2 pr-1.5 border-b border-primary shrink-0 relative z-0 grow overflow-x-auto">
{visibleTabs.map((tab) => {
const { Icon, label } = SIDE_PANEL_TABS[tab]!
return (
<Tooltip
key={tab}
title={
deprecatedTabs.includes(tab)
? `${label} (moving to the menus next to the page title)`
: label
}
delayMs={100}
>
<Tabs.Tab
value={tab}
render={(props) => (
<ButtonPrimitive
{...props}
onClick={() => openSidePanel(tab as SidePanelTab)}
data-attr={`context-panel-tab-${tab}`}
className={cn(
'size-[33px] @[660px]/side-panel:w-auto hover:bg-transparent group justify-center @[660px]/side-panel:justify-normal',
deprecatedTabs.includes(tab) && 'opacity-50 hover:opacity-100',
tab === firstDeprecatedTab && 'ml-auto'
)}
>
{tab === SidePanelTab.Max ? (
<IconSparkles
className={cn(
'text-ai size-4 -mt-[1px] ml-[2px] group-hover/button-primitive:animate-hue-rotate'
)}
/>
) : (
<Icon
className={cn(
'size-4 text-tertiary group-hover:text-primary',
activeTab === tab ? 'text-primary' : 'text-tertiary'
)}
/>
)}
<span
className={cn(
'hidden @[660px]/side-panel:block text-tertiary group-hover:text-primary',
activeTab === tab ? 'text-primary' : 'text-tertiary'
)}
>
{label}
</span>
</ButtonPrimitive>
)}
/>
</Tooltip>
)
})}
<Tabs.Indicator className="transform-gpu absolute top-1/2 left-0 z-[-1] h-[33px] w-[var(--active-tab-width)] translate-x-[var(--active-tab-left)] -translate-y-1/2 rounded bg-[var(--color-bg-fill-button-tertiary-active)] transition-all duration-200 ease-in-out" />
<ButtonPrimitive
onClick={() => {
closeSidePanel()
}}
data-attr="context-panel-close-button"
tooltip={
<>
Close context panel{' '}
<RenderKeybind className="relative -top-px" keybind={[keyBinds.toggleRightNav]} />
</>
}
tooltipPlacement="bottom-end"
iconOnly
className={cn('group size-[33px]', !firstDeprecatedTab && 'ml-auto')}
>
<IconX className="text-tertiary size-3 group-hover:text-primary z-10" />
</ButtonPrimitive>
</Tabs.List>
{/* Content area */}
<Tabs.Panel
className="h-full grow flex flex-col gap-2 relative -outline-offset-1 outline-blue-800 focus-visible:rounded-md overflow-hidden bg-surface-primary"
value={activeTab}
>
{children}
</Tabs.Panel>
</Tabs.Root>
)
}