0.1.5 • Published 2 years ago

use-more-than-click v0.1.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

React use more than click npm npm type definitions

Handles double clicks and long presses on buttons.

example

Installation

npm install use-more-than-click

How to use

You can get inspired by Example here and Storybook demo here.

import { useMoreThanClick } from 'use-more-than-click'
import { useRef } from 'react'

const MyApp = () => {
	const ref = useRef(null)

	useMoreThanClick(ref, (actionType) => {
		alert(`You've performed ${actionType}.`)
	})

	return <button ref={ref}>Click me</button>
}

Parameters

useMoreThanClick(ref, actionHandler, progressHandler, options)

ref

Element ref created by useRef.

actionHandler

Callback called after user successfully performs double click on long press.

progressHandler

Callback called every time progress updates. Progress indicating how close is user to performing an action (triggering actionHandler). 0 meaning hasn't tried yet and 1 indicates complete long press.

options

namedescriptiontypedefault
firstSingleClickProgressHow much should the progress be set to after a first short click to indicate that more than click is expected.number from 0 to 10.3
minimumHoldDurationHow much time should pass while holding before assuming user is trying to hold.number in milliseconds300
holdDurationToActionFor how long should user hold to trigger action callback.number in milliseconds800
decayDurationHow long it takes to reset to initial state after unfinished hold.number in milliseconds1000
decayAfterActionDurationHow long it takes to reset after triggered action.number in milliseconds200
doubleClickMaximumIntervalMaximum accepted delay between first and second click to be identified as a double click.number in milliseconds500

Development

Run npm start and npm run storybook parallelly.

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago