Code Monkey home page Code Monkey logo

vue-mq's Introduction

vue-mq

npm version JavaScript Style Guide license

Note: Draft, not quite production ready.

Vue.js 2.0+ plugin for media queries.

Installation

yarn add @wearelucid/vue-mq

Integration

import { MediaQueries } from 'plugins/mediaqueries'

// Define your breakpoints or import them from elsewhere
const breakpoints = {
  small: 400,
  medium: 768,
  large: 1100,
  huge: 1400
}

Vue.use(MediaQueries, { breakpoints })

And then use it in your components

// JSX Example
Vue.component({
  // ...
  render (h) {
    return (
      <div>
      {this.$query({ from: 'medium' })
        ? 'Small Content'
        : 'Large Content'}
      </div>
    )
  }
})

Use cases:

this.$query({ from: 'medium' })
this.$query({ from: 'small', to: 'large' })
this.$query({ to: 'large' })

Or, as another example, display the currentBreakpoint

// JSX Example
Vue.component({
  name: 'DevStats'
  // ...
  render (h) {
    return (
      <span> Current Breakpoint: {this.$mq.current.name} @ {this.$mq.current.value}px </span>
    )
  }
})

Todos

  • Validate reactive property. Is this correctly implemented? (_mq, mq, $mq)
  • Option to sync with CSS (e.g by reading breakpoints from JSON String, which we set <title>'s font-size property)
  • Implement alternative way to pass in breakpoints
  • Tests
  • Npm Compat

Browser Support

IE8+ (See clientWidth) Uses matchMedia for newer browsers but has a polyfill for IE8/IE9.

License

MIT

vue-mq's People

Contributors

d-simon avatar fabianellenberger avatar jones-s avatar marcoeh avatar

Stargazers

Junya Shimazu avatar h4nyu avatar Gregory Buzdyk avatar johannes avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar Sebastian Bayer avatar  avatar

vue-mq's Issues

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.