-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only update computed positions if it actually changed
- Loading branch information
1 parent
6f700f4
commit 31358c9
Showing
3 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
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
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,25 +1,30 @@ | ||
import { CSSProperties } from 'react' | ||
import type { Middleware } from '../components/Tooltip/TooltipTypes' | ||
import type { Middleware, PlacesType } from '../components/Tooltip/TooltipTypes' | ||
|
||
export interface IComputePositions { | ||
elementReference?: Element | HTMLElement | null | ||
tooltipReference?: Element | HTMLElement | null | ||
tooltipArrowReference?: Element | HTMLElement | null | ||
place?: | ||
| 'top' | ||
| 'top-start' | ||
| 'top-end' | ||
| 'right' | ||
| 'right-start' | ||
| 'right-end' | ||
| 'bottom' | ||
| 'bottom-start' | ||
| 'bottom-end' | ||
| 'left' | ||
| 'left-start' | ||
| 'left-end' | ||
place?: PlacesType | ||
offset?: number | ||
strategy?: 'absolute' | 'fixed' | ||
middlewares?: Middleware[] | ||
border?: CSSProperties['border'] | ||
} | ||
|
||
export interface IComputedPosition { | ||
tooltipStyles: { | ||
left?: string | ||
top?: string | ||
border?: CSSProperties['border'] | ||
} | ||
tooltipArrowStyles: { | ||
left?: string | ||
top?: string | ||
right?: string | ||
bottom?: string | ||
borderRight?: CSSProperties['border'] | ||
borderBottom?: CSSProperties['border'] | ||
} | ||
place: PlacesType | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const isObject = (object: unknown): object is Record<string, unknown> => { | ||
return object !== null && typeof object === 'object' | ||
} | ||
|
||
export const deepEqual = (object1: unknown, object2: unknown): boolean => { | ||
if (!isObject(object1) || !isObject(object2)) { | ||
return object1 === object2 | ||
} | ||
|
||
const keys1 = Object.keys(object1) | ||
const keys2 = Object.keys(object2) | ||
|
||
if (keys1.length !== keys2.length) { | ||
return false | ||
} | ||
|
||
return keys1.every((key) => { | ||
const val1 = object1[key] | ||
const val2 = object2[key] | ||
if (isObject(val1) && isObject(val2)) { | ||
return deepEqual(val1, val2) | ||
} | ||
return val1 === val2 | ||
}) | ||
} |