GithubHelp home page GithubHelp logo

faceless-ui / window-info Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 1.28 MB

A React library for subscribing to window events

Home Page: https://facelessui.com/docs/window-info

License: MIT License

JavaScript 52.28% TypeScript 47.72%
react react-component window viewport responsive typescript css-in-js breakpoints

window-info's Introduction

Faceless UI

To regenerate search indices, run yarn build:cache.

window-info's People

Contributors

dependabot[bot] avatar jacobsfletch avatar jarrodmflesch avatar jmikrut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

window-info's Issues

`breakpoints` should default to an empty object

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();

Browser disconnect when calculating media-queries

The Browser Issue

Example breakpoint: @media (max-width: 850px) { }

Chrome calculates media-query breakpoints based on the window width.

  • If the browser is 850px wide (from edge to edge) the breakpoint will trigger

Safari calculates media-query breakpoints based on the documents body (not including the scrollbar)

  • If the browser is 865px wide (from edge to edge) the breakpoint would hit, because it is calculating document body width and not including the scrollbar.

The window-info Issue

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.

Possible Solution

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?

RFC - Fully custom breakpoints object

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.

Write Unit Tests

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.

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.