Giter Site home page Giter Site logo

radium-grid's Introduction

Radium Grid Build Status Coverage Status Maintenance Status

Radium Grid is a powerful, no-fuss grid system component for React. It combines the best decisions from the ecosystem of (S)CSS-based grid systems and implements them hack-free on top of Flexbox.

What makes Radium Grid special?

  • Declarative layout using JSX.
  • Sensible defaults.
  • Uses arbitrary fractions for cell widths. No more 12-column straitjacket!
  • Infers rows from the given cell sizes. No need for explicit rows or extra <div>s!
  • Customizable cell alignment, including a hack-free vertical align!
  • Customizable fixed-width and fluid-width gutters. Just pass a CSS unit!
  • Customizable media queries for breakpoint definitions.
  • Uses Radium Style to handle breakpoint changes efficiently.
  • Accepts style arrays and resolves them with Radium Style.
  • Cascading defaults: set cell props on:
    • all cells for all sizes,
    • all cells for individual sizes,
    • a single cell for all sizes,
    • a single cell for individual sizes,
    • ...with the lowest props in the tree overriding parent props.

Prerelease

Although this is prerelease software, we'll do our best to avoid breaking public API changes.

Installation

npm install --save radium-grid

Usage

import { Grid, Cell } from 'radium-grid';

const App = () => {
  return (
    <Grid>
      <Cell>
        <p>Lorem</p>
      </Cell>
      <Cell>
        <p>ipsum</p>
      </Cell>
      <Cell>
        <p>dolor</p>
      </Cell>
      <Cell>
        <p>sit</p>
      </Cell>
    </Grid>
  );
}

The above example will render with the following provided defaults:

  • All cells in the grid are 1/3 wide for all screen sizes.
  • The grid uses a 16px fixed gutter.
  • Cell content is aligned to the top left.
  • The breakpoints use the following media queries:
    • small: "@media only screen and (max-width: 640px)",
    • medium: "@media only screen and (min-width: 641px) and (max-width: 1024px)",
    • large: "@media only screen and (min-width: 1025px) and (max-width: 1440px)",
    • xlarge: "@media only screen and (min-width: 1441px)"

To set a default width and alignment for every cell in the grid:

<Grid cellWidth="1/2">
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

An example of setting widths and alignment per screen size for every cell in the grid:

<Grid
  smallCellWidth="1"
  smallAlign="right"
  smallVerticalAlign="bottom"
  mediumCellWidth="1"
  mediumCellAlign="right"
  mediumCellVerticalAlign="bottom"
>
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

An example of custom per-cell widths and alignments:

<Grid>
  <Cell
    align="right"
    verticalAlign="bottom"
    width="1/4"
  >
    <p>Lorem</p>
  </Cell>
  <Cell
    align="left"
    verticalAlign="top"
    width="3/4"
  >
    <p>ipsum</p>
  </Cell>
  <Cell
    align="right"
    verticalAlign="bottom"
    width="3/4"
  >
    <p>dolor</p>
  </Cell>
  <Cell
    align="left"
    verticalAlign="top"
    width="1/4"
  >
    <p>sit</p>
  </Cell>
</Grid>

The same as above, but with different per-cell widths on small screens:

<Grid>
  <Cell
    align="right"
    verticalAlign="bottom"
    width="1/4"
    smallWidth="1/2"
  >
    <p>Lorem</p>
  </Cell>
  <Cell
    align="left"
    verticalAlign="top"
    width="3/4"
    smallWidth="1/2"
  >
    <p>ipsum</p>
  </Cell>
</Grid>

Custom gutters can use any valid CSS value string. Percentage values create fluid gutters, while all other values create fixed gutters. Example:

<Grid gutter="24px">
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

<Grid gutter="4%">
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

While we recommend the default breakpoints, you can customize them:

