Skip to content

Commit f142df0

Browse files
committed
Refresh examples in readme
1 parent e4c5f09 commit f142df0

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

README.md

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -109,45 +109,46 @@ produce a grid with three items where:
109109
- item `b` will be restricted to a minimum width of 2 grid blocks and a maximum width of 4 grid blocks
110110
- users will be able to freely drag and resize item `c`
111111

112-
```javascript
113-
var ReactGridLayout = require('react-grid-layout');
112+
```js
113+
import GridLayout from 'react-grid-layout';
114114

115-
var MyFirstGrid = React.createClass({
116-
render: function() {
115+
class MyFirstGrid extends React.Component {
116+
render() {
117117
// layout is an array of objects, see the demo for more complete usage
118118
var layout = [
119119
{i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
120120
{i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4},
121121
{i: 'c', x: 4, y: 0, w: 1, h: 2}
122122
];
123123
return (
124-
<ReactGridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
124+
<GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
125125
<div key="a">a</div>
126126
<div key="b">b</div>
127127
<div key="c">c</div>
128-
</ReactGridLayout>
128+
</GridLayout>
129129
)
130130
}
131-
});
131+
}
132132
```
133133

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

136-
```javascript
137-
var ReactGridLayout = require('react-grid-layout');
136+
```js
137+
import GridLayout from 'react-grid-layout';
138138

139-
var MyFirstGrid = React.createClass({
140-
render: function () {
139+
class MyFirstGrid extends React.Component {
140+
render() {
141141
return (
142-
<ReactGridLayout className="layout" cols={12} rowHeight={30} width={1200}>
142+
<GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
143143
<div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}>a</div>
144144
<div key="b" data-grid={{x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}}>b</div>
145145
<div key="c" data-grid={{x: 4, y: 0, w: 1, h: 2}}>c</div>
146-
</ReactGridLayout>
146+
</GridLayout>
147147
)
148148
}
149-
});
149+
}
150150
```
151+
151152
### Usage without Browserify/Webpack
152153

153154
A module usable in a `<script>` tag is included [here](/dist/react-grid-layout.min.js). It uses a UMD shim and
@@ -157,21 +158,23 @@ excludes `React`, so it must be otherwise available in your application, either
157158

158159
To make RGL responsive, use the `<ResponsiveReactGridLayout>` element:
159160

160-
```javascript
161-
var ResponsiveReactGridLayout = require('react-grid-layout').Responsive;
162-
//...
163-
render: function() {
164-
// {lg: layout1, md: layout2, ...}
165-
var layouts = getLayoutsFromSomewhere();
166-
return (
167-
<ResponsiveReactGridLayout className="layout" layouts={layouts}
168-
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
169-
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
170-
<div key="1">1</div>
171-
<div key="2">2</div>
172-
<div key="3">3</div>
173-
</ResponsiveReactGridLayout>
174-
)
161+
```js
162+
import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
163+
164+
class MyResponsiveGrid extends React.Component {
165+
render() {
166+
// {lg: layout1, md: layout2, ...}
167+
var layouts = getLayoutsFromSomewhere();
168+
return (
169+
<ResponsiveGridLayout className="layout" layouts={layouts}
170+
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
171+
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
172+
<div key="1">1</div>
173+
<div key="2">2</div>
174+
<div key="3">3</div>
175+
</ResponsiveGridLayout>
176+
)
177+
}
175178
}
176179
```
177180

@@ -192,23 +195,25 @@ Both `<ResponsiveReactGridLayout>` and `<ReactGridLayout>` take `width` to calcu
192195
positions on drag events. In simple cases a HOC `WidthProvider` can be used to automatically determine
193196
width upon initialization and window resize events.
194197

195-
```javascript
196-
import {Responsive, WidthProvider} from 'react-grid-layout';
197-
const ResponsiveReactGridLayout = WidthProvider(Responsive);
198-
199-
//...
200-
render() {
201-
// {lg: layout1, md: layout2, ...}
202-
var layouts = getLayoutsFromSomewhere();
203-
return (
204-
<ResponsiveReactGridLayout className="layout" layouts={layouts}
205-
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
206-
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
207-
<div key="1">1</div>
208-
<div key="2">2</div>
209-
<div key="3">3</div>
210-
</ResponsiveReactGridLayout>
211-
)
198+
```js
199+
import { Responsive, WidthProvider } from 'react-grid-layout';
200+
201+
const ResponsiveGridLayout = WidthProvider(Responsive);
202+
203+
class MyResponsiveGrid extends React.Component {
204+
render() {
205+
// {lg: layout1, md: layout2, ...}
206+
var layouts = getLayoutsFromSomewhere();
207+
return (
208+
<ResponsiveGridLayout className="layout" layouts={layouts}
209+
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
210+
cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
211+
<div key="1">1</div>
212+
<div key="2">2</div>
213+
<div key="3">3</div>
214+
</ResponsiveGridLayout>
215+
)
216+
}
212217
}
213218
```
214219

@@ -226,7 +231,7 @@ listens to window `'resize'` events. If you need more power and flexibility, try
226231

227232
RGL supports the following properties (see the source for the final word on this):
228233

229-
```javascript
234+
```js
230235
//
231236
// Basic props
232237
//
@@ -322,7 +327,7 @@ onResizeStop: ItemCallback
322327
The responsive grid layout can be used instead. It supports all of the props above, excepting `layout`.
323328
The new properties and changes are:
324329

325-
```javascript
330+
```js
326331
// {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}
327332
// Breakpoint names are arbitrary but must match in the cols and layouts objects.
328333
breakpoints: ?Object = {lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0},
@@ -369,7 +374,7 @@ Any `<GridItem>` properties defined directly will take precedence over globally-
369374
example, if the layout has the property `isDraggable: false`, but the grid item has the prop `isDraggable: true`, the item
370375
will be draggable.
371376

372-
```javascript
377+
```js
373378
{
374379

375380
// A string corresponding to the component key

0 commit comments

Comments
 (0)