Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cron tooltip clipped #275

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading