Skip to content

Commit a1eb43b

Browse files
committed
update README
1 parent 078bf92 commit a1eb43b

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,35 @@ In order to generate accurate media queries, all horizontal spacing must be appl
2727

2828
The components rely on a CSS-in-JS library of your choosing. You must provide a function which generates a class name based on an object of styles.
2929

30-
Example using emotion ([CodeSandbox link](https://codesandbox.io/s/rl0vjonq1n)):
30+
### Example using emotion
31+
32+
[![Edit 7ylpq13poq](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/7ylpq13poq)
3133

3234
```jsx
3335
import ReactDOM from 'react-dom'
34-
import React, { useContext } from 'react'
36+
import React from 'react'
3537
import { css } from 'emotion'
36-
import { Belt, Columns, CSSProvider, MQContext } from 'react-responsive-layout'
37-
38-
const createStyles = maxWidth => css`
38+
import {
39+
Belt,
40+
Columns,
41+
CSSProvider,
42+
useMediaQuery,
43+
} from 'react-responsive-layout'
44+
45+
const createStyles = mq => css`
3946
background-color: red;
4047
height: 100px;
4148
padding: 10px;
4249
43-
@media (max-width: ${maxWidth}px) {
50+
${mq} {
4451
background-color: lime;
4552
}
4653
`
4754

4855
const MyResponsiveComponent = () => {
49-
const { mq } = useContext(MQContext)
50-
const breakpoint = mq(200)
51-
const maxWidth = isFinite(breakpoint) ? breakpoint - 1 : 1000000
56+
const mq = useMediaQuery(200)
5257

53-
return <div className={createStyles(maxWidth)}>Hello</div>
58+
return <div className={createStyles(mq)}>Hello</div>
5459
}
5560

5661
const notches = [
@@ -62,7 +67,14 @@ const notches = [
6267
const App = () => (
6368
<CSSProvider value={{ css }}>
6469
<Belt notches={notches}>
65-
<Columns ratios={[1, 2, 1]} gap={10}>
70+
<Columns
71+
columns={[
72+
{ type: 'ratio', value: 1 },
73+
{ type: 'ratio', value: 2 },
74+
{ type: 'ratio', value: 1 },
75+
]}
76+
gap={10}
77+
>
6678
<MyResponsiveComponent />
6779
<MyResponsiveComponent />
6880
<MyResponsiveComponent />
@@ -71,8 +83,7 @@ const App = () => (
7183
</CSSProvider>
7284
)
7385

74-
const rootElement = document.getElementById('root')
75-
ReactDOM.render(<App />, rootElement)
86+
ReactDOM.render(<App />, document.getElementById('root'))
7687
```
7788

7889
This will render 3 columns with the middle column being twice as wide as the other two. At different window widths, the following will be rendered:
@@ -95,10 +106,12 @@ This will render 3 columns with the middle column being twice as wide as the oth
95106

96107
Props
97108

98-
| Name | Type | Default | Description |
99-
| -------- | ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
100-
| `ratios` | `number[]` | Required | The proportions to render each column. Equates to [`grid-template-columns`](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns). |
101-
| `gap` | `number` | `0` | The fixed spacing between each column (in pixels). Equates to [`grid-column-gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap) |
109+
| Name | Type | Default | Description |
110+
| ----------- | ------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
111+
| `columns` | `Array<{type: 'ratio' | 'fixed', value: number }` | Required | The proportions to render each column. Equates to [`grid-template-columns`](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns). |
112+
| `gap` | `number` | `0` | The fixed spacing between each column and row (in pixels). Equates to [`grid-gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/gap) |
113+
| `columnGap` | `number` | `gap` | The fixed spacing between each column and row (in pixels). Equates to [`grid-column-gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap) |
114+
| `rowGap` | `number` | `gap` | The fixed spacing between each row and row (in pixels). Equates to [`grid-row-gap`](https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap) |
102115

103116
### Belt
104117

@@ -108,4 +121,4 @@ Props
108121

109122
| Name | Type | Default | Description |
110123
| --------- | ----------------------------------------- | -------- | --------------------------------------------------------- |
111-
| `notches` | `Array<{ width: number, fluio: boolean}>` | Required | The widths at which the content should be constrained to. |
124+
| `notches` | `Array<{ width: number, fluid: boolean}>` | Required | The widths at which the content should be constrained to. |

0 commit comments

Comments
 (0)