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.

  • 1.1.1
  • Source
  • npm
  • Socket score

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

Usage

// Import using ES6 syntax
import ConditionalStyleSheet from 'react-native-conditional-stylesheet';

// ... or use `require`
const ConditionalStyleSheet = require('react-native-conditional-stylesheet');

// Create conditional style builder as you would create traditional styles.
const buildStyle = ConditionalStyleSheet.create({
  base: {
    fontSize: 200,
    backgroundColor: 'white',
  },
  success: {
    color: 'green',
  },
  danger: {
    color: 'red',
  },
});

const Button = (props) => {
  let style;

  // Build style:
  //
  // 1, Explicitly name styles to pick & use
  style = buildStyle('base', 'active');

  // 2, Selectively pick styles based on given conditions
  style = buildStyle('base', {
    success: props.success,
    danger: props.danger,
  });

  // 3, Push custom style on the fly for additional styling
  // or to override previously passed styles
  style = buildStyle('base', {
      success: props.success,
      danger: props.danger,
    },
    {
      fontWeight: 'bold',
      backgroundColor: 'black',
    }
  );

  return (
    <View>
      <Text style={style}>{ props.children }</Text>
    </View>
  );
}

TODO

  • docs
  • HOC
  • check for style existence when pushing to collection
  • automatically pick platform specific styles when object contains ios or android keys
  • tests
  • cache styles in order to improve performance?!

Keywords

FAQs

Package last updated on 02 Jun 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