Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 702b329

Browse files
committed
docs: document utilities
Closes #37
1 parent 30de417 commit 702b329

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

docs/basics/Utilities.mdx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: Utilities
3+
menu: 1. Basics
4+
order: 6
5+
---
6+
7+
import { Playground } from 'docz'
8+
9+
# Utilities
10+
11+
Smooth UI exposes several utilities to simplify the styling of components.
12+
13+
## Styling utilities
14+
15+
### styled
16+
17+
`styled` is exported from `react-emotion` if you use `@smooth-ui/core-em` or from `styled-components` if you use `@smooth-ui/core-sc`.
18+
19+
```js
20+
import { styled } from '@smooth-ui/core-sc'
21+
22+
const Box = styled.div`
23+
width: 200px;
24+
height: 100px;
25+
`
26+
```
27+
28+
### css
29+
30+
`css` offers the same experience as [`styled-components` css utility](https://www.styled-components.com/docs/api#css). It means that props interpolations are supported even if you `@smooth-ui/core-em`.
31+
32+
```js
33+
import { styled, css } from '@smooth-ui/core-sc'
34+
35+
const bordered = css`
36+
border: 1px solid ${p => p.borderColor};
37+
`
38+
39+
const Box = styled.div`
40+
width: 200px;
41+
height: 100px;
42+
${bordered}
43+
`
44+
```
45+
46+
### th
47+
48+
`th` lets you get a property from the theme, you can also apply a modifier.
49+
50+
```js
51+
import { styled, th } from '@smooth-ui/core-sc'
52+
53+
const RedBox = styled.div`
54+
width: 200px;
55+
height: 200px;
56+
background-color: ${th('primary')};
57+
border: 1px solid ${th('primary', color => darken(0.2, color))};
58+
`
59+
```
60+
61+
### prop
62+
63+
`prop` lets you get a property from props, you can also specify a theme default.
64+
65+
```js
66+
import { styled, th } from '@smooth-ui/core-sc'
67+
68+
const RedBox = styled.div`
69+
width: 200px;
70+
height: 200px;
71+
background-color: ${prop('bgColor', 'primary')};
72+
`
73+
```
74+
75+
### unit, px
76+
77+
`unit` automatically adds unit.
78+
79+
```js
80+
import { unit, px } from '@smooth-ui/core-sc'
81+
82+
unit('px')(10) // 10px
83+
unit('em')(10) // 10em
84+
unit('em')('20px') // 20px
85+
86+
// `px` is similar to `unit('px')`
87+
px(10) // 10px
88+
```
89+
90+
## Responsive utilities
91+
92+
### up, down, between
93+
94+
`up`, `down` and `between` let you apply style relative to breakpoints.
95+
96+
97+
```js
98+
import { styled, css, up } from '@smooth-ui/core-sc'
99+
100+
const RedBox = styled.div`
101+
width: 200px;
102+
height: 200px;
103+
${up('md', css`
104+
height: 300px;
105+
`)}
106+
`
107+
```

0 commit comments

Comments
 (0)