faceless-ui / window-info Goto Github PK
View Code? Open in Web Editor NEWA React library for subscribing to window events
Home Page: https://facelessui.com/docs/window-info
License: MIT License
A React library for subscribing to window events
Home Page: https://facelessui.com/docs/window-info
License: MIT License
Jest
should be highly-considered here as React itself now suggests this framework in its documentation (it's a Facebook product, go figure) and even rolls it out with Create React App.
Provided state values should initialize as undefined
until the window is available, as opposed to false
, 0
, etc.
This will give developers more freedom in their conditional rendering.
Example breakpoint: @media (max-width: 850px) { }
Chrome calculates media-query breakpoints based on the window width.
Safari calculates media-query breakpoints based on the documents body (not including the scrollbar)
This package follows the chrome approach to calculate when breakpoints have hit, by using the entire window as the measurement. In safari, the disconnect occurs when you are using this package to break at 850px, the JS breakpoint approach will hit after the browser media-query does, because at 865px in Safari, the 850px media-query styles will apply and the JS ones will not unless the browser shrinks down to 850px.
Instead of using the window width to determine if a breakpoint has hit, I think window.matchMedia could replace that, so on resize, these functions would run and then they would align with the browsers' stylesheet media-query approach.
Thoughts?
Should include:
This is to avoid needing to add an empty object fallback when using breakpoints with the useWindowInfo
hook.
For example:
const {
breakpoints: {
m: midBreak
} = {} // AVOIDS THIS
} = useWindowInfo();
This may be more appropriate as a stand-alone package โ should be audited based on merit.
With the current setup, we are only exposing/allowing certain breakpoints to hit and report back to the user and they are all max-width
based breakpoints that range from xs/s/m/l/xl
I think a better approach would to allow the user to supply (almost) the entire object and that would have the potential to look exactly how the user wants it to. Take the following as an example, the user could use their own descriptive keys that fit their use case (only using these to show the customization potential):
{
iphoneXS: '(max-width: 300px)',
iphoneX: '(max-width: 400px)',
ipad: '(max-width: 1000px)',
iphoneXMaxHeight: '(max-height: 800px)',
}
With this approach, breakpoints would be 100% customizable, which would be ideal in many cases.
Then we would create the necessary window.matchMedia
queries to fire when the window changes height/width and report back using the keys from their breakpoints object.
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.