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

react-resizable-collapsible-grid

v1.3.3

Published

Components For Building Resizable Web Apps

Downloads

237

Readme

React Resizable Collapsible Grid

👉 Try It Out 👈

GitHub Publish Libraries

The components work on desktop and mobile with touch events.

There are two components the ResizableHorizontalGrid and ResizableVerticalGrid, these can be nested within each other for any configuration you might need.

You can drag the Horizontal and Vertical handles to rearrange the layout to fit your content as needed, or pass in a boolean to hide various sections.

Included is a hook to save the current positions of the handles to localStorage, you can then restore state to the page when it is reloaded.

How to Use

pnpm i react-resizable-collapsible-grid

npm install react-resizable-collapsible-grid

ResizableHorizontalGrid

Takes two or three child elements

import {
    ResizableHorizontalGrid,
} from 'react-resizable-collapsible-grid'

// add the css variables
import 'react-resizable-collapsible-grid/dist/resizableGrid.css'

function App(){
    <ResizableHorizontalGrid>
           <div>Content left</div>
           <div>Content Center</div>
           <div>Content Right</div>    {/* optional */}
       </ResizableHorizontalGrid>
}

Options

type ResizableHorizontalGridProps = {
  children: React.ReactNode[]
  gridId?: number | string // for saving/restoring state
  minWidth?: number  // minimum width of left or right columns
  collapseLeft?: boolean // true collapses left
  collapseRight?: boolean // true collapses right
  initialWidths?: HorizontalGridWidths // {left:'20vw':right:300}
  getCurrentState?: ({ gridId, left, right }: HorizontalGridState) => void // function for returning current state of the component
}
// your imports as above
import { isHorizontalGrid, GridState} from 'react-resizable-collapsible-grid'

function App(){
    // your function to save state of component.
    const getGridState = (gridState: GridState) => {
        if (isHorizontalGrid(gridState)) {
        // Resizable Horizontal Grid
        } else {
        // Resizable Vertical Grid
        }
    }
    <ResizableHorizontalGrid
        initialWidths={{left:'20vw',right:200}}
        getCurrentState={getGridState}
        gridId={5}
        collapseLeft={false}
        collapseRight={false}
    >
           <div>Content left</div>
           <div>Content Center</div>
           <div>Content Right</div>
       </ResizableHorizontalGrid>
}

ResizableVerticalGrid

Takes two child elements

import {
    ResizableVerticalGrid,
} from 'react-resizable-collapsible-grid'

// add the css variables
import 'react-resizable-collapsible-grid/dist/resizableGrid.css'

function App(){
    <ResizableVerticalGrid>
        <div>Content Top</div>
        <div>Content Bottom</div>
    </ResizableVerticalGrid>
}

Options:

type ResizableVerticalGridProps = {
  children: React.ReactNode[]
  gridId?: number | string // for saving/restoring state
  minHeight?: number // either sections min height
  collapseTop?: boolean // true hides top
  collapseBottom?: boolean // true hides bottom
  initialHeight?: string | number  // any css size value
  getCurrentState?: ({ gridId, height }: VerticalGridState) => void // function for returning components current state
}

See example above for ResizableHorizontalGrid with options for using getCurrentState.

   <ResizableVerticalGrid
          gridId={6}
          initialHeight={'50%'}
          getCurrentState={getGridState} 
          collapseTop={false}
          collapseBottom={false}
        >

Styling with css

The default exports from the library use css modules (component.module.css) so should work out of the box with vite.js and next.js.

TODO: add support for non css modules usage.

All the components are using css variables so it is quite easy to override any setting.

Important! You will need to add the css variables to your app through an import or add them to your own css variables. If you don't add one of these you get no styling!!!

import 'react-resizable-collapsible-grid/dist/resizableGrid.css'
function App(){
    // your component 
}

or add to your css file

body {
  --resizable-grid-final-scale: 1.8;
  --resizable-grid-track-color: var(--gray-8);
  --resizable-grid-track-color-hover: var(--gray-7);
  --resizable-grid-track-opacity: 0.2;
  --resizable-grid-track-opacity-hover: 0.5;
}

/* 
   only needed on children elements
   to contain content and alloy scrolling.
 */
.resizable-grid__content {
  overflow-y: auto;
  padding: 1rem;
}

Hook

  const { getVerticalGridHeight, getHorizontalGridWidths, setResizeState } =
    useResizeGridLocalStorage()

The included hook just saves and retrieves component state to localStorage to see the code have a look in the example using hooks

Nested example:

import {
    ResizableHorizontalGrid,
    ResizableVerticalGrid,
} from 'react-resizable-collapsible-grid'

function App(){
    <ResizableHorizontalGrid>
        <div>Content left</div>
        <ResizableVerticalGrid>
            <div>Content Top</div>
            <div>Content Bottom</div>
        </ResizableVerticalGrid>
        <div>Content Right</div>  
    </ResizableHorizontalGrid>
}