@@ -18,18 +18,18 @@ Useful interpolated functions for [styled-components](https://github.com/styled-
1818Play with it on [ WebpackBin] ( https://www.webpackbin.com/bins/-Kel3KgddZSrD5oK0fIk )
1919
2020``` jsx
21- import styled , { css } from ' styled-components'
22- import { prop , ifProp , switchProp } from ' styled-tools'
21+ import styled , { css } from " styled-components" ;
22+ import { prop , ifProp , switchProp } from " styled-tools" ;
2323
2424const Button = styled .button `
25- color: ${ prop (' color' , ' red' )} ;
26- font-size: ${ ifProp ({ size: ' large' }, ' 20px' , ' 14px' )} ;
27- background-color: ${ switchProp (' theme' , {
28- dark: ' blue' ,
29- darker: ' mediumblue' ,
30- darkest: ' darkblue'
25+ color: ${ prop (" color" , " red" )} ;
26+ font-size: ${ ifProp ({ size: " large" }, " 20px" , " 14px" )} ;
27+ background-color: ${ switchProp (" theme" , {
28+ dark: " blue" ,
29+ darker: " mediumblue" ,
30+ darkest: " darkblue"
3131 })} ;
32- `
32+ ` ;
3333
3434// renders with color: blue
3535< Button color= " blue" / >
@@ -48,31 +48,31 @@ A more complex example:
4848
4949``` jsx
5050const Button = styled .button `
51- color: ${ prop (' theme.colors.white' , ' #fff' )} ;
52- font-size: ${ ifProp ({ size: ' large' }, prop (' theme.sizes.lg' , ' 20px' ), prop (' theme.sizes.md' , ' 14px' ))} ;
53- background-color: ${ prop (' theme.colors.black' , ' #000' )} ;
51+ color: ${ prop (" theme.colors.white" , " #fff" )} ;
52+ font-size: ${ ifProp ({ size: " large" }, prop (" theme.sizes.lg" , " 20px" ), prop (" theme.sizes.md" , " 14px" ))} ;
53+ background-color: ${ prop (" theme.colors.black" , " #000" )} ;
5454
55- ${ switchProp (' kind' , {
55+ ${ switchProp (" kind" , {
5656 dark: css`
57- background-color: ${ prop (' theme.colors.blue' , ' blue' )} ;
58- border: 1px solid ${ prop (' theme.colors.blue' , ' blue' )} ;
57+ background-color: ${ prop (" theme.colors.blue" , " blue" )} ;
58+ border: 1px solid ${ prop (" theme.colors.blue" , " blue" )} ;
5959 ` ,
6060 darker: css`
61- background-color: ${ prop (' theme.colors.mediumblue' , ' mediumblue' )} ;
62- border: 1px solid ${ prop (' theme.colors.mediumblue' , ' mediumblue' )} ;
61+ background-color: ${ prop (" theme.colors.mediumblue" , " mediumblue" )} ;
62+ border: 1px solid ${ prop (" theme.colors.mediumblue" , " mediumblue" )} ;
6363 ` ,
6464 darkest: css`
65- background-color: ${ prop (' theme.colors.darkblue' , ' darkblue' )} ;
66- border: 1px solid ${ prop (' theme.colors.darkblue' , ' darkblue' )} ;
67- ` ,
65+ background-color: ${ prop (" theme.colors.darkblue" , " darkblue" )} ;
66+ border: 1px solid ${ prop (" theme.colors.darkblue" , " darkblue" )} ;
67+ `
6868 })}
6969
70- ${ ifProp (' disabled' , css`
71- background-color: ${ prop (' theme.colors.gray' , ' #999' )} ;
72- border-color: ${ prop (' theme.colors.gray' , ' #999' )} ;
70+ ${ ifProp (" disabled" , css`
71+ background-color: ${ prop (" theme.colors.gray" , " #999" )} ;
72+ border-color: ${ prop (" theme.colors.gray" , " #999" )} ;
7373 pointer-events: none;
7474 ` )}
75- `
75+ ` ;
7676```
7777
7878## API
@@ -101,8 +101,8 @@ Returns the value of `props[path]` or `defaultValue`
101101
102102``` javascript
103103const Button = styled .button `
104- color: ${ prop (' color' , ' red' )} ;
105- `
104+ color: ${ prop (" color" , " red" )} ;
105+ ` ;
106106```
107107
108108Returns ** any**
@@ -121,15 +121,15 @@ Returns `pass` if prop is truthy. Otherwise returns `fail`
121121
122122``` javascript
123123// usage with styled-theme
124- import styled from ' styled-components'
125- import { ifProp } from ' styled-tools'
126- import { palette } from ' styled-theme'
124+ import styled from " styled-components" ;
125+ import { ifProp } from " styled-tools" ;
126+ import { palette } from " styled-theme" ;
127127
128128const Button = styled .button `
129- background-color: ${ ifProp (' transparent' , ' transparent' , palette (0 ))} ;
130- color: ${ ifProp ([' transparent' , ' accent' ], palette (' secondary' , 0 ))} ;
131- font-size: ${ ifProp ({ size: ' large' }, ' 20px' , ifProp ({ size: ' medium' }, ' 16px' , ' 12px' ))} ;
132- `
129+ background-color: ${ ifProp (" transparent" , " transparent" , palette (0 ))} ;
130+ color: ${ ifProp ([" transparent" , " accent" ], palette (" secondary" , 0 ))} ;
131+ font-size: ${ ifProp ({ size: " large" }, " 20px" , ifProp ({ size: " medium" }, " 16px" , " 12px" ))} ;
132+ ` ;
133133```
134134
135135Returns ** any**
@@ -147,23 +147,22 @@ Calls a function passing properties values as arguments.
147147
148148``` javascript
149149// example with polished
150- import styled from ' styled-components'
151- import { darken } from ' polished'
152- import { withProp , prop } from ' styled-tools'
150+ import styled from " styled-components" ;
151+ import { darken } from " polished" ;
152+ import { withProp , prop } from " styled-tools" ;
153153
154154const Button = styled .button `
155- border-color: ${ withProp (prop (' theme.primaryColor' , ' blue' ), darken (0.5 ))} ;
156- font-size: ${ withProp (' theme.size' , size => ` ${ size + 1 } px` )} ;
157- background: ${ withProp ([' foo' , ' bar' ], (foo , bar ) => ` ${ foo}${ bar} ` )} ;
158- `
155+ border-color: ${ withProp (prop (" theme.primaryColor" , " blue" ), darken (0.5 ))} ;
156+ font-size: ${ withProp (" theme.size" , size => ` ${ size + 1 } px` )} ;
157+ background: ${ withProp ([" foo" , " bar" ], (foo , bar ) => ` ${ foo}${ bar} ` )} ;
158+ ` ;
159159```
160160
161161Returns ** any**
162162
163163### switchProp
164164
165165Switches on a given prop. Returns the value or function for a given prop value.
166- Otherwise returns ` defaultValue `
167166
168167** Parameters**
169168
@@ -173,26 +172,26 @@ Otherwise returns `defaultValue`
173172** Examples**
174173
175174``` javascript
176- import styled , { css } from ' styled-components'
177- import { switchProp , prop } from ' styled-tools'
175+ import styled , { css } from " styled-components" ;
176+ import { switchProp , prop } from " styled-tools" ;
178177
179178const Button = styled .button `
180- font-size: ${ switchProp (prop (' size' , ' medium' ), {
181- small: prop (' theme.sizes.sm' , ' 12px' ),
182- medium: prop (' theme.sizes.md' , ' 16px' ),
183- large: prop (' theme.sizes.lg' , ' 20px' ),
179+ font-size: ${ switchProp (prop (" size" , " medium" ), {
180+ small: prop (" theme.sizes.sm" , " 12px" ),
181+ medium: prop (" theme.sizes.md" , " 16px" ),
182+ large: prop (" theme.sizes.lg" , " 20px" )
184183 }};
185- ${switchProp (' theme.kind' , {
184+ ${switchProp (" theme.kind" , {
186185 light: css`
187186 color: LightBlue;
188187 ` ,
189188 dark: css`
190189 color: DarkBlue;
191- ` ,
190+ `
192191 })}
193- `
192+ ` ;
194193
195- <Button size="large" theme={{ kind: ' light' }} />
194+ <Button size="large" theme={{ kind: " light" }} />
196195` ` `
197196
198197Returns ** any**
0 commit comments