const breakpoints = {
  small: "@media only screen and (max-width: 320px)",
  medium: "@media only screen and (min-width: 320px) and (max-width: 640px)",
  large: "@media only screen and (min-width: 641px) and (max-width: 1024px)",
  xlarge: "@media only screen and (min-width: 1025px)"
}
<Grid breakpoints={breakpoints}>
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

Demo

There are more complex examples on the demo page. Check out the code in app.jsx.

Installation

  • Install builder: npm install -g builder
  • Clone this repo
  • npm install and then builder run hot will load a webpack dev server at localhost:3000

Gotchas

<Grid /> only accepts <Cell />s as children, since inserting arbitrary children can break the layout. Two options for custom children are:

  • Wrap the children in a <Cell />.
  • Move the children to a sibling of <Grid>.

Maintenance Status

Archived: This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

radium-grid's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

radium-grid's Issues

Investigate grid behavior when including iframes in cells

From @philholden, talking about a grid system he's working on:

We use iframes and these reload if an iframe is reparented or if a sibling before an iframe is removed from the DOM.

I am getting round this by drawing panels absolute, constraining the width measuring the height and then transitioning to the correct column and order. If an element gets removed then we need to insert a hidden placeholder div at this index in the panels array. The next panel added should reuse any placeholders in the panel array in preference to pushing on a new item.

Invalid context `_radiumStyleKeeper` of type `StyleKeeper` supplied to `Grid`

I'm trying out with this simple example:-

import { StyleRoot } from 'radium';
import { Grid, Cell } from 'radium-grid';
import React from 'react';

export default () => (
  <StyleRoot>
    <Grid>
      <Cell>
        <p>Lorem</p>
      </Cell>
      <Cell>
        <p>ipsum</p>
      </Cell>
      <Cell>
        <p>dolor</p>
      </Cell>
      <Cell>
        <p>sit</p>
      </Cell>
    </Grid>

  </StyleRoot>
);

It renders fine, but I'm seeing this error in the console:-

warning.js:45 Warning: Failed Context Types: Invalid context `_radiumStyleKeeper` of type `StyleKeeper` supplied to `Grid`, expected instance of `StyleKeeper`. Check the render method of `StatelessComponent`.

I'm using v1.1.0.

Thank you.

Initial Width UA

Hi All,

I'm getting an initial flicker of large sizes prior to snapping to small. I know the flicker for the initial grid render is due to inability to detect viewport on the server, is there any way to improve this without spinners or hiding during load?

If Radium already has a knowledge of the UA is there any fear of combining the current approach with UA detection to have an understanding of the UA type (Ie Mobile, tablet etc) prior to the first render and increasing the success rate of falling into the correct bracket of small, medium and large before hitting the client?

@tptee

Larger screen inherit settings from smaller screen settings?

In one of your examples you have this:

<Grid
  smallCellWidth="1"
  smallAlign="right"
  smallVerticalAlign="bottom"
  mediumCellWidth="1"
  mediumCellAlign="right"
  mediumCellVerticalAlign="bottom"
>
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

Would it not be better if all sizes above the size you use just inherited the closest setting below (like using min-width)? Then you don't need to write parameters for every screen size.

With the belove example, medium/large/xlarge would inherit the settings from the small:

<Grid
  smallCellWidth="1"
  smallAlign="right"
  smallVerticalAlign="bottom"
>
  <Cell>
    <p>Lorem</p>
  </Cell>
  <Cell>
    <p>ipsum</p>
  </Cell>
</Grid>

Radium as peer dependency

Should radium be a peer dependency instead of a regular one so that extra copies don't sneak in to builds?

Has this project been sidelined?

@tptee, I was looking for an update to issue #42 and noticed there hasn't been any major contributions for about a year now. If so is there an alternative that folks at Formidable have been using in its place lately?

Warning and errors when installing radium-grid

When trying to npm install radium-grid --save, I get this response:

npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130

> [email protected] install /Users/ole/Documents/webapps/rewebapp/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

