1.0.3 • Published 7 years ago

ifprop v1.0.3

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
7 years ago

Functions

fromTheme(name)

Extracts a value from theme.

Kind: global function

ParamTypeDescription
namestringThe 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

ParamTypeDescription
mappingobjectAn 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

ParamTypeDescription
mappingobjectAn 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

ParamTypeDescription
pathstringA string representation of the path of keys to parse.

Example

// returns props.user.favoriteColors.green.
styled.div`
 backgroundColor: ${fromProp('user.favoriteColors.green')};
`;
1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago