Skip to content

Commit 70fb3ec

Browse files
authored
Merge pull request #1308 from adumesny/typescript
TS: #723 #726 `margin` to replace `verticalMargin`
2 parents 6c7f7e4 + b79a603 commit 70fb3ec

12 files changed

+743
-338
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,15 @@ make sure to read v1.0.0 migration first!
334334
335335
v2.x is a Typescript rewrite of 1.x, removing all jquery events, using classes and overall code cleanup. Your code might need to change from 1.x
336336
337-
1. In general methods that used no args (getter) vs setter are not used in Typescript.
338-
Also legacy methods that used to take tons of parameters will now take a single object (typically `GridstackOptions` or `GridStackWidget`).
337+
1. In general methods that used no args (getter) vs setter are not used in Typescript when the arguments differ.
338+
Also legacy methods that used to take many parameters will now take a single object (typically `GridstackOptions` or `GridStackWidget`).
339339
340340
```
341341
removed `addWidget(el, x, y, width, ...)` --> use the widget options version instead `addWidget(el, {with, ...})`
342342
`float()` to get value --> `getFloat()`
343343
'cellHeight()` to get value --> `getCellHeight()`
344-
'verticalMargin()` to get value --> `getVerticalMargin()`
344+
'verticalMargin' is now 'margin' grid options and applies to all 4 sides.
345+
'verticalMargin()` to get value --> `getMargin()`
345346
```
346347

347348
2. event signatures are generic and not jquery-ui dependent anymore. `gsresizestop` has been removed as `resizestop|dragstop` are now called **after** the DOm attributes have been updated.

demo/nested.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ <h1>Nested grids demo</h1>
5757
let nestOptions = {
5858
acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted, otherwise grid-items causes all sort of issues
5959
dragOut: true, // let us drag them out!
60-
disableOneColumnMode: true // nested are small, but still want N columns
60+
disableOneColumnMode: true, // nested are small, but still want N columns
61+
margin: 1
6162
};
6263
GridStack.init(null, '.grid-stack.top');
6364
let grid1 = GridStack.init(nestOptions, '.grid-stack.nested1');

doc/CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Change log
4040
- add `getGridItems()` to return list of HTML grid items
4141
- add `{dragIn | dragInOptions}` grid attributes to handle external drag&drop items
4242
- add `save()` and `restore()` to serialize grids from JSON, saving all attributes (not just w,h,x,y) [1286](https://github.com/gridstack/gridstack.js/issues/1286)
43+
- add `margin` to replace `verticalMargin` which affects both dimensions in code, rather than one in code the other in CSS.
44+
You can now have perfect square cells (default) [723](https://github.com/gridstack/gridstack.js/issues/723)
4345
- fix [1299](https://github.com/gridstack/gridstack.js/pull/1299) many columns round-off error
4446

4547
## 1.1.2 (2020-05-17)
@@ -210,7 +212,7 @@ thanks [@ermcgrat](https://github.com/ermcgrat) and others for pointing out code
210212
## v0.2.5 (2016-03-02)
211213

212214
- update names to respect js naming convention.
213-
- `cellHeight` and `verticalMargin` can now be string (e.g. '3em', '20px') (Thanks to @jlowcs).
215+
- `cellHeight` and `margin` can now be string (e.g. '3em', '20px') (Thanks to @jlowcs).
214216
- add `maxWidth`/`maxHeight` methods.
215217
- add `enableMove`/`enableResize` methods.
216218
- fix window resize issue [#331](https://github.com/gridstack/gridstack.js/issues/331)).

doc/README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gridstack.js API
2424
- [addWidget(el, [options])](#addwidgetel-options)
2525
- [batchUpdate()](#batchupdate)
2626
- [compact()](#compact)
27-
- [cellHeight(val, noUpdate)](#cellheightval-noupdate)
27+
- [cellHeight(val: number, update = true)](#cellheightval-number-update--true)
2828
- [cellWidth()](#cellwidth)
2929
- [commit()](#commit)
3030
- [column(column, doNotPropagate)](#columncolumn-donotpropagate)
@@ -37,9 +37,11 @@ gridstack.js API
3737
- [getCellHeight()](#getcellheight)
3838
- [getCellFromPixel(position[, useOffset])](#getcellfrompixelposition-useoffset)
3939
- [getGridItems(): GridItemHTMLElement[]](#getgriditems-griditemhtmlelement)
40+
- [getMargin()](#getmargin)
4041
- [isAreaEmpty(x, y, width, height)](#isareaemptyx-y-width-height)
4142
- [locked(el, val)](#lockedel-val)
4243
- [makeWidget(el)](#makewidgetel)
44+
- [margin(value: numberOrString)](#marginvalue-numberorstring)
4345
- [maxHeight(el, val)](#maxheightel-val)
4446
- [minHeight(el, val)](#minheightel-val)
4547
- [maxWidth(el, val)](#maxwidthel-val)
@@ -55,8 +57,6 @@ gridstack.js API
5557
- [setAnimation(doAnimate)](#setanimationdoanimate)
5658
- [setStatic(staticValue)](#setstaticstaticvalue)
5759
- [update(el, x, y, width, height)](#updateel-x-y-width-height)
58-
- [getVerticalMargin()](#getverticalmargin)
59-
- [verticalMargin(value, noUpdate)](#verticalmarginvalue-noupdate)
6060
- [willItFit(x, y, width, height, autoPosition)](#willitfitx-y-width-height-autoposition)
6161
- [Utils](#utils)
6262
- [GridStack.Utils.sort(nodes[, dir[, width]])](#gridstackutilssortnodes-dir-width)
@@ -76,11 +76,11 @@ gridstack.js API
7676
See [example](http://gridstack.github.io/gridstack.js/demo/advance.html)
7777
- `animate` - turns animation on (default: `false`)
7878
- `auto` - if `false` gridstack will not initialize existing items (default: `true`)
79-
- `cellHeight` - one cell height (default: `60`). Can be:
79+
- `cellHeight` - one cell height (default: `auto`). Can be:
8080
* an integer (px)
81-
* a string (ex: '100px', '10em', '10rem', '10%')
81+
* a string (ex: '100px', '10em', '10rem', '10%', `10vh')
8282
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
83-
* `'auto'` - height will be calculated cell square initially.
83+
* `'auto'` - height will be square cells initially.
8484
- `column` - number of columns (default: `12`) which can change on the fly with `column(N)` as well. See [example](http://gridstackjs.com/demo/column.html)
8585
- `ddPlugin` - class that implement drag'n'drop functionality for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
8686
- `disableDrag` - disallows dragging of widgets (default: `false`).
@@ -94,6 +94,13 @@ gridstack.js API
9494
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
9595
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
9696
- `itemClass` - widget class (default: `'grid-stack-item'`)
97+
- `margin` - gap size around grid item and content (default: `10`). Can be:
98+
* an integer (px)
99+
* a string (ex: '2em', '20px', '2rem')
100+
- `marginTop`: numberOrString - can set individual settings (defaults to `margin`)
101+
- `marginRight`: numberOrString
102+
- `marginBottom`: numberOrString
103+
- `marginLeft`: numberOrString
97104
- `maxRow` - maximum rows amount. Default is `0` which means no max.
98105
- `minRow` - minimum rows amount which is handy to prevent grid from collapsing when empty. Default is `0`. You can also do this with `min-height` CSS attribute on the grid div in pixels, which will round to the closest row.
99106
- `minWidth` - minimal width. If grid width is less than or equal to, grid will be shown in one-column mode (default: `768`)
@@ -106,9 +113,6 @@ gridstack.js API
106113
- `row` - fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`. (default `0` no constrain)
107114
- `rtl` - if `true` turns grid to RTL. Possible values are `true`, `false`, `'auto'` (default: `'auto'`) See [example](http://gridstackjs.com/demo/rtl.html)
108115
- `staticGrid` - removes drag&drop&resize (default `false`). If `true` widgets are not movable/resizable by the user, but code can still move and oneColumnMode will still work. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
109-
- `verticalMargin` - vertical gap size (default: `20`). Can be:
110-
* an integer (px)
111-
* a string (ex: '2em', '20px', '2rem')
112116

113117
## Grid attributes
114118

@@ -273,9 +277,9 @@ starts batch updates. You will see no changes until `commit()` method is called.
273277

274278
re-layout grid items to reclaim any empty space.
275279

276-
### cellHeight(val, noUpdate)
280+
### cellHeight(val: number, update = true)
277281

278-
Update current cell height. This method rebuilds an internal CSS stylesheet (unless optional noUpdate=true). Note: You can expect performance issues if
282+
Update current cell height. This method rebuilds an internal CSS stylesheet (unless optional update=false). Note: You can expect performance issues if
279283
call this method too often.
280284

281285
```js
@@ -284,7 +288,7 @@ grid.cellHeight(grid.cellWidth() * 1.2);
284288

285289
### cellWidth()
286290

287-
Gets current cell width.
291+
Gets current cell width (grid width / # of columns).
288292

289293
### commit()
290294

@@ -370,6 +374,10 @@ Returns an object with properties `x` and `y` i.e. the column and row in the gri
370374

371375
Return list of GridItem HTML dom elements (excluding temporary placeholder)
372376

377+
### getMargin()
378+
379+
returns current margin value.
380+
373381
### isAreaEmpty(x, y, width, height)
374382

375383
Checks if specified area is empty.
@@ -396,6 +404,12 @@ grid.el.appendChild('<div id="gsi-1" data-gs-x="0" data-gs-y="0" data-gs-width="
396404
grid.makeWidget('gsi-1');
397405
```
398406

407+
### margin(value: numberOrString)
408+
409+
set the top/right/bottom/left margin between grid item and content. Parameters:
410+
- `value` - new margin value. see `cellHeight` for possible value formats.
411+
Note: you can instead use `marginTop | marginBottom | marginLeft | marginRight` so set the sides separately.
412+
399413
### maxHeight(el, val)
400414

401415
Set the `maxHeight` for a widget.
@@ -506,17 +520,6 @@ Parameters:
506520

507521
Updates widget position/size.
508522

509-
### getVerticalMargin()
510-
511-
returns current vertical margin value.
512-
513-
### verticalMargin(value, noUpdate)
514-
515-
Parameters:
516-
517-
- `value` - new vertical margin value.
518-
- `noUpdate` - if true, styles will not be updated.
519-
520523
### willItFit(x, y, width, height, autoPosition)
521524

522525
Returns `true` if the `height` of the grid will be less the vertical constraint. Always returns `true` if grid doesn't

spec/e2e/html/1017-items-no-x-y-for-autoPosition.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<script type="text/javascript">
4848
let options = {
4949
cellHeight: 80,
50-
verticalMargin: 10,
50+
margin: 5,
5151
float: true
5252
};
5353
GridStack.init(options);

0 commit comments

Comments
 (0)