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-stylable

v0.2.2

Published

Cascading styles for ReactNative

Downloads

6

Readme

react-native-stylable

Build Status Coverage Status

Cascading styles for ReactNative. A components for easy styling you React Native application.

:warning: The package is currently in alpha stage of development. If you find a bug or missing functionality, please feel free to report, but better fix or implement what you want and send a pull request to GitHub repository.

Installation

npm install --save react-native-stylable

Usage

// app.js
import React from 'react'
import { StyleProvider } from 'react-native-stylable'

import AppView from './AppView'
import styleSheet from './styles'

const App = () => <StyleProvider styleSheet={styleSheet}>
  <AppView/>
</StyleProvider>

export default App
// styles.js
import { Stylesheet } from 'react-native-stylable'

const s = new Stylesheet()
// Global styles, theme code, etc...
// Will overwrite defaults...
s.addRules({
  'baseText': {
    style: { fontSize: 8 }
  }
})
export default s
// some component, Item.js for ex
import PropTypes from 'prop-types'
import React from 'react'
import { Image, Text, View } from 'react-native'
import { stylable } from 'react-native-stylable'

import styleSheet from './styles'

// default styles for our component
styleSheet.addDefaultRules({
  Item: {
    style: {
      borderWidth: 1,
      borderColor: 'rgb(240,240,240)',
      margin: 4,
      flex: 1
    }
  },
  'Item Description': {
    style: {
      marginHorizontal: 12
    }
  },
  'Item PriceText': {
    mixins: ['baseText'],
    style: {
      fontWeight: 'bold'
    }
  },
  'Item DescriptionText': {
    mixins: ['baseText'],
    style: {
      marginVertical: 6
    }
  },
  'Item Image': {
    style: {
      left: 0,
      right: 0,
      height: 160
    }
  }
})

const Description = stylable('Description')(View)
const DescriptionText = stylable('DescriptionText')(Text)
const Image = stylable('Image')(Image)
const PriceText = stylable('PriceText')(Text)

class Item extends React.Component {
  static propTypes = {
    modelItem: PropTypes.object.isRequired
  }
  render () {
    const { modelItem, ...other } = this.props
    const price = modelItem.price + modelItem.currency
    const uri = modelItem.imageUri
    return <View {...other}>
      <Image source={{uri}} />
      <Description>
        <DescriptionText>{modelItem.name}</DescriptionText>
        <PriceText>{price}</PriceText>
      </Description>
    </View>
  }
}

export default stylable('Item')(Item)

API

import { StyleSheet, StyleProvider, stylable } from 'react-native-stylable'

Stylesheet

Holds style rules.

Constructor

Creates new empty style sheet.

const styleSheet = new StyleSheet()

addDefaultRules(rules:Object)

Add default (low priority) rules to style sheet. This method intended to be called from custom components code to provide default styles.

addRules(rules:Object)

Add normal rules. This method intended to be called from application startup to provide customizations.

Rules object

Each rule has selector and properties.

Selector is an element name or sequence of names separated by space (same as descendant selectors in CSS). Also any element name can be suffixed with variant with dot symbol (ex: Button.active ButtonTitle), variants works like classes in CSS.

Properties is an object, that can contains mixins, props and style keys.

  • mixins - Array of others element names.
  • props - Properties to be added to React component.
  • style - Styles to be added to style of React component.

StyleProvider

React component that provides StyleSheet to other stylable components.

<StyleProvider styleSheet={styleSheet}>{other app components}</StyleSheet>

stylable(name:String):Function

Return function (fn(component:Component):Component) to produce Higher Order Component with name that pass props and style from StyleSheet to wrapped component. Also generated component can accept one additional property - variant to dynamically change styles.

Author

Vladimir Timofeev

License

Source code is licensed under the MIT License.