UNPKG

@pdftron/webviewer-react-toolkit

Version:

A React component library for integrating with PDFTron WebViewer API.

29 lines (28 loc) 1.12 kB
import { useCallback } from 'react'; /** * Returns the handler for onClick. Allows you to add specific options to the * event before passing it through to the default onClick. * @param onClick The onClick prop if it's available. * @param options UseOnClickOptions for the hook. */ export function useOnClick(onClick, options) { if (options === void 0) { options = {}; } var stopPropagation = !!options.stopPropagation; var preventDefault = !!options.preventDefault; var blurOnClick = !!options.blurOnClick; var disabled = !!options.disabled; var handler = useCallback(function (event) { if (preventDefault) event.preventDefault(); if (stopPropagation) event.stopPropagation(); if (disabled) return; if (blurOnClick) { var focused = document.activeElement; focused === null || focused === void 0 ? void 0 : focused.blur(); } onClick === null || onClick === void 0 ? void 0 : onClick(event); }, [preventDefault, stopPropagation, blurOnClick, onClick, disabled]); return handler; }