npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solidjs-div-100vh

v1.0.1

Published

A workaround for the '100vh' issue in mobile browsers

Downloads

5

Readme

Div100vh SolidJS component and create100vh signal

This is a workaround for iOS Safari and other mobile browsers.

Forked from react-div-100vh by mvasin.

The problem

In mobile browsers, the real height of the viewport is dynamic, as browser "chrome" (panels) slide away on scrolling. The browser developers faced two choices: either to reflow the page as the pixel value of a vh changes, or ignore the fact that the browser panel covers part of the screen.

The browser panels are supposed to slide away smoothly, and because the layout reflow during scrolling will not look smooth, the browser developers went for the second option.

It may work for the most of use cases, but if you're looking for an app-like full-screen experience, or want to make sure that the call to action button at the bottom of your splash screen isn't covered, you may need to know the fair value of a vh.

| <div style={{ height: "100vh" }}> | <Div100vh> | | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | Page cropped by bottom Safari chrome | Page cropped by bottom Safari chrome |

More on this issue here.

The solution

Div100vh SolidJS component is the default export:

import Div100vh from "solidjs-div-100vh"

const MyFullHeightComponent = () => (
  <Div100vh>
    <span>Look ma, no crop!</span>
  </Div100vh>
)

For more advanced use cases (for instance, if you need 50% of the real height), there is a named export create100vh. This SolidJS signal provides an accurate vertical height in pixels. The return type is a number in a browser and null in Node environment. You may need to check if it's not null if you're doing SSR, otherwise, manipulate the value as you wish:

import { create100vh } from "solidjs-div-100vh"

const HalfHeightComponent = ({ children }) => {
  const height = create100vh()
  // This *must* be a function,
  // otherwise SolidJS won't track the changes.
  const halfHeight = () => (height() ? height() / 2 : "50vh")
  return <div style={{ height: halfHeight }}>{children}</div>
}

const FourthHeightComponent = ({ children }) => {
  const height = create100vh()
  return (
    <div style={{ height: height() ? height() / 4 : "25vh" }}>
      {children}
    </div>
  )
}

Under the hood create100vh uses measureHeight function which is exported as well, so feel free to use it, even without SolidJS. Currently it returns document.documentElement?.clientHeight || window.innerHeight if executed in a browser or null if on a server.