1.2.0 • Published 11 months ago

kaveh-nuxt-breakpoints v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

IMPORTANT NOTE: THIS REPO IS DEPRECATED.

So why is this repo deprecated? As time goes by, browsers and front-end progress rapidly, this lib was initially created to make it easy for me to get the current breakpoints through js when using Nuxt 2 at work, to display specific components, it has served its purpose for a while but it was not continuously maintained.

Nowadays, Resize Observer is widely used and has good support, there are even better alternatives like MediaQueryList that have better ways of achieving the same goal.

Vue and Nuxt have also released version 3, if you are already using the composition-api, VueUse has also provided useBreakpoints which may be a good alternative option.

As things change, implementing a similar lib is not difficult, I recently tidied up my GitHub and thought this package is no longer necessary. So I have decided to deprecate this project, I hope to write other good projects in the future and maintain them properly.

nuxt-breakpoints

Resize observer breakpoints with Nuxt.js module.

NPM Codecov License: MIT Package Size

DEMO

📖 Release Notes

Setup

  1. Add nuxt-breakpoints dependency to your project
yarn add nuxt-breakpoints # or npm install nuxt-breakpoints
  1. Add nuxt-breakpoints to the modules section of nuxt.config.js
{
  modules: [
    // Simple usage
    'nuxt-breakpoints',

    // With options
    ['nuxt-breakpoints', { /* module options */ }]
  ]

  // Another way to use options
  breakpoints: {
    // default options
    sm: 576,
    md: 768,
    lg: 992,
    xl: 1200,
    options: {
      polyfill: true,
      throttle: 200
    }
  }
}

Usage

// components.vue
export default {
  computed: {
    isMdOrSm () { return this.$breakpoints.md || this.$breakpoints.sm },
    isLargeThanSm() {
      return this.$breakpoints.lSm // Is Large than sm include sm
    },
    isSmallThanMd() {
      return this.$breakpoints.sMd // Is Small than md include md
    }
    // ... etc lSm lMd lLg, and sSm sMd sLg
  }
}

Options

propertytypedefaultnote
xsnonenone<= 576px,Extra small, smallest.
smnumber576>= 576px(sm) && <= 768px(md)
mdnumber768>= 768px(md) && <= 992px(lg)
lgnumber992>= 992px(lg) && <= 1200px(xl)
xlnumber1200>= 1200px, Extra large, largest.
optionsobject<polyfill: boolean, throttle: number>{ polyfill: true, throttle: 200 }polyfill default by true, which means will auto-import resize-observer-polyfill when the browser doesn't support ResizeObserver more information below, throttle will slow down when Window has resizing trigger speed.

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

Ref

Nuxt.js

MDN - ResizeObserver

ResizeObserver Polyfill

License

MIT License

Copyright (c) Steven Ho hi@stevenho.pro