Skip to content

pjjanak/react-native-nested-stylesheets

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

react-native-nested-stylesheet

Nestable stylesheets for react-native.

Installation

npm install react-native-nested-stylesheet

Usage notes

This plugin will allow you to create styles of the following format:

...
namespace: {
	styleA: {...},
	styleB: {...},
},
...

With the plain StyleSheet API you can only create stylesheets with one level. It should noted that NestedStyleSheet does not create cascading selectors. This is merely to allow namespacing of styles (e.g. containing the styles for all items in a specific ListView).

Note: You are only allowed to include other objects within a nested style. You cannot define rules at the namespace level.

Usage Example

var React = require('react-native');
var NestedStyleSheet = require('react-native-nested-stylesheet');

var {
	View,
	Text,
	Image,
} = React;

var styles = NestedStyleSheet.create({
	cells: {
		container: {
			flex: 1,
			flexDirection: 'row',
			alignItems: 'center',
		},
		thumbnail: {
			width: 53,
			height: 81,
		},
		content: {
			flex: 1,
		},
	},
});

var Demo = React.createClass({
	render: function() {
		return (
			<View style={styles.cells.container}>
				<Image source={{...}} style={styles.cells.thumbnail}
				<View style={styles.content}>
					<Text>...</Text>
				</View>
			</View>
		);
	},
});

module.exports = Demo;

About

Extends React Native's StyleSheet Object to allow for nesting of styles

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published