Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
vue-screen
Advanced tools
Reactive window size and media query states for Vue components. Integrates with most UI frameworks.
Reactive window size and media query states for VueJS. Supports your favourite UI framework grid breakpoints out of the box, and can be configured with any custom breakpoints.
✔ Reactive and debounced window innerWidth and innerHeight ↔ 🕐
✔ Reactive media query states and device orientation 💻📲
✔ Detect touch screen capability 👆🖱
✔ breakpoints for most common ui frameworks provided out of the box: Tailwind, Bootstrap, Bulma, Foundation, Materialize, Semantic UI ⚙ 📦
✔ SSR compatible 🚀 📟 (Nuxt module included)
As the library uses Vue.Observable API internally, Vue 2.6+ is required.
Embed directly as a script:
<script src="https://unpkg.com/vue-screen/dist/vue-screen.min.js"></script>
When embedding, the script automatically registers itself as a Vue plugin.
Via npm:
npm i vue-screen
Via yarn:
yarn add vue-screen
import Vue from 'vue';
import VueScreen from 'vue-screen';
Vue.use(VueScreen);
Use default breakpoints from one of the supported UI frameworks:
Vue.use(VueScreen);
Vue.use(VueScreen, 'tailwind');
Vue.use(VueScreen, 'bootstrap');
Vue.use(VueScreen, 'bulma');
Vue.use(VueScreen, 'foundation');
Vue.use(VueScreen, 'materialize');
Vue.use(VueScreen, 'semantic-ui');
Vue.use(VueScreen, {
sm: 480, // will be converted to 480px
md: '47em',
lg: '1200px',
});
You can find default UI framework breakpoints here
You can provide custom callbacks that will be run every time the debounced window resize event is triggered:
Vue.use(VueScreen, {
md: 768,
lg: 992,
xl: 1200,
tablet: screen => screen.md && !screen.xl && screen.touch,
});
To use callbacks together with breakpoints from one of the supported UI frameworks you can specify the extend
property:
Vue.use(VueScreen, {
extend: 'bootstrap',
tablet: screen => screen.md && !screen.xl && screen.touch,
});
After registering, the property $screen
will be injected on the Vue prototype. You can access it in a component using this.$screen
.
<template>
<div>
<p>Page width is {{ $screen.width }} px</p>
<p>Page height is {{ $screen.height }} px</p>
<p>Current breakpoint is {{ $screen.breakpoint }} px</p>
</div>
</template>
<template>
<div :class="media">
<p>VueScreen</p>
</div>
</template>
<script>
export default {
computed: {
media() {
return {
'is-phone': this.$screen.sm,
'is-tablet': this.$screen.md,
'is-desktop': this.$screen.lg,
'can-touch': this.$screen.touch,
'breakpoint': this.$screen.breakpoint,
};
}
}
}
</script>
export default {
watch: {
'$screen.width'() {
alert('Width changed');
}
}
}
Check out demo source code for more examples.
Available properties on the $screen
object:
Number
Alias of window.innerWidth
Number
Alias of window.innerHeight
Boolean
Tells if touch events are supported
Boolean
Tells if the device is in portrait mode
Boolean
Tells if the device is in landscape mode
String
Returns the currently active breakpoint. If you use custom breakpoint names, you must also provide the breakpointsOrder
property (see below).
Array
Contains the order of the custom breakpoints provided in the configuration. This is required for the breakpoint
property to work with custom breakpoint names.
Example:
Vue.use(VueScreen, {
phonePortrait: 0,
phoneLandscape: 520,
tabletPortrait: 768,
tabletLandscape: 1024,
desktop: 1200,
breakpointsOrder: ['phonePortrait', 'phoneLandscape', 'tabletPortrait', 'tabletLandscape', 'desktop']
});
If you extend one of the default frameworks,
breakpointsOrder
is provided automatically.
Boolean
Every breakpoint key specified in the configuration will be available as a boolean value indicating if the corresponding media query matches.
To view default breakpoint keys and values for each framework, click here.
Any
Every callback specified in the configuration will have a corresponding property indicating the result of the callback. Callbacks will be called on every debounced resize event.
The library can be used directly as a Nuxt module, just add it to the module section in nuxt.config.js
:
export default {
...
...
modules: [
'vue-screen/nuxt',
],
screen: {
extend: 'bootstrap',
},
...
...
}
All browsers that support matchMedia API
FAQs
Reactive screen size and media query states for Vue. Integrates with most UI frameworks out of the box.
The npm package vue-screen receives a total of 6,334 weekly downloads. As such, vue-screen popularity was classified as popular.
We found that vue-screen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.