1 import type { ClipboardEventHandler } from 'react';
3 import { c } from 'ttag';
5 import { useNotifications } from '@proton/components';
7 export const usePasteLengthLimiter = () => {
8 const { createNotification } = useNotifications();
12 originalOnPaste?: ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement>
13 ): ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement> =>
15 const text = event.clipboardData?.getData('text') ?? '';
16 const { value, selectionStart, selectionEnd } = event.currentTarget;
17 const base = value.length - ((selectionEnd ?? 0) - (selectionStart ?? 0));
19 if (base + text.length > maxLength) {
21 key: 'max-length-limiter',
25 .t`The text you're trying to paste is longer than the maximum allowed length of ${maxLength} characters.`,
29 originalOnPaste?.(event);