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
import { ref, onUnmounted } from 'vue'; | |
export const useTimer = (callback = () => { }, step = 1000) => { | |
let timerVariableId = null; | |
let times = 0; | |
const isPaused = ref(false); | |
const stop = () => { | |
if (timerVariableId) { | |
clearInterval(timerVariableId); |
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
import { onMounted, onUnmounted } from 'vue'; | |
export const useScrollToBottom = (callback = () => { }) => { | |
const handleScrolling = () => { | |
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { | |
callback(); | |
} | |
} | |
onMounted(() => { |
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
import { onMounted, onUnmounted } from 'vue'; | |
export const useOnClickOutside = (ref = null, callback = () => {}) => { | |
function handleClickOutside(event) { | |
if (ref.value && !ref.value.contains(event.target)) { | |
callback() | |
} | |
} | |
onMounted(() => { |
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
import { ref, onMounted, onUnmounted } from 'vue'; | |
export const MOBILE = 'MOBILE' | |
export const TABLET = 'TABLET' | |
export const DESKTOP = 'DESKTOP' | |
export const useViewport = (config = {}) => { | |
const { mobile = null, tablet = null } = config; | |
let mobileWidth = mobile ? mobile : 768; | |
let tabletWidth = tablet ? tablet : 922; |
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
import { onMounted, onUnmounted } from 'vue'; | |
export const usePageVisibility = (callback = () => { }) => { | |
let hidden, visibilityChange; | |
if (typeof document.hidden !== "undefined") { | |
hidden = "hidden"; | |
visibilityChange = "visibilitychange"; | |
} else if (typeof document.msHidden !== "undefined") { | |
hidden = "msHidden"; |
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
function copyToClipboard(text) { | |
let input = document.createElement('input'); | |
input.setAttribute('value', text); | |
document.body.appendChild(input); | |
input.select(); | |
let result = document.execCommand('copy'); | |
document.body.removeChild(input); | |
return result; | |
} |
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
import { onMounted, onUnmounted } from 'vue'; | |
export const useNetworkStatus = (callback = () => { }) => { | |
const updateOnlineStatus = () => { | |
const status = navigator.onLine ? 'online' : 'offline'; | |
callback(status); | |
} | |
onMounted(() => { | |
window.addEventListener('online', updateOnlineStatus); |
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
import { ref } from 'vue'; | |
const getItem = (key, storage) => { | |
let value = storage.getItem(key); | |
if (!value) { | |
return null; | |
} | |
try { | |
return JSON.parse(value) | |
} catch (error) { |
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
Design is about simplicity |