[fsevents] Success: "/Users/ole/Documents/webapps/rewebapp/node_modules/fsevents/lib/binding/Release/node-v47-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] postinstall /Users/ole/Documents/webapps/rewebapp/node_modules/radium-grid
> cd lib || builder run npm:postinstall || (echo 'POSTINSTALL FAILED: If using npm v2, please upgrade to npm v3. See bug https://github.com/FormidableLabs/builder/issues/35' && exit 1)
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130

> [email protected] install /Users/ole/Documents/webapps/rewebapp/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

[fsevents] Success: "/Users/ole/Documents/webapps/rewebapp/node_modules/fsevents/lib/binding/Release/node-v47-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] postinstall /Users/ole/Documents/webapps/rewebapp/node_modules/radium-grid
> cd lib || builder run npm:postinstall || (echo 'POSTINSTALL FAILED: If using npm v2, please upgrade to npm v3. See bug https://github.com/FormidableLabs/builder/issues/35' && exit 1)

I also get this error:
UNMET PEER DEPENDENCY [email protected]

I use:
NPM 3.6.0
Radium 0.18.1

How can I resolve this?

support for IE 10?

First of all, this is a really nice project. Keep up the good work ๐Ÿ‘

I tried this grid in one of my projects and it doesn't seem to be working in IE10. I also tried the demo and it doesn't work in IE10 either. It looks like it's a problem with the styles in <Cell> components. I know that flexbox is not fully supported in IE10. So maybe radium-grid is not compatible with IE10?

This is how the demo looks like in IE10:

screen shot 2016-07-11 at 12 16 59 pm

Module build failed. Error: ./~/radium-grid/lib/index.js

Hi, nice component u got here.

I'm facing this error just after installing radium-grid with
npm install --save radium-grid and
import {Grid, Cell} from 'radium-grid'; in my react file.
When i run my task i get the error

 Error: ./~/radium-grid/lib/index.js
Module build failed: Error: [BABEL] /home/niggacode/Projects/Sites/kombo/node_modules/radium-grid/lib/index.js: Couldn't resolve extends clause of ./node_modules/builder-radium-component/config/babel/.babelrc in /home/niggacode/Projects/Sites/kombo/node_modules/radium-grid/.babelrc
    at Logger.error (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/logger.js:41:11)
    at ConfigChainBuilder.mergeConfig (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:190:32)
    at ConfigChainBuilder.addConfig (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:161:10)
    at ConfigChainBuilder.findConfigs (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:100:16)
    at buildConfigChain (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:65:13)
    at OptionManager.init (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:359:58)
    at File.initOptions (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/index.js:221:65)
    at new File (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/file/index.js:141:24)
    at Pipeline.transform (/home/niggacode/Projects/Sites/kombo/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/home/niggacode/Projects/Sites/kombo/node_modules/babel-loader/index.js:38:20)
 @ ./assets/jsx/main.js 22:18-40

I'm not sure what i am doing wrong, please help.

Array inside Grid style, breaks the styling?

This
<Grid style={[Styles.something.grid, Styles.something.grid.bgBlack]} >
and this
<Grid style={[Styles.something.grid]} >
seems to break the styling.

(While this works: <Grid style={Styles.something.grid} > )

Am I doing something wrong, or is it a bug?

[BUG] CI is failing.

https://travis-ci.org/FormidableLabs/radium-grid/builds/337671358?utm_source=github_status&utm_medium=notification

