Skip to content

Commit

Permalink
fix: tooltip styles
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jan 25, 2024
1 parent 6bf0285 commit afe507a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/components/ui/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
useHover,
useInteractions,
useRole,
useTransitionStyles,
} from "@floating-ui/react"

import { cn } from "~/lib/utils"
Expand All @@ -39,12 +38,13 @@ export const Tooltip = ({
}: Props) => {
const [open, setOpen] = useState(false)

const { x, y, refs, strategy, context } = useFloating({
const { floatingStyles, refs, context } = useFloating({
placement,
open,
onOpenChange: setOpen,
middleware: [offset(5), flip(), shift({ padding: 8 })],
whileElementsMounted: autoUpdate,
transform: false,
})

const { getReferenceProps, getFloatingProps } = useInteractions([
Expand All @@ -54,12 +54,8 @@ export const Tooltip = ({
useDismiss(context),
])

const { isMounted, styles } = useTransitionStyles(context, {
duration: 100,
})

return (
<div className="relative">
<>
<div
ref={refs.setReference}
{...getReferenceProps()}
Expand All @@ -72,19 +68,14 @@ export const Tooltip = ({
{children}
</div>
<AnimatePresence>
{isMounted && (
{open && (
<m.div
ref={refs.setFloating}
style={floatingStyles}
className={cn(
"bg-zinc-600 text-white rounded-lg shadow-lg px-3 py-1 whitespace-nowrap",
className,
)}
style={{
position: strategy,
top: y ?? "0",
left: x ?? "0",
...styles,
}}
initial={{ translateY: "10px", opacity: 0 }}
animate={{ translateY: "0px", opacity: 1 }}
exit={{ translateY: "10px", opacity: 0 }}
Expand All @@ -94,6 +85,6 @@ export const Tooltip = ({
</m.div>
)}
</AnimatePresence>
</div>
</>
)
}

0 comments on commit afe507a

Please sign in to comment.