mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
add button component
This commit is contained in:
35
packages/editor/src/components/button.tsx
Normal file
35
packages/editor/src/components/button.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React, { useCallback, useRef } from "react";
|
||||
import { Button as RebassButton, ButtonProps } from "rebass";
|
||||
|
||||
export default function Button(props: ButtonProps) {
|
||||
const touchStartTime = useRef(0);
|
||||
|
||||
const onTouchEnd = useCallback((e) => {
|
||||
e.preventDefault();
|
||||
const now = Date.now();
|
||||
setTimeout(() => {
|
||||
if (touchStartTime.current === 0) return;
|
||||
if (now - touchStartTime.current > 300) return;
|
||||
//@ts-ignore
|
||||
props.onClick(e);
|
||||
}, 1);
|
||||
}, []);
|
||||
|
||||
const onTouchStart = useCallback((e) => {
|
||||
touchStartTime.current = Date.now();
|
||||
e.preventDefault();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<RebassButton
|
||||
{...props}
|
||||
onClick={props.onClick}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onTouchEnd={onTouchEnd}
|
||||
onTouchMove={() => {
|
||||
touchStartTime.current = 0;
|
||||
}}
|
||||
onTouchStart={onTouchStart}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user