- Notifications
You must be signed in to change notification settings - Fork1.1k
refactor: replace MUI Tooltip with MiniTooltip#20027
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
3e71889262df488cbcb7b062dc859438da7f2e21a8e0e2bcdfd622772991d90d843fa99398e0d8b1e512dc2adf8bfb263d0e100ba2da4f52File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| Tooltip, | ||
| TooltipArrow, | ||
| TooltipContent, | ||
| type TooltipContentProps, | ||
| TooltipProvider, | ||
| TooltipTrigger, | ||
| } from "components/Tooltip/Tooltip"; | ||
| import { type FC, type ReactNode, useState } from "react"; | ||
| import { cn } from "utils/cn"; | ||
| type MiniTooltipProps = Omit<TooltipContentProps, "title"> & { | ||
| title: ReactNode; | ||
| arrow?: boolean; | ||
| open?: boolean; | ||
| }; | ||
| const MiniTooltip: FC<MiniTooltipProps> = ({ | ||
| title, | ||
| children, | ||
| arrow, | ||
| open = false, | ||
| ...contentProps | ||
| }) => { | ||
| const [isOpen, setIsOpen] = useState(open); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think it's fine to have state here, but the current implementation will cause bugs. If the I think this will work constMiniTooltip:FC<MiniTooltipProps>=({// No default assignmentopen,// Also destructure onOpenChange, even if it's not defined onOpenChange,...contentProps})=>{const[isOpen,setIsOpen]=useState(false);constactiveIsOpen=open??isOpen;// Sync state change to both so that if the component ever flips from// controlled to uncontrolled, the other piece of state won't be lagging behindconsthandleOpenChange=(newOpen:boolean)=>{setIsOpen(newOpen);onOpenChange?.(newOpen);}; | ||
| return ( | ||
| <TooltipProvider> | ||
| <Tooltip delayDuration={0} open={isOpen} onOpenChange={setIsOpen}> | ||
| <TooltipTrigger | ||
| asChild | ||
| aria-label={typeof title === "string" ? title : undefined} | ||
| > | ||
| {children} | ||
| </TooltipTrigger> | ||
| <TooltipContent | ||
| collisionPadding={16} | ||
| side="bottom" | ||
| {...contentProps} | ||
| className={cn( | ||
| "max-w-[300px] bg-surface-secondary border-surface-quaternary text-content-primary text-xs", | ||
| contentProps.className, | ||
| )} | ||
| > | ||
| {title} | ||
| {arrow && <TooltipArrow className="fill-surface-quaternary" />} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </TooltipProvider> | ||
| ); | ||
| }; | ||
| export default MiniTooltip; | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.