8000 refactor: move `isVisible()` to utils · mastercodekw/coreui-react@327632e · GitHub
[go: up one dir, main page]

Skip to content

Commit 327632e

Browse files
committed
refactor: move isVisible() to utils
1 parent 9638f40 commit 327632e

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

packages/coreui-react/src/components/carousel/CCarousel.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,9 @@ import React, {
1010
import PropTypes from 'prop-types'
1111
import classNames from 'classnames'
1212

13+
import { isVisible } from '../../utils'
1314
import { useForkedRef } from '../../utils/hooks'
1415

15-
const isVisible = (element: HTMLDivElement) => {
16-
const rect = element.getBoundingClientRect()
17-
return (
18-
rect.top >= 0 &&
19-
rect.left >= 0 &&
20-
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
21-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
22-
)
23-
}
24-
2516
export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
2617
/**
2718
* index of the active item.

packages/coreui-react/src/ 8000 components/sidebar/CSidebar.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createPortal } from 'react-dom'
33
import PropTypes from 'prop-types'
44
import classNames from 'classnames'
55

6+
import { isVisible } from '../../utils'
67
import { useForkedRef } from '../../utils/hooks'
78
import { CBackdrop } from '../backdrop/CBackdrop'
89

@@ -52,16 +53,6 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
5253
const isOnMobile = (element: HTMLDivElement) =>
5354
Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
5455

55-
const isVisible = (element: HTMLDivElement) => {
56-
const rect = element.getBoundingClientRect()
57-
return (
58-
rect.top >= 0 &&
59-
rect.left >= 0 &&
60-
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
61-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
62-
)
63-
}
64-
6556
export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
6657
(
6758
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import isVisible from './isVisible'
2+
3+
export { isVisible }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const isVisible = (element: HTMLElement) => {
2+
const rect = element.getBoundingClientRect()
3+
return (
4+
rect.top >= 0 &&
5+
rect.left >= 0 &&
6+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
7+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
8+
)
9+
}
10+
11+
export default isVisible

0 commit comments

Comments
 (0)
0