/** @jsxRuntime classic */
/** @jsx jsx */
import { type AllHTMLAttributes, type ReactNode, Fragment } from 'react'
import { useRouter } from 'next/router'
import { Stack, jsx, useTheme, Text } from '@keystone-ui/core'
import { Button } from '@keystone-ui/button'
import { Popover } from '@keystone-ui/popover'
import { MoreHorizontalIcon } from '@keystone-ui/icons/icons/MoreHorizontalIcon'
import { ChevronRightIcon } from '@keystone-ui/icons/icons/ChevronRightIcon'
import { type NavigationProps, type ListMeta, type AuthenticatedItem } from '../../types'
import { useKeystone } from '../context'
import { Link } from '../router'
import { SignoutButton } from './SignoutButton'
type NavItemProps = {
href: string
children: ReactNode
isSelected?: boolean
}
export const NavItem = ({ href, children, isSelected: _isSelected }: NavItemProps) => {
const { colors, palette, spacing, radii, typography } = useTheme()
const router = useRouter()
const isSelected = _isSelected !== undefined ? _isSelected : router.pathname === href
return (
{children}
)
}
const AuthenticatedItemDialog = ({ item }: { item: AuthenticatedItem | undefined }) => {
const { apiPath } = useKeystone()
const { spacing, typography } = useTheme()
return (
{item && item.state === 'authenticated' ? (
Signed in as {item.label}
) : (
process.env.NODE_ENV !== 'production' && (
GraphQL Playground and Docs
)
)}
{process.env.NODE_ENV === 'production' ? (
item && item.state === 'authenticated' &&
) : (
(
)}
>
API Explorer
GitHub Repository
Keystone Documentation
{item && item.state === 'authenticated' && }
)}
)
}
const PopoverLink = ({ children, ...props }: AllHTMLAttributes) => {
const { typography } = useTheme()
return (
{children}
)
}
export type NavigationContainerProps = Partial> & {
children: ReactNode
}
export const NavigationContainer = ({ authenticatedItem, children }: NavigationContainerProps) => {
const { spacing } = useTheme()
return (
)
}
export const ListNavItem = ({ list }: { list: ListMeta }) => {
const router = useRouter()
return (
{list.label}
)
}
type NavItemsProps = Pick & { include?: string[] }
export const ListNavItems = ({ lists = [], include = [] }: NavItemsProps) => {
const renderedList = include.length > 0 ? lists.filter(i => include.includes(i.key)) : lists
return (
{renderedList.map((list: ListMeta) => {
return
})}
)
}
export function Navigation () {
const {
adminMeta: { lists },
adminConfig,
authenticatedItem,
visibleLists,
} = useKeystone()
if (visibleLists.state === 'loading') return null
// This visible lists error is critical and likely to result in a server restart
// if it happens, we'll show the error and not render the navigation component/s
if (visibleLists.state === 'error') {
return (
{visibleLists.error instanceof Error
? visibleLists.error.message
: visibleLists.error[0].message}
)
}
const renderableLists = Object.keys(lists)
.map(key => {
if (!visibleLists.lists.has(key)) return null
return lists[key]
})
.filter((x): x is NonNullable => Boolean(x))
if (adminConfig?.components?.Navigation) {
return (
)
}
return (
Dashboard
)
}