Coder Social home page Coder Social logo

reegodev / vue-screen Goto Github PK

View Code? Open in Web Editor NEW
238.0 5.0 18.0 3.47 MB

Reactive screen size and media query states for VueJS

Home Page: https://reegodev.github.io/vue-screen/

JavaScript 45.73% TypeScript 36.85% HTML 9.33% CSS 1.70% Vue 6.39%
vue window screen width height matchmedia media query reactive innerwidth

vue-screen's People

Contributors

dependabot[bot] avatar digirigo avatar hymair avatar outdoorsman avatar reegodev avatar ryanjbonnell avatar sidneygijzen avatar stefangalescu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-screen's Issues

Get values of breakpoints through $screen object

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!

Remove spread operators

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

Vue 3 support

Plugin install fails with
Uncaught TypeError: Vue.observable is not a function

Using vue-screen in SSR causes hydration errors

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:
image

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?

How to detect that lib was initialized successfully?

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.

Support for vue-test-utils

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:

  1. Create a Vue component that uses vue-screen
  2. Write & run a test for that component

Expected behavior
Test should run without errors

Width and Height on mobile view on Chrome is not correct

Version
2.1.0-alpha.5

Config
default

Describe the bug
!!! It is happenning on Chrome.
On Safari and Firefox it is working.

console log the screen for the window on mobile.
refresh multiple times, is not happenning everytime

To Reproduce
image

Expected behavior
sizes to be okay

wrong breakpoint even when the condition is correct

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 :)

Screen Shot 2021-09-28 at 17 53 27

Screen Shot 2021-09-28 at 17 54 37

nuxtjs - $screen is not resolved after build

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?

Leftover console.log in package version

Version
2.1.0-alpha.5

Reproduction link
Fresh install of the package, use useGrid

Describe the bug
There is a leftover console.log during createMediaQueries

Screenshot 2021-10-28 at 13 22 14

[nuxtjs] vue-screen breaks on ios 12,13

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

Property $screen does not exist.

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!

onUnmounted is called when there is no active component instance to be associated with

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>

grid is not reactive in vite , screen still works though

"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

dont work correctly on nuxt 3 3.4.2

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.

image

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'],
	})
})

Using vue-screen as plugin and accessing in composition API script

Discussed in #89

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.