• Stars
    star
    856
  • Rank 53,268 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pinterest like layout components for React.js

react-stack-grid

Build Status npm version

Pinterest like layout components for React.js.

Table of Contents

Live Demo

Screenshot

https://tsuyoshiwada.github.io/react-stack-grid/

Install

You can install the react-stack-grid from npm.

$ npm install react-stack-grid

Quick Example

Following code is simplest usage.

import React, { Component } from "react";
import StackGrid from "react-stack-grid";

class MyComponent extends Component {
  render() {
    return (
      <StackGrid
        columnWidth={150}
      >
        <div key="key1">Item 1</div>
        <div key="key2">Item 2</div>
        <div key="key3">Item 3</div>
      </StackGrid>
    );
  }
}

width of parent is managed by react-sizeme.

Props

You can set the following properties.

Property Type Default Description
className PropTypes.string undefined Specify className of component.
style PropTypes.object {} Original style of component. Following styles are ignored. (position, height, transition)
gridRef PropTypes.func null Reference the instance of StackGrid. Unlike ordinary ref, it accepts only functions.
component PropTypes.string "div" See ReactTransitionGroup
itemComponent PropTypes.string "span" Specify the component of the grid item.
columnWidth PropTypes.oneOfType([PropTypes.number, PropTypes.string]) 150 Specify column width as an number(px), or percentage string. (Example "33.33%")
gutterWidth PropTypes.number 5 Specify gutter width as an number.
gutterHeight PropTypes.number 5 Specify gutter height as an number.
duration PropTypes.number 480 Specify duration of animation in ms.
easing PropTypes.string easings.quartOut Specify a css valid transition-timing-function string. It can be easily specification by using easings.
appearDelay PropTypes.number 30 Specify delay of the initial animation in ms.
appear PropTypes.func fadeUp.appear See Animations section.
appeared PropTypes.func fadeUp.appear ...
enter PropTypes.func fadeUp.appear ...
entered PropTypes.func fadeUp.appear ...
leaved PropTypes.func fadeUp.appear ...
units PropTypes.func { length: "px", angle: "deg" } ...
monitorImagesLoaded PropTypes.bool false If set to true, images reading is monitored. use imagesloaded.
vendorPrefix PropTypes.bool false If set to true, add a vendor prefix to styles add dynamically.
userAgent PropTypes.string undefined Specify userAgent for determinig the vendor prefix. See inline-style-prefixer.
enableSSR PropTypes.bool false Render component on the server side. More info.
onLayout PropTypes.func null It is called at the timing when the layout is confirmed, or at the updated timing. (Called only by client.)
horizontal PropTypes.bool false The transposed (horizontal) order of drawing elements. Retains the original order of the items.
rtl PropTypes.bool false When true, items are placed right-to-left instead of the default left-to-right. Useful for RTL languages such as Arabic and Hebrew.

Instance API

updateLayout(): void

Update the current layout.

Animations

The following function must return styles related to animation.
See ReactTransitionGroup for details.

  • appear
  • appeared
  • enter
  • entered
  • leaved

You can use extended syntax for transform's style. For example properties like translateX and scale.
See easy-css-transform-builder.

Each function is given the following arguments.

  • rect: { top: number; left: number; width: number; height: number; }
  • containerSize: { width: number; height: number; }
  • index: number

It is easiest to use them because you have several presets.

  • fade
  • fadeDown
  • fadeUp
  • scaleDown
  • scaleUp
  • flip
  • helix

It's an actual use example.

import StackGrid, { transitions } from "react-stack-grid";

const { scaleDown } = transitions;

class MyComponent extends Component {
  render() {
    return (
      <StackGrid
        ...
        appear={scaleDown.appear}
        appeared={scaleDown.appeared}
        enter={scaleDown.enter}
        entered={scaleDown.entered}
        leaved={scaleDown.leaved}
      >
        ...
      </StackGrid>
    );
  }
}

Please try actual demonstration in live demo.

Tips

Performance when using images

When true is specified for monitorImagesLoaded, reloading occurs when the image loading is completed.
If you know the size in advance, specify monitorImagesLoaded as false.

