Skip to content
On this page

useBreakpoints

Category
Last Changed
7 days ago

Reactive viewport breakpoints

Demo

sm: false
md: false
lg: false
xl: false
2xl: false
3xl: false

Usage

import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'

const breakpoints = useBreakpoints(breakpointsTailwind)

const smAndLarger = breakpoints.greater('sm')
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'

const breakpoints = useBreakpoints(breakpointsTailwind)

const smAndLarger = breakpoints.greater('sm')
import { useBreakpoints } from '@vueuse/core'

const breakpoints = useBreakpoints({
  tablet: 640,
  laptop: 1024,
  desktop: 1280,
})

const laptop = breakpoints.between('laptop', 'desktop')
import { useBreakpoints } from '@vueuse/core'

const breakpoints = useBreakpoints({
  tablet: 640,
  laptop: 1024,
  desktop: 1280,
})

const laptop = breakpoints.between('laptop', 'desktop')

Type Declarations

export * from "./breakpoints"
export declare type Breakpoints<K extends string = string> = Record<
  K,
  number | string
>
/**
 * Reactively viewport breakpoints
 *
 * @see https://vueuse.org/useBreakpoints
 * @param options
 */
export declare function useBreakpoints<K extends string>(
  breakpoints: Breakpoints<K>,
  options?: ConfigurableWindow
): {
  greater: (k: K) => Ref<boolean>
  smaller(k: K): Ref<boolean>
  between(a: K, b: K): Ref<boolean>
  isGreater(k: K): boolean
  isSmaller(k: K): boolean
  isInBetween(a: K, b: K): boolean
} & Record<K, Ref<boolean>>
export declare type UseBreakpointsReturn<K extends string = string> = {
  greater: (k: K) => Ref<boolean>
  smaller(k: K): Ref<boolean>
  between(a: K, b: K): Ref<boolean>
  isGreater(k: K): boolean
  isSmaller(k: K): boolean
  isInBetween(a: K, b: K): boolean
} & Record<K, Ref<boolean>>
export * from "./breakpoints"
export declare type Breakpoints<K extends string = string> = Record<
  K,
  number | string
>
/**
 * Reactively viewport breakpoints
 *
 * @see https://vueuse.org/useBreakpoints
 * @param options
 */
export declare function useBreakpoints<K extends string>(
  breakpoints: Breakpoints<K>,
  options?: ConfigurableWindow
): {
  greater: (k: K) => Ref<boolean>
  smaller(k: K): Ref<boolean>
  between(a: K, b: K): Ref<boolean>
  isGreater(k: K): boolean
  isSmaller(k: K): boolean
  isInBetween(a: K, b: K): boolean
} & Record<K, Ref<boolean>>
export declare type UseBreakpointsReturn<K extends string = string> = {
  greater: (k: K) => Ref<boolean>
  smaller(k: K): Ref<boolean>
  between(a: K, b: K): Ref<boolean>
  isGreater(k: K): boolean
  isSmaller(k: K): boolean
  isInBetween(a: K, b: K): boolean
} & Record<K, Ref<boolean>>

Source

SourceDemoDocs

Contributors

Anthony Fu
webfansplz
Ege İliklier
Shinigami
Alex Kozack
taidaid
wheat
Azri Kahar

Changelog

v6.8.0 on 11/6/2021
0bcf5 - feat: shortcuts (#905)
v6.4.0 on 9/17/2021
130c3 - feat: add breakpoints for Quasar (#756)
v4.11.2 on 5/30/2021
68c7d - feat(typedef): add return typedefs (#543) (#544)
v4.6.3 on 3/31/2021
0a0f7 - feat: add more breakpoint presets
e6def - feat: isGreater/isSmaller for one-time check
a32d4 - fix: useBreakpoints smaller should be < rather than <=, closes #404 (#406)
v4.6.0 on 3/25/2021
535a4 - feat: new function (#392)
useBreakpoints has loaded