Giter VIP home page Giter VIP logo

react-snuggle's Introduction

React Snuggle

minzip

Lightweight React component to create css-based masonry-like layouts. Snuggle all your components really tight ๐Ÿ›Œ

Demo

Like a loving couple snuggling in bed, react-snuggle basically tries to make everything very intimate and comfortable by filling every space available (using CSS grid and a bit of javascript).

Features

  • ๐ŸคŸ Responsive: It works on all size screens;
  • ๐Ÿค™ Customizable: Easily change how your elements should snuggle;
  • ๐Ÿค Use your favorite library: CSS-in-JS, css modules, plain css, whatever. Feel free to use whatever you want;

Install:

yarn add react-snuggle

Usage:

import Snuggle from 'react-snuggle'

const List = () => (
  <Snuggle>
    <div>Item</div>
    <div>Item</div>
    ...
  </Snuggle>
)

Options

Name Type Default
item React.Element <div />
container React.Element <div />
rowGap Number 10
columnWidth Number 250

Methods

resize Recalculate all spaces available and snuggle each element z its space, it is helpful for lazing loading, resize listeners, and loading images.

Example:

const Component = () => {
  const snuggleRef = useRef()

  const onLoad = () => {
    if (snuggleRef.current) {
      snuggleRef.current.resize()
    }
  }

  return (
    <Snuggle ref={snuggleRef}>
      <img src="example.jpg" onLoad={onLoad} />
    </Snuggle>
  )
}

Todo

  • Span options (element fill two columns or more);
  • Filter elements;
  • Missing tests;
  • ...

License

MIT

Kudos

@andybarefoot Masonry style layout with CSS Grid


Significa Lda

Significa is an Oporto based digital studio founded in late 2013. Despite being specialised in Interaction Design and Brand Development, we believe that good design thinking can answer almost any question and solve most problems. We aim to provide meaningful design solutions to achieve the best user engagement possible in any situation.

react-snuggle's People

Contributors

danilowoz avatar dependabot[bot] avatar isabelsa avatar

Watchers

James Cloos avatar

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.