-
Notifications
You must be signed in to change notification settings - Fork 92
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
Marinich Maxim
authored and
Marinich Maxim
committed
Mar 27, 2024
1 parent
435af5f
commit 5ba72fb
Showing
3 changed files
with
37 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,5 @@ npm-debug.log | |
dist | ||
lib | ||
static | ||
|
||
!src/lib |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import type { AnchorHTMLAttributes, PropsWithChildren, MouseEvent } from 'react'; | ||
|
||
export type LinkProps = PropsWithChildren<AnchorHTMLAttributes<HTMLAnchorElement>>; | ||
|
||
export default function Link(props: LinkProps) { | ||
const coords: Record<string, number | null> = { | ||
xDown: null, | ||
xUp: null, | ||
}; | ||
|
||
const handleOnMouseDown = (e: MouseEvent) => { | ||
e.preventDefault(); | ||
coords.xUp = null; | ||
coords.xDown = e.clientX; | ||
}; | ||
|
||
const handleMouseUp = (e: MouseEvent) => { | ||
e.preventDefault(); | ||
coords.xUp = e.clientX; | ||
}; | ||
|
||
const handleOnClick = (e: MouseEvent) => { | ||
if (coords.xDown !== coords.xUp) { | ||
e.preventDefault(); | ||
} | ||
}; | ||
|
||
return ( | ||
<a onClick={handleOnClick} onMouseDown={handleOnMouseDown} onMouseUp={handleMouseUp} {...props}> | ||
{props.children} | ||
</a> | ||
); | ||
} |