reegodev / vue-screen Goto Github PK
View Code? Open in Web Editor NEWReactive screen size and media query states for VueJS
Home Page: https://reegodev.github.io/vue-screen/
Reactive screen size and media query states for VueJS
Home Page: https://reegodev.github.io/vue-screen/
Hi!
First of all, many thanks for your work. :)
I initialize plugin with Nuxt like this (simplified):
['vue-screen/nuxt', {
phonePortrait: 0,
phoneStandard: 375,
phoneLandscape: 480,
...
breakpointsOrder: [
'phonePortrait',
'phoneStandard',
'phoneLandscape',
...
],
}],
I want to get access to breakpoints values through $screen object. Smth like:
this.$screen.breakpoints.phoneLandscape; // expect 480
I already tried to pass custom property in configuration object (with object i needed) and it works, but only client-side (because setter called in initMediaQueries, which runs only in browser link). I need this values with SSR.
I can ofc create external object with same params and inject it into Vue, but I think this issue in scope of this plugin.
So, what do you think about that? Can you provide this feature? How can I help? I think it will be useful not only for me.
Thanks!
Version
2.2.0
Describe the bug
In Bootstrap 2 phones
breakpoint ends at 480px, and bootstrap 3 starts at 768px
In Bootstrap 4 and 5 sm
breakpoint starts at 576px.
In vue-screen 2.2.0 bootstrap's sm
breakpoint starts at 480px. In develop branch it starts at 576px
Perhaps, there's a typo in bootstrap breakpoint value?
It might be obvious to others who're more experienced with Nuxt but I definitely tripped on this:
When integrating with Nuxt, the variable is $nuxt.$screen and not $screen as listed in the docs here
For now, the tailwind breakpoint is the same as the bootstrap's
bootstrap: https://github.com/reegodev/vue-screen/blob/develop/src/grids/bootstrap.js
tailwind: https://github.com/reegodev/vue-screen/blob/develop/src/grids/tailwind.js
The tailwind official breakpoint setting : https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
Spread operators are currently breaking ESM builds on Safari mobile <= 12 and most likely IE11 as well so users are forced to transpile node_modules
Plugin install fails with
Uncaught TypeError: Vue.observable is not a function
So I tried doing something like the following:
<template>
<Notifications v-if="showNotifications" />
</template>
<script>
export default {
computed: {
showNotifications() {
return this.$screen.lg;
},
},
}
</script>
and I get hit with this error:
If I remove the v-if, and the computed property, no errors.
What am I missing? Is there a default breakpoint setting so that SSR won't cause a mismatch?
Since there is a slight delay between lib initialization and actual rendering there is no way to tell whether the current brakepoint is actually the one that was set or we just didn't switch to a real one yet since lib is not yet initialized. It would be good if there would be some reactive property that would indicate that lib is initialized and we can actually account for the specified brakepoint.
Version
vue-screen: 2.3.0
vue: 3.3.4
@vue/test-utils: 2.3.2
Describe the bug
Following error message is displayed when running Vue Tests on a component that uses vue-screen:
TypeError: Cannot read properties of undefined (reading 'min')
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Test should run without errors
Hi! not sure if I'm doing something wrong or I'm missing a detail.
What I did was to set this screen sizes and some callbacks on my nuxt config file. Everything is working fine except it's showing the 'tablet' breakpoint when its 'desktop'. If I remove the "screen.touch" from the condition it display the correct one but I need to add the touch detection. The weird thing is that the touch value is correct when I log it
Thanks :)
Using nuxtjs, after following the documentation, I get the following error on "start", after building the application:
ERROR Cannot read property 'breakpoint' of undefined
The error is caused because I use the variable $screen
in a template, inside a <client-only>
tag.
The 'vue-screen' entry has been added to the 'modules' configuration, with custom breakpoints. The issue seems to be caused by the fact that the provided nuxt module has the "ssr" property set to true.
If I remove this line, all works fine and the plugin added by 'vue-screen' is loaded on server AND client sides.
this.addPlugin({
src: resolve(__dirname, 'src', 'nuxt', 'plugin.js'),
fileName: 'vue-screen.js',
//ssr: true,
options,
});
Am I missing something?
Hi,
I stumpled upon some issues with the vue-screen library on ipads. The client side js breaks
when I've added the nuxtjs vue-screen library on ios 12 and 13.
IOS 14 Works fine (Tested with Browserstack)
vue-screen version: 1.5.2
TypeError: _query.addEventListener is not a function. (In '_query.addEventListener('change', function (e) {(…)promiseReactionJob @ (program):1
Hi!
I'm using nuxt. I added a new plugin and imported it on the nuxt config but when I try to use it on one component it says that $screen does not exist (but if I log the object I can see it :S). I'm missing something?
Thanks!
Great library, I like it too much, just I was curios about using matchMedia instead of resizing. can you please explain me why you are using resize
and matchMedia together in https://github.com/reegodev/vue-screen/blob/master/packages/lib/src/useScreen.ts#L46. ?
Thanks a lot.
I am using Inertia JS with the example below. I am getting the warning:
[Vue warn]: onUnmounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
import { createApp } from 'vue'
import VueScreen from 'vue-screen'
// In App.vue
createApp({
render: () =>
h(InertiaApp, {
initialPage: JSON.parse(el.dataset.page),
resolveComponent: (name) => require(`./Pages/${name}`).default,
}),
})
.mixin({ methods: { route } })
.use(InertiaPlugin)
.use(VueScreen)
.mount(el);
// In MyComponent.vue
<template>
<ul>
<li>Current breakpoint is: {{ $grid.breakpoint }}</li>
<li>Window width is: {{ $screen.width }}</li>
<li>Window height is: {{ $screen.height }}</li>
</ul>
</template>
"vue-screen": "^2.3.2"
"vite": "^4.4.11"
grid is not reactive anymore? screen object is still reactive , eg
const grid = useGrid("bootstrap");
const screen = useScreen()
<div>{{ grid.breakpoint }}</div>
<p>Screen width is {{ screen.width }}</p>
screen.width updates when changing screensizes
grid.breakpoint DOES NOT UPDATE when changing screensizes
Version
2.2.0
Config
{
xs: 320,
sm: 576,
md: 768,
lg: 992,
xl: 1200,
isMobile: screen => screen.xs || screen.sm,
isTablet: screen => screen.md,
isDesktop: screen => screen.lg || screen.xl,
breakpointsOrder: ['xs', 'sm', 'md', 'lg', 'xl'],
}
Describe the bug
Im setting up the plugin to get some values auto like isTablet or isDesktop and isnt working on page.
Here is the nuxt plugin:
import VueScreen from 'vue-screen'
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.use(VueScreen, {
xs: 320,
sm: 576,
md: 768,
lg: 992,
xl: 1200,
isMobile: screen => screen.xs || screen.sm,
isTablet: screen => screen.md,
isDesktop: screen => screen.lg || screen.xl,
breakpointsOrder: ['xs', 'sm', 'md', 'lg', 'xl'],
})
})
Originally posted by 21stcn March 11, 2024
Looking for some pointers for correct usage please.
I am using vue-screen as a plugin (as described in docs):
//plugins/screen.js
import VueScreen from "vue-screen";
import tailwindScreens from "#twcss/theme/screens";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueScreen, {
grid: {
base: "0px",
...tailwindScreens,
},
});
});
In this way I can access $screen and $grid within any template in the app, which is functioning as expected:
<button v-show="$grid.lg">Button</button>
How can I access $grid and $screen with this global configuration from within the composition api? For example:
const initHome = () => {
if ($screen.touch){
logic
}
};
Is it necessary to use a composable (as described in docs) alongside the plugin config to use this single config in the script of every component? Ideally I would like to just configure the plugin and have $screen and $grid available in the composition api.
Thanks for your help!
Adding breakpoints like xsOnly or smAndUp could be really I think !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.