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

qwik-breakpoints

v1.0.1

Published

Qwik Breakpoints lets you evaluate media queries to determine the current screen size and react to changes when the viewport size crosses a breakpoint.

Downloads

2

Readme

Qwik Breakpoints

This package provides utilities to build responsive UIs that react to screen-size changes.

useBreakpointSignal

A layout breakpoint is a viewport size threshold at which a layout shift can occur. The viewport size ranges between breakpoints corresponde to different standard screen sizes.

useBreakpointSignal lets you evaluate media queries to determine the current screen size and react to changes when the viewport size crosses a breakpoint.

import { component$, useComputed$ } from '@builder.io/qwik';
import { Breakpoints, useBreakpointSignal } from 'qwik-breakpoints';

export default component$(() => {
  const bpSignal = useBreakpointSignal([
    Breakpoints.XSmall,
    Breakpoints.Small,
    Breakpoints.Medium,
    Breakpoints.Large,
    Breakpoints.XLarge,
  ]);

  const currentScreenSize = useComputed$(() => {
    const displayNameMap = new Map([
      [Breakpoints.XSmall, 'XSmall'],
      [Breakpoints.Small, 'Small'],
      [Breakpoints.Medium, 'Medium'],
      [Breakpoints.Large, 'Large'],
      [Breakpoints.XLarge, 'XLarge'],
    ]);
    for (const query of Object.keys(bpSignal.value.breakpoints)) {
      if (bpSignal.value.breakpoints[query]) {
        return displayNameMap.get(query) ?? 'Unknown';
      }
    }
  });

  return (
    <>
      <p>Resize your browser window to see the current screen size change.</p>
      <p>
        The current screen size is <strong>{currentScreenSize.value}</strong>
      </p>
    </>
  );
});

React to changes to the viewport

const layoutChanges = useBreakpointSignal([
  '(orientation: portrait)',
  '(orientation: landscape)',
]);

useVisibleTask$(({ track }) => {
  track(() => layoutChanges.value);
  updateMyLayoutForOrientationChange();
}

Predefined breakpoints

The built-in Breakpoints constant offers the following predefinded breakpoints for convenience, originally drawn from the Material Design specification.

| Breakpoint name | Media query | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | XSmall | (max-width: 599.98px) | | Small | (min-width: 600px) and (max-width: 959.98px) | | Medium | (min-width: 960px) and (max-width: 1279.98px) | | Large | (min-width: 1280px) and (max-width: 1919.98px) | | XLarge | (min-width: 1920px) | | Handset | (max-width: 599.98px) and (orientation: portrait), (max-width: 959.98px) and (orientation: landscape) | | Tablet | (min-width: 600px) and (max-width: 839.98px) and (orientation: portrait), (min-width: 960px) and (max-width: 1279.98px) and (orientation: landscape) | | Web | (min-width: 840px) and (orientation: portrait), (min-width: 1280px) and (orientation: landscape) | | HandsetPortrait | (max-width: 599.98px) and (orientation: portrait) | | TabletPortrait | (min-width: 600px) and (max-width: 839.98px) and (orientation: portrait) | | WebPortrait | (min-width: 840px) and (orientation: portrait) | | HandsetLandscape | (max-width: 959.98px) and (orientation: landscape) | | TabletLandscape | (min-width: 960px) and (max-width: 1279.98px) and (orientation: landscape) | | WebLandscape | (min-width: 1280px) and (orientation: landscape) |

You can use these predefined breakpoints with useBreakpointSignal.

const result = useBreakpointSignal([
  Breakpoints.HandsetLandscape,
  Breakpoints.HandsetPortrait
]);

return {
  result.value.matches
  ? <div>Handset</div>
  : <div>Not Handset</div>
}