stylesnames
stylesnames conditionally applies style objects for react and react-native similar to how classes can be combinded in react with classnames.
Installation
npm i stylesnames
Usage
const styles = stylesnames const result = // result will be an array with all the style objects that apply. If disabled is// false it won't be in the resulting array. highlight will always be added,// while focus is only present if value is equal to 5.
React
import React Component from 'react'import stylesnames from 'stylesnames' const styles = stylesnames { const disabled label = thisprops return <div =>label</div> }
This will result in the following styles being applied:
<FakeButton label="Regular Button" />
backgroundColor: red;
<FakeButton label="Disabled Button" disabled />
backgroundColor: red;
opacity: 0.5;
React Native
import React Component from 'react'import View Text StyleSheet from 'react-native'import stylesnames from 'stylesnames' const styles = stylesnames { const disabled label = thisprops return <View => <Text>label</Text> </View> }
The result will be the same as for the react
example.
License
MIT