When animation is unnecessary

By default animation is enabled.
If it's not necessary, specify 0 for duration property.

<StackGrid
  ...
  duration={0}
>
  ...
</StackGrid/>

How to manually update layout ?

If the size of an item is changed by an action such as a click event, there are cases where you want to update the layout manually.
You can manually update the layout by referring to the StackGrid instance with gridRef and executing theupdateLayout() method.

class MyComponent extends React.Component {

  // When the size of the item is changed...
  something = () => {
    this.grid.updateLayout();
  };

  render() {
    return (
      <StackGrid
        gridRef={grid => this.grid = grid}
      >
        {/* items ... */}
      </StackGrid>
    );
  }
}

Responsive layout

You can get width using react-sizeme and change columnWidth according to width.
This is a solution, but we can respond in other ways!

import React, { Component } from 'react';
import sizeMe from 'react-sizeme';
import StackGrid from 'react-stack-grid';

class YourComponent extends Component {
  render() {
    const { 
      size: { 
        width
      } 
    } = this.props;

    return (
      <StackGrid
        // more...
        columnWidth={width <= 768 ? '100%' : '33.33%'}
      >
        // Grid items...
      </StackGrid>
    );
  }
}

export default sizeMe()(YourComponent);

Thanks

License

Released under the MIT Licence

ChangeLog

See CHANGELOG.md

Author

tsuyoshiwada

Development

Initialization of the project.

$ cd /your/project/dir
$ git clone https://github.com/tsuyoshiwada/react-stack-grid.git

Install some dependencies.

$ npm install

