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

light-react-grid

v1.0.5

Published

Small and very simple React grid system based on simple-scss-layout-grid package

Downloads

18

Readme

Light React Grid

This library package includes:

  • useBreakpoint hook
  • GridSystemContext Context
  • GridSystem Component with GridHelper component
  • Grid Component
  • Column Component

Configuration:

If we aren't using default settings we can define breakpoints however we like. We need to define breakpoints, prefixes, gridHelperMargins. gridHelperColumnColor

  • breakpoints is used for declaring names, number of columns, gutterSize and minimum/maximum width of breakpoint
  • prefixes are used for naming CSS classes that are going to be generated
  • gridHelperColumnColor will set the column color of GridHelper. By default, it's set to rgba(0, 0, 0, .1)
  • gridHelperMargins should be only set if you are using some container in your project, for example:
<main style={{margin: '0 5%'}}>
    <header><h1>Hello</h1></header>
    <Grid>
        <Column ... />
        ...
    </Grid>
    ...
</main>

In that case we need to use gridHelperMargins to match our Grid. If you need more control over GridHelper, you could import <GridHelper /> component and override CSS styles.

Here is the sample configuration:

const GRID_SETTINGS: GridSettings = {
  breakpoints: {
    sm: {
      columns: 4,
      gutterSize: 5,
      maxWidth: 600,
    },
    md: {
      columns: 8,
      gutterSize: 10,
      minWidth: 600,
      maxWidth: 900,
    },
    lg: {
      columns: 12,
      gutterSize: 20,
      minWidth: 900,
    }
  },
  prefixes: {
    grid: 'g',
    gridColumn: 'gc',
  },
  gridHelperColumnColor: 'rgba(0, 0, 0, .05)'
}

Now we can use it in <GridSystem /> and define that we want to use Grid Helper:

// Import CSS for GridHelper component
import 'light-react-grid/dist/index.css'

ReactDOM.render(
  <React.StrictMode>
      <GridSystem 
           settings={myGridSettings}
           useGridHelper={true}
      >
        <App />
      </GridSystem>
  </React.StrictMode>,
  document.getElementById('root')
);

Please be aware that we are going to use that breakpoint name for size property in <Column /> component. To set column size we need to write exact column names as they are defined in myGridSettings: <Column size={{sm: 2, md: 3}} />.

Please checkout example code for more details: example/src.


Usage

We can set column size and left or right offset.
To define column size we need to pass size for a breakpoint that we want to use, if we don't define column size for the breakpoints it will automatically set width to 100%.

<Grid>
    <Column size={{sm: 2, md: 2, lg: 8}} offsetLeft={{md: 2}}></Column>
    <Column size={{sm: 2, md: 4}}></Column>
    ...
</Grid>

In case that we don't need column for some reason in a large breakpoint we can use useBreakpoint hook to remove it:

    const breakpoint = useBreakpoint();
    return (<div>
        <Grid>
            { breakpoint === 'md' && <Column size={{md: 4}} /> }
            <Column size={{sm: 2, md: 4}}></Column>
        </Grid>
    </div>);

Tips

When you define your breakpoints you can always create a wrapper around <Column /> component and define breakpoints as props.


interface ColumnWrappperProps {
  className?: string;
  sm?: number;
  md?: number;
  lg?: number;
  offsetLeft?: {
    sm?: number;
    md?: number;
    lg?: number;
  };
  offsetRight?: {
    sm?: number;
    md?: number;
    lg?: number;
  };
}

export const ColumnWrapper: FunctionComponent<ColumnWrappperProps> = ({
  children,
  className = '',
  sm,
  md,
  lg,
  offsetLeft = {},
  offsetRight = {},
}) => (
  <Column
    size={{ sm, md, lg }}
    offsetLeft={offsetLeft}
    offsetRight={offsetRight}
    className={className}
  >
    {children}
  </Column>
);

Usage:

<Grid>
    <ColumnWrapper sm={2} md={4} offsetLeft={{md: 1}} />    
</Grid>

I wish u happy coding!


Light React grid is MIT licensed.