0.6.1 • Published 5 years ago

@yutahaga/vue-media-breakpoints v0.6.1

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

vue-media-breakpoints

Features

  • Not using Vue's private API.
  • Using Passive Event Listeners.
  • You can use a custom debouncing function.

Getting Started

Install

npm i @yutahaga/vue-media-breakpoints -S

or

yarn add @yutahaga/vue-media-breakpoints

Usage

When supporting SSR, avoid using v-if and use v-show. Note that v-show does not support the <template> element, nor does it work with v-else.

import { install as MediaBreakPointsPlugin, BreakPointManager } from '@yutahaga/vue-media-breakpoints';
import debounce from 'lodash.debounce';
import Vue from 'vue';

const GRID_BREAKPOINTS = {
  xs: 0,
  sm: 576,
  md: 768,
  lg: 992,
  xl: 1200,
};

Vue.use(MediaBreakPointsPlugin, {
  breakPoints: GRID_BREAKPOINTS,
  debounceFunction: debounce,
  debounceInterval: 30,
});

const vm = new Vue({
  el: '#app',
  template: `
    <div>
      <p>{{ $bp.name }}: {{ $bp.width }}px</p>
      <p v-show="$bp.above('sm')">
        This tag is displayed only when the viewport is md ~ xl.
      </p>
      <p v-show="!$bp.below('md', false /* SSR Fallback. Default fallback is true */)">
        This tag is displayed only when the viewport is xs ~ sm.
      </p>
      <p v-show="$bp.equal('lg')">
        This tag is displayed only when the viewport is lg.
      </p>
      <p v-show="$bp.equal(['xs', 'xl'])">
        This tag is displayed only when the viewport is xs and xl.
      </p>
      <p v-show="$bp.between('sm', 'lg')">
        This tag is displayed only when the viewport is between sm and lg. (sm <= ViewPort < lg)
      </p>
      <p v-show="$bp.orAbove('sm')">
        This tag is displayed only when the viewport is sm or above.
      </p>
      <p v-show="$bp.orBelow('sm')">
        This tag is displayed only when the viewport is sm or below.
      </p>
    </div>
  `
});

declare module 'vue/types/vue' {
  interface Vue {
    $bp: BreakPointManager<typeof GRID_BREAKPOINTS>;
  }
}
0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

6 years ago

0.0.1

6 years ago