File tree Expand file tree Collapse file tree 4 files changed +60
-15
lines changed
packages/core/useBreakpoints Expand file tree Collapse file tree 4 files changed +60
-15
lines changed Original file line number Diff line number Diff line change @@ -28,15 +28,37 @@ export const breakpointsBootstrapV5 = {
28
28
/**
29
29
* Breakpoints from Vuetify V2
30
30
*
31
- * @see https://vuetifyjs.com/en/features/breakpoints
31
+ * @see https://v2. vuetifyjs.com/en/features/breakpoints/
32
32
*/
33
- export const breakpointsVuetify = {
34
- xs : 600 ,
35
- sm : 960 ,
36
- md : 1264 ,
37
- lg : 1904 ,
33
+ export const breakpointsVuetifyV2 = {
34
+ xs : 0 ,
35
+ sm : 600 ,
36
+ md : 960 ,
37
+ lg : 1264 ,
38
+ xl : 1904 ,
39
+ }
40
+
41
+ /**
42
+ * Breakpoints from Vuetify V3
43
+ *
44
+ * @see https://vuetifyjs.com/en/styles/float/#overview
45
+ */
46
+ export const breakpointsVuetifyV3 = {
47
+ xs : 0 ,
48
+ sm : 600 ,
49
+ md : 960 ,
50
+ lg : 1280 ,
51
+ xl : 1920 ,
52
+ xxl : 2560 ,
38
53
}
39
54
55
+ /**
56
+ * Alias to `breakpointsVuetifyV2`
57
+ *
58
+ * @deprecated explictly use `breakpointsVuetifyV2` or `breakpointsVuetifyV3` instead
59
+ */
60
+ export const breakpointsVuetify = breakpointsVuetifyV2
61
+
40
62
/**
41
63
* Breakpoints from Ant Design
42
64
*
@@ -57,10 +79,11 @@ export const breakpointsAntDesign = {
57
79
* @see https://quasar.dev/style/breakpoints
58
80
*/
59
81
export const breakpointsQuasar = {
60
- xs : 600 ,
61
- sm : 1024 ,
62
- md : 1440 ,
63
- lg : 1920 ,
82
+ xs : 0 ,
83
+ sm : 600 ,
84
+ md : 1024 ,
85
+ lg : 1440 ,
86
+ xl : 1920 ,
64
87
}
65
88
66
89
/**
@@ -97,7 +120,7 @@ export const breakpointsMasterCss = {
97
120
/**
98
121
* Breakpoints from PrimeFlex
99
122
*
100
- * @see https://www.primefaces. org/primeflex/setup
123
+ * @see https://primeflex. org/installation
101
124
*/
102
125
export const breakpointsPrimeFlex = {
103
126
sm : 576 ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const reactiveStuff = ref<keyof typeof breakpointsTailwind>('sm')
10
10
const isGreaterThanBreakpoint = breakpoints .greaterOrEqual (() => reactiveStuff .value )
11
11
12
12
const current = breakpoints .current ()
13
+ const active = breakpoints .active ()
13
14
const xs = breakpoints .smaller (' sm' )
14
15
const xse = breakpoints .smallerOrEqual (' sm' )
15
16
const sm = breakpoints .between (' sm' , ' md' )
@@ -22,6 +23,7 @@ const xxl = breakpoints['2xl']
22
23
<template >
23
24
<div class =" font-mono" >
24
25
<div > Current breakpoints: {{ current }} </div >
26
+ <div > Active breakpoint: {{ active }} </div >
25
27
<div > xs(< ; {{ smWidth }}px): <BooleanDisplay :value =" xs" /></div >
26
28
<div > xs(< ; ={{ smWidth }}px): <BooleanDisplay :value =" xse" /></div >
27
29
<div > sm: <BooleanDisplay :value =" sm" /></div >
Original file line number Diff line number Diff line change @@ -19,14 +19,27 @@ const lgAndSmaller = breakpoints.smallerOrEqual('lg') // lg and smaller
19
19
const smallerThanLg = breakpoints .smaller (' lg' ) // only smaller than lg
20
20
```
21
21
22
- ``` js
22
+ ``` vue
23
+ <script setup lang="ts">
23
24
import { useBreakpoints } from '@vueuse/core'
24
25
25
26
const breakpoints = useBreakpoints({
27
+ mobile: 0, // optional
26
28
tablet: 640,
27
29
laptop: 1024,
28
30
desktop: 1280,
29
31
})
30
32
33
+ // Can be 'mobile' or 'tablet' or 'laptop' or 'desktop'
34
+ const activeBreakpoint = breakpoints.active()
35
+
36
+ // true or false
31
37
const laptop = breakpoints.between('laptop', 'desktop')
38
+ </script>
39
+
40
+ <template>
41
+ <div :class="activeBreakpoint">
42
+ ...
43
+ </div>
44
+ </template>
32
45
```
Original file line number Diff line number Diff line change @@ -71,6 +71,11 @@ export function useBreakpoints<K extends string>(
71
71
return shortcuts
72
72
} , { } as Record < K , Ref < boolean > > )
73
73
74
+ function current ( ) {
75
+ const points = Object . keys ( breakpoints ) . map ( i => [ i , greaterOrEqual ( i as K ) ] as const )
76
+ return computed ( ( ) => points . filter ( ( [ , v ] ) => v . value ) . map ( ( [ k ] ) => k ) )
77
+ }
78
+
74
79
return Object . assign ( shortcutMethods , {
75
80
greaterOrEqual,
76
81
smallerOrEqual,
@@ -98,9 +103,10 @@ export function useBreakpoints<K extends string>(
98
103
isInBetween ( a : MaybeRefOrGetter < K > , b : MaybeRefOrGetter < K > ) {
99
104
return match ( `(min-width: ${ getValue ( a ) } ) and (max-width: ${ getValue ( b , - 0.1 ) } )` )
100
105
} ,
101
- current ( ) {
102
- const points = Object . keys ( breakpoints ) . map ( i => [ i , greaterOrEqual ( i as K ) ] as const )
103
- return computed ( ( ) => points . filter ( ( [ , v ] ) => v . value ) . map ( ( [ k ] ) => k ) )
106
+ current,
107
+ active ( ) {
108
+ const bps = current ( )
109
+ return computed ( ( ) => bps . value . length === 0 ? '' : bps . value . at ( - 1 ) )
104
110
} ,
105
111
} )
106
112
}
@@ -117,4 +123,5 @@ export type UseBreakpointsReturn<K extends string = string> = {
117
123
isSmallerOrEqual : ( k : MaybeRefOrGetter < K > ) => boolean
118
124
isInBetween : ( a : MaybeRefOrGetter < K > , b : MaybeRefOrGetter < K > ) => boolean
119
125
current : ( ) => ComputedRef < string [ ] >
126
+ active : ComputedRef < string >
120
127
} & Record < K , ComputedRef < boolean > >
You can’t perform that action at this time.
0 commit comments