react-flexbox-grid icon indicating copy to clipboard operation
react-flexbox-grid copied to clipboard

Documentation for customization

Open redfrost opened this issue 8 years ago • 9 comments

Hi, thanks for the great grid system. It's very nice to use right out of the box, but it's hard to figure out where to start to modify some settings, for example gutter size between boxes.

It would be nice to have a detailed instruction or more examples.

redfrost avatar Jan 20 '17 05:01 redfrost

I'm not sure if this feature would be within the scope of this library. It is meant to only be a React wrapper around flexboxgrid, which doesn't offer this kind of customization.

I see why people would want to customize it, but currently I don't have any idea how to achieve this. Does anybody else?

flexboxgrid/src/css/flexboxgrid.css uses variables, maybe we could somehow use that, but it sounds very tricky.

silvenon avatar Feb 22 '17 11:02 silvenon

Thanks for your reply. In my case I got a simple sass setup like this to override default values, but I was wondering is there any way to approach in raw level in react by hijacking original variables, also I would like to see how other people do it.

$container-width: 1280px;
$container-gutter: 10px;
$breakpoint-sm: 960px;   // default 768px
$breakpoint-md: 1024px; // default 1024px
$breakpoint-lg: 1280px;   // default 1280px
$breakpoint-xlg:1920px;  // default 1920px

.grid {
  max-width: $container-width;
  padding-right: $container-gutter/2; 
  padding-left:  $container-gutter/2; 
  
    .col {
      padding: $container-gutter;
      @media (max-width: $breakpoint-sm - 1px) {
        max-width: 100%; 
        flex-basis:100%;
      }
    }
}

redfrost avatar Feb 23 '17 10:02 redfrost

Yeah, this is probably a pain, because you have to understand how flexboxgrid is written.

silvenon avatar Feb 27 '17 10:02 silvenon

I think CSS Modules support complicate our lives a bit, it would probably be much easier otherwise.

silvenon avatar Feb 27 '17 10:02 silvenon

Hi!

I faced this issue recently, and I was able to override the variables using webpack.NormalModuleReplacementPlugin like this:

/* webpack.config.js */

const NormalModuleReplacementPlugin = require('webpack');

// ...
plugins: [
      new NormalModuleReplacementPlugin(
      /node_modules\/flexboxgrid\/dist\/flexboxgrid\.css/,
      require.resolve('./src/styles/custom-flex-box-grid.css')
    )
]
// ...

And then, in that custom file:

/* custom-flex-box-grid.css */

@import 'flexboxgrid/src/css/flexboxgrid.css';

:root {
  --gutter-width: 0;
}

Hope this can be usefull!

alejandrolacasa avatar Mar 27 '17 10:03 alejandrolacasa

Any idea how to do this on the latest version that uses flexboxgrid2?

planetflash avatar Feb 22 '18 16:02 planetflash

I think one way would be to have more properties on Row and Col to allow more flexibility. I will try to have a look.

jsergiu avatar Jun 08 '18 13:06 jsergiu

This affects my usage of the component. Seeing that react-flexbox-grid consumes plain CSS from flexboxgrid2, it's not straightforward to override CSS4 variables programmatically. I was thinking of approaching this problem a couple ways:

  1. Refactor flexboxgrid2 to use Sass, and allow the consumer of react-flexbox-grid to provide overrides to its source files, and then be responsible for building react-flexbox-grid
  2. Refactor react-flexbox-grid to use a CSS-in-JS solution such as Emotion, that way react-flexbox-grid can accept settings as a prop and perform composition to override values and classes from flexboxgrid2

If either of these proposals seem attractive, let me know and I'll be glad to contribute.

theetrain avatar Jun 08 '18 14:06 theetrain

I just created a CSS-in-JS version that can be easily customized by passing an object:

const gridConfig = { 
  gutterWidth: 16, 
  outerMargin:8 
}

<div className={ FlexGrid.grid(gridConfig)}>  </div> 

Let me know what you think: https://github.com/LaloMrtnz/flexgrid-js 😛

lalomts avatar Jun 14 '18 07:06 lalomts