-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from KasperskyLab/fix/tabs-fixes
fix: tab refactoring, fix localization in 'more' tabs. fix hiding the last tab when it is placed
- Loading branch information
Showing
7 changed files
with
407 additions
and
172 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
packages/kaspersky-components/helpers/useIntersectionChildren.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { RefObject, useMemo } from 'react' | ||
import { useResizeObserver } from './useResizeObserver' | ||
|
||
/** Find position last inside element */ | ||
export const useIntersectionChildren = (ref: RefObject<Element>, padding = 0): number | undefined => { | ||
/** The hook calculates the intersection of the container and its children, returns the index of last fitting child | ||
@param ref External container ref | ||
@param padding Padding to consider when intersecting | ||
@param wrapperQuerySelector selector of internal container | ||
@param renderCounter flag to trigger the recalculation | ||
*/ | ||
export const useIntersectionChildren = (ref: RefObject<Element>, padding = 0, wrapperQuerySelector?: string, renderCounter?: number): number | undefined => { | ||
const { right: containerRight } = useResizeObserver(ref) ?? { right: 0 } | ||
|
||
return useMemo<number | undefined>(() => { | ||
const container = ref.current | ||
if (container === null) return undefined | ||
const container = wrapperQuerySelector ? ref.current?.querySelector(wrapperQuerySelector) : ref.current | ||
if (container === null || container === undefined) return undefined | ||
|
||
const children = new Array(container.children.length) | ||
.fill(null) | ||
.map((_, i) => container.children[i]) | ||
|
||
const res = children.findIndex((child) => child.getBoundingClientRect().right + padding > containerRight) | ||
return res === -1 ? undefined : Math.max(res - 1, 0) | ||
}, [containerRight, ref]) | ||
}, [containerRight, ref, padding, renderCounter]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './Indicator' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.