Skip to content

Commit

Permalink
docs(README): add section on margin and rowHeight / column width.
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Jan 6, 2023
1 parent 89bf059 commit 30ac650
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,20 @@ will be draggable, even if the item is marked `static: true`.
}
```
### Grid Item Heights and Widths
Grid item widths are based on container and number of columns. The size of a grid unit's height is based on `rowHeight`.
Note that an item that has `h=2` is *not exactly twice as tall as one with `h=1` unless you have no `margin`*!
In order for the grid to not be ragged, when an item spans grid units, it must also span margins. So you must add the height or width or the margin you are spanning for each unit. So actual pixel height is `(rowHeight * h) + (marginH * (h - 1)`.
For example, with `rowHeight=30`, `margin=[10,10]` and a unit with height 4, the calculation is `(30 * 4) + (10 * 3)`
![margin](margin.png)
If this is a problem for you, set `margin=[0,0]` and handle visual spacing between your elements inside the elements' content.
### Performance
`<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:
Expand Down
Binary file added margin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30ac650

Please sign in to comment.