[builder:proc:start] Command: karma start --browsers PhantomJS,Firefox node_modules/builder-radium-component/config/karma/karma.conf.coverage.js
/home/travis/build/FormidableLabs/radium-grid/node_modules/di/lib/injector.js:9
      throw error('No provider for "' + name + '"!');
      ^
Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
    at error (/home/travis/build/FormidableLabs/radium-grid/node_modules/di/lib/injector.js:22:12)
    at Object.parent.get (/home/travis/build/FormidableLabs/radium-grid/node_modules/di/lib/injector.js:9:13)
    at get (/home/travis/build/FormidableLabs/radium-grid/node_modules/di/lib/injector.js:54:19)
    at /home/travis/build/FormidableLabs/radium-grid/node_modules/karma/lib/server.js:138:20
    at Array.forEach (native)
    at Server._start (/home/travis/build/FormidableLabs/radium-grid/node_modules/karma/lib/server.js:137:21)
    at invoke (/home/travis/build/FormidableLabs/radium-grid/node_modules/di/lib/injector.js:75:15)
    at Server.start (/home/travis/build/FormidableLabs/radium-grid/node_modules/karma/lib/server.js:102:18)
    at Object.exports.run (/home/travis/build/FormidableLabs/radium-grid/node_modules/karma/lib/cli.js:243:26)
    at Object.<anonymous> (/home/travis/build/FormidableLabs/radium-grid/node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
[builder:proc:end:1] Command: karma start --browsers PhantomJS,Firefox node_modules/builder-radium-component/config/karma/karma.conf.coverage.js
[builder:builder-core:end:3336] Task: run test-frontend-ci, Error: Command failed: sh -c karma start --browsers PhantomJS,Firefox node_modules/builder-radium-component/config/karma/karma.conf.coverage.js

Cell Offsets

I have a silly question: how do I center a single Cell inside a Grid?

<Grid>
  <Cell/>
</Grid>

I want to be able to give the Cell a certain width, but want to keep it horizontally in the center. I have tried doing this with adding empty Cells before and after, but I don't think that's the right way of doing it.

Edit: Basically I'm looking for the radium-grid's equivalent of Bootstrap's offset.

Why is 1441px the highest breakpoint?

First; this looks really nice, and I am super excited to try this out. Great job on improving and expanding the Radium family! :)

I only wonder why you have chosen 1441px as the highest breakpoint, and not make a xxlarge that breaks at 1921px (since there are so many larger displays these days)?

Cannot find module 'babel-runtime/helpers/interop-require'

After a few hours of debugging, I have determined that v1.1.0 causes Cannot find module 'babel-runtime/helpers/interop-require' error when I do npm run build.

Based on https://phabricator.babeljs.io/T6993 , it appears interop-require was a helper in Babel 5, but not anymore in Babel 6.

I attached my very simplified project (test.zip).

Run npm install, then npm run build to produce the error.

To be 100% sure, remove radium-grid dependency from package.json, then npm run reinstall (to clear node_modules and npm cache), then npm run build... and the problem goes away.

Thank you.

Radium in dist

The whole of radium is included in dist right now. Presumably, it should be referenced as an external and not built in.

Leveraging Grid's breakpoints using window.matchMedia(..)

This is due to my unfamiliarity with radium and media queries in general, but I'm trying to figure out how to leverage Grid's breakpoints using window.matchMedia(..) properly.

To further illustrate, here's a problem set... I want build a React component that wraps material-ui's LeftNav. The goal is if the Grid falls into large or xlarge category, I want the LeftNav to be shown. Otherwise, collapse it.

Ideally, I would like to reuse the radium-grid's default breakpoint values, if possible, instead of hardcoding the width.

So, my code looks something like this:-

// line in question... currently hardcoding max-width value from `Grid.defaultProps.breakpoints.medium`
const mediumGridMaxWidth = 1024;

const mql = window.matchMedia(`(min-width: ${mediumGridMaxWidth + 1}px)`);

export default class extends React.Component {
  constructor(props) {
    super(props);
    this.state = { open: true, mql };
  }

  componentWillMount() {
    this.state.mql.addListener(this.handleMediaQueryChanged);
    this.handleMediaQueryChanged();
  }

  componentWillUnmount() {
    this.state.mql.removeListener(this.handleMediaQueryChanged);
  }

  handleMediaQueryChanged = () => this.setState({ open: this.state.mql.matches });

