8000 change the `isVisible` utility name to `isInViewport` · coreui/coreui-vue@abd6230 · GitHub
[go: up one dir, main page]

Skip to content

Commit abd6230

Browse files
committed
change the isVisible utility name to isInViewport
1 parent 8d6fb3b commit abd6230

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

packages/coreui-vue/src/components/carousel/CCarousel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
watch,
1212
} from 'vue'
1313

14-
import { isVisible } from './../../utils'
14+
import { isInViewport } from './../../utils'
1515

1616
const CCarousel = defineComponent({
1717
name: 'CCarousel',
@@ -133,7 +133,7 @@ const CCarousel = defineComponent({
133133
const nextItemWhenVisible = () => {
134134
// Don't call next when the page isn't visible
135135
// or the carousel or its parent isn't visible
136-
if (!document.hidden && isVisible(carouselRef.value)) {
136+
if (!document.hidden && isInViewport(carouselRef.value)) {
137137
handleControlClick('next')
138138
}
139139
}
@@ -156,7 +156,7 @@ const CCarousel = defineComponent({
156156
}
157157

158158
const handleScroll = () => {
159-
if (!document.hidden && isVisible(carouselRef.value)) {
159+
if (!document.hidden && isInViewport(carouselRef.value)) {
160160
visible.value = true
161161
} else {
162162
visible.value = false

packages/coreui-vue/src/components/sidebar/CSidebar.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue'
22
import { CBackdrop } from '../backdrop'
33

4-
import { isVisible } from './../../utils'
4+
import { isInViewport } from './../../utils'
55

66
const isOnMobile = (element: HTMLDivElement) =>
77
Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
@@ -88,15 +88,15 @@ const CSidebar = defineComponent({
8888

8989
onMounted(() => {
9090
mobile.value = isOnMobile(sidebarRef.value)
91-
inViewport.value = isVisible(sidebarRef.value)
91+
inViewport.value = isInViewport(sidebarRef.value)
9292

9393
window.addEventListener('resize', () => handleResize())
9494
window.addEventListener('mouseup', handleClickOutside)
9595
window.addEventListener('keyup', handleKeyup)
9696

9797
sidebarRef.value.addEventListener('mouseup', handleOnClick)
9898
sidebarRef.value.addEventListener('transitionend', () => {
99-
inViewport.value = isVisible(sidebarRef.value)
99+
inViewport.value = isInViewport(sidebarRef.value)
100100
})
101101
})
102102

@@ -107,7 +107,7 @@ const CSidebar = defineComponent({
107107

108108
sidebarRef.value.removeEventListener('mouseup', handleOnClick)
109109
sidebarRef.value.removeEventListener('transitionend', () => {
110-
inViewport.value = isVisible(sidebarRef.value)
110+
inViewport.value = isInViewport(sidebarRef.value)
111111
})
112112
})
113113

@@ -118,7 +118,7 @@ const CSidebar = defineComponent({
118118

119119
const handleResize = () => {
120120
mobile.value = isOnMobile(sidebarRef.value)
121-
inViewport.value = isVisible(sidebarRef.value)
121+
inViewport.value = isInViewport(sidebarRef.value)
122122
}
123123

124124
const handleKeyup = (event: Event) => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import isVisible from './isVisible'
1+
import isInViewport from './isInViewport'
22

3-
export { isVisible }
3+
export { isInViewport }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const isInViewport = (element: HTMLElement) => {
2+
const rect = element.getBoundingClientRect()
3+
return (
4+
Math.floor(rect.top) >= 0 &&
5+
Math.floor(rect.left) >= 0 &&
6+
Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
7+
Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth)
8+
)
9+
}
10+
11+
export default isInViewport

packages/coreui-vue/src/utils/isVisible.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0