Skip to content

Commit 5ba72fb

Browse files
Marinich MaximMarinich Maxim
Marinich Maxim
authored and
Marinich Maxim
committed
Add Link component
1 parent 435af5f commit 5ba72fb

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ npm-debug.log
6969
dist
7070
lib
7171
static
72+
73+
!src/lib

src/lib/react-alice-carousel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import VS, { EventData } from 'vanilla-swipe';
33
import { defaultProps } from './defaultProps';
4-
import Link, { type LinkProps } from './views/DNDLink';
4+
import Link, { type LinkProps } from './views/Link';
55
import * as Views from './views';
66
import * as Utils from './utils';
77
import {

src/lib/views/Link.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import type { AnchorHTMLAttributes, PropsWithChildren, MouseEvent } from 'react';
3+
4+
export type LinkProps = PropsWithChildren<AnchorHTMLAttributes<HTMLAnchorElement>>;
5+
6+
export default function Link(props: LinkProps) {
7+
const coords: Record<string, number | null> = {
8+
xDown: null,
9+
xUp: null,
10+
};
11+
12+
const handleOnMouseDown = (e: MouseEvent) => {
13+
e.preventDefault();
14+
coords.xUp = null;
15+
coords.xDown = e.clientX;
16+
};
17+
18+
const handleMouseUp = (e: MouseEvent) => {
19+
e.preventDefault();
20+
coords.xUp = e.clientX;
21+
};
22+
23+
const handleOnClick = (e: MouseEvent) => {
24+
if (coords.xDown !== coords.xUp) {
25+
e.preventDefault();
26+
}
27+
};
28+
29+
return (
30+
<a onClick={handleOnClick} onMouseDown={handleOnMouseDown} onMouseUp={handleMouseUp} {...props}>
31+
{props.children}
32+
</a>
33+
);
34+
}

0 commit comments

Comments
 (0)