Skip to content

Commit

Permalink
Add Link component
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinich Maxim authored and Marinich Maxim committed Mar 27, 2024
1 parent 435af5f commit 5ba72fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ npm-debug.log
dist
lib
static

!src/lib
2 changes: 1 addition & 1 deletion src/lib/react-alice-carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import VS, { EventData } from 'vanilla-swipe';
import { defaultProps } from './defaultProps';
import Link, { type LinkProps } from './views/DNDLink';
import Link, { type LinkProps } from './views/Link';
import * as Views from './views';
import * as Utils from './utils';
import {
Expand Down
34 changes: 34 additions & 0 deletions src/lib/views/Link.tsx
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>
);
}

0 comments on commit 5ba72fb

Please sign in to comment.