Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

タブレット用のUI分岐を作成 #1317

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/use/isMobile.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { onUnmounted, Ref, ref } from 'vue'

const MOBILE_BREAKPOINT = '599'

const mql = window.matchMedia(`(min-width: ${MOBILE_BREAKPOINT}px)`)

const useIsMobile = (): { isMobile: Ref<boolean> } => {
const isMobile = ref(!mql.matches)

const onChange = (e: MediaQueryListEvent) => {
isMobile.value = !e.matches
}

mql.addEventListener('change', onChange)
onUnmounted(() => {
mql.removeEventListener('change', onChange)
})
import useBreakpoint from '/@/use/useBreakpoint'

const useIsMobile = () => {
const { isSmaller: isMobile } = useBreakpoint('599')
return { isMobile }
}

Expand Down
8 changes: 8 additions & 0 deletions src/use/isTablet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import useBreakpoint from '/@/use/useBreakpoint'

const useIsTablet = () => {
const { isSmaller: IsTablet } = useBreakpoint('1023')
return { IsTablet }
}

export default useIsTablet
21 changes: 21 additions & 0 deletions src/use/useBreakpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { onUnmounted, ref } from 'vue'
import type { Ref } from 'vue'

Check warning on line 2 in src/use/useBreakpoint.ts

View workflow job for this annotation

GitHub Actions / Lint

'Ref' is defined but never used

Check warning on line 2 in src/use/useBreakpoint.ts

View workflow job for this annotation

GitHub Actions / Lint

'Ref' is defined but never used

const useBreakpoint = (breakpoint: string) => {
const mql = window.matchMedia(`(min-width: ${breakpoint}px)`)

const isSmaller = ref(!mql.matches)

const onChange = (e: MediaQueryListEvent) => {
isSmaller.value = !e.matches
}

mql.addEventListener('change', onChange)
onUnmounted(() => {
mql.removeEventListener('change', onChange)
})

return { isSmaller }
}

export default useBreakpoint
Loading