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-zero-theme

v0.8.0

Published

Zero Molecule Theme plugin for React Native

Downloads

2

Readme

Introduction

Zero Theme is Zero Molecule's new approach to React Native styling which can be overwhelming from time to time. We wanted to be able to use css-like className styling instead of writing {flex: 1} a million times. Yes, we know this can all be achieved using plain JavaScript, but we prefer this way for it's simplicity and readability.

Note

This is a pure styling library, not a UI kit. It is compatible with any component and UI kit available. If you're looking for a UI kit, please check out our zero-components UI kit for React Native

Features

  • Global style (theme) containing all classes that themed components use
  • A way to set default component styles
  • Support for other styling properties like contentContainerStyle
  • Flow typed props
  • Utility and parsing functions so you can use them for yourself
  • withTheme High-Order Component that enables you to wrap any component and make it themeable
  • BEM inspired way to have subclasses

Getting started

Installation

If you want just the components, you need to add the plugin from npm.js using

npm install react-native-zero-theme --save

or if you prefer yarn

yarn add react-native-zero-theme

Create your theme

Your theme is actually a collection of css-like classes and some BEM-like blocks with substyles. Simple theme looks something like this:

export default {
  flex: {
    flex: 1,
  },
  flexGrow: {
    flexGrow: 1,
  },
  'p-24': {
    padding: 24,
  },
  text: {
    color: '#333',
    fontSize: 14,
    '--bold': {
      fontWeight: 'bold',
    },
    '--center': {
      textAlign: 'center',
    },
    '--error': {
      textColor: 'red',
    },
  },
  background: {
    backgroundColor: '#f1f1f1',
    '--dark': {
      backgroundColor: '#333',
    },
    '--light': {
      backgroundColor: '#fff',
    },
  },
};

Here you can see that we've added few global classes for all components to use (like flex, and p-24). In addition to those, we also added come block specific classes like text and background which have their own styles and subclasses. Their usage is shown below.

Usage

Basic

If you just want to wrap your component and maybe set some default classes to it, you use it like this

import React from 'react';
import { ScrollView, Text, View } from 'react-native';
import { Theme, withTheme } from 'react-native-zero-theme';
import showcaseTheme from './showcaseTheme';

const ThemedView = withTheme()(View);
const ThemedText = withTheme({ className: ['style', 'text'] })(Text);
const ThemedScrollView = withTheme({
  className: ['style'],
  contentContainerClassName: ['contentContainerStyle'],
})(ScrollView);

const BasicShowcase = () => (
  <Theme.Provider value={showcaseTheme}>
    <ThemedScrollView className="flex" contentContainerClassName="flex flex-grow">
      <ThemedView className="center flex p-24">
        <ThemedText>
          My font size is 14 and color is #333
        </ThemedText>
        <ThemedText className="text--error">
          There is danger ahead! I look just like text above, but my text is red
        </ThemedText>
        <ThemedText className="p-24 text--center text--bold">
          Well that is all good for you, but I am in the center of attention!
        </ThemedText>
      </ThemedView>
    </ThemedScrollView>
  </Theme.Provider>
);

License

Zero Theme is open source and released under the BSD-3-Clause License