-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor: migrate CopyableValue from MUI to Radix UI #20261
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75bf770
refactor: migrate CopyableValue from MUI to Radix UI
jaaydenh e199c54
refactor: update SensitiveValue to pass className instead of css
jaaydenh 3c90fd2
fix: improvements
jaaydenh 6a2a508
fix: simplify and handle keyboard usage
jaaydenh e6a3bc9
chore: cleanup
jaaydenh 1c700a6
Merge branch 'main' into jaaydenh/refactor-copyable-value
jaaydenh 589a27a
chore: PR review updates
jaaydenh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,35 +1,91 @@ | ||
| import Tooltip, { type TooltipProps } from "@mui/material/Tooltip"; | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipProvider, | ||
| TooltipTrigger, | ||
| } from "components/Tooltip/Tooltip"; | ||
| import { useClickable } from "hooks/useClickable"; | ||
| import { useClipboard } from "hooks/useClipboard"; | ||
| import type { FC, HTMLAttributes } from "react"; | ||
| import { type FC, type HTMLAttributes, useState } from "react"; | ||
| import { cn } from "utils/cn"; | ||
|
|
||
| type TooltipSide = "top" | "right" | "bottom" | "left"; | ||
|
|
||
| interface CopyableValueProps extends HTMLAttributes<HTMLSpanElement> { | ||
| value: string; | ||
| placement?: TooltipProps["placement"]; | ||
| PopperProps?: TooltipProps["PopperProps"]; | ||
| side?: TooltipSide; | ||
| } | ||
|
|
||
| export const CopyableValue: FC<CopyableValueProps> = ({ | ||
| value, | ||
| placement = "bottom-start", | ||
| PopperProps, | ||
| side = "bottom", | ||
| children, | ||
| className, | ||
| role, | ||
| tabIndex, | ||
| onClick, | ||
| onKeyDown, | ||
| onKeyUp, | ||
| ...attrs | ||
| }) => { | ||
| const { showCopiedSuccess, copyToClipboard } = useClipboard(); | ||
| const [tooltipOpen, setTooltipOpen] = useState(false); | ||
| const [isFocused, setIsFocused] = useState(false); | ||
| const clickableProps = useClickable<HTMLSpanElement>(() => { | ||
| copyToClipboard(value); | ||
| setTooltipOpen(true); | ||
| }); | ||
|
|
||
| return ( | ||
| <Tooltip | ||
| title={showCopiedSuccess ? "Copied!" : "Click to copy"} | ||
| placement={placement} | ||
| PopperProps={PopperProps} | ||
| > | ||
| <span {...attrs} {...clickableProps} css={{ cursor: "pointer" }}> | ||
| {children} | ||
| </span> | ||
| </Tooltip> | ||
| <TooltipProvider delayDuration={100}> | ||
| <Tooltip | ||
| open={tooltipOpen} | ||
| onOpenChange={(shouldBeOpen) => { | ||
| // Always keep the tooltip open when in focus to handle issues when onOpenChange is unexpectedly false | ||
| if (!shouldBeOpen && isFocused) return; | ||
| setTooltipOpen(shouldBeOpen); | ||
| }} | ||
| > | ||
| <TooltipTrigger asChild> | ||
| <span | ||
| ref={clickableProps.ref} | ||
| {...attrs} | ||
| className={cn("cursor-pointer", className)} | ||
| role={role ?? clickableProps.role} | ||
| tabIndex={tabIndex ?? clickableProps.tabIndex} | ||
| onClick={(event) => { | ||
| clickableProps.onClick(event); | ||
| onClick?.(event); | ||
| }} | ||
| onKeyDown={(event) => { | ||
| clickableProps.onKeyDown(event); | ||
| onKeyDown?.(event); | ||
| }} | ||
| onKeyUp={(event) => { | ||
| clickableProps.onKeyUp(event); | ||
| onKeyUp?.(event); | ||
| }} | ||
| onMouseEnter={() => { | ||
| setIsFocused(true); | ||
| setTooltipOpen(true); | ||
| }} | ||
| onMouseLeave={() => { | ||
| setTooltipOpen(false); | ||
| }} | ||
| onFocus={() => { | ||
| setIsFocused(true); | ||
| }} | ||
|
Comment on lines
+75
to
+77
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. Do we also want to open the tooltip here? |
||
| onBlur={() => { | ||
| setTooltipOpen(false); | ||
| }} | ||
| > | ||
| {children} | ||
| </span> | ||
| </TooltipTrigger> | ||
| <TooltipContent side={side}> | ||
| {showCopiedSuccess ? "Copied!" : "Click to copy"} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </TooltipProvider> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is our goal with the focus state? Because right now, it looks like we're flipping the state within React, but we're not actually changing the focus behavior on the actual HTML element
The main area where I'm worried about drift between React and the underlying HTML is the
onMouseEnterprop settingisFocusedto true