Start the development and can you see demo page (access to the http://localhost:3000/).

$ npm start

Run lint and testing.

$ npm test

Generates build file.

$ npm run build

Contribution

Thank you for your interest in react-stack-grid.js.
Bugs, feature requests and comments are more than welcome in the issues.

Before you open a PR:

Be careful to follow the code style of the project. Run npm test after your changes and ensure you do not introduce any new errors or warnings. All new features and changes need documentation.

Thanks!

More Repositories

1

vim-dogrun

🐶 A dark Neovim / Vim colorscheme for the GUI and 256 / true-color terminals.
Rust
454
star
2

sweet-scroll

🍭 ECMAScript2015+ & TypeScript Friendly, dependency-free smooth scroll library.
TypeScript
384
star
3

rs-monkey-lang

Monkey Programming Language written in Rust.
Rust
256
star
4

react-md-spinner

Material Design spinner components for React.js.
TypeScript
194
star
5

react-drip-form

☕ HoC based React forms state manager, Support for validation and normalization.
JavaScript
65
star
6

slack-memo-vim

Simple memo manager with Vim using Slack.
Vim Script
42
star
7

jp-prefecture

Utility library dealing with prefectures and regions in Japan.
JavaScript
33
star
8

github-pr-diff-tree

🌲 This action provide a comment that displays the diff of the pull request in a tree format.
TypeScript
31
star
9

dot-wild

Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON
TypeScript
29
star
10

sequential-number

An Atom package, to inputs sequential numbers across multiple cursors.
CoffeeScript
29
star
11

color-classifier

Classify the color along the reference color. using algorithm the CIEDE2000, RGB, HSV.
JavaScript
27
star
12

nvim-syntax-info

nvim-syntax-info is a plugin that displays syntax information (highlight-groups) with nvim_buf_set_virtual_text.
Vim Script
24
star
13

git-diff-archive

Archive of the diff files using node.js and git.
JavaScript
23
star
14

svg-to-jsx-with-gui

It's a tool to convert SVG to JSX on Web browser.
JavaScript
22
star
15

gin-sandbox

🐕 gin + gorm + jwt authenticate
Go
17
star
16

scs-with-reg-viz

A example repository of visual regression test using storybook-chrome-screenshot and reg-suit.
HTML
13
star
17

toy-tree

WEB+DB PRESS Vol.117「特集1 小さく始めて,大きく改善 実戦投入TypeScript」のサンプルリポジトリ
TypeScript
13
star
18

go-gitlog

Go (golang) package for providing a means to handle git-log.
Go
11
star
19

css-keyframer

Dynamic css animation keyframes Manipulation library.
JavaScript
11
star
20

git-prout

Checkout pull request locally with Golang.
Go
10
star
21

rs-td4

WebAssembly TD4 Emulator with Rust.
Rust
9
star
22

files-sync-action

📦 A customizable action that synchronizes files across multiple repositories.
TypeScript
9
star
23

htmltojsx

⚠️ [DEPRECATED] HTML to JSX converter. Forked from reactjs/react-magic. Support for SVG attributes.
JavaScript
8
star
24

cake-hash

CakePHP in Utility.Hash class like a collection manipulation. In JavaScript.
JavaScript
8
star
25

easy-css-transform-builder

Easily build CSS transform values with JavaScript.
TypeScript
8
star
26

jquery-pwd-measure

jQuery.pwdMeasure.js is jQuery plug-in that measure the strength of the password.
JavaScript
7
star
27

dotfiles

Vim Script
6
star
28

react-drip-form-material-ui

☕ Material-UI component set for react-drip-form.
JavaScript
6
star
29

react-tax-calculator

React.jsを使った消費税計算Webアプリ
JavaScript
6
star
30

lime-grid.css

Powerful Flexbox based Grid System for modern browsers.
CSS
6
star
31

redux-samples

Redux+ES6 samples
JavaScript
5
star
32

go-gitcmd

Go (golang) package providing for tiny git command wrapper.
Go
5
star
33

flamber

💥 WIP 💥 Inspiration scraping tool for Web Designer & Web Engineer.
JavaScript
5
star
34

redux-saga-sandbox

JavaScript
4
star
35

react-drip-form-components

☕ Official UI Components for react-drip-form. styling by styled-components.
JavaScript
4
star
36

blog.wadackel.me

@wadackel's blog.
Astro
4
star
37

drip-form-validator

☕ Simple and Powerful and Customizable validation library for JavaScript.
TypeScript
4
star
38

dot-wild-tiny

Use powerful dot notation (dot path + wildcard) to access properties of JSON
TypeScript
3
star
39

react-samples

JavaScript
3
star
40

sample-d3-pie-chart

JavaScript
2
star
41

jquery-image-changer

Simple jQuery plug-in that the switching of the image with the animation.
JavaScript
2
star
42

dot-finder

dot-finder is using powerful dot notation to get values in JSON object
JavaScript
2
star
43

tslint-ass-wipe-yourself

[EXPERIMENTAL RULE] A TSLint rule. annotation comment are requires assignee name.
TypeScript
2
star
44

gulp-babel-boilerplate

CSS
2
star
45

gha-docgen

📝 Generate documentation based on the Metadata of the GitHub Action.
TypeScript
1
star
46

react-selectable-sandbox

JavaScript
1
star
47

sample-jquery-tooltip

JavaScript
1
star
48

yarn-outdated-notifier-with-circleci

Example repository using yarn-outdated-notifier in CircleCI
1
star
49

react-drip-form-test-utils

Provides useful utilities for testing react-drip-form.
JavaScript
1
star
50

enzyme-sample

JavaScript
1
star
51

sample-webpack-coffee

JavaScript
1
star
52

sample-sort-colors

JavaScript
1
star
53

laravel-sandbox

PHP
1
star
54

react-drip-form-bootstrap

React Bootstrap component set for react-drip-form.
JavaScript
1
star
55

dialog-polyfill-on-ie11

HTML
1
star
56

jquery-sweet-scroll

JavaScript
1
star
57

actions-sandbox

JavaScript
1
star
58

indent2obj

Hierarchy expressed by the indent is converted into the JavaScript object.
JavaScript
1
star
59

sample-react-dnd

react-dndを使ってドラッグ&ドロップを実装するサンプル
JavaScript
1
star
60

directree

Indent text to Tree text.
CSS
1
star
61

react-lime-grid

lime-grid.css for React.js
JavaScript
1
star
62

template-obj

template strings in the javascript object.
JavaScript
1
star