Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-conditional-stylesheet

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-conditional-stylesheet

React Native package that helps you selectively pick and merge styles based on provided conditions.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Usage

import { StyleSheet } from 'react-native';
import createSelector from 'react-native-conditional-stylesheet';

const styleSheet = StyleSheet.create({
    button: {
        backgroundColor: 'gray',
        padding: 20,
        borderRadius: 5,
    },
    buttonBlue: {
        backgroundColor: 'blue',
    },
    buttonRed: {
        backgroundColor: 'red',
    },
});
const select = createSelector(styleSheet);

class Button extends Component {
    static propTypes = {
        // Background color variations
        blue: PropTypes.bool,
        red: PropTypes.bool,
    }

    render() {
        // We use `button` as base style. Base on props button becomes blue or red, or stays gray.
        const style = select('button', {
            buttonBlue: this.props.blue,
            buttonRed: this.props.red,
        });

        // If you want to add some styles on the fly, use `.add` method to pass it down.
        style.add({ marginBottom: this.props.last ? 0 : 25 });

        return (
            <View style={style}>
                <Text>Press Me<Text/>
            </View>
        );
    }
}

TODO

  • docs
  • HOC
  • automatically pick platform specific styles when object contains ios or android keys

Keywords

FAQs

Package last updated on 05 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc