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

fix: improved documentatation #1137

Merged
merged 5 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Getting Started

- [Installation](#installation)
- [default breakpoints](#default-breakpoints)
- [custom breakpoints](#custom-breakpoints)
- [customization](#customization)
- [object notation](#object-notation)

API
Expand Down Expand Up @@ -136,7 +136,7 @@ const Component = styled.div`
`;
```

### Custom breakpoints
### Customization

```jsx
import { up, down, between, only } from 'styled-breakpoints';
Expand Down Expand Up @@ -219,9 +219,15 @@ For example, let's take default values of breakpoints.

### up

```jsx
// const up = (min: string, orientation?: 'portrait' | 'landscape') => any
<details><summary><strong>Type declaration</strong></summary>

```ts
declare function up(min: string, max: string, orientation?: 'portrait' | 'landscape') => any
```

</details>

```jsx
css`
${up('md')} {
background-color: rebeccapurple;
Expand All @@ -241,21 +247,27 @@ css`

### down

<details><summary><strong>Type declaration</strong></summary>

```ts
declare function down(max: string, orientation?: 'portrait' | 'landscape') => any
```

</details>

We occasionally use media queries that go in the other direction (the given screen size or smaller).

This function takes this declared breakpoint, subtracts 0.02px from it, and uses it as the maximum width value.

```tsx
// const down = (max: string, orientation?: 'portrait' | 'landscape') => any

css`
${down('md')} {
background-color: rebeccapurple;
}
`;
```

<details><summary><strong>Convert to pure css: </strong></summary>
<details><summary><strong>Convert to: </strong></summary>

```css
@media (max-width: 991.98px) {
Expand All @@ -273,19 +285,25 @@ css`

### between

<details><summary><strong>Type declaration</strong></summary>

```ts
declare function between(min: string, max: string, orientation?: 'portrait' | 'landscape') => any
```

</details>

Similarly, media queries may span multiple breakpoint widths:

```js
// const between = (min: string, max: string, orientation?: 'portrait' | 'landscape') => any

css`
${between('md', 'lg')} {
background-color: rebeccapurple;
}
`;
```

<details><summary><strong>Convert to pure css: </strong></summary>
<details><summary><strong>Convert to: </strong></summary>

```css
@media (min-width: 768px) and (max-width: 1199.98px) {
Expand All @@ -297,19 +315,25 @@ css`

### only

<details><summary><strong>Type declaration</strong></summary>

```ts
declare function only(name: string, orientation?: 'portrait' | 'landscape') => any
```

</details>

There is also function for targeting a single segment of screen sizes using the minimum and maximum breakpoint widths.

```jsx
// const only = (name: string, orientation?: 'portrait' | 'landscape') => any

css`
${only('md')} {
background-color: rebeccapurple;
}
`;
```

<details><summary><strong>Convert to pure css: </strong></summary>
<details><summary><strong>Convert to: </strong></summary>

```css
@media (min-width: 768px) and (max-width: 991.98px) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"name": "core",
"path": "./core",
"import": "{ createBreakpoints }",
"limit": "766 B"
"limit": "792 B"
},
{
"name": "core + styled-breakpoints",
Expand All @@ -78,7 +78,7 @@
"styled-breakpoints/index.js": "{ up, down, between, only }",
"react-emotion/index.js": "{ useBreakpoint }"
},
"limit": "1543 B"
"limit": "1544 B"
}
],
"prettier": {
Expand Down