dan503 / mq-js Goto Github PK
View Code? Open in Web Editor NEWMedia queries in JavaScript inspired by the mq-scss Sass mixin
Home Page: https://dan503.github.io/mq-js/
License: MIT License
Media queries in JavaScript inspired by the mq-scss Sass mixin
Home Page: https://dan503.github.io/mq-js/
License: MIT License
The world is moving to TypeScript.
This is still a useful library so it needs to keep up.
I've already made a start on writing out the Types needed for this:
type Callback = (screenSize: number) => void
type SimpleMq<BP> = (bp: keyof BP, cb?: Callback) => boolean
type ComplexMq<BP> = (bp1: keyof BP, bp2: keyof BP, cb?: Callback) => boolean
type ReactToCB = (isActive: boolean, screenSize: number) => void
export interface MqJs<BP extends object> {
/** Returns `true` if the window size is **less than** the breakpoint size */
min: SimpleMq<BP>,
/** Returns `true` if the window size is **greater than** the breakpoint size */
max: SimpleMq<BP>,
/** Returns `true` if the window size is **greater than smaller** breakpoint but **less than the larger** breakpoint */
inside: ComplexMq<BP>,
/** Returns `true` if the window size is **less than the smaller breakpoint** or **greater than the larger** breakpoint */
outside: ComplexMq<BP>,
/** Runs a callback function every time `testMQ` changes from returning `true` to returning `false` */
reactTo: (testMQ: () => boolean, cb: ReactToCB) => void
}
If someone is using mq-scss in em conversion mode and the website user increases their default browser font size, mq-scss and mq-js will get out of sync with one another.
mq-js has no em conversion functionality so the only way around this is to turn off em conversion in mq-scss at the moment.
mq-js needs an em conversion mode. I plan to do this by using window.matchMedia
rather than gathering data on the window dimensions and doing the math manually. This is the better way for the plugin to work anyway.
It only runs when switching from one screen size to another but it should also run on initial page load.
I have a shitty unit testing solution at the moment.
It does the job but using Cypress for this would be immensely better.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.