Skip to content

Commit 3bd84b2

Browse files
refactor: utils index
1 parent 74b4243 commit 3bd84b2

File tree

7 files changed

+36
-15
lines changed

7 files changed

+36
-15
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React, { useEffect, useState, useRef, useCallback, useImperativeHandle } from 'react'
22
import { autoUpdate } from '@floating-ui/dom'
33
import classNames from 'classnames'
4-
import debounce from 'utils/debounce'
4+
import {
5+
debounce,
6+
deepEqual,
7+
useIsomorphicLayoutEffect,
8+
getScrollParent,
9+
computeTooltipPosition,
10+
cssTimeToMs,
11+
} from 'utils'
12+
import type { IComputedPosition } from 'utils'
513
import { useTooltip } from 'components/TooltipProvider'
6-
import useIsomorphicLayoutEffect from 'utils/use-isomorphic-layout-effect'
7-
import computeTooltipPosition from 'utils/compute-positions'
8-
import type { IComputedPosition } from 'utils/compute-positions-types'
9-
import cssTimeToMs from 'utils/css-time-to-ms'
10-
import { deepEqual } from 'utils/deep-equal'
11-
import getScrollParent from 'utils/get-scroll-parent'
1214
import coreStyles from './core-styles.module.css'
1315
import styles from './styles.module.css'
1416
import type {

src/components/TooltipController/TooltipController.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
} from 'components/Tooltip/TooltipTypes'
1414
import { useTooltip } from 'components/TooltipProvider'
1515
import { TooltipContent } from 'components/TooltipContent'
16-
import cssSupports from 'utils/css-supports'
16+
import { cssSupports } from 'utils'
1717
import classNames from 'classnames'
1818
import type { ITooltipController } from './TooltipControllerTypes'
1919

src/test/utils.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import debounce from 'utils/debounce'
2-
import computeTooltipPosition from 'utils/compute-positions'
3-
import cssTimeToMs from 'utils/css-time-to-ms'
1+
import { debounce, computeTooltipPosition, cssTimeToMs } from 'utils'
42

53
// Tell Jest to mock all timeout functions
64
jest.useRealTimers()

src/utils/compute-positions-types.d.ts renamed to src/utils/compute-tooltip-position-types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CSSProperties } from 'react'
22
import type { Middleware, PlacesType } from '../components/Tooltip/TooltipTypes'
33

4-
export interface IComputePositions {
4+
export interface IComputePositionArgs {
55
elementReference?: Element | HTMLElement | null
66
tooltipReference?: Element | HTMLElement | null
77
tooltipArrowReference?: Element | HTMLElement | null

src/utils/compute-positions.ts renamed to src/utils/compute-tooltip-position.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computePosition, offset, shift, arrow, flip } from '@floating-ui/dom'
2-
import type { IComputePositions } from './compute-positions-types'
2+
import type { IComputePositionArgs } from './compute-tooltip-position-types'
33

44
const computeTooltipPosition = async ({
55
elementReference = null,
@@ -16,7 +16,7 @@ const computeTooltipPosition = async ({
1616
shift({ padding: 5 }),
1717
],
1818
border,
19-
}: IComputePositions) => {
19+
}: IComputePositionArgs) => {
2020
if (!elementReference) {
2121
// elementReference can be null or undefined and we will not compute the position
2222
// eslint-disable-next-line no-console

src/utils/deep-equal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const isObject = (object: unknown): object is Record<string, unknown> => {
22
return object !== null && typeof object === 'object'
33
}
44

5-
export const deepEqual = (object1: unknown, object2: unknown): boolean => {
5+
const deepEqual = (object1: unknown, object2: unknown): boolean => {
66
if (!isObject(object1) || !isObject(object2)) {
77
return object1 === object2
88
}
@@ -23,3 +23,5 @@ export const deepEqual = (object1: unknown, object2: unknown): boolean => {
2323
return val1 === val2
2424
})
2525
}
26+
27+
export default deepEqual

src/utils/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { IComputedPosition } from './compute-tooltip-position-types'
2+
import computeTooltipPosition from './compute-tooltip-position'
3+
import cssSupports from './css-supports'
4+
import cssTimeToMs from './css-time-to-ms'
5+
import debounce from './debounce'
6+
import deepEqual from './deep-equal'
7+
import getScrollParent from './get-scroll-parent'
8+
import useIsomorphicLayoutEffect from './use-isomorphic-layout-effect'
9+
10+
export type { IComputedPosition }
11+
export {
12+
computeTooltipPosition,
13+
cssSupports,
14+
cssTimeToMs,
15+
debounce,
16+
deepEqual,
17+
getScrollParent,
18+
useIsomorphicLayoutEffect,
19+
}

0 commit comments

Comments
 (0)