-
Notifications
You must be signed in to change notification settings - Fork 0
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 #12 from Explicit12/FN-1788_Remove-viewport-compon…
…ent_Dmytro-Holdobin Remove viewport component
- Loading branch information
Showing
12 changed files
with
9,547 additions
and
166 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { onMounted, ref, watch, computed } from "vue"; | ||
|
||
const BREAKPOINT_NAME = { | ||
xs: "xs", | ||
sm: "sm", | ||
md: "md", | ||
lg: "lg", | ||
xl: "xl", | ||
"2xl": "2xl", | ||
}; | ||
|
||
const BREAKPOINT = { | ||
xs: 0, | ||
sm: 640, | ||
md: 768, | ||
lg: 1024, | ||
xl: 1280, | ||
"2xl": 1536, | ||
}; | ||
|
||
const mobileDevices = ["xs", "sm"]; | ||
const portableDevices = ["xs", "sm", "md"]; | ||
|
||
export default function useBreakpoint() { | ||
let timeout; | ||
|
||
const windowWidth = ref(undefined); | ||
const currentBreakpoint = ref(BREAKPOINT_NAME.xs); | ||
|
||
const isMobileBreakpoint = computed(() => { | ||
return mobileDevices.includes(currentBreakpoint.value); | ||
}); | ||
|
||
const isTabletBreakpoint = computed(() => { | ||
return mobileDevices.includes(currentBreakpoint.value); | ||
}); | ||
|
||
const isLaptopBreakpoint = computed(() => { | ||
return currentBreakpoint.value === BREAKPOINT_NAME.lg; | ||
}); | ||
|
||
const isPortableBreakpoint = computed(() => { | ||
return portableDevices.includes(currentBreakpoint.value); | ||
}); | ||
|
||
const elementSize = computed(() => { | ||
return isMobileBreakpoint.value ? BREAKPOINT_NAME.md : BREAKPOINT_NAME.lg; | ||
}); | ||
|
||
onMounted(() => { | ||
windowWidth.value = window.innerWidth; | ||
|
||
window.addEventListener(resizeListener, { passive: true }); | ||
}); | ||
|
||
watch(windowWidth, setBreakpoint, { immediate: true }); | ||
|
||
function resizeListener() { | ||
if (timeout) { | ||
window.cancelAnimationFrame(timeout); | ||
} | ||
|
||
timeout = window.requestAnimationFrame(() => { | ||
windowWidth.value = window.innerWidth; | ||
}); | ||
} | ||
|
||
function setBreakpoint(newWindowWidth) { | ||
if (newWindowWidth === undefined) return; | ||
|
||
currentBreakpoint.value = "xs"; | ||
|
||
if (newWindowWidth >= BREAKPOINT.sm && newWindowWidth < BREAKPOINT.smd) { | ||
currentBreakpoint.value = "sm"; | ||
} else if (newWindowWidth >= BREAKPOINT.md && newWindowWidth < BREAKPOINT.lg) { | ||
currentBreakpoint.value = "md"; | ||
} else if (newWindowWidth >= BREAKPOINT.lg && newWindowWidth < BREAKPOINT.xl) { | ||
currentBreakpoint.value = "lg"; | ||
} else if (newWindowWidth >= BREAKPOINT.xl && newWindowWidth < BREAKPOINT["2xl"]) { | ||
currentBreakpoint.value = "xl"; | ||
} else if (newWindowWidth >= BREAKPOINT["2xl"]) { | ||
currentBreakpoint.value = "2xl"; | ||
} | ||
} | ||
|
||
return { | ||
isLaptopBreakpoint, | ||
isTabletBreakpoint, | ||
isMobileBreakpoint, | ||
isPortableBreakpoint, | ||
elementSize, | ||
}; | ||
} |
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
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
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
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.