-
Notifications
You must be signed in to change notification settings - Fork 607
feat: add override button to ratelimits #2950
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
2 commits
Select commit
Hold shift + click to select a range
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
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
80 changes: 80 additions & 0 deletions
80
apps/dashboard/components/navigation/copyable-id-button.tsx
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { Button } from "@unkey/ui"; | ||
| import { useRef } from "react"; | ||
| import { CopyButton } from "../dashboard/copy-button"; | ||
|
|
||
| type CopyableIDButtonProps = { | ||
| value: string; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export const CopyableIDButton = ({ value, className = "" }: CopyableIDButtonProps) => { | ||
| const textRef = useRef<HTMLDivElement>(null); | ||
| const pressTimer = useRef<NodeJS.Timeout | null>(null); | ||
| const copyButtonRef = useRef<HTMLButtonElement>(null); | ||
|
|
||
| const handleMouseDown = () => { | ||
| // Start a long-press timer | ||
| pressTimer.current = setTimeout(() => { | ||
| // For long-press, select the text | ||
| if (textRef.current) { | ||
| const range = document.createRange(); | ||
| range.selectNodeContents(textRef.current); | ||
| const selection = window.getSelection(); | ||
| if (selection) { | ||
| selection.removeAllRanges(); | ||
| selection.addRange(range); | ||
| } | ||
| } | ||
| }, 500); | ||
| }; | ||
|
|
||
| const handleMouseUp = () => { | ||
| // Clear the timer if mouse is released before long-press threshold | ||
| if (pressTimer.current) { | ||
| clearTimeout(pressTimer.current); | ||
| pressTimer.current = null; | ||
| } | ||
| }; | ||
|
|
||
| const handleMouseLeave = () => { | ||
| // Clear the timer if mouse leaves the button | ||
| if (pressTimer.current) { | ||
| clearTimeout(pressTimer.current); | ||
| pressTimer.current = null; | ||
| } | ||
| }; | ||
|
|
||
| const handleClick = (e: React.MouseEvent) => { | ||
| // Only handle click if it wasn't a long press | ||
| if (!window.getSelection()?.toString()) { | ||
| // Programmatically click the CopyButton if text isn't selected | ||
| copyButtonRef.current?.click(); | ||
| } else { | ||
| // If text is selected, don't trigger the copy | ||
| e.stopPropagation(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Button | ||
| variant="outline" | ||
| size="md" | ||
| className={`text-xs font-mono font-medium ph-no-capture h-8 bg-grayA-2 hover:bg-grayA-3 ${className}`} | ||
| onMouseDown={handleMouseDown} | ||
| onMouseUp={handleMouseUp} | ||
| onMouseLeave={handleMouseLeave} | ||
| onClick={handleClick} | ||
| > | ||
| <div className="flex gap-2 items-center justify-center"> | ||
| <div ref={textRef} className="select-text"> | ||
| {value} | ||
| </div> | ||
| <CopyButton | ||
| value={value} | ||
| ref={copyButtonRef} | ||
| className="pointer-events-none" // Make the button non-interactive directly | ||
| /> | ||
| </div> | ||
| </Button> | ||
| ); | ||
| }; | ||
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.