mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 07:30:21 +08:00
Replace docs command menu with Command Menu V2 from ui-patterns/CommandMenu. This introduces the prepackaged folder for the shared Command Menu, which contains commands that are shared across the sites (for example, docs search, theme switcher). Commands that are only applicable to a single site are now defined within that site's own app folder (put them wherever makes sense for your app folder organization, as long as you use the hooks within a global CommandProvider it will work...) Tested navigating around, using search and AI on laptop and mobile.
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
'use client'
|
|
|
|
import { forwardRef, useRef } from 'react'
|
|
|
|
import { CommandList_Shadcn_, cn } from 'ui'
|
|
|
|
import { CommandItem, type ICommand } from '../internal/Command'
|
|
import { CommandEmpty } from '../internal/CommandEmpty'
|
|
import { CommandGroup } from '../internal/CommandGroup'
|
|
import { useCommands } from './hooks/commandsHooks'
|
|
import { useQuery } from './hooks/queryHooks'
|
|
import { TextHighlighter } from './TextHighlighter'
|
|
|
|
const CommandList = forwardRef<
|
|
React.ElementRef<typeof CommandList_Shadcn_>,
|
|
React.ComponentPropsWithoutRef<typeof CommandList_Shadcn_>
|
|
>(({ className, ...props }, ref) => {
|
|
const commandSections = useCommands()
|
|
const query = useQuery()
|
|
|
|
const innerRef = useRef<HTMLDivElement | undefined>(undefined)
|
|
const setInnerRef = (elem: HTMLDivElement) => (innerRef.current = elem)
|
|
|
|
const setRef = (elem: HTMLDivElement) => {
|
|
if (ref) typeof ref === 'function' ? ref(elem) : (ref.current = elem)
|
|
setInnerRef(elem)
|
|
}
|
|
|
|
return (
|
|
<CommandList_Shadcn_
|
|
ref={setRef}
|
|
className={cn('max-h-[initial] overflow-y-auto overflow-x-hidden bg-transparent', className)}
|
|
{...props}
|
|
>
|
|
<CommandEmpty listRef={innerRef}>No results found.</CommandEmpty>
|
|
{commandSections.map((section) => {
|
|
if (section.commands.every((command) => command.defaultHidden) && !query) return null
|
|
|
|
return (
|
|
<CommandGroup key={section.id} heading={section.name} forceMount={section.forceMount}>
|
|
{section.commands
|
|
.filter((command) => !command.defaultHidden || query)
|
|
.map((_command) => {
|
|
const command = _command as ICommand // strip the readonly applied from the proxy
|
|
|
|
return (
|
|
<CommandItem key={command.id} command={command}>
|
|
<TextHighlighter>{command.name}</TextHighlighter>
|
|
</CommandItem>
|
|
)
|
|
})}
|
|
</CommandGroup>
|
|
)
|
|
})}
|
|
</CommandList_Shadcn_>
|
|
)
|
|
})
|
|
CommandList.displayName = CommandList_Shadcn_.displayName
|
|
|
|
export { CommandList }
|