Skip to content

Commit

Permalink
fix cron tooltip clipped
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Dec 2, 2024
1 parent 6f0f43d commit 28d628c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
23 changes: 14 additions & 9 deletions apps/web/src/components/Schedules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import cronstrue from 'cronstrue'
import { useSchedules } from '@/hooks/useSchedules'
import AddScheduleForm from './AddScheduleForm'
import { ChevronDoubleRightIcon } from '@heroicons/react/24/outline'
import { Tooltip } from '../Tooltips'
import { PortalTooltip, Tooltip } from '../Tooltips'
import ScrollBar from '../ScrollBar'

interface Props {
Expand Down Expand Up @@ -139,17 +139,22 @@ const CronSchedule = ({ schedule }: { schedule: CronSchedule }) => {

return (
<div>
<div className="font-medium pb-2">
<span className="pr-2">Cron: </span>
<div className="font-medium pb-2 flex items-center gap-x-2">
<span className="">Cron: </span>
<span className="rounded-sm px-2 py-1 font-mono bg-gray-100 border border-gray-200">
{cron}
</span>
<span className="ml-2 group relative">
<QuestionMarkCircleIcon className="w-4 h-4 inline-block text-gray-300" />

<div className="pointer-events-none absolute -top-2 left-1/2 -translate-y-full -translate-x-1/2 w-[124px] opacity-0 transition-opacity group-hover:opacity-100 bg-hunter-950 text-gray-400 text-xs p-2 rounded-md flex flex-col gap-y-1">
{tooltipText}
</div>
<span className="group relative">
<PortalTooltip
ignoreScrollableAncestor
content={
<div className="pointer-events-none w-[124px] bg-hunter-950 text-gray-400 text-xs p-2 rounded-md flex flex-col gap-y-1 -translate-x-1/2 translate-y-[2px]">
{tooltipText}
</div>
}
>
<QuestionMarkCircleIcon className="w-4 h-4 inline-block text-gray-300" />
</PortalTooltip>
</span>
</div>
<div className="pt-0.5 flex flex-col text-gray-400 gap-y-0.5">
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/Tooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ interface PortalTooltipProps {
className?: string
children: React.ReactNode
content: React.ReactNode
ignoreScrollableAncestor?: boolean
}
export function PortalTooltip(props: PortalTooltipProps) {
const ref = useRef<HTMLDivElement>(null)
const [active, setActive] = useState(false)
const { onOpen, dropdownPosition } = useDropdownPosition(ref, 'top')
const { onOpen, dropdownPosition } = useDropdownPosition(
ref,
'top',
0,
0,
props.ignoreScrollableAncestor
)
useEffect(() => {
if (active) {
onOpen()
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/hooks/dropdownPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function useDropdownPosition(
buttonRef: React.RefObject<HTMLElement>,
anchor: 'top' | 'bottom' = 'bottom',
paddingX = 0,
paddingY = 0
paddingY = 0,
ignoreScrollableAncestor = false
) {
const [dropdownPosition, setDropdownPosition] = useState({
top: 0,
Expand All @@ -28,7 +29,7 @@ function useDropdownPosition(
currentButtonRef.closest('.overflow-scroll') ??
currentButtonRef.closest('.overflow-auto')

if (scrollableAncestor) {
if (!ignoreScrollableAncestor && scrollableAncestor) {
const scrollableRect = scrollableAncestor.getBoundingClientRect()

setDropdownPosition({
Expand Down

0 comments on commit 28d628c

Please sign in to comment.