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

use-grid

v1.0.1

Published

๐Ÿค use-grid is a hook to build responsive layouts of all shapes and sizes.

Downloads

21

Readme

Table of Contents

Install via npm

npm i use-grid

Quick started

git clone github.com/tseijp/use-grid
cd use-grid
npm i -D
npm start

Simple example

switch by media query

import React from 'react'
import { useMedia, useGrid } from 'use-grid'
export const App = () => {
    const isMedium      = useMedia({ minWidth:720, maxWidth:960 });
    const [ fontSize ]  = useGrid({ xs:"2em", md:"50px", xl:"75px" });
    const [ width,set ] = useGrid({ xs:8/9  , md:500   , lg:750    });
    return (
        <div style={{fontSize, width}}
            onClick={() => set((p)=>({md:p.lg,lg:p.md}))}>
            {isMedium?'๐Ÿ˜ƒ':'๐Ÿ˜ข'}
        </div>
    );
};

use grid system

import React from 'react'
import { useGrids } from 'use-grid'
export const App = () => {
    const face = ['๐Ÿ™„','๐Ÿคฃ','๐Ÿง','๐Ÿคฏ','๐Ÿคฎ'];
    const ref  = React.useRef(null)
    const [ws] = useGrids(face.length, (i)=>(i%2===0)
        ? { md: 1/5, xl:i/face.length/3 }
        : { md:1/10, xl:i/face.length/6 }
    , [ref]);
    return (
        <div ref={ref} style={{display:"grid", width:"95%"}}>
            {face.map( (emoji, i) =>
                <div style={{width:ws[i]}}>{emoji}</div>
            )}
        </div>
    );
};

use view system

import React from 'react';
import {useGrid, useView} from 'use-grid';
export const App = () => {
    const ref1 = React.useRef(null)
    const ref2 = React.useRef(null)
    const isView = useView(ref1)
    const [fontSize,set] = useGrid({md:100,lg:200}, [ref1])
    const [background]   = useGrid({
        none:"#000", init:"#fff",
        onView:(bool) =>
            set(bool
                ? {md:150, lg:250}
                : {md:100, lg:200})
    }, [ref1, ref2])
    return (
        <div style={{fontSize,background}}>
            <div ref={ref1}>{'๐Ÿ˜Ž'}</div>
            {[...Array(10)].map((_,i)=>
                <div key={i}>{isView?'๐Ÿ˜˜':'๐Ÿคฃ'}</div>
            )}
            <div ref={ref2}>{'๐Ÿ˜Ž'}</div>
        </div>
    )
}

Available hooks

| Hook | Description |
| ----------------- | ------------------------------------------------------- |
| useGrid | make it switch value by media query with useEffect |
| useGrids | multiple values can be switched by media queries |
| useMedia | get a match to media query with useEffect |
| useView | get a flag whether the target intersects |
| useLayoutGrid | work like useGrid with useLayoutEffect |
| useLayoutGrids | work like useGrids with useLayoutEffect |
| useLayoutMedia | work like useMedia with useLayoutEffect |
| useLayoutView | work like useView with useLayoutEffect |

Performance Pitfalls

Grid prefix

The grid system uses containers, rows and columns to control layout and alignment.

Learn More

name|prefix|max width|max container width|
:----------|:--|:----------|:--------|
Extra small|xs |<576 px|auto |
Small |sm |>=576 px|540 px |
Medium |md |>=768 px|720 px |
Large |lg |>=992 px|960 px |
Extra large|xl |>=1200 px|1140 px|

Grid Options

name |works|
:-----------|:----|
init |initial value to be specified|
none |value when the element is not visible|
onView |function called when the target intersects| config |config for useGrid viewConfig |config for useMedia mediaConfig |config for useView

same works

export function Note ({children}) {
    const width1 = useGrid({sm:1, md:1/2, lg:"750px"})
    const width2 = useGrid({sm:"100%",md:"50%",lg:"750px"})
    const width3 = useGrid([["sm","100%"], ["md":"50%"], ["lg":"750px"]])
    const width4 = useGrid([[{                 maxWidth:"576px"}, "100%"],
                            [{minWidth:"576px",maxWidth:"768px"},  "50%"],
                            [{minWidth:"768px"                 },"750px"]])
    const width5 = useGrid([[                    "max-width:576px", "100%"],
                            ["min-width:576px and max-width:768px",  "50%"],
                            ["min-width:768px"                    ,"750px"]])
    const width =
       || width1
       || width2
       || width3
       || width4
       || width5
    return <div style={{width}} />
}