Giter Club home page Giter Club logo

use-pulled-grid's Introduction

use-pulled-grid

NPM Build Status Coverage License

⚠️ Wait, you don't need JS here! you can do this using only CSS

grid-template-columns: repeat(auto-fit, minmax(--min-width, 1fr));

Use this code only when you need fallback styles.


A React hook provides responsive CSS Grid container

  • Calculate CSS properties for grid container to fit the current window width
  • Get easier to use animated-css-grid

Live demo

See in CodeSandbox

Usage

Inline style

import React from 'react'

import usePulledGrid from 'use-pulled-grid'

const ProductCardList = ({ products }) => {
  const { styles } = usePulledGrid({
    columnMinWidth: 100, // Each grid items never get smaller than 100px
    gridGap: 10,
  })

  return (
    <div style={styles.container}>
      {products.map(product => (
        {/* Wrappers to each child are required for css-animated-grid and fallback style of grid gap */}
        <div key={product.id} style={styles.itemWrapper}>
            <ProductCard {...product}/>
        </div>
      )}
    </div>
  )
}

emotion

/* @jsx jsx */

import React from 'react'
import { css, jsx } from '@emotion/core'

import usePulledGrid from 'use-pulled-grid'

const ProductCardList = ({ products }) => {
  const { styles } = usePulledGrid({
    columnMinWidth: 100,
    gridGap: 10,
  })

  const containerCss = React.useMemo(() => (
    css(styles.container)
  ), [styles.container])

  const itemWrapperCss = React.useMemo(() => (
    css(styles.itemWrapper)
  ), [styles.itemWrapper])

  return (
    <div css={containerCss}>
      {products.map(product => (
        <div key={product.id} css={itemWrapperCss}>
          <ProductCard {...product}/>
        </div>
      )}
    </Container>
  )
}

Changelog

v1.1.0

  • Cleanup codes
  • Make test coverage 100%

License

MIT

use-pulled-grid's People

Contributors

cometkim avatar

Stargazers

MINJI avatar Jaisung Lee avatar Andrejs Agejevs avatar Dohyung Ahn avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

use-pulled-grid's Issues

An in-range update of lodash is breaking the build 🚨

The dependency lodash was updated from 4.17.11 to 4.17.12.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lodash is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ ci/circleci: build: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Style objects should be immutable

Class names are changed in the styled-component example (live demo).

This is weird behavior because Hooks would shallow compare all entries of the second argument in and triggered by its result.

If there is an inevitable reason for the style to update even though the result is the same, the hook should return an immutable object for ease of use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.