npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-simple-styles

v1.0.6

Published

Let's not reinvent the wheel. A stylesheet based CSS solution for React Native.

Downloads

15

Readme

React Native Simple Styles npm version npm version

Not everyone wants to write scoped CSS. This package allows you to write CSS that:

  • All lives in the one file;
  • Is applied using a classNames prop (similar to React);
  • Is compatible with an atomic CSS approach;
  • Doesn't need to be repeated for every component;
  • Doesn't require you to import and use StyleSheet.create() in every component

Usage

Write your CSS in a single style.js file and also import the react-native-simple-styles npm package here. You should also make sure to export the react-native-simple-styles package from here using whatever name you like (this will make your life easier with importing later!). Use standard CSS-in-JS object format. You can organise your CSS however you like. E.g.

// styles.js

import reactNativeSimpleStyles from "react-native-simple-styles";

const headings = {
	h1: { fontSize: 56 },
	h2: { fontSize: 36 },
	h3: { fontSize: 24 },
}

const textUtilities = {
	uppercase: { textTransform: 'uppercase'},
	italic: { fontStyles: 'italic'}
}

export const styles = {
	centerAll: {
		display: 'flex',
		alignItems: 'center',
		justifyContent: 'center'
	},
	hScreen: {
		height: '100vh'
	}
	...headings,
	...textUtilities,
}

export const simpleStyles = reactNativeSimpleStyles;

In your components pass in your stylesheet to the react-native-simple-styles function you exported from style.js. All of the standard React Native core components will be returned that you can use as normal. The only difference is that they now accept a className prop that you can pass your classNames to.

import { styles, simpleStyles) from "./styles/style";
const { View, Text } = simpleStyles(styles);

const Example = () => (
	<View className="centerAll hScreen">
		<Text className="h1 uppercase italic">
			Just like native CSS (almost!)
		</Text>
	</View>
);

export default Example;

You can also mix and match classNames and inline styles and it will work fine.

<Text className='uppercase' style={{ fontWeight: bold }> This works fine too. </Text>

Under the hood

Under the hood reactNativeSimpleStyles is simply a higher order compnent that wraps the regular react native components.

This HOC uses React Native's StyleSheet component along with your stylesheet to find your styles and abstracts away the manual process of creating a StyleSheet for each component. Since the StyleSheet component is used under the hood you still get the same performance benefits (as compared to simply using inline styles, for example)

Disclaimers & Contributions

Full disclosure that I am not primarily a React Native developer and I may have overlooked certain issues that may exist with this library.

If you would like to enhance this library, fix bugs, add typescript support, add tests, or otherwise contribute in any other way you are more than welcome to raise an issue or make a PR.