mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 11:55:05 +03:00
## Problem The `_Shadcn_` suffix isn't needed anymore on `Command` components ## Solution - Remove the `_Shadcn_` suffix - Simplify UI package exports - Apply prettier <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Simplified command component imports and exports across the UI library by removing internal naming aliases and adopting direct component references. Updated the public UI package barrel export to use wildcard re-exports for cleaner API surface. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46153?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
'use client'
|
|
|
|
import { useBreakpoint } from 'common'
|
|
import { InfoIcon, XIcon } from 'lucide-react'
|
|
import React, {
|
|
useCallback,
|
|
useEffect,
|
|
useId,
|
|
useRef,
|
|
useState,
|
|
type PropsWithChildren,
|
|
} from 'react'
|
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
import {
|
|
Button,
|
|
cn,
|
|
CommandEmpty,
|
|
Sheet,
|
|
SheetContent,
|
|
SheetHeader,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
|
|
interface PopUpProps extends PropsWithChildren {
|
|
tooltipContent: React.ReactNode
|
|
className?: string
|
|
contentContainerClassName?: string
|
|
}
|
|
|
|
const buttonClassName = cn(
|
|
'relative px-1 py-0 -my-px',
|
|
'rounded-sm bg-surface-200 border border-dashed',
|
|
'transition-colors hover:border-strong group/inline-popup'
|
|
)
|
|
|
|
const InfoTooltip = ({
|
|
children,
|
|
className,
|
|
tooltipContent,
|
|
contentContainerClassName,
|
|
}: PopUpProps) => {
|
|
const id = useId().replaceAll(':', '')
|
|
const timeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
|
|
const [mobileSheetOpen, setMobileSheetOpen] = useState(false)
|
|
const [tooltipOpen, _setTooltipOpen] = useState(false)
|
|
const isMobile = useBreakpoint('md')
|
|
|
|
const setTooltipOpen = useCallback(
|
|
(open: boolean) => {
|
|
_setTooltipOpen(open)
|
|
setMobileSheetOpen(true)
|
|
|
|
timeout.current = setTimeout(() => {
|
|
if (isMobile) return
|
|
const targetElem: HTMLElement | null = document.querySelector(`#tooltip-content-${id}`)
|
|
targetElem?.focus()
|
|
})
|
|
},
|
|
[_setTooltipOpen, id, isMobile]
|
|
)
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
if (timeout.current) {
|
|
clearTimeout(timeout.current)
|
|
}
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<>
|
|
<Tooltip open={tooltipOpen} onOpenChange={(open) => !isMobile && setTooltipOpen(open)}>
|
|
<TooltipTrigger asChild>
|
|
<span
|
|
role="button"
|
|
tabIndex={0}
|
|
onClick={() => setMobileSheetOpen(true)}
|
|
className={cn(buttonClassName, className)}
|
|
>
|
|
{children}
|
|
<InfoIcon
|
|
aria-hidden={true}
|
|
className="absolute p-px bg-background rounded-full -left-1.5 -top-1.5 w-3 h-3 text-foreground-lighter group-hover/inline-popup:text-foreground-light transition-colors"
|
|
/>
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent id={`tooltip-content-${id}`} className={contentContainerClassName}>
|
|
{tooltipContent}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
{isMobile && (
|
|
<Sheet open={mobileSheetOpen} onOpenChange={setMobileSheetOpen}>
|
|
<SheetContent
|
|
id={`mobile-sheet-content-${id}`}
|
|
showClose={false}
|
|
size="full"
|
|
side="bottom"
|
|
className={cn(
|
|
'md:hidden',
|
|
'text-foreground-lighter',
|
|
'rounded-t-lg overflow-hidden overflow-y-scroll',
|
|
'w-full h-fit min-h-[200px] py-2 px-4'
|
|
)}
|
|
>
|
|
<ErrorBoundary FallbackComponent={() => <CommandEmpty />}>
|
|
<SheetHeader className="flex items-center justify-between gap-2 px-0 py-2 mb-2 max-w-full">
|
|
<div className="flex items-center gap-2 max-w-[90%]">
|
|
<InfoIcon className="p-px min-w-4 min-h-4 text-foreground-lighter" />
|
|
<p className="italic text-foreground-light truncate">{children}</p>
|
|
</div>
|
|
<Button type="text" onClick={() => setMobileSheetOpen(false)} className="px-1">
|
|
<XIcon className="w-4 h-4 text-foreground-lighter" />
|
|
</Button>
|
|
</SheetHeader>
|
|
{tooltipContent}
|
|
</ErrorBoundary>
|
|
</SheetContent>
|
|
</Sheet>
|
|
)}
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default InfoTooltip
|