-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
468 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import type { LucideProps } from "lucide-react"; | ||
import { forwardRef } from "react"; | ||
import { type IconType, icons } from "./icons"; | ||
|
||
interface IconProps extends LucideProps { | ||
type: IconType; | ||
} | ||
|
||
export default function Icon(props: IconProps) { | ||
type El = SVGSVGElement; | ||
const Icon = forwardRef<El, IconProps>((props, ref) => { | ||
const { type, ...rest } = props; | ||
const Icon = icons[type]; | ||
return <Icon {...rest} />; | ||
} | ||
return <Icon {...rest} ref={ref} />; | ||
}); | ||
|
||
export default Icon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,25 @@ | ||
import { Transition } from "@headlessui/react"; | ||
import { useEffect, useState } from "react"; | ||
import type { RefObject } from "react"; | ||
import { createPortal } from "react-dom"; | ||
|
||
type Props<T extends HTMLElement> = { | ||
content: string; | ||
anchorRef?: RefObject<T>; | ||
}; | ||
|
||
export default function Tooltip<T extends HTMLElement>({ | ||
content, | ||
anchorRef, | ||
}: Props<T>) { | ||
const [top, setTop] = useState(0); | ||
const [left, setLeft] = useState(0); | ||
const [isHovered, setHovered] = useState(false); | ||
|
||
useEffect(() => { | ||
const element = anchorRef?.current; | ||
if (!element) return; | ||
|
||
function handleMouseEnter(this: HTMLElement) { | ||
const rect = this.getBoundingClientRect(); | ||
setTop(rect.top); | ||
setLeft(rect.left); | ||
setHovered(true); | ||
} | ||
|
||
function handleMouseLeave(this: HTMLElement) { | ||
setHovered(false); | ||
} | ||
|
||
element.addEventListener("mouseenter", handleMouseEnter); | ||
element.addEventListener("mouseleave", handleMouseLeave); | ||
|
||
return () => { | ||
element.removeEventListener("mouseenter", handleMouseEnter); | ||
element.removeEventListener("mouseleave", handleMouseLeave); | ||
}; | ||
}, [anchorRef]); | ||
|
||
return createPortal( | ||
<Transition | ||
as="div" | ||
show={isHovered} | ||
enter="transition-opacity duration-500" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="transition-opacity duration-150" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
className="fixed -translate-x-1/2 -translate-y-full -mt-2 ml-2.5 z-50 flex items-center justify-center px-3 py-2 rounded bg-gray-d2 dark:bg-white font-normal text-sm w-max max-w-[200px] text-white dark:text-navy-d4 after:content-[''] after:absolute after:top-full after:left-1/2 after:-ml-1 after:-translate-y-1/2 after:w-2 after:h-2 after:bg-gray-d2 after:dark:bg-white after:rotate-45" | ||
// had to move top+left position calculations to the props.style as the expected behavior wasn't there when setting these values | ||
// in className using tailwind | ||
style={{ | ||
top: `${Math.floor(top)}px`, | ||
left: `${Math.floor(left)}px`, | ||
}} | ||
> | ||
{content} | ||
</Transition>, | ||
document.body | ||
import type { ReactNode } from "react"; | ||
|
||
import { | ||
Portal, | ||
Root, | ||
TooltipProvider, | ||
Trigger, | ||
} from "@radix-ui/react-tooltip"; | ||
export { Content, TooltipArrow as Arrow } from "@radix-ui/react-tooltip"; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
/** must be wrapped by Content */ | ||
content: ReactNode; | ||
} | ||
export function Tooltip(props: Props) { | ||
return ( | ||
<TooltipProvider> | ||
<Root delayDuration={50}> | ||
<Trigger asChild>{props.children}</Trigger> | ||
<Portal>{props.content}</Portal> | ||
</Root> | ||
</TooltipProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import { useRef } from "react"; | ||
import Icon from "./Icon"; | ||
import Tooltip from "./Tooltip"; | ||
type Props = { | ||
classes?: string; | ||
size: number; | ||
}; | ||
import { Arrow, Content, Tooltip } from "./Tooltip"; | ||
type Props = { size: number }; | ||
|
||
export default function VerifiedIcon({ classes = "", size }: Props) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
export default function VerifiedIcon({ size }: Props) { | ||
return ( | ||
<> | ||
<Tooltip anchorRef={ref} content="Verified" /> | ||
<div ref={ref} className={classes}> | ||
<Icon | ||
type="Verified" | ||
size={size} | ||
className="text-white inline fill-blue" | ||
/> | ||
</div> | ||
</> | ||
<Tooltip | ||
content={ | ||
<Content className="bg-navy-d4 text-white px-4 py-2 rounded text-sm"> | ||
Verified | ||
<Arrow className="fill-navy-d4" /> | ||
</Content> | ||
} | ||
> | ||
<Icon | ||
type="Verified" | ||
size={size} | ||
className="text-white inline fill-blue" | ||
/> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.