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

grif-layout

v0.1.1

Published

A simple set of ReactJS components that can be used to create grids and other layouts in a webpage. This is a personal project to help me learn both CSS Grid and the process for publishing an NPM module.

Downloads

5

Readme

Synopsis

A simple set of ReactJS components that can be used to create grids and other layouts in a webpage. This is a personal project to help me learn both CSS Grid and the process for publishing an NPM module.

Code Example

The example component below will shows how you can use Grif Layout to create a page. The Box component is just an empty colored div.

import React from 'react';
import { Layout, Item } from 'grif-layout';

import Box from './components/Box';

const App = () => {
  return (
    <div
      className="App"
      style={{ width: '100vw', height: '100vh' }}
    >
      <Layout
        columns={[1/10, 1/2, 3/10]}
        gap="1rem"
      >
        <Item
          cs={1}
          rs={2}
        >
          <Box color="blue" />
        </Item>
        <Item
          ce={3}
          cs={1}
          p="1rem"
        >
          <Box color="orange">
            <div style={{padding: '1rem'}}>
              Lorem ipsum dolor sit amet, consectetur adipiscing elit.
              Cras ut pulvinar massa. Praesent ultricies, elit quis convallis ultrices,
            </div>
          </Box>
        </Item>
        <Item
          cs={3}
          pl="1rem"
        >
          <Box color="purple" />
        </Item>
        <Item
          cs={3}
          rs={2}
        >
          <Box color="green" />
        </Item>
        <Item
          cs={2}
          pt="1rem"
          rs={2}
        >
          <Box color="brown" />
        </Item>
      </Layout>
    </div>
  );
};

export default App;

Motivation

In some personal React projects I really enjoyed using Reflexbox as a way to provide layout for my apps. However, for more complicated use I found the system based on flexbox to be lacking, since it is only really designed to handle layout in one dimension at a time. It was often necessary to deeply nest components to get the layout I wanted. I decided that a set of layout components based on CSS grid would better fit my needs. This also served as an oppurtunity to teach me the process of publishing an npm module.

Installation

If you use npm you can install the components with

npm install --save grif-layout

Yarn users can run

yarn add grif-layout

API Reference

There are two componenets, Layout and Item. Layout is designed to take multiple Item components as children.

Layout

This component holds Item components. It sepcifies the grid which the Item components will fill. The properties are below.

  • columns (number | array of (number | string) ): Creates the columns of your grid. A single number will create that many evenly spaced columns. For more fine control, you can pass an array of numbers. This will make columns proportional to the array contents in the order in which they appear. For example, setting column={[1, 2]} will create a grid with two columns, the second of which is twice the width of the first. You can also pass absolute css widths. Will default to 1.

  • rows (number | array of numbers): Creates the rows of your grid. Works much like the columns property. Will default to 1.

  • gap (string | number): The gap between different items in the grid. Takes a css width like 2rem or a number of pixels.

  • xAlign (string): How to justify content on the x axis. Possible values are the same as the values for the css properties align-content and justify-content. Useful options include center, left, right, stretch, or space-between.

  • yAlign (string): How to justify content on the y axis. Works the same way as xAlign.

Item

This component can hold different content as its children. The properties are below.

  • cs (number): The grid line to start the item along the x axis. Grid lines start at 1, which is the furthest right.

  • ce (number): The grid line to end the item along the x axis.

  • rs (number): The grid line the start the item along the y axis.

  • re (number): The grid line to end the item along the y axis.

  • m (string | number): The margin of the child content. If set to greater than the value of the gap on the parent layout, it will cause the item to be drawn over other child items.

  • ml (string | number): The left margin.

  • mr (string | number): The right margin.

  • mt (string | number): The top margin.

  • mb (string | number): The bottom margin.

  • p (string | number): The padding of the child content. Will not extend past the limits of its row or column. Takes a css length like 1rem or a number of pixels.

  • pt (string | number): The top padding.

  • pb (string | number): The bottom padding.

  • pl (string | number): The left padding.

  • pr (string | number): The right padding.

License

The project is licensed with the WTFPL license, a copy of which is included in this repository. See copying.txt for more information.