Skip to content

Commit

Permalink
docs(responsive): add child function usage notes
Browse files Browse the repository at this point in the history
  • Loading branch information
theetrain committed Nov 15, 2017
1 parent 494edab commit e569fce
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/components/Responsive/Responsive.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
### Usage

The Responsive component is a thin wrapper over the [**react-responsive**](https://github.com/contra/react-responsive) community component. We encourage mobile-first development by using the `minWidth` prop exclusively, though you're welcome to use `maxWidth` or any of the other props supplied by **react-responsive** if the need arises; **note** if you do use props supplied by react-responsive, you must provide pixel values and not breakpoint keys as used by the Responsive component.

### Breakpoints

Using the `minWidth` and `maxWidth` props, you can pass a breakpoint key. They represent the following:

| Breakpoint key | Value as `minWidth` | Value as `maxWidth` |
| ---------- | ------------------- | ------------------- |
| -------------- | ------------------- | ------------------- |
| `sm` | 576px | 575px |
| `md` | 768px | 767px |
| `lg` | 992px | 991px |
| `xl` | 1200px | 1199px |

### Basic usage

```jsx
<div>
<Responsive minWidth='xs' maxWidth='md'>
<Responsive minWidth="xs" maxWidth="md">
<Heading level="h1">Hello I'm a heading in XS and SM</Heading>
</Responsive>
<Responsive minWidth='md' maxWidth='lg'>
<Responsive minWidth="md" maxWidth="lg">
<Card>
Hello I'm a Card in MD
</Card>
</Responsive>
<Responsive minWidth='lg'>
<Responsive minWidth="lg">
<Button>Hello I'm a Button in L and XL</Button>
</Responsive>
</div>
```
### Passing a child function
Since the Responsive component wraps **react-responsive**, you may pass a function as the only child to perform logical operations based on whether or not the query matches the browser viewport.
```jsx
<Responsive minWidth="sm">
{
(matches) =>
matches ? "You're using a large display." : "You're viewing this on mobile."
}
</Responsive>
```

0 comments on commit e569fce

Please sign in to comment.