From 6ad4a78ca202ecc6e843d14f0c71f922d0845828 Mon Sep 17 00:00:00 2001 From: Nikita Gorin <36075690+NikitaCG@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:48:33 +0300 Subject: [PATCH] fix: start refactor hooks: useOutsideClick (#1035) --- CODEOWNERS | 3 +++ package.json | 1 + src/components/index.ts | 1 - src/hooks/index.ts | 1 + src/hooks/useOutsideClick/README.md | 18 ++++++++++++++++++ .../useOutsideClick/__tests__/Demo.tsx | 0 .../__tests__/useOutsideClick.test.tsx | 0 .../utils => hooks}/useOutsideClick/index.ts | 0 .../useOutsideClick/useOutsideClick.tsx | 0 src/index.ts | 1 + 10 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/hooks/index.ts create mode 100644 src/hooks/useOutsideClick/README.md rename src/{components/utils => hooks}/useOutsideClick/__tests__/Demo.tsx (100%) rename src/{components/utils => hooks}/useOutsideClick/__tests__/useOutsideClick.test.tsx (100%) rename src/{components/utils => hooks}/useOutsideClick/index.ts (100%) rename src/{components/utils => hooks}/useOutsideClick/useOutsideClick.tsx (100%) diff --git a/CODEOWNERS b/CODEOWNERS index 29ccb1a503..2d52a78e3d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -41,6 +41,9 @@ /src/components/Toaster @ogonkov /src/components/theme @resure /src/components/Pagination @jhoncool + +/src/hooks/useOutsideClick @NikitaCG + # Allow everyone to update dependencies /package.json /package-lock.json diff --git a/package.json b/package.json index c6a7c1ae2f..949b813651 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "lint:js": "eslint --ext .js,.jsx,.ts,.tsx .", "lint:styles": "stylelint '{styles,src}/**/*.scss'", "lint:prettier": "prettier --check '**/*.md'", + "lint:prettier:fix": "prettier --write '**/*.md'", "lint": "run-p lint:*", "typecheck": "tsc --noEmit", "prepublishOnly": "npm run build" diff --git a/src/components/index.ts b/src/components/index.ts index 99bb2799ed..3b820c3d7a 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -69,4 +69,3 @@ export * from './utils/useFileInput/useFileInput'; export {useActionHandlers} from './utils/useActionHandlers'; export {useUniqId} from './utils/useUniqId'; export {getLayersCount} from './utils/LayerManager'; -export * from './utils/useOutsideClick'; diff --git a/src/hooks/index.ts b/src/hooks/index.ts new file mode 100644 index 0000000000..bcd5297292 --- /dev/null +++ b/src/hooks/index.ts @@ -0,0 +1 @@ +export * from './useOutsideClick'; diff --git a/src/hooks/useOutsideClick/README.md b/src/hooks/useOutsideClick/README.md new file mode 100644 index 0000000000..5b516629bd --- /dev/null +++ b/src/hooks/useOutsideClick/README.md @@ -0,0 +1,18 @@ + + +# useOutsideClick + + + +```tsx +import {useOutsideClick} from '@gravity-ui/uikit'; +``` + +The `useOutsideClick` hook helps to track the click outside of the tracked element. + +## Properties + +| Name | Description | Type | Default | +| :------ | :---------------------------------------------------------------- | :---------------: | :-----: | +| ref | Ref-link to target of observation | `React.RefObject` | | +| handler | Callback when a click is triggered outside the observation target | `() => void` | | diff --git a/src/components/utils/useOutsideClick/__tests__/Demo.tsx b/src/hooks/useOutsideClick/__tests__/Demo.tsx similarity index 100% rename from src/components/utils/useOutsideClick/__tests__/Demo.tsx rename to src/hooks/useOutsideClick/__tests__/Demo.tsx diff --git a/src/components/utils/useOutsideClick/__tests__/useOutsideClick.test.tsx b/src/hooks/useOutsideClick/__tests__/useOutsideClick.test.tsx similarity index 100% rename from src/components/utils/useOutsideClick/__tests__/useOutsideClick.test.tsx rename to src/hooks/useOutsideClick/__tests__/useOutsideClick.test.tsx diff --git a/src/components/utils/useOutsideClick/index.ts b/src/hooks/useOutsideClick/index.ts similarity index 100% rename from src/components/utils/useOutsideClick/index.ts rename to src/hooks/useOutsideClick/index.ts diff --git a/src/components/utils/useOutsideClick/useOutsideClick.tsx b/src/hooks/useOutsideClick/useOutsideClick.tsx similarity index 100% rename from src/components/utils/useOutsideClick/useOutsideClick.tsx rename to src/hooks/useOutsideClick/useOutsideClick.tsx diff --git a/src/index.ts b/src/index.ts index 07635cbbc8..f76fd6f166 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,2 @@ export * from './components'; +export * from './hooks';