Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests calcWH and calcXY #1637

Merged
merged 10 commits into from
Jan 6, 2022
14 changes: 5 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ jobs:
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: 14

- name: Install Node.js dependencies
run: yarn

- name: Run linters
uses: wearerequired/lint-action@v1
with:
eslint: true
prettier: true
- name: Run Prettier
run: yarn fmt:check

# Flow is not supported by lint-action, so we run it raw
- name: Run Flow
run: yarn flow
- name: Run ESLint/Flow
run: yarn lint
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
make lint
yarn flow
make test
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ node_js:
script:
- make build test
cache: yarn

618 changes: 353 additions & 265 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lint:
@$(BIN)/eslint --ext .js,.jsx

test:
env NODE_ENV=test $(BIN)/jest
env NODE_ENV=test $(BIN)/jest --coverage

test-watch:
env NODE_ENV=test $(BIN)/jest --watch
Expand Down
112 changes: 65 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ or autogenerated.
RGL is React-only and does not require jQuery.

![BitMEX UI](http://i.imgur.com/oo1NT6c.gif)

> GIF from production usage on [BitMEX.com](https://www.bitmex.com)

[**[Demo](https://react-grid-layout.github.io/react-grid-layout/) | [Changelog](/CHANGELOG.md) | [CodeSandbox Editable demo](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js)**]
Expand Down Expand Up @@ -77,32 +78,32 @@ RGL is React-only and does not require jQuery.
- [Statsout](https://statsout.com/)
- [Datto RMM](https://www.datto.com/uk/products/rmm/)

*Know of others? Create a PR to let me know!*
_Know of others? Create a PR to let me know!_

## Features

* 100% React - no jQuery
* Compatible with server-rendered apps
* Draggable widgets
* Resizable widgets
* Static widgets
* Configurable packing: horizontal, vertical, or off
* Bounds checking for dragging and resizing
* Widgets may be added or removed without rebuilding grid
* Layout can be serialized and restored
* Responsive breakpoints
* Separate layouts per responsive breakpoint
* Grid Items placed using CSS Transforms
* Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
* Compatibility with `<React.StrictMode>`

|Version | Compatibility |
|----------------|------------------|
| >= 0.17.0 | React 16 & 17 |
| >= 0.11.3 | React 0.14 & 15 |
| >= 0.10.0 | React 0.14 |
| 0.8. - 0.9.2 | React 0.13 |
| < 0.8 | React 0.12 |
- 100% React - no jQuery
- Compatible with server-rendered apps
- Draggable widgets
- Resizable widgets
- Static widgets
- Configurable packing: horizontal, vertical, or off
- Bounds checking for dragging and resizing
- Widgets may be added or removed without rebuilding grid
- Layout can be serialized and restored
- Responsive breakpoints
- Separate layouts per responsive breakpoint
- Grid Items placed using CSS Transforms
- Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
- Compatibility with `<React.StrictMode>`

| Version | Compatibility |
| ------------ | --------------- |
| >= 0.17.0 | React 16 & 17 |
| >= 0.11.3 | React 0.14 & 15 |
| >= 0.10.0 | React 0.14 |
| 0.8. - 0.9.2 | React 0.13 |
| < 0.8 | React 0.12 |

## Installation

Expand All @@ -129,41 +130,53 @@ produce a grid with three items where:
- users will be able to freely drag and resize item `c`

```js
import GridLayout from 'react-grid-layout';
import GridLayout from "react-grid-layout";

class MyFirstGrid extends React.Component {
render() {
// layout is an array of objects, see the demo for more complete usage
const layout = [
{i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
{i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4},
{i: 'c', x: 4, y: 0, w: 1, h: 2}
{ i: "a", x: 0, y: 0, w: 1, h: 2, static: true },
{ i: "b", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
{ i: "c", x: 4, y: 0, w: 1, h: 2 }
];
return (
<GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
<GridLayout
className="layout"
layout={layout}
cols={12}
rowHeight={30}
width={1200}
>
<div key="a">a</div>
<div key="b">b</div>
<div key="c">c</div>
</GridLayout>
)
);
}
}
```

You may also choose to set layout properties directly on the children:

```js
import GridLayout from 'react-grid-layout';
import GridLayout from "react-grid-layout";

class MyFirstGrid extends React.Component {
render() {
return (
<GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
<div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}>a</div>
<div key="b" data-grid={{x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}}>b</div>
<div key="c" data-grid={{x: 4, y: 0, w: 1, h: 2}}>c</div>
<div key="a" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}>
a
</div>
<div key="b" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}>
b
</div>
<div key="c" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}>
c
</div>
</GridLayout>
)
);
}
}
```
Expand All @@ -178,21 +191,24 @@ excludes `React`, so it must be otherwise available in your application, either
To make RGL responsive, use the `<ResponsiveReactGridLayout>` element:

```js
import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
import { Responsive as ResponsiveGridLayout } from "react-grid-layout";

class MyResponsiveGrid extends React.Component {
render() {
// {lg: layout1, md: layout2, ...}
const layouts = getLayoutsFromSomewhere();
return (
<ResponsiveGridLayout className="layout" layouts={layouts}
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
<ResponsiveGridLayout
className="layout"
layouts={layouts}
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
>
<div key="1">1</div>
<div key="2">2</div>
<div key="3">3</div>
</ResponsiveGridLayout>
)
);
}
}
```
Expand All @@ -215,7 +231,7 @@ positions on drag events. In simple cases a HOC `WidthProvider` can be used to a
width upon initialization and window resize events.

```js
import { Responsive, WidthProvider } from 'react-grid-layout';
import { Responsive, WidthProvider } from "react-grid-layout";

const ResponsiveGridLayout = WidthProvider(Responsive);

Expand All @@ -224,14 +240,17 @@ class MyResponsiveGrid extends React.Component {
// {lg: layout1, md: layout2, ...}
var layouts = getLayoutsFromSomewhere();
return (
<ResponsiveGridLayout className="layout" layouts={layouts}
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
<ResponsiveGridLayout
className="layout"
layouts={layouts}
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
>
<div key="1">1</div>
<div key="2">2</div>
<div key="3">3</div>
</ResponsiveGridLayout>
)
);
}
}
```
Expand Down Expand Up @@ -494,7 +513,6 @@ will be draggable, even if the item is marked `static: true`.

`<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:


```js
// lib/ReactGridLayout.jsx
// ...
Expand All @@ -517,7 +535,7 @@ If you memoize your children, you can take advantage of this, and reap faster re
function MyGrid(props) {
const children = React.useMemo(() => {
return new Array(props.count).fill(undefined).map((val, idx) => {
return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
return <div key={idx} data-grid={{ x: idx, y: 1, w: 1, h: 1 }} />;
});
}, [props.count]);
return <ReactGridLayout cols={12}>{children}</ReactGridLayout>;
Expand All @@ -540,7 +558,7 @@ const CustomGridItemComponent = React.forwardRef(({style, className, ...props},
return (
<div style={{ /* styles */, ...style}} className={className} ref={ref}>
{/* Some other content */}
</div>
</div>
);
}
```
Expand Down
3 changes: 2 additions & 1 deletion index-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = require("./lib/ReactGridLayout").default;
module.exports.utils = require("./lib/utils");
module.exports.Responsive = require("./lib/ResponsiveReactGridLayout").default;
module.exports.Responsive.utils = require("./lib/responsiveUtils");
module.exports.WidthProvider = require("./lib/components/WidthProvider").default;
module.exports.WidthProvider =
require("./lib/components/WidthProvider").default;
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = require("./build/ReactGridLayout").default;
module.exports.utils = require("./build/utils");
module.exports.Responsive = require("./build/ResponsiveReactGridLayout").default;
module.exports.Responsive =
require("./build/ResponsiveReactGridLayout").default;
module.exports.Responsive.utils = require("./build/responsiveUtils");
module.exports.WidthProvider = require("./build/components/WidthProvider").default;
module.exports.WidthProvider =
require("./build/components/WidthProvider").default;
14 changes: 0 additions & 14 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,20 +770,6 @@ export function validateLayout(
);
}
}
if (item.i && typeof item.i !== "string") {
throw new Error(
"ReactGridLayout: " + contextName + "[" + i + "].i must be a string!"
);
}
if (item.static !== undefined && typeof item.static !== "boolean") {
throw new Error(
"ReactGridLayout: " +
contextName +
"[" +
i +
"].static must be a boolean!"
);
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"dev": "make dev",
"prepublishOnly": "make build",
"validate": "npm ls",
"flow": "flow"
"flow": "flow",
"fmt": "prettier --write ./**.{json,js,yml,md}",
"fmt:check": "prettier --check ./**.{json,js,yml,md}"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -102,11 +104,20 @@
"<rootDir>/test/spec/*.js"
],
"testEnvironment": "jsdom",
"testURL": "http://localhost"
"testURL": "http://localhost",
"coverageThreshold": {
"global": {
"statements": 75.15,
"branches": 69.16,
"functions": 77.12,
"lines": 77.07
}
}
},
"lint-staged": {
"*.{js,jsx,css}": [
"prettier --write"
"eslint --ext .js,.jsx --fix",
"yarn fmt"
]
}
}
Loading