  render() {
    return (
      <LeftNav open={this.state.open} containerStyle={style.leftNav}>
        <MenuItem href="/">Home</MenuItem>
        <MenuItem href="/chuck-norris">Chuck Norris</MenuItem>
      </LeftNav>
    );
  }
}

One way to get the breakpoint value, I can do rudimentary regexp... but it seems pretty hacky:-

// returns 1024
const mediumGridMaxWidth = parseInt(Grid.defaultProps.breakpoints.medium.match(/max-width: (\d+)px/)[1], 10);

Another way is to leverage css-mediaquery to do the same thing:-

import cssMediaQuery from 'css-mediaquery';

// returns 1024
const mediumGridMaxWidth = parseInt(cssMediaQuery
  .parse(Grid.defaultProps.breakpoints.medium)[0]
  .expressions.find(e => e.modifier === 'max' && e.feature === 'width').value, 10);

My question is... is there a better approach to apply radium-grid's breakpoints using window.matchMedia(..)?

Thank you.

Gutter issues caused by space-between

I'm a very interested follower of the Radium and Radium-Grid projects of yours.

I love your approach at using the space-between setting for creating the gutter, even though I somehow don't like the fact that it will only work if the Cells add up to a width of 1 for each wrapped line. And detecting line breaks to fill those gaps automatically with e.g. margins would require large amounts of logic involving the order property, given sizes etc., effectively reverse-engineering a fair part of the flexbox placement logic.

That's why I have two questions:

  1. Is there a specific reason why you chose to use the rather dynamic and unreliable space-between setting instead of e.g. center or flex-start/-end along with margins? After all, you do render a div per Cell anyways, so why not give it half a gutter as margin per side and make the gutter width adapt to the breakpoints? Even if the reason is that you don't want to have that half gutter before the first or after the last column (which is a common requirement on the other hand), you could easily remove that again using negative margin on the Grid component, which is also entirely under your control.
  2. Did you ever try to build a grid using higher-order components or decorators to avoid having too many layers of divs within the dom? I'm also a huge supporter of fighting all those unnecessary row, wrapper, container etc. divs in favor of trying to accomplish everything with one flex-container and its flex-items as children.

I would be really happy if you could give me your thoughts on those questions. Or maybe hint me towards a mailing list or discussion going on somewhere where people had the same ideas.

Is there any chance of using the radium-grid standalone ?

I really love the grid and I would love using it more, but I am not so keen on the Radium way of styling and all the "fuss".

So is it possible to use the grid without "Radium" and most of all without etc.

If not, you should mention "Radium" as a dependency for the grid in the Readme, since the user has to find that out after not being able to run the grid as is.

How to center align a Cell inside a Grid?

How can a Cell be placed in the middle of a grid?

For example; if I have a Cell with width='1/2', how can that Cell be placed inside the Grid so it have 1/4 of space on each side (without making extra Cells just to fill the empty space)?

Horizontal default prop issues

In
cellBreakpointDefault: {
width: props[size + "Width"],
horizontalAlign: props[size + "Align"],
verticalAlign: props[size + "VerticalAlign"],
order: props[size + "Order"]
}

as u can see this snippet is looking for smallAlign and not smallHorizontalAlign (which is the prop itself), just a small typo which should be fixed (or just use smallAlign/mediumAlign etc.. without prop validation)

Cell order should be aware of breakpoints

Although we can set the order of a given cell, it just sets the order for all the breakpoints and there's no way to change it unless using the style prop with media queries inside to mimic the existing breakpoints.

It should be possible to define different orders for different breakpoints so that we have total control over the cell order across all the breakpoints. Something like:

<Cell
  smallOrder={1}
  mediumOrder={2}
  largeOrder={3}
  xlargeOrder={4}
>
  ...
</Cell>

I'm going to submit a PR for this in a moment, just wanted to create the issue for future reference.

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.