From c041f2e8e1ed3b608e65a1209e02381ebd00cdb3 Mon Sep 17 00:00:00 2001 From: Nikita Gorin <36075690+NikitaCG@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:23:55 +0300 Subject: [PATCH] feat!: delete deprecated hooks (#1213) --- src/components/index.ts | 2 - src/components/utils/useOnFocusOutside.ts | 86 -------------------- src/hooks/useFileInput/index.ts | 2 +- src/hooks/useFileInput/useFileInput.ts | 11 +-- src/hooks/useIntersection/index.ts | 2 +- src/hooks/useIntersection/useIntersection.ts | 7 +- src/hooks/useSelect/types.ts | 4 - src/hooks/useSelect/useSelect.ts | 4 - 8 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 src/components/utils/useOnFocusOutside.ts diff --git a/src/components/index.ts b/src/components/index.ts index 5fe7b4428..d9b69db80 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -53,7 +53,5 @@ export {getComponentName} from './utils/getComponentName'; export * from './utils/withEventBrokerDomHandlers'; export * from './utils/layer-manager'; export {Lang, configure} from './utils/configure'; -/** @deprecated, drop on next major */ -export {useOnFocusOutside} from './utils/useOnFocusOutside'; export * from './utils/xpath'; export {getUniqId} from './utils/common'; diff --git a/src/components/utils/useOnFocusOutside.ts b/src/components/utils/useOnFocusOutside.ts deleted file mode 100644 index 98c6412bf..000000000 --- a/src/components/utils/useOnFocusOutside.ts +++ /dev/null @@ -1,86 +0,0 @@ -import React from 'react'; - -/** - * Callback on focus outside event. - * - * @callback onFocusOutsideCallback - * @param {FocusEvent} event - */ - -interface UseOnFocusOutsideProps { - enabled?: boolean; - onFocusOutside: (event: FocusEvent) => void; -} - -/** - * @deprecated use useFocusWithin instead, drop on next major - * - * Calls callback on focus element outside of some React sub-tree - * - * @param {Object} props - * @param {true} [props.enabled=true] - if false, will not track focus outside events - * @param {onFocusOutsideCallback} props.onFocusOutside - handler for focus outside event - * @returns container props - * - * @example - * - * function Select() { - * const [open, setOpen] = React.useState(false); - * - * const handleFocusOutside = React.useCallback(() => {setOpen(false);}, []); - * - * const {onFocus, onBlur} = useOnFocusOutside({onFocusOutside: handleFocusOutside, enabled: open}); - * - * return ( - * - * - * - * ... - * - * - * ); - * } - * } - */ -export function useOnFocusOutside({onFocusOutside, enabled = true}: UseOnFocusOutsideProps) { - const capturedRef = React.useRef(false); - - React.useEffect(() => { - if (!enabled) { - return undefined; - } - - const handleFocus = function (event: FocusEvent) { - capturedRef.current = false; - window.setTimeout(() => { - if (!capturedRef.current) { - onFocusOutside(event); - } - }, 0); - }; - - window.addEventListener('focus', handleFocus, {capture: true}); - - return () => { - window.removeEventListener('focus', handleFocus, {capture: true}); - }; - }, [enabled, onFocusOutside]); - - const handleFocusIn = React.useCallback(() => { - capturedRef.current = true; - }, []); - - const handleFocusOut = React.useCallback( - (event: React.FocusEvent) => { - if ( - enabled && - (event.relatedTarget === null || event.relatedTarget === document.body) - ) { - onFocusOutside(event.nativeEvent); - } - }, - [onFocusOutside, enabled], - ); - - return {onFocus: handleFocusIn, onBlur: handleFocusOut}; -} diff --git a/src/hooks/useFileInput/index.ts b/src/hooks/useFileInput/index.ts index a327ebb52..8189346d3 100644 --- a/src/hooks/useFileInput/index.ts +++ b/src/hooks/useFileInput/index.ts @@ -1,2 +1,2 @@ export {useFileInput} from './useFileInput'; -export type {UseFileInputProps, UseFileInputOutput, UseFileInputResult} from './useFileInput'; +export type {UseFileInputProps, UseFileInputResult} from './useFileInput'; diff --git a/src/hooks/useFileInput/useFileInput.ts b/src/hooks/useFileInput/useFileInput.ts index d777b920f..8af062b6f 100644 --- a/src/hooks/useFileInput/useFileInput.ts +++ b/src/hooks/useFileInput/useFileInput.ts @@ -6,10 +6,7 @@ export type UseFileInputProps = { onChange?: (event: React.ChangeEvent) => void; }; -/** - * @deprecated use UseFileInputResult instead - */ -export type UseFileInputOutput = { +export type UseFileInputResult = { controlProps: React.DetailedHTMLProps< React.InputHTMLAttributes, HTMLInputElement @@ -19,8 +16,6 @@ export type UseFileInputOutput = { }; }; -export type UseFileInputResult = UseFileInputOutput; - /** * Used to shape props for input with type "file". * @@ -42,7 +37,7 @@ export type UseFileInputResult = UseFileInputOutput; }; ``` */ -export function useFileInput({onUpdate, onChange}: UseFileInputProps): UseFileInputOutput { +export function useFileInput({onUpdate, onChange}: UseFileInputProps): UseFileInputResult { const ref = React.useRef(null); const handleChange = React.useCallback( @@ -59,7 +54,7 @@ export function useFileInput({onUpdate, onChange}: UseFileInputProps): UseFileIn ref.current?.click(); }, []); - const result: UseFileInputOutput = React.useMemo( + const result: UseFileInputResult = React.useMemo( () => ({ controlProps: { ref, diff --git a/src/hooks/useIntersection/index.ts b/src/hooks/useIntersection/index.ts index f91f08e04..becb9ef03 100644 --- a/src/hooks/useIntersection/index.ts +++ b/src/hooks/useIntersection/index.ts @@ -1,2 +1,2 @@ export {useIntersection} from './useIntersection'; -export type {UseIntersection, UseIntersectionProps} from './useIntersection'; +export type {UseIntersectionProps} from './useIntersection'; diff --git a/src/hooks/useIntersection/useIntersection.ts b/src/hooks/useIntersection/useIntersection.ts index cfcbbe452..dfa80beca 100644 --- a/src/hooks/useIntersection/useIntersection.ts +++ b/src/hooks/useIntersection/useIntersection.ts @@ -1,16 +1,11 @@ import React from 'react'; -/** - * @deprecated use UseIntersectionProps instead - */ -export type UseIntersection = { +export type UseIntersectionProps = { element: Element | null; options?: IntersectionObserverInit; onIntersect?: () => void; }; -export type UseIntersectionProps = UseIntersection; - export const useIntersection = ({element, options, onIntersect}: UseIntersectionProps) => { React.useEffect(() => { const observer = new IntersectionObserver(([entry]) => { diff --git a/src/hooks/useSelect/types.ts b/src/hooks/useSelect/types.ts index aec84bce5..c86e7454d 100644 --- a/src/hooks/useSelect/types.ts +++ b/src/hooks/useSelect/types.ts @@ -20,10 +20,6 @@ export type UseSelectResult = { activeIndex: number | undefined; handleSelection: (option: UseSelectOption) => void; handleClearValue: () => void; - /** - * @deprecated use toggleOpen - */ - setOpen: (val?: boolean | undefined) => void; toggleOpen: (val?: boolean | undefined) => void; setActiveIndex: React.Dispatch>; }; diff --git a/src/hooks/useSelect/useSelect.ts b/src/hooks/useSelect/useSelect.ts index a8db79e2a..94f30f99a 100644 --- a/src/hooks/useSelect/useSelect.ts +++ b/src/hooks/useSelect/useSelect.ts @@ -64,10 +64,6 @@ export const useSelect = (props: UseSelectProps): UseSelectRe activeIndex, handleSelection, handleClearValue, - /** - * @deprecated use toggleOpen - */ - setOpen: toggleOpen, toggleOpen, setActiveIndex, ...openState,