1.0.3 • Published 7 years ago
ifprop v1.0.3
Functions
fromTheme(name)
Extracts a value from theme.
Kind: global function
Param | Type | Description |
---|---|---|
name | string | The key for the theme value to return. |
Example
// returns props.theme.colorGrey
styled.div`
backgroundColor: ${fromTheme('colorGrey')};
`;
ifProp(mapping)
Returns a value dependent on the presence of props.
Kind: global function
Param | Type | Description |
---|---|---|
mapping | object | An object that maps prop keys to strings or functions. |
Example
// returns 'red' if 'colored' prop is not falsey, and 'black' otherwise.
styled.div`
backgroundColor: ${ifProp({
colored: 'red',
greyscale: 'grey',
default: 'black',
});
`;
ifPropEquals(mapping)
Returns a value dependent on the values of props.
Kind: global function
Param | Type | Description |
---|---|---|
mapping | object | An object that maps prop keys to strings or functions. |
Example
// returns '#ff0000' if 'color' prop equals 'red'.
styled.div`
background: ${ifPropEquals({
color: { red: '#ff0000', green: '#00800'},
image: { happyCows: 'url(happyCows)' },
default: fromTheme('black');
});
`;
fromProp(path)
Digs through props and returns value.
Kind: global function
Param | Type | Description |
---|---|---|
path | string | A string representation of the path of keys to parse. |
Example
// returns props.user.favoriteColors.green.
styled.div`
backgroundColor: ${fromProp('user.favoriteColors.